2 # DX database control routines
4 # This manages the on-line cluster user 'database'
6 # This should all be pretty trees and things, but for now I
7 # just can't be bothered. If it becomes an issue I shall
10 # Copyright (c) 1998 - Dirk Koopman G1TLH
21 use vars qw(%cluster %valid);
23 %cluster = (); # this is where we store the dxcluster database
26 mynode => '0,Parent Node',
28 confmode => '0,Conference Mode,yesno',
29 here => '0,Here?,yesno',
30 dxchancall => '5,Channel Call',
31 pcversion => '5,Node Version',
32 list => '5,User List,DXCluster::dolist',
33 users => '0,No of Users',
36 use vars qw($VERSION $BRANCH);
37 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
38 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ ) || 0;
39 $main::build += $VERSION;
40 $main::branch += $BRANCH;
44 my ($pkg, $dxchan, $call, $confmode, $here) = @_;
45 die "$call is already alloced" if $cluster{$call};
47 $self->{call} = $call;
48 $self->{confmode} = $confmode;
49 $self->{here} = $here;
50 $self->{dxchancall} = $dxchan->call;
52 $cluster{$call} = bless $self, $pkg;
56 # get an entry exactly as it is
59 my ($pkg, $call) = @_;
64 # search for 'as is' only
65 return $cluster{$call};
69 # search for a call in the cluster
70 # taking into account SSIDs
74 my ($pkg, $call) = @_;
80 my $ref = $cluster{$call};
83 # search for the unSSIDed one
85 $ref = $cluster{$call};
88 # search for the SSIDed one
90 for ($i = 1; $i < 17; $i++) {
91 $ref = $cluster{"$call-$i"};
100 return values(%cluster);
103 # return a prompt for a field
106 my ($self, $ele) = @_;
110 # return a list of valid elements
118 # this expects a reference to a list in a node NOT a ref to a node
125 foreach my $call (keys %{$self}) {
126 $ref = $$self{$call};
127 my $s = $ref->{call};
128 $s = "($s)" if !$ref->{here};
135 # this expects a reference to a node
139 return $self->{call};
142 # the answer required by show/cluster
145 my $users = DXCommandmode::get_all();
146 my $uptime = main::uptime();
147 my $tot = $DXNode::users;
149 return " $DXNode::nodes nodes, $users local / $tot total users Max users $DXNode::maxusers Uptime $uptime";
158 $self->{mynode} = $noderef->call;
160 $noderef = DXCluster->get_exact($self->{mynode});
162 my $mynode = $self->{mynode};
163 my $call = $self->{call};
164 dbg("parent node $mynode has disappeared from $call") if isdbg('err');
176 $self->{dxchancall} = $dxchan->call;
178 $dxchan = DXChannel->get($self->{dxchancall});
180 my $dxcall = $self->{dxchancall};
181 my $call = $self->{call};
182 dbg("parent dxchan $dxcall has disappeared from $call") if isdbg('err');
192 my $name = $AUTOLOAD;
194 return if $name =~ /::DESTROY$/;
197 confess "Non-existant field '$AUTOLOAD'" if !$valid{$name};
198 # this clever line of code creates a subroutine which takes over from autoload
199 # from OO Perl - Conway
200 *{$AUTOLOAD} = sub {@_ > 1 ? $_[0]->{$name} = $_[1] : $_[0]->{$name}} ;
201 @_ ? $self->{$name} = shift : $self->{$name} ;
205 # USER special routines
210 @ISA = qw(DXCluster);
218 my ($pkg, $dxchan, $node, $call, $confmode, $here) = @_;
220 die "tried to add $call when it already exists" if DXCluster->get_exact($call);
222 my $self = $pkg->alloc($dxchan, $call, $confmode, $here);
223 $self->{mynode} = $node->call;
224 $node->add_user($call, $self);
225 dbg("allocating user $call to $node->{call} in cluster\n") if isdbg('cluster');
232 my $call = $self->{call};
233 my $node = $self->mynode;
235 $node->del_user($call);
236 dbg("deleting user $call from $node->{call} in cluster\n") if isdbg('cluster');
241 return $DXNode::users; # + 1 for ME (naf eh!)
247 # NODE special routines
252 @ISA = qw(DXCluster);
257 use vars qw($nodes $users $maxusers);
266 my ($pkg, $dxchan, $call, $confmode, $here, $pcversion) = @_;
267 my $self = $pkg->alloc($dxchan, $call, $confmode, $here);
268 $self->{pcversion} = $pcversion;
269 $self->{list} = { } ;
270 $self->{mynode} = $self->call; # for sh/station
273 dbg("allocating node $call to cluster\n") if isdbg('cluster');
282 foreach $list (values(%DXCluster::cluster)) {
283 push @out, $list if $list->{pcversion};
291 my $call = $self->{call};
294 # delete all the listed calls
295 foreach $ref (values %{$self->{list}}) {
296 $ref->del(); # this also takes them out of this list
298 delete $DXCluster::cluster{$call}; # remove me from the cluster table
299 dbg("deleting node $call from cluster\n") if isdbg('cluster');
300 $users -= $self->{users}; # it may be PC50 updated only therefore > 0
301 $users = 0 if $users < 0;
303 $nodes = 0 if $nodes < 0;
312 $self->{list}->{$call} = $ref; # add this user to the list on this node
313 $self->{users} = keys %{$self->{list}};
315 $maxusers = $users+$nodes if $users+$nodes > $maxusers;
323 delete $self->{list}->{$call};
324 delete $DXCluster::cluster{$call}; # remove me from the cluster table
325 $self->{users} = keys %{$self->{list}};
327 $users = 0, warn "\$users gone neg, reset" if $users < 0;
328 $maxusers = $users+$nodes if $users+$nodes > $maxusers;
335 $count = 0 unless $count;
337 $users -= $self->{users};
338 $self->{users} = $count unless keys %{$self->{list}};
339 $users += $self->{users};
340 $maxusers = $users+$nodes if $users+$nodes > $maxusers;
345 return $nodes; # + 1 for ME!
356 undef $self->{list} if $self->{list};