1. first cut with new routing code. Created NEW_ROUTE branch
[spider.git] / perl / DXCron.pm
index d300779456931861463060bf80ed80779cb5bc58..39776dccde4094ccfe6814568c185e58ff77c187 100644 (file)
@@ -175,32 +175,43 @@ sub connected
 sub present
 {
        my $call = uc shift;
-       return DXCluster->get_exact($call);
+       return Route::get($call);
 }
 
 # is it remotely connected anywhere (ignoring SSIDS)?
 sub presentish
 {
        my $call = uc shift;
-       return DXCluster->get($call);
+       my $c = Route::get($call);
+       unless ($c) {
+               for (1..15) {
+                       $c = Route::get("$call-$_");
+                       last if $c;
+               }
+       }
+       return $c;
 }
 
 # is it remotely connected anywhere (with exact callsign) and on node?
 sub present_on
 {
        my $call = uc shift;
-       my $node = uc shift;
-       my $ref = DXCluster->get_exact($call);
-       return ($ref && $ref->mynode) ? $ref->mynode->call eq $node : undef;
+       my $ncall = uc shift;
+       my $node = Route::Node::get($ncall);
+       return ($node) ? grep $call eq $_, $node->users : undef;
 }
 
-# is it remotely connected anywhere (ignoring SSIDS) and on node?
+# is it remotely connected (ignoring SSIDS) and on node?
 sub presentish_on
 {
        my $call = uc shift;
-       my $node = uc shift;
-       my $ref = DXCluster->get($call);
-       return ($ref && $ref->mynode) ? $ref->mynode->call eq $node : undef;
+       my $ncall = uc shift;
+       my $node = Route::Node::get($ncall);
+       my $present;
+       if ($node) {
+               $present = grep {/^$call/ } $node->users;
+       }
+       return $present;
 }
 
 # last time this thing was connected
@@ -215,40 +226,16 @@ sub last_connect
 # disconnect a locally connected thing
 sub disconnect
 {
-       my $call = uc shift;
-       my $dxchan = DXChannel->get($call);
-       if ($dxchan) {
-               if ($dxchan->is_ak1a) {
-                       $dxchan->send_now("D", DXProt::pc39($main::mycall, "$main::mycall DXCron"));
-               } else {
-                       $dxchan->send_now('D', "");
-               } 
-               $dxchan->disconnect;
-       }
-       my $out = grep {$_->{call} eq $call} @main::outstanding_connects;
-       if ($out) {
-               unless ($^O =~ /^MS/i) {
-                       kill 'TERM', $out->{pid};
-               }
-               @main::outstanding_connects = grep {$_->{call} ne $call} @main::outstanding_connects;
-       }
+       my $call =  shift;
+       run_cmd("disconnect $call");
 }
 
 # start a connect process off
 sub start_connect
 {
-       my $call = uc shift;
-       my $lccall = lc $call;
-
-       if (grep {$_->{call} eq $call} @main::outstanding_connects) {
-               dbg('cron', "Connect not started, outstanding connect to $call");
-               return;
-       }
-       if (-e "$main::root/connect/$lccall") {
-               ExtMsg::start_connect($call, "$main::root/connect/$lccall");    
-       } else {
-               dbg('err', "Cannot find connect script for $lccall");
-       }
+       my $call = shift;
+       # connecting is now done in one place - Yeah!
+       run_cmd("connect $call");
 }
 
 # spawn any old job off
@@ -262,14 +249,14 @@ sub spawn
                        # in child, unset warnings, disable debugging and general clean up from us
                        $^W = 0;
                        eval "{ package DB; sub DB {} }";
-                       alarm(0);
                        DXChannel::closeall();
                        for (@main::listeners) {
                                $_->close_server;
                        }
-                       unless ($^O =~ /^MS/) {
+                       unless ($main::is_win) {
                                $SIG{HUP} = 'IGNORE';
                                $SIG{CHLD} = $SIG{TERM} = $SIG{INT} = $SIG{__WARN__} = 'DEFAULT';
+                               alarm(0);
                        }
                        exec "$line" or dbg('cron', "exec '$line' failed $!");
                }
@@ -289,11 +276,22 @@ sub rcmd
        my $line = shift;
 
        # can we see it? Is it a node?
-       my $noderef = DXCluster->get_exact($call);
-       return  if !$noderef || !$noderef->pcversion;
+       my $noderef = Route::Node::get($call);
+       return  unless $noderef && $noderef->version;
 
        # send it 
        DXProt::addrcmd($DXProt::me, $call, $line);
 }
+
+sub run_cmd
+{
+       my $line = shift;
+       my @in = DXCommandmode::run_cmd($DXProt::me, $line);
+       dbg('cron', "cmd run: $line");
+       for (@in) {
+               s/\s*$//og;
+               dbg('cron', "cmd out: $_");
+       }
+}
 1;
 __END__