From fd0a44e81640e93bb67f1755134236cbca1a0dfe Mon Sep 17 00:00:00 2001 From: stan Date: Thu, 16 Nov 2006 11:32:56 +0000 Subject: [PATCH] Merged in changes for enhanced triggers and showtext. git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@2061 e3e1d417-86f3-4887-817a-d78f3d33393f --- .../ZoneMinder/lib/ZoneMinder/SharedMem.pm | 2 +- .../lib/ZoneMinder/Trigger/Connection.pm | 4 ++ .../ZoneMinder/Trigger/Connection/Example.pm | 2 +- scripts/zmtrigger.pl | 49 +++++++++++++++++-- 4 files changed, 50 insertions(+), 7 deletions(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/SharedMem.pm b/scripts/ZoneMinder/lib/ZoneMinder/SharedMem.pm index 96a505a2e..3c5b94344 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/SharedMem.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/SharedMem.pm @@ -147,7 +147,7 @@ our $shm_data = "trigger_score" => { "type"=>"int", "seq"=>$shm_seq++ }, "trigger_cause" => { "type"=>"char[32]", "seq"=>$shm_seq++ }, "trigger_text" => { "type"=>"char[256]", "seq"=>$shm_seq++ }, - "trigger_showtext" => { "type"=>"char[32]", "seq"=>$shm_seq++ }, + "trigger_showtext" => { "type"=>"char[256]", "seq"=>$shm_seq++ }, } }, "end" => { "seq"=>$shm_seq++, "size"=> 0 } diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Trigger/Connection.pm b/scripts/ZoneMinder/lib/ZoneMinder/Trigger/Connection.pm index 7f31bb8ad..7b6a68f74 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Trigger/Connection.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Trigger/Connection.pm @@ -151,6 +151,10 @@ sub putMessages return( undef ); } +sub timedActions +{ +} + sub DESTROY { } diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Trigger/Connection/Example.pm b/scripts/ZoneMinder/lib/ZoneMinder/Trigger/Connection/Example.pm index 69cec51d8..deae64e42 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Trigger/Connection/Example.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Trigger/Connection/Example.pm @@ -46,7 +46,7 @@ sub new { my $class = shift; my $path = shift; - my $self = (ZoneMinder::Trigger::Connection->new( @_ ); + my $self = ZoneMinder::Trigger::Connection->new( @_ ); bless( $self, $class ); return $self; } diff --git a/scripts/zmtrigger.pl b/scripts/zmtrigger.pl index 671df50e7..e729e2eb2 100644 --- a/scripts/zmtrigger.pl +++ b/scripts/zmtrigger.pl @@ -59,9 +59,9 @@ push( @connections, ZoneMinder::Trigger::Connection->new( name=>"Chan4", channel use ZoneMinder; use DBI; -use POSIX; #use Socket; use Data::Dumper; +use Time::HiRes qw( usleep ); $| = 1; @@ -248,6 +248,30 @@ while( 1 ) delete( $actions{$action_time} ); } + # Allow connections to do their own timed actions + foreach my $connection ( @connections ) + { + my $messages = $connection->timedActions(); + if ( defined($messages) ) + { + foreach my $message ( @$messages ) + { + handleMessage( $connection, $message ); + } + } + } + foreach my $connection ( values(%spawned_connections) ) + { + my $messages = $connection->timedActions(); + if ( defined($messages) ) + { + foreach my $message ( @$messages ) + { + handleMessage( $connection, $message ); + } + } + } + # If necessary reload monitors if ( (time() - $monitor_reload_time) > MONITOR_RELOAD_INTERVAL ) { @@ -351,13 +375,28 @@ sub handleMessage if ( $trigger eq "on" ) { zmTriggerEventOn( $monitor, $score, $cause, $text ); + zmTriggerShowtext( $monitor, $showtext ) if defined($showtext); + Info( "Trigger '$trigger' '$cause'\n" ); + } + elsif ( $trigger eq "off" ) + { + my $last_event = zmGetLastEvent( $monitor ); + zmTriggerEventOff( $monitor ); + zmTriggerShowtext( $monitor, $showtext ) if defined($showtext); + Info( "Trigger '$trigger'\n" ); + # Wait til it's finished + while( zmInAlarm( $monitor ) && ($last_event == zmGetLastEvent( $monitor )) ) + { + # Tenth of a second + usleep( 100000 ); + } + zmTriggerEventCancel( $monitor ); } else { - zmTriggerEventOff( $monitor ); + Info( "Trigger '$trigger'\n" ); + zmTriggerEventCancel( $monitor ); } - zmTriggerShowtext( $monitor, $showtext ) if defined($showtext); - Info( "Triggered event '$trigger' '$cause'\n" ); if ( $delay ) { my $action_time = time()+$delay; @@ -376,7 +415,7 @@ sub handleMessage { zmTriggerEventCancel( $monitor ); zmTriggerShowtext( $monitor, $showtext ) if defined($showtext); - Info( "Cancelled event '$cause'\n" ); + Info( "Cancelled event\n" ); } elsif( $action eq "show" ) {