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.

198 lines
15 KiB

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