Updated fro remote cameras and DB functions.

git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@412 e3e1d417-86f3-4887-817a-d78f3d33393f
This commit is contained in:
stan 2003-03-26 12:00:16 +00:00
parent 56bd41eea9
commit 64529e60ce
4 changed files with 95 additions and 102 deletions

View File

@ -18,23 +18,19 @@
// //
#include <getopt.h> #include <getopt.h>
#include <signal.h>
#include "zm.h" #include "zm.h"
#include "zm_db.h"
#include "zm_monitor.h"
bool reload = false; void zm_die_handler( int signal )
void die_handler( int signal )
{ {
Info(( "Got signal %d, crashing", signal )); Info(( "Got signal %d, crashing", signal ));
exit( signal ); exit( signal );
} }
void hup_handler( int signal ) void zm_term_handler( int signal )
{
Info(( "Got HUP signal, reloading" ));
reload = true;
}
void term_handler( int signal )
{ {
Info(( "Got TERM signal, exiting" )); Info(( "Got TERM signal, exiting" ));
exit( 0 ); exit( 0 );
@ -104,25 +100,11 @@ int main( int argc, char *argv[] )
char dbg_name_string[16]; char dbg_name_string[16];
sprintf( dbg_name_string, "zma-m%d", id ); sprintf( dbg_name_string, "zma-m%d", id );
dbg_name = dbg_name_string; zm_dbg_name = dbg_name_string;
DbgInit(); zmDbgInit();
if ( !mysql_init( &dbconn ) ) zmDbConnect( ZM_DB_USERA, ZM_DB_PASSA );
{
fprintf( stderr, "Can't initialise structure: %s\n", mysql_error( &dbconn ) );
exit( mysql_errno( &dbconn ) );
}
if ( !mysql_connect( &dbconn, ZM_DB_SERVER, ZM_DB_USERA, ZM_DB_PASSA ) )
{
fprintf( stderr, "Can't connect to server: %s\n", mysql_error( &dbconn ) );
exit( mysql_errno( &dbconn ) );
}
if ( mysql_select_db( &dbconn, ZM_DB_NAME ) )
{
fprintf( stderr, "Can't select database: %s\n", mysql_error( &dbconn ) );
exit( mysql_errno( &dbconn ) );
}
Monitor *monitor = Monitor::Load( id, true ); Monitor *monitor = Monitor::Load( id, true );
@ -134,12 +116,12 @@ int main( int argc, char *argv[] )
sigemptyset( &block_set ); sigemptyset( &block_set );
struct sigaction action, old_action; struct sigaction action, old_action;
action.sa_handler = term_handler; action.sa_handler = zm_term_handler;
action.sa_mask = block_set; action.sa_mask = block_set;
action.sa_flags = 0; action.sa_flags = 0;
sigaction( SIGTERM, &action, &old_action ); sigaction( SIGTERM, &action, &old_action );
action.sa_handler = die_handler; action.sa_handler = zm_die_handler;
action.sa_mask = block_set; action.sa_mask = block_set;
action.sa_flags = 0; action.sa_flags = 0;
sigaction( SIGBUS, &action, &old_action ); sigaction( SIGBUS, &action, &old_action );

View File

@ -18,14 +18,18 @@
// //
#include <getopt.h> #include <getopt.h>
#include <signal.h>
#include "zm.h" #include "zm.h"
#include "zm_db.h"
#include "zm_monitor.h"
bool zm_terminate = false; bool zmc_terminate = false;
void term_handler( int signal ) void zmc_term_handler( int signal )
{ {
Info(( "Got TERM signal, exiting" )); Info(( "Got TERM signal, exiting" ));
zm_terminate = true; zmc_terminate = true;
} }
void Usage() void Usage()
@ -40,9 +44,15 @@ void Usage()
int main( int argc, char *argv[] ) int main( int argc, char *argv[] )
{ {
int device = -1; int device = -1;
char *host = "";
char *port = "";
char *path = "";
static struct option long_options[] = { static struct option long_options[] = {
{"device", 1, 0, 'd'}, {"device", 1, 0, 'd'},
{"host", 1, 0, 'H'},
{"port", 1, 0, 'P'},
{"path", 1, 0, 'p'},
{"help", 0, 0, 'h'}, {"help", 0, 0, 'h'},
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
@ -53,7 +63,7 @@ int main( int argc, char *argv[] )
int option_index = 0; int option_index = 0;
int opterr = 1; int opterr = 1;
int c = getopt_long (argc, argv, "d:h", long_options, &option_index); int c = getopt_long (argc, argv, "d:H:P:p:h", long_options, &option_index);
if (c == -1) if (c == -1)
{ {
break; break;
@ -64,6 +74,15 @@ int main( int argc, char *argv[] )
case 'd': case 'd':
device = atoi(optarg); device = atoi(optarg);
break; break;
case 'H':
host = optarg;
break;
case 'P':
port = optarg;
break;
case 'p':
path = optarg;
break;
case 'h': case 'h':
case '?': case '?':
Usage(); Usage();
@ -83,54 +102,72 @@ int main( int argc, char *argv[] )
Usage(); Usage();
} }
if ( device < 0 ) if ( device >= 0 && host[0] )
{ {
fprintf( stderr, "Bogus device %d\n", device ); fprintf( stderr, "Only one of device or host/port/path allowed\n" );
Usage(); Usage();
exit( 0 ); exit( 0 );
} }
if ( device < 0 && !host[0] )
{
fprintf( stderr, "One of device or host/port/path must be specified\n" );
Usage();
exit( 0 );
}
zm_dbg_name = "zmc";
char dbg_name_string[16]; char dbg_name_string[16];
sprintf( dbg_name_string, "zmc-d%d", device ); if ( device >= 0 )
dbg_name = dbg_name_string; {
sprintf( dbg_name_string, "zmc-d%d", device );
}
else
{
sprintf( dbg_name_string, "zmc-h%s", host );
}
zm_dbg_name = dbg_name_string;
DbgInit(); zmDbgInit();
if ( !mysql_init( &dbconn ) ) zmDbConnect( ZM_DB_USERA, ZM_DB_PASSA );
{
fprintf( stderr, "Can't initialise structure: %s\n", mysql_error( &dbconn ) );
exit( mysql_errno( &dbconn ) );
}
if ( !mysql_connect( &dbconn, ZM_DB_SERVER, ZM_DB_USERA, ZM_DB_PASSA ) )
{
fprintf( stderr, "Can't connect to server: %s\n", mysql_error( &dbconn ) );
exit( mysql_errno( &dbconn ) );
}
if ( mysql_select_db( &dbconn, ZM_DB_NAME ) )
{
fprintf( stderr, "Can't select database: %s\n", mysql_error( &dbconn ) );
exit( mysql_errno( &dbconn ) );
}
Monitor **monitors = 0; Monitor **monitors = 0;
int n_monitors = Monitor::Load( device, monitors ); int n_monitors = 0;
if ( device >= 0 )
{
n_monitors = Monitor::Load( device, monitors );
}
else
{
if ( !port )
port = "80";
n_monitors = Monitor::Load( host, port, path, monitors );
}
if ( !n_monitors )
{
Error(( "No monitors found" ));
exit ( -1 );
}
Info(( "Starting Capture" )); Info(( "Starting Capture" ));
sigset_t block_set; sigset_t block_set;
sigemptyset( &block_set ); sigemptyset( &block_set );
struct sigaction action, old_action; struct sigaction action, old_action;
action.sa_handler = term_handler; action.sa_handler = zmc_term_handler;
action.sa_mask = block_set; action.sa_mask = block_set;
action.sa_flags = 0; action.sa_flags = 0;
sigaction( SIGTERM, &action, &old_action ); sigaction( SIGTERM, &action, &old_action );
//sigaddset( &block_set, SIGTERM ); //sigaddset( &block_set, SIGTERM );
if ( n_monitors == 1 ) if ( device >= 0 && n_monitors == 1 )
{ {
monitors[0]->PreCapture(); monitors[0]->PreCapture();
} }
while( 1 ) while( !zmc_terminate )
{ {
/* grab a new one */ /* grab a new one */
sigprocmask( SIG_BLOCK, &block_set, 0 ); sigprocmask( SIG_BLOCK, &block_set, 0 );
@ -140,14 +177,10 @@ int main( int argc, char *argv[] )
monitors[i]->PostCapture(); monitors[i]->PostCapture();
} }
sigprocmask( SIG_UNBLOCK, &block_set, 0 ); sigprocmask( SIG_UNBLOCK, &block_set, 0 );
if ( zm_terminate ) }
{ for ( int i = 0; i < n_monitors; i++ )
for ( int i = 0; i < n_monitors; i++ ) {
{ delete monitors[i];
delete monitors[i];
}
break;
}
} }
return( 0 ); return( 0 );
} }

View File

@ -18,6 +18,8 @@
// //
#include "zm.h" #include "zm.h"
#include "zm_db.h"
#include "zm_monitor.h"
int main( int argc, const char *argv[] ) int main( int argc, const char *argv[] )
{ {
@ -61,25 +63,11 @@ int main( int argc, const char *argv[] )
} }
} }
dbg_name = "zms"; zm_dbg_name = "zms";
DbgInit(); zmDbgInit();
if ( !mysql_init( &dbconn ) ) zmDbConnect( ZM_DB_USERA, ZM_DB_PASSA );
{
fprintf( stderr, "Can't initialise structure: %s\n", mysql_error( &dbconn ) );
exit( mysql_errno( &dbconn ) );
}
if ( !mysql_connect( &dbconn, ZM_DB_SERVER, ZM_DB_USERB, ZM_DB_PASSB ) )
{
fprintf( stderr, "Can't connect to server: %s\n", mysql_error( &dbconn ) );
exit( mysql_errno( &dbconn ) );
}
if ( mysql_select_db( &dbconn, ZM_DB_NAME ) )
{
fprintf( stderr, "Can't select database: %s\n", mysql_error( &dbconn ) );
exit( mysql_errno( &dbconn ) );
}
if ( !event ) if ( !event )
{ {

View File

@ -18,7 +18,11 @@
// //
#include <getopt.h> #include <getopt.h>
#include "zm.h" #include "zm.h"
#include "zm_db.h"
#include "zm_monitor.h"
#include "zm_local_camera.h"
void Usage( int status=-1 ) void Usage( int status=-1 )
{ {
@ -180,26 +184,12 @@ int main( int argc, char *argv[] )
} }
//printf( "Monitor %d, Function %d\n", mon_id, function ); //printf( "Monitor %d, Function %d\n", mon_id, function );
dbg_name = "zmu"; zm_dbg_name = "zmu";
dbg_level = -1; zm_dbg_level = -1;
DbgInit(); zmDbgInit();
if ( !mysql_init( &dbconn ) ) zmDbConnect( ZM_DB_USERB, ZM_DB_PASSB );
{
fprintf( stderr, "Can't initialise structure: %s\n", mysql_error( &dbconn ) );
exit( mysql_errno( &dbconn ) );
}
if ( !mysql_connect( &dbconn, ZM_DB_SERVER, ZM_DB_USERB, ZM_DB_PASSB ) )
{
fprintf( stderr, "Can't connect to server: %s\n", mysql_error( &dbconn ) );
exit( mysql_errno( &dbconn ) );
}
if ( mysql_select_db( &dbconn, ZM_DB_NAME ) )
{
fprintf( stderr, "Can't select database: %s\n", mysql_error( &dbconn ) );
exit( mysql_errno( &dbconn ) );
}
if ( dev_id >= 0 ) if ( dev_id >= 0 )
{ {
@ -210,7 +200,7 @@ int main( int argc, char *argv[] )
} }
else else
{ {
Monitor *monitor = Monitor::Load( mon_id, function&QUERY ); Monitor *monitor = Monitor::Load( mon_id, function&(QUERY|ZONES) );
if ( monitor ) if ( monitor )
{ {
@ -311,7 +301,7 @@ int main( int argc, char *argv[] )
{ {
if ( verbose ) if ( verbose )
printf( "Dumping zone image to %s-Zones.jpg\n", monitor->Name() ); printf( "Dumping zone image to %s-Zones.jpg\n", monitor->Name() );
monitor->ReloadZones(); monitor->DumpZoneImage();
} }
if ( function & ALARM ) if ( function & ALARM )
{ {