Sorted out exports and added new shared memory functions.
git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@1716 e3e1d417-86f3-4887-817a-d78f3d33393fpull/27/merge
parent
c49d7191a1
commit
3aff14ed63
|
@ -29,11 +29,11 @@ use strict;
|
|||
use warnings;
|
||||
|
||||
require Exporter;
|
||||
use ZoneMinder::Base;
|
||||
use ZoneMinder::Config;
|
||||
use ZoneMinder::Debug;
|
||||
use ZoneMinder::Database;
|
||||
use ZoneMinder::SharedMem;
|
||||
use ZoneMinder::Base qw(:all);
|
||||
use ZoneMinder::Config qw(:all);
|
||||
use ZoneMinder::Debug qw(:all);
|
||||
use ZoneMinder::Database qw(:all);
|
||||
use ZoneMinder::SharedMem qw(:all);
|
||||
|
||||
our @ISA = qw(Exporter ZoneMinder::Base ZoneMinder::Config ZoneMinder::Debug ZoneMinder::Database ZoneMinder::SharedMem);
|
||||
|
||||
|
@ -44,19 +44,28 @@ our @ISA = qw(Exporter ZoneMinder::Base ZoneMinder::Config ZoneMinder::Debug Zon
|
|||
# This allows declaration use ZoneMinder ':all';
|
||||
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
|
||||
# will save memory.
|
||||
our %EXPORT_TAGS = ( 'all' => [ qw(
|
||||
|
||||
) ] );
|
||||
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
|
||||
our @EXPORT = (
|
||||
@ZoneMinder::Base::EXPORT,
|
||||
@ZoneMinder::Debug::EXPORT,
|
||||
@ZoneMinder::Config::EXPORT,
|
||||
@ZoneMinder::Database::EXPORT,
|
||||
@ZoneMinder::SharedMem::EXPORT
|
||||
our %EXPORT_TAGS = (
|
||||
'base' => [
|
||||
@ZoneMinder::Base::EXPORT_OK
|
||||
],
|
||||
'debug' => [
|
||||
@ZoneMinder::Debug::EXPORT_OK
|
||||
],
|
||||
'config' => [
|
||||
@ZoneMinder::Config::EXPORT_OK
|
||||
],
|
||||
'database' => [
|
||||
@ZoneMinder::Database::EXPORT_OK
|
||||
],
|
||||
'sharedmem' => [
|
||||
@ZoneMinder::SharedMem::EXPORT_OK
|
||||
],
|
||||
);
|
||||
push( @{$EXPORT_TAGS{all}}, @{$EXPORT_TAGS{$_}} ) foreach keys %EXPORT_TAGS;
|
||||
|
||||
our @EXPORT_OK = @{ $EXPORT_TAGS{'all'} };
|
||||
|
||||
our @EXPORT = ( @EXPORT_OK );
|
||||
|
||||
our $VERSION = $ZoneMinder::Base::VERSION;
|
||||
|
||||
|
|
|
@ -40,15 +40,19 @@ our @ISA = qw(Exporter ZoneMinder::Base);
|
|||
# This allows declaration use ZoneMinder ':all';
|
||||
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
|
||||
# will save memory.
|
||||
our %EXPORT_TAGS = ( 'all' => [ qw(
|
||||
|
||||
) ] );
|
||||
our @EXPORT_CONFIG; # Get populated by BEGIN
|
||||
|
||||
our %EXPORT_TAGS = (
|
||||
'constants' => [ qw(
|
||||
ZM_PID
|
||||
) ]
|
||||
);
|
||||
push( @{$EXPORT_TAGS{config}}, @EXPORT_CONFIG );
|
||||
push( @{$EXPORT_TAGS{all}}, @{$EXPORT_TAGS{$_}} ) foreach keys %EXPORT_TAGS;
|
||||
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
|
||||
our @EXPORT = qw();
|
||||
our @EXPORT_CONFIG; # Get populated by BEGIN
|
||||
push( @EXPORT, @EXPORT_CONFIG );
|
||||
|
||||
our $VERSION = $ZoneMinder::Base::VERSION;
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ our $VERSION = $ZoneMinder::Base::VERSION;
|
|||
#
|
||||
# ==========================================================================
|
||||
|
||||
use ZoneMinder::Config;
|
||||
use ZoneMinder::Config qw(:all);
|
||||
|
||||
our $config_header = "src/zm_config_defines.h";
|
||||
our $config_sql = "db/zm_config.sql";
|
||||
|
|
|
@ -56,8 +56,8 @@ our $VERSION = $ZoneMinder::Base::VERSION;
|
|||
#
|
||||
# ==========================================================================
|
||||
|
||||
use ZoneMinder::Debug;
|
||||
use ZoneMinder::Config;
|
||||
use ZoneMinder::Debug qw(:all);
|
||||
use ZoneMinder::Config qw(:all);
|
||||
|
||||
our $dbh = undef;
|
||||
|
||||
|
|
|
@ -40,20 +40,28 @@ our @ISA = qw(Exporter ZoneMinder::Base);
|
|||
# This allows declaration use ZoneMinder ':all';
|
||||
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
|
||||
# will save memory.
|
||||
our %EXPORT_TAGS = ( 'all' => [ qw(
|
||||
|
||||
) ] );
|
||||
our %EXPORT_TAGS = (
|
||||
'constants' => [ qw(
|
||||
DBG_DEBUG
|
||||
DBG_INFO
|
||||
DBG_WARNING
|
||||
DBG_ERROR
|
||||
DBG_FATAL
|
||||
) ],
|
||||
'functions' => [ qw(
|
||||
zmDbgInit
|
||||
Debug
|
||||
Info
|
||||
Warning
|
||||
Error
|
||||
Fatal
|
||||
) ]
|
||||
);
|
||||
push( @{$EXPORT_TAGS{all}}, @{$EXPORT_TAGS{$_}} ) foreach keys %EXPORT_TAGS;
|
||||
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
|
||||
our @EXPORT = qw(
|
||||
zmDbgInit
|
||||
Debug
|
||||
Info
|
||||
Warning
|
||||
Error
|
||||
Fatal
|
||||
);
|
||||
our @EXPORT = qw();
|
||||
|
||||
our $VERSION = $ZoneMinder::Base::VERSION;
|
||||
|
||||
|
@ -70,6 +78,12 @@ use Time::HiRes qw/gettimeofday/;
|
|||
|
||||
use constant CARP_DEBUG => 0;
|
||||
|
||||
use constant DBG_DEBUG => 1;
|
||||
use constant DBG_INFO => 0;
|
||||
use constant DBG_WARNING => -1;
|
||||
use constant DBG_ERROR => -2;
|
||||
use constant DBG_FATAL => -3;
|
||||
|
||||
our $dbg_initialised = undef;
|
||||
our $dbg_id = "zm?";
|
||||
our $dbg_level = 0;
|
||||
|
@ -135,30 +149,30 @@ sub dbgPrint
|
|||
|
||||
sub Debug
|
||||
{
|
||||
dbgPrint( "DBG", $_[0] ) if ( $dbg_level >= 1 );
|
||||
dbgPrint( "DBG", $_[0] ) if ( $dbg_level >= DBG_DEBUG );
|
||||
}
|
||||
|
||||
sub Info
|
||||
{
|
||||
dbgPrint( "INF", $_[0] ) if ( $dbg_level >= 0 );
|
||||
dbgPrint( "INF", $_[0] ) if ( $dbg_level >= DBG_INFO );
|
||||
syslog( "info", "INF [%s]", $_[0] );
|
||||
}
|
||||
|
||||
sub Warning
|
||||
{
|
||||
dbgPrint( "WAR", $_[0] ) if ( $dbg_level >= -1 );
|
||||
dbgPrint( "WAR", $_[0] ) if ( $dbg_level >= DBG_WARNING );
|
||||
syslog( "warning", "WAR [%s]", $_[0] );
|
||||
}
|
||||
|
||||
sub Error
|
||||
{
|
||||
dbgPrint( "ERR", $_[0] ) if ( $dbg_level >= -2 );
|
||||
dbgPrint( "ERR", $_[0] ) if ( $dbg_level >= DBG_ERROR );
|
||||
syslog( "err", "ERR [%s]", $_[0] );
|
||||
}
|
||||
|
||||
sub Fatal
|
||||
{
|
||||
dbgPrint( "FAT", $_[0] ) if ( $dbg_level >= -3 );
|
||||
dbgPrint( "FAT", $_[0] ) if ( $dbg_level >= DBG_FATAL );
|
||||
syslog( "err", "ERR [%s]", $_[0] );
|
||||
confess( $_[0] );
|
||||
}
|
||||
|
|
|
@ -40,9 +40,43 @@ our @ISA = qw(Exporter ZoneMinder::Base);
|
|||
# This allows declaration use ZoneMinder ':all';
|
||||
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
|
||||
# will save memory.
|
||||
our %EXPORT_TAGS = ( 'all' => [ qw(
|
||||
|
||||
) ] );
|
||||
our %EXPORT_TAGS = (
|
||||
'constants' => [ qw(
|
||||
STATE_IDLE
|
||||
STATE_PREALARM
|
||||
STATE_ALARM
|
||||
STATE_ALERT
|
||||
STATE_TAPE
|
||||
ACTION_GET
|
||||
ACTION_SET
|
||||
ACTION_SUSPEND
|
||||
ACTION_RESUME
|
||||
TRIGGER_CANCEL
|
||||
TRIGGER_ON
|
||||
TRIGGER_OFF
|
||||
) ],
|
||||
'functions' => [ qw(
|
||||
zmShmGet
|
||||
zmShmVerify
|
||||
zmShmRead
|
||||
zmShmWrite
|
||||
zmGetMonitorState
|
||||
zmGetLastEventId
|
||||
zmGetAlarmLocation
|
||||
zmIsAlarmed
|
||||
zmInAlarm
|
||||
zmHasAlarmed
|
||||
zmGetLastImageTime
|
||||
zmGetMonitorActions
|
||||
zmMonitorSuspend
|
||||
zmMonitorResume
|
||||
zmTriggerEventOn
|
||||
zmTriggerEventOff
|
||||
zmTriggerEventCancel
|
||||
zmTriggerShowtext
|
||||
) ],
|
||||
);
|
||||
push( @{$EXPORT_TAGS{all}}, @{$EXPORT_TAGS{$_}} ) foreach keys %EXPORT_TAGS;
|
||||
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
|
||||
|
@ -56,8 +90,8 @@ our $VERSION = $ZoneMinder::Base::VERSION;
|
|||
#
|
||||
# ==========================================================================
|
||||
|
||||
use ZoneMinder::Config;
|
||||
use ZoneMinder::Debug;
|
||||
use ZoneMinder::Config qw(:all);
|
||||
use ZoneMinder::Debug qw(:all);
|
||||
|
||||
use constant STATE_IDLE => 0;
|
||||
use constant STATE_PREALARM => 1;
|
||||
|
@ -125,6 +159,7 @@ sub zmShmGet( $ )
|
|||
$monitor->{ShmId} = $shm_id;
|
||||
zmShmVerify( $monitor );
|
||||
}
|
||||
return( !undef );
|
||||
}
|
||||
|
||||
sub zmShmVerify( $ )
|
||||
|
@ -139,16 +174,17 @@ sub zmShmVerify( $ )
|
|||
if ( $sd_size != $shm_data->{shared_data}->{size} )
|
||||
{
|
||||
Error( "Shared memory size conflict in shared_data, expected ".$shm_data->{shared_data}->{size}.", got ".$sd_size );
|
||||
return;
|
||||
return( undef );
|
||||
}
|
||||
my $td_size = zmShmRead( $monitor, "trigger_data:size" );
|
||||
if ( $td_size != $shm_data->{trigger_data}->{size} )
|
||||
{
|
||||
Error( "Shared memory size conflict in trigger_data, expected ".$shm_data->{triggger_data}->{size}.", got ".$td_size );
|
||||
return;
|
||||
return( undef );
|
||||
}
|
||||
$shm_verified->{$shm_key} = !undef;
|
||||
}
|
||||
return( !undef );
|
||||
}
|
||||
|
||||
sub zmShmRead( $$ )
|
||||
|
@ -156,7 +192,11 @@ sub zmShmRead( $$ )
|
|||
my $monitor = shift;
|
||||
my $fields = shift;
|
||||
|
||||
zmShmGet( $monitor );
|
||||
if ( !zmShmGet( $monitor ) )
|
||||
{
|
||||
return( undef );
|
||||
}
|
||||
|
||||
my $shm_key = $monitor->{ShmKey};
|
||||
my $shm_id = $monitor->{ShmId};
|
||||
|
||||
|
@ -178,6 +218,7 @@ sub zmShmRead( $$ )
|
|||
if ( !shmread( $shm_id, $data, $offset, $size ) )
|
||||
{
|
||||
Error( "Can't read '$field' from shared memory '$shm_key/$shm_id': $!" );
|
||||
return( undef );
|
||||
}
|
||||
|
||||
my $value;
|
||||
|
@ -211,7 +252,11 @@ sub zmShmWrite( $$ )
|
|||
my $monitor = shift;
|
||||
my $field_values_ref = shift;
|
||||
|
||||
zmShmGet( $monitor );
|
||||
if ( !zmShmGet( $monitor ) )
|
||||
{
|
||||
return( undef );
|
||||
}
|
||||
|
||||
my $shm_key = $monitor->{ShmKey};
|
||||
my $shm_id = $monitor->{ShmId};
|
||||
|
||||
|
@ -250,9 +295,10 @@ sub zmShmWrite( $$ )
|
|||
if ( !shmwrite( $shm_id, $data, $offset, $size ) )
|
||||
{
|
||||
Error( "Can't write value '$value' to '$field' in shared memory '$shm_key/$shm_id': $!" );
|
||||
return( undef );
|
||||
}
|
||||
|
||||
}
|
||||
return( !undef );
|
||||
}
|
||||
|
||||
sub zmGetMonitorState( $ )
|
||||
|
@ -312,6 +358,13 @@ sub zmHasAlarmed( $$ )
|
|||
return( undef );
|
||||
}
|
||||
|
||||
sub zmGetLastImageTime( $ )
|
||||
{
|
||||
my $monitor = shift;
|
||||
|
||||
return( zmShmRead( $monitor, "shared_data:last_image_time" ) );
|
||||
}
|
||||
|
||||
sub zmGetMonitorActions( $ )
|
||||
{
|
||||
my $monitor = shift;
|
||||
|
@ -337,7 +390,14 @@ sub zmMonitorResume( $ )
|
|||
zmShmWrite( $monitor, { "shared_data:action" => $action } );
|
||||
}
|
||||
|
||||
sub zmTriggerEventOn( $$$$;$ )
|
||||
sub zmGetTriggerState( $ )
|
||||
{
|
||||
my $monitor = shift;
|
||||
|
||||
return( zmShmRead( $monitor, "trigger_data:trigger_state" ) );
|
||||
}
|
||||
|
||||
sub zmTriggerEventOn( $$$;$$ )
|
||||
{
|
||||
my $monitor = shift;
|
||||
my $score = shift;
|
||||
|
@ -348,14 +408,10 @@ sub zmTriggerEventOn( $$$$;$ )
|
|||
my @values = (
|
||||
( "trigger_data:trigger_score" => $score ),
|
||||
( "trigger_data:trigger_cause" => $cause ),
|
||||
( "trigger_data:trigger_text" => $text ),
|
||||
( "trigger_data:trigger_state" => TRIGGER_ON ), # Write state last so event not read incomplete
|
||||
);
|
||||
|
||||
if ( defined($showtext) )
|
||||
{
|
||||
push( @values, ( "trigger_data:trigger_showtext" => $showtext ) );
|
||||
}
|
||||
push( @values, ( "trigger_data:trigger_text" => $text ) ) if ( defined($text) );
|
||||
push( @values, ( "trigger_data:trigger_showtext" => $showtext ) ) if ( defined($showtext) );
|
||||
push( @values, ( "trigger_data:trigger_state" => TRIGGER_ON ) ); # Write state last so event not read incomplete
|
||||
|
||||
zmShmWrite( $monitor, \@values );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue