3 # This module impliments the abstracted routing for all protocols and
4 # is probably what I SHOULD have done the first time.
8 # This is just a container class which I expect to subclass
10 # Copyright (c) 2001 Dirk Koopman G1TLH
23 use vars qw(%list %valid $filterdef);
27 flags => "0,Flags,phex",
28 dxcc => '0,Country Code',
34 # tag, sort, field, priv, special parser
36 ['channel_dxcc', 'n', 1],
37 ['channel_itu', 'n', 2],
38 ['channel_zone', 'n', 3],
40 ['call_dxcc', 'n', 5],
42 ['call_zone', 'n', 7],
48 my ($pkg, $call) = @_;
49 $pkg = ref $pkg if ref $pkg;
51 my $self = bless {call => $call}, $pkg;
52 dbg('routelow', "create $pkg with $call");
54 # add in all the dxcc, itu, zone info
55 my @dxcc = Prefix::extract($call);
57 $self->{dxcc} = $dxcc[1]->dxcc;
58 $self->{itu} = $dxcc[1]->itu;
59 $self->{cq} = $dxcc[1]->cq;
66 # get a callsign from a passed reference or a string
73 $thingy = $self unless $thingy;
74 $thingy = $thingy->call if ref $thingy;
75 $thingy = uc $thingy if $thingy;
80 # add and delete a callsign to/from a list
88 my $call = _getcall($c);
89 unless (grep {$_ eq $call} @{$self->{$field}}) {
90 push @{$self->{$field}}, $call;
91 dbg('routelow', ref($self) . " adding $call to " . $self->{call} . "->\{$field\}");
94 return $self->{$field};
102 my $call = _getcall($c);
103 if (grep {$_ eq $call} @{$self->{$field}}) {
104 $self->{$field} = [ grep {$_ ne $call} @{$self->{$field}} ];
105 dbg('routelow', ref($self) . " deleting $call from " . $self->{call} . "->\{$field\}");
108 return $self->{$field};
112 # flag field constructors/enquirers
119 return $self ? 2 : 0 unless ref $self;
120 return ($self->{flags} & 2) ? 1 : 0 unless $r;
121 $self->{flags} = (($self->{flags} & ~2) | ($r ? 1 : 0));
129 return $self ? 1 : 0 unless ref $self;
130 return ($self->{flags} & 1) ? 1 : 0 unless $r;
131 $self->{flags} = (($self->{flags} & ~1) | ($r ? 1 : 0));
138 return @{$self->{parent}};
148 my $call = sprintf "%s", $self->{call};
149 return $self->here ? "$call" : "($call)";
155 my $nodes_only = shift;
159 my $call = $self->user_call;
164 $printit = grep $call =~ m|$_|, @_;
168 $line = ' ' x ($level*2) . "$call";
169 $call = ' ' x length $call;
170 unless ($nodes_only) {
171 if (@{$self->{users}}) {
173 foreach my $ucall (sort @{$self->{users}}) {
174 my $uref = Route::User::get($ucall);
177 $c = $uref->user_call;
181 if ((length $line) + (length $c) + 1 < 79) {
186 $line = ' ' x ($level*2) . "$call->$c ";
193 push @out, $line if length $line;
196 foreach my $ncall (sort @{$self->{nodes}}) {
197 my $nref = Route::Node::get($ncall);
200 my $c = $nref->user_call;
201 push @out, $nref->config($nodes_only, $level+1, @_);
203 push @out, ' ' x (($level+1)*2) . "$ncall?" if @_ == 0 || (@_ && grep $ncall =~ m|$_|, @_);
212 my $nodes = Route::Node::count();
213 my $tot = Route::User::count();
214 my $users = scalar DXCommandmode::get_all();
215 my $maxusers = Route::User::max();
216 my $uptime = main::uptime();
218 return " $nodes nodes, $users local / $tot total users Max users $maxusers Uptime $uptime";
228 return Route::Node::get($call) || Route::User::get($call);
231 # find all the possible dxchannels which this object might be on
236 my $dxchan = DXChannel->get($self->{call});
237 push @dxchan, $dxchan if $dxchan;
239 # it isn't, build up a list of dxchannels and possible ping times
240 # for all the candidates.
241 foreach my $p (@{$self->{parent}}) {
242 my $dxchan = DXChannel->get($p);
244 push @dxchan, $dxchan unless grep $dxchan == $_, @dxchan;
246 next if $p eq $main::mycall; # the root
247 my $ref = $self->get($p);
248 push @dxchan, $ref->alldxchan if $ref;
257 my $dxchan = DXChannel->get($self->{call});
258 return $dxchan if $dxchan;
260 my @dxchan = $self->alldxchan;
261 return undef unless @dxchan;
263 # determine the minimum ping channel
264 my $minping = 99999999;
265 foreach my $dxc (@dxchan) {
266 my $p = $dxc->pingave;
267 if (defined $p && $p < $minping) {
272 $dxchan = shift @dxchan unless $dxchan;
285 dbg('routelow', "$pkg $self->{call} destroyed");
290 # return a list of valid elements
296 $pkg = ref $pkg if ref $pkg;
297 my $val = "${pkg}::valid";
298 my @out = keys %$val;
299 push @out, keys %valid;
304 # return a prompt for a field
309 my ($self, $ele) = @_;
311 my $val = "${pkg}::valid";
312 return $val->{$ele} || $valid{$ele};
316 # generic AUTOLOAD for accessors
321 my $name = $AUTOLOAD;
322 return if $name =~ /::DESTROY$/;
325 confess "Non-existant field '$AUTOLOAD'" if !$valid{$name};
327 # this clever line of code creates a subroutine which takes over from autoload
328 # from OO Perl - Conway
329 # *{$AUTOLOAD} = sub {@_ > 1 ? $_[0]->{$name} = $_[1] : $_[0]->{$name}} ;
330 @_ ? $self->{$name} = shift : $self->{$name} ;