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;
61 $self->{flags} = here(1);
67 # get a callsign from a passed reference or a string
74 $thingy = $self unless $thingy;
75 $thingy = $thingy->call if ref $thingy;
76 $thingy = uc $thingy if $thingy;
81 # add and delete a callsign to/from a list
89 my $call = _getcall($c);
90 unless (grep {$_ eq $call} @{$self->{$field}}) {
91 push @{$self->{$field}}, $call;
92 dbg('routelow', ref($self) . " adding $call to " . $self->{call} . "->\{$field\}");
95 return $self->{$field};
103 my $call = _getcall($c);
104 if (grep {$_ eq $call} @{$self->{$field}}) {
105 $self->{$field} = [ grep {$_ ne $call} @{$self->{$field}} ];
106 dbg('routelow', ref($self) . " deleting $call from " . $self->{call} . "->\{$field\}");
109 return $self->{$field};
113 # flag field constructors/enquirers
120 return $self ? 2 : 0 unless ref $self;
121 return ($self->{flags} & 2) ? 1 : 0 unless $r;
122 $self->{flags} = (($self->{flags} & ~2) | ($r ? 1 : 0));
130 return $self ? 1 : 0 unless ref $self;
131 return ($self->{flags} & 1) ? 1 : 0 unless $r;
132 $self->{flags} = (($self->{flags} & ~1) | ($r ? 1 : 0));
139 return @{$self->{parent}};
149 my $call = sprintf "%s", $self->{call};
150 return $self->here ? "$call" : "($call)";
156 my $nodes_only = shift;
160 my $call = $self->user_call;
165 $printit = grep $call =~ m|$_|, @_;
169 $line = ' ' x ($level*2) . "$call";
170 $call = ' ' x length $call;
171 unless ($nodes_only) {
172 if (@{$self->{users}}) {
174 foreach my $ucall (sort @{$self->{users}}) {
175 my $uref = Route::User::get($ucall);
178 $c = $uref->user_call;
182 if ((length $line) + (length $c) + 1 < 79) {
187 $line = ' ' x ($level*2) . "$call->$c ";
194 push @out, $line if length $line;
197 foreach my $ncall (sort @{$self->{nodes}}) {
198 my $nref = Route::Node::get($ncall);
201 my $c = $nref->user_call;
202 push @out, $nref->config($nodes_only, $level+1, @_);
204 push @out, ' ' x (($level+1)*2) . "$ncall?" if @_ == 0 || (@_ && grep $ncall =~ m|$_|, @_);
213 my $nodes = Route::Node::count();
214 my $tot = Route::User::count();
215 my $users = scalar DXCommandmode::get_all();
216 my $maxusers = Route::User::max();
217 my $uptime = main::uptime();
219 return " $nodes nodes, $users local / $tot total users Max users $maxusers Uptime $uptime";
229 return Route::Node::get($call) || Route::User::get($call);
232 # find all the possible dxchannels which this object might be on
237 my $dxchan = DXChannel->get($self->{call});
238 push @dxchan, $dxchan if $dxchan;
240 # it isn't, build up a list of dxchannels and possible ping times
241 # for all the candidates.
242 foreach my $p (@{$self->{parent}}) {
243 my $dxchan = DXChannel->get($p);
245 push @dxchan, $dxchan unless grep $dxchan == $_, @dxchan;
247 next if $p eq $main::mycall; # the root
248 my $ref = $self->get($p);
249 push @dxchan, $ref->alldxchan if $ref;
258 my $dxchan = DXChannel->get($self->{call});
259 return $dxchan if $dxchan;
261 my @dxchan = $self->alldxchan;
262 return undef unless @dxchan;
264 # determine the minimum ping channel
265 my $minping = 99999999;
266 foreach my $dxc (@dxchan) {
267 my $p = $dxc->pingave;
268 if (defined $p && $p < $minping) {
273 $dxchan = shift @dxchan unless $dxchan;
286 dbg('routelow', "$pkg $self->{call} destroyed");
291 # return a list of valid elements
297 $pkg = ref $pkg if ref $pkg;
298 my $val = "${pkg}::valid";
299 my @out = keys %$val;
300 push @out, keys %valid;
305 # return a prompt for a field
310 my ($self, $ele) = @_;
312 my $val = "${pkg}::valid";
313 return $val->{$ele} || $valid{$ele};
317 # generic AUTOLOAD for accessors
322 my $name = $AUTOLOAD;
323 return if $name =~ /::DESTROY$/;
326 confess "Non-existant field '$AUTOLOAD'" if !$valid{$name};
328 # this clever line of code creates a subroutine which takes over from autoload
329 # from OO Perl - Conway
330 # *{$AUTOLOAD} = sub {@_ > 1 ? $_[0]->{$name} = $_[1] : $_[0]->{$name}} ;
331 @_ ? $self->{$name} = shift : $self->{$name} ;