2 # Node routing routines
4 # Copyright (c) 2001 Dirk Koopman G1TLH
17 use vars qw($VERSION $BRANCH);
18 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
19 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0));
20 $main::build += $VERSION;
21 $main::branch += $BRANCH;
23 use vars qw(%list %valid @ISA $max $filterdef);
27 parent => '0,Parent Calls,parray',
28 nodes => '0,Nodes,parray',
29 users => '0,Users,parray',
30 usercount => '0,User Count',
31 version => '0,Version',
32 handle_xml => '0,Using XML,yesno',
33 lastmsg => '0,Last Route Msg,atime',
34 lastid => '0,Last Route MsgID',
37 $filterdef = $Route::filterdef;
43 my $n = scalar (keys %list);
44 $max = $n if $n > $max;
55 # this routine handles the possible adding of an entry in the routing
56 # table. It will only add an entry if it is new. It may have all sorts of
57 # other side effects which may include fixing up other links.
59 # It will return a node object if (and only if) it is a completely new
60 # object with that callsign. The upper layers are expected to do something
63 # called as $parent->add(call, dxchan, version, flags)
70 confess "Route::add trying to add $call to myself" if $call eq $parent->{call};
71 my $self = get($call);
73 $self->_addparent($parent);
74 $parent->_addnode($self);
77 $self = $parent->new($call, @_);
78 $parent->_addnode($self);
83 # this routine is the opposite of 'add' above.
85 # It will return an object if (and only if) this 'del' will remove
86 # this object completely
94 # delete parent from this call's parent list
95 $pref->_delnode($self);
96 $self->_delparent($pref);
98 my $ncall = $self->{call};
100 # is this the last connection, I have no parents anymore?
101 unless (@{$self->{parent}}) {
102 foreach my $rcall (@{$self->{nodes}}) {
103 next if grep $rcall eq $_, @_;
104 my $r = Route::Node::get($rcall);
105 push @nodes, $r->del($self, $ncall, @_) if $r;
108 delete $list{$self->{call}};
118 foreach my $rcall (@{$parent->{nodes}}) {
120 push @out, $r->del($parent, $parent->{call}, @_) if $r;
128 for (@{$self->{users}}) {
129 my $ref = Route::User::get($_);
130 $ref->del($self) if $ref;
135 # add a user to this node
141 confess "Trying to add NULL User call to routing tables" unless $ucall;
143 my $uref = Route::User::get($ucall);
146 @out = $uref->addparent($self);
148 $uref = Route::User->new($ucall, $self->{call}, @_);
151 $self->_adduser($uref);
152 $self->{usercount} = scalar @{$self->{users}};
157 # delete a user from this node
165 @out = $self->_deluser($ref);
168 confess "tried to delete non-existant $ref->{call} from $self->{call}";
170 $self->{usercount} = scalar @{$self->{users}};
177 if (@_ && @{$self->{users}} == 0) {
178 $self->{usercount} = shift;
180 return $self->{usercount};
186 return @{$self->{users}};
192 return @{$self->{nodes}};
198 return @{$self->{parent}};
205 foreach my $call (@{$self->{nodes}}) {
206 next if grep $call eq $_, @_;
209 push @out, $r->rnodes($call, @_) if $r;
220 confess "already have $call in $pkg" if $list{$call};
222 my $self = $pkg->SUPER::new($call);
223 $self->{parent} = ref $pkg ? [ $pkg->{call} ] : [ ];
224 $self->{version} = shift;
225 $self->{flags} = shift;
229 $list{$call} = $self;
237 $call = shift if ref $call;
238 my $ref = $list{uc $call};
239 dbg("Failed to get Node $call" ) if !$ref && isdbg('routerr');
251 return $self->_addlist('parent', @_);
257 return $self->_dellist('parent', @_);
264 return $self->_addlist('nodes', @_);
270 return $self->_dellist('nodes', @_);
277 return $self->_addlist('users', @_);
283 return $self->_dellist('users', @_);
290 my $call = $self->{call} || "Unknown";
292 dbg("destroying $pkg with $call") if isdbg('routelow');
296 # generic AUTOLOAD for accessors
302 my $name = $AUTOLOAD;
303 return if $name =~ /::DESTROY$/;
306 confess "Non-existant field '$AUTOLOAD'" unless $valid{$name} || $Route::valid{$name};
308 # this clever line of code creates a subroutine which takes over from autoload
309 # from OO Perl - Conway
310 *$AUTOLOAD = sub {$_[0]->{$name} = $_[1] if @_ > 1; return $_[0]->{$name}};