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

Switch to AUTOLOAD in the Vinterfaces package.

parent c6073582
...@@ -792,7 +792,9 @@ use libdb; ...@@ -792,7 +792,9 @@ use libdb;
use libtestbed; use libtestbed;
use emutil qw(GenFakeMac); use emutil qw(GenFakeMac);
use English; use English;
use Carp;
use overload ('""' => 'Stringify'); use overload ('""' => 'Stringify');
use vars qw($AUTOLOAD);
my $nextfake = 0; my $nextfake = 0;
...@@ -818,23 +820,40 @@ sub Lookup($$$) ...@@ -818,23 +820,40 @@ sub Lookup($$$)
my $vinterface = {}; my $vinterface = {};
$vinterface->{"DBROW"} = $query_result->fetchrow_hashref(); $vinterface->{"DBROW"} = $query_result->fetchrow_hashref();
$vinterface->{"HASH"} = {};
bless($vinterface, $class); bless($vinterface, $class);
} }
# accessors
sub field($$) { return ((! ref($_[0])) ? -1 : $_[0]->{'DBROW'}->{$_[1]}); } AUTOLOAD {
sub node_id($) { return field($_[0], 'node_id'); } my $self = $_[0];
sub unit($) { return field($_[0], 'unit'); } my $type = ref($self) or croak "$self is not an object";
sub mac($) { return field($_[0], 'mac'); } my $name = $AUTOLOAD;
sub IP($) { return field($_[0], 'IP'); } $name =~ s/.*://; # strip fully-qualified portion
sub mask($) { return field($_[0], 'mask'); }
sub type($) { return field($_[0], 'type'); } # A DB row proxy method call.
sub iface($) { return field($_[0], 'iface'); } if (exists($self->{'DBROW'}->{$name})) {
sub rtabid($) { return field($_[0], 'rtabid'); } return $self->{'DBROW'}->{$name};
sub vnode_id($) { return field($_[0], 'vnode_id'); } }
sub exptidx($) { return field($_[0], 'exptidx'); } # Or it is for a local storage slot.
sub virtlanidx($) { return field($_[0], 'virtlanidx'); } if ($name =~ /^_.*$/) {
sub vlanid($) { return field($_[0], 'vlanid'); } if (scalar(@_) == 2) {
sub bandwidth($) { return field($_[0], 'bandwidth'); } 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 # The virtual iface name is $type$unit
sub viface($) { return $_[0]->type() . $_[0]->unit(); } sub viface($) { return $_[0]->type() . $_[0]->unit(); }
...@@ -932,13 +951,15 @@ sub MakeFake($$$) ...@@ -932,13 +951,15 @@ sub MakeFake($$$)
$nodeid = $nodeid->node_id() $nodeid = $nodeid->node_id()
if (ref($nodeid)); 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. # This is usually generated by the insert.
$argref->{'unit'} = $nextfake++; $argref->{'unit'} = $nextfake++;
my $self = {}; my $self = {};
$self->{"DBROW"} = $argref; $self->{"DBROW"} = $argref;
$self->{"HASH"} = {};
$self->{"FAKE"} = 1; $self->{"FAKE"} = 1;
bless($self, $class); bless($self, $class);
return $self; return $self;
...@@ -1465,6 +1486,6 @@ sub Stringify($) ...@@ -1465,6 +1486,6 @@ sub Stringify($)
return "[LogicalWire: $nodeA:$ifaceA/$nodeB:$ifaceB]"; return "[LogicalWire: $nodeA:$ifaceA/$nodeB:$ifaceB]";
} }
# _Always_ make sure that this 1 is at the end of the file... # _Always_ make sure that this 1 is at the end of the file...
1; 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