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
23 use vars qw(%cluster %valid);
25 %cluster = (); # this is where we store the dxcluster database
28 mynode => '0,Parent Node,showcall',
30 confmode => '0,Conference Mode,yesno',
31 here => '0,Here?,yesno',
32 dxchan => '5,Channel ref',
33 pcversion => '5,Node Version',
34 list => '5,User List,dolist',
35 users => '0,No of Users',
40 my ($pkg, $dxchan, $call, $confmode, $here) = @_;
41 die "$call is already alloced" if $cluster{$call};
43 $self->{call} = $call;
44 $self->{confmode} = $confmode;
45 $self->{here} = $here;
46 $self->{dxchan} = $dxchan;
48 $cluster{$call} = bless $self, $pkg;
52 # search for a call in the cluster
55 my ($pkg, $call) = @_;
56 return $cluster{$call};
62 return values(%cluster);
65 # return a prompt for a field
68 my ($self, $ele) = @_;
72 # this expects a reference to a list in a node NOT a ref to a node
79 foreach $ref (@{$self}) {
81 $s = "($s)" if !$ref->{here};
88 # this expects a reference to a node
98 dbg('cluster', "destroying $self->{call}\n");
105 my $name = $AUTOLOAD;
107 return if $name =~ /::DESTROY$/;
110 confess "Non-existant field '$AUTOLOAD'" if !$valid{$name};
111 @_ ? $self->{$name} = shift : $self->{$name} ;
115 # USER special routines
120 @ISA = qw(DXCluster);
131 my ($pkg, $dxchan, $node, $call, $confmode, $here) = @_;
133 die "tried to add $call when it already exists" if DXCluster->get($call);
135 my $self = $pkg->alloc($dxchan, $call, $confmode, $here);
136 $self->{mynode} = $node;
137 $node->{list}->{$call} = $self; # add this user to the list on this node
139 dbg('cluster', "allocating user $call to $node->{call} in cluster\n");
147 my $call = $self->{call};
148 my $node = $self->{mynode};
150 delete $node->{list}->{$call};
151 delete $DXCluster::cluster{$call}; # remove me from the cluster table
152 dbg('cluster', "deleting user $call from $node->{call} in cluster\n");
154 $users-- if $users > 0;
159 return $users; # + 1 for ME (naf eh!)
165 # NODE special routines
170 @ISA = qw(DXCluster);
181 my ($pkg, $dxchan, $call, $confmode, $here, $pcversion) = @_;
182 my $self = $pkg->alloc($dxchan, $call, $confmode, $here);
183 $self->{pcversion} = $pcversion;
184 $self->{list} = { } ;
186 dbg('cluster', "allocating node $call to cluster\n");
195 foreach $list (values(%DXCluster::cluster)) {
196 push @out, $list if $list->{pcversion};
204 my $call = $self->{call};
207 # delete all the listed calls
208 foreach $ref (values %{$self->{list}}) {
209 $ref->del(); # this also takes them out of this list
211 delete $DXCluster::cluster{$call}; # remove me from the cluster table
212 dbg('cluster', "deleting node $call from cluster\n");
213 $nodes-- if $nodes > 0;
220 if ((keys %{$self->{list}})) {
221 $self->{users} = (keys %{$self->{list}});
223 $self->{users} = $count;
229 return $nodes; # + 1 for ME!