2002-09-24 06:08:50 +08:00
|
|
|
//
|
2002-12-10 21:21:41 +08:00
|
|
|
// ZoneMinder Control Utility, $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-09-16 17:19:24 +08:00
|
|
|
#include <getopt.h>
|
2003-03-26 20:00:16 +08:00
|
|
|
|
2002-09-16 17:19:24 +08:00
|
|
|
#include "zm.h"
|
2003-03-26 20:00:16 +08:00
|
|
|
#include "zm_db.h"
|
2005-01-19 09:50:24 +08:00
|
|
|
#include "zm_user.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"
|
|
|
|
#include "zm_local_camera.h"
|
2002-09-16 17:19:24 +08:00
|
|
|
|
2003-01-16 22:53:26 +08:00
|
|
|
void Usage( int status=-1 )
|
2002-11-01 06:12:53 +08:00
|
|
|
{
|
2005-10-17 18:58:25 +08:00
|
|
|
fprintf( stderr, "zmu <-d device_path> [-v] [function] [-U<username> -P<password>]\n" );
|
2003-07-04 22:48:51 +08:00
|
|
|
fprintf( stderr, "zmu <-m monitor_id> [-v] [function] [-U<username> -P<password>]\n" );
|
2003-06-25 17:47:09 +08:00
|
|
|
fprintf( stderr, "General options:\n" );
|
|
|
|
fprintf( stderr, " -h, --help : This screen\n" );
|
|
|
|
fprintf( stderr, " -v, --verbose : Produce more verbose output\n" );
|
2005-11-20 20:17:45 +08:00
|
|
|
fprintf( stderr, " -l, --list : List the current status of active (or all with -v) monitors\n" );
|
2003-06-25 17:47:09 +08:00
|
|
|
fprintf( stderr, "Options for use with devices:\n" );
|
2005-10-17 18:58:25 +08:00
|
|
|
fprintf( stderr, " -d, --device <device_path> : Get the current video device settings for <device_path>\n" );
|
2003-06-25 17:47:09 +08:00
|
|
|
fprintf( stderr, " -q, --query : Query the current settings for the device\n" );
|
|
|
|
fprintf( stderr, "Options for use with monitors:\n" );
|
2002-12-11 07:29:22 +08:00
|
|
|
fprintf( stderr, " -m, --monitor <monitor_id> : Specify which monitor to address, default 1 if absent\n" );
|
2003-06-25 17:47:09 +08:00
|
|
|
fprintf( stderr, " -q, --query : Query the current settings for the monitor\n" );
|
2005-11-20 20:17:45 +08:00
|
|
|
fprintf( stderr, " -s, --state : Output the current monitor state, 0 = idle, 1 = prealarm, 2 = alarm,\n" );
|
|
|
|
fprintf( stderr, " 3 = alert, 4 = tape\n" );
|
2003-06-25 17:47:09 +08:00
|
|
|
fprintf( stderr, " -B, --brightness [value] : Output the current brightness, set to value if given \n" );
|
|
|
|
fprintf( stderr, " -C, --contrast [value] : Output the current contrast, set to value if given \n" );
|
|
|
|
fprintf( stderr, " -H, --hue [value] : Output the current hue, set to value if given \n" );
|
|
|
|
fprintf( stderr, " -O, --colour [value] : Output the current colour, set to value if given \n" );
|
2002-11-01 06:17:23 +08:00
|
|
|
fprintf( stderr, " -i, --image [image_index] : Write captured image to disk as <monitor_name>.jpg, last image captured\n" );
|
2002-11-01 06:12:53 +08:00
|
|
|
fprintf( stderr, " or specified ring buffer index if given.\n" );
|
2004-02-18 23:35:51 +08:00
|
|
|
fprintf( stderr, " -S, --scale <scale_%%ge> : With --image specify any scaling (in %%) to be applied to the image\n" );
|
2002-11-01 06:12:53 +08:00
|
|
|
fprintf( stderr, " -t, --timestamp [image_index] : Output captured image timestamp, last image captured or specified\n" );
|
|
|
|
fprintf( stderr, " ring buffer index if given\n" );
|
2005-02-24 18:43:29 +08:00
|
|
|
fprintf( stderr, " -R, --read_index : Output ring buffer read index\n" );
|
|
|
|
fprintf( stderr, " -W, --write_index : Output ring buffer write index\n" );
|
2002-11-28 00:23:04 +08:00
|
|
|
fprintf( stderr, " -e, --event : Output last event index\n" );
|
2002-11-01 06:12:53 +08:00
|
|
|
fprintf( stderr, " -f, --fps : Output last Frames Per Second captured reading\n" );
|
|
|
|
fprintf( stderr, " -z, --zones : Write last captured image overlaid with zones to <monitor_name>-Zones.jpg\n" );
|
2002-12-11 07:29:22 +08:00
|
|
|
fprintf( stderr, " -a, --alarm : Force alarm in monitor, this will trigger recording until cancelled with -c\n" );
|
2003-03-26 21:18:26 +08:00
|
|
|
fprintf( stderr, " -n, --noalarm : Force no alarms in monitor, this will prevent alarms until cancelled with -c\n" );
|
|
|
|
fprintf( stderr, " -c, --cancel : Cancel a forced alarm/noalarm in monitor, required after being enabled with -a or -n\n" );
|
2005-12-23 00:46:25 +08:00
|
|
|
fprintf( stderr, " -L, --reload : Signal monitor to reload settings\n" );
|
|
|
|
fprintf( stderr, " -E, --enable : Enable detection, wake monitor up\n" );
|
2008-02-14 06:44:37 +08:00
|
|
|
fprintf( stderr, " -D, --disable : Disable detection, put monitor to sleep\n" );
|
2005-02-24 18:43:29 +08:00
|
|
|
fprintf( stderr, " -u, --suspend : Suspend detection, useful to prevent bogus alarms when panning etc\n" );
|
|
|
|
fprintf( stderr, " -r, --resume : Resume detection after a suspend\n" );
|
2003-07-04 22:48:51 +08:00
|
|
|
fprintf( stderr, " -U, --username <username> : When running in authenticated mode the username and\n" );
|
2005-10-20 23:42:41 +08:00
|
|
|
fprintf( stderr, " -P, --password <password> : password combination of the given user\n" );
|
2005-01-19 09:50:24 +08:00
|
|
|
fprintf( stderr, " -A, --auth <authentication> : Pass authentication hash string instead of user details\n" );
|
2002-11-01 06:12:53 +08:00
|
|
|
|
2003-01-16 22:53:26 +08:00
|
|
|
exit( status );
|
2002-11-01 06:12:53 +08:00
|
|
|
}
|
|
|
|
|
2003-07-04 22:48:51 +08:00
|
|
|
typedef enum {
|
2006-01-03 17:59:32 +08:00
|
|
|
ZMU_BOGUS = 0x00000000,
|
|
|
|
ZMU_STATE = 0x00000001,
|
|
|
|
ZMU_IMAGE = 0x00000002,
|
|
|
|
ZMU_TIME = 0x00000004,
|
|
|
|
ZMU_READ_IDX = 0x00000008,
|
|
|
|
ZMU_WRITE_IDX = 0x00000010,
|
|
|
|
ZMU_EVENT = 0x00000020,
|
|
|
|
ZMU_FPS = 0x00000040,
|
|
|
|
ZMU_ZONES = 0x00000080,
|
|
|
|
ZMU_ALARM = 0x00000100,
|
|
|
|
ZMU_NOALARM = 0x00000200,
|
|
|
|
ZMU_CANCEL = 0x00000400,
|
|
|
|
ZMU_QUERY = 0x00000800,
|
|
|
|
ZMU_BRIGHTNESS = 0x00001000,
|
|
|
|
ZMU_CONTRAST = 0x00002000,
|
|
|
|
ZMU_HUE = 0x00004000,
|
|
|
|
ZMU_COLOUR = 0x00008000,
|
|
|
|
ZMU_RELOAD = 0x00010000,
|
|
|
|
ZMU_ENABLE = 0x00100000,
|
|
|
|
ZMU_DISABLE = 0x00200000,
|
|
|
|
ZMU_SUSPEND = 0x00400000,
|
|
|
|
ZMU_RESUME = 0x00800000,
|
|
|
|
ZMU_LIST = 0x10000000,
|
2003-07-04 22:48:51 +08:00
|
|
|
} Function;
|
|
|
|
|
2005-11-20 20:17:45 +08:00
|
|
|
bool ValidateAccess( User *user, int mon_id, int function )
|
2003-07-04 22:48:51 +08:00
|
|
|
{
|
2005-01-19 09:50:24 +08:00
|
|
|
bool allowed = true;
|
2006-01-03 17:59:32 +08:00
|
|
|
if ( function & (ZMU_STATE|ZMU_IMAGE|ZMU_TIME|ZMU_READ_IDX|ZMU_WRITE_IDX|ZMU_FPS) )
|
2003-07-04 22:48:51 +08:00
|
|
|
{
|
2005-01-19 09:50:24 +08:00
|
|
|
if ( user->getStream() < User::PERM_VIEW )
|
|
|
|
allowed = false;
|
|
|
|
}
|
2006-01-03 17:59:32 +08:00
|
|
|
if ( function & ZMU_EVENT )
|
2005-01-19 09:50:24 +08:00
|
|
|
{
|
|
|
|
if ( user->getEvents() < User::PERM_VIEW )
|
|
|
|
allowed = false;
|
|
|
|
}
|
2006-01-03 17:59:32 +08:00
|
|
|
if ( function & (ZMU_ZONES|ZMU_QUERY|ZMU_LIST) )
|
2005-01-19 09:50:24 +08:00
|
|
|
{
|
|
|
|
if ( user->getMonitors() < User::PERM_VIEW )
|
|
|
|
allowed = false;
|
|
|
|
}
|
2006-01-03 17:59:32 +08:00
|
|
|
if ( function & (ZMU_ALARM|ZMU_NOALARM|ZMU_CANCEL|ZMU_RELOAD|ZMU_ENABLE|ZMU_DISABLE|ZMU_SUSPEND|ZMU_RESUME|ZMU_BRIGHTNESS|ZMU_CONTRAST|ZMU_HUE|ZMU_COLOUR) )
|
2005-01-19 09:50:24 +08:00
|
|
|
{
|
|
|
|
if ( user->getMonitors() < User::PERM_EDIT )
|
|
|
|
allowed = false;
|
|
|
|
}
|
|
|
|
if ( mon_id > 0 )
|
|
|
|
{
|
|
|
|
if ( !user->canAccess( mon_id ) )
|
2003-07-04 22:48:51 +08:00
|
|
|
{
|
2005-01-19 09:50:24 +08:00
|
|
|
allowed = false;
|
2003-07-04 22:48:51 +08:00
|
|
|
}
|
|
|
|
}
|
2005-01-19 09:50:24 +08:00
|
|
|
if ( !allowed )
|
|
|
|
{
|
|
|
|
fprintf( stderr, "Error, insufficient privileges for requested action\n" );
|
|
|
|
exit( -1 );
|
|
|
|
}
|
|
|
|
return( allowed );
|
2003-07-04 22:48:51 +08:00
|
|
|
}
|
|
|
|
|
2002-10-28 22:33:57 +08:00
|
|
|
int main( int argc, char *argv[] )
|
2002-09-16 17:19:24 +08:00
|
|
|
{
|
|
|
|
static struct option long_options[] = {
|
2003-01-16 22:53:26 +08:00
|
|
|
{"device", 1, 0, 'd'},
|
2002-09-16 17:19:24 +08:00
|
|
|
{"monitor", 1, 0, 'm'},
|
2003-01-16 22:53:26 +08:00
|
|
|
{"verbose", 0, 0, 'v'},
|
2002-09-16 17:19:24 +08:00
|
|
|
{"image", 2, 0, 'i'},
|
2004-02-18 23:35:51 +08:00
|
|
|
{"scale", 1, 0, 'S'},
|
2002-09-16 17:19:24 +08:00
|
|
|
{"timestamp", 2, 0, 't'},
|
|
|
|
{"state", 0, 0, 's'},
|
2003-06-25 17:47:09 +08:00
|
|
|
{"brightness", 2, 0, 'B'},
|
|
|
|
{"contrast", 2, 0, 'C'},
|
|
|
|
{"hue", 2, 0, 'H'},
|
|
|
|
{"contrast", 2, 0, 'O'},
|
2005-02-24 18:43:29 +08:00
|
|
|
{"read_index", 0, 0, 'R'},
|
|
|
|
{"write_index", 0, 0, 'W'},
|
2002-11-28 00:23:04 +08:00
|
|
|
{"event", 0, 0, 'e'},
|
2002-09-16 17:19:24 +08:00
|
|
|
{"fps", 0, 0, 'f'},
|
2005-12-02 00:33:51 +08:00
|
|
|
{"zones", 2, 0, 'z'},
|
2002-12-11 07:29:22 +08:00
|
|
|
{"alarm", 0, 0, 'a'},
|
2003-03-26 21:18:26 +08:00
|
|
|
{"noalarm", 0, 0, 'n'},
|
2002-12-11 07:29:22 +08:00
|
|
|
{"cancel", 0, 0, 'c'},
|
2005-12-23 00:46:25 +08:00
|
|
|
{"reload", 0, 0, 'L'},
|
|
|
|
{"enable", 0, 0, 'E'},
|
|
|
|
{"disable", 0, 0, 'D'},
|
2005-02-24 18:43:29 +08:00
|
|
|
{"suspend", 0, 0, 'u'},
|
|
|
|
{"resume", 0, 0, 'r'},
|
2003-03-06 01:14:17 +08:00
|
|
|
{"query", 0, 0, 'q'},
|
2003-07-04 22:48:51 +08:00
|
|
|
{"username", 1, 0, 'U'},
|
|
|
|
{"password", 1, 0, 'P'},
|
2002-11-01 06:12:53 +08:00
|
|
|
{"help", 0, 0, 'h'},
|
2005-11-20 20:17:45 +08:00
|
|
|
{"list", 0, 0, 'l'},
|
2002-09-16 17:19:24 +08:00
|
|
|
{0, 0, 0, 0}
|
|
|
|
};
|
|
|
|
|
2005-10-17 18:58:25 +08:00
|
|
|
const char *device = "";
|
2004-03-22 17:11:42 +08:00
|
|
|
int mon_id = 0;
|
2003-01-16 22:53:26 +08:00
|
|
|
bool verbose = false;
|
2006-01-03 17:59:32 +08:00
|
|
|
int function = ZMU_BOGUS;
|
2003-01-13 18:51:52 +08:00
|
|
|
|
2002-09-16 17:19:24 +08:00
|
|
|
int image_idx = -1;
|
2004-02-18 23:35:51 +08:00
|
|
|
int scale = -1;
|
2003-06-25 17:47:09 +08:00
|
|
|
int brightness = -1;
|
|
|
|
int contrast = -1;
|
|
|
|
int hue = -1;
|
|
|
|
int colour = -1;
|
2005-11-30 01:51:06 +08:00
|
|
|
char *zone_string = 0;
|
2003-07-04 22:48:51 +08:00
|
|
|
char *username = 0;
|
|
|
|
char *password = 0;
|
2005-01-19 09:50:24 +08:00
|
|
|
char *auth = 0;
|
2002-09-16 17:19:24 +08:00
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
int option_index = 0;
|
|
|
|
|
2007-08-30 01:33:06 +08:00
|
|
|
int c = getopt_long (argc, argv, "d:m:vsEDLurwei::S:t::fz::ancqhlB::C::H::O::U:P:A:", long_options, &option_index);
|
2002-09-16 17:19:24 +08:00
|
|
|
if (c == -1)
|
2002-11-01 06:12:53 +08:00
|
|
|
{
|
2002-09-16 17:19:24 +08:00
|
|
|
break;
|
2002-11-01 06:12:53 +08:00
|
|
|
}
|
2002-09-16 17:19:24 +08:00
|
|
|
|
|
|
|
switch (c)
|
|
|
|
{
|
2003-01-16 22:53:26 +08:00
|
|
|
case 'd':
|
2005-10-17 18:58:25 +08:00
|
|
|
device = optarg;
|
2003-01-16 22:53:26 +08:00
|
|
|
break;
|
2002-09-16 17:19:24 +08:00
|
|
|
case 'm':
|
2003-01-16 22:53:26 +08:00
|
|
|
mon_id = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
verbose = true;
|
2002-09-16 17:19:24 +08:00
|
|
|
break;
|
|
|
|
case 's':
|
2006-01-03 17:59:32 +08:00
|
|
|
function |= ZMU_STATE;
|
2002-09-16 17:19:24 +08:00
|
|
|
break;
|
|
|
|
case 'i':
|
2006-01-03 17:59:32 +08:00
|
|
|
function |= ZMU_IMAGE;
|
2002-09-16 17:19:24 +08:00
|
|
|
if ( optarg )
|
|
|
|
{
|
|
|
|
image_idx = atoi( optarg );
|
|
|
|
}
|
|
|
|
break;
|
2004-02-18 23:35:51 +08:00
|
|
|
case 'S':
|
|
|
|
scale = atoi(optarg);
|
|
|
|
break;
|
2002-09-16 17:19:24 +08:00
|
|
|
case 't':
|
2006-01-03 17:59:32 +08:00
|
|
|
function |= ZMU_TIME;
|
2002-09-16 17:19:24 +08:00
|
|
|
if ( optarg )
|
|
|
|
{
|
|
|
|
image_idx = atoi( optarg );
|
|
|
|
}
|
|
|
|
break;
|
2005-02-24 18:43:29 +08:00
|
|
|
case 'R':
|
2006-01-03 17:59:32 +08:00
|
|
|
function |= ZMU_READ_IDX;
|
2002-09-16 17:19:24 +08:00
|
|
|
break;
|
2005-02-24 18:43:29 +08:00
|
|
|
case 'W':
|
2006-01-03 17:59:32 +08:00
|
|
|
function |= ZMU_WRITE_IDX;
|
2002-09-16 17:19:24 +08:00
|
|
|
break;
|
2002-11-28 00:23:04 +08:00
|
|
|
case 'e':
|
2006-01-03 17:59:32 +08:00
|
|
|
function |= ZMU_EVENT;
|
2002-11-28 00:23:04 +08:00
|
|
|
break;
|
2002-09-16 17:19:24 +08:00
|
|
|
case 'f':
|
2006-01-03 17:59:32 +08:00
|
|
|
function |= ZMU_FPS;
|
2002-09-16 17:19:24 +08:00
|
|
|
break;
|
|
|
|
case 'z':
|
2006-01-03 17:59:32 +08:00
|
|
|
function |= ZMU_ZONES;
|
2005-11-30 01:51:06 +08:00
|
|
|
if ( optarg )
|
|
|
|
{
|
|
|
|
zone_string = optarg;
|
|
|
|
}
|
2002-09-16 17:19:24 +08:00
|
|
|
break;
|
2002-12-11 07:29:22 +08:00
|
|
|
case 'a':
|
2006-01-03 17:59:32 +08:00
|
|
|
function |= ZMU_ALARM;
|
2002-12-11 07:29:22 +08:00
|
|
|
break;
|
2003-03-26 21:18:26 +08:00
|
|
|
case 'n':
|
2006-01-03 17:59:32 +08:00
|
|
|
function |= ZMU_NOALARM;
|
2003-03-26 21:18:26 +08:00
|
|
|
break;
|
2002-12-11 07:29:22 +08:00
|
|
|
case 'c':
|
2006-01-03 17:59:32 +08:00
|
|
|
function |= ZMU_CANCEL;
|
2002-12-11 07:29:22 +08:00
|
|
|
break;
|
2005-12-23 00:46:25 +08:00
|
|
|
case 'L':
|
2006-01-03 17:59:32 +08:00
|
|
|
function |= ZMU_RELOAD;
|
2005-12-23 00:46:25 +08:00
|
|
|
break;
|
|
|
|
case 'E':
|
2006-01-03 17:59:32 +08:00
|
|
|
function |= ZMU_ENABLE;
|
2005-12-23 00:46:25 +08:00
|
|
|
break;
|
|
|
|
case 'D':
|
2006-01-03 17:59:32 +08:00
|
|
|
function |= ZMU_DISABLE;
|
2005-12-23 00:46:25 +08:00
|
|
|
break;
|
2005-02-24 18:43:29 +08:00
|
|
|
case 'u':
|
2006-01-03 17:59:32 +08:00
|
|
|
function |= ZMU_SUSPEND;
|
2005-02-24 18:43:29 +08:00
|
|
|
break;
|
|
|
|
case 'r':
|
2006-01-03 17:59:32 +08:00
|
|
|
function |= ZMU_RESUME;
|
2005-02-24 18:43:29 +08:00
|
|
|
break;
|
2003-03-06 01:14:17 +08:00
|
|
|
case 'q':
|
2006-01-03 17:59:32 +08:00
|
|
|
function |= ZMU_QUERY;
|
2003-03-06 01:14:17 +08:00
|
|
|
break;
|
2003-06-25 17:47:09 +08:00
|
|
|
case 'B':
|
2006-01-03 17:59:32 +08:00
|
|
|
function |= ZMU_BRIGHTNESS;
|
2003-06-25 17:47:09 +08:00
|
|
|
if ( optarg )
|
|
|
|
{
|
|
|
|
brightness = atoi( optarg );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'C':
|
2006-01-03 17:59:32 +08:00
|
|
|
function |= ZMU_CONTRAST;
|
2003-06-25 17:47:09 +08:00
|
|
|
if ( optarg )
|
|
|
|
{
|
|
|
|
contrast = atoi( optarg );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'H':
|
2006-01-03 17:59:32 +08:00
|
|
|
function |= ZMU_HUE;
|
2003-06-25 17:47:09 +08:00
|
|
|
if ( optarg )
|
|
|
|
{
|
|
|
|
hue = atoi( optarg );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'O':
|
2006-01-03 17:59:32 +08:00
|
|
|
function |= ZMU_COLOUR;
|
2003-06-25 17:47:09 +08:00
|
|
|
if ( optarg )
|
|
|
|
{
|
|
|
|
colour = atoi( optarg );
|
|
|
|
}
|
|
|
|
break;
|
2003-07-04 22:48:51 +08:00
|
|
|
case 'U':
|
|
|
|
username = optarg;
|
|
|
|
break;
|
|
|
|
case 'P':
|
|
|
|
password = optarg;
|
|
|
|
break;
|
2005-01-19 09:50:24 +08:00
|
|
|
case 'A':
|
|
|
|
auth = optarg;
|
|
|
|
break;
|
2002-11-01 06:12:53 +08:00
|
|
|
case 'h':
|
2003-01-16 22:53:26 +08:00
|
|
|
Usage( 0 );
|
2002-11-01 06:12:53 +08:00
|
|
|
break;
|
2005-11-20 20:17:45 +08:00
|
|
|
case 'l':
|
2006-01-03 17:59:32 +08:00
|
|
|
function |= ZMU_LIST;
|
2005-11-20 20:17:45 +08:00
|
|
|
break;
|
2002-09-16 17:19:24 +08:00
|
|
|
case '?':
|
2002-11-01 06:12:53 +08:00
|
|
|
Usage();
|
2002-09-16 17:19:24 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
//fprintf( stderr, "?? getopt returned character code 0%o ??\n", c );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (optind < argc)
|
|
|
|
{
|
2002-11-01 06:12:53 +08:00
|
|
|
fprintf( stderr, "Extraneous options, " );
|
2002-09-16 17:19:24 +08:00
|
|
|
while (optind < argc)
|
2003-01-16 22:53:26 +08:00
|
|
|
fprintf( stderr, "%s ", argv[optind++]);
|
|
|
|
fprintf( stderr, "\n");
|
2002-11-01 06:12:53 +08:00
|
|
|
Usage();
|
2002-09-16 17:19:24 +08:00
|
|
|
}
|
|
|
|
|
2006-01-03 17:59:32 +08:00
|
|
|
if ( device[0] && !(function&ZMU_QUERY) )
|
2003-01-16 22:53:26 +08:00
|
|
|
{
|
2003-06-25 17:47:09 +08:00
|
|
|
fprintf( stderr, "Error, -d option cannot be used with this option\n" );
|
2003-01-16 22:53:26 +08:00
|
|
|
Usage();
|
|
|
|
}
|
2006-01-03 17:59:32 +08:00
|
|
|
if ( scale != -1 && !(function&ZMU_IMAGE) )
|
2004-02-18 23:35:51 +08:00
|
|
|
{
|
|
|
|
fprintf( stderr, "Error, -S option cannot be used with this option\n" );
|
|
|
|
Usage();
|
|
|
|
}
|
2003-01-16 22:53:26 +08:00
|
|
|
//printf( "Monitor %d, Function %d\n", mon_id, function );
|
2002-09-16 17:19:24 +08:00
|
|
|
|
2005-01-16 01:45:51 +08:00
|
|
|
zmDbgInit( "zmu", "", -1 );
|
2002-09-16 17:19:24 +08:00
|
|
|
|
2004-12-29 00:46:48 +08:00
|
|
|
zmLoadConfig();
|
2002-09-16 17:19:24 +08:00
|
|
|
|
2006-04-05 20:22:27 +08:00
|
|
|
zmSetDefaultTermHandler();
|
|
|
|
zmSetDefaultDieHandler();
|
|
|
|
|
2005-11-20 20:17:45 +08:00
|
|
|
User *user = 0;
|
|
|
|
|
2005-05-16 17:27:06 +08:00
|
|
|
if ( config.opt_use_auth )
|
2005-01-19 09:50:24 +08:00
|
|
|
{
|
2006-01-14 21:37:11 +08:00
|
|
|
if ( strcmp( config.auth_relay, "none" ) == 0 )
|
2005-01-19 09:50:24 +08:00
|
|
|
{
|
2006-01-14 21:37:11 +08:00
|
|
|
if ( !username )
|
|
|
|
{
|
|
|
|
fprintf( stderr, "Error, username must be supplied\n" );
|
|
|
|
exit( -1 );
|
|
|
|
}
|
2005-01-19 09:50:24 +08:00
|
|
|
|
2006-01-14 21:37:11 +08:00
|
|
|
if ( username )
|
2005-10-20 23:42:41 +08:00
|
|
|
{
|
2006-01-14 21:37:11 +08:00
|
|
|
user = zmLoadUser( username );
|
2005-10-20 23:42:41 +08:00
|
|
|
}
|
2005-01-19 09:50:24 +08:00
|
|
|
}
|
2006-01-14 21:37:11 +08:00
|
|
|
else
|
2005-01-19 09:50:24 +08:00
|
|
|
{
|
2006-01-14 21:37:11 +08:00
|
|
|
if ( !(username && password) && !auth )
|
|
|
|
{
|
|
|
|
fprintf( stderr, "Error, username and password or auth string must be supplied\n" );
|
|
|
|
exit( -1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
//if ( strcmp( config.auth_relay, "hashed" ) == 0 )
|
2005-10-20 23:42:41 +08:00
|
|
|
{
|
2006-01-14 21:37:11 +08:00
|
|
|
if ( auth )
|
|
|
|
{
|
|
|
|
user = zmLoadAuthUser( auth, false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//else if ( strcmp( config.auth_relay, "plain" ) == 0 )
|
|
|
|
{
|
|
|
|
if ( username && password )
|
|
|
|
{
|
|
|
|
user = zmLoadUser( username, password );
|
|
|
|
}
|
2005-10-20 23:42:41 +08:00
|
|
|
}
|
2005-01-19 09:50:24 +08:00
|
|
|
}
|
|
|
|
if ( !user )
|
|
|
|
{
|
|
|
|
fprintf( stderr, "Error, unable to authenticate user\n" );
|
|
|
|
exit( -1 );
|
|
|
|
}
|
|
|
|
ValidateAccess( user, mon_id, function );
|
|
|
|
}
|
2005-11-30 01:51:06 +08:00
|
|
|
|
2003-07-04 22:48:51 +08:00
|
|
|
|
2005-10-17 18:58:25 +08:00
|
|
|
if ( device[0] )
|
2002-09-16 17:19:24 +08:00
|
|
|
{
|
2006-01-03 17:59:32 +08:00
|
|
|
if ( function & ZMU_QUERY )
|
2003-06-25 17:47:09 +08:00
|
|
|
{
|
2003-11-05 22:49:55 +08:00
|
|
|
char vid_string[BUFSIZ] = "";
|
2005-10-17 18:58:25 +08:00
|
|
|
bool ok = LocalCamera::GetCurrentSettings( device, vid_string, verbose );
|
2003-06-25 17:47:09 +08:00
|
|
|
printf( "%s", vid_string );
|
|
|
|
exit( ok?0:-1 );
|
|
|
|
}
|
2003-01-16 22:53:26 +08:00
|
|
|
}
|
2005-11-20 20:17:45 +08:00
|
|
|
else if ( mon_id > 0 )
|
2003-01-16 22:53:26 +08:00
|
|
|
{
|
2007-12-30 02:50:53 +08:00
|
|
|
Monitor *monitor = Monitor::Load( mon_id, function&(ZMU_QUERY|ZMU_ZONES), Monitor::QUERY );
|
2003-01-16 22:53:26 +08:00
|
|
|
if ( monitor )
|
2003-01-13 18:51:52 +08:00
|
|
|
{
|
2003-01-16 22:53:26 +08:00
|
|
|
if ( verbose )
|
|
|
|
{
|
|
|
|
printf( "Monitor %d(%s)\n", monitor->Id(), monitor->Name() );
|
|
|
|
}
|
|
|
|
char separator = ' ';
|
|
|
|
bool have_output = false;
|
2006-01-03 17:59:32 +08:00
|
|
|
if ( function & ZMU_STATE )
|
2003-01-16 22:53:26 +08:00
|
|
|
{
|
|
|
|
Monitor::State state = monitor->GetState();
|
|
|
|
if ( verbose )
|
|
|
|
printf( "Current state: %s\n", state==Monitor::ALARM?"Alarm":(state==Monitor::ALERT?"Alert":"Idle") );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( have_output ) printf( "%c", separator );
|
|
|
|
printf( "%d", state );
|
|
|
|
have_output = true;
|
|
|
|
}
|
|
|
|
}
|
2006-01-03 17:59:32 +08:00
|
|
|
if ( function & ZMU_TIME )
|
2003-01-16 22:53:26 +08:00
|
|
|
{
|
2003-03-11 23:17:30 +08:00
|
|
|
struct timeval timestamp = monitor->GetTimestamp( image_idx );
|
2003-01-16 22:53:26 +08:00
|
|
|
if ( verbose )
|
|
|
|
{
|
|
|
|
char timestamp_str[64] = "None";
|
2003-03-11 23:17:30 +08:00
|
|
|
if ( timestamp.tv_sec )
|
|
|
|
strftime( timestamp_str, sizeof(timestamp_str), "%Y-%m-%d %H:%M:%S", localtime( ×tamp.tv_sec ) );
|
2003-01-16 22:53:26 +08:00
|
|
|
if ( image_idx == -1 )
|
2003-04-07 19:16:34 +08:00
|
|
|
printf( "Time of last image capture: %s.%02ld\n", timestamp_str, timestamp.tv_usec/10000 );
|
2003-01-16 22:53:26 +08:00
|
|
|
else
|
2003-04-07 19:16:34 +08:00
|
|
|
printf( "Time of image %d capture: %s.%02ld\n", image_idx, timestamp_str, timestamp.tv_usec/10000 );
|
2003-01-16 22:53:26 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( have_output ) printf( "%c", separator );
|
2003-04-07 19:16:34 +08:00
|
|
|
printf( "%ld.%02ld", timestamp.tv_sec, timestamp.tv_usec/10000 );
|
2003-01-16 22:53:26 +08:00
|
|
|
have_output = true;
|
|
|
|
}
|
|
|
|
}
|
2006-01-03 17:59:32 +08:00
|
|
|
if ( function & ZMU_READ_IDX )
|
2003-01-16 22:53:26 +08:00
|
|
|
{
|
|
|
|
if ( verbose )
|
|
|
|
printf( "Last read index: %d\n", monitor->GetLastReadIndex() );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( have_output ) printf( "%c", separator );
|
|
|
|
printf( "%d", monitor->GetLastReadIndex() );
|
|
|
|
have_output = true;
|
|
|
|
}
|
|
|
|
}
|
2006-01-03 17:59:32 +08:00
|
|
|
if ( function & ZMU_WRITE_IDX )
|
2003-01-16 22:53:26 +08:00
|
|
|
{
|
|
|
|
if ( verbose )
|
|
|
|
printf( "Last write index: %d\n", monitor->GetLastWriteIndex() );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( have_output ) printf( "%c", separator );
|
|
|
|
printf( "%d", monitor->GetLastWriteIndex() );
|
|
|
|
have_output = true;
|
|
|
|
}
|
|
|
|
}
|
2006-01-03 17:59:32 +08:00
|
|
|
if ( function & ZMU_EVENT )
|
2003-01-16 22:53:26 +08:00
|
|
|
{
|
|
|
|
if ( verbose )
|
|
|
|
printf( "Last event id: %d\n", monitor->GetLastEvent() );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( have_output ) printf( "%c", separator );
|
|
|
|
printf( "%d", monitor->GetLastEvent() );
|
|
|
|
have_output = true;
|
|
|
|
}
|
|
|
|
}
|
2006-01-03 17:59:32 +08:00
|
|
|
if ( function & ZMU_FPS )
|
2003-01-16 22:53:26 +08:00
|
|
|
{
|
|
|
|
if ( verbose )
|
2003-04-07 19:16:34 +08:00
|
|
|
printf( "Current capture rate: %.2f frames per second\n", monitor->GetFPS() );
|
2003-01-16 22:53:26 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( have_output ) printf( "%c", separator );
|
|
|
|
printf( "%.2f", monitor->GetFPS() );
|
|
|
|
have_output = true;
|
|
|
|
}
|
|
|
|
}
|
2006-01-03 17:59:32 +08:00
|
|
|
if ( function & ZMU_IMAGE )
|
2003-01-16 22:53:26 +08:00
|
|
|
{
|
|
|
|
if ( verbose )
|
|
|
|
{
|
|
|
|
if ( image_idx == -1 )
|
2004-02-18 23:35:51 +08:00
|
|
|
printf( "Dumping last image captured to %s.jpg", monitor->Name() );
|
2003-01-16 22:53:26 +08:00
|
|
|
else
|
2004-02-18 23:35:51 +08:00
|
|
|
printf( "Dumping buffer image %d to %s.jpg", image_idx, monitor->Name() );
|
|
|
|
if ( scale != -1 )
|
|
|
|
printf( ", scaling by %d%%", scale );
|
|
|
|
printf( "\n" );
|
2003-01-16 22:53:26 +08:00
|
|
|
}
|
2004-02-18 23:35:51 +08:00
|
|
|
monitor->GetImage( image_idx, scale>0?scale:100 );
|
2003-01-16 22:53:26 +08:00
|
|
|
}
|
2006-01-03 17:59:32 +08:00
|
|
|
if ( function & ZMU_ZONES )
|
2003-01-16 22:53:26 +08:00
|
|
|
{
|
|
|
|
if ( verbose )
|
|
|
|
printf( "Dumping zone image to %s-Zones.jpg\n", monitor->Name() );
|
2005-11-30 01:51:06 +08:00
|
|
|
monitor->DumpZoneImage( zone_string );
|
2003-01-16 22:53:26 +08:00
|
|
|
}
|
2006-01-03 17:59:32 +08:00
|
|
|
if ( function & ZMU_ALARM )
|
2003-01-16 22:53:26 +08:00
|
|
|
{
|
|
|
|
if ( verbose )
|
2003-03-26 21:18:26 +08:00
|
|
|
printf( "Forcing alarm on\n" );
|
2005-05-16 17:27:06 +08:00
|
|
|
monitor->ForceAlarmOn( config.forced_alarm_score, "Forced Web" );
|
2003-03-26 21:18:26 +08:00
|
|
|
}
|
2006-01-03 17:59:32 +08:00
|
|
|
if ( function & ZMU_NOALARM )
|
2003-03-26 21:18:26 +08:00
|
|
|
{
|
|
|
|
if ( verbose )
|
|
|
|
printf( "Forcing alarm off\n" );
|
|
|
|
monitor->ForceAlarmOff();
|
2003-01-16 22:53:26 +08:00
|
|
|
}
|
2006-01-03 17:59:32 +08:00
|
|
|
if ( function & ZMU_CANCEL )
|
2003-01-16 22:53:26 +08:00
|
|
|
{
|
|
|
|
if ( verbose )
|
2003-03-26 21:18:26 +08:00
|
|
|
printf( "Cancelling forced alarm on/off\n" );
|
|
|
|
monitor->CancelForced();
|
2003-01-16 22:53:26 +08:00
|
|
|
}
|
2006-01-03 17:59:32 +08:00
|
|
|
if ( function & ZMU_RELOAD )
|
2005-12-23 00:46:25 +08:00
|
|
|
{
|
|
|
|
if ( verbose )
|
|
|
|
printf( "Reloading monitor settings\n" );
|
|
|
|
monitor->actionReload();
|
|
|
|
}
|
2006-01-03 17:59:32 +08:00
|
|
|
if ( function & ZMU_ENABLE )
|
2005-12-23 00:46:25 +08:00
|
|
|
{
|
|
|
|
if ( verbose )
|
|
|
|
printf( "Enabling event generation\n" );
|
|
|
|
monitor->actionEnable();
|
|
|
|
}
|
2006-01-03 17:59:32 +08:00
|
|
|
if ( function & ZMU_DISABLE )
|
2005-12-23 00:46:25 +08:00
|
|
|
{
|
|
|
|
if ( verbose )
|
|
|
|
printf( "Disabling event generation\n" );
|
|
|
|
monitor->actionDisable();
|
|
|
|
}
|
2006-01-03 17:59:32 +08:00
|
|
|
if ( function & ZMU_SUSPEND )
|
2005-02-24 18:43:29 +08:00
|
|
|
{
|
|
|
|
if ( verbose )
|
2005-12-23 00:46:25 +08:00
|
|
|
printf( "Suspending event generation\n" );
|
|
|
|
monitor->actionSuspend();
|
2005-02-24 18:43:29 +08:00
|
|
|
}
|
2006-01-03 17:59:32 +08:00
|
|
|
if ( function & ZMU_RESUME )
|
2005-02-24 18:43:29 +08:00
|
|
|
{
|
|
|
|
if ( verbose )
|
2005-12-23 00:46:25 +08:00
|
|
|
printf( "Resuming event generation\n" );
|
|
|
|
monitor->actionResume();
|
2005-02-24 18:43:29 +08:00
|
|
|
}
|
2006-01-03 17:59:32 +08:00
|
|
|
if ( function & ZMU_QUERY )
|
2003-03-06 01:14:17 +08:00
|
|
|
{
|
2006-01-22 02:02:46 +08:00
|
|
|
char mon_string[16382] = "";
|
2003-03-06 01:14:17 +08:00
|
|
|
monitor->DumpSettings( mon_string, verbose );
|
|
|
|
printf( "%s\n", mon_string );
|
|
|
|
}
|
2006-01-03 17:59:32 +08:00
|
|
|
if ( function & ZMU_BRIGHTNESS )
|
2003-06-25 17:47:09 +08:00
|
|
|
{
|
|
|
|
if ( verbose )
|
|
|
|
{
|
|
|
|
if ( brightness >= 0 )
|
2005-12-23 00:46:25 +08:00
|
|
|
printf( "New brightness: %d\n", monitor->actionBrightness( brightness ) );
|
2003-06-25 17:47:09 +08:00
|
|
|
else
|
2005-12-23 00:46:25 +08:00
|
|
|
printf( "Current brightness: %d\n", monitor->actionBrightness() );
|
2003-06-25 17:47:09 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( have_output ) printf( "%c", separator );
|
|
|
|
if ( brightness >= 0 )
|
2005-12-23 00:46:25 +08:00
|
|
|
printf( "%d", monitor->actionBrightness( brightness ) );
|
2003-06-25 17:47:09 +08:00
|
|
|
else
|
2005-12-23 00:46:25 +08:00
|
|
|
printf( "%d", monitor->actionBrightness() );
|
2003-06-25 17:47:09 +08:00
|
|
|
have_output = true;
|
|
|
|
}
|
|
|
|
}
|
2006-01-03 17:59:32 +08:00
|
|
|
if ( function & ZMU_CONTRAST )
|
2003-06-25 17:47:09 +08:00
|
|
|
{
|
|
|
|
if ( verbose )
|
|
|
|
{
|
|
|
|
if ( contrast >= 0 )
|
2005-12-23 00:46:25 +08:00
|
|
|
printf( "New brightness: %d\n", monitor->actionContrast( contrast ) );
|
2003-06-25 17:47:09 +08:00
|
|
|
else
|
2005-12-23 00:46:25 +08:00
|
|
|
printf( "Current contrast: %d\n", monitor->actionContrast() );
|
2003-06-25 17:47:09 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( have_output ) printf( "%c", separator );
|
|
|
|
if ( contrast >= 0 )
|
2005-12-23 00:46:25 +08:00
|
|
|
printf( "%d", monitor->actionContrast( contrast ) );
|
2003-06-25 17:47:09 +08:00
|
|
|
else
|
2005-12-23 00:46:25 +08:00
|
|
|
printf( "%d", monitor->actionContrast() );
|
2003-06-25 17:47:09 +08:00
|
|
|
have_output = true;
|
|
|
|
}
|
|
|
|
}
|
2006-01-03 17:59:32 +08:00
|
|
|
if ( function & ZMU_HUE )
|
2003-06-25 17:47:09 +08:00
|
|
|
{
|
|
|
|
if ( verbose )
|
|
|
|
{
|
|
|
|
if ( hue >= 0 )
|
2005-12-23 00:46:25 +08:00
|
|
|
printf( "New hue: %d\n", monitor->actionHue( hue ) );
|
2003-06-25 17:47:09 +08:00
|
|
|
else
|
2005-12-23 00:46:25 +08:00
|
|
|
printf( "Current hue: %d\n", monitor->actionHue() );
|
2003-06-25 17:47:09 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( have_output ) printf( "%c", separator );
|
|
|
|
if ( hue >= 0 )
|
2005-12-23 00:46:25 +08:00
|
|
|
printf( "%d", monitor->actionHue( hue ) );
|
2003-06-25 17:47:09 +08:00
|
|
|
else
|
2005-12-23 00:46:25 +08:00
|
|
|
printf( "%d", monitor->actionHue() );
|
2003-06-25 17:47:09 +08:00
|
|
|
have_output = true;
|
|
|
|
}
|
|
|
|
}
|
2006-01-03 17:59:32 +08:00
|
|
|
if ( function & ZMU_COLOUR )
|
2003-06-25 17:47:09 +08:00
|
|
|
{
|
|
|
|
if ( verbose )
|
|
|
|
{
|
|
|
|
if ( colour >= 0 )
|
2005-12-23 00:46:25 +08:00
|
|
|
printf( "New colour: %d\n", monitor->actionColour( colour ) );
|
2003-06-25 17:47:09 +08:00
|
|
|
else
|
2005-12-23 00:46:25 +08:00
|
|
|
printf( "Current colour: %d\n", monitor->actionColour() );
|
2003-06-25 17:47:09 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( have_output ) printf( "%c", separator );
|
|
|
|
if ( colour >= 0 )
|
2005-12-23 00:46:25 +08:00
|
|
|
printf( "%d", monitor->actionColour( colour ) );
|
2003-06-25 17:47:09 +08:00
|
|
|
else
|
2005-12-23 00:46:25 +08:00
|
|
|
printf( "%d", monitor->actionColour() );
|
2003-06-25 17:47:09 +08:00
|
|
|
have_output = true;
|
|
|
|
}
|
|
|
|
}
|
2003-01-16 22:53:26 +08:00
|
|
|
if ( have_output )
|
|
|
|
{
|
|
|
|
printf( "\n" );
|
|
|
|
}
|
|
|
|
if ( !function )
|
|
|
|
{
|
|
|
|
Usage();
|
|
|
|
}
|
2005-11-30 01:51:06 +08:00
|
|
|
delete monitor;
|
2003-01-13 18:51:52 +08:00
|
|
|
}
|
2003-01-16 22:53:26 +08:00
|
|
|
else
|
2002-11-01 06:12:53 +08:00
|
|
|
{
|
2003-07-04 22:48:51 +08:00
|
|
|
fprintf( stderr, "Error, invalid monitor id %d\n", mon_id );
|
2003-01-16 22:53:26 +08:00
|
|
|
exit( -1 );
|
2002-11-01 06:12:53 +08:00
|
|
|
}
|
2002-09-16 17:19:24 +08:00
|
|
|
}
|
2005-11-20 20:17:45 +08:00
|
|
|
else
|
|
|
|
{
|
2006-01-03 17:59:32 +08:00
|
|
|
if ( function & ZMU_LIST )
|
2005-11-20 20:17:45 +08:00
|
|
|
{
|
|
|
|
char sql[BUFSIZ];
|
|
|
|
strncpy( sql, "select Id, Function+0 from Monitors", sizeof(sql) );
|
|
|
|
if ( !verbose )
|
|
|
|
{
|
|
|
|
strncat( sql, " where Function != 'None'", sizeof(sql)-strlen(sql) );
|
|
|
|
}
|
|
|
|
strncat( sql, " order by Id asc", sizeof(sql)-strlen(sql) );
|
|
|
|
|
|
|
|
if ( mysql_query( &dbconn, sql ) )
|
|
|
|
{
|
2008-07-14 22:43:47 +08:00
|
|
|
Error( "Can't run query: %s", mysql_error( &dbconn ) );
|
2005-11-20 20:17:45 +08:00
|
|
|
exit( mysql_errno( &dbconn ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
MYSQL_RES *result = mysql_store_result( &dbconn );
|
|
|
|
if ( !result )
|
|
|
|
{
|
2008-07-14 22:43:47 +08:00
|
|
|
Error( "Can't use query result: %s", mysql_error( &dbconn ) );
|
2005-11-20 20:17:45 +08:00
|
|
|
exit( mysql_errno( &dbconn ) );
|
|
|
|
}
|
|
|
|
int n_monitors = mysql_num_rows( result );
|
2008-07-14 22:43:47 +08:00
|
|
|
Debug( 1, "Got %d monitors", n_monitors );
|
2005-11-20 20:17:45 +08:00
|
|
|
|
|
|
|
printf( "%4s%5s%6s%9s%14s%6s%6s%8s%8s\n", "Id", "Func", "State", "TrgState", "LastImgTim", "RdIdx", "WrIdx", "LastEvt", "FrmRate" );
|
|
|
|
for( int i = 0; MYSQL_ROW dbrow = mysql_fetch_row( result ); i++ )
|
|
|
|
{
|
|
|
|
int mon_id = atoi(dbrow[0]);
|
|
|
|
int function = atoi(dbrow[1]);
|
|
|
|
if ( !user || user->canAccess( mon_id ) )
|
|
|
|
{
|
|
|
|
if ( function > 1 )
|
|
|
|
{
|
2007-12-30 02:50:53 +08:00
|
|
|
Monitor *monitor = Monitor::Load( mon_id, false, Monitor::QUERY );
|
2005-11-20 20:17:45 +08:00
|
|
|
if ( monitor )
|
|
|
|
{
|
|
|
|
struct timeval tv = monitor->GetTimestamp();
|
|
|
|
printf( "%4d%5d%6d%9d%11ld.%02ld%6d%6d%8d%8.2f\n",
|
|
|
|
monitor->Id(),
|
|
|
|
function,
|
|
|
|
monitor->GetState(),
|
|
|
|
monitor->GetTriggerState(),
|
|
|
|
tv.tv_sec, tv.tv_usec/10000,
|
|
|
|
monitor->GetLastReadIndex(),
|
|
|
|
monitor->GetLastWriteIndex(),
|
|
|
|
monitor->GetLastEvent(),
|
|
|
|
monitor->GetFPS()
|
|
|
|
);
|
|
|
|
delete monitor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
struct timeval tv = { 0, 0 };
|
|
|
|
printf( "%4d%5d%6d%9d%11ld.%02ld%6d%6d%8d%8.2f\n",
|
|
|
|
mon_id,
|
|
|
|
function,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
tv.tv_sec, tv.tv_usec/10000,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0.0
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-11-30 01:51:06 +08:00
|
|
|
mysql_free_result( result );
|
2005-11-20 20:17:45 +08:00
|
|
|
}
|
|
|
|
}
|
2005-11-30 01:51:06 +08:00
|
|
|
delete user;
|
|
|
|
|
2002-10-28 22:33:57 +08:00
|
|
|
return( 0 );
|
2002-09-16 17:19:24 +08:00
|
|
|
}
|