You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

202 lines
10 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __MYSQL_DATA_BINDER_HEADER__
  2. #define __MYSQL_DATA_BINDER_HEADER__
  3. #include "../../alg/generic/md5.h"
  4. #include "../../alg/lgs/mask.h"
  5. #include "../../components/base/basicSettingsProvider.h"
  6. #include "../../data/mysql/mysql_class.h"
  7. #include "dataBinder.h"
  8. class mysqlDBC : public dataBinder
  9. {
  10. private:
  11. basicLogCollection * m_pLog;
  12. config_setting_t * m_pSettings;
  13. MySQL_Connector * m_pDatabase;
  14. bool m_bIsConnected;
  15. bool m_bIsServerLocal;
  16. char m_pDbHost[CLOG];
  17. char m_pDbUsername[CLOG];
  18. char m_pDbPassword[CLOG];
  19. char m_pDbDatabase[CLOG];
  20. uint32_t m_nSiteID;
  21. uint32_t m_nServerID;
  22. uint32_t m_nServerNodeID;
  23. static mysqlDBC * _instance;
  24. explicit mysqlDBC(config_setting_t * Settings = NULL);
  25. public:
  26. static mysqlDBC * getInstance(config_setting_t * Settings = NULL);
  27. virtual ~mysqlDBC();
  28. /* Functionality */
  29. bool connect(void);
  30. bool isLocal(void) const
  31. {
  32. return m_bIsServerLocal;
  33. }
  34. // SET GLOBAL tmp_table_size = 1024 * 1024 * 1024 * 2;
  35. // SET GLOBAL max_heap_table_size = 1024 * 1024 * 1024 * 2;
  36. // SELECT @@max_heap_table_size;
  37. // SHOW VARIABLES LIKE 'max_heap_table_size';
  38. uint32_t addEvent(uint32_t SRC, CSTR UUID, uint32_t tss, uint32_t tsms, uint8_t evt_type, uint8_t k_id = 0, uint16_t dig_r = 0, float EL = .0f, float AZ = .0f, float RANGE = .0f, float AREA = .0f, float lat = .0f, float lon = .0f,
  39. float alt = .0f, uint32_t RefID = 0, CSTR RefUUID = NULL);
  40. bool addDeviceDraw(uint32_t DBID, uint8_t type, uint8_t lrf, void * th_data, uint32_t th_size);
  41. bool addLRFDraw(uint32_t DBID, uint32_t SIZE, CSTR ID, uint8_t kID = 0, uint8_t type = 0, bool rendered = false);
  42. uint32_t addLRFMask(uint32_t devID, uint8_t lrfID = 0, uint8_t layerID = 0);
  43. uint32_t addLRFMaskPolygone(uint32_t maskID, uint8_t r, uint8_t g, uint8_t b);
  44. bool addLRFMaskPolygonePoint(uint32_t polyID, int16_t x, int16_t y);
  45. bool addIPCam(OBSERVER_RESULT * tPtr);
  46. uint32_t addLocalMediaSource(uint32_t SiteID, CSTR path, uint32_t width, uint32_t height);
  47. uint32_t addLocalDCB(uint32_t SiteID, CSTR PATH, CSTR SERIAL, uint8_t CNT, uint32_t status);
  48. uint32_t addLocalUART(/*uint32_t NodeID,*/ uint8_t utype, uint32_t speed, uint8_t bit, char parity, float stop_bit, CSTR PATH, uint8_t mode = 0, uint16_t port = 0);
  49. uint32_t addLocalNIF(CSTR device, CSTR mac, NIF_TYPE dtype, NIF_MODE dmode, uint32_t aux_id = 0);
  50. uint32_t addLocalNetwork(uint32_t NIF_ID, NETWORK_TYPE net_type, CSTR address, CSTR mask, CSTR gateway, CSTR broadcast);
  51. uint32_t addLocalNetworkInfrastructure(uint32_t NIF_ID, uint32_t OUTBOUND_NIF, bool ena_dhcp = false, CSTR BRANG = NULL, CSTR ERANG = NULL, CSTR MASK = NULL, CSTR LEASE_TIME = NULL);
  52. uint32_t addLocalWiFi(uint32_t NIF_ID, WIFI_MODE mode, CSTR SSID, CSTR password, WIFI_ENCRIPTION encryption, uint32_t router_id = 0);
  53. bool addNotification(uint32_t MSG_ID, uint8_t DIS_LVL = 0, uint32_t OBJ_ID = 0);
  54. bool addPicture(DBC_SNAPSHOT_DATA * ptr, CSTR ext);
  55. // bool addPictureEvent( uint32_t evtID, uint32_t pictureoID );
  56. virtual uint32_t addResource(uint8_t type, CSTR devName, uint32_t auxID = 0);
  57. // uint32_t addResource( uint32_t NodeID, uint8_t type, CSTR devName, uint32_t auxID = 0 );
  58. // uint32_t addUploadFile( uint32_t NodeID, CSTR uid, CSTR fileName );
  59. bool addVideoEvent(uint32_t evtID, uint32_t videoID, uint32_t clen);
  60. uint32_t addVideoRecord(uint32_t streamID, CSTR md5, CSTR ext, uint32_t ts, uint32_t tsms, uint32_t fps);
  61. bool cleanResources(bool all = false);
  62. bool cleanLRFMask(uint32_t maskID, bool deleteMask = false);
  63. bool cleanNodeEvents(uint32_t NodeID, bool all = false);
  64. bool cleanEvents2PictureBinding(uint32_t PicID);
  65. bool cleanEvents2VideoBinding(uint32_t PicID);
  66. void lazyEventArchiver(uint32_t DalayTime = 10);
  67. DBC_INT_LIST * listCamMediaStreams(uint32_t CAMID);
  68. DBC_INT_LIST * listStreamCapPictures(uint32_t StreamID, uint32_t cnt);
  69. DBC_INT_LIST * listDetectionProfileIDs(uint32_t nodeID);
  70. DBC_INT_LIST * listDetectionProfiles(uint32_t nodeID);
  71. DBC_INT_LIST * listFilters(uint32_t ServerID);
  72. DBC_INT_LIST * listLRFMaskVertexes(uint32_t MaskID);
  73. DBC_INT_LIST * listLRFMaskVertexPoints(uint32_t VertexID);
  74. DBC_INT_LIST * listMediaServerStreams(uint32_t SiteId, uint32_t MediaServerID, uint8_t listingType = LIST_ALL_RECORDS);
  75. DBC_INT_LIST * listMediaStreams(uint32_t SiteId, uint8_t listingType = LIST_ALL_RECORDS);
  76. DBC_INT_LIST * listModules();
  77. DBC_INT_LIST * listNetworks(uint32_t nif_id);
  78. DBC_INT_LIST * listNewModules(DBC_INT_LIST * old_ids);
  79. DBC_INT_LIST * listNewNodes(uint32_t SiteID, uint32_t ServerID, DBC_INT_LIST * old_ids);
  80. DBC_INT_LIST * listNodes(uint32_t SiteID, uint32_t ServerID, bool all = false);
  81. // DBC_INT_LIST * listSockets( uint32_t NodeID );
  82. DBC_INT_LIST * listResources(uint32_t NodeID = 0);
  83. simplePolygone * loadLRFMaskVertex(uint32_t vid);
  84. bool getAllCamRecords(uint32_t SiteID, vectorCamRecords & VR);
  85. DBC_APF_DATA * getAPFData(uint32_t APFID);
  86. DBC_CAM_DATA * getCamData(uint32_t CamID);
  87. uint32_t getCamId(CSTR UUID);
  88. bool getConnectionStatus(void)
  89. {
  90. return m_bIsConnected;
  91. }
  92. DBC_CAP_DATA * getCamCapPictureData(uint32_t PicID);
  93. DBC_EVT_RECORD * getEventByUUID(CSTR UUID);
  94. DBC_MODULE_EMBED_VIDEO_DATA * getEmbedVideoData(uint32_t ID);
  95. DBC_FH_DATA * getFlyHunterData(uint32_t ID);
  96. // int getIPCamCount( uint32_t SiteID );
  97. KAFKA_TEMPLATE * getKafkaTemplateForEvent(uint32_t ModuleID, uint32_t ClassID, uint32_t EventID);
  98. // bool getLastEvents( vectorEventRecords &VR, uint32_t tss, uint32_t tsms );
  99. virtual DBC_LRF_INI * getINIData(uint32_t lrfID);
  100. DBC_LRF_DATA * getLRFData(uint32_t ID);
  101. uint8_t getLRFDataStatus(uint32_t ID);
  102. PLGS_2D_PARAMETERS getLRFDetectionProfile(uint32_t lrfID, uint8_t profileID, bool master);
  103. CSTR getLRFDraw(uint32_t DBID);
  104. uint32_t getLRFMaskID(uint32_t deviceID, uint8_t lrfID = 0, uint8_t layer = 0);
  105. DBC_MEDIA_STREAM_DATA * getMediaStreamData(uint32_t ID);
  106. DBC_MEDIA_SERVER_DATA * getMediaServerData(uint32_t ID);
  107. DBC_MEDIA_SERVER_STREAM_DATA * getMediaServerStreamData(uint32_t ID);
  108. DBC_MEDIA_SERVER_STREAM_DATA * getMediaServerStreamDataBySource(uint32_t ID);
  109. DBC_MODULE_DATA * getModuleData(uint32_t ID);
  110. CSTR getNodeName(uint32_t NodeID);
  111. uint32_t getNodeAuxParam(uint32_t NodeID);
  112. uint32_t getNodeAuxID(uint32_t NodeID);
  113. DBC_NETWORK_DATA * getNetworkData(uint32_t net_id);
  114. uint32_t getNetworkInfrastructureID(uint32_t nif_id);
  115. DBC_NET_IF_DATA * getNIF_Data(uint32_t ID);
  116. uint32_t getNIF_ID(CSTR key);
  117. uint32_t getNIF_IDbyDevice(CSTR device);
  118. DBC_NODE_DATA * getNodeData(uint32_t ID);
  119. DBC_PUSHED_CMD * getNodePushedCMD(uint32_t NodeID);
  120. DBC_PUSHED_CMD * getActivePushedCMD(uint32_t NodeID);
  121. DBC_PUSHED_CMD * getPushedCMD(uint32_t CmdID);
  122. // uint32_t getNodeSocketID( uint32_t NodeID, uint32_t auxID, uint8_t SocketType, CSTR path );
  123. DBC_RESOURCE_DATA * getResourceData(uint32_t ResourceID);
  124. uint32_t getResourceID(uint32_t NodeID, uint8_t type, uint32_t auxID);
  125. uint32_t getServerID(CSTR identity);
  126. uint32_t getServerNode(uint32_t SID);
  127. KAFKA_SETTINGS * getSettingsKAFKA(uint32_t NodeID);
  128. DBC_SITE_DATA * getSiteData(uint32_t ID);
  129. // DBC_SOCKET_DATA * getSocketData( uint32_t ID );
  130. DBC_TARGET_FLITER_DATA * getTargetFilterData(uint32_t ID);
  131. DBC_UART_DATA * getUartData(uint32_t UartID);
  132. uint32_t getUartID(uint32_t NodeID, uint8_t Type, CSTR path);
  133. uint32_t getWiFi_ID(uint32_t nif_id);
  134. bool fillShadow2D(uint32_t ID, SHADOW & SH);
  135. void deleteCamCapPicture(uint32_t PicID);
  136. void deleteNode(uint32_t NodeID);
  137. void deleteCamera(uint32_t CamID);
  138. void deleteConnections(uint32_t NodeID);
  139. void deleteNodeEvents(uint32_t NodeID);
  140. void deleteMediaStream(uint32_t MediaID);
  141. void deleteNIF(uint32_t NifID);
  142. void deleteNIS(uint32_t NisID);
  143. void deleteResource(uint32_t ResourceID);
  144. void deleteSensor(uint32_t SensorID);
  145. void deleteUART(uint32_t UARTID);
  146. // void finalizeVideoRecord( uint32_t videoID, uint32_t clen );
  147. void registerServer(uint32_t SiteID, CSTR identity, int PID, uint32_t * ServID, uint32_t * ServNode);
  148. void unregisterServer();
  149. bool transferEvtToArchive(uint32_t SECONDS = ONE_DAY_HISTORY);
  150. bool setNodeOnline(uint32_t NodeID, uint8_t status = NODE_STATUS_WORK);
  151. bool setNodeOffline(uint32_t NodeID);
  152. // bool setOnlineStatus( bool Status );
  153. bool setLRFDetectionProfile(uint32_t lrfID, uint8_t profileID);
  154. bool setLRFDataStatus(uint32_t lrfID, uint8_t ST);
  155. bool setLRFAltSerial(uint32_t lrfID, CSTR Serial);
  156. bool setLRFAltVerison(uint32_t lrfID, CSTR version);
  157. bool setLRFMaskStatus(uint32_t maskID, bool status);
  158. bool setStreamValid(uint32_t streamID, bool status = true);
  159. // bool syncEventArchive( void ); ALTER TABLE table_name AUTO_INCREMENT = start_value;
  160. bool update3DRuntimeStatus(uint32_t lrfID, ALG_RUN_STATUS * ptr);
  161. bool updateAFPBox(uint32_t filterID, CSTR Tag, float x, float y, float z);
  162. bool updateCamRange(uint32_t camID, float range);
  163. bool updateIPCam(CSTR uuid, CSTR Addr);
  164. bool updateIPCam(uint32_t CamID, CSTR Addr);
  165. bool updateLRFSerial(uint32_t lrfID, CSTR Serial);
  166. bool updateLRFVerison(uint32_t lrfID, CSTR version);
  167. bool updateLRFDetectionProfile(uint32_t lrfID, uint8_t profileID, bool master, uint16_t nOrder, uint16_t nOffset, uint16_t nDelta, uint16_t nWidth, uint16_t nFlip, uint16_t nSun, uint8_t bSST, uint32_t GP = 0, uint32_t spikes = 0);
  168. bool updateMediaServerStream(uint32_t id, CSTR mrl = NULL, CSTR key = NULL);
  169. // bool updateNetworkNode( bool OnlineStatus );
  170. bool updateNodePushedCMD(uint32_t CmdID, uint8_t status);
  171. bool updateResourceAUX(uint32_t ResID, uint32_t AUX);
  172. // bool updateServerUtilisation( uint32_t ServerID, uint32_t nCores, float cpu1, float cpu5, float cpu15, float mem, float disk, uint64_t dtsize, uint64_t dcsize, uint64_t mtsize, uint64_t mcsize );
  173. virtual bool updateServerUtilisation(DBC_SYS_LOAD_INFO * ptr);
  174. };
  175. #endif