2 # Node routing routines
4 # Copyright (c) 2001 Dirk Koopman G1TLH
17 use vars qw(%list %valid @ISA $max $filterdef);
21 parent => '0,Parent Calls,parray',
22 nodes => '0,Nodes,parray',
23 users => '0,Users,parray',
24 usercount => '0,User Count',
25 version => '0,Version',
28 $filterdef = $Route::filterdef;
34 my $n = scalar (keys %list);
35 $max = $n if $n > $max;
45 # this routine handles the possible adding of an entry in the routing
46 # table. It will only add an entry if it is new. It may have all sorts of
47 # other side effects which may include fixing up other links.
49 # It will return a node object if (and only if) it is a completely new
50 # object with that callsign. The upper layers are expected to do something
53 # called as $parent->add(call, dxchan, version, flags)
64 $call = $self->{call};
69 confess "Trying to add NULL Node call to routing tables" unless $call;
72 $self->_addparent($parent->{call});
73 $parent->_addnode($call);
76 confess "Route::Node::add trying to add $call to myself" if $call eq $parent->{call};
77 $parent->_addnode($call);
78 $self = $parent->new($call, @_);
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 my $pcall = $pref->{call};
96 my $ncall = $self->{call};
97 $pref->_delnode($ncall);;
98 my $ref = $self->_delparent($pcall);
101 # is this the last connection, I have no parents anymore?
103 foreach my $rcall (@{$self->{nodes}}) {
104 next if grep $rcall eq $_, @_;
105 my $r = Route::Node::get($rcall);
106 push @nodes, $r->del($self, $ncall, @_) if $r;
109 delete $list{$self->{call}};
119 foreach my $rcall (@{$parent->{nodes}}) {
121 push @out, $r->del($parent, $parent->{call}, @_) if $r;
129 for (@{$self->{users}}) {
130 my $ref = Route::User::get($_);
131 $ref->del($self) if $ref;
136 # add a user to this node
142 confess "Trying to add NULL User call to routing tables" unless $ucall;
144 $self->_adduser($ucall);
146 $self->{usercount} = scalar @{$self->{users}};
147 my $uref = Route::User::get($ucall);
148 my @out = (Route::User->new($ucall, $self->{call}, @_)) unless $uref;
152 # delete a user from this node
157 my $ref = Route::User::get($ucall);
158 $self->_deluser($ucall);
159 my @out = $ref->del($self) if $ref;
166 if (@_ && @{$self->{users}} == 0) {
167 $self->{usercount} = shift;
169 return $self->{usercount};
175 return @{$self->{users}};
181 return @{$self->{nodes}};
188 foreach my $call (@{$self->{nodes}}) {
189 next if grep $call eq $_, @_;
192 push @out, $r->rnodes($call, @_) if $r;
203 confess "already have $call in $pkg" if $list{$call};
205 my $self = $pkg->SUPER::new($call);
206 $self->{parent} = ref $pkg ? [ $pkg->{call} ] : [ ];
207 $self->{version} = shift;
208 $self->{flags} = shift;
212 $list{$call} = $self;
220 $call = shift if ref $call;
221 my $ref = $list{uc $call};
222 dbg("Failed to get Node $call" ) if !$ref && isdbg('routerr');
234 return $self->_addlist('parent', @_);
240 return $self->_dellist('parent', @_);
247 return $self->_addlist('nodes', @_);
253 return $self->_dellist('nodes', @_);
260 return $self->_addlist('users', @_);
266 return $self->_dellist('users', @_);
273 my $call = $self->{call} || "Unknown";
275 dbg("destroying $pkg with $call") if isdbg('routelow');
279 # generic AUTOLOAD for accessors
288 return if $name =~ /::DESTROY$/;
291 confess "Non-existant field '$AUTOLOAD'" unless $valid{$name} || $Route::valid{$name};
293 # this clever line of code creates a subroutine which takes over from autoload
294 # from OO Perl - Conway
295 # print "AUTOLOAD: $AUTOLOAD\n";
296 # *{$AUTOLOAD} = sub {my $self = shift; @_ ? $self->{$name} = shift : $self->{$name}} ;
297 @_ ? $self->{$name} = shift : $self->{$name} ;