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:
parent
56bd41eea9
commit
64529e60ce
40
src/zma.cpp
40
src/zma.cpp
|
@ -18,23 +18,19 @@
|
|||
//
|
||||
|
||||
#include <getopt.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "zm.h"
|
||||
#include "zm_db.h"
|
||||
#include "zm_monitor.h"
|
||||
|
||||
bool reload = false;
|
||||
|
||||
void die_handler( int signal )
|
||||
void zm_die_handler( int signal )
|
||||
{
|
||||
Info(( "Got signal %d, crashing", signal ));
|
||||
exit( signal );
|
||||
}
|
||||
|
||||
void hup_handler( int signal )
|
||||
{
|
||||
Info(( "Got HUP signal, reloading" ));
|
||||
reload = true;
|
||||
}
|
||||
|
||||
void term_handler( int signal )
|
||||
void zm_term_handler( int signal )
|
||||
{
|
||||
Info(( "Got TERM signal, exiting" ));
|
||||
exit( 0 );
|
||||
|
@ -104,25 +100,11 @@ int main( int argc, char *argv[] )
|
|||
|
||||
char dbg_name_string[16];
|
||||
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 ) )
|
||||
{
|
||||
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 ) );
|
||||
}
|
||||
zmDbConnect( ZM_DB_USERA, ZM_DB_PASSA );
|
||||
|
||||
Monitor *monitor = Monitor::Load( id, true );
|
||||
|
||||
|
@ -134,12 +116,12 @@ int main( int argc, char *argv[] )
|
|||
sigemptyset( &block_set );
|
||||
struct sigaction action, old_action;
|
||||
|
||||
action.sa_handler = term_handler;
|
||||
action.sa_handler = zm_term_handler;
|
||||
action.sa_mask = block_set;
|
||||
action.sa_flags = 0;
|
||||
sigaction( SIGTERM, &action, &old_action );
|
||||
|
||||
action.sa_handler = die_handler;
|
||||
action.sa_handler = zm_die_handler;
|
||||
action.sa_mask = block_set;
|
||||
action.sa_flags = 0;
|
||||
sigaction( SIGBUS, &action, &old_action );
|
||||
|
|
105
src/zmc.cpp
105
src/zmc.cpp
|
@ -18,14 +18,18 @@
|
|||
//
|
||||
|
||||
#include <getopt.h>
|
||||
#include <signal.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" ));
|
||||
zm_terminate = true;
|
||||
zmc_terminate = true;
|
||||
}
|
||||
|
||||
void Usage()
|
||||
|
@ -40,9 +44,15 @@ void Usage()
|
|||
int main( int argc, char *argv[] )
|
||||
{
|
||||
int device = -1;
|
||||
char *host = "";
|
||||
char *port = "";
|
||||
char *path = "";
|
||||
|
||||
static struct option long_options[] = {
|
||||
{"device", 1, 0, 'd'},
|
||||
{"host", 1, 0, 'H'},
|
||||
{"port", 1, 0, 'P'},
|
||||
{"path", 1, 0, 'p'},
|
||||
{"help", 0, 0, 'h'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
@ -53,7 +63,7 @@ int main( int argc, char *argv[] )
|
|||
int option_index = 0;
|
||||
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)
|
||||
{
|
||||
break;
|
||||
|
@ -64,6 +74,15 @@ int main( int argc, char *argv[] )
|
|||
case 'd':
|
||||
device = atoi(optarg);
|
||||
break;
|
||||
case 'H':
|
||||
host = optarg;
|
||||
break;
|
||||
case 'P':
|
||||
port = optarg;
|
||||
break;
|
||||
case 'p':
|
||||
path = optarg;
|
||||
break;
|
||||
case 'h':
|
||||
case '?':
|
||||
Usage();
|
||||
|
@ -83,54 +102,72 @@ int main( int argc, char *argv[] )
|
|||
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();
|
||||
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];
|
||||
sprintf( dbg_name_string, "zmc-d%d", device );
|
||||
dbg_name = dbg_name_string;
|
||||
if ( device >= 0 )
|
||||
{
|
||||
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 ) )
|
||||
{
|
||||
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 ) );
|
||||
}
|
||||
zmDbConnect( ZM_DB_USERA, ZM_DB_PASSA );
|
||||
|
||||
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" ));
|
||||
sigset_t block_set;
|
||||
sigemptyset( &block_set );
|
||||
struct sigaction action, old_action;
|
||||
|
||||
action.sa_handler = term_handler;
|
||||
action.sa_handler = zmc_term_handler;
|
||||
action.sa_mask = block_set;
|
||||
action.sa_flags = 0;
|
||||
sigaction( SIGTERM, &action, &old_action );
|
||||
|
||||
//sigaddset( &block_set, SIGTERM );
|
||||
if ( n_monitors == 1 )
|
||||
if ( device >= 0 && n_monitors == 1 )
|
||||
{
|
||||
monitors[0]->PreCapture();
|
||||
}
|
||||
while( 1 )
|
||||
while( !zmc_terminate )
|
||||
{
|
||||
/* grab a new one */
|
||||
sigprocmask( SIG_BLOCK, &block_set, 0 );
|
||||
|
@ -140,14 +177,10 @@ int main( int argc, char *argv[] )
|
|||
monitors[i]->PostCapture();
|
||||
}
|
||||
sigprocmask( SIG_UNBLOCK, &block_set, 0 );
|
||||
if ( zm_terminate )
|
||||
{
|
||||
for ( int i = 0; i < n_monitors; i++ )
|
||||
{
|
||||
delete monitors[i];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
for ( int i = 0; i < n_monitors; i++ )
|
||||
{
|
||||
delete monitors[i];
|
||||
}
|
||||
return( 0 );
|
||||
}
|
||||
|
|
22
src/zms.cpp
22
src/zms.cpp
|
@ -18,6 +18,8 @@
|
|||
//
|
||||
|
||||
#include "zm.h"
|
||||
#include "zm_db.h"
|
||||
#include "zm_monitor.h"
|
||||
|
||||
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 ) )
|
||||
{
|
||||
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 ) );
|
||||
}
|
||||
zmDbConnect( ZM_DB_USERA, ZM_DB_PASSA );
|
||||
|
||||
if ( !event )
|
||||
{
|
||||
|
|
30
src/zmu.cpp
30
src/zmu.cpp
|
@ -18,7 +18,11 @@
|
|||
//
|
||||
|
||||
#include <getopt.h>
|
||||
|
||||
#include "zm.h"
|
||||
#include "zm_db.h"
|
||||
#include "zm_monitor.h"
|
||||
#include "zm_local_camera.h"
|
||||
|
||||
void Usage( int status=-1 )
|
||||
{
|
||||
|
@ -180,26 +184,12 @@ int main( int argc, char *argv[] )
|
|||
}
|
||||
//printf( "Monitor %d, Function %d\n", mon_id, function );
|
||||
|
||||
dbg_name = "zmu";
|
||||
dbg_level = -1;
|
||||
zm_dbg_name = "zmu";
|
||||
zm_dbg_level = -1;
|
||||
|
||||
DbgInit();
|
||||
zmDbgInit();
|
||||
|
||||
if ( !mysql_init( &dbconn ) )
|
||||
{
|
||||
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 ) );
|
||||
}
|
||||
zmDbConnect( ZM_DB_USERB, ZM_DB_PASSB );
|
||||
|
||||
if ( dev_id >= 0 )
|
||||
{
|
||||
|
@ -210,7 +200,7 @@ int main( int argc, char *argv[] )
|
|||
}
|
||||
else
|
||||
{
|
||||
Monitor *monitor = Monitor::Load( mon_id, function&QUERY );
|
||||
Monitor *monitor = Monitor::Load( mon_id, function&(QUERY|ZONES) );
|
||||
|
||||
if ( monitor )
|
||||
{
|
||||
|
@ -311,7 +301,7 @@ int main( int argc, char *argv[] )
|
|||
{
|
||||
if ( verbose )
|
||||
printf( "Dumping zone image to %s-Zones.jpg\n", monitor->Name() );
|
||||
monitor->ReloadZones();
|
||||
monitor->DumpZoneImage();
|
||||
}
|
||||
if ( function & ALARM )
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue