X-Git-Url: http://www.dxcluster.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXCluster.pm;h=6daf65a3874a5ebfd29ba8326e45b13b733854d0;hb=cce345b95c555a0b45218c5b452bc0f5f4f13bab;hp=9560ba576a5b131132c9ef26a5ab455946449f2b;hpb=21e7642d216656c60b164d76208633a0c81cf5db;p=spider.git diff --git a/perl/DXCluster.pm b/perl/DXCluster.pm index 9560ba57..6daf65a3 100644 --- a/perl/DXCluster.pm +++ b/perl/DXCluster.pm @@ -16,14 +16,15 @@ package DXCluster; use Exporter; @ISA = qw(Exporter); -use Carp; use DXDebug; +use Carp; use strict; +use vars qw(%cluster %valid); -my %cluster = (); # this is where we store the dxcluster database +%cluster = (); # this is where we store the dxcluster database -my %valid = ( +%valid = ( mynode => '0,Parent Node,showcall', call => '0,Callsign', confmode => '0,Conference Mode,yesno', @@ -61,13 +62,6 @@ sub get_all return values(%cluster); } -sub delcluster; -{ - my $self = shift; - delete $cluster{$self->{call}}; -} - - # return a prompt for a field sub field_prompt { @@ -98,6 +92,15 @@ sub showcall return $self->{call}; } +# the answer required by show/cluster +sub cluster +{ + my $users = DXCommandmode::get_all(); + my $uptime = main::uptime(); + + return " $DXNode::nodes nodes, $users local / $DXNode::users total users Max users $DXNode::maxusers Uptime $uptime"; +} + sub DESTROY { my $self = shift; @@ -128,7 +131,6 @@ package DXNodeuser; use DXDebug; use strict; -my $users = 0; sub new { @@ -138,9 +140,9 @@ sub new 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"); + $node->{list}->{$call} = $self; # add this user to the list on this node + dbg('cluster', "allocating user $call to $node->{call} in cluster\n"); + $node->update_users; return $self; } @@ -149,15 +151,16 @@ sub del my $self = shift; 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; + delete $DXCluster::cluster{$call}; # remove me from the cluster table + dbg('cluster', "deleting user $call from $node->{call} in cluster\n"); + $node->update_users; } sub count { - return $users; # + 1 for ME (naf eh!) + return $DXNode::users; # + 1 for ME (naf eh!) } no strict; @@ -173,16 +176,21 @@ package DXNode; use DXDebug; use strict; -my $nodes = 0; +use vars qw($nodes $users $maxusers); + +$nodes = 0; +$users = 0; +$maxusers = 0; + sub new { my ($pkg, $dxchan, $call, $confmode, $here, $pcversion) = @_; my $self = $pkg->alloc($dxchan, $call, $confmode, $here); - $self->{version} = $pcversion; + $self->{pcversion} = $pcversion; $self->{list} = { } ; $nodes++; - dbg('cluster', "allocating node $self->{call}\n"); + dbg('cluster', "allocating node $call to cluster\n"); return $self; } @@ -191,7 +199,7 @@ sub get_all { my $list; my @out; - foreach $list (values(%cluster)) { + foreach $list (values(%DXCluster::cluster)) { push @out, $list if $list->{pcversion}; } return @out; @@ -207,17 +215,23 @@ sub del foreach $ref (values %{$self->{list}}) { $ref->del(); # this also takes them out of this list } + delete $DXCluster::cluster{$call}; # remove me from the cluster table + 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}}; + my $count = shift; + $users -= $self->{users}; + if ((keys %{$self->{list}})) { + $self->{users} = (keys %{$self->{list}}); } else { - $self->{users} = shift; + $self->{users} = $count; } + $users += $self->{users}; + $maxusers = $users+$nodes if $users+$nodes > $maxusers; } sub count