MythTV  0.28pre
zmserver.cpp
Go to the documentation of this file.
1 /* Implementation 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 
17 #include <iostream>
18 #include <cstdlib>
19 #include <cstring>
20 #include <cstdio>
21 #include <errno.h>
22 #include <sys/socket.h>
23 #include <fcntl.h>
24 #include <netinet/in.h>
25 #include <sys/stat.h>
26 #include <sys/shm.h>
27 #include <sys/mman.h>
28 
29 #ifdef linux
30 # include <sys/vfs.h>
31 # include <sys/statvfs.h>
32 # include <sys/sysinfo.h>
33 #else
34 # include <sys/param.h>
35 # include <sys/mount.h>
36 # if CONFIG_CYGWIN
37 # include <sys/statfs.h>
38 # else // if !CONFIG_CYGWIN
39 # include <sys/sysctl.h>
40 # endif // !CONFIG_CYGWIN
41 #endif
42 
43 #include "mythtv/mythconfig.h"
44 
45 #if CONFIG_DARWIN
46 #define MSG_NOSIGNAL 0 // Apple also has SO_NOSIGPIPE?
47 #endif
48 
49 #include "zmserver.h"
50 
51 // the version of the protocol we understand
52 #define ZM_PROTOCOL_VERSION "11"
53 
54 // the maximum image size we are ever likely to get from ZM
55 #define MAX_IMAGE_SIZE (2048*1536*3)
56 
57 #define ADD_STR(list,s) list += s; list += "[]:[]";
58 // TODO rewrite after we require C++11, see http://en.cppreference.com/w/cpp/string/basic_string/to_string
59 #define ADD_INT(list,n) sprintf(m_buf, "%d", (int)n); list += m_buf; list += "[]:[]";
60 
61 // error messages
62 #define ERROR_TOKEN_COUNT "Invalid token count"
63 #define ERROR_MYSQL_QUERY "Mysql Query Error"
64 #define ERROR_MYSQL_ROW "Mysql Get Row Error"
65 #define ERROR_FILE_OPEN "Cannot open event file"
66 #define ERROR_INVALID_MONITOR "Invalid Monitor"
67 #define ERROR_INVALID_POINTERS "Cannot get shared memory pointers"
68 #define ERROR_INVALID_MONITOR_FUNCTION "Invalid Monitor Function"
69 #define ERROR_INVALID_MONITOR_ENABLE_VALUE "Invalid Monitor Enable Value"
70 #define ERROR_NO_FRAMES "No frames found for event"
71 
72 // Subpixel ordering (from zm_rgb.h)
73 // Based on byte order naming. For example, for ARGB (on both little endian or big endian)
74 // byte+0 should be alpha, byte+1 should be red, and so on.
75 #define ZM_SUBPIX_ORDER_NONE 2
76 #define ZM_SUBPIX_ORDER_RGB 6
77 #define ZM_SUBPIX_ORDER_BGR 5
78 #define ZM_SUBPIX_ORDER_BGRA 7
79 #define ZM_SUBPIX_ORDER_RGBA 8
80 #define ZM_SUBPIX_ORDER_ABGR 9
81 #define ZM_SUBPIX_ORDER_ARGB 10
82 
83 MYSQL g_dbConn;
84 string g_zmversion = "";
85 string g_password = "";
86 string g_server = "";
87 string g_database = "";
88 string g_webPath = "";
89 string g_user = "";
90 string g_webUser = "";
91 string g_binPath = "";
95 
96 time_t g_lastDBKick = 0;
97 
98 // returns true if the ZM version >= the requested version
99 bool checkVersion(int major, int minor, int revision)
100 {
101  if (g_majorVersion >= major && g_minorVersion >= minor && g_revisionVersion >= revision)
102  return true;
103 
104  return false;
105 }
106 
107 void loadZMConfig(const string &configfile)
108 {
109  cout << "loading zm config from " << configfile << endl;
110  FILE *cfg;
111  char line[512];
112  char val[250];
113 
114  if ( (cfg = fopen(configfile.c_str(), "r")) == NULL )
115  {
116  fprintf(stderr,"Can't open %s\n", configfile.c_str());
117  exit(1);
118  }
119 
120  while ( fgets( line, sizeof(line), cfg ) != NULL )
121  {
122  char *line_ptr = line;
123  // Trim off any cr/lf line endings
124  size_t chomp_len = strcspn( line_ptr, "\r\n" );
125  line_ptr[chomp_len] = '\0';
126 
127  // Remove leading white space
128  size_t white_len = strspn( line_ptr, " \t" );
129  line_ptr += white_len;
130 
131  // Check for comment or empty line
132  if ( *line_ptr == '\0' || *line_ptr == '#' )
133  continue;
134 
135  // Remove trailing white space
136  char *temp_ptr = line_ptr+strlen(line_ptr)-1;
137  while ( *temp_ptr == ' ' || *temp_ptr == '\t' )
138  {
139  *temp_ptr-- = '\0';
140  temp_ptr--;
141  }
142 
143  // Now look for the '=' in the middle of the line
144  temp_ptr = strchr( line_ptr, '=' );
145  if ( !temp_ptr )
146  {
147  fprintf(stderr,"Invalid data in %s: '%s'\n", configfile.c_str(), line );
148  continue;
149  }
150 
151  // Assign the name and value parts
152  char *name_ptr = line_ptr;
153  char *val_ptr = temp_ptr+1;
154 
155  // Trim trailing space from the name part
156  do
157  {
158  *temp_ptr = '\0';
159  temp_ptr--;
160  }
161  while ( *temp_ptr == ' ' || *temp_ptr == '\t' );
162 
163  // Remove leading white space from the value part
164  white_len = strspn( val_ptr, " \t" );
165  val_ptr += white_len;
166 
167  strncpy( val, val_ptr, strlen(val_ptr)+1 );
168  if ( strcasecmp( name_ptr, "ZM_DB_HOST" ) == 0 ) g_server = val;
169  else if ( strcasecmp( name_ptr, "ZM_DB_NAME" ) == 0 ) g_database = val;
170  else if ( strcasecmp( name_ptr, "ZM_DB_USER" ) == 0 ) g_user = val;
171  else if ( strcasecmp( name_ptr, "ZM_DB_PASS" ) == 0 ) g_password = val;
172  else if ( strcasecmp( name_ptr, "ZM_PATH_WEB" ) == 0 ) g_webPath = val;
173  else if ( strcasecmp( name_ptr, "ZM_PATH_BIN" ) == 0 ) g_binPath = val;
174  else if ( strcasecmp( name_ptr, "ZM_WEB_USER" ) == 0 ) g_webUser = val;
175  else if ( strcasecmp( name_ptr, "ZM_VERSION" ) == 0 ) g_zmversion = val;
176  }
177  fclose(cfg);
178 }
179 
181 {
182  if (!mysql_init(&g_dbConn))
183  {
184  cout << "Error: Can't initialise structure: " << mysql_error(&g_dbConn) << endl;
185  exit(mysql_errno(&g_dbConn));
186  }
187 
188  g_dbConn.reconnect = 1;
189 
190  if (!mysql_real_connect(&g_dbConn, g_server.c_str(), g_user.c_str(),
191  g_password.c_str(), 0, 0, 0, 0))
192  {
193  cout << "Error: Can't connect to server: " << mysql_error(&g_dbConn) << endl;
194  exit(mysql_errno( &g_dbConn));
195  }
196 
197  if (mysql_select_db(&g_dbConn, g_database.c_str()))
198  {
199  cout << "Error: Can't select database: " << mysql_error(&g_dbConn) << endl;
200  exit(mysql_errno(&g_dbConn));
201  }
202 }
203 
204 void kickDatabase(bool debug)
205 {
206  if (time(NULL) < g_lastDBKick + DB_CHECK_TIME)
207  return;
208 
209  if (debug)
210  cout << "Kicking database connection" << endl;
211 
212  g_lastDBKick = time(NULL);
213 
214  if (mysql_query(&g_dbConn, "SELECT NULL;") == 0)
215  {
216  MYSQL_RES *res = mysql_store_result(&g_dbConn);
217  if (res)
218  mysql_free_result(res);
219  return;
220  }
221 
222  cout << "Lost connection to DB - trying to reconnect" << endl;
223 
224  // failed so try to reconnect to the DB
225  mysql_close(&g_dbConn);
227 }
228 
230 
232  name(""), type(""), function(""), enabled(0), device(""), host(""),
233  image_buffer_count(0), width(0), height(0), bytes_per_pixel(3), mon_id(0),
234  shared_images(NULL), last_read(0), status(""), palette(0),
235  controllable(0), trackMotion(0), mapFile(-1), shm_ptr(NULL),
236  shared_data(NULL), shared_data26(NULL), id("")
237 {
238 }
239 
240 void MONITOR::initMonitor(bool debug, string mmapPath, int shmKey)
241 {
242  int shared_data_size;
243  int frame_size = width * height * bytes_per_pixel;
244 
245  if (checkVersion(1, 26, 0))
246  {
247  shared_data_size = sizeof(SharedData26) +
248  sizeof(TriggerData26) +
249  ((image_buffer_count) * (sizeof(struct timeval))) +
250  ((image_buffer_count) * frame_size) + 64;
251  }
252  else
253  {
254  shared_data_size = sizeof(SharedData) +
255  sizeof(TriggerData) +
256  ((image_buffer_count) * (sizeof(struct timeval))) +
257  ((image_buffer_count) * frame_size);
258  }
259 
260 #if _POSIX_MAPPED_FILES > 0L
261  /*
262  * Try to open the mmap file first if the architecture supports it.
263  * Otherwise, legacy shared memory will be used below.
264  */
265  stringstream mmap_filename;
266  mmap_filename << mmapPath << "/zm.mmap." << mon_id;
267 
268  mapFile = open(mmap_filename.str().c_str(), O_RDONLY, 0x0);
269  if (mapFile >= 0)
270  {
271  if (debug)
272  cout << "Opened mmap file: " << mmap_filename.str() << endl;
273 
274  shm_ptr = mmap(NULL, shared_data_size, PROT_READ,
275  MAP_SHARED, mapFile, 0x0);
276  if (shm_ptr == MAP_FAILED)
277  {
278  cout << "Failed to map shared memory from file ["
279  << mmap_filename.str() << "] " << "for monitor: "
280  << mon_id << endl;
281  status = "Error";
282 
283  if (close(mapFile) == -1)
284  cout << "Failed to close mmap file" << endl;
285 
286  mapFile = -1;
287  shm_ptr = NULL;
288 
289  return;
290  }
291  }
292  else
293  {
294  // this is not necessarily a problem, maybe the user is still
295  // using the legacy shared memory support
296  if (debug)
297  {
298  cout << "Failed to open mmap file [" << mmap_filename.str() << "] "
299  << "for monitor: " << mon_id
300  << " : " << strerror(errno) << endl;
301  cout << "Falling back to the legacy shared memory method" << endl;
302  }
303  }
304 #endif
305 
306  if (shm_ptr == NULL)
307  {
308  // fail back to shmget() functionality if mapping memory above failed.
309  int shmid;
310 
311  if ((shmid = shmget((shmKey & 0xffffff00) | mon_id,
312  shared_data_size, SHM_R)) == -1)
313  {
314  cout << "Failed to shmget for monitor: " << mon_id << endl;
315  status = "Error";
316  switch(errno)
317  {
318  case EACCES: cout << "EACCES - no rights to access segment\n"; break;
319  case EEXIST: cout << "EEXIST - segment already exists\n"; break;
320  case EINVAL: cout << "EINVAL - size < SHMMIN or size > SHMMAX\n"; break;
321  case ENFILE: cout << "ENFILE - limit on open files has been reached\n"; break;
322  case ENOENT: cout << "ENOENT - no segment exists for the given key\n"; break;
323  case ENOMEM: cout << "ENOMEM - couldn't reserve memory for segment\n"; break;
324  case ENOSPC: cout << "ENOSPC - shmmni or shmall limit reached\n"; break;
325  }
326 
327  return;
328  }
329 
330  shm_ptr = shmat(shmid, 0, SHM_RDONLY);
331 
332 
333  if (shm_ptr == NULL)
334  {
335  cout << "Failed to shmat for monitor: " << mon_id << endl;
336  status = "Error";
337  return;
338  }
339  }
340 
341  if (checkVersion(1, 26, 0))
342  {
343  shared_data = NULL;
345 
346  shared_images = (unsigned char*) shm_ptr +
347  sizeof(SharedData26) + sizeof(TriggerData26) +
348  ((image_buffer_count) * sizeof(struct timeval));
349 
350  if (((unsigned long)shared_images % 16) != 0)
351  {
352  // align images buffer to nearest 16 byte boundary
353  shared_images = (unsigned char*)((unsigned long)shared_images + (16 - ((unsigned long)shared_images % 16)));
354  }
355  }
356  else
357  {
358  shared_data26 = NULL;
360 
361  shared_images = (unsigned char*) shm_ptr +
362  sizeof(SharedData) + sizeof(TriggerData) +
363  ((image_buffer_count) * sizeof(struct timeval));
364  }
365 }
366 
368 {
369  if (checkVersion(1, 26, 0))
370  return shared_data26 != NULL && shared_images != NULL;
371 
372  // must be version >= 1.24.0 and < 1.26.0
373  return shared_data != NULL && shared_images != NULL;
374 }
375 
376 
377 string MONITOR::getIdStr(void)
378 {
379  if (id == "")
380  {
381  std::stringstream out;
382  out << mon_id;
383  id = out.str();
384  }
385  return id;
386 }
387 
389 {
390  if (shared_data)
392 
393  if (shared_data26)
395 
396  return 0;
397 }
398 
400 {
401  if (shared_data)
402  return shared_data->state;
403 
404  if (shared_data26)
405  return shared_data26->state;
406 
407  return 0;
408 }
409 
411 {
412  if (shared_data)
413  {
414  if (bytes_per_pixel == 1)
415  return ZM_SUBPIX_ORDER_NONE;
416  else
417  return ZM_SUBPIX_ORDER_RGB;
418  }
419 
420  if (shared_data26)
421  return shared_data26->format;
422 
423  return ZM_SUBPIX_ORDER_NONE;
424 }
425 
427 {
428  if (shared_data)
429  return width * height * bytes_per_pixel;
430 
431  if (shared_data26)
432  return shared_data26->imagesize;
433 
434  return 0;
435 }
436 
438 
439 ZMServer::ZMServer(int sock, bool debug)
440 {
441  if (debug)
442  cout << "Using server protocol version '" << ZM_PROTOCOL_VERSION << "'\n";
443 
444  m_sock = sock;
445  m_debug = debug;
446 
447  // get the shared memory key
448  char buf[100];
449  m_shmKey = 0x7a6d2000;
450  string setting = getZMSetting("ZM_SHM_KEY");
451 
452  if (setting != "")
453  {
454  unsigned long long tmp = m_shmKey;
455  sscanf(setting.c_str(), "%20llx", &tmp);
456  m_shmKey = tmp;
457  }
458 
459  if (m_debug)
460  {
461  snprintf(buf, sizeof(buf), "0x%x", (unsigned int)m_shmKey);
462  cout << "Shared memory key is: " << buf << endl;
463  }
464 
465  // get the MMAP path
466  m_mmapPath = getZMSetting("ZM_PATH_MAP");
467  if (m_debug)
468  {
469  cout << "Memory path directory is: " << m_mmapPath << endl;
470  }
471 
472  // get the event filename format
473  setting = getZMSetting("ZM_EVENT_IMAGE_DIGITS");
474  int eventDigits = atoi(setting.c_str());
475  snprintf(buf, sizeof(buf), "%%0%dd-capture.jpg", eventDigits);
477  if (m_debug)
478  cout << "Event file format is: " << m_eventFileFormat << endl;
479 
480  // get the analysis filename format
481  snprintf(buf, sizeof(buf), "%%0%dd-analyse.jpg", eventDigits);
483  if (m_debug)
484  cout << "Analysis file format is: " << m_analysisFileFormat << endl;
485 
486  // is ZM using the deep storage directory format?
487  m_useDeepStorage = (getZMSetting("ZM_USE_DEEP_STORAGE") == "1");
488  if (m_debug)
489  {
490  if (m_useDeepStorage)
491  cout << "using deep storage directory structure" << endl;
492  else
493  cout << "using flat directory structure" << endl;
494  }
495 
496  // is ZM creating analysis images?
497  m_useAnalysisImages = (getZMSetting("ZM_CREATE_ANALYSIS_IMAGES") == "1");
498  if (m_debug)
499  {
501  cout << "using analysis images" << endl;
502  else
503  cout << "not using analysis images" << endl;
504  }
505 
506  getMonitorList();
507 
508  // zero buffer for conversion of integer to string in ADD_INT
509  memset (m_buf, '\0', sizeof(m_buf));
510 }
511 
513 {
514  for (uint x = 0; x < m_monitors.size(); x++)
515  {
516  MONITOR *mon = m_monitors.at(x);
517  if (mon->mapFile != -1)
518  {
519  if (close(mon->mapFile) == -1)
520  cout << "Failed to close mapFile" << endl;
521  else
522  if (m_debug)
523  cout << "Closed mapFile for monitor: " << mon->name << endl;
524  }
525 
526  delete mon;
527  }
528 
529  m_monitors.clear();
530  m_monitorMap.clear();
531 
532  if (m_debug)
533  cout << "ZMServer destroyed\n";
534 }
535 
536 void ZMServer::tokenize(const string &command, vector<string> &tokens)
537 {
538  string token = "";
539  tokens.clear();
540  string::size_type startPos = 0;
541  string::size_type endPos = 0;
542 
543  while((endPos = command.find("[]:[]", startPos)) != string::npos)
544  {
545  token = command.substr(startPos, endPos - startPos);
546  tokens.push_back(token);
547  startPos = endPos + 5;
548  }
549 
550  // make sure we add the last token
551  if (endPos != command.length())
552  {
553  token = command.substr(startPos);
554  tokens.push_back(token);
555  }
556 }
557 
558 // returns true if we get a QUIT command from the client
559 bool ZMServer::processRequest(char* buf, int nbytes)
560 {
561 #if 0
562  // first 8 bytes is the length of the following data
563  char len[9];
564  memcpy(len, buf, 8);
565  len[8] = '\0';
566  int dataLen = atoi(len);
567 #endif
568 
569  buf[nbytes] = '\0';
570  string s(buf+8);
571  vector<string> tokens;
572  tokenize(s, tokens);
573 
574  if (tokens.empty())
575  return false;
576 
577  if (m_debug)
578  cout << "Processing: '" << tokens[0] << "'" << endl;
579 
580  if (tokens[0] == "HELLO")
581  handleHello();
582  else if (tokens[0] == "QUIT")
583  return true;
584  else if (tokens[0] == "GET_SERVER_STATUS")
586  else if (tokens[0] == "GET_MONITOR_STATUS")
588  else if (tokens[0] == "GET_ALARM_STATES")
590  else if (tokens[0] == "GET_EVENT_LIST")
591  handleGetEventList(tokens);
592  else if (tokens[0] == "GET_EVENT_DATES")
593  handleGetEventDates(tokens);
594  else if (tokens[0] == "GET_EVENT_FRAME")
595  handleGetEventFrame(tokens);
596  else if (tokens[0] == "GET_ANALYSE_FRAME")
597  handleGetAnalysisFrame(tokens);
598  else if (tokens[0] == "GET_LIVE_FRAME")
599  handleGetLiveFrame(tokens);
600  else if (tokens[0] == "GET_FRAME_LIST")
601  handleGetFrameList(tokens);
602  else if (tokens[0] == "GET_CAMERA_LIST")
604  else if (tokens[0] == "GET_MONITOR_LIST")
606  else if (tokens[0] == "DELETE_EVENT")
607  handleDeleteEvent(tokens);
608  else if (tokens[0] == "DELETE_EVENT_LIST")
609  handleDeleteEventList(tokens);
610  else if (tokens[0] == "RUN_ZMAUDIT")
612  else if (tokens[0] == "SET_MONITOR_FUNCTION")
613  handleSetMonitorFunction(tokens);
614  else
615  send("UNKNOWN_COMMAND");
616 
617  return false;
618 }
619 
620 bool ZMServer::send(const string &s) const
621 {
622  // send length
623  size_t len = s.size();
624  char buf[9];
625  sprintf(buf, "%8u", (unsigned int) len);
626  int status = ::send(m_sock, buf, 8, MSG_NOSIGNAL);
627  if (status == -1)
628  return false;
629 
630  // send message
631  status = ::send(m_sock, s.c_str(), s.size(), MSG_NOSIGNAL);
632  if ( status == -1 )
633  return false;
634  else
635  return true;
636 }
637 
638 bool ZMServer::send(const string &s, const unsigned char *buffer, int dataLen) const
639 {
640  // send length
641  size_t len = s.size();
642  char buf[9];
643  sprintf(buf, "%8u", (unsigned int) len);
644  int status = ::send(m_sock, buf, 8, MSG_NOSIGNAL);
645  if (status == -1)
646  return false;
647 
648  // send message
649  status = ::send(m_sock, s.c_str(), s.size(), MSG_NOSIGNAL);
650  if ( status == -1 )
651  return false;
652 
653  // send data
654  status = ::send(m_sock, buffer, dataLen, MSG_NOSIGNAL);
655  if ( status == -1 )
656  return false;
657 
658  return true;
659 }
660 
662 {
663  string outStr("");
664  ADD_STR(outStr, string("ERROR - ") + error);
665  send(outStr);
666 }
667 
669 {
670  // just send OK so the client knows all is well
671  // followed by the protocol version we understand
672  string outStr("");
673  ADD_STR(outStr, "OK");
674  ADD_STR(outStr, ZM_PROTOCOL_VERSION);
675  send(outStr);
676 }
677 
678 long long ZMServer::getDiskSpace(const string &filename, long long &total, long long &used)
679 {
680  struct statfs statbuf;
681  memset(&statbuf, 0, sizeof(statbuf));
682  long long freespace = -1;
683 
684  total = used = -1;
685 
686  // there are cases where statfs will return 0 (good), but f_blocks and
687  // others are invalid and set to 0 (such as when an automounted directory
688  // is not mounted but still visible because --ghost was used),
689  // so check to make sure we can have a total size > 0
690  if ((statfs(filename.c_str(), &statbuf) == 0) &&
691  (statbuf.f_blocks > 0) &&
692  (statbuf.f_bsize > 0))
693  {
694  total = statbuf.f_blocks;
695  total *= statbuf.f_bsize;
696  total = total >> 10;
697 
698  freespace = statbuf.f_bavail;
699  freespace *= statbuf.f_bsize;
700  freespace = freespace >> 10;
701 
702  used = total - freespace;
703  }
704 
705  return freespace;
706 }
707 
709 {
710  string outStr("");
711  ADD_STR(outStr, "OK")
712 
713  // server status
714  string status = runCommand(g_binPath + "/zmdc.pl check");
715  ADD_STR(outStr, status)
716 
717  // get load averages
718  double loads[3];
719  if (getloadavg(loads, 3) == -1)
720  {
721  ADD_STR(outStr, "Unknown")
722  }
723  else
724  {
725  char buf[30];
726  sprintf(buf, "%0.2lf", loads[0]);
727  ADD_STR(outStr, buf)
728  }
729 
730  // get free space on the disk where the events are stored
731  char buf[15];
732  long long total, used;
733  string eventsDir = g_webPath + "/events/";
734  getDiskSpace(eventsDir, total, used);
735  sprintf(buf, "%d%%", (int) ((100.0 / ((float) total / used))));
736  ADD_STR(outStr, buf)
737 
738  send(outStr);
739 }
740 
742 {
743  string outStr("");
744  ADD_STR(outStr, "OK")
745 
746  // add the monitor count
747  ADD_INT(outStr, m_monitors.size())
748 
749  for (int x = 0; x < (int)m_monitors.size(); x++)
750  {
751  MONITOR *monitor = m_monitors.at(x);
752 
753  // add monitor ID
754  ADD_INT(outStr, monitor->mon_id)
755 
756  // add monitor status
757  ADD_INT(outStr, monitor->getState())
758  }
759 
760  send(outStr);
761 }
762 
763 void ZMServer::handleGetEventList(vector<string> tokens)
764 {
765  string outStr("");
766 
767  if (tokens.size() != 5)
768  {
769  sendError(ERROR_TOKEN_COUNT);
770  return;
771  }
772 
773  string monitor = tokens[1];
774  bool oldestFirst = (tokens[2] == "1");
775  string date = tokens[3];
776  bool includeContinuous = (tokens[4] == "1");
777 
778  if (m_debug)
779  cout << "Loading events for monitor: " << monitor << ", date: " << date << endl;
780 
781  ADD_STR(outStr, "OK")
782 
783  MYSQL_RES *res;
784  MYSQL_ROW row;
785 
786  string sql("SELECT E.Id, E.Name, M.Id AS MonitorID, M.Name AS MonitorName, E.StartTime, "
787  "E.Length, M.Width, M.Height, M.DefaultRate, M.DefaultScale "
788  "from Events as E inner join Monitors as M on E.MonitorId = M.Id ");
789 
790  if (monitor != "<ANY>")
791  {
792  sql += "WHERE M.Name = '" + monitor + "' ";
793 
794  if (date != "<ANY>")
795  sql += "AND DATE(E.StartTime) = DATE('" + date + "') ";
796  }
797  else
798  {
799  if (date != "<ANY>")
800  {
801  sql += "WHERE DATE(E.StartTime) = DATE('" + date + "') ";
802 
803  if (!includeContinuous)
804  sql += "AND Cause != 'Continuous' ";
805  }
806  else
807  if (!includeContinuous)
808  sql += "WHERE Cause != 'Continuous' ";
809  }
810 
811  if (oldestFirst)
812  sql += "ORDER BY E.StartTime ASC";
813  else
814  sql += "ORDER BY E.StartTime DESC";
815 
816  if (mysql_query(&g_dbConn, sql.c_str()))
817  {
818  fprintf(stderr, "%s\n", mysql_error(&g_dbConn));
819  sendError(ERROR_MYSQL_QUERY);
820  return;
821  }
822 
823  res = mysql_store_result(&g_dbConn);
824  int eventCount = mysql_num_rows(res);
825 
826  if (m_debug)
827  cout << "Got " << eventCount << " events" << endl;
828 
829  ADD_INT(outStr, eventCount)
830 
831  for (int x = 0; x < eventCount; x++)
832  {
833  row = mysql_fetch_row(res);
834  if (row)
835  {
836  ADD_STR(outStr, row[0]) // eventID
837  ADD_STR(outStr, row[1]) // event name
838  ADD_STR(outStr, row[2]) // monitorID
839  ADD_STR(outStr, row[3]) // monitor name
840  row[4][10] = 'T';
841  ADD_STR(outStr, row[4]) // start time
842  ADD_STR(outStr, row[5]) // length
843  }
844  else
845  {
846  cout << "Failed to get mysql row" << endl;
847  sendError(ERROR_MYSQL_ROW);
848  return;
849  }
850  }
851 
852  mysql_free_result(res);
853 
854  send(outStr);
855 }
856 
857 void ZMServer::handleGetEventDates(vector<string> tokens)
858 {
859  string outStr("");
860 
861  if (tokens.size() != 3)
862  {
863  sendError(ERROR_TOKEN_COUNT);
864  return;
865  }
866 
867  string monitor = tokens[1];
868  bool oldestFirst = (tokens[2] == "1");
869 
870  if (m_debug)
871  cout << "Loading event dates for monitor: " << monitor << endl;
872 
873  ADD_STR(outStr, "OK")
874 
875  MYSQL_RES *res;
876  MYSQL_ROW row;
877 
878  string sql("SELECT DISTINCT DATE(E.StartTime) "
879  "from Events as E inner join Monitors as M on E.MonitorId = M.Id ");
880 
881  if (monitor != "<ANY>")
882  sql += "WHERE M.Name = '" + monitor + "' ";
883 
884  if (oldestFirst)
885  sql += "ORDER BY E.StartTime ASC";
886  else
887  sql += "ORDER BY E.StartTime DESC";
888 
889  if (mysql_query(&g_dbConn, sql.c_str()))
890  {
891  fprintf(stderr, "%s\n", mysql_error(&g_dbConn));
892  sendError(ERROR_MYSQL_QUERY);
893  return;
894  }
895 
896  res = mysql_store_result(&g_dbConn);
897  int dateCount = mysql_num_rows(res);
898 
899  if (m_debug)
900  cout << "Got " << dateCount << " dates" << endl;
901 
902  ADD_INT(outStr, dateCount)
903 
904  for (int x = 0; x < dateCount; x++)
905  {
906  row = mysql_fetch_row(res);
907  if (row)
908  {
909  ADD_STR(outStr, row[0]) // event date
910  }
911  else
912  {
913  cout << "Failed to get mysql row" << endl;
914  sendError(ERROR_MYSQL_ROW);
915  return;
916  }
917  }
918 
919  mysql_free_result(res);
920 
921  send(outStr);
922 }
923 
925 {
926  string outStr("");
927  ADD_STR(outStr, "OK")
928 
929  // get monitor list
930  MYSQL_RES *res;
931  MYSQL_ROW row;
932 
933  string sql("SELECT Id, Name, Type, Device, Host, Channel, Function, Enabled "
934  "FROM Monitors;");
935  if (mysql_query(&g_dbConn, sql.c_str()))
936  {
937  fprintf(stderr, "%s\n", mysql_error(&g_dbConn));
938  sendError(ERROR_MYSQL_QUERY);
939  return;
940  }
941 
942  res = mysql_store_result(&g_dbConn);
943 
944  // add monitor count
945  int monitorCount = mysql_num_rows(res);
946 
947  if (m_debug)
948  cout << "Got " << monitorCount << " monitors" << endl;
949 
950  ADD_INT(outStr, monitorCount)
951 
952  for (int x = 0; x < monitorCount; x++)
953  {
954  row = mysql_fetch_row(res);
955  if (row)
956  {
957  string id = row[0];
958  string type = row[2];
959  string device = row[3];
960  string host = row[4];
961  string channel = row[5];
962  string function = row[6];
963  string enabled = row[7];
964  string name = row[1];
965  string events = "";
966  string zmcStatus = "";
967  string zmaStatus = "";
968  getMonitorStatus(id, type, device, host, channel, function,
969  zmcStatus, zmaStatus, enabled);
970  MYSQL_RES *res2;
971  MYSQL_ROW row2;
972 
973  string sql2("SELECT count(if(Archived=0,1,NULL)) AS EventCount "
974  "FROM Events AS E "
975  "WHERE MonitorId = " + id);
976 
977  if (mysql_query(&g_dbConn, sql2.c_str()))
978  {
979  fprintf(stderr, "%s\n", mysql_error(&g_dbConn));
980  sendError(ERROR_MYSQL_QUERY);
981  return;
982  }
983 
984  res2 = mysql_store_result(&g_dbConn);
985  if (mysql_num_rows(res2) > 0)
986  {
987  row2 = mysql_fetch_row(res2);
988  if (row2)
989  events = row2[0];
990  else
991  {
992  cout << "Failed to get mysql row" << endl;
993  sendError(ERROR_MYSQL_ROW);
994  return;
995  }
996  }
997 
998  ADD_STR(outStr, id)
999  ADD_STR(outStr, name)
1000  ADD_STR(outStr, zmcStatus)
1001  ADD_STR(outStr, zmaStatus)
1002  ADD_STR(outStr, events)
1003  ADD_STR(outStr, function)
1004  ADD_STR(outStr, enabled)
1005 
1006  mysql_free_result(res2);
1007  }
1008  else
1009  {
1010  cout << "Failed to get mysql row" << endl;
1011  sendError(ERROR_MYSQL_ROW);
1012  return;
1013  }
1014  }
1015 
1016  mysql_free_result(res);
1017 
1018  send(outStr);
1019 }
1020 
1021 string ZMServer::runCommand(string command)
1022 {
1023  string outStr("");
1024  FILE *fd = popen(command.c_str(), "r");
1025  char buffer[100];
1026 
1027  while (fgets(buffer, sizeof(buffer), fd) != NULL)
1028  {
1029  outStr += buffer;
1030  }
1031  pclose(fd);
1032  return outStr;
1033 }
1034 
1035 void ZMServer::getMonitorStatus(string id, string type, string device, string host, string channel,
1036  string function, string &zmcStatus, string &zmaStatus,
1037  string enabled)
1038 {
1039  zmaStatus = "";
1040  zmcStatus = "";
1041 
1042  string command(g_binPath + "/zmdc.pl status");
1043  string status = runCommand(command);
1044 
1045  if (type == "Local")
1046  {
1047  if (enabled == "0")
1048  zmaStatus = device + "(" + channel + ") [-]";
1049  else if (status.find("'zma -m " + id + "' running") != string::npos)
1050  zmaStatus = device + "(" + channel + ") [R]";
1051  else
1052  zmaStatus = device + "(" + channel + ") [S]";
1053  }
1054  else
1055  {
1056  if (enabled == "0")
1057  zmaStatus = host + " [-]";
1058  else if (status.find("'zma -m " + id + "' running") != string::npos)
1059  zmaStatus = host + " [R]";
1060  else
1061  zmaStatus = host + " [S]";
1062  }
1063 
1064  if (type == "Local")
1065  {
1066  if (enabled == "0")
1067  zmcStatus = function + " [-]";
1068  else if (status.find("'zmc -d "+ device + "' running") != string::npos)
1069  zmcStatus = function + " [R]";
1070  else
1071  zmcStatus = function + " [S]";
1072  }
1073  else
1074  {
1075  if (enabled == "0")
1076  zmcStatus = function + " [-]";
1077  else if (status.find("'zmc -m " + id + "' running") != string::npos)
1078  zmcStatus = function + " [R]";
1079  else
1080  zmcStatus = function + " [S]";
1081  }
1082 }
1083 
1084 void ZMServer::handleGetEventFrame(vector<string> tokens)
1085 {
1086  static unsigned char buffer[MAX_IMAGE_SIZE];
1087 
1088  if (tokens.size() != 5)
1089  {
1090  sendError(ERROR_TOKEN_COUNT);
1091  return;
1092  }
1093 
1094  string monitorID(tokens[1]);
1095  string eventID(tokens[2]);
1096  int frameNo = atoi(tokens[3].c_str());
1097  string eventTime(tokens[4]);
1098 
1099  if (m_debug)
1100  cout << "Getting frame " << frameNo << " for event " << eventID
1101  << " on monitor " << monitorID << " event time is " << eventTime << endl;
1102 
1103  string outStr("");
1104 
1105  ADD_STR(outStr, "OK")
1106 
1107  // try to find the frame file
1108  string filepath("");
1109  char str[100];
1110 
1111  if (m_useDeepStorage)
1112  {
1113  filepath = g_webPath + "/events/" + monitorID + "/" + eventTime + "/";
1114  sprintf(str, m_eventFileFormat.c_str(), frameNo);
1115  filepath += str;
1116  }
1117  else
1118  {
1119  filepath = g_webPath + "/events/" + monitorID + "/" + eventID + "/";
1120  sprintf(str, m_eventFileFormat.c_str(), frameNo);
1121  filepath += str;
1122  }
1123 
1124  FILE *fd;
1125  int fileSize = 0;
1126  if ((fd = fopen(filepath.c_str(), "r" )))
1127  {
1128  fileSize = fread(buffer, 1, sizeof(buffer), fd);
1129  fclose(fd);
1130  }
1131  else
1132  {
1133  cout << "Can't open " << filepath << ": " << strerror(errno) << endl;
1134  sendError(ERROR_FILE_OPEN + string(" - ") + filepath + " : " + strerror(errno));
1135  return;
1136  }
1137 
1138  if (m_debug)
1139  cout << "Frame size: " << fileSize << endl;
1140 
1141  // get the file size
1142  ADD_INT(outStr, fileSize)
1143 
1144  // send the data
1145  send(outStr, buffer, fileSize);
1146 }
1147 
1148 void ZMServer::handleGetAnalysisFrame(vector<string> tokens)
1149 {
1150  static unsigned char buffer[MAX_IMAGE_SIZE];
1151  char str[100];
1152 
1153  if (tokens.size() != 5)
1154  {
1155  sendError(ERROR_TOKEN_COUNT);
1156  return;
1157  }
1158 
1159  string monitorID(tokens[1]);
1160  string eventID(tokens[2]);
1161  int frameNo = atoi(tokens[3].c_str());
1162  string eventTime(tokens[4]);
1163 
1164  if (m_debug)
1165  cout << "Getting analysis frame " << frameNo << " for event " << eventID
1166  << " on monitor " << monitorID << " event time is " << eventTime << endl;
1167 
1168  // get the 'alarm' frames from the Frames table for this event
1169  MYSQL_RES *res;
1170  MYSQL_ROW row = NULL;
1171 
1172  string sql("");
1173  sql += "SELECT FrameId FROM Frames ";
1174  sql += "WHERE EventID = " + eventID + " ";
1175  sql += "AND Type = 'Alarm' ";
1176  sql += "ORDER BY FrameID";
1177 
1178  if (mysql_query(&g_dbConn, sql.c_str()))
1179  {
1180  fprintf(stderr, "%s\n", mysql_error(&g_dbConn));
1181  sendError(ERROR_MYSQL_QUERY);
1182  return;
1183  }
1184 
1185  res = mysql_store_result(&g_dbConn);
1186  int frameCount = mysql_num_rows(res);
1187  int frameID;
1188  string fileFormat = m_analysisFileFormat;
1189 
1190  // if we didn't find any analysis frames look for a normal frame instead
1191  if (frameCount == 0 || m_useAnalysisImages == false)
1192  {
1193  mysql_free_result(res);
1194 
1195  frameNo = 0;
1196  fileFormat = m_eventFileFormat;
1197  sql = "SELECT FrameId FROM Frames ";
1198  sql += "WHERE EventID = " + eventID + " ";
1199  sql += "ORDER BY FrameID";
1200 
1201  if (mysql_query(&g_dbConn, sql.c_str()))
1202  {
1203  fprintf(stderr, "%s\n", mysql_error(&g_dbConn));
1204  sendError(ERROR_MYSQL_QUERY);
1205  return;
1206  }
1207 
1208  res = mysql_store_result(&g_dbConn);
1209  frameCount = mysql_num_rows(res);
1210  }
1211 
1212  // if the required frame mumber is 0 or out of bounds then use the middle frame
1213  if (frameNo == 0 || frameNo < 0 || frameNo > frameCount)
1214  frameNo = (frameCount / 2) + 1;
1215 
1216  // move to the required frame in the table
1217  for (int x = 0; x < frameNo; x++)
1218  {
1219  row = mysql_fetch_row(res);
1220  }
1221 
1222  if (row)
1223  {
1224  frameID = atoi(row[0]);
1225  }
1226  else
1227  {
1228  cout << "handleGetAnalyseFrame: Failed to get mysql row for frameNo " << frameNo << endl;
1229  sendError(ERROR_MYSQL_ROW);
1230  return;
1231  }
1232 
1233  mysql_free_result(res);
1234 
1235  string outStr("");
1236 
1237  ADD_STR(outStr, "OK")
1238 
1239  // try to find the analyse frame file
1240  string filepath("");
1241  if (m_useDeepStorage)
1242  {
1243  filepath = g_webPath + "/events/" + monitorID + "/" + eventTime + "/";
1244  sprintf(str, fileFormat.c_str(), frameID);
1245  filepath += str;
1246  }
1247  else
1248  {
1249  filepath = g_webPath + "/events/" + monitorID + "/" + eventID + "/";
1250  sprintf(str, fileFormat.c_str(), frameID);
1251  filepath += str;
1252  }
1253 
1254  FILE *fd;
1255  int fileSize = 0;
1256  if ((fd = fopen(filepath.c_str(), "r" )))
1257  {
1258  fileSize = fread(buffer, 1, sizeof(buffer), fd);
1259  fclose(fd);
1260  }
1261  else
1262  {
1263  cout << "Can't open " << filepath << ": " << strerror(errno) << endl;
1264  sendError(ERROR_FILE_OPEN + string(" - ") + filepath + " : " + strerror(errno));
1265  return;
1266  }
1267 
1268  if (m_debug)
1269  cout << "Frame size: " << fileSize << endl;
1270 
1271  // get the file size
1272  ADD_INT(outStr, fileSize)
1273 
1274  // send the data
1275  send(outStr, buffer, fileSize);
1276 }
1277 
1278 void ZMServer::handleGetLiveFrame(vector<string> tokens)
1279 {
1280  static unsigned char buffer[MAX_IMAGE_SIZE];
1281 
1282  // we need to periodically kick the DB connection here to make sure it
1283  // stays alive because the user may have left the frontend on the live
1284  // view which doesn't query the DB at all and eventually the connection
1285  // will timeout
1287 
1288  if (tokens.size() != 2)
1289  {
1290  sendError(ERROR_TOKEN_COUNT);
1291  return;
1292  }
1293 
1294  int monitorID = atoi(tokens[1].c_str());
1295 
1296  if (m_debug)
1297  cout << "Getting live frame from monitor: " << monitorID << endl;
1298 
1299  string outStr("");
1300 
1301  ADD_STR(outStr, "OK")
1302 
1303  // echo the monitor id
1304  ADD_INT(outStr, monitorID)
1305 
1306  // try to find the correct MONITOR
1307  MONITOR *monitor;
1308  if (m_monitorMap.find(monitorID) != m_monitorMap.end())
1309  monitor = m_monitorMap[monitorID];
1310  else
1311  {
1312  sendError(ERROR_INVALID_MONITOR);
1313  return;
1314  }
1315 
1316  // are the data pointers valid?
1317  if (!monitor->isValid())
1318  {
1319  sendError(ERROR_INVALID_POINTERS);
1320  return;
1321  }
1322 
1323  // read a frame from the shared memory
1324  int dataSize = getFrame(buffer, sizeof(buffer), monitor);
1325 
1326  if (m_debug)
1327  cout << "Frame size: " << dataSize << endl;
1328 
1329  if (dataSize == 0)
1330  {
1331  // not really an error
1332  outStr = "";
1333  ADD_STR(outStr, "WARNING - No new frame available");
1334  send(outStr);
1335  return;
1336  }
1337 
1338  // add status
1339  ADD_STR(outStr, monitor->status)
1340 
1341  // send the data size
1342  ADD_INT(outStr, dataSize)
1343 
1344  // send the data
1345  send(outStr, buffer, dataSize);
1346 }
1347 
1348 void ZMServer::handleGetFrameList(vector<string> tokens)
1349 {
1350  string eventID;
1351  string outStr("");
1352 
1353  if (tokens.size() != 2)
1354  {
1355  sendError(ERROR_TOKEN_COUNT);
1356  return;
1357  }
1358 
1359  eventID = tokens[1];
1360 
1361  if (m_debug)
1362  cout << "Loading frames for event: " << eventID << endl;
1363 
1364  ADD_STR(outStr, "OK")
1365 
1366  MYSQL_RES *res;
1367  MYSQL_ROW row;
1368  string sql("");
1369 
1370  // check to see what type of event this is
1371  sql += "SELECT Cause, Length, Frames FROM Events ";
1372  sql += "WHERE Id = " + eventID + " ";
1373 
1374  if (mysql_query(&g_dbConn, sql.c_str()))
1375  {
1376  fprintf(stderr, "%s\n", mysql_error(&g_dbConn));
1377  sendError(ERROR_MYSQL_QUERY);
1378  return;
1379  }
1380 
1381  res = mysql_store_result(&g_dbConn);
1382  row = mysql_fetch_row(res);
1383 
1384  // make sure we have some frames to display
1385  if (row[1] == NULL || row[2] == NULL)
1386  {
1387  sendError(ERROR_NO_FRAMES);
1388  return;
1389  }
1390 
1391  string cause = row[0];
1392  double length = atof(row[1]);
1393  int frameCount = atoi(row[2]);
1394 
1395  mysql_free_result(res);
1396 
1397  if (cause == "Continuous")
1398  {
1399  // event is a continuous recording so guess the frame delta's
1400 
1401  if (m_debug)
1402  cout << "Got " << frameCount << " frames (continuous event)" << endl;
1403 
1404  ADD_INT(outStr, frameCount)
1405 
1406  if (frameCount > 0)
1407  {
1408  double delta = length / frameCount;
1409 
1410  for (int x = 0; x < frameCount; x++)
1411  {
1412  char str[10];
1413  sprintf(str, "%f", delta);
1414 
1415  ADD_STR(outStr, "Normal") // Type
1416  ADD_STR(outStr, str) // Delta
1417  }
1418  }
1419  }
1420  else
1421  {
1422  sql = "SELECT Type, Delta FROM Frames ";
1423  sql += "WHERE EventID = " + eventID + " ";
1424  sql += "ORDER BY FrameID";
1425 
1426  if (mysql_query(&g_dbConn, sql.c_str()))
1427  {
1428  fprintf(stderr, "%s\n", mysql_error(&g_dbConn));
1429  sendError(ERROR_MYSQL_QUERY);
1430  return;
1431  }
1432 
1433  res = mysql_store_result(&g_dbConn);
1434  frameCount = mysql_num_rows(res);
1435 
1436  if (m_debug)
1437  cout << "Got " << frameCount << " frames" << endl;
1438 
1439  ADD_INT(outStr, frameCount)
1440 
1441  for (int x = 0; x < frameCount; x++)
1442  {
1443  row = mysql_fetch_row(res);
1444  if (row)
1445  {
1446  ADD_STR(outStr, row[0]) // Type
1447  ADD_STR(outStr, row[1]) // Delta
1448  }
1449  else
1450  {
1451  cout << "handleGetFrameList: Failed to get mysql row " << x << endl;
1452  sendError(ERROR_MYSQL_ROW);
1453  return;
1454  }
1455  }
1456 
1457  mysql_free_result(res);
1458  }
1459 
1460  send(outStr);
1461 }
1462 
1464 {
1465  string outStr("");
1466 
1467  ADD_STR(outStr, "OK")
1468 
1469  ADD_INT(outStr, m_monitors.size())
1470 
1471  for (uint x = 0; x < m_monitors.size(); x++)
1472  {
1473  ADD_STR(outStr, m_monitors.at(x)->name)
1474  }
1475 
1476  send(outStr);
1477 }
1478 
1480 {
1481  string outStr("");
1482 
1483  ADD_STR(outStr, "OK")
1484 
1485  if (m_debug)
1486  cout << "We have " << m_monitors.size() << " monitors" << endl;
1487 
1488  ADD_INT(outStr, m_monitors.size())
1489 
1490  for (uint x = 0; x < m_monitors.size(); x++)
1491  {
1492  MONITOR *mon = m_monitors.at(x);
1493 
1494  ADD_INT(outStr, mon->mon_id)
1495  ADD_STR(outStr, mon->name)
1496  ADD_INT(outStr, mon->width)
1497  ADD_INT(outStr, mon->height)
1498  ADD_INT(outStr, mon->bytes_per_pixel)
1499 
1500  if (m_debug)
1501  {
1502  cout << "id: " << mon->mon_id << endl;
1503  cout << "name: " << mon->name << endl;
1504  cout << "width: " << mon->width << endl;
1505  cout << "height: " << mon->height << endl;
1506  cout << "palette: " << mon->palette << endl;
1507  cout << "byte per pixel: " << mon->bytes_per_pixel << endl;
1508  cout << "sub pixel order:" << mon->getSubpixelOrder() << endl;
1509  cout << "-------------------" << endl;
1510  }
1511  }
1512 
1513  send(outStr);
1514 }
1515 
1516 void ZMServer::handleDeleteEvent(vector<string> tokens)
1517 {
1518  string eventID;
1519  string outStr("");
1520 
1521  if (tokens.size() != 2)
1522  {
1523  sendError(ERROR_TOKEN_COUNT);
1524  return;
1525  }
1526 
1527  eventID = tokens[1];
1528 
1529  if (m_debug)
1530  cout << "Deleting event: " << eventID << endl;
1531 
1532  ADD_STR(outStr, "OK")
1533 
1534  string sql("");
1535  sql += "DELETE FROM Events WHERE Id = " + eventID;
1536 
1537  if (mysql_query(&g_dbConn, sql.c_str()))
1538  {
1539  fprintf(stderr, "%s\n", mysql_error(&g_dbConn));
1540  sendError(ERROR_MYSQL_QUERY);
1541  return;
1542  }
1543 
1544  // run zmaudit.pl to clean everything up
1545  string command(g_binPath + "/zmaudit.pl &");
1546  errno = 0;
1547  if (system(command.c_str()) < 0 && errno)
1548  cerr << "Failed to run '" << command << "'" << endl;
1549 
1550  send(outStr);
1551 }
1552 
1553 void ZMServer::handleDeleteEventList(vector<string> tokens)
1554 {
1555  string eventList("");
1556  string outStr("");
1557 
1558  vector<string>::iterator it = tokens.begin();
1559  if (it != tokens.end())
1560  ++it;
1561  while (it != tokens.end())
1562  {
1563  if (eventList == "")
1564  eventList = (*it);
1565  else
1566  eventList += "," + (*it);
1567 
1568  ++it;
1569  }
1570 
1571  if (m_debug)
1572  cout << "Deleting events: " << eventList << endl;
1573 
1574  string sql("");
1575  sql += "DELETE FROM Events WHERE Id IN (" + eventList + ")";
1576 
1577  if (mysql_query(&g_dbConn, sql.c_str()))
1578  {
1579  fprintf(stderr, "%s\n", mysql_error(&g_dbConn));
1580  sendError(ERROR_MYSQL_QUERY);
1581  return;
1582  }
1583 
1584  ADD_STR(outStr, "OK")
1585  send(outStr);
1586 }
1587 
1589 {
1590  string outStr("");
1591 
1592  // run zmaudit.pl to clean up orphaned db entries etc
1593  string command(g_binPath + "/zmaudit.pl &");
1594 
1595  if (m_debug)
1596  cout << "Running command: " << command << endl;
1597 
1598  errno = 0;
1599  if (system(command.c_str()) < 0 && errno)
1600  cerr << "Failed to run '" << command << "'" << endl;
1601 
1602  ADD_STR(outStr, "OK")
1603  send(outStr);
1604 }
1605 
1607 {
1608  m_monitors.clear();
1609  m_monitorMap.clear();
1610 
1611  string sql("SELECT Id, Name, Width, Height, ImageBufferCount, MaxFPS, Palette, ");
1612  sql += " Type, Function, Enabled, Device, Host, Controllable, TrackMotion";
1613 
1614  if (checkVersion(1, 26, 0))
1615  sql += ", Colours";
1616 
1617  sql += " FROM Monitors";
1618  sql += " ORDER BY Sequence";
1619 
1620  MYSQL_RES *res;
1621  MYSQL_ROW row;
1622 
1623  if (mysql_query(&g_dbConn, sql.c_str()))
1624  {
1625  fprintf(stderr, "%s\n", mysql_error(&g_dbConn));
1626  return;
1627  }
1628 
1629  res = mysql_store_result(&g_dbConn);
1630  int monitorCount = mysql_num_rows(res);
1631 
1632  if (m_debug)
1633  cout << "Got " << monitorCount << " monitors" << endl;
1634 
1635  for (int x = 0; x < monitorCount; x++)
1636  {
1637  row = mysql_fetch_row(res);
1638  if (row)
1639  {
1640  MONITOR *m = new MONITOR;
1641  m->mon_id = atoi(row[0]);
1642  m->name = row[1];
1643  m->width = atoi(row[2]);
1644  m->height = atoi(row[3]);
1645  m->image_buffer_count = atoi(row[4]);
1646  m->palette = atoi(row[6]);
1647  m->type = row[7];
1648  m->function = row[8];
1649  m->enabled = atoi(row[9]);
1650  m->device = row[10];
1651  m->host = row[11];
1652  m->controllable = atoi(row[12]);
1653  m->trackMotion = atoi(row[13]);
1654 
1655  // from version 1.26.0 ZM can have 1, 3 or 4 bytes per pixel
1656  // older versions can be 1 or 3
1657  if (checkVersion(1, 26, 0))
1658  m->bytes_per_pixel = atoi(row[14]);
1659  else
1660  if (m->palette == 1)
1661  m->bytes_per_pixel = 1;
1662  else
1663  m->bytes_per_pixel = 3;
1664 
1665  m_monitors.push_back(m);
1666  m_monitorMap[m->mon_id] = m;
1667 
1669  }
1670  else
1671  {
1672  cout << "Failed to get mysql row" << endl;
1673  return;
1674  }
1675  }
1676 
1677  mysql_free_result(res);
1678 }
1679 
1680 int ZMServer::getFrame(unsigned char *buffer, int bufferSize, MONITOR *monitor)
1681 {
1682  (void) bufferSize;
1683 
1684  // is there a new frame available?
1685  if (monitor->getLastWriteIndex() == monitor->last_read)
1686  return 0;
1687 
1688  // sanity check last_read
1689  if (monitor->getLastWriteIndex() < 0 ||
1690  monitor->getLastWriteIndex() >= monitor->image_buffer_count)
1691  return 0;
1692 
1693  monitor->last_read = monitor->getLastWriteIndex();
1694 
1695  switch (monitor->getState())
1696  {
1697  case IDLE:
1698  monitor->status = "Idle";
1699  break;
1700  case PREALARM:
1701  monitor->status = "Pre Alarm";
1702  break;
1703  case ALARM:
1704  monitor->status = "Alarm";
1705  break;
1706  case ALERT:
1707  monitor->status = "Alert";
1708  break;
1709  case TAPE:
1710  monitor->status = "Tape";
1711  break;
1712  default:
1713  monitor->status = "Unknown";
1714  break;
1715  }
1716 
1717  // FIXME: should do some sort of compression JPEG??
1718  // just copy the data to our buffer for now
1719 
1720  // fixup the colours if necessary we aim to always send RGB24 images
1721  unsigned char *data = monitor->shared_images + monitor->getFrameSize() * monitor->last_read;
1722  unsigned int rpos = 0;
1723  unsigned int wpos = 0;
1724 
1725  switch (monitor->getSubpixelOrder())
1726  {
1727  case ZM_SUBPIX_ORDER_NONE:
1728  {
1729  for (wpos = 0, rpos = 0; wpos < (unsigned int) (monitor->width * monitor->height * 3); wpos += 3, rpos += 1)
1730  {
1731  buffer[wpos + 0] = data[rpos + 0]; // r
1732  buffer[wpos + 1] = data[rpos + 0]; // g
1733  buffer[wpos + 2] = data[rpos + 0]; // b
1734  }
1735 
1736  break;
1737  }
1738 
1739  case ZM_SUBPIX_ORDER_RGB:
1740  {
1741  for (wpos = 0, rpos = 0; wpos < (unsigned int) (monitor->width * monitor->height * 3); wpos += 3, rpos += 3)
1742  {
1743  buffer[wpos + 0] = data[rpos + 0]; // r
1744  buffer[wpos + 1] = data[rpos + 1]; // g
1745  buffer[wpos + 2] = data[rpos + 2]; // b
1746  }
1747 
1748  break;
1749  }
1750 
1751  case ZM_SUBPIX_ORDER_BGR:
1752  {
1753  for (wpos = 0, rpos = 0; wpos < (unsigned int) (monitor->width * monitor->height * 3); wpos += 3, rpos += 3)
1754  {
1755  buffer[wpos + 0] = data[rpos + 2]; // r
1756  buffer[wpos + 1] = data[rpos + 1]; // g
1757  buffer[wpos + 2] = data[rpos + 0]; // b
1758  }
1759 
1760  break;
1761  }
1762  case ZM_SUBPIX_ORDER_BGRA:
1763  {
1764  for (wpos = 0, rpos = 0; wpos < (unsigned int) (monitor->width * monitor->height * 3); wpos += 3, rpos += 4)
1765  {
1766  buffer[wpos + 0] = data[rpos + 2]; // r
1767  buffer[wpos + 1] = data[rpos + 1]; // g
1768  buffer[wpos + 2] = data[rpos + 0]; // b
1769  }
1770 
1771  break;
1772  }
1773 
1774  case ZM_SUBPIX_ORDER_RGBA:
1775  {
1776  for (wpos = 0, rpos = 0; wpos < (unsigned int) (monitor->width * monitor->height * 3); wpos += 3, rpos += 4)
1777  {
1778  buffer[wpos + 0] = data[rpos + 0]; // r
1779  buffer[wpos + 1] = data[rpos + 1]; // g
1780  buffer[wpos + 2] = data[rpos + 2]; // b
1781  }
1782 
1783  break;
1784  }
1785 
1786  case ZM_SUBPIX_ORDER_ABGR:
1787  {
1788  for (wpos = 0, rpos = 0; wpos < (unsigned int) (monitor->width * monitor->height * 3); wpos += 3, rpos += 4)
1789  {
1790  buffer[wpos + 0] = data[rpos + 3]; // r
1791  buffer[wpos + 1] = data[rpos + 2]; // g
1792  buffer[wpos + 2] = data[rpos + 1]; // b
1793  }
1794 
1795  break;
1796  }
1797 
1798  case ZM_SUBPIX_ORDER_ARGB:
1799  {
1800  for (wpos = 0, rpos = 0; wpos < (unsigned int) (monitor->width * monitor->height * 3); wpos += 3, rpos += 4)
1801  {
1802  buffer[wpos + 0] = data[rpos + 1]; // r
1803  buffer[wpos + 1] = data[rpos + 2]; // g
1804  buffer[wpos + 2] = data[rpos + 3]; // b
1805  }
1806 
1807  break;
1808  }
1809  }
1810 
1811  return monitor->width * monitor->height * 3;
1812 }
1813 
1814 string ZMServer::getZMSetting(const string &setting)
1815 {
1816  string result;
1817  string sql("SELECT Name, Value FROM Config ");
1818  sql += "WHERE Name = '" + setting + "'";
1819 
1820  MYSQL_RES *res;
1821  MYSQL_ROW row;
1822 
1823  if (mysql_query(&g_dbConn, sql.c_str()))
1824  {
1825  fprintf(stderr, "%s\n", mysql_error(&g_dbConn));
1826  return "";
1827  }
1828 
1829  res = mysql_store_result(&g_dbConn);
1830  row = mysql_fetch_row(res);
1831  if (row)
1832  {
1833  result = row[1];
1834  }
1835  else
1836  {
1837  cout << "Failed to get mysql row" << endl;
1838  result = "";
1839  }
1840 
1841  if (m_debug)
1842  cout << "getZMSetting: " << setting << " Result: " << result << endl;
1843 
1844  mysql_free_result(res);
1845 
1846  return result;
1847 }
1848 
1849 void ZMServer::handleSetMonitorFunction(vector<string> tokens)
1850 {
1851  string outStr("");
1852 
1853  if (tokens.size() != 4)
1854  {
1855  sendError(ERROR_TOKEN_COUNT);
1856  return;
1857  }
1858 
1859  string monitorID(tokens[1]);
1860  string function(tokens[2]);
1861  string enabled(tokens[3]);
1862 
1863  // Check validity of input passed to server. Does monitor exist && is function ok
1864  if (m_monitorMap.find(atoi(monitorID.c_str())) == m_monitorMap.end())
1865  {
1866  sendError(ERROR_INVALID_MONITOR);
1867  return;
1868  }
1869 
1870  if (function != FUNCTION_NONE && function != FUNCTION_MONITOR &&
1871  function != FUNCTION_MODECT && function != FUNCTION_NODECT &&
1872  function != FUNCTION_RECORD && function != FUNCTION_MOCORD)
1873  {
1874  sendError(ERROR_INVALID_MONITOR_FUNCTION);
1875  return;
1876  }
1877 
1878  if (enabled != "0" && enabled != "1")
1879  {
1880  sendError(ERROR_INVALID_MONITOR_ENABLE_VALUE);
1881  return;
1882  }
1883 
1884  if (m_debug)
1885  cout << "User input validated OK" << endl;
1886 
1887 
1888  // Now perform db update && (re)start/stop daemons as required.
1889  MONITOR *monitor = m_monitorMap[atoi(monitorID.c_str())];
1890  string oldFunction = monitor->function;
1891  string newFunction = function;
1892  int oldEnabled = monitor->enabled;
1893  int newEnabled = atoi(enabled.c_str());
1894  monitor->function = newFunction;
1895  monitor->enabled = newEnabled;
1896 
1897  if (m_debug)
1898  cout << "SetMonitorFunction MonitorId: " << monitorID << endl <<
1899  " oldEnabled: " << oldEnabled << endl <<
1900  " newEnabled: " << newEnabled << endl <<
1901  " oldFunction: " << oldFunction << endl <<
1902  " newFunction: " << newFunction << endl;
1903 
1904  if ( newFunction != oldFunction || newEnabled != oldEnabled)
1905  {
1906  string sql("UPDATE Monitors ");
1907  sql += "SET Function = '" + function + "', ";
1908  sql += "Enabled = '" + enabled + "' ";
1909  sql += "WHERE Id = '" + monitorID + "'";
1910 
1911  if (mysql_query(&g_dbConn, sql.c_str()))
1912  {
1913  fprintf(stderr, "%s\n", mysql_error(&g_dbConn));
1914  sendError(ERROR_MYSQL_QUERY);
1915  return;
1916  }
1917 
1918  if (m_debug)
1919  cout << "Monitor function SQL update OK" << endl;
1920 
1921  string status = runCommand(g_binPath + "/zmdc.pl check");
1922 
1923  // Now refresh servers
1924  if (RUNNING.compare(0, RUNNING.size(), status, 0, RUNNING.size()) == 0)
1925  {
1926  if (m_debug)
1927  cout << "Monitor function Refreshing daemons" << endl;
1928 
1929  bool restart = (oldFunction == FUNCTION_NONE) ||
1930  (newFunction == FUNCTION_NONE) ||
1931  (newEnabled != oldEnabled);
1932 
1933  if (restart)
1934  zmcControl(monitor, RESTART);
1935  else
1936  zmcControl(monitor, "");
1937  zmaControl(monitor, RELOAD);
1938  }
1939  else
1940  if (m_debug)
1941  cout << "zm daemons are not running" << endl;
1942  }
1943  else
1944  cout << "Not updating monitor function as identical to existing configuration" << endl;
1945 
1946  ADD_STR(outStr, "OK")
1947  send(outStr);
1948 }
1949 
1950 void ZMServer::zmcControl(MONITOR *monitor, const string &mode)
1951 {
1952  string zmcArgs = "";
1953  string sql = "";
1954  sql += "SELECT count(if(Function!='None',1,NULL)) as ActiveCount ";
1955  sql += "FROM Monitors ";
1956 
1957  if (monitor->type == "Local" )
1958  {
1959  sql += "WHERE Device = '" + monitor->device + "'";
1960  zmcArgs = "-d " + monitor->device;
1961  }
1962  else
1963  {
1964  sql += "WHERE Id = '" + monitor->getIdStr() + "'";
1965  zmcArgs = "-m " + monitor->mon_id;
1966  }
1967 
1968  if (mysql_query(&g_dbConn, sql.c_str()))
1969  {
1970  fprintf(stderr, "%s\n", mysql_error(&g_dbConn));
1971  sendError(ERROR_MYSQL_QUERY);
1972  return;
1973  }
1974 
1975  MYSQL_RES *res;
1976  MYSQL_ROW row;
1977  int activeCount;
1978 
1979  res = mysql_store_result(&g_dbConn);
1980  row = mysql_fetch_row(res);
1981 
1982  if (row)
1983  activeCount = atoi(row[0]);
1984  else
1985  {
1986  sendError(ERROR_MYSQL_QUERY);
1987  return;
1988  }
1989 
1990  if (!activeCount)
1991  runCommand(g_binPath + "/zmdc.pl stop zmc " + zmcArgs);
1992  else
1993  {
1994  if (mode == RESTART)
1995  runCommand(g_binPath + "/zmdc.pl stop zmc " + zmcArgs);
1996 
1997  runCommand(g_binPath + "/zmdc.pl start zmc " + zmcArgs);
1998  }
1999 }
2000 
2001 void ZMServer::zmaControl(MONITOR *monitor, const string &mode)
2002 {
2003  int zmOptControl = atoi(getZMSetting("ZM_OPT_CONTROL").c_str());
2004  int zmOptFrameServer = atoi(getZMSetting("ZM_OPT_FRAME_SERVER").c_str());
2005 
2006  if (monitor->function == FUNCTION_MODECT ||
2007  monitor->function == FUNCTION_RECORD ||
2008  monitor->function == FUNCTION_MOCORD ||
2009  monitor->function == FUNCTION_NODECT)
2010  {
2011  if (mode == RESTART)
2012  {
2013  if (zmOptControl)
2014  runCommand(g_binPath + "/zmdc.pl stop zmtrack.pl -m " + monitor->getIdStr());
2015 
2016  runCommand(g_binPath + "/zmdc.pl stop zma -m " + monitor->getIdStr());
2017 
2018  if (zmOptFrameServer)
2019  runCommand(g_binPath + "/zmdc.pl stop zmf -m " + monitor->getIdStr());
2020  }
2021 
2022  if (zmOptFrameServer)
2023  runCommand(g_binPath + "/zmdc.pl start zmf -m " + monitor->getIdStr());
2024 
2025  runCommand(g_binPath + "/zmdc.pl start zma -m " + monitor->getIdStr());
2026 
2027  if (zmOptControl && monitor->controllable && monitor->trackMotion &&
2028  ( monitor->function == FUNCTION_MODECT || monitor->function == FUNCTION_MOCORD) )
2029  runCommand(g_binPath + "/zmdc.pl start zmtrack.pl -m " + monitor->getIdStr());
2030 
2031  if (mode == RELOAD)
2032  runCommand(g_binPath + "/zmdc.pl reload zma -m " + monitor->getIdStr());
2033  }
2034  else
2035  {
2036  if (zmOptControl)
2037  runCommand(g_binPath + "/zmdc.pl stop zmtrack.pl -m " + monitor->getIdStr());
2038 
2039  runCommand(g_binPath + "/zmdc.pl stop zma -m " + monitor->getIdStr());
2040 
2041  if (zmOptFrameServer)
2042  runCommand(g_binPath + "/zmdc.pl stop zmf -m " + monitor->getIdStr());
2043  }
2044 }
GLuint buffer
void tokenize(const string &command, vector< string > &tokens)
Definition: zmserver.cpp:536
MYTH_GLsizeiptr const GLvoid * data
string id
Definition: zmserver.h:189
const string FUNCTION_MODECT
Definition: zmserver.h:52
const string RUNNING
Definition: zmserver.h:60
int mapFile
Definition: zmserver.h:184
void getMonitorStatus(string id, string type, string device, string host, string channel, string function, string &zmcStatus, string &zmaStatus, string enabled)
Definition: zmserver.cpp:1035
int getState(void)
Definition: zmserver.cpp:399
void handleGetEventFrame(vector< string > tokens)
Definition: zmserver.cpp:1084
int last_read
Definition: zmserver.h:179
int mon_id
Definition: zmserver.h:177
string g_server
Definition: zmserver.cpp:86
bool m_debug
Definition: zmserver.h:232
int g_minorVersion
Definition: zmserver.cpp:93
void connectToDatabase(void)
Definition: zmserver.cpp:180
bool m_useDeepStorage
Definition: zmserver.h:236
static void error(const char *str,...)
Definition: vbi.c:41
void initMonitor(bool debug, string mmapPath, int shmKey)
Definition: zmserver.cpp:240
void handleGetCameraList(void)
Definition: zmserver.cpp:1463
string g_webPath
Definition: zmserver.cpp:88
void kickDatabase(bool debug)
Definition: zmserver.cpp:204
string device
Definition: zmserver.h:171
void zmaControl(MONITOR *monitor, const string &mode)
Definition: zmserver.cpp:2001
void handleRunZMAudit(void)
Definition: zmserver.cpp:1588
string host
Definition: zmserver.h:172
key_t m_shmKey
Definition: zmserver.h:240
int height
Definition: zmserver.h:175
long f_bavail
Definition: compat.h:159
const char * filename
Definition: ioapi.h:135
void handleGetEventList(vector< string > tokens)
Definition: zmserver.cpp:763
void loadZMConfig(const string &configfile)
Definition: zmserver.cpp:107
unsigned int uint
Definition: compat.h:136
const string RESTART
Definition: zmserver.h:58
string getZMSetting(const string &setting)
Definition: zmserver.cpp:1814
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
int palette
Definition: zmserver.h:181
void handleGetEventDates(vector< string > tokens)
Definition: zmserver.cpp:857
Definition: zmserver.h:68
string g_webUser
Definition: zmserver.cpp:90
int m_sock
Definition: zmserver.h:233
int g_revisionVersion
Definition: zmserver.cpp:94
string g_zmversion
Definition: zmserver.cpp:84
string g_binPath
Definition: zmserver.cpp:91
voidpf void * buf
Definition: ioapi.h:136
const string FUNCTION_NONE
Definition: zmserver.h:56
State state
Definition: zmserver.h:78
bool isValid(void)
Definition: zmserver.cpp:367
string m_eventFileFormat
Definition: zmserver.h:238
int g_majorVersion
Definition: zmserver.cpp:92
uint32_t state
Definition: zmserver.h:100
time_t g_lastDBKick
Definition: zmserver.cpp:96
string g_password
Definition: zmserver.cpp:85
void handleGetFrameList(vector< string > tokens)
Definition: zmserver.cpp:1348
MYSQL g_dbConn
Definition: zmserver.cpp:83
char m_buf[10]
Definition: zmserver.h:242
uint32_t imagesize
Definition: zmserver.h:113
string getIdStr(void)
Definition: zmserver.cpp:377
int statfs(const char *path, struct statfs *buffer)
Definition: compat.h:166
string type
Definition: zmserver.h:168
vector< MONITOR * > m_monitors
Definition: zmserver.h:234
const char * name
Definition: ParseText.cpp:338
const string FUNCTION_MOCORD
Definition: zmserver.h:55
string g_database
Definition: zmserver.cpp:87
int errno
bool send(const string &s) const
Definition: zmserver.cpp:620
map< int, MONITOR * > m_monitorMap
Definition: zmserver.h:235
void * shm_ptr
Definition: zmserver.h:185
const string FUNCTION_RECORD
Definition: zmserver.h:54
int image_buffer_count
Definition: zmserver.h:173
void handleGetMonitorStatus(void)
Definition: zmserver.cpp:924
void handleGetServerStatus(void)
Definition: zmserver.cpp:708
int enabled
Definition: zmserver.h:170
__u64 val
Definition: videodev2.h:1041
struct v4l2_mpeg_vbi_itv0_line line[35]
Definition: videodev2.h:1039
VERBOSE_PREAMBLE Most debug(nodatabase, notimestamp, noextra)") VERBOSE_MAP(VB_IMPORTANT
unsigned char * shared_images
Definition: zmserver.h:178
int bytes_per_pixel
Definition: zmserver.h:176
typedef long(ZCALLBACK *tell_file_func) OF((voidpf opaque
Definition: compat.h:154
int getFrameSize(void)
Definition: zmserver.cpp:426
bool processRequest(char *buf, int nbytes)
Definition: zmserver.cpp:559
void getMonitorList(void)
Definition: zmserver.cpp:1606
string g_user
Definition: zmserver.cpp:89
string function
Definition: zmserver.h:169
SharedData26 * shared_data26
Definition: zmserver.h:188
int FILE
Definition: mythburn.py:110
int controllable
Definition: zmserver.h:182
void sendError(string error)
Definition: zmserver.cpp:661
void handleGetLiveFrame(vector< string > tokens)
Definition: zmserver.cpp:1278
string status
Definition: zmserver.h:180
void handleGetMonitorList(void)
Definition: zmserver.cpp:1479
string name
Definition: zmserver.h:167
void handleSetMonitorFunction(vector< string > tokens)
Definition: zmserver.cpp:1849
const string FUNCTION_NODECT
Definition: zmserver.h:53
ZMServer(int sock, bool debug)
Definition: zmserver.cpp:439
__u32 id
Definition: videodev2.h:1038
long f_blocks
Definition: compat.h:157
GLint GLenum GLsizei width
int getFrame(unsigned char *buffer, int bufferSize, MONITOR *monitor)
Definition: zmserver.cpp:1680
uint8_t format
Definition: zmserver.h:112
static int x0
Definition: mythsocket.cpp:59
int getLastWriteIndex(void)
Definition: zmserver.cpp:388
Definition: zmserver.h:66
typedef void(APIENTRY *MYTH_GLTEXIMAGE1DPROC)(GLenum target
int getSubpixelOrder(void)
Definition: zmserver.cpp:410
void zmcControl(MONITOR *monitor, const string &mode)
Definition: zmserver.cpp:1950
int width
Definition: zmserver.h:174
long f_bsize
Definition: compat.h:156
Definition: zmserver.h:64
int trackMotion
Definition: zmserver.h:183
GLint GLenum GLsizei GLint GLenum GLenum type
GLuint GLfloat x
uint32_t last_write_index
Definition: zmserver.h:98
void handleDeleteEventList(vector< string > tokens)
Definition: zmserver.cpp:1553
const char int mode
Definition: ioapi.h:135
Definition: zmserver.h:67
const string FUNCTION_MONITOR
Definition: zmserver.h:51
bool m_useAnalysisImages
Definition: zmserver.h:237
void handleDeleteEvent(vector< string > tokens)
Definition: zmserver.cpp:1516
int last_write_index
Definition: zmserver.h:79
void handleGetAnalysisFrame(vector< string > tokens)
Definition: zmserver.cpp:1148
__u32 height
Definition: videodev2.h:1039
string m_analysisFileFormat
Definition: zmserver.h:239
bool checkVersion(int major, int minor, int revision)
Definition: zmserver.cpp:99
const string RELOAD
Definition: zmserver.h:59
string runCommand(string command)
Definition: zmserver.cpp:1021
long long getDiskSpace(const string &filename, long long &total, long long &used)
Definition: zmserver.cpp:678
void handleHello(void)
Definition: zmserver.cpp:668
SharedData * shared_data
Definition: zmserver.h:187
GLenum GLsizei len
void handleGetAlarmStates(void)
Definition: zmserver.cpp:741
string m_mmapPath
Definition: zmserver.h:241