2002-09-24 06:08:50 +08:00
|
|
|
//
|
2002-12-10 21:21:41 +08:00
|
|
|
// ZoneMinder Analysis Daemon, $Date$, $Revision$
|
2003-01-12 02:22:27 +08:00
|
|
|
// Copyright (C) 2003 Philip Coombes
|
2002-09-24 06:08:50 +08:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
|
|
|
// as published by the Free Software Foundation; either version 2
|
|
|
|
// of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
//
|
|
|
|
|
2002-12-24 20:01:28 +08:00
|
|
|
#include <getopt.h>
|
2003-03-26 20:00:16 +08:00
|
|
|
#include <signal.h>
|
2002-09-16 17:19:24 +08:00
|
|
|
|
2003-03-26 20:00:16 +08:00
|
|
|
#include "zm.h"
|
|
|
|
#include "zm_db.h"
|
|
|
|
#include "zm_monitor.h"
|
2002-09-16 17:19:24 +08:00
|
|
|
|
2003-03-26 20:00:16 +08:00
|
|
|
void zm_die_handler( int signal )
|
2002-11-07 20:25:48 +08:00
|
|
|
{
|
|
|
|
Info(( "Got signal %d, crashing", signal ));
|
|
|
|
exit( signal );
|
|
|
|
}
|
|
|
|
|
2003-10-08 20:53:07 +08:00
|
|
|
bool zma_terminate = false;
|
|
|
|
|
2003-03-26 20:00:16 +08:00
|
|
|
void zm_term_handler( int signal )
|
2002-09-23 18:11:04 +08:00
|
|
|
{
|
|
|
|
Info(( "Got TERM signal, exiting" ));
|
2003-10-08 20:53:07 +08:00
|
|
|
zma_terminate = true;
|
2002-09-23 18:11:04 +08:00
|
|
|
}
|
|
|
|
|
2002-12-24 20:01:28 +08:00
|
|
|
void Usage()
|
2002-09-16 17:19:24 +08:00
|
|
|
{
|
2002-12-24 20:01:28 +08:00
|
|
|
fprintf( stderr, "zma -m <monitor_id>\n" );
|
|
|
|
fprintf( stderr, "Options:\n" );
|
|
|
|
fprintf( stderr, " -m, --monitor <monitor_id> : Specify which monitor to use\n" );
|
|
|
|
fprintf( stderr, " -h, --help : This screen\n" );
|
|
|
|
exit( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
int main( int argc, char *argv[] )
|
|
|
|
{
|
|
|
|
int id = -1;
|
|
|
|
|
|
|
|
static struct option long_options[] = {
|
|
|
|
{"monitor", 1, 0, 'm'},
|
|
|
|
{"help", 0, 0, 'h'},
|
|
|
|
{0, 0, 0, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
int option_index = 0;
|
|
|
|
|
|
|
|
int c = getopt_long (argc, argv, "m:h", long_options, &option_index);
|
|
|
|
if (c == -1)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (c)
|
|
|
|
{
|
|
|
|
case 'm':
|
|
|
|
id = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
case '?':
|
|
|
|
Usage();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
//fprintf( stderr, "?? getopt returned character code 0%o ??\n", c );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (optind < argc)
|
|
|
|
{
|
|
|
|
fprintf( stderr, "Extraneous options, " );
|
|
|
|
while (optind < argc)
|
|
|
|
printf ("%s ", argv[optind++]);
|
|
|
|
printf ("\n");
|
|
|
|
Usage();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( id < 0 )
|
|
|
|
{
|
|
|
|
fprintf( stderr, "Bogus monitor %d\n", id );
|
|
|
|
Usage();
|
|
|
|
exit( 0 );
|
|
|
|
}
|
2002-09-16 17:19:24 +08:00
|
|
|
|
|
|
|
char dbg_name_string[16];
|
2002-12-24 20:01:28 +08:00
|
|
|
sprintf( dbg_name_string, "zma-m%d", id );
|
2003-03-26 20:00:16 +08:00
|
|
|
zm_dbg_name = dbg_name_string;
|
2003-04-22 22:15:59 +08:00
|
|
|
//sprintf( zm_dbg_log, "/tmp/zma-%d.log", id );
|
|
|
|
//zm_dbg_level = 1;
|
2002-09-16 17:19:24 +08:00
|
|
|
|
2003-03-26 20:00:16 +08:00
|
|
|
zmDbgInit();
|
2002-09-16 17:19:24 +08:00
|
|
|
|
2003-03-26 20:00:16 +08:00
|
|
|
zmDbConnect( ZM_DB_USERA, ZM_DB_PASSA );
|
2002-09-16 17:19:24 +08:00
|
|
|
|
2003-06-12 22:29:54 +08:00
|
|
|
Monitor *monitor = Monitor::Load( id, true, Monitor::ANALYSIS );
|
2002-09-16 17:19:24 +08:00
|
|
|
|
2002-12-24 20:01:28 +08:00
|
|
|
if ( monitor )
|
|
|
|
{
|
|
|
|
Info(( "Warming up" ));
|
2002-11-07 20:25:48 +08:00
|
|
|
|
2003-07-04 20:31:36 +08:00
|
|
|
if ( (bool)config.Item( ZM_OPT_FRAME_SERVER ) )
|
2003-04-22 22:15:59 +08:00
|
|
|
{
|
|
|
|
Event::OpenFrameSocket( monitor->Id() );
|
|
|
|
}
|
|
|
|
|
2002-12-24 20:01:28 +08:00
|
|
|
sigset_t block_set;
|
|
|
|
sigemptyset( &block_set );
|
|
|
|
struct sigaction action, old_action;
|
2002-11-07 20:25:48 +08:00
|
|
|
|
2003-03-26 20:00:16 +08:00
|
|
|
action.sa_handler = zm_term_handler;
|
2002-12-24 20:01:28 +08:00
|
|
|
action.sa_mask = block_set;
|
|
|
|
action.sa_flags = 0;
|
|
|
|
sigaction( SIGTERM, &action, &old_action );
|
2002-11-07 20:25:48 +08:00
|
|
|
|
2003-03-26 20:00:16 +08:00
|
|
|
action.sa_handler = zm_die_handler;
|
2002-12-24 20:01:28 +08:00
|
|
|
action.sa_mask = block_set;
|
|
|
|
action.sa_flags = 0;
|
|
|
|
sigaction( SIGBUS, &action, &old_action );
|
|
|
|
sigaction( SIGSEGV, &action, &old_action );
|
2002-11-07 20:25:48 +08:00
|
|
|
|
2003-10-08 20:53:07 +08:00
|
|
|
while( !zma_terminate )
|
2002-09-16 17:19:24 +08:00
|
|
|
{
|
2002-12-24 20:01:28 +08:00
|
|
|
// Process the next image
|
|
|
|
sigprocmask( SIG_BLOCK, &block_set, 0 );
|
|
|
|
if ( !monitor->Analyse() )
|
2002-09-23 18:11:04 +08:00
|
|
|
{
|
2002-12-24 20:01:28 +08:00
|
|
|
usleep( 10000 );
|
2002-09-23 18:11:04 +08:00
|
|
|
}
|
2002-12-24 20:01:28 +08:00
|
|
|
sigprocmask( SIG_UNBLOCK, &block_set, 0 );
|
2002-09-23 18:11:04 +08:00
|
|
|
}
|
2003-10-08 20:53:07 +08:00
|
|
|
delete monitor;
|
2002-12-24 20:01:28 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf( stderr, "Can't find monitor with id of %d\n", id );
|
2002-09-16 17:19:24 +08:00
|
|
|
}
|
2002-10-28 22:33:57 +08:00
|
|
|
return( 0 );
|
2002-09-16 17:19:24 +08:00
|
|
|
}
|