Commit 7ed40187 authored by Leigh Stoller's avatar Leigh Stoller

Switch to AUTOLOAD in the Vinterfaces package.

parent c6073582
......@@ -792,7 +792,9 @@ use libdb;
use libtestbed;
use emutil qw(GenFakeMac);
use English;
use Carp;
use overload ('""' => 'Stringify');
use vars qw($AUTOLOAD);
my $nextfake = 0;
......@@ -818,23 +820,40 @@ sub Lookup($$$)
my $vinterface = {};
$vinterface->{"DBROW"} = $query_result->fetchrow_hashref();
$vinterface->{"HASH"} = {};
bless($vinterface, $class);
}
# accessors
sub field($$) { return ((! ref($_[0])) ? -1 : $_[0]->{'DBROW'}->{$_[1]}); }
sub node_id($) { return field($_[0], 'node_id'); }
sub unit($) { return field($_[0], 'unit'); }
sub mac($) { return field($_[0], 'mac'); }
sub IP($) { return field($_[0], 'IP'); }
sub mask($) { return field($_[0], 'mask'); }
sub type($) { return field($_[0], 'type'); }
sub iface($) { return field($_[0], 'iface'); }
sub rtabid($) { return field($_[0], 'rtabid'); }
sub vnode_id($) { return field($_[0], 'vnode_id'); }
sub exptidx($) { return field($_[0], 'exptidx'); }
sub virtlanidx($) { return field($_[0], 'virtlanidx'); }
sub vlanid($) { return field($_[0], 'vlanid'); }
sub bandwidth($) { return field($_[0], 'bandwidth'); }
AUTOLOAD {
my $self = $_[0];
my $type = ref($self) or croak "$self is not an object";
my $name = $AUTOLOAD;
$name =~ s/.*://; # strip fully-qualified portion
# A DB row proxy method call.
if (exists($self->{'DBROW'}->{$name})) {
return $self->{'DBROW'}->{$name};
}
# Or it is for a local storage slot.
if ($name =~ /^_.*$/) {
if (scalar(@_) == 2) {
return $self->{'HASH'}->{$name} = $_[1];
}
elsif (exists($self->{'HASH'}->{$name})) {
return $self->{'HASH'}->{$name};
}
}
carp("No such slot '$name' field in class $type");
return undef;
}
# Break circular reference someplace to avoid exit errors.
sub DESTROY {
my $self = shift;
$self->{'DBROW'} = undef;
$self->{'HASH'} = undef;
}
# The virtual iface name is $type$unit
sub viface($) { return $_[0]->type() . $_[0]->unit(); }
......@@ -932,13 +951,15 @@ sub MakeFake($$$)
$nodeid = $nodeid->node_id()
if (ref($nodeid));
$argref->{'node_id'} = $nodeid;
$argref->{'node_id'} = $nodeid;
$argref->{'vnode_id'} = undef if (!exists($argref->{'vnode_id'}));
# This is usually generated by the insert.
$argref->{'unit'} = $nextfake++;
my $self = {};
$self->{"DBROW"} = $argref;
$self->{"HASH"} = {};
$self->{"FAKE"} = 1;
bless($self, $class);
return $self;
......@@ -1465,6 +1486,6 @@ sub Stringify($)
return "[LogicalWire: $nodeA:$ifaceA/$nodeB:$ifaceB]";
}
# _Always_ make sure that this 1 is at the end of the file...
1;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment