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)
60 confess "Route::add trying to add $call to myself" if $call eq $parent->{call};
61 my $self = get($call);
63 $self->_addparent($parent->{call});
64 $parent->_addnode($call);
67 $parent->_addnode($call);
68 $self = $parent->new($call, @_);
73 # this routine is the opposite of 'add' above.
75 # It will return an object if (and only if) this 'del' will remove
76 # this object completely
84 # delete parent from this call's parent list
85 my $pcall = $pref->{call};
86 my $ncall = $self->{call};
87 $pref->_delnode($ncall);;
88 my $ref = $self->_delparent($pcall);
91 # is this the last connection, I have no parents anymore?
93 foreach my $rcall (@{$self->{nodes}}) {
94 next if grep $rcall eq $_, @_;
95 my $r = Route::Node::get($rcall);
96 push @nodes, $r->del($self, $ncall, @_) if $r;
99 delete $list{$self->{call}};
109 foreach my $rcall (@{$parent->{nodes}}) {
111 push @out, $r->del($parent, $parent->{call}, @_) if $r;
119 for (@{$self->{users}}) {
120 my $ref = Route::User::get($_);
121 $ref->del($self) if $ref;
126 # add a user to this node
132 confess "Trying to add NULL User call to routing tables" unless $ucall;
134 $self->_adduser($ucall);
136 $self->{usercount} = scalar @{$self->{users}};
137 my $uref = Route::User::get($ucall);
140 $uref->addparent($self->{call});
142 @out = Route::User->new($ucall, $self->{call}, @_);
147 # delete a user from this node
152 my $ref = Route::User::get($ucall);
153 $self->_deluser($ucall);
154 my @out = $ref->del($self) if $ref;
161 if (@_ && @{$self->{users}} == 0) {
162 $self->{usercount} = shift;
164 return $self->{usercount};
170 return @{$self->{users}};
176 return @{$self->{nodes}};
183 foreach my $call (@{$self->{nodes}}) {
184 next if grep $call eq $_, @_;
187 push @out, $r->rnodes($call, @_) if $r;
198 confess "already have $call in $pkg" if $list{$call};
200 my $self = $pkg->SUPER::new($call);
201 $self->{parent} = ref $pkg ? [ $pkg->{call} ] : [ ];
202 $self->{version} = shift;
203 $self->{flags} = shift;
207 $list{$call} = $self;
215 $call = shift if ref $call;
216 my $ref = $list{uc $call};
217 dbg("Failed to get Node $call" ) if !$ref && isdbg('routerr');
229 return $self->_addlist('parent', @_);
235 return $self->_dellist('parent', @_);
242 return $self->_addlist('nodes', @_);
248 return $self->_dellist('nodes', @_);
255 return $self->_addlist('users', @_);
261 return $self->_dellist('users', @_);
268 my $call = $self->{call} || "Unknown";
270 dbg("destroying $pkg with $call") if isdbg('routelow');
274 # generic AUTOLOAD for accessors
283 return if $name =~ /::DESTROY$/;
286 confess "Non-existant field '$AUTOLOAD'" unless $valid{$name} || $Route::valid{$name};
288 # this clever line of code creates a subroutine which takes over from autoload
289 # from OO Perl - Conway
290 # print "AUTOLOAD: $AUTOLOAD\n";
291 # *{$AUTOLOAD} = sub {my $self = shift; @_ ? $self->{$name} = shift : $self->{$name}} ;
292 @_ ? $self->{$name} = shift : $self->{$name} ;