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);
73 $self->{flags} = here(1);
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;
140 $self->{aranea} = shift if @_;
141 return $self->{aranea};
145 # flag field constructors/enquirers
147 # These can be called in various ways:-
149 # Route::here or $ref->here returns 1 or 0 depending on value of the here flag
150 # Route::here(1) returns 1 (the bit value of the here flag)
151 # $ref->here(1) or $ref->here(0) sets the here flag
153 # these are now redundant really as we are not interested in conferences
154 # and here is back to being '1'.
160 return $self ? 1 : 0 unless ref $self;
161 return ($self->{flags} & 1) ? 1 : 0 unless defined $r;
162 $self->{flags} = (($self->{flags} & ~1) | ($r ? 1 : 0));
170 return $self ? 2 : 0 unless ref $self;
171 return ($self->{flags} & 2) ? 2 : 0 unless defined $r;
172 $self->{flags} = (($self->{flags} & ~2) | ($r ? 2 : 0));
179 return @{$self->{parent}};
189 my $call = sprintf "%s", $self->{call};
190 return $self->here ? "$call" : "($call)";
196 my $nodes_only = shift;
201 my $call = $self->user_call;
206 $printit = grep $call =~ m|$_|, @_;
210 $line = ' ' x ($level*2) . "$call";
211 $call = ' ' x length $call;
214 if ((DXChannel::get($self->{call}) && $level > 1) || grep $self->{call} eq $_, @$seen) {
219 push @$seen, $self->{call};
222 unless ($nodes_only) {
223 if (@{$self->{users}}) {
225 foreach my $ucall (sort @{$self->{users}}) {
226 my $uref = Route::User::get($ucall);
229 $c = $uref->user_call;
233 if ((length $line) + (length $c) + 1 < 79) {
238 $line = ' ' x ($level*2) . "$call->$c ";
245 push @out, $line if length $line;
248 # deal with more nodes
249 foreach my $ncall (sort @{$self->{nodes}}) {
250 my $nref = Route::Node::get($ncall);
253 my $c = $nref->user_call;
254 # dbg("recursing from $call -> $c") if isdbg('routec');
255 push @out, $nref->config($nodes_only, $level+1, $seen, @_);
257 push @out, ' ' x (($level+1)*2) . "$ncall?" if @_ == 0 || (@_ && grep $ncall =~ m|$_|, @_);
266 my $nodes = Route::Node::count();
267 my $tot = Route::User::count();
268 my $users = scalar DXCommandmode::get_all();
269 my $maxusers = Route::User::max();
270 my $uptime = main::uptime();
272 return " $nodes nodes, $users local / $tot total users Max users $maxusers Uptime $uptime";
282 return Route::Node::get($call) || Route::User::get($call);
285 # find all the possible dxchannels which this object might be on
290 # dbg("Trying node $self->{call}") if isdbg('routech');
292 my $dxchan = DXChannel::get($self->{call});
293 push @dxchan, $dxchan if $dxchan;
295 # it isn't, build up a list of dxchannels and possible ping times
296 # for all the candidates.
298 foreach my $p (@{$self->{parent}}) {
299 # dbg("Trying parent $p") if isdbg('routech');
300 next if $p eq $main::mycall; # the root
301 my $dxchan = DXChannel::get($p);
303 push @dxchan, $dxchan unless grep $dxchan == $_, @dxchan;
305 next if grep $p eq $_, @_;
306 my $ref = Route::Node::get($p);
307 # dbg("Next node $p " . ($ref ? 'Found' : 'NOT Found') if isdbg('routech') );
308 push @dxchan, $ref->alldxchan($self->{call}, @_) if $ref;
312 # dbg('routech', "Got dxchan: " . join(',', (map{ $_->call } @dxchan)) );
320 # ALWAYS return the locally connected channel if present;
321 my $dxchan = DXChannel::get($self->call);
322 return $dxchan if $dxchan;
324 my @dxchan = $self->alldxchan;
325 return undef unless @dxchan;
327 # determine the minimum ping channel
328 my $minping = 99999999;
329 foreach my $dxc (@dxchan) {
330 my $p = $dxc->pingave;
331 if (defined $p && $p < $minping) {
336 $dxchan = shift @dxchan unless $dxchan;
351 dbg("$pkg $self->{call} destroyed") if isdbg('routelow');
356 # return a list of valid elements
362 $pkg = ref $pkg if ref $pkg;
363 my $val = "${pkg}::valid";
364 my @out = keys %$val;
365 push @out, keys %valid;
370 # return a prompt for a field
375 my ($self, $ele) = @_;
377 my $val = "${pkg}::valid";
378 return $val->{$ele} || $valid{$ele};
382 # generic AUTOLOAD for accessors
387 my $name = $AUTOLOAD;
388 return if $name =~ /::DESTROY$/;
391 confess "Non-existant field '$AUTOLOAD'" if !$valid{$name};
393 # this clever line of code creates a subroutine which takes over from autoload
394 # from OO Perl - Conway
395 *{$AUTOLOAD} = sub {@_ > 1 ? $_[0]->{$name} = $_[1] : $_[0]->{$name}};