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
24 use vars qw($VERSION $BRANCH);
26 main::mkver($VERSION = q$Revision$);
28 use vars qw(%list %valid $filterdef);
32 flags => "0,Flags,phex",
33 dxcc => '0,Country Code',
38 aranea => '0, By Aranea,yesno',
42 # tag, sort, field, priv, special parser
44 ['channel_dxcc', 'nc', 1],
45 ['channel_itu', 'ni', 2],
46 ['channel_zone', 'nz', 3],
49 ['call_dxcc', 'nc', 5],
51 ['call_itu', 'ni', 6],
53 ['call_zone', 'nz', 7],
55 ['channel_state', 'ns', 8],
56 ['call_state', 'ns', 9],
57 ['by_state', 'ns', 9],
63 my ($pkg, $call) = @_;
64 $pkg = ref $pkg if ref $pkg;
66 my $self = bless {call => $call}, $pkg;
67 dbg("create $pkg with $call") if isdbg('routelow');
69 # add in all the dxcc, itu, zone info
70 ($self->{dxcc}, $self->{itu}, $self->{cq}, $self->{state}, $self->{city}) =
71 Prefix::cty_data($call);
79 # get a callsign from a passed reference or a string
86 $thingy = $self unless $thingy;
87 $thingy = $thingy->call if ref $thingy;
88 $thingy = uc $thingy if $thingy;
93 # add and delete a callsign to/from a list
102 confess "Need a ref here" unless ref($c);
104 my $call = $c->{call};
105 unless (grep $_ eq $call, @{$self->{$field}}) {
106 push @{$self->{$field}}, $call;
107 dbg(ref($self) . " adding $call to " . $self->{call} . "->\{$field\}") if isdbg('routelow');
120 confess "Need a ref here" unless ref($c);
121 my $call = $c->{call};
122 if (grep $_ eq $call, @{$self->{$field}}) {
123 $self->{$field} = [ grep {$_ ne $call} @{$self->{$field}} ];
124 dbg(ref($self) . " deleting $call from " . $self->{call} . "->\{$field\}") if isdbg('routelow');
134 return @{$self->{$_[0]}} == 0;
138 # flag field constructors/enquirers
140 # These can be called in various ways:-
142 # Route::here or $ref->here returns 1 or 0 depending on value of the here flag
143 # Route::here(1) returns 1 (the bit value of the here flag)
144 # $ref->here(1) or $ref->here(0) sets the here flag
146 # these are now redundant really as we are not interested in conferences
147 # and here is back to being '1'.
152 $self->{flags} = shift if @_;
153 return $self->{flags};
156 # conferencing in the ak1a sense is not supported
166 return @{$self->{parent}};
176 my $call = sprintf "%s", $self->{call};
177 return $self->here ? "$call" : "($call)";
183 my $nodes_only = shift;
188 my $call = $self->user_call;
193 $printit = grep $call =~ m|$_|, @_;
197 $line = ' ' x ($level*2) . "$call";
198 $call = ' ' x length $call;
201 if ((DXChannel::get($self->{call}) && $level > 1) || grep $self->{call} eq $_, @$seen) {
206 push @$seen, $self->{call};
209 unless ($nodes_only) {
210 if (@{$self->{users}}) {
212 foreach my $ucall (sort @{$self->{users}}) {
213 my $uref = Route::User::get($ucall);
216 $c = $uref->user_call;
220 if ((length $line) + (length $c) + 1 < 79) {
225 $line = ' ' x ($level*2) . "$call->$c ";
232 push @out, $line if length $line;
235 # deal with more nodes
236 foreach my $ncall (sort @{$self->{nodes}}) {
237 my $nref = Route::Node::get($ncall);
240 my $c = $nref->user_call;
241 # dbg("recursing from $call -> $c") if isdbg('routec');
242 push @out, $nref->config($nodes_only, $level+1, $seen, @_);
244 push @out, ' ' x (($level+1)*2) . "$ncall?" if @_ == 0 || (@_ && grep $ncall =~ m|$_|, @_);
253 my $nodes = Route::Node::count();
254 my $tot = Route::User::count();
255 my $users = scalar DXCommandmode::get_all();
256 my $maxusers = Route::User::max();
257 my $uptime = main::uptime();
259 return " $nodes nodes, $users local / $tot total users Max users $maxusers Uptime $uptime";
269 return Route::Node::get($call) || Route::User::get($call);
272 # find all the possible dxchannels which this object might be on
277 # dbg("Trying node $self->{call}") if isdbg('routech');
279 my $dxchan = DXChannel::get($self->{call});
280 push @dxchan, $dxchan if $dxchan;
282 # it isn't, build up a list of dxchannels and possible ping times
283 # for all the candidates.
285 foreach my $p (@{$self->{parent}}) {
286 # dbg("Trying parent $p") if isdbg('routech');
287 next if $p eq $main::mycall; # the root
288 my $dxchan = DXChannel::get($p);
290 push @dxchan, $dxchan unless grep $dxchan == $_, @dxchan;
292 next if grep $p eq $_, @_;
293 my $ref = Route::Node::get($p);
294 # dbg("Next node $p " . ($ref ? 'Found' : 'NOT Found') if isdbg('routech') );
295 push @dxchan, $ref->alldxchan($self->{call}, @_) if $ref;
299 # dbg('routech', "Got dxchan: " . join(',', (map{ $_->call } @dxchan)) );
307 # ALWAYS return the locally connected channel if present;
308 my $dxchan = DXChannel::get($self->call);
309 return $dxchan if $dxchan;
311 my @dxchan = $self->alldxchan;
312 return undef unless @dxchan;
314 # determine the minimum ping channel
315 my $minping = 99999999;
316 foreach my $dxc (@dxchan) {
317 my $p = $dxc->pingave;
318 if (defined $p && $p < $minping) {
323 $dxchan = shift @dxchan unless $dxchan;
338 dbg("$pkg $self->{call} destroyed") if isdbg('routelow');
343 # return a list of valid elements
349 $pkg = ref $pkg if ref $pkg;
350 my $val = "${pkg}::valid";
351 my @out = keys %$val;
352 push @out, keys %valid;
357 # return a prompt for a field
362 my ($self, $ele) = @_;
364 my $val = "${pkg}::valid";
365 return $val->{$ele} || $valid{$ele};
369 # generic AUTOLOAD for accessors
374 my $name = $AUTOLOAD;
375 return if $name =~ /::DESTROY$/;
378 confess "Non-existant field '$AUTOLOAD'" if !$valid{$name};
380 # this clever line of code creates a subroutine which takes over from autoload
381 # from OO Perl - Conway
382 *{$AUTOLOAD} = sub {@_ > 1 ? $_[0]->{$name} = $_[1] : $_[0]->{$name}};