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;
161 my $call = $self->user_call;
166 $printit = grep $call =~ m|$_|, @_;
170 $line = ' ' x ($level*2) . "$call";
171 $call = ' ' x length $call;
174 if ((DXChannel->get($self->{call}) && $level > 1) || grep $self->{call} eq $_, @$seen) {
179 push @$seen, $self->{call};
182 unless ($nodes_only) {
183 if (@{$self->{users}}) {
185 foreach my $ucall (sort @{$self->{users}}) {
186 my $uref = Route::User::get($ucall);
189 $c = $uref->user_call;
193 if ((length $line) + (length $c) + 1 < 79) {
198 $line = ' ' x ($level*2) . "$call->$c ";
205 push @out, $line if length $line;
208 # deal with more nodes
209 foreach my $ncall (sort @{$self->{nodes}}) {
210 my $nref = Route::Node::get($ncall);
213 my $c = $nref->user_call;
214 dbg('routec', "recursing from $call -> $c");
215 push @out, $nref->config($nodes_only, $level+1, $seen, @_);
217 push @out, ' ' x (($level+1)*2) . "$ncall?" if @_ == 0 || (@_ && grep $ncall =~ m|$_|, @_);
226 my $nodes = Route::Node::count();
227 my $tot = Route::User::count();
228 my $users = scalar DXCommandmode::get_all();
229 my $maxusers = Route::User::max();
230 my $uptime = main::uptime();
232 return " $nodes nodes, $users local / $tot total users Max users $maxusers Uptime $uptime";
242 return Route::Node::get($call) || Route::User::get($call);
245 # find all the possible dxchannels which this object might be on
250 my $dxchan = DXChannel->get($self->{call});
251 push @dxchan, $dxchan if $dxchan;
253 # it isn't, build up a list of dxchannels and possible ping times
254 # for all the candidates.
255 foreach my $p (@{$self->{parent}}) {
256 my $dxchan = DXChannel->get($p);
258 push @dxchan, $dxchan unless grep $dxchan == $_, @dxchan;
260 next if $p eq $main::mycall; # the root
261 my $ref = $self->get($p);
262 push @dxchan, $ref->alldxchan if $ref;
271 my $dxchan = DXChannel->get($self->{call});
272 return $dxchan if $dxchan;
274 my @dxchan = $self->alldxchan;
275 return undef unless @dxchan;
277 # determine the minimum ping channel
278 my $minping = 99999999;
279 foreach my $dxc (@dxchan) {
280 my $p = $dxc->pingave;
281 if (defined $p && $p < $minping) {
286 $dxchan = shift @dxchan unless $dxchan;
299 dbg('routelow', "$pkg $self->{call} destroyed");
304 # return a list of valid elements
310 $pkg = ref $pkg if ref $pkg;
311 my $val = "${pkg}::valid";
312 my @out = keys %$val;
313 push @out, keys %valid;
318 # return a prompt for a field
323 my ($self, $ele) = @_;
325 my $val = "${pkg}::valid";
326 return $val->{$ele} || $valid{$ele};
330 # generic AUTOLOAD for accessors
335 my $name = $AUTOLOAD;
336 return if $name =~ /::DESTROY$/;
339 confess "Non-existant field '$AUTOLOAD'" if !$valid{$name};
341 # this clever line of code creates a subroutine which takes over from autoload
342 # from OO Perl - Conway
343 # *{$AUTOLOAD} = sub {@_ > 1 ? $_[0]->{$name} = $_[1] : $_[0]->{$name}} ;
344 @_ ? $self->{$name} = shift : $self->{$name} ;