Merge pull request #816 from onlyjob/PBP

more perlcritic/PBP corrections
This commit is contained in:
Andrew Bauer 2015-04-16 20:26:35 -05:00
commit 3261d974f7
16 changed files with 145 additions and 139 deletions

View File

@ -72,8 +72,9 @@ BEGIN
print( STDERR "Warning, overriding installed $local_config_file file with local copy\n" ); print( STDERR "Warning, overriding installed $local_config_file file with local copy\n" );
$config_file = $local_config_file; $config_file = $local_config_file;
} }
open( CONFIG, "<".$config_file ) or croak( "Can't open config file '$config_file': $!" ); open( my $CONFIG, "<", $config_file )
foreach my $str ( <CONFIG> ) or croak( "Can't open config file '$config_file': $!" );
foreach my $str ( <$CONFIG> )
{ {
next if ( $str =~ /^\s*$/ ); next if ( $str =~ /^\s*$/ );
next if ( $str =~ /^\s*#/ ); next if ( $str =~ /^\s*#/ );
@ -85,7 +86,7 @@ BEGIN
$name =~ tr/a-z/A-Z/; $name =~ tr/a-z/A-Z/;
$Config{$name} = $value; $Config{$name} = $value;
} }
close( CONFIG ); close( $CONFIG );
use DBI; use DBI;
my $dbh = DBI->connect( "DBI:mysql:database=".$Config{ZM_DB_NAME}.";host=".$Config{ZM_DB_HOST}, $Config{ZM_DB_USER}, $Config{ZM_DB_PASS} ) or croak( "Can't connect to db" ); my $dbh = DBI->connect( "DBI:mysql:database=".$Config{ZM_DB_NAME}.";host=".$Config{ZM_DB_HOST}, $Config{ZM_DB_USER}, $Config{ZM_DB_PASS} ) or croak( "Can't connect to db" );

View File

@ -75,7 +75,7 @@ sub AUTOLOAD
croak( "Can't access $name member of object of class $class" ); croak( "Can't access $name member of object of class $class" );
} }
sub getKey() sub getKey
{ {
my $self = shift; my $self = shift;
return( $self->{id} ); return( $self->{id} );
@ -145,7 +145,7 @@ sub executeCommand
&{$self->{$command}}( $self, $params ); &{$self->{$command}}( $self, $params );
} }
sub printMsg() sub printMsg
{ {
my $self = shift; my $self = shift;
Fatal( "No printMsg method defined for protocol ".$self->{name} ); Fatal( "No printMsg method defined for protocol ".$self->{name} );

View File

@ -22,7 +22,7 @@
# This module contains the implementation of the Pelco-P camera control # This module contains the implementation of the Pelco-P camera control
# protocol # protocol
# #
package ZoneMinder::Control::PelcoD; package ZoneMinder::Control::PelcoP;
use 5.006; use 5.006;
use strict; use strict;

View File

@ -70,7 +70,7 @@ use Carp;
our $dbh = undef; our $dbh = undef;
sub zmDbConnect( ;$ ) sub zmDbConnect
{ {
my $force = shift; my $force = shift;
if ( $force ) if ( $force )
@ -94,7 +94,7 @@ sub zmDbConnect( ;$ )
return( $dbh ); return( $dbh );
} }
sub zmDbDisconnect() sub zmDbDisconnect
{ {
if ( defined( $dbh ) ) if ( defined( $dbh ) )
{ {
@ -110,7 +110,7 @@ use constant DB_MON_MOTION => 3; # All monitors that are doing motion detection
use constant DB_MON_RECORD => 4; # All monitors that are doing unconditional recording use constant DB_MON_RECORD => 4; # All monitors that are doing unconditional recording
use constant DB_MON_PASSIVE => 5; # All monitors that are in nodect state use constant DB_MON_PASSIVE => 5; # All monitors that are in nodect state
sub zmDbGetMonitors( ;$ ) sub zmDbGetMonitors
{ {
zmDbConnect(); zmDbConnect();
@ -152,7 +152,7 @@ sub zmDbGetMonitors( ;$ )
return( \@monitors ); return( \@monitors );
} }
sub zmDbGetMonitor( $ ) sub zmDbGetMonitor
{ {
zmDbConnect(); zmDbConnect();
@ -168,7 +168,7 @@ sub zmDbGetMonitor( $ )
return( $monitor ); return( $monitor );
} }
sub zmDbGetMonitorAndControl( $ ) sub zmDbGetMonitorAndControl
{ {
zmDbConnect(); zmDbConnect();

View File

@ -76,7 +76,7 @@ use ZoneMinder::Database qw(:all);
use POSIX; use POSIX;
# For running general shell commands # For running general shell commands
sub executeShellCommand( $ ) sub executeShellCommand
{ {
my $command = shift; my $command = shift;
my $output = qx( $command ); my $output = qx( $command );
@ -90,7 +90,7 @@ sub executeShellCommand( $ )
return( $status ); return( $status );
} }
sub getCmdFormat() sub getCmdFormat
{ {
Debug( "Testing valid shell syntax\n" ); Debug( "Testing valid shell syntax\n" );
@ -162,7 +162,7 @@ our $testedShellSyntax = 0;
our ( $cmdPrefix, $cmdSuffix ); our ( $cmdPrefix, $cmdSuffix );
# For running ZM daemons etc # For running ZM daemons etc
sub runCommand( $ ) sub runCommand
{ {
if ( !$testedShellSyntax ) if ( !$testedShellSyntax )
{ {
@ -196,7 +196,7 @@ sub runCommand( $ )
return( $output ); return( $output );
} }
sub getEventPath( $ ) sub getEventPath
{ {
my $event = shift; my $event = shift;
@ -213,7 +213,7 @@ sub getEventPath( $ )
return( $event_path ); return( $event_path );
} }
sub createEventPath( $ ) sub createEventPath
{ {
# #
# WARNING assumes running from events directory # WARNING assumes running from events directory
@ -250,8 +250,9 @@ sub createEventPath( $ )
# Create empty id tag file # Create empty id tag file
$idFile = sprintf( "%s/.%d", $eventPath, $event->{Id} ); $idFile = sprintf( "%s/.%d", $eventPath, $event->{Id} );
open( ID_FP, ">$idFile" ) or Fatal( "Can't open $idFile: $!" ); open( my $ID_FP, ">", $idFile )
close( ID_FP ); or Fatal( "Can't open $idFile: $!" );
close( $ID_FP );
setFileOwner( $idFile ); setFileOwner( $idFile );
} }
else else
@ -260,8 +261,9 @@ sub createEventPath( $ )
$eventPath .= '/'.$event->{Id}; $eventPath .= '/'.$event->{Id};
my $idFile = sprintf( "%s/.%d", $eventPath, $event->{Id} ); my $idFile = sprintf( "%s/.%d", $eventPath, $event->{Id} );
open( ID_FP, ">$idFile" ) or Fatal( "Can't open $idFile: $!" ); open( my $ID_FP, ">", $idFile )
close( ID_FP ); or Fatal( "Can't open $idFile: $!" );
close( $ID_FP );
setFileOwner( $idFile ); setFileOwner( $idFile );
} }
return( $eventPath ); return( $eventPath );
@ -272,7 +274,7 @@ use Data::Dumper;
our $_setFileOwner = undef; our $_setFileOwner = undef;
our ( $_ownerUid, $_ownerGid ); our ( $_ownerUid, $_ownerGid );
sub _checkProcessOwner() sub _checkProcessOwner
{ {
if ( !defined($_setFileOwner) ) if ( !defined($_setFileOwner) )
{ {
@ -291,7 +293,7 @@ sub _checkProcessOwner()
return( $_setFileOwner ); return( $_setFileOwner );
} }
sub setFileOwner( $ ) sub setFileOwner
{ {
my $file = shift; my $file = shift;
@ -303,7 +305,7 @@ sub setFileOwner( $ )
our $_hasImageInfo = undef; our $_hasImageInfo = undef;
sub _checkForImageInfo() sub _checkForImageInfo
{ {
if ( !defined($_hasImageInfo) ) if ( !defined($_hasImageInfo) )
{ {
@ -317,7 +319,7 @@ sub _checkForImageInfo()
return( $_hasImageInfo ); return( $_hasImageInfo );
} }
sub createEvent( $;$ ) sub createEvent
{ {
my $event = shift; my $event = shift;
@ -447,7 +449,7 @@ sub createEvent( $;$ )
} }
} }
sub addEventImage( $$ ) sub addEventImage
{ {
my $event = shift; my $event = shift;
my $frame = shift; my $frame = shift;
@ -455,7 +457,7 @@ sub addEventImage( $$ )
# TBD # TBD
} }
sub updateEvent( $ ) sub updateEvent
{ {
my $event = shift; my $event = shift;
@ -488,7 +490,7 @@ sub updateEvent( $ )
my $res = $sth->execute( @values ) or Fatal( "Can't execute sql '$sql': ".$sth->errstr() ); my $res = $sth->execute( @values ) or Fatal( "Can't execute sql '$sql': ".$sth->errstr() );
} }
sub deleteEventFiles( $;$ ) sub deleteEventFiles
{ {
# #
# WARNING assumes running from events directory # WARNING assumes running from events directory
@ -541,7 +543,7 @@ sub deleteEventFiles( $;$ )
} }
} }
sub makePath( $;$ ) sub makePath
{ {
my $path = shift; my $path = shift;
my $root = shift; my $root = shift;
@ -585,7 +587,7 @@ sub _testJSON
$hasJSONAny = 1 if ( $result ); $hasJSONAny = 1 if ( $result );
} }
sub _getJSONType( $ ) sub _getJSONType
{ {
my $value = shift; my $value = shift;
return( 'null' ) unless( defined($value) ); return( 'null' ) unless( defined($value) );
@ -596,9 +598,9 @@ sub _getJSONType( $ )
return( 'string' ); return( 'string' );
} }
sub jsonEncode( $ ); sub jsonEncode;
sub jsonEncode( $ ) sub jsonEncode
{ {
my $value = shift; my $value = shift;
@ -649,7 +651,7 @@ sub jsonEncode( $ )
} }
} }
sub jsonDecode( $ ) sub jsonDecode
{ {
my $value = shift; my $value = shift;

View File

@ -126,6 +126,7 @@ our %priorities = (
); );
our $logger; our $logger;
our $LOGFILE;
sub new sub new
{ {
@ -290,7 +291,7 @@ sub initialise( @ )
Debug( "LogOpts: level=".$codes{$this->{level}}."/".$codes{$this->{effectiveLevel}}.", screen=".$codes{$this->{termLevel}}.", database=".$codes{$this->{databaseLevel}}.", logfile=".$codes{$this->{fileLevel}}."->".$this->{logFile}.", syslog=".$codes{$this->{syslogLevel}} ); Debug( "LogOpts: level=".$codes{$this->{level}}."/".$codes{$this->{effectiveLevel}}.", screen=".$codes{$this->{termLevel}}.", database=".$codes{$this->{databaseLevel}}.", logfile=".$codes{$this->{fileLevel}}."->".$this->{logFile}.", syslog=".$codes{$this->{syslogLevel}} );
} }
sub terminate() sub terminate
{ {
my $this = shift; my $this = shift;
return unless ( $this->{initialised} ); return unless ( $this->{initialised} );
@ -300,7 +301,7 @@ sub terminate()
$this->termLevel( NOLOG ); $this->termLevel( NOLOG );
} }
sub reinitialise() sub reinitialise
{ {
my $this = shift; my $this = shift;
@ -322,7 +323,7 @@ sub reinitialise()
$this->databaseLevel( $databaseLevel ) if ( $databaseLevel > NOLOG ); $this->databaseLevel( $databaseLevel ) if ( $databaseLevel > NOLOG );
} }
sub limit( $ ) sub limit
{ {
my $this = shift; my $this = shift;
my $level = shift; my $level = shift;
@ -331,7 +332,7 @@ sub limit( $ )
return( $level ); return( $level );
} }
sub getTargettedEnv( $ ) sub getTargettedEnv
{ {
my $this = shift; my $this = shift;
my $name = shift; my $name = shift;
@ -354,7 +355,7 @@ sub getTargettedEnv( $ )
return( $value ); return( $value );
} }
sub fetch() sub fetch
{ {
if ( !$logger ) if ( !$logger )
{ {
@ -364,7 +365,7 @@ sub fetch()
return( $logger ); return( $logger );
} }
sub id( ;$ ) sub id
{ {
my $this = shift; my $this = shift;
my $id = shift; my $id = shift;
@ -388,7 +389,7 @@ sub id( ;$ )
return( $this->{id} ); return( $this->{id} );
} }
sub level( ;$ ) sub level
{ {
my $this = shift; my $this = shift;
my $level = shift; my $level = shift;
@ -405,20 +406,20 @@ sub level( ;$ )
return( $this->{level} ); return( $this->{level} );
} }
sub debugOn() sub debugOn
{ {
my $this = shift; my $this = shift;
return( $this->{effectiveLevel} >= DEBUG ); return( $this->{effectiveLevel} >= DEBUG );
} }
sub trace( ;$ ) sub trace
{ {
my $this = shift; my $this = shift;
$this->{trace} = $_[0] if ( @_ ); $this->{trace} = $_[0] if ( @_ );
return( $this->{trace} ); return( $this->{trace} );
} }
sub termLevel( ;$ ) sub termLevel
{ {
my $this = shift; my $this = shift;
my $termLevel = shift; my $termLevel = shift;
@ -434,7 +435,7 @@ sub termLevel( ;$ )
return( $this->{termLevel} ); return( $this->{termLevel} );
} }
sub databaseLevel( ;$ ) sub databaseLevel
{ {
my $this = shift; my $this = shift;
my $databaseLevel = shift; my $databaseLevel = shift;
@ -486,7 +487,7 @@ sub databaseLevel( ;$ )
return( $this->{databaseLevel} ); return( $this->{databaseLevel} );
} }
sub fileLevel( ;$ ) sub fileLevel
{ {
my $this = shift; my $this = shift;
my $fileLevel = shift; my $fileLevel = shift;
@ -503,7 +504,7 @@ sub fileLevel( ;$ )
return( $this->{fileLevel} ); return( $this->{fileLevel} );
} }
sub syslogLevel( ;$ ) sub syslogLevel
{ {
my $this = shift; my $this = shift;
my $syslogLevel = shift; my $syslogLevel = shift;
@ -520,19 +521,19 @@ sub syslogLevel( ;$ )
return( $this->{syslogLevel} ); return( $this->{syslogLevel} );
} }
sub openSyslog() sub openSyslog
{ {
my $this = shift; my $this = shift;
openlog( $this->{id}, "pid", "local1" ); openlog( $this->{id}, "pid", "local1" );
} }
sub closeSyslog() sub closeSyslog
{ {
my $this = shift; my $this = shift;
#closelog(); #closelog();
} }
sub logFile( $ ) sub logFile
{ {
my $this = shift; my $this = shift;
my $logFile = shift; my $logFile = shift;
@ -546,18 +547,19 @@ sub logFile( $ )
} }
} }
sub openFile() sub openFile
{ {
my $this = shift; my $this = shift;
if ( open( LOGFILE, ">>".$this->{logFile} ) ) if ( open( $LOGFILE, ">>", $this->{logFile} ) )
{ {
LOGFILE->autoflush() if ( $this->{autoFlush} ); $LOGFILE->autoflush() if ( $this->{autoFlush} );
my $webUid = (getpwnam( $Config{ZM_WEB_USER} ))[2]; my $webUid = (getpwnam( $Config{ZM_WEB_USER} ))[2];
my $webGid = (getgrnam( $Config{ZM_WEB_GROUP} ))[2]; my $webGid = (getgrnam( $Config{ZM_WEB_GROUP} ))[2];
if ( $> == 0 ) if ( $> == 0 )
{ {
chown( $webUid, $webGid, $this->{logFile} ) or Fatal( "Can't change permissions on log file '".$this->{logFile}."': $!" ) chown( $webUid, $webGid, $this->{logFile} )
or Fatal( "Can't change permissions on log file '".$this->{logFile}."': $!" )
} }
} }
else else
@ -567,13 +569,13 @@ sub openFile()
} }
} }
sub closeFile() sub closeFile
{ {
my $this = shift; my $this = shift;
close( LOGFILE ) if ( fileno(LOGFILE) ); close( $LOGFILE ) if ( fileno($LOGFILE) );
} }
sub logPrint( $;$ ) sub logPrint
{ {
my $this = shift; my $this = shift;
my $level = shift; my $level = shift;
@ -596,7 +598,7 @@ sub logPrint( $;$ )
$message = $message."\n"; $message = $message."\n";
} }
syslog( $priorities{$level}, $code." [%s]", $string ) if ( $level <= $this->{syslogLevel} ); syslog( $priorities{$level}, $code." [%s]", $string ) if ( $level <= $this->{syslogLevel} );
print( LOGFILE $message ) if ( $level <= $this->{fileLevel} ); print( $LOGFILE $message ) if ( $level <= $this->{fileLevel} );
if ( $level <= $this->{databaseLevel} ) if ( $level <= $this->{databaseLevel} )
{ {
my $sql = "insert into Logs ( TimeKey, Component, Pid, Level, Code, Message, File, Line ) values ( ?, ?, ?, ?, ?, ?, ?, NULL )"; my $sql = "insert into Logs ( TimeKey, Component, Pid, Level, Code, Message, File, Line ) values ( ?, ?, ?, ?, ?, ?, ?, NULL )";
@ -624,7 +626,7 @@ sub logInit( ;@ )
$logger->initialise( %options ); $logger->initialise( %options );
} }
sub logReinit() sub logReinit
{ {
fetch()->reinitialise(); fetch()->reinitialise();
} }
@ -636,7 +638,7 @@ sub logTerm
$logger = undef; $logger = undef;
} }
sub logHupHandler() sub logHupHandler
{ {
my $savedErrno = $!; my $savedErrno = $!;
return unless( $logger ); return unless( $logger );
@ -645,47 +647,47 @@ sub logHupHandler()
$! = $savedErrno; $! = $savedErrno;
} }
sub logSetSignal() sub logSetSignal
{ {
$SIG{HUP} = \&logHupHandler; $SIG{HUP} = \&logHupHandler;
} }
sub logClearSignal() sub logClearSignal
{ {
$SIG{HUP} = 'DEFAULT'; $SIG{HUP} = 'DEFAULT';
} }
sub logLevel( ;$ ) sub logLevel
{ {
return( fetch()->level( @_ ) ); return( fetch()->level( @_ ) );
} }
sub logDebugging() sub logDebugging
{ {
return( fetch()->debugOn() ); return( fetch()->debugOn() );
} }
sub logTermLevel( ;$ ) sub logTermLevel
{ {
return( fetch()->termLevel( @_ ) ); return( fetch()->termLevel( @_ ) );
} }
sub logDatabaseLevel( ;$ ) sub logDatabaseLevel
{ {
return( fetch()->databaseLevel( @_ ) ); return( fetch()->databaseLevel( @_ ) );
} }
sub logFileLevel( ;$ ) sub logFileLevel
{ {
return( fetch()->fileLevel( @_ ) ); return( fetch()->fileLevel( @_ ) );
} }
sub logSyslogLevel( ;$ ) sub logSyslogLevel
{ {
return( fetch()->syslogLevel( @_ ) ); return( fetch()->syslogLevel( @_ ) );
} }
sub Mark( ;$$ ) sub Mark
{ {
my $level = shift; my $level = shift;
$level = DEBUG unless( defined($level) ); $level = DEBUG unless( defined($level) );
@ -693,7 +695,7 @@ sub Mark( ;$$ )
fetch()->logPrint( $level, $tag ); fetch()->logPrint( $level, $tag );
} }
sub Dump( \$;$ ) sub Dump
{ {
my $var = shift; my $var = shift;
my $label = shift; my $label = shift;

View File

@ -249,7 +249,7 @@ sub zmMemInit
&zmMemInit(); &zmMemInit();
sub zmMemVerify( $ ) sub zmMemVerify
{ {
my $monitor = shift; my $monitor = shift;
if ( !zmMemAttach( $monitor, $mem_size ) ) if ( !zmMemAttach( $monitor, $mem_size ) )
@ -291,7 +291,7 @@ sub zmMemVerify( $ )
return( !undef ); return( !undef );
} }
sub zmMemRead( $$;$ ) sub zmMemRead
{ {
my $monitor = shift; my $monitor = shift;
my $fields = shift; my $fields = shift;
@ -387,7 +387,7 @@ sub zmMemRead( $$;$ )
return( $values[0] ); return( $values[0] );
} }
sub zmMemInvalidate( $ ) sub zmMemInvalidate
{ {
my $monitor = shift; my $monitor = shift;
my $mem_key = zmMemKey($monitor); my $mem_key = zmMemKey($monitor);
@ -398,12 +398,12 @@ sub zmMemInvalidate( $ )
} }
} }
sub zmMemTidy() sub zmMemTidy
{ {
zmMemClean(); zmMemClean();
} }
sub zmMemWrite( $$;$ ) sub zmMemWrite
{ {
my $monitor = shift; my $monitor = shift;
my $field_values = shift; my $field_values = shift;
@ -489,21 +489,21 @@ sub zmMemWrite( $$;$ )
return( !undef ); return( !undef );
} }
sub zmGetMonitorState( $ ) sub zmGetMonitorState
{ {
my $monitor = shift; my $monitor = shift;
return( zmMemRead( $monitor, "shared_data:state" ) ); return( zmMemRead( $monitor, "shared_data:state" ) );
} }
sub zmGetAlarmLocation( $ ) sub zmGetAlarmLocation
{ {
my $monitor = shift; my $monitor = shift;
return( zmMemRead( $monitor, [ "shared_data:alarm_x", "shared_data:alarm_y" ] ) ); return( zmMemRead( $monitor, [ "shared_data:alarm_x", "shared_data:alarm_y" ] ) );
} }
sub zmSetControlState( $$ ) sub zmSetControlState
{ {
my $monitor = shift; my $monitor = shift;
my $control_state = shift; my $control_state = shift;
@ -511,14 +511,14 @@ sub zmSetControlState( $$ )
zmMemWrite( $monitor, { "shared_data:control_state" => $control_state } ); zmMemWrite( $monitor, { "shared_data:control_state" => $control_state } );
} }
sub zmGetControlState( $ ) sub zmGetControlState
{ {
my $monitor = shift; my $monitor = shift;
return( zmMemRead( $monitor, "shared_data:control_state" ) ); return( zmMemRead( $monitor, "shared_data:control_state" ) );
} }
sub zmSaveControlState( $$ ) sub zmSaveControlState
{ {
my $monitor = shift; my $monitor = shift;
my $control_state = shift; my $control_state = shift;
@ -526,14 +526,14 @@ sub zmSaveControlState( $$ )
zmSetControlState( $monitor, freeze( $control_state ) ); zmSetControlState( $monitor, freeze( $control_state ) );
} }
sub zmRestoreControlState( $ ) sub zmRestoreControlState
{ {
my $monitor = shift; my $monitor = shift;
return( thaw( zmGetControlState( $monitor ) ) ); return( thaw( zmGetControlState( $monitor ) ) );
} }
sub zmIsAlarmed( $ ) sub zmIsAlarmed
{ {
my $monitor = shift; my $monitor = shift;
@ -542,7 +542,7 @@ sub zmIsAlarmed( $ )
return( $state == STATE_ALARM ); return( $state == STATE_ALARM );
} }
sub zmInAlarm( $ ) sub zmInAlarm
{ {
my $monitor = shift; my $monitor = shift;
@ -551,7 +551,7 @@ sub zmInAlarm( $ )
return( $state == STATE_ALARM || $state == STATE_ALERT ); return( $state == STATE_ALARM || $state == STATE_ALERT );
} }
sub zmHasAlarmed( $$ ) sub zmHasAlarmed
{ {
my $monitor = shift; my $monitor = shift;
my $last_event_id = shift; my $last_event_id = shift;
@ -569,35 +569,35 @@ sub zmHasAlarmed( $$ )
return( undef ); return( undef );
} }
sub zmGetLastEvent( $ ) sub zmGetLastEvent
{ {
my $monitor = shift; my $monitor = shift;
return( zmMemRead( $monitor, "shared_data:last_event" ) ); return( zmMemRead( $monitor, "shared_data:last_event" ) );
} }
sub zmGetLastWriteTime( $ ) sub zmGetLastWriteTime
{ {
my $monitor = shift; my $monitor = shift;
return( zmMemRead( $monitor, "shared_data:last_write_time" ) ); return( zmMemRead( $monitor, "shared_data:last_write_time" ) );
} }
sub zmGetLastReadTime( $ ) sub zmGetLastReadTime
{ {
my $monitor = shift; my $monitor = shift;
return( zmMemRead( $monitor, "shared_data:last_read_time" ) ); return( zmMemRead( $monitor, "shared_data:last_read_time" ) );
} }
sub zmGetMonitorActions( $ ) sub zmGetMonitorActions
{ {
my $monitor = shift; my $monitor = shift;
return( zmMemRead( $monitor, "shared_data:action" ) ); return( zmMemRead( $monitor, "shared_data:action" ) );
} }
sub zmMonitorEnable( $ ) sub zmMonitorEnable
{ {
my $monitor = shift; my $monitor = shift;
@ -606,7 +606,7 @@ sub zmMonitorEnable( $ )
zmMemWrite( $monitor, { "shared_data:action" => $action } ); zmMemWrite( $monitor, { "shared_data:action" => $action } );
} }
sub zmMonitorDisable( $ ) sub zmMonitorDisable
{ {
my $monitor = shift; my $monitor = shift;
@ -615,7 +615,7 @@ sub zmMonitorDisable( $ )
zmMemWrite( $monitor, { "shared_data:action" => $action } ); zmMemWrite( $monitor, { "shared_data:action" => $action } );
} }
sub zmMonitorSuspend( $ ) sub zmMonitorSuspend
{ {
my $monitor = shift; my $monitor = shift;
@ -624,7 +624,7 @@ sub zmMonitorSuspend( $ )
zmMemWrite( $monitor, { "shared_data:action" => $action } ); zmMemWrite( $monitor, { "shared_data:action" => $action } );
} }
sub zmMonitorResume( $ ) sub zmMonitorResume
{ {
my $monitor = shift; my $monitor = shift;
@ -633,14 +633,14 @@ sub zmMonitorResume( $ )
zmMemWrite( $monitor, { "shared_data:action" => $action } ); zmMemWrite( $monitor, { "shared_data:action" => $action } );
} }
sub zmGetTriggerState( $ ) sub zmGetTriggerState
{ {
my $monitor = shift; my $monitor = shift;
return( zmMemRead( $monitor, "trigger_data:trigger_state" ) ); return( zmMemRead( $monitor, "trigger_data:trigger_state" ) );
} }
sub zmTriggerEventOn( $$$;$$ ) sub zmTriggerEventOn
{ {
my $monitor = shift; my $monitor = shift;
my $score = shift; my $score = shift;
@ -659,7 +659,7 @@ sub zmTriggerEventOn( $$$;$$ )
zmMemWrite( $monitor, $values ); zmMemWrite( $monitor, $values );
} }
sub zmTriggerEventOff( $ ) sub zmTriggerEventOff
{ {
my $monitor = shift; my $monitor = shift;
@ -674,7 +674,7 @@ sub zmTriggerEventOff( $ )
zmMemWrite( $monitor, $values ); zmMemWrite( $monitor, $values );
} }
sub zmTriggerEventCancel( $ ) sub zmTriggerEventCancel
{ {
my $monitor = shift; my $monitor = shift;
@ -689,7 +689,7 @@ sub zmTriggerEventCancel( $ )
zmMemWrite( $monitor, $values ); zmMemWrite( $monitor, $values );
} }
sub zmTriggerShowtext( $$ ) sub zmTriggerShowtext
{ {
my $monitor = shift; my $monitor = shift;
my $showtext = shift; my $showtext = shift;

View File

@ -68,13 +68,13 @@ use ZoneMinder::Logger qw(:all);
use Sys::Mmap; use Sys::Mmap;
sub zmMemKey( $ ) sub zmMemKey
{ {
my $monitor = shift; my $monitor = shift;
return( defined($monitor->{MMapAddr})?$monitor->{MMapAddr}:undef ); return( defined($monitor->{MMapAddr})?$monitor->{MMapAddr}:undef );
} }
sub zmMemAttach( $$ ) sub zmMemAttach
{ {
my ( $monitor, $size ) = @_; my ( $monitor, $size ) = @_;
if ( ! $size ) { if ( ! $size ) {
@ -96,7 +96,7 @@ sub zmMemAttach( $$ )
Error( sprintf( "Memory map file '%s' should have been %d but was instead %d", $mmap_file, $size, $mmap_file_size ) ); Error( sprintf( "Memory map file '%s' should have been %d but was instead %d", $mmap_file, $size, $mmap_file_size ) );
return ( undef ); return ( undef );
} }
if ( !open( MMAP, "+<".$mmap_file ) ) if ( !open( MMAP, "+<", $mmap_file ) )
{ {
Error( sprintf( "Can't open memory map file '%s': $!\n", $mmap_file ) ); Error( sprintf( "Can't open memory map file '%s': $!\n", $mmap_file ) );
return( undef ); return( undef );
@ -116,7 +116,7 @@ sub zmMemAttach( $$ )
return( !undef ); return( !undef );
} }
sub zmMemDetach( $ ) sub zmMemDetach
{ {
my $monitor = shift; my $monitor = shift;
@ -138,7 +138,7 @@ sub zmMemDetach( $ )
} }
} }
sub zmMemGet( $$$ ) sub zmMemGet
{ {
my $monitor = shift; my $monitor = shift;
my $offset = shift; my $offset = shift;
@ -154,7 +154,7 @@ sub zmMemGet( $$$ )
return( $data ); return( $data );
} }
sub zmMemPut( $$$$ ) sub zmMemPut
{ {
my $monitor = shift; my $monitor = shift;
my $offset = shift; my $offset = shift;

View File

@ -69,13 +69,13 @@ our $VERSION = $ZoneMinder::Base::VERSION;
use ZoneMinder::Config qw(:all); use ZoneMinder::Config qw(:all);
use ZoneMinder::Logger qw(:all); use ZoneMinder::Logger qw(:all);
sub zmMemKey( $ ) sub zmMemKey
{ {
my $monitor = shift; my $monitor = shift;
return( defined($monitor->{ShmKey})?$monitor->{ShmKey}:undef ); return( defined($monitor->{ShmKey})?$monitor->{ShmKey}:undef );
} }
sub zmMemAttach( $$ ) sub zmMemAttach
{ {
my $monitor = shift; my $monitor = shift;
my $size = shift; my $size = shift;
@ -94,14 +94,14 @@ sub zmMemAttach( $$ )
return( !undef ); return( !undef );
} }
sub zmMemDetach( $ ) sub zmMemDetach
{ {
my $monitor = shift; my $monitor = shift;
delete $monitor->{ShmId}; delete $monitor->{ShmId};
} }
sub zmMemGet( $$$ ) sub zmMemGet
{ {
my $monitor = shift; my $monitor = shift;
my $offset = shift; my $offset = shift;
@ -119,7 +119,7 @@ sub zmMemGet( $$$ )
return( $data ); return( $data );
} }
sub zmMemPut( $$$$ ) sub zmMemPut
{ {
my $monitor = shift; my $monitor = shift;
my $offset = shift; my $offset = shift;
@ -143,8 +143,9 @@ sub zmMemClean
# Find ZoneMinder shared memory # Find ZoneMinder shared memory
my $command = "ipcs -m | grep '^".substr( sprintf( "0x%x", hex($Config{ZM_SHM_KEY}) ), 0, -2 )."'"; my $command = "ipcs -m | grep '^".substr( sprintf( "0x%x", hex($Config{ZM_SHM_KEY}) ), 0, -2 )."'";
Debug( "Checking for shared memory with '$command'\n" ); Debug( "Checking for shared memory with '$command'\n" );
open( CMD, "$command |" ) or Fatal( "Can't execute '$command': $!" ); open( my $CMD, '<', "$command |" )
while( <CMD> ) or Fatal( "Can't execute '$command': $!" );
while( <$CMD> )
{ {
chomp; chomp;
my ( $key, $id ) = split( /\s+/ ); my ( $key, $id ) = split( /\s+/ );
@ -156,7 +157,7 @@ sub zmMemClean
qx( $command ); qx( $command );
} }
} }
close( CMD ); close( $CMD );
} }
1; 1;

View File

@ -63,33 +63,33 @@ sub clone
bless $clone, ref $self; bless $clone, ref $self;
} }
sub open() sub open
{ {
my $self = shift; my $self = shift;
my $class = ref($self) or croak( "Can't get class for non object $self" ); my $class = ref($self) or croak( "Can't get class for non object $self" );
croak( "Abstract base class method called for object of class $class" ); croak( "Abstract base class method called for object of class $class" );
} }
sub close() sub close
{ {
my $self = shift; my $self = shift;
my $class = ref($self) or croak( "Can't get class for non object $self" ); my $class = ref($self) or croak( "Can't get class for non object $self" );
croak( "Abstract base class method called for object of class $class" ); croak( "Abstract base class method called for object of class $class" );
} }
sub getState() sub getState
{ {
my $self = shift; my $self = shift;
return( $self->{state} ); return( $self->{state} );
} }
sub isOpen() sub isOpen
{ {
my $self = shift; my $self = shift;
return( $self->{state} eq "open" ); return( $self->{state} eq "open" );
} }
sub isConnected() sub isConnected
{ {
my $self = shift; my $self = shift;
return( $self->{state} eq "connected" ); return( $self->{state} eq "connected" );

View File

@ -56,13 +56,13 @@ sub new
return $self; return $self;
} }
sub open() sub open
{ {
my $self = shift; my $self = shift;
local *sfh; local *sfh;
#sysopen( *sfh, $conn->{path}, O_NONBLOCK|O_RDONLY ) or croak( "Can't sysopen: $!" ); #sysopen( *sfh, $conn->{path}, O_NONBLOCK|O_RDONLY ) or croak( "Can't sysopen: $!" );
#open( *sfh, "<".$conn->{path} ) or croak( "Can't open: $!" ); #open( *sfh, "<".$conn->{path} ) or croak( "Can't open: $!" );
open( *sfh, "+<".$self->{path} ) or croak( "Can't open: $!" ); open( *sfh, "+<", $self->{path} ) or croak( "Can't open: $!" );
$self->{state} = 'open'; $self->{state} = 'open';
$self->{handle} = *sfh; $self->{handle} = *sfh;
} }

View File

@ -59,7 +59,7 @@ sub spawns
return( undef ); return( undef );
} }
sub close() sub close
{ {
my $self = shift; my $self = shift;
close( $self->{handle} ); close( $self->{handle} );
@ -67,7 +67,7 @@ sub close()
$self->{handle} = undef; $self->{handle} = undef;
} }
sub read() sub read
{ {
my $self = shift; my $self = shift;
my $buffer; my $buffer;
@ -80,7 +80,7 @@ sub read()
return( $buffer ); return( $buffer );
} }
sub write() sub write
{ {
my $self = shift; my $self = shift;
my $buffer = shift; my $buffer = shift;
@ -94,7 +94,7 @@ sub write()
return( !undef ); return( !undef );
} }
sub fileno() sub fileno
{ {
my $self = shift; my $self = shift;
return( defined($self->{handle})?fileno($self->{handle}):-1 ); return( defined($self->{handle})?fileno($self->{handle}):-1 );

View File

@ -57,7 +57,7 @@ sub new
return $self; return $self;
} }
sub open() sub open
{ {
my $self = shift; my $self = shift;
local *sfh; local *sfh;
@ -70,7 +70,7 @@ sub open()
$self->{handle} = *sfh; $self->{handle} = *sfh;
} }
sub _spawn( $ ) sub _spawn
{ {
my $self = shift; my $self = shift;
my $new_handle = shift; my $new_handle = shift;
@ -80,7 +80,7 @@ sub _spawn( $ )
return( $clone ); return( $clone );
} }
sub accept() sub accept
{ {
my $self = shift; my $self = shift;
local *cfh; local *cfh;

View File

@ -54,7 +54,7 @@ sub new
return $self; return $self;
} }
sub open() sub open
{ {
my $self = shift; my $self = shift;
my $device = new Device::SerialPort( $self->{path} ); my $device = new Device::SerialPort( $self->{path} );
@ -72,14 +72,14 @@ sub open()
$self->{state} = 'connected'; $self->{state} = 'connected';
} }
sub close() sub close
{ {
my $self = shift; my $self = shift;
$self->{device}->close(); $self->{device}->close();
$self->{state} = 'closed'; $self->{state} = 'closed';
} }
sub read() sub read
{ {
my $self = shift; my $self = shift;
my $buffer = $self->{device}->lookfor(); my $buffer = $self->{device}->lookfor();
@ -91,7 +91,7 @@ sub read()
return( $buffer ); return( $buffer );
} }
sub write() sub write
{ {
my $self = shift; my $self = shift;
my $buffer = shift; my $buffer = shift;

View File

@ -57,7 +57,7 @@ sub new
return $self; return $self;
} }
sub open() sub open
{ {
my $self = shift; my $self = shift;
local *sfh; local *sfh;
@ -69,7 +69,7 @@ sub open()
$self->{handle} = *sfh; $self->{handle} = *sfh;
} }
sub _spawn( $ ) sub _spawn
{ {
my $self = shift; my $self = shift;
my $new_handle = shift; my $new_handle = shift;
@ -79,7 +79,7 @@ sub _spawn( $ )
return( $clone ); return( $clone );
} }
sub accept() sub accept
{ {
my $self = shift; my $self = shift;
local *cfh; local *cfh;

View File

@ -71,7 +71,7 @@ sub spawns
return( $self->{channel}->spawns() ); return( $self->{channel}->spawns() );
} }
sub _spawn( $ ) sub _spawn
{ {
my $self = shift; my $self = shift;
my $new_channel = shift; my $new_channel = shift;
@ -80,50 +80,50 @@ sub _spawn( $ )
return( $clone ); return( $clone );
} }
sub accept() sub accept
{ {
my $self = shift; my $self = shift;
my $new_channel = $self->{channel}->accept(); my $new_channel = $self->{channel}->accept();
return( $self->_spawn( $new_channel ) ); return( $self->_spawn( $new_channel ) );
} }
sub open() sub open
{ {
my $self = shift; my $self = shift;
return( $self->{channel}->open() ); return( $self->{channel}->open() );
} }
sub close() sub close
{ {
my $self = shift; my $self = shift;
return( $self->{channel}->close() ); return( $self->{channel}->close() );
} }
sub fileno() sub fileno
{ {
my $self = shift; my $self = shift;
return( $self->{channel}->fileno() ); return( $self->{channel}->fileno() );
} }
sub isOpen() sub isOpen
{ {
my $self = shift; my $self = shift;
return( $self->{channel}->isOpen() ); return( $self->{channel}->isOpen() );
} }
sub isConnected() sub isConnected
{ {
my $self = shift; my $self = shift;
return( $self->{channel}->isConnected() ); return( $self->{channel}->isConnected() );
} }
sub canRead() sub canRead
{ {
my $self = shift; my $self = shift;
return( $self->{input} && $self->isConnected() ); return( $self->{input} && $self->isConnected() );
} }
sub canWrite() sub canWrite
{ {
my $self = shift; my $self = shift;
return( $self->{output} && $self->isConnected() ); return( $self->{output} && $self->isConnected() );