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 {
68  TAPE
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_imageBufferCount {0};
221  int m_width {0};
222  int m_height {0};
223  int m_bytesPerPixel {3};
224  int m_monId {0};
225  unsigned char *m_sharedImages {nullptr};
226  int m_lastRead {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_shmPtr {nullptr};
233  private:
234  SharedData *m_sharedData {nullptr};
235  SharedData26 *m_sharedData26 {nullptr};
236  SharedData32 *m_sharedData32 {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) const;
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
connectToDatabase
void connectToDatabase(void)
Definition: zmserver.cpp:186
ZMServer::m_shmKey
key_t m_shmKey
Definition: zmserver.h:290
SharedData26::imagesize
uint32_t imagesize
Definition: zmserver.h:113
SharedData32::last_read_time
time_t last_read_time
Definition: zmserver.h:157
TRIGGER_ON
@ TRIGGER_ON
Definition: zmserver.h:165
SharedData26::format
uint8_t format
Definition: zmserver.h:112
channel
QDomElement channel
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:498
SharedData32::last_event
uint64_t last_event
Definition: zmserver.h:134
RELOAD
const string RELOAD
Definition: zmserver.h:59
SharedData32::extrapad1
uint64_t extrapad1
Definition: zmserver.h:150
g_webUser
string g_webUser
Definition: zmserver.cpp:88
SharedData32::active
uint8_t active
Definition: zmserver.h:143
TRIGGER_CANCEL
@ TRIGGER_CANCEL
Definition: zmserver.h:165
SharedData::alarm_y
int alarm_y
Definition: zmserver.h:90
SharedData26::contrast
int32_t contrast
Definition: zmserver.h:106
SharedData::signal
bool signal
Definition: zmserver.h:77
error
static void error(const char *str,...)
Definition: vbi.cpp:42
SharedData32::alarm_x
int32_t alarm_x
Definition: zmserver.h:140
SharedData26::alarm_y
int32_t alarm_y
Definition: zmserver.h:108
IDLE
@ IDLE
Definition: zmserver.h:64
SharedData26::valid
uint8_t valid
Definition: zmserver.h:109
getDiskSpace
int64_t getDiskSpace(const QString &file_on_disk, int64_t &total, int64_t &used)
Definition: mythcoreutil.cpp:43
SharedData32::epadding1
uint32_t epadding1
Definition: zmserver.h:147
SharedData26::action
uint32_t action
Definition: zmserver.h:102
VideoStoreData::current_event
uint64_t current_event
Definition: zmserver.h:194
FUNCTION_NODECT
const string FUNCTION_NODECT
Definition: zmserver.h:53
SharedData26::last_read_time
time_t last_read_time
Definition: zmserver.h:121
TAPE
@ TAPE
Definition: zmserver.h:68
SharedData::state
State state
Definition: zmserver.h:78
VideoStoreData::recording
timeval recording
Definition: zmserver.h:196
SharedData26::last_write_index
uint32_t last_write_index
Definition: zmserver.h:98
SharedData26::last_event
uint32_t last_event
Definition: zmserver.h:101
TriggerData26::trigger_score
uint32_t trigger_score
Definition: zmserver.h:183
PREALARM
@ PREALARM
Definition: zmserver.h:65
SharedData32::last_write_time
time_t last_write_time
Definition: zmserver.h:153
FUNCTION_MOCORD
const string FUNCTION_MOCORD
Definition: zmserver.h:55
g_database
string g_database
Definition: zmserver.cpp:85
SharedData::last_event
int last_event
Definition: zmserver.h:83
SharedData32::startup_time
time_t startup_time
Definition: zmserver.h:149
RUNNING
const string RUNNING
Definition: zmserver.h:60
ZMServer
Definition: zmserver.h:241
SharedData32::valid
uint8_t valid
Definition: zmserver.h:142
g_webPath
string g_webPath
Definition: zmserver.cpp:86
TriggerData::size
int size
Definition: zmserver.h:170
SharedData::last_read_index
int last_read_index
Definition: zmserver.h:80
VideoStoreData::size
uint32_t size
Definition: zmserver.h:193
ZMServer::m_analysisFileFormat
string m_analysisFileFormat
Definition: zmserver.h:289
SharedData32::hue
int32_t hue
Definition: zmserver.h:137
SharedData32::signal
uint8_t signal
Definition: zmserver.h:144
SharedData26::active
uint8_t active
Definition: zmserver.h:110
loadZMConfig
void loadZMConfig(const string &configfile)
Definition: zmserver.cpp:106
SharedData::contrast
int contrast
Definition: zmserver.h:88
SharedData26::extrapad2
uint64_t extrapad2
Definition: zmserver.h:122
minor
#define minor(X)
Definition: compat.h:138
SharedData
Definition: zmserver.h:73
SharedData32::last_read_index
uint32_t last_read_index
Definition: zmserver.h:132
g_minorVersion
int g_minorVersion
Definition: zmserver.cpp:93
SharedData::brightness
int brightness
Definition: zmserver.h:85
SharedData26::colour
int32_t colour
Definition: zmserver.h:105
TriggerData::trigger_score
int trigger_score
Definition: zmserver.h:172
g_lastDBKick
time_t g_lastDBKick
Definition: zmserver.cpp:96
g_password
string g_password
Definition: zmserver.cpp:83
SharedData26::epadding1
uint32_t epadding1
Definition: zmserver.h:114
FUNCTION_NONE
const string FUNCTION_NONE
Definition: zmserver.h:56
ZMServer::m_monitors
vector< MONITOR * > m_monitors
Definition: zmserver.h:284
debug
VERBOSE_PREAMBLE Most debug(nodatabase, notimestamp, noextra)") VERBOSE_MAP(VB_GENERAL
State
State
Definition: zmserver.h:63
g_zmversion
string g_zmversion
Definition: zmserver.cpp:82
SharedData32::extrapad3
uint64_t extrapad3
Definition: zmserver.h:158
SharedData::size
int size
Definition: zmserver.h:74
filename
QString filename
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:634
SharedData::valid
bool valid
Definition: zmserver.h:75
ALERT
@ ALERT
Definition: zmserver.h:67
VideoStoreData
Definition: zmserver.h:192
TRIGGER_OFF
@ TRIGGER_OFF
Definition: zmserver.h:165
SharedData26::alarm_x
int32_t alarm_x
Definition: zmserver.h:107
SharedData26::extrapad1
uint64_t extrapad1
Definition: zmserver.h:118
g_revisionVersion
int g_revisionVersion
Definition: zmserver.cpp:94
g_user
string g_user
Definition: zmserver.cpp:87
SharedData::action
int action
Definition: zmserver.h:84
SharedData32::action
uint32_t action
Definition: zmserver.h:135
SharedData26::epadding2
uint32_t epadding2
Definition: zmserver.h:115
FUNCTION_MODECT
const string FUNCTION_MODECT
Definition: zmserver.h:52
ZMServer::m_eventFileFormat
string m_eventFileFormat
Definition: zmserver.h:288
checkVersion
bool checkVersion(int major, int minor, int revision)
Definition: zmserver.cpp:99
g_dbConn
MYSQL g_dbConn
Definition: zmserver.cpp:81
SharedData26::hue
int32_t hue
Definition: zmserver.h:104
SharedData26::last_read_index
uint32_t last_read_index
Definition: zmserver.h:99
FUNCTION_MONITOR
const string FUNCTION_MONITOR
Definition: zmserver.h:51
TriggerData
Definition: zmserver.h:169
SharedData32::colour
int32_t colour
Definition: zmserver.h:138
ZMServer::m_monitorMap
map< int, MONITOR * > m_monitorMap
Definition: zmserver.h:285
MONITOR::MONITOR
MONITOR()=default
SharedData::hue
int hue
Definition: zmserver.h:86
TriggerData26::size
uint32_t size
Definition: zmserver.h:181
SharedData32::contrast
int32_t contrast
Definition: zmserver.h:139
SharedData32::format
uint8_t format
Definition: zmserver.h:145
m_name
const char * m_name
Definition: ParseText.cpp:329
TriggerData26::trigger_state
uint32_t trigger_state
Definition: zmserver.h:182
SharedData26::signal
uint8_t signal
Definition: zmserver.h:111
SharedData26::last_write_time
time_t last_write_time
Definition: zmserver.h:117
TriggerState
TriggerState
Definition: zmserver.h:165
SharedData::colour
int colour
Definition: zmserver.h:87
SharedData::last_write_time
time_t last_write_time
Definition: zmserver.h:81
TriggerData::trigger_state
TriggerState trigger_state
Definition: zmserver.h:171
TriggerData26
Definition: zmserver.h:180
mythburn.runCommand
def runCommand(command)
Runs an external command checking to see if the user has cancelled the DVD creation process.
Definition: mythburn.py:503
RESTART
const string RESTART
Definition: zmserver.h:58
SharedData32
Definition: zmserver.h:129
MONITOR
Definition: zmserver.h:200
ALARM
@ ALARM
Definition: zmserver.h:66
SharedData32::brightness
int32_t brightness
Definition: zmserver.h:136
SharedData32::alarm_y
int32_t alarm_y
Definition: zmserver.h:141
g_binPath
string g_binPath
Definition: zmserver.cpp:89
SharedData26::size
uint32_t size
Definition: zmserver.h:97
SharedData::last_read_time
time_t last_read_time
Definition: zmserver.h:82
ZMServer::m_mmapPath
string m_mmapPath
Definition: zmserver.h:291
SharedData32::last_write_index
uint32_t last_write_index
Definition: zmserver.h:131
SharedData::active
bool active
Definition: zmserver.h:76
SharedData26
Definition: zmserver.h:96
TriggerData26::padding
uint32_t padding
Definition: zmserver.h:184
SharedData32::state
uint32_t state
Definition: zmserver.h:133
SharedData::last_write_index
int last_write_index
Definition: zmserver.h:79
SharedData32::extrapad2
uint64_t extrapad2
Definition: zmserver.h:154
SharedData26::state
uint32_t state
Definition: zmserver.h:100
g_majorVersion
int g_majorVersion
Definition: zmserver.cpp:92
FUNCTION_RECORD
const string FUNCTION_RECORD
Definition: zmserver.h:54
g_server
string g_server
Definition: zmserver.cpp:84
SharedData26::brightness
int32_t brightness
Definition: zmserver.h:103
kickDatabase
void kickDatabase(bool debug)
Definition: zmserver.cpp:211
SharedData::alarm_x
int alarm_x
Definition: zmserver.h:89
SharedData32::imagesize
uint32_t imagesize
Definition: zmserver.h:146
SharedData32::size
uint32_t size
Definition: zmserver.h:130