2 # Node routing routines
4 # Copyright (c) 2001 Dirk Koopman G1TLH
17 use vars qw(%list %valid @ISA $max);
21 parent => '0,Parent Calls,parray',
22 nodes => '0,Nodes,parray',
23 users => '0,Users,parray',
24 version => '0,Version',
33 $max = $n if $n > $max;
43 # this routine handles the possible adding of an entry in the routing
44 # table. It will only add an entry if it is new. It may have all sorts of
45 # other side effects which may include fixing up other links.
47 # It will return a node object if (and only if) it is a completely new
48 # object with that callsign. The upper layers are expected to do something
51 # called as $parent->add(call, dxchan, version, flags)
58 my $self = get($call);
60 $self->_addparent($parent->{call});
63 $parent->_addnode($call);
64 $self = $parent->new($call, @_);
69 # this routine is the opposite of 'add' above.
71 # It will return an object if (and only if) this 'del' will remove
72 # this object completely
80 # delete parent from this call's parent list
81 my $pcall = $pref->{call};
82 my $ref = $self->_delparent($pcall);
85 # is this the last connection?
88 push @nodes, $self->del_nodes;
89 delete $list{$self->{call}};
99 for (@{$self->{users}}) {
100 my $ref = Route::User::get($_);
101 $ref->del($self) if $ref;
106 # remove all sub nodes from this parent
112 for (@{$self->{nodes}}) {
113 next if $self->{call} eq $_;
114 push @nodes, $self->del_node($_);
119 # add a user to this node
124 $self->_adduser($ucall);
126 my $uref = Route::User::get($ucall);
127 return $uref ? () : (Route::User->new($ucall, $self->{call}, @_));
130 # delete a user from this node
135 my $ref = Route::User::get($ucall);
136 $self->_deluser($ucall);
137 return ($ref->del($self)) if $ref;
141 # delete a node from this node (ie I am a parent)
146 $self->_delnode($ncall);
147 my $ref = get($ncall);
148 return ($ref->del($self)) if $ref;
157 confess "already have $call in $pkg" if $list{$call};
159 my $self = $pkg->SUPER::new($call);
160 $self->{parent} = ref $pkg ? [ $pkg->{call} ] : [ ];
161 $self->{version} = shift;
162 $self->{flags} = shift;
166 $list{$call} = $self;
174 $call = shift if ref $call;
175 return $list{uc $call};
181 return $self->_addlist('parent', @_);
187 return $self->_dellist('parent', @_);
194 return $self->_addlist('nodes', @_);
200 return $self->_dellist('nodes', @_);
207 return $self->_addlist('users', @_);
213 return $self->_dellist('users', @_);
220 my $call = $self->{call} || "Unknown";
222 dbg('route', "destroying $pkg with $call");
226 # generic AUTOLOAD for accessors
235 return if $name =~ /::DESTROY$/;
238 confess "Non-existant field '$AUTOLOAD'" unless $valid{$name} || $Route::valid{$name};
240 # this clever line of code creates a subroutine which takes over from autoload
241 # from OO Perl - Conway
242 # print "AUTOLOAD: $AUTOLOAD\n";
243 # *{$AUTOLOAD} = sub {my $self = shift; @_ ? $self->{$name} = shift : $self->{$name}} ;
244 @_ ? $self->{$name} = shift : $self->{$name} ;