From 9500f7a60a913dc6637d0150d687b5749148d959 Mon Sep 17 00:00:00 2001 From: markusbloch <> Date: Tue, 16 Jul 2013 18:58:40 +0000 Subject: [PATCH] implementing "now" command for instant testing git-svn-id: https://svn.fhem.de/fhem/trunk@3437 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/contrib/PRESENCE/presenced | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/fhem/contrib/PRESENCE/presenced b/fhem/contrib/PRESENCE/presenced index aee718bec..086484a2b 100755 --- a/fhem/contrib/PRESENCE/presenced +++ b/fhem/contrib/PRESENCE/presenced @@ -217,6 +217,21 @@ while(1) $child_handles{$client} = $new_thread; } + elsif(lc($buf) =~ /^\s*now\s*$/) + { + print timestamp()."received now command from client ".$client->peerhost()."\n" if($opt_v); + + if(defined($child_handles{$client})) + { + print timestamp()."signalling thread ".$child_handles{$client}->tid()." for an instant test for client ".$client->peerhos$ + $child_handles{$client}->kill('HUP'); + $client->send("command accepted\n"); + } + else + { + $client->send("no command running\n"); + } + } elsif(lc($buf) =~ /^\s*stop\s*$/) { print timestamp()."received stop command from client ".$client->peerhost()."\n" if($opt_v); @@ -319,6 +334,9 @@ local $SIG{KILL} = sub {threads->exit();}; my ($write_handle, $address, $timeout) = @_; my $return; my $hcitool; +my $nextrun = gettimeofday(); + +local $SIG{HUP} = sub {$nextrun = gettimeofday();}; if($address and $timeout) { @@ -326,6 +344,8 @@ my $hcitool; { if($write_handle) { + if($nextrun <= gettimeofday()) + { { lock($querylocker); if($querylocker gt (time() - 10)) @@ -354,7 +374,8 @@ my $hcitool; $write_handle->send("absence\n"); } - sleep $timeout; + $nextrun = gettimeofday() + $timeout; + } }