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 $ref = $self->_delparent($pcall);
89 # is this the last connection, I have no parents anymore?
91 my $ncall = $self->{call};
92 foreach my $rcall (@{$self->{nodes}}) {
93 next if grep $rcall eq $_, @_;
94 my $r = Route::Node::get($rcall);
95 push @nodes, $r->del($self, $ncall, @_) if $r;
98 delete $list{$self->{call}};
108 foreach my $rcall (@{$parent->{nodes}}) {
110 push @out, $r->del($parent, $parent->{call}, @_) if $r;
118 for (@{$self->{users}}) {
119 my $ref = Route::User::get($_);
120 $ref->del($self) if $ref;
125 # add a user to this node
130 $self->_adduser($ucall);
132 $self->{usercount} = scalar @{$self->{users}};
133 my $uref = Route::User::get($ucall);
134 my @out = (Route::User->new($ucall, $self->{call}, @_)) unless $uref;
138 # delete a user from this node
143 my $ref = Route::User::get($ucall);
144 $self->_deluser($ucall);
145 my @out = $ref->del($self) if $ref;
152 if (@_ && @{$self->{users}} == 0) {
153 $self->{usercount} = shift;
155 return $self->{usercount};
161 return @{$self->{users}};
167 return @{$self->{nodes}};
174 foreach my $call (@{$self->{nodes}}) {
175 next if grep $call eq $_, @_;
178 push @out, $r->rnodes($call, @_) if $r;
189 confess "already have $call in $pkg" if $list{$call};
191 my $self = $pkg->SUPER::new($call);
192 $self->{parent} = ref $pkg ? [ $pkg->{call} ] : [ ];
193 $self->{version} = shift;
194 $self->{flags} = shift;
198 $list{$call} = $self;
206 $call = shift if ref $call;
207 my $ref = $list{uc $call};
208 dbg('routerr', "Failed to get Node $call" ) unless $ref;
220 return $self->_addlist('parent', @_);
226 return $self->_dellist('parent', @_);
233 return $self->_addlist('nodes', @_);
239 return $self->_dellist('nodes', @_);
246 return $self->_addlist('users', @_);
252 return $self->_dellist('users', @_);
259 my $call = $self->{call} || "Unknown";
261 dbg('route', "destroying $pkg with $call");
265 # generic AUTOLOAD for accessors
274 return if $name =~ /::DESTROY$/;
277 confess "Non-existant field '$AUTOLOAD'" unless $valid{$name} || $Route::valid{$name};
279 # this clever line of code creates a subroutine which takes over from autoload
280 # from OO Perl - Conway
281 # print "AUTOLOAD: $AUTOLOAD\n";
282 # *{$AUTOLOAD} = sub {my $self = shift; @_ ? $self->{$name} = shift : $self->{$name}} ;
283 @_ ? $self->{$name} = shift : $self->{$name} ;