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;
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',
34 $filterdef = $Route::filterdef;
40 my $n = scalar (keys %list);
41 $max = $n if $n > $max;
51 # this routine handles the possible adding of an entry in the routing
52 # table. It will only add an entry if it is new. It may have all sorts of
53 # other side effects which may include fixing up other links.
55 # It will return a node object if (and only if) it is a completely new
56 # object with that callsign. The upper layers are expected to do something
59 # called as $parent->add(call, dxchan, version, flags)
66 confess "Route::add trying to add $call to myself" if $call eq $parent->{call};
67 my $self = get($call);
69 $self->_addparent($parent->{call});
70 $parent->_addnode($call);
73 $parent->_addnode($call);
74 $self = $parent->new($call, @_);
79 # this routine is the opposite of 'add' above.
81 # It will return an object if (and only if) this 'del' will remove
82 # this object completely
90 # delete parent from this call's parent list
91 my $pcall = $pref->{call};
92 my $ncall = $self->{call};
93 $pref->_delnode($ncall);;
94 my $ref = $self->_delparent($pcall);
97 # is this the last connection, I have no parents anymore?
99 foreach my $rcall (@{$self->{nodes}}) {
100 next if grep $rcall eq $_, @_;
101 my $r = Route::Node::get($rcall);
102 push @nodes, $r->del($self, $ncall, @_) if $r;
105 delete $list{$self->{call}};
115 foreach my $rcall (@{$parent->{nodes}}) {
117 push @out, $r->del($parent, $parent->{call}, @_) if $r;
125 for (@{$self->{users}}) {
126 my $ref = Route::User::get($_);
127 $ref->del($self) if $ref;
132 # add a user to this node
138 confess "Trying to add NULL User call to routing tables" unless $ucall;
140 $self->_adduser($ucall);
142 $self->{usercount} = scalar @{$self->{users}};
143 my $uref = Route::User::get($ucall);
146 $uref->addparent($self->{call});
148 @out = Route::User->new($ucall, $self->{call}, @_);
153 # delete a user from this node
158 my $ref = Route::User::get($ucall);
159 $self->_deluser($ucall);
160 my @out = $ref->del($self) if $ref;
167 if (@_ && @{$self->{users}} == 0) {
168 $self->{usercount} = shift;
170 return $self->{usercount};
176 return @{$self->{users}};
182 return @{$self->{nodes}};
189 foreach my $call (@{$self->{nodes}}) {
190 next if grep $call eq $_, @_;
193 push @out, $r->rnodes($call, @_) if $r;
204 confess "already have $call in $pkg" if $list{$call};
206 my $self = $pkg->SUPER::new($call);
207 $self->{parent} = ref $pkg ? [ $pkg->{call} ] : [ ];
208 $self->{version} = shift;
209 $self->{flags} = shift;
213 $list{$call} = $self;
221 $call = shift if ref $call;
222 my $ref = $list{uc $call};
223 dbg("Failed to get Node $call" ) if !$ref && isdbg('routerr');
235 return $self->_addlist('parent', @_);
241 return $self->_dellist('parent', @_);
248 return $self->_addlist('nodes', @_);
254 return $self->_dellist('nodes', @_);
261 return $self->_addlist('users', @_);
267 return $self->_dellist('users', @_);
274 my $call = $self->{call} || "Unknown";
276 dbg("destroying $pkg with $call") if isdbg('routelow');
280 # generic AUTOLOAD for accessors
289 return if $name =~ /::DESTROY$/;
292 confess "Non-existant field '$AUTOLOAD'" unless $valid{$name} || $Route::valid{$name};
294 # this clever line of code creates a subroutine which takes over from autoload
295 # from OO Perl - Conway
296 # print "AUTOLOAD: $AUTOLOAD\n";
297 # *{$AUTOLOAD} = sub {my $self = shift; @_ ? $self->{$name} = shift : $self->{$name}} ;
298 @_ ? $self->{$name} = shift : $self->{$name} ;