X-Git-Url: http://www.dxcluster.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXCluster.pm;h=2ddd2358648f28616c2c8f2f197bce61303e9d4a;hb=7432cb12ce865030c8b0315a30764e0088a59102;hp=2dad1cb61ffb42c87b74149827ca45e93a05cdd6;hpb=07ea293f3919d2da76220b5fbc55b734008ed44c;p=spider.git diff --git a/perl/DXCluster.pm b/perl/DXCluster.pm index 2dad1cb6..2ddd2358 100644 --- a/perl/DXCluster.pm +++ b/perl/DXCluster.pm @@ -16,18 +16,34 @@ package DXCluster; use Exporter; @ISA = qw(Exporter); +use Carp; +use DXDebug; + +use strict; +use vars qw(%cluster %valid); %cluster = (); # this is where we store the dxcluster database +%valid = ( + mynode => '0,Parent Node,showcall', + call => '0,Callsign', + confmode => '0,Conference Mode,yesno', + here => '0,Here?,yesno', + dxchan => '5,Channel ref', + pcversion => '5,Node Version', + list => '5,User List,dolist', + users => '0,No of Users', +); + sub alloc { - my ($pkg, $call, $confmode, $here, $dxprot) = @_; + my ($pkg, $dxchan, $call, $confmode, $here) = @_; die "$call is already alloced" if $cluster{$call}; my $self = {}; $self->{call} = $call; $self->{confmode} = $confmode; $self->{here} = $here; - $self->{dxprot} = $dxprot; + $self->{dxchan} = $dxchan; $cluster{$call} = bless $self, $pkg; return $self; @@ -46,21 +62,6 @@ sub get_all return values(%cluster); } -sub delcluster; -{ - my $self = shift; - delete $cluster{$self->{call}}; -} - -%valid = ( - mynode => '0,Parent Node', - call => '0,Callsign', - confmode => '5,Conference Mode,yesno', - here => '5,Here?,yesno', - dxprot => '5,Channel ref', - version => '5,Node Version', -); - # return a prompt for a field sub field_prompt { @@ -68,6 +69,36 @@ sub field_prompt return $valid{$ele}; } +# this expects a reference to a list in a node NOT a ref to a node +sub dolist +{ + my $self = shift; + my $out; + my $ref; + + foreach $ref (@{$self}) { + my $s = $ref->{call}; + $s = "($s)" if !$ref->{here}; + $out .= "$s "; + } + chop $out; + return $out; +} + +# this expects a reference to a node +sub showcall +{ + my $self = shift; + return $self->{call}; +} + +sub DESTROY +{ + my $self = shift; + dbg('cluster', "destroying $self->{call}\n"); +} + +no strict; sub AUTOLOAD { my $self = shift; @@ -76,7 +107,7 @@ sub AUTOLOAD return if $name =~ /::DESTROY$/; $name =~ s/.*:://o; - die "Non-existant field '$AUTOLOAD'" if !$valid{$name}; + confess "Non-existant field '$AUTOLOAD'" if !$valid{$name}; @_ ? $self->{$name} = shift : $self->{$name} ; } @@ -84,34 +115,48 @@ sub AUTOLOAD # USER special routines # -package DXUser; +package DXNodeuser; @ISA = qw(DXCluster); -%users = (); +use DXDebug; + +use strict; +my $users = 0; sub new { - my ($pkg, $mynode, $call, $confmode, $here, $dxprot) = @_; - my $self = $pkg->alloc($call, $confmode, $here, $dxprot); - $self->{mynode} = $mynode; + my ($pkg, $dxchan, $node, $call, $confmode, $here) = @_; - $users{$call} = $self; + die "tried to add $call when it already exists" if DXCluster->get($call); + + my $self = $pkg->alloc($dxchan, $call, $confmode, $here); + $self->{mynode} = $node; + $node->{list}->{$call} = $self; # add this user to the list on this node + $users++; + dbg('cluster', "allocating user $call to $node->{call} in cluster\n"); return $self; } -sub delete +sub del { my $self = shift; - $self->delcluster(); # out of the whole cluster table - delete $users{$self->{call}}; # out of the users table + my $call = $self->{call}; + my $node = $self->{mynode}; + + delete $node->{list}->{$call}; + delete $DXCluster::cluster{$call}; # remove me from the cluster table + dbg('cluster', "deleting user $call from $node->{call} in cluster\n"); + $users-- if $users > 0; } sub count { - return %users + 1; # + 1 for ME (naf eh!) + return $users; # + 1 for ME (naf eh!) } +no strict; + # # NODE special routines # @@ -120,47 +165,65 @@ package DXNode; @ISA = qw(DXCluster); -%nodes = (); +use DXDebug; + +use strict; +my $nodes = 0; sub new { - my ($pkg, $call, $confmode, $here, $version, $dxprot) = @_; - my $self = $pkg->alloc($call, $confmode, $here, $dxprot); - $self->{version} = $version; - $nodes{$call} = $self; + my ($pkg, $dxchan, $call, $confmode, $here, $pcversion) = @_; + my $self = $pkg->alloc($dxchan, $call, $confmode, $here); + $self->{version} = $pcversion; + $self->{list} = { } ; + $nodes++; + dbg('cluster', "allocating node $call to cluster\n"); return $self; } -# get a node -sub get -{ - my ($pkg, $call) = @_; - return $nodes{$call}; -} - # get all the nodes sub get_all { my $list; my @out; - foreach $list (values(%nodes)) { - push @out, $list if $list->{version}; + foreach $list (values(%DXCluster::cluster)) { + push @out, $list if $list->{pcversion}; } return @out; } -sub delete +sub del { my $self = shift; - my $call = $self->call; - - DXUser->delete($call); # delete all the users one this node - delete $nodes{$call}; + my $call = $self->{call}; + my $ref; + + # delete all the listed calls + foreach $ref (values %{$self->{list}}) { + $ref->del(); # this also takes them out of this list + } + dbg('cluster', "deleting node $call from cluster\n"); + $nodes-- if $nodes > 0; +} + +sub update_users +{ + my $self = shift; + if (%{$self->{list}}) { + $self->{users} = scalar %{$self->{list}}; + } else { + $self->{users} = shift; + } } sub count { - return %nodes + 1; # + 1 for ME! + return $nodes; # + 1 for ME! +} + +sub dolist +{ + } 1; __END__