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.
 
 
 
 
 
 

199 lines
15 KiB

#ifndef __MYSQL_DATA_BINDER_HEADER__
#define __MYSQL_DATA_BINDER_HEADER__
#include "dataBinder.h"
#include "../../data/mysql/mysql_class.h"
#include "../../components/base/basicSettingsProvider.h"
#include "../../alg/generic/md5.h"
#include "../../alg/lgs/mask.h"
class mysqlDBC: public dataBinder {
private:
basicLogCollection * m_pLog;
config_setting_t * m_pSettings;
MySQL_Connector * m_pDatabase;
bool m_bIsConnected;
bool m_bIsServerLocal;
char m_pDbHost[CLOG];
char m_pDbUsername[CLOG];
char m_pDbPassword[CLOG];
char m_pDbDatabase[CLOG];
uint32_t m_nSiteID;
uint32_t m_nServerID;
uint32_t m_nServerNodeID;
static mysqlDBC * _instance;
explicit mysqlDBC( config_setting_t * Settings = NULL );
public:
static mysqlDBC * getInstance( config_setting_t * Settings = NULL );
virtual ~mysqlDBC();
/* Functionality */
bool connect( void );
bool isLocal( void ) const { return m_bIsServerLocal; };
//SET GLOBAL tmp_table_size = 1024 * 1024 * 1024 * 2;
//SET GLOBAL max_heap_table_size = 1024 * 1024 * 1024 * 2;
//SELECT @@max_heap_table_size;
//SHOW VARIABLES LIKE 'max_heap_table_size';
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 );
bool addDeviceDraw( uint32_t DBID, uint8_t type, uint8_t lrf, void *th_data, uint32_t th_size );
bool addLRFDraw( uint32_t DBID, uint32_t SIZE, CSTR ID, uint8_t kID =0, uint8_t type = 0, bool rendered = false );
uint32_t addLRFMask( uint32_t devID, uint8_t lrfID = 0, uint8_t layerID = 0 );
uint32_t addLRFMaskPolygone( uint32_t maskID, uint8_t r, uint8_t g, uint8_t b );
bool addLRFMaskPolygonePoint( uint32_t polyID, int16_t x, int16_t y );
bool addIPCam( OBSERVER_RESULT *tPtr );
uint32_t addLocalMediaSource( uint32_t SiteID, CSTR path, uint32_t width, uint32_t height );
uint32_t addLocalDCB( uint32_t SiteID, CSTR PATH, CSTR SERIAL, uint8_t CNT, uint32_t status );
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 );
uint32_t addLocalNIF( CSTR device, CSTR mac, NIF_TYPE dtype, NIF_MODE dmode, uint32_t aux_id = 0 );
uint32_t addLocalNetwork( uint32_t NIF_ID, NETWORK_TYPE net_type, CSTR address, CSTR mask, CSTR gateway, CSTR broadcast );
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 );
uint32_t addLocalWiFi( uint32_t NIF_ID, WIFI_MODE mode, CSTR SSID, CSTR password, WIFI_ENCRIPTION encryption, uint32_t router_id=0 );
bool addNotification( uint32_t MSG_ID, uint8_t DIS_LVL = 0, uint32_t OBJ_ID=0 );
bool addPicture( DBC_SNAPSHOT_DATA *ptr, CSTR ext );
//bool addPictureEvent( uint32_t evtID, uint32_t pictureoID );
virtual uint32_t addResource( uint8_t type, CSTR devName, uint32_t auxID = 0 );
//uint32_t addResource( uint32_t NodeID, uint8_t type, CSTR devName, uint32_t auxID = 0 );
//uint32_t addUploadFile( uint32_t NodeID, CSTR uid, CSTR fileName );
bool addVideoEvent( uint32_t evtID, uint32_t videoID, uint32_t clen );
uint32_t addVideoRecord( uint32_t streamID, CSTR md5, CSTR ext, uint32_t ts, uint32_t tsms, uint32_t fps );
bool cleanResources( bool all = false );
bool cleanLRFMask( uint32_t maskID, bool deleteMask = false );
bool cleanNodeEvents( uint32_t NodeID, bool all = false );
bool cleanEvents2PictureBinding( uint32_t PicID );
bool cleanEvents2VideoBinding( uint32_t PicID );
void lazyEventArchiver( uint32_t DalayTime = 10 );
DBC_INT_LIST * listCamMediaStreams( uint32_t CAMID );
DBC_INT_LIST * listStreamCapPictures( uint32_t StreamID, uint32_t cnt );
DBC_INT_LIST * listDetectionProfileIDs( uint32_t nodeID );
DBC_INT_LIST * listDetectionProfiles( uint32_t nodeID );
DBC_INT_LIST * listFilters( uint32_t ServerID );
DBC_INT_LIST * listLRFMaskVertexes( uint32_t MaskID );
DBC_INT_LIST * listLRFMaskVertexPoints( uint32_t VertexID );
DBC_INT_LIST * listMediaServerStreams( uint32_t SiteId, uint32_t MediaServerID, uint8_t listingType = LIST_ALL_RECORDS );
DBC_INT_LIST * listMediaStreams( uint32_t SiteId, uint8_t listingType = LIST_ALL_RECORDS );
DBC_INT_LIST * listModules();
DBC_INT_LIST * listNetworks( uint32_t nif_id );
DBC_INT_LIST * listNewModules( DBC_INT_LIST * old_ids );
DBC_INT_LIST * listNewNodes( uint32_t SiteID, uint32_t ServerID, DBC_INT_LIST * old_ids );
DBC_INT_LIST * listNodes( uint32_t SiteID, uint32_t ServerID, bool all = false );
//DBC_INT_LIST * listSockets( uint32_t NodeID );
DBC_INT_LIST * listResources( uint32_t NodeID = 0 );
simplePolygone * loadLRFMaskVertex( uint32_t vid );
bool getAllCamRecords( uint32_t SiteID, vectorCamRecords &VR );
DBC_APF_DATA * getAPFData( uint32_t APFID );
DBC_CAM_DATA * getCamData( uint32_t CamID );
uint32_t getCamId( CSTR UUID );
bool getConnectionStatus(void){return m_bIsConnected;};
DBC_CAP_DATA * getCamCapPictureData( uint32_t PicID );
DBC_EVT_RECORD * getEventByUUID( CSTR UUID );
DBC_MODULE_EMBED_VIDEO_DATA * getEmbedVideoData( uint32_t ID );
DBC_FH_DATA * getFlyHunterData( uint32_t ID );
//int getIPCamCount( uint32_t SiteID );
KAFKA_TEMPLATE * getKafkaTemplateForEvent( uint32_t ModuleID, uint32_t ClassID, uint32_t EventID );
//bool getLastEvents( vectorEventRecords &VR, uint32_t tss, uint32_t tsms );
virtual DBC_LRF_INI * getINIData( uint32_t lrfID );
DBC_LRF_DATA * getLRFData( uint32_t ID );
uint8_t getLRFDataStatus( uint32_t ID );
PLGS_2D_PARAMETERS getLRFDetectionProfile( uint32_t lrfID, uint8_t profileID, bool master );
CSTR getLRFDraw( uint32_t DBID );
uint32_t getLRFMaskID( uint32_t deviceID, uint8_t lrfID = 0, uint8_t layer = 0 );
DBC_MEDIA_STREAM_DATA * getMediaStreamData( uint32_t ID );
DBC_MEDIA_SERVER_DATA * getMediaServerData( uint32_t ID );
DBC_MEDIA_SERVER_STREAM_DATA * getMediaServerStreamData( uint32_t ID );
DBC_MEDIA_SERVER_STREAM_DATA * getMediaServerStreamDataBySource( uint32_t ID );
DBC_MODULE_DATA * getModuleData( uint32_t ID );
CSTR getNodeName( uint32_t NodeID );
uint32_t getNodeAuxParam( uint32_t NodeID );
uint32_t getNodeAuxID( uint32_t NodeID );
DBC_NETWORK_DATA * getNetworkData( uint32_t net_id );
uint32_t getNetworkInfrastructureID( uint32_t nif_id );
DBC_NET_IF_DATA * getNIF_Data( uint32_t ID );
uint32_t getNIF_ID( CSTR key );
uint32_t getNIF_IDbyDevice( CSTR device );
DBC_NODE_DATA * getNodeData( uint32_t ID );
DBC_PUSHED_CMD * getNodePushedCMD( uint32_t NodeID );
DBC_PUSHED_CMD * getActivePushedCMD( uint32_t NodeID );
DBC_PUSHED_CMD * getPushedCMD( uint32_t CmdID );
//uint32_t getNodeSocketID( uint32_t NodeID, uint32_t auxID, uint8_t SocketType, CSTR path );
DBC_RESOURCE_DATA * getResourceData( uint32_t ResourceID );
uint32_t getResourceID( uint32_t NodeID, uint8_t type, uint32_t auxID );
uint32_t getServerID( CSTR identity );
uint32_t getServerNode( uint32_t SID );
KAFKA_SETTINGS * getSettingsKAFKA( uint32_t NodeID );
DBC_SITE_DATA * getSiteData( uint32_t ID );
//DBC_SOCKET_DATA * getSocketData( uint32_t ID );
DBC_TARGET_FLITER_DATA * getTargetFilterData( uint32_t ID );
DBC_UART_DATA * getUartData( uint32_t UartID );
uint32_t getUartID( uint32_t NodeID, uint8_t Type, CSTR path );
uint32_t getWiFi_ID( uint32_t nif_id );
bool fillShadow2D( uint32_t ID, SHADOW & SH );
void deleteCamCapPicture( uint32_t PicID );
void deleteNode( uint32_t NodeID );
void deleteCamera( uint32_t CamID );
void deleteConnections( uint32_t NodeID );
void deleteNodeEvents( uint32_t NodeID );
void deleteMediaStream( uint32_t MediaID );
void deleteNIF( uint32_t NifID );
void deleteNIS( uint32_t NisID );
void deleteResource( uint32_t ResourceID );
void deleteSensor( uint32_t SensorID );
void deleteUART( uint32_t UARTID );
//void finalizeVideoRecord( uint32_t videoID, uint32_t clen );
void registerServer( uint32_t SiteID, CSTR identity, int PID, uint32_t *ServID, uint32_t *ServNode );
void unregisterServer();
bool transferEvtToArchive( uint32_t SECONDS = ONE_DAY_HISTORY );
bool setNodeOnline( uint32_t NodeID, uint8_t status=NODE_STATUS_WORK );
bool setNodeOffline( uint32_t NodeID );
//bool setOnlineStatus( bool Status );
bool setLRFDetectionProfile( uint32_t lrfID, uint8_t profileID );
bool setLRFDataStatus( uint32_t lrfID, uint8_t ST );
bool setLRFAltSerial( uint32_t lrfID, CSTR Serial );
bool setLRFAltVerison( uint32_t lrfID, CSTR version );
bool setLRFMaskStatus( uint32_t maskID, bool status );
bool setStreamValid( uint32_t streamID, bool status = true );
//bool syncEventArchive( void ); ALTER TABLE table_name AUTO_INCREMENT = start_value;
bool update3DRuntimeStatus( uint32_t lrfID, ALG_RUN_STATUS *ptr );
bool updateAFPBox( uint32_t filterID, CSTR Tag, float x, float y, float z );
bool updateCamRange( uint32_t camID, float range );
bool updateIPCam( CSTR uuid, CSTR Addr );
bool updateIPCam( uint32_t CamID, CSTR Addr );
bool updateLRFSerial( uint32_t lrfID, CSTR Serial );
bool updateLRFVerison( uint32_t lrfID, CSTR version );
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 );
bool updateMediaServerStream( uint32_t id, CSTR mrl=NULL, CSTR key = NULL );
//bool updateNetworkNode( bool OnlineStatus );
bool updateNodePushedCMD( uint32_t CmdID, uint8_t status );
bool updateResourceAUX( uint32_t ResID, uint32_t AUX );
//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 );
virtual bool updateServerUtilisation( DBC_SYS_LOAD_INFO *ptr );
};
#endif