2002-09-24 06:08:50 +08:00
|
|
|
//
|
2002-12-10 21:21:41 +08:00
|
|
|
// ZoneMinder Capture Daemon, $Date$, $Revision$
|
2002-09-24 06:08:50 +08:00
|
|
|
// Copyright (C) 2002 Philip Coombes
|
|
|
|
//
|
|
|
|
// 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:02:08 +08:00
|
|
|
#include <getopt.h>
|
2002-09-16 17:19:24 +08:00
|
|
|
#include "zm.h"
|
|
|
|
|
2002-10-31 01:02:06 +08:00
|
|
|
bool terminate = false;
|
2002-09-16 17:19:24 +08:00
|
|
|
|
2002-09-23 18:11:04 +08:00
|
|
|
void term_handler( int signal )
|
|
|
|
{
|
|
|
|
Info(( "Got TERM signal, exiting" ));
|
2002-10-31 01:02:06 +08:00
|
|
|
terminate = true;
|
2002-09-23 18:11:04 +08:00
|
|
|
}
|
|
|
|
|
2002-12-24 20:02:08 +08:00
|
|
|
void Usage()
|
2002-09-16 17:19:24 +08:00
|
|
|
{
|
2002-12-24 20:02:08 +08:00
|
|
|
fprintf( stderr, "zmc -d <device_id>\n" );
|
|
|
|
fprintf( stderr, "Options:\n" );
|
|
|
|
fprintf( stderr, " -d, --device <device_id> : Specify which device to access, 0=>/dev/video0 etc\n" );
|
|
|
|
fprintf( stderr, " -h, --help : This screen\n" );
|
|
|
|
exit( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
int main( int argc, char *argv[] )
|
|
|
|
{
|
|
|
|
int device = -1;
|
|
|
|
|
|
|
|
static struct option long_options[] = {
|
|
|
|
{"device", 1, 0, 'd'},
|
|
|
|
{"help", 0, 0, 'h'},
|
|
|
|
{0, 0, 0, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
int this_option_optind = optind ? optind : 1;
|
|
|
|
int option_index = 0;
|
|
|
|
int opterr = 1;
|
|
|
|
|
|
|
|
int c = getopt_long (argc, argv, "d:h", long_options, &option_index);
|
|
|
|
if (c == -1)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (c)
|
|
|
|
{
|
|
|
|
case 'd':
|
|
|
|
device = 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 ( device < 0 )
|
|
|
|
{
|
|
|
|
fprintf( stderr, "Bogus device %d\n", device );
|
|
|
|
Usage();
|
|
|
|
exit( 0 );
|
|
|
|
}
|
2002-09-16 17:19:24 +08:00
|
|
|
|
|
|
|
char dbg_name_string[16];
|
2002-12-24 20:02:08 +08:00
|
|
|
sprintf( dbg_name_string, "zmc-d%d", device );
|
2002-09-16 17:19:24 +08:00
|
|
|
dbg_name = dbg_name_string;
|
|
|
|
|
|
|
|
DbgInit();
|
|
|
|
|
|
|
|
if ( !mysql_init( &dbconn ) )
|
|
|
|
{
|
|
|
|
fprintf( stderr, "Can't initialise structure: %s\n", mysql_error( &dbconn ) );
|
|
|
|
exit( mysql_errno( &dbconn ) );
|
|
|
|
}
|
2003-01-11 01:03:03 +08:00
|
|
|
if ( !mysql_connect( &dbconn, ZM_DB_SERVER, ZM_DB_USERA, ZM_DB_PASSA ) )
|
2002-09-16 17:19:24 +08:00
|
|
|
{
|
|
|
|
fprintf( stderr, "Can't connect to server: %s\n", mysql_error( &dbconn ) );
|
|
|
|
exit( mysql_errno( &dbconn ) );
|
|
|
|
}
|
2003-01-11 01:03:03 +08:00
|
|
|
if ( mysql_select_db( &dbconn, ZM_DB_NAME ) )
|
2002-09-16 17:19:24 +08:00
|
|
|
{
|
|
|
|
fprintf( stderr, "Can't select database: %s\n", mysql_error( &dbconn ) );
|
|
|
|
exit( mysql_errno( &dbconn ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
Monitor **monitors = 0;
|
|
|
|
int n_monitors = Monitor::Load( device, monitors );
|
|
|
|
|
|
|
|
Info(( "Starting Capture" ));
|
|
|
|
sigset_t block_set;
|
|
|
|
sigemptyset( &block_set );
|
|
|
|
struct sigaction action, old_action;
|
2002-12-24 20:02:08 +08:00
|
|
|
|
2002-09-23 18:11:04 +08:00
|
|
|
action.sa_handler = term_handler;
|
|
|
|
action.sa_mask = block_set;
|
|
|
|
action.sa_flags = 0;
|
|
|
|
sigaction( SIGTERM, &action, &old_action );
|
2002-12-24 20:02:08 +08:00
|
|
|
|
2002-09-25 16:46:29 +08:00
|
|
|
//sigaddset( &block_set, SIGTERM );
|
2002-09-16 17:19:24 +08:00
|
|
|
if ( n_monitors == 1 )
|
|
|
|
{
|
|
|
|
monitors[0]->PreCapture();
|
|
|
|
}
|
|
|
|
while( 1 )
|
|
|
|
{
|
|
|
|
/* grab a new one */
|
|
|
|
sigprocmask( SIG_BLOCK, &block_set, 0 );
|
|
|
|
for ( int i = 0; i < n_monitors; i++ )
|
|
|
|
{
|
|
|
|
monitors[i]->PreCapture();
|
|
|
|
monitors[i]->PostCapture();
|
|
|
|
}
|
|
|
|
sigprocmask( SIG_UNBLOCK, &block_set, 0 );
|
2002-10-31 01:02:06 +08:00
|
|
|
if ( terminate )
|
|
|
|
{
|
|
|
|
for ( int i = 0; i < n_monitors; i++ )
|
|
|
|
{
|
|
|
|
delete monitors[i];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
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
|
|
|
}
|