MythTV  master
zmserver.h
Go to the documentation of this file.
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 #include <cstdint>
20 #include <map>
21 #include <mysql/mysql.h>
22 #include <sstream>
23 #include <string>
24 #include <unistd.h>
25 #include <vector>
26 
27 using namespace std;
28 
29 extern bool checkVersion(int major, int minor, int revision);
30 extern void loadZMConfig(const string &configfile);
31 extern void connectToDatabase(void);
32 extern void kickDatabase(bool debug);
33 
34 // these are shared by all ZMServer's
35 extern MYSQL g_dbConn;
36 extern string g_zmversion;
37 extern string g_password;
38 extern string g_server;
39 extern string g_database;
40 extern string g_webPath;
41 extern string g_user;
42 extern string g_webUser;
43 extern string g_binPath;
44 extern int g_majorVersion;
45 extern int g_minorVersion;
46 extern int g_revisionVersion;
47 
48 #define DB_CHECK_TIME 60
49 extern time_t g_lastDBKick;
50 
51 const string FUNCTION_MONITOR = "Monitor";
52 const string FUNCTION_MODECT = "Modect";
53 const string FUNCTION_NODECT = "Nodect";
54 const string FUNCTION_RECORD = "Record";
55 const string FUNCTION_MOCORD = "Mocord";
56 const string FUNCTION_NONE = "None";
57 
58 const string RESTART = "restart";
59 const string RELOAD = "reload";
60 const string RUNNING = "running";
61 
62 enum State
63 {
69 };
70 
71 // shared data for ZM version 1.24.x and 1.25.x
72 struct SharedData
73 {
74  int size;
75  bool valid;
76  bool active;
77  bool signal;
84  int action;
86  int hue;
87  int colour;
88  int contrast;
89  int alarm_x;
90  int alarm_y;
91  char control_state[256];
92 };
93 
94 // shared data for ZM version 1.26.x
96 {
97  uint32_t size;
98  uint32_t last_write_index;
99  uint32_t last_read_index;
100  uint32_t state;
101  uint32_t last_event;
102  uint32_t action;
103  int32_t brightness;
104  int32_t hue;
105  int32_t colour;
106  int32_t contrast;
107  int32_t alarm_x;
108  int32_t alarm_y;
109  uint8_t valid;
110  uint8_t active;
111  uint8_t signal;
112  uint8_t format;
113  uint32_t imagesize;
114  uint32_t epadding1;
115  uint32_t epadding2;
116  union {
118  uint64_t extrapad1;
119  };
120  union {
122  uint64_t extrapad2;
123  };
124  uint8_t control_state[256];
125 };
126 
127 // shared data for ZM version 1.32.x
129 {
130  uint32_t size;
132  uint32_t last_read_index;
133  uint32_t state;
134  uint64_t last_event;
135  uint32_t action;
136  int32_t brightness;
137  int32_t hue;
138  int32_t colour;
139  int32_t contrast;
140  int32_t alarm_x;
141  int32_t alarm_y;
142  uint8_t valid;
143  uint8_t active;
144  uint8_t signal;
145  uint8_t format;
146  uint32_t imagesize;
147  uint32_t epadding1;
148  union {
149  time_t startup_time;
150  uint64_t extrapad1;
151  };
152  union {
154  uint64_t extrapad2;
155  };
156  union {
158  uint64_t extrapad3;
159  };
160  uint8_t control_state[256];
161 
162  char alarm_cause[256];
163 };
164 
166 
167 // Triggerdata for ZM version 1.24.x and 1.25.x
169 {
170  int size;
173  char trigger_cause[32];
174  char trigger_text[256];
175  char trigger_showtext[256];
176 };
177 
178 // Triggerdata for ZM version 1.26.x and 1.32.x
180 {
181  uint32_t size;
182  uint32_t trigger_state;
183  uint32_t trigger_score;
184  uint32_t padding;
185  char trigger_cause[32];
186  char trigger_text[256];
187  char trigger_showtext[256];
188 };
189 
190 // VideoStoreData for ZM version 1.32.x
192 {
193  uint32_t size;
194  uint64_t current_event;
195  char event_file[4096];
196  timeval recording;
197 };
198 
199 class MONITOR
200 {
201  public:
202  MONITOR() = default;
203 
204  void initMonitor(bool debug, const string &mmapPath, int shmKey);
205 
206  bool isValid(void);
207 
208  string getIdStr(void);
209  int getLastWriteIndex(void);
210  int getSubpixelOrder(void);
211  int getState(void);
212  int getFrameSize(void);
213 
214  string m_name {""};
215  string m_type {""};
216  string m_function {""};
217  int m_enabled {0};
218  string m_device {""};
219  string m_host {""};
220  int m_image_buffer_count {0};
221  int m_width {0};
222  int m_height {0};
223  int m_bytes_per_pixel {3};
224  int m_mon_id {0};
225  unsigned char *m_shared_images {nullptr};
226  int m_last_read {0};
227  string m_status {""};
228  int m_palette {0};
229  int m_controllable {0};
230  int m_trackMotion {0};
231  int m_mapFile {-1};
232  void *m_shm_ptr {nullptr};
233  private:
234  SharedData *m_shared_data {nullptr};
235  SharedData26 *m_shared_data26 {nullptr};
236  SharedData32 *m_shared_data32 {nullptr};
237  string m_id {""};
238 };
239 
240 class ZMServer
241 {
242  public:
243  ZMServer(int sock, bool debug);
244  ~ZMServer();
245 
246  bool processRequest(char* buf, int nbytes);
247 
248  private:
249  string getZMSetting(const string &setting);
250  bool send(const string &s) const;
251  bool send(const string &s, const unsigned char *buffer, int dataLen) const;
252  void sendError(const string &error);
253  void getMonitorList(void);
254  static int getFrame(unsigned char *buffer, int bufferSize, MONITOR *monitor);
255  static long long getDiskSpace(const string &filename, long long &total, long long &used);
256  static void tokenize(const string &command, vector<string> &tokens);
257  void handleHello(void);
258  static string runCommand(const string& command);
259  static void getMonitorStatus(const string &id, const string &type,
260  const string &device, const string &host,
261  const string &channel, const string &function,
262  string &zmcStatus, string &zmaStatus,
263  const string &enabled);
264  void handleGetServerStatus(void);
265  void handleGetMonitorStatus(void);
266  void handleGetAlarmStates(void);
267  void handleGetMonitorList(void);
268  void handleGetCameraList(void);
269  void handleGetEventList(vector<string> tokens);
270  void handleGetEventFrame(vector<string> tokens);
271  void handleGetAnalysisFrame(vector<string> tokens);
272  void handleGetLiveFrame(vector<string> tokens);
273  void handleGetFrameList(vector<string> tokens);
274  void handleDeleteEvent(vector<string> tokens);
275  void handleDeleteEventList(vector<string> tokens);
276  void handleGetEventDates(vector<string> tokens);
277  void handleRunZMAudit(void);
278  void handleSetMonitorFunction(vector<string> tokens);
279  void zmcControl(MONITOR *monitor, const string &mode);
280  void zmaControl(MONITOR *monitor, const string &mode);
281 
282  bool m_debug {false};
283  int m_sock {-1};
284  vector<MONITOR *> m_monitors;
285  map<int, MONITOR *> m_monitorMap;
286  bool m_useDeepStorage {false};
287  bool m_useAnalysisImages {false};
290  key_t m_shmKey;
291  string m_mmapPath;
292  char m_buf[10] {0};
293 };
294 
295 
296 #endif
int32_t alarm_x
Definition: zmserver.h:140
int32_t brightness
Definition: zmserver.h:103
string g_database
Definition: zmserver.cpp:85
uint32_t last_read_index
Definition: zmserver.h:99
const string FUNCTION_MODECT
Definition: zmserver.h:52
uint8_t signal
Definition: zmserver.h:111
const string RUNNING
Definition: zmserver.h:60
int32_t hue
Definition: zmserver.h:104
int alarm_x
Definition: zmserver.h:89
string g_webPath
Definition: zmserver.cpp:86
string g_user
Definition: zmserver.cpp:87
int alarm_y
Definition: zmserver.h:90
int trigger_score
Definition: zmserver.h:172
string g_server
Definition: zmserver.cpp:84
uint8_t active
Definition: zmserver.h:110
uint32_t size
Definition: zmserver.h:181
static void error(const char *str,...)
Definition: vbi.c:42
uint32_t size
Definition: zmserver.h:193
void connectToDatabase(void)
Definition: zmserver.cpp:186
key_t m_shmKey
Definition: zmserver.h:290
uint64_t extrapad1
Definition: zmserver.h:118
uint64_t last_event
Definition: zmserver.h:134
int32_t colour
Definition: zmserver.h:138
const string RESTART
Definition: zmserver.h:58
uint32_t action
Definition: zmserver.h:102
int last_event
Definition: zmserver.h:83
Definition: zmserver.h:68
int32_t hue
Definition: zmserver.h:137
const string FUNCTION_NONE
Definition: zmserver.h:56
State
Definition: zmserver.h:62
State state
Definition: zmserver.h:78
uint8_t format
Definition: zmserver.h:145
int last_read_index
Definition: zmserver.h:80
string m_eventFileFormat
Definition: zmserver.h:288
uint32_t last_read_index
Definition: zmserver.h:132
bool valid
Definition: zmserver.h:75
uint32_t state
Definition: zmserver.h:100
int brightness
Definition: zmserver.h:85
uint32_t imagesize
Definition: zmserver.h:146
string g_binPath
Definition: zmserver.cpp:89
int g_revisionVersion
Definition: zmserver.cpp:94
bool checkVersion(int major, int minor, int revision)
Definition: zmserver.cpp:99
uint32_t imagesize
Definition: zmserver.h:113
int action
Definition: zmserver.h:84
uint32_t size
Definition: zmserver.h:130
vector< MONITOR * > m_monitors
Definition: zmserver.h:284
uint32_t size
Definition: zmserver.h:97
uint64_t current_event
Definition: zmserver.h:194
const string FUNCTION_MOCORD
Definition: zmserver.h:55
map< int, MONITOR * > m_monitorMap
Definition: zmserver.h:285
int32_t contrast
Definition: zmserver.h:139
void kickDatabase(bool debug)
Definition: zmserver.cpp:211
uint32_t padding
Definition: zmserver.h:184
const string FUNCTION_RECORD
Definition: zmserver.h:54
int32_t brightness
Definition: zmserver.h:136
int contrast
Definition: zmserver.h:88
#define minor(X)
Definition: compat.h:138
int hue
Definition: zmserver.h:86
int g_majorVersion
Definition: zmserver.cpp:92
int size
Definition: zmserver.h:74
timeval recording
Definition: zmserver.h:196
int colour
Definition: zmserver.h:87
time_t last_read_time
Definition: zmserver.h:157
uint32_t state
Definition: zmserver.h:133
uint8_t signal
Definition: zmserver.h:144
uint32_t last_event
Definition: zmserver.h:101
const char * m_name
Definition: ParseText.cpp:328
time_t last_write_time
Definition: zmserver.h:153
int64_t getDiskSpace(const QString &file_on_disk, int64_t &total, int64_t &used)
time_t g_lastDBKick
Definition: zmserver.cpp:96
string g_zmversion
Definition: zmserver.cpp:82
int32_t contrast
Definition: zmserver.h:106
const string FUNCTION_NODECT
Definition: zmserver.h:53
time_t last_write_time
Definition: zmserver.h:117
uint32_t last_write_index
Definition: zmserver.h:131
uint8_t format
Definition: zmserver.h:112
time_t last_write_time
Definition: zmserver.h:81
uint64_t extrapad1
Definition: zmserver.h:150
Definition: zmserver.h:66
VERBOSE_PREAMBLE Most debug(nodatabase, notimestamp, noextra)") VERBOSE_MAP(VB_GENERAL
time_t last_read_time
Definition: zmserver.h:82
int32_t alarm_y
Definition: zmserver.h:108
time_t last_read_time
Definition: zmserver.h:121
uint8_t valid
Definition: zmserver.h:109
time_t startup_time
Definition: zmserver.h:149
Definition: zmserver.h:64
int32_t alarm_x
Definition: zmserver.h:107
MYSQL g_dbConn
Definition: zmserver.cpp:81
uint32_t trigger_score
Definition: zmserver.h:183
void loadZMConfig(const string &configfile)
Definition: zmserver.cpp:106
uint32_t epadding1
Definition: zmserver.h:147
uint8_t active
Definition: zmserver.h:143
uint32_t last_write_index
Definition: zmserver.h:98
def runCommand(command)
Runs an external command checking to see if the user has cancelled the DVD creation process.
Definition: mythburn.py:471
int32_t colour
Definition: zmserver.h:105
Definition: zmserver.h:67
string g_webUser
Definition: zmserver.cpp:88
int32_t alarm_y
Definition: zmserver.h:141
const string FUNCTION_MONITOR
Definition: zmserver.h:51
int last_write_index
Definition: zmserver.h:79
bool active
Definition: zmserver.h:76
string m_analysisFileFormat
Definition: zmserver.h:289
const string RELOAD
Definition: zmserver.h:59
TriggerState
Definition: zmserver.h:165
uint8_t valid
Definition: zmserver.h:142
bool signal
Definition: zmserver.h:77
uint32_t epadding1
Definition: zmserver.h:114
string g_password
Definition: zmserver.cpp:83
TriggerState trigger_state
Definition: zmserver.h:171
int g_minorVersion
Definition: zmserver.cpp:93
uint32_t action
Definition: zmserver.h:135
uint64_t extrapad3
Definition: zmserver.h:158
uint64_t extrapad2
Definition: zmserver.h:122
uint32_t epadding2
Definition: zmserver.h:115
uint32_t trigger_state
Definition: zmserver.h:182
string m_mmapPath
Definition: zmserver.h:291
uint64_t extrapad2
Definition: zmserver.h:154