X-Git-Url: http://www.dxcluster.org/gitweb/gitweb.cgi?p=spider.git;a=blobdiff_plain;f=perl%2FDXCluster.pm;h=9560ba576a5b131132c9ef26a5ab455946449f2b;hp=b61cb3411da12f62ace223e5da883fc40116f917;hb=21e7642d216656c60b164d76208633a0c81cf5db;hpb=8cc3ac88ee6ba2216a9f19761385c9869a2f91b1 diff --git a/perl/DXCluster.pm b/perl/DXCluster.pm index b61cb341..9560ba57 100644 --- a/perl/DXCluster.pm +++ b/perl/DXCluster.pm @@ -16,24 +16,27 @@ package DXCluster; use Exporter; @ISA = qw(Exporter); +use Carp; +use DXDebug; use strict; my %cluster = (); # this is where we store the dxcluster database my %valid = ( - mynode => '0,Parent Node', + 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, $dxchan) = @_; + my ($pkg, $dxchan, $call, $confmode, $here) = @_; die "$call is already alloced" if $cluster{$call}; my $self = {}; $self->{call} = $call; @@ -72,9 +75,33 @@ 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; @@ -86,7 +113,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} ; } @@ -98,29 +125,39 @@ package DXNodeuser; @ISA = qw(DXCluster); +use DXDebug; + use strict; -my %users = (); +my $users = 0; sub new { - my ($pkg, $mynode, $call, $confmode, $here, $dxchan) = @_; - my $self = $pkg->alloc($call, $confmode, $here, $dxchan); - $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; + $self->{list}->{$call} = $self; # add this user to the list on this node + $users++; + dbg('cluster', "allocating user $self->{call}\n"); return $self; } 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 $cluster{$call}; # remove me from the cluster table + $users-- if $users > 0; } sub count { - return %users + 1; # + 1 for ME (naf eh!) + return $users; # + 1 for ME (naf eh!) } no strict; @@ -133,31 +170,28 @@ package DXNode; @ISA = qw(DXCluster); +use DXDebug; + use strict; -my %nodes = (); +my $nodes = 0; sub new { - my ($pkg, $call, $confmode, $here, $pcversion, $dxchan) = @_; - my $self = $pkg->alloc($call, $confmode, $here, $dxchan); + my ($pkg, $dxchan, $call, $confmode, $here, $pcversion) = @_; + my $self = $pkg->alloc($dxchan, $call, $confmode, $here); $self->{version} = $pcversion; - $nodes{$call} = $self; + $self->{list} = { } ; + $nodes++; + dbg('cluster', "allocating node $self->{call}\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)) { + foreach $list (values(%cluster)) { push @out, $list if $list->{pcversion}; } return @out; @@ -166,15 +200,29 @@ sub get_all sub del { my $self = shift; - my $call = $self->call; - - DXUser->delete($call); # delete all the users on 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 + } + $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