Ticket #5758: zmserver.h

File zmserver.h, 5.3 KB (added by noisymime@…, 17 years ago)
Line 
1/* Definition of the ZMServer class.
2 * ============================================================
3 * This program is free software; you can redistribute it
4 * and/or modify it under the terms of the GNU General
5 * Public License as published bythe Free Software Foundation;
6 * either version 2, or (at your option)
7 * any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * ============================================================ */
15
16#ifndef ZMSERVER_H
17#define ZMSERVER_H
18
19
20#include <unistd.h>
21#include <string>
22#include <sstream>
23#include <vector>
24#include <map>
25#include <mysql/mysql.h>
26
27using namespace std;
28
29extern void loadZMConfig(const string &configfile);
30extern void connectToDatabase(void);
31extern void kickDatabase(bool debug);
32
33// these are shared by all ZMServer's
34extern MYSQL g_dbConn;
35extern string g_zmversion;
36extern string g_password;
37extern string g_server;
38extern string g_database;
39extern string g_webPath;
40extern string g_user;
41extern string g_webUser;
42extern string g_binPath;
43
44#define DB_CHECK_TIME 60
45extern time_t g_lastDBKick;
46
47const string FUNCTION_MONITOR = "Monitor";
48const string FUNCTION_MODECT = "Modect";
49const string FUNCTION_NODECT = "Nodect";
50const string FUNCTION_RECORD = "Record";
51const string FUNCTION_MOCORD = "Mocord";
52const string FUNCTION_NONE = "None";
53
54const string RESTART = "restart";
55const string RELOAD = "reload";
56const string RUNNING = "running";
57
58typedef enum
59{
60 IDLE,
61 PREALARM,
62 ALARM,
63 ALERT,
64 TAPE
65} State;
66
67typedef struct
68{
69 int size;
70 bool valid;
71 bool active;
72 bool signal;
73 State state;
74 int last_write_index;
75 int last_read_index;
76 time_t last_image_time;
77 int last_event;
78 int action;
79 int brightness;
80 int hue;
81 int colour;
82 int contrast;
83 int alarm_x;
84 int alarm_y;
85 char control_state[256];
86} SharedData;
87
88typedef enum { TRIGGER_CANCEL, TRIGGER_ON, TRIGGER_OFF } TriggerState;
89
90// use this for ZM version 1.22.2
91typedef struct
92{
93 int size;
94 TriggerState trigger_state;
95 int trigger_score;
96 char trigger_cause[32];
97 char trigger_text[256];
98 char trigger_showtext[32];
99} TriggerData_old;
100
101// use this for ZM version 1.22.3 and later
102typedef struct
103{
104 int size;
105 TriggerState trigger_state;
106 int trigger_score;
107 char trigger_cause[32];
108 char trigger_text[256];
109 char trigger_showtext[256];
110} TriggerData;
111
112typedef struct
113{
114 string name;
115 string type;
116 string function;
117 int enabled;
118 string device;
119 int image_buffer_count;
120 int width;
121 int height;
122 int mon_id;
123 SharedData *shared_data;
124 unsigned char *shared_images;
125 int last_read;
126 string status;
127 int frame_size;
128 int palette;
129 int controllable;
130 int trackMotion;
131
132 string getIdStr()
133 {
134 if (id == "")
135 {
136 std::stringstream out;
137 out << mon_id;
138 id = out.str();
139 }
140 return id;
141 }
142
143 private:
144 string id;
145
146} MONITOR;
147
148class ZMServer
149{
150 public:
151 ZMServer(int sock, bool debug);
152 ~ZMServer();
153
154 void processRequest(char* buf, int nbytes);
155
156 private:
157 string getZMSetting(const string &setting, bool useDefault);
158 bool send(const string s) const;
159 bool send(const string s, const unsigned char *buffer, int dataLen) const;
160 void sendError(string error);
161 void getMonitorList(void);
162 void initMonitor(MONITOR *monitor);
163 int getFrame(unsigned char *buffer, int bufferSize, MONITOR *monitor);
164 long long getDiskSpace(const string &filename, long long &total, long long &used);
165 void tokenize(const string &command, vector<string> &tokens);
166 void handleHello(void);
167 string runCommand(string command);
168 void getMonitorStatus(string id, string type, string device, string channel,
169 string function, string &zmcStatus, string &zmaStatus,
170 string enabled);
171 void handleGetServerStatus(void);
172 void handleGetMonitorStatus(void);
173 void handleGetMonitorList(void);
174 void handleGetCameraList(void);
175 void handleGetEventList(vector<string> tokens);
176 void handleGetEventFrame(vector<string> tokens);
177 void handleGetAnalyseFrame(vector<string> tokens);
178 void handleGetLiveFrame(vector<string> tokens);
179 void handleGetFrameList(vector<string> tokens);
180 void handleDeleteEvent(vector<string> tokens);
181 void handleDeleteEventList(vector<string> tokens);
182 void handleGetEventDates(vector<string> tokens);
183 void handleRunZMAudit(void);
184 void handleSetMonitorFunction(vector<string> tokens);
185 void zmcControl(MONITOR *monitor, const string &mode);
186 void zmaControl(MONITOR *monitor, const string &mode);
187
188 bool m_debug;
189 int m_sock;
190 map<int, MONITOR *> m_monitors;
191 string m_eventFileFormat;
192 string m_analyseFileFormat;
193 key_t m_shmKey;
194 key_t m_defaultShmKey;
195};
196
197
198#endif