2002-09-24 06:08:50 +08:00
|
|
|
//
|
2002-12-10 21:21:41 +08:00
|
|
|
// ZoneMinder Analysis Daemon, $Date$, $Revision$
|
2008-07-25 17:33:23 +08:00
|
|
|
// Copyright (C) 2001-2008 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"
|
2006-04-05 20:22:27 +08:00
|
|
|
#include "zm_signal.h"
|
2003-03-26 20:00:16 +08:00
|
|
|
#include "zm_monitor.h"
|
2002-09-16 17:19:24 +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" );
|
2015-01-07 09:52:18 +08:00
|
|
|
fprintf( stderr, " -v, --version : Report the installed version of ZoneMinder\n" );
|
2002-12-24 20:01:28 +08:00
|
|
|
exit( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
int main( int argc, char *argv[] )
|
|
|
|
{
|
2013-10-07 07:37:50 +08:00
|
|
|
self = argv[0];
|
|
|
|
|
|
|
|
srand( getpid() * time( 0 ) );
|
2009-04-15 04:18:57 +08:00
|
|
|
|
2002-12-24 20:01:28 +08:00
|
|
|
int id = -1;
|
|
|
|
|
|
|
|
static struct option long_options[] = {
|
|
|
|
{"monitor", 1, 0, 'm'},
|
|
|
|
{"help", 0, 0, 'h'},
|
2015-01-07 09:52:18 +08:00
|
|
|
{"version", 0, 0, 'v'},
|
2002-12-24 20:01:28 +08:00
|
|
|
{0, 0, 0, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
int option_index = 0;
|
|
|
|
|
2015-01-07 09:52:18 +08:00
|
|
|
int c = getopt_long (argc, argv, "m:h:v", long_options, &option_index);
|
2002-12-24 20:01:28 +08:00
|
|
|
if (c == -1)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (c)
|
|
|
|
{
|
|
|
|
case 'm':
|
|
|
|
id = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
case '?':
|
|
|
|
Usage();
|
|
|
|
break;
|
2015-01-07 09:52:18 +08:00
|
|
|
case 'v':
|
2015-05-30 05:22:20 +08:00
|
|
|
std::cout << ZM_VERSION << "\n";
|
2015-01-07 09:52:18 +08:00
|
|
|
exit(0);
|
2002-12-24 20:01:28 +08:00
|
|
|
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
|
|
|
|
2011-06-21 17:19:10 +08:00
|
|
|
char log_id_string[16];
|
|
|
|
snprintf( log_id_string, sizeof(log_id_string), "zma_m%d", id );
|
2002-09-16 17:19:24 +08:00
|
|
|
|
2004-12-29 00:46:48 +08:00
|
|
|
zmLoadConfig();
|
|
|
|
|
2011-06-21 17:19:10 +08:00
|
|
|
logInit( log_id_string );
|
2011-09-08 00:07:23 +08:00
|
|
|
|
|
|
|
ssedetect();
|
2011-06-21 17:19:10 +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 )
|
|
|
|
{
|
2008-07-14 22:43:47 +08:00
|
|
|
Info( "In mode %d/%d, warming up", monitor->GetFunction(), monitor->Enabled() );
|
2002-11-07 20:25:48 +08:00
|
|
|
|
2005-05-16 17:27:06 +08:00
|
|
|
if ( config.opt_frame_server )
|
2003-04-22 22:15:59 +08:00
|
|
|
{
|
|
|
|
Event::OpenFrameSocket( monitor->Id() );
|
|
|
|
}
|
|
|
|
|
2006-04-05 20:22:27 +08:00
|
|
|
zmSetDefaultHupHandler();
|
|
|
|
zmSetDefaultTermHandler();
|
|
|
|
zmSetDefaultDieHandler();
|
|
|
|
|
2002-12-24 20:01:28 +08:00
|
|
|
sigset_t block_set;
|
|
|
|
sigemptyset( &block_set );
|
2002-11-07 20:25:48 +08:00
|
|
|
|
2006-04-05 20:22:27 +08:00
|
|
|
while( !zm_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
|
|
|
{
|
2005-12-23 00:46:25 +08:00
|
|
|
usleep( monitor->Active()?ZM_SAMPLE_RATE:ZM_SUSPENDED_RATE );
|
|
|
|
}
|
2006-04-05 20:22:27 +08:00
|
|
|
if ( zm_reload )
|
2005-12-23 00:46:25 +08:00
|
|
|
{
|
|
|
|
monitor->Reload();
|
2006-04-05 20:22:27 +08:00
|
|
|
zm_reload = false;
|
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
|
|
|
}
|
2014-11-15 05:17:44 +08:00
|
|
|
logTerm();
|
|
|
|
zmDbClose();
|
2002-10-28 22:33:57 +08:00
|
|
|
return( 0 );
|
2002-09-16 17:19:24 +08:00
|
|
|
}
|