|
|
#include "MySQL_dataBinder.h"
#define LOG( X ) m_pLog->Log( "MDBC", this, X )
#ifdef DEBUG
#define LOG_ERROR( X ) {\
char _tBfrErrMSG2w34[256];\ sprintf( _tBfrErrMSG2w34, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\ m_pLog->Log( "MDBC", this, _LOG_ERROR, _tBfrErrMSG2w34 );\ }#else
#define LOG_ERROR( X ) m_pLog->Log( "MDBC", this, _LOG_ERROR, X );
#endif
mysqlDBC *mysqlDBC::_instance = NULL;
/**
* Returns the single instance of the object. */mysqlDBC* mysqlDBC::getInstance( config_setting_t * Settings ) { // check if the instance has been created yet
if( 0 == _instance ){ // if not, then create it
_instance = new mysqlDBC( Settings ); }; // return the single instance
return _instance;};
mysqlDBC::mysqlDBC( config_setting_t * Settings ):dataBinder(){ m_pLog = basicLogCollection::getInstance(); m_pSettings = basicSettingsProvider::getInstance()->getSubNode( Settings, "DBC" ); m_bIsConnected = false; m_bIsServerLocal = false; m_nSiteID = 0; m_pDatabase = NULL;};
mysqlDBC::~mysqlDBC(){ m_bIsConnected = false; if( m_pDatabase != NULL ) delete( m_pDatabase ); m_pDatabase = NULL; _instance = NULL;};
bool mysqlDBC::connect( void ){ config_setting_t * tSetting; m_bIsConnected = false; if( m_pSettings!= NULL ) { tSetting = config_setting_get_member( m_pSettings, "DATABASE_HOST" ); if( tSetting == NULL ){ tSetting = config_setting_add(m_pSettings, "DATABASE_HOST", CONFIG_TYPE_STRING ); config_setting_set_string( tSetting, "localhost" ); basicSettingsProvider::getInstance()->compromise(); LOG("No DB Host Setting! Using default!"); }; sprintf(m_pDbHost, "%s", config_setting_get_string(tSetting));
//Check if using local database
if( strstr( m_pDbHost, "localhost" )!= NULL ){ m_bIsServerLocal = true; } else { // Check if setting is local IP address
};
tSetting = config_setting_get_member(m_pSettings, "DATABASE_NAME"); if( tSetting == NULL ){ tSetting = config_setting_add(m_pSettings, "DATABASE_NAME", CONFIG_TYPE_STRING ); config_setting_set_string( tSetting, "dfsl_gunter" ); basicSettingsProvider::getInstance()->compromise(); LOG("No DB Database Setting! Using default!"); }; sprintf(m_pDbDatabase, "%s", config_setting_get_string(tSetting)); tSetting = config_setting_get_member( m_pSettings, "DATABASE_USER" ); if( tSetting == NULL ){ tSetting = config_setting_add(m_pSettings, "DATABASE_USER", CONFIG_TYPE_STRING ); config_setting_set_string( tSetting, "dbroot" ); basicSettingsProvider::getInstance()->compromise(); LOG("No DB User Setting! Using default!"); }; sprintf(m_pDbUsername, "%s", config_setting_get_string(tSetting)); tSetting = config_setting_get_member( m_pSettings, "DATABASE_PASSWORD" ); if( tSetting == NULL ){ tSetting = config_setting_add(m_pSettings, "DATABASE_PASSWORD", CONFIG_TYPE_STRING ); config_setting_set_string( tSetting, "123567" ); basicSettingsProvider::getInstance()->compromise(); LOG("No DB Password Setting! Using default!"); }; sprintf(m_pDbPassword, "%s", config_setting_get_string(tSetting)); basicSettingsProvider::getInstance()->validate(); m_pDatabase = new MySQL_Connector(); if( m_pDatabase == NULL )return false; m_bIsConnected = m_pDatabase->Connect( m_pDbDatabase, m_pDbHost, m_pDbUsername, m_pDbPassword ); } else { LOG_ERROR("No Settings Provided!"); }; return m_bIsConnected;};
void mysqlDBC::deleteCamCapPicture( uint32_t PicID ){ if(m_bIsConnected) { char tQBuf[MAX_PATH_LEN]; sprintf( tQBuf, "DELETE FROM `pictures` WHERE `id`=%d", PicID );#ifdef DEBUG_EXTRA
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); };};
void mysqlDBC::deleteNode( uint32_t NodeID ){ if(m_bIsConnected) { char tQBuf[MAX_PATH_LEN]; sprintf( tQBuf, "DELETE FROM `nodes` WHERE `id`=%d", NodeID );#ifdef DEBUG
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); };};
void mysqlDBC::deleteCamera( uint32_t CamID ){ if(m_bIsConnected) { char tQBuf[MAX_PATH_LEN]; sprintf( tQBuf, "DELETE FROM `cameras` WHERE `id`=%d", CamID );#ifdef DEBUG
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); };};
void mysqlDBC::deleteResource( uint32_t ResourceID ){ if(m_bIsConnected) { char tQBuf[MAX_PATH_LEN]; sprintf( tQBuf, "DELETE FROM `resources` WHERE `id`=%d", ResourceID );#ifdef DEBUG
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); };};
void mysqlDBC::deleteSensor( uint32_t SensorID ){ if(m_bIsConnected) { char tQBuf[MAX_PATH_LEN]; sprintf( tQBuf, "DELETE FROM `lrf_sensors` WHERE `id`=%d", SensorID );#ifdef DEBUG
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); };};
void mysqlDBC::deleteNodeEvents( uint32_t NodeID ){ if(m_bIsConnected) { char tQBuf[MAX_PATH_LEN]; sprintf(tQBuf, "DELETE `ep` FROM `events_2_pictures` `ep` LEFT JOIN `events_archive` `ea` ON ( `ep`.`evt_id` = `ea`.`id` ) WHERE `ea`.`node_id`=%d", NodeID);#ifdef DEBUG
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf );
sprintf(tQBuf, "DELETE `ep` FROM `events_2_videos` `ep` LEFT JOIN `events_archive` `ea` ON ( `ep`.`evt_id` = `ea`.`id` ) WHERE `ea`.`node_id`=%d", NodeID);#ifdef DEBUG
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf );
sprintf( tQBuf, "DELETE FROM `events_archive` WHERE `node_id`=%d", NodeID );#ifdef DEBUG
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf );
sprintf( tQBuf, "DELETE FROM `events_cloud` WHERE `node_id`=%d", NodeID );#ifdef DEBUG
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); };};
void mysqlDBC::deleteUART( uint32_t UARTID ){ if(m_bIsConnected) { char tQBuf[MAX_PATH_LEN]; sprintf( tQBuf, "DELETE FROM `uart_settings` WHERE `id`=%d", UARTID );#ifdef DEBUG
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); };};
void mysqlDBC::deleteConnections( uint32_t NodeID ){ if(m_bIsConnected) { char tQBuf[MAX_PATH_LEN]; sprintf( tQBuf, "DELETE FROM `connections` WHERE `from`=%d OR `to`=%d", NodeID, NodeID );#ifdef DEBUG
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); };};
void mysqlDBC::deleteMediaStream( uint32_t MediaID ){ if(m_bIsConnected) { char tQBuf[MAX_PATH_LEN]; sprintf( tQBuf, "DELETE FROM `media_streams` WHERE `id`=%d", MediaID );#ifdef DEBUG
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); };};
void mysqlDBC::deleteNIF( uint32_t NifID ){ if(m_bIsConnected) { char tQBuf[MAX_PATH_LEN]; sprintf( tQBuf, "DELETE FROM `network_interfaces` WHERE `id`=%d", NifID );#ifdef DEBUG
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); };};
void mysqlDBC::deleteNIS( uint32_t NisID ){ if(m_bIsConnected) { char tQBuf[MAX_PATH_LEN]; sprintf( tQBuf, "DELETE FROM `network_infrastructure` WHERE `id`=%d", NisID );#ifdef DEBUG
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); };};
bool mysqlDBC::cleanEvents2PictureBinding( uint32_t PicID ){ if(m_bIsConnected) { char tQBuf[MAX_PATH_LEN]; sprintf( tQBuf, "DELETE FROM `events_2_pictures` WHERE `picture_id`=%d", PicID );#ifdef DEBUG_EXTRA
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); return true; }; return false;};
bool mysqlDBC::cleanEvents2VideoBinding( uint32_t VidID ){ if(m_bIsConnected) { char tQBuf[MAX_PATH_LEN]; sprintf( tQBuf, "DELETE FROM `events_2_videos` WHERE `video_id`=%d", VidID );#ifdef DEBUG_EXTRA
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); return true; }; return false;};
bool mysqlDBC::cleanResources(bool all ){ if(m_bIsConnected) { char tQBuf[MAX_PATH_LEN]; if( all ) { sprintf( tQBuf, "UPDATE `resources` SET `active`=0 WHERE `node_id`=%d", m_nServerNodeID ); } else { sprintf( tQBuf, "UPDATE `resources` SET `active`=0 WHERE ( `node_id`=%d ) AND ( `type`=100 OR `type`=101 OR `type`=103 OR `type`=120 )", m_nServerNodeID ); };#ifdef DEBUG_EXTRA
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); return true; }; return false;};
bool mysqlDBC::cleanNodeEvents( uint32_t NodeID, bool all ){ if(m_bIsConnected) { char tQBuf[MAX_PATH_LEN]; if( all ) { sprintf( tQBuf, "DELETE FROM `events_cloud` WHERE `node_id`=%d", NodeID ); m_pDatabase->SilentQuery( tQBuf ); sprintf( tQBuf, "DELETE FROM `events_archive` WHERE `node_id`=%d", NodeID ); m_pDatabase->SilentQuery( tQBuf ); } else { sprintf( tQBuf, "DELETE FROM `events_cloud` WHERE `node_id`=%d", NodeID ); };#ifdef DEBUG_EXTRA
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); return true; }; return false;};
bool mysqlDBC::cleanLRFMask( uint32_t maskID, bool deleteMask ){ if(m_bIsConnected) { char tQBuf[MAX_PATH_LEN]; sprintf( tQBuf, "DELETE FROM `lrf_mask_trace_zones` WHERE `zone_id` IN ( SELECT `id` FROM `lrf_mask_traces` WHERE `mask_id`=%d )", maskID );#ifdef DEBUG_EXTRA
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); sprintf( tQBuf, "DELETE FROM `lrf_mask_traces` WHERE `mask_id`=%d", maskID );#ifdef DEBUG_EXTRA
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); sprintf( tQBuf, "DELETE FROM `lrf_mask_vertex_points` WHERE `vertex_id` IN ( SELECT `id` FROM `lrf_mask_vertexes` WHERE `mask_id`=%d )", maskID );#ifdef DEBUG_EXTRA
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); sprintf( tQBuf, "DELETE FROM `lrf_mask_vertexes` WHERE `mask_id`=%d", maskID );#ifdef DEBUG_EXTRA
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); //Delete Mask Itself!
if ( deleteMask ) { sprintf( tQBuf, "DELETE FROM `lrf_masks` WHERE `id`=%d", maskID );#ifdef DEBUG_EXTRA
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); }; return true; }; return false;};
bool mysqlDBC::updateCamRange( uint32_t camID, float range ){ if(m_bIsConnected) { char tQBuf[MAX_PATH_LEN]; sprintf(tQBuf,"UPDATE cameras SET `max_range`=%.3f WHERE `id`=%d", range, camID );#ifdef DEBUG_EXTRA
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); return true; }; return false;};
bool mysqlDBC::updateIPCam( CSTR uuid, CSTR Addr ){ if(m_bIsConnected) { char tQBuf[MAX_PATH_LEN]; char tIpBuf[CTEXT]; char *tPos; char *tPos2;
tPos = strstr(Addr,"//"); if( tPos != NULL ) { tPos2 = strstr( tPos + 2,"/"); if( tPos2 != NULL ) { int len; len = tPos2 - tPos - 2; strncpy(tIpBuf,tPos + 2,len); tIpBuf[len] = (char)0; } else { LOG_ERROR("Pos 2 - err"); tIpBuf[0] = (char)0; }; } else { LOG_ERROR("Pos 0 - err"); tIpBuf[0] = (char)0; }; sprintf(tQBuf,"UPDATE cameras SET `online`=1,`onvif_ctrl`='%s', `ip`='%s' WHERE `uuid`='%s'", Addr, tIpBuf, uuid );#ifdef DEBUG_EXTRA
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); return true; }; return false;};
bool mysqlDBC::updateIPCam( uint32_t CamID, CSTR Addr ){ if(m_bIsConnected) { char tQBuf[MAX_PATH_LEN]; char tIpBuf[CTEXT]; char *tPos; char *tPos2;
tPos = strstr(Addr,"//"); if( tPos != NULL ) { tPos2 = strstr( tPos + 2,"/"); if( tPos2 != NULL ) { int len; len = tPos2 - tPos - 2; strncpy(tIpBuf,tPos + 2,len); tIpBuf[len] = (char)0; } else { LOG_ERROR("Pos 2 - err"); tIpBuf[0] = (char)0; }; } else { LOG_ERROR("Pos 0 - err"); tIpBuf[0] = (char)0; }; sprintf(tQBuf,"UPDATE cameras SET `online`=1, `onvif_ctrl`='%s', `ip`='%s' WHERE `id`=%d", Addr, tIpBuf, CamID );#ifdef DEBUG_EXTRA
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); sprintf(tQBuf,"UPDATE media_streams SET `valid`=1 WHERE source_id=%d AND source_type='D'", CamID );#ifdef DEBUG_EXTRA
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); return true; }; return false;};/*
bool mysqlDBC::addIPCam( uint32_t SiteID, resultWoWo *tPtr ){ if(m_bIsConnected) { char tQBuf[1024]; char tIpBuf[32]; char tProto[32]; char tPath[CTEXT]; char *tPos; char *tPos2;
memcpy( tProto, tPtr->XAddrs, 5 ); tProto[5] = (char)0; if( tProto[4] == ':') tProto[4] = (char)0; memset( tPath, 0, CTEXT ); tPos = strstr(tPtr->XAddrs,"//"); if( tPos != NULL ) { tPos2 = strstr( tPos + 2,"/"); if( tPos2 != NULL ) { int len,len2,len3; len = tPos2 - tPos - 2; strncpy( tIpBuf, tPos + 2, len); tIpBuf[len] = (char)0; strncpy( tPath, tPos + 2 + len, CTEXT ); } else { LOG_ERROR("Pos 2 - err"); tIpBuf[0] = (char)0; }; } else { LOG_ERROR("Pos 0 - err"); tIpBuf[0] = (char)0; }; sprintf(tQBuf,"INSERT INTO cameras SET `online`=1, `uuid`='%s', `onvif_ctrl`='%s', `ip`='%s', `type`=2, `status`=0, `site_id`=%d, `mac`='%s', `hardware`='%s', `name`='%s', `onvif_access`='%s' ON DUPLICATE KEY UPDATE `online`=1, `ip`='%s'", tPtr->RefID, //tPtr->XAddrs,
tPath, tIpBuf, SiteID, tPtr->MAC, tPtr->Hardware, tPtr->Name, tProto, //tPtr->XAddrs,
tIpBuf );#ifdef DEBUG_EXTRA
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); return true; }; return false;};*/bool mysqlDBC::addIPCam( OBSERVER_RESULT *tPtr ){ if(m_bIsConnected) { char tQBuf[1024]; char tIpBuf[32]; char tProto[32]; char tPath[CTEXT]; char *tPos; char *tPos2; memcpy( tProto, tPtr->XAddrs, 5 ); tProto[5] = (char)0; if( tProto[4] == ':') tProto[4] = (char)0; memset( tPath, 0, CTEXT ); tPos = strstr(tPtr->XAddrs,"//"); if( tPos != NULL ) { tPos2 = strstr( tPos + 2,"/"); if( tPos2 != NULL ) { int len,len2,len3; len = tPos2 - tPos - 2; strncpy( tIpBuf, tPos + 2, len); tIpBuf[len] = (char)0; strncpy( tPath, tPos + 2 + len, CTEXT ); } else { LOG_ERROR("Pos 2 - err"); tIpBuf[0] = (char)0; }; } else { LOG_ERROR("Pos 0 - err"); tIpBuf[0] = (char)0; }; sprintf(tQBuf,"INSERT INTO cameras SET `online`=1, `uuid`='%s', `onvif_ctrl`='%s', `ip`='%s', `type`=2, `status`=0, `site_id`=%d, `mac`='%s', `hardware`='%s', `name`='%s', `onvif_access`='%s' ON DUPLICATE KEY UPDATE `online`=1, `ip`='%s'", tPtr->RefID, //tPtr->XAddrs,
tPath, tIpBuf, m_nSiteID, tPtr->MAC, tPtr->Hardware, tPtr->Name, tProto, //tPtr->XAddrs,
tIpBuf );#ifdef DEBUG_EXTRA
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); return true; }; return false;};
bool mysqlDBC::transferEvtToArchive( uint32_t SECONDS ){ if(m_bIsConnected) { if( SECONDS > 0 ) { char tQBuf[CTEXT]; sprintf(tQBuf,"INSERT INTO events_archive ( SELECT * FROM events_cloud ec WHERE ec.ts < ( UNIX_TIMESTAMP(NOW()) - %d ) ); DELETE FROM events_cloud WHERE ts < ( UNIX_TIMESTAMP(NOW()) - %d );", SECONDS, SECONDS ); m_pDatabase->SilentQuery( tQBuf ); return true; }; }; return false;}/*
bool mysqlDBC::getLastEvents( vectorEventRecords &VR, uint32_t tss, uint32_t tsms ){ if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT * FROM events_cloud WHERE `ts`>%d AND `ts_ms`>%d", tss, tsms ); result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { DBC_EVT_DATA *tPtr; Assoc *cArr; for(int i=0;i<result->size();i++) { cArr = result->at(i); tPtr = (DBC_EVT_DATA*)malloc(sizeof(DBC_EVT_DATA)); if( tPtr!= NULL ) { Assoc::iterator it; memset(tPtr,0,sizeof(DBC_EVT_DATA)); it = cArr->find("id"); if( it != cArr->end() ){ tPtr->id = atoi( it->second.c_str() ); }; it = cArr->find("node_id"); if( it != cArr->end() ){ tPtr->node_id = atoi( it->second.c_str() ); }; it = cArr->find("uuid"); if( it != cArr->end() ){ strncpy( tPtr->uuid, it->second.c_str(),64 ); }; it = cArr->find("ts"); if( it != cArr->end() ){ tPtr->ts_s = atoi( it->second.c_str() ); }; it = cArr->find("ts_ms"); if( it != cArr->end() ){ tPtr->ts_ms = atoi( it->second.c_str() ); }; it = cArr->find("evt_type"); if( it != cArr->end() ){ tPtr->type = atoi( it->second.c_str() ); }; it = cArr->find("range_digital"); if( it != cArr->end() ){ tPtr->range_digital = atoi( it->second.c_str() ); }; it = cArr->find("azimuth"); if( it != cArr->end() ){ tPtr->az = atof( it->second.c_str() ); }; it = cArr->find("elevation"); if( it != cArr->end() ){ tPtr->el = atof( it->second.c_str() ); }; it = cArr->find("range"); if( it != cArr->end() ){ tPtr->ra = atof( it->second.c_str() ); }; it = cArr->find("area"); if( it != cArr->end() ){ tPtr->area = atof( it->second.c_str() ); }; it = cArr->find("lat"); if( it != cArr->end() ){ tPtr->lat = atof( it->second.c_str() ); }; it = cArr->find("lon"); if( it != cArr->end() ){ tPtr->lon = atof( it->second.c_str() ); }; it = cArr->find("alt"); if( it != cArr->end() ){ tPtr->alt = atof( it->second.c_str() ); }; it = cArr->find("ref_uuid"); if( it != cArr->end() ){ strncpy( tPtr->uuid, it->second.c_str(),64 ); }; char tBuf[CLOG]; sprintf(tBuf,"Evt: %d %d %d", tPtr->type, tPtr->ts_s, tPtr->ts_ms ); LOG(tBuf); VR.push_back(tPtr); }; }; }; deleteResult( result ); if( m_pDatabase->isConnected()) return true; }; return false;};*/
//Is safe to remove???
bool mysqlDBC::getAllCamRecords( uint32_t SiteID, vectorCamRecords &VR ){ if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT * FROM cameras WHERE `site_id`=%d AND `type`=2 AND `status`=2", SiteID );#ifdef DEBUG_EXTRA
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { DBC_CAM_DATA *tVal; Assoc *cArr; for(int i=0;i<result->size();i++) { LOG("Cam_Record!"); cArr = result->at(i); tVal = (DBC_CAM_DATA*)malloc(sizeof(DBC_CAM_DATA)); if( tVal!= NULL ) { Assoc::iterator it; memset(tVal,0,sizeof(DBC_CAM_DATA));
it = cArr->find("id"); if( it != cArr->end() ){ tVal->id = atoi( it->second.c_str() ); }; it = cArr->find("type"); if( it != cArr->end() ){ tVal->type = atoi( it->second.c_str() ); }; it = cArr->find("online"); if( it != cArr->end() ){ tVal->online = (bool) atoi( it->second.c_str() ); }; it = cArr->find("stream_id"); if( it != cArr->end() ){ tVal->stream_id = atoi( it->second.c_str() ); }; it = cArr->find("hardware"); if( it != cArr->end() ){ strncpy( tVal->hardware, it->second.c_str(), 32 ); }; it = cArr->find("name"); if( it != cArr->end() ){ strncpy( tVal->name, it->second.c_str(), 64 ); }; it = cArr->find("status"); if( it != cArr->end() ){ tVal->status = atoi( it->second.c_str() ); }; it = cArr->find("session"); if( it != cArr->end() ){ strncpy( tVal->session, it->second.c_str(), 32 ); }; it = cArr->find("protocol"); if( it != cArr->end() ){ tVal->protocol = atoi( it->second.c_str() ); }; it = cArr->find("protocol_aux"); if( it != cArr->end() ){ tVal->protocol_aux = atoi( it->second.c_str() ); }; it = cArr->find("x"); if( it != cArr->end() ){ tVal->x = atof( it->second.c_str() ); }; it = cArr->find("y"); if( it != cArr->end() ){ tVal->y = atof( it->second.c_str() ); }; it = cArr->find("z"); if( it != cArr->end() ){ tVal->z = atof( it->second.c_str() ); }; it = cArr->find("x_rot"); if( it != cArr->end() ){ tVal->x_rot = atof( it->second.c_str() ); }; it = cArr->find("y_rot"); if( it != cArr->end() ){ tVal->y_rot = atof( it->second.c_str() ); }; it = cArr->find("z_rot"); if( it != cArr->end() ){ tVal->z_rot = atof( it->second.c_str() ); }; it = cArr->find("imager_type"); if( it != cArr->end() ){ tVal->imager_type = atoi( it->second.c_str() ); }; it = cArr->find("lense_f"); if( it != cArr->end() ){ tVal->lens_f = atoi( it->second.c_str() ); }; it = cArr->find("zoom"); if( it != cArr->end() ){ tVal->zoom = atof( it->second.c_str() ); }; it = cArr->find("access_login"); if( it != cArr->end() ){ strncpy( tVal->username, it->second.c_str(), 32 ); }; it = cArr->find("access_pass"); if( it != cArr->end() ){ strncpy( tVal->password, it->second.c_str(), 32 ); }; it = cArr->find("uuid"); if( it != cArr->end() ){ strncpy( tVal->uuid, it->second.c_str(), 64 ); }; it = cArr->find("mac"); if( it != cArr->end() ){ strncpy( tVal->mac, it->second.c_str(), 17 ); }; it = cArr->find("ip"); if( it != cArr->end() ){ strncpy( tVal->ip, it->second.c_str(), 17 ); }; it = cArr->find("port"); if( it != cArr->end() ){ tVal->port = atoi( it->second.c_str() ); }; it = cArr->find("onvif_access"); if( it != cArr->end() ){ strncpy( tVal->onvif_access, it->second.c_str(), 5); }; it = cArr->find("onvif_ctrl"); if( it != cArr->end() ){ strncpy( tVal->onvif_ctrl, it->second.c_str(), 250); }; it = cArr->find("ptz_token"); if( it != cArr->end() ){ strncpy( tVal->ptz_token, it->second.c_str(), 64); }; VR.push_back(tVal); }; //??
//delete(cArr);
}; }; deleteResult( result );#ifdef DEBUG
sprintf( tQBuf,"Now %d Camera Records in System", VR.size()); LOG(tQBuf);#endif
if( m_pDatabase->isConnected()) return true; }; return false;};
DBC_INT_LIST *mysqlDBC::listNodes( uint32_t SiteID, uint32_t ServerID, bool all ){ DBC_INT_LIST * tVal = NULL; if( m_bIsConnected ){ char tQBuf[1024]; AAssoc *result; if( all ) { if ( ServerID == 0 ) { sprintf(tQBuf, "SELECT `id` FROM `nodes` WHERE `site_id`=%d", SiteID); } else { sprintf(tQBuf, "SELECT `id` FROM `nodes` WHERE `site_id`=%d AND `server_id`=%d", SiteID, ServerID ); }; } else { if ( ServerID == 0 ){ sprintf(tQBuf, "SELECT `id` FROM `nodes` WHERE `site_id`=%d AND `type` > 0", SiteID ); } else { sprintf(tQBuf, "SELECT `id` FROM `nodes` WHERE `site_id`=%d AND `server_id`=%d AND `type` > 0", SiteID, ServerID ); }; };#ifdef DEBUG_EXTRA
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; tVal = new DBC_INT_LIST(); if( tVal != NULL ) { Assoc::iterator it; for(int i=0; i <result->size();i++) { cArr = result->at(i); it = cArr->find("id"); if( it != cArr->end() ){ tVal->push_back( atoi( it->second.c_str() )); }; }; }; }; }; deleteResult( result ); }; return tVal;};
DBC_INT_LIST *mysqlDBC::listNewNodes( uint32_t SiteID, uint32_t ServerID, DBC_INT_LIST *old_ids ){ DBC_INT_LIST * tVal = NULL; char tParam[CTEXT]; //memset( tParam, 0, CTEXT );
sprintf(tParam,"0"); if( old_ids != NULL ) { char tBuffer[CTEXT]; for(int i = 0; i< old_ids->size(); i++ ) { sprintf( tBuffer, "%s,%d", tParam, old_ids->at(i) ); strncpy( tParam, tBuffer, CTEXT ); }; }; if( m_bIsConnected ){ char tQBuf[CTEXT]; AAssoc *result; if ( ServerID == 0 ) { sprintf(tQBuf, "SELECT id FROM nodes WHERE `site_id`=%d AND `type` > 0 AND `id` NOT IN(%s)", SiteID, tParam); } else { sprintf(tQBuf, "SELECT id FROM nodes WHERE `site_id`=%d AND `server_id`=%d AND `type` > 0 AND `id` NOT IN(%s)", SiteID, ServerID, tParam ); };#ifdef DEBUG_EXTRA
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; tVal = new DBC_INT_LIST(); if( tVal != NULL ) { Assoc::iterator it; for(int i=0;i<result->size();i++) { cArr = result->at(i); it = cArr->find("id"); if( it != cArr->end() ){ tVal->push_back( atoi( it->second.c_str() )); }; }; }; }; }; deleteResult( result ); }; return tVal;};
void mysqlDBC::lazyEventArchiver( uint32_t DalayTime ){ if( m_bIsConnected ){ char tQBuf[CTEXT]; AAssoc *result; uint32_t LastID = 0; sprintf( tQBuf, "SELECT * FROM `events_cloud` WHERE ( UNIX_TIMESTAMP(NOW()) - `ts` ) > %d ORDER BY `id` ASC LIMIT 10", DalayTime );#ifdef DEBUG_EXTRA
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; for(int i=0;i<result->size();i++){ uint32_t nodeid=0; char uuid[64]={0}; uint32_t ts=0; uint32_t ts_ms=0; uint32_t evt_t=0; uint32_t range_d=0; float az=.0f, el=.0f, ra=.0f, ar=.0f, lat=.0f, lon=.0f, alt=.0f; uint32_t ref_id=0; char ref_uuid[64]={0}; Assoc::iterator it;
cArr = result->at(i);
it = cArr->find("id"); if( it != cArr->end() ){ LastID = atoi( it->second.c_str()); }; it = cArr->find("node_id"); if( it != cArr->end() ){ nodeid = atoi( it->second.c_str()); }; it = cArr->find("uuid"); if( it != cArr->end() ){ strncpy( uuid, it->second.c_str(), 64 ); }; it = cArr->find("ts"); if( it != cArr->end() ){ ts = atoi( it->second.c_str()); }; it = cArr->find("ts_ms"); if( it != cArr->end() ){ ts_ms = atoi( it->second.c_str()); }; it = cArr->find("evt_type"); if( it != cArr->end() ){ evt_t = atoi( it->second.c_str()); }; it = cArr->find("range_digital"); if( it != cArr->end() ){ range_d = atoi( it->second.c_str()); }; it = cArr->find("azimuth"); if( it != cArr->end() ){ az = (float)atof( it->second.c_str()); }; it = cArr->find("elevation"); if( it != cArr->end() ){ el = (float)atof( it->second.c_str()); }; it = cArr->find("range"); if( it != cArr->end() ){ ra = (float)atof( it->second.c_str()); }; it = cArr->find("area"); if( it != cArr->end() ){ ar = (float)atof( it->second.c_str()); }; it = cArr->find("lat"); if( it != cArr->end() ){ lat = (float)atof( it->second.c_str()); }; it = cArr->find("lon"); if( it != cArr->end() ){ lon = (float)atof( it->second.c_str()); }; it = cArr->find("alt"); if( it != cArr->end() ){ alt = (float)atof( it->second.c_str()); }; it = cArr->find("ref_id"); if( it != cArr->end() ){ ref_id = atoi( it->second.c_str()); }; it = cArr->find("ref_uuid"); if( it != cArr->end() ){ strncpy( ref_uuid, it->second.c_str(), 64 ); }; sprintf(tQBuf, "INSERT INTO `events_archive` SET `node_id`=%d, `uuid`='%s', `ts`=%d, `ts_ms`=%d, `evt_type`=%d, `range_digital`=%d, `azimuth`=%0.8f, `elevation`=%0.8f, `range`=%0.2f, `area`=%0.5f, `lat`=%0.8f, `lon`=%0.8f, `alt`=%0.3f, `ref_id`=%d, `ref_uuid`='%s'", nodeid, uuid, ts, ts_ms, evt_t, range_d, az, el, ra, ar, lat, lon, alt, ref_id, ref_uuid ); uint32_t IID = (uint32_t) m_pDatabase->QueryID(tQBuf); sprintf(tQBuf,"UPDATE `events_2_pictures` SET `event_id`=%d WHERE `event_id`=%d", IID, LastID ); //m_pDatabase->SilentQuery(tQBuf);
sprintf(tQBuf,"UPDATE `events_2_videos` SET `event_id`=%d WHERE `event_id`=%d", IID, LastID ); //m_pDatabase->SilentQuery(tQBuf);
}; }; }; deleteResult( result ); };};
DBC_INT_LIST *mysqlDBC::listCamMediaStreams( uint32_t CAMID ){ DBC_INT_LIST * tVal = NULL; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT id FROM media_streams WHERE `source_id`=%d AND `valid`=1", CAMID );#ifdef DEBUG_EXTRA
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; tVal = new DBC_INT_LIST(); if( tVal != NULL ) { Assoc::iterator it; for(int i=0;i<result->size();i++) { cArr = result->at(i); it = cArr->find("id"); if( it != cArr->end() ){ tVal->push_back( atoi( it->second.c_str() )); }; }; }; }; }; deleteResult( result ); }; return tVal;};
DBC_INT_LIST *mysqlDBC::listStreamCapPictures( uint32_t StreamID, uint32_t cnt ){ DBC_INT_LIST * tVal = NULL; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT `id` FROM `pictures` WHERE `media_stream_id`=%d LIMIT %d", StreamID, cnt );#ifdef DEBUG_EXTRA
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; tVal = new DBC_INT_LIST(); if( tVal != NULL ) { Assoc::iterator it; for(int i=0;i<result->size();i++) { cArr = result->at(i); it = cArr->find("id"); if( it != cArr->end() ){ tVal->push_back( atoi( it->second.c_str() )); }; }; }; }; }; deleteResult( result ); }; return tVal;};
DBC_NETWORK_DATA *mysqlDBC::getNetworkData( uint32_t net_id ){ DBC_NETWORK_DATA * tVal = NULL; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT * FROM `networks` WHERE `id`=%d", net_id );#ifdef DEBUG_EXTRA
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; tVal = (DBC_NETWORK_DATA*) malloc(sizeof(DBC_NETWORK_DATA)); if( tVal != NULL ) { memset(tVal, 0, sizeof(DBC_NETWORK_DATA)); Assoc::iterator it; tVal->id = net_id; cArr = result->at(0); it = cArr->find("nif_id"); if( it != cArr->end() ){ tVal->nif_id = atoi(it->second.c_str()); }; it = cArr->find("type"); if( it != cArr->end() ){ tVal->type = (NETWORK_TYPE) atoi(it->second.c_str()); }; it = cArr->find("address"); if( it != cArr->end() ){ strncpy( tVal->address, it->second.c_str(), 65 ); tVal->address[64]=(char)0; }; it = cArr->find("gateway"); if( it != cArr->end() ){ strncpy(tVal->gateway, it->second.c_str(), 65); tVal->gateway[64]=(char)0; }; it = cArr->find("mask"); if( it != cArr->end() ){ strncpy( tVal->netmask, it->second.c_str(), 65 ); tVal->netmask[64]=(char)0; }; it = cArr->find("broadcast"); if( it != cArr->end() ){ strncpy( tVal->broadcast, it->second.c_str(), 65 ); tVal->broadcast[64]=(char)0; }; }; }; }; deleteResult( result ); }; return tVal;};
DBC_NET_IF_DATA *mysqlDBC::getNIF_Data( uint32_t nif_id ){ DBC_NET_IF_DATA * tVal = NULL; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT `type`, `mode`, `device_name`, `mac`, `aux_id` FROM `network_interfaces` WHERE `id`=%d", nif_id );#ifdef DEBUG_EXTRA
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; tVal = (DBC_NET_IF_DATA*) malloc(sizeof(DBC_NET_IF_DATA)); if( tVal != NULL ) { Assoc::iterator it; tVal->id = nif_id; cArr = result->at(0); it = cArr->find("type"); if( it != cArr->end() ){ tVal->type = atoi(it->second.c_str()); }; it = cArr->find("mode"); if( it != cArr->end() ){ tVal->mode = atoi(it->second.c_str()); }; it = cArr->find("device_name"); if( it != cArr->end() ){ strncpy( tVal->device_name, it->second.c_str(),11); tVal->device_name[10]=(char)0; }; it = cArr->find("mac"); if( it != cArr->end() ){ strncpy( tVal->mac, it->second.c_str(), 33 ); tVal->mac[32]=(char)0; }; it = cArr->find("aux_id"); if( it != cArr->end() ){ tVal->aux_id = atoi(it->second.c_str()); }; }; }; }; deleteResult( result ); }; return tVal;};
uint32_t mysqlDBC::getNetworkInfrastructureID( uint32_t nif_id ){ uint32_t tVal = 0; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT id FROM `network_infrastructure` WHERE `nif_id`=%d", nif_id );#ifdef DEBUG
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; Assoc::iterator it; cArr = result->at(0); it = cArr->find("id"); if( it != cArr->end() ){ tVal = atoi( it->second.c_str() ); }; }; }; deleteResult( result ); }; return tVal;};
CSTR mysqlDBC::getNodeName( uint32_t NodeID ){ CSTR tVal = NULL; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT `name` FROM `nodes` WHERE `id`=%d", NodeID );#ifdef DEBUG
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; Assoc::iterator it; cArr = result->at(0); it = cArr->find("name"); if( it != cArr->end() ){ tVal = strdup( it->second.c_str() ); }; }; }; deleteResult( result ); }; return tVal;};
uint32_t mysqlDBC::getNodeAuxID( uint32_t NodeID ){ uint32_t tVal; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT `aux_id` FROM `nodes` WHERE `id`=%d", NodeID );#ifdef DEBUG
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; Assoc::iterator it; cArr = result->at(0); it = cArr->find("aux_id"); if( it != cArr->end() ){ tVal = atoi( it->second.c_str() ); }; }; }; deleteResult( result ); }; return tVal;};
uint32_t mysqlDBC::getNodeAuxParam( uint32_t NodeID ){ uint32_t tVal; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT `aux_parameter` FROM `nodes` WHERE `id`=%d", NodeID );#ifdef DEBUG
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; Assoc::iterator it; cArr = result->at(0); it = cArr->find("aux_parameter"); if( it != cArr->end() ){ tVal = atoi( it->second.c_str() ); }; }; }; deleteResult( result ); }; return tVal;};
uint32_t mysqlDBC::getWiFi_ID( uint32_t nif_id ){ uint32_t tVal = 0; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT `id` FROM `wifis` WHERE `nif_id`=%d", nif_id );#ifdef DEBUG
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; Assoc::iterator it; cArr = result->at(0); it = cArr->find("id"); if( it != cArr->end() ){ tVal = atoi( it->second.c_str() ); }; }; }; deleteResult( result ); }; return tVal;};
uint32_t mysqlDBC::getNIF_ID( CSTR key ){ uint32_t tVal = 0; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT id FROM `network_interfaces` WHERE `key`='%s'", key );#ifdef DEBUG_EXTRA
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; Assoc::iterator it; cArr = result->at(0); it = cArr->find("id"); if( it != cArr->end() ){ tVal = atoi( it->second.c_str() ); }; }; }; deleteResult( result ); }; return tVal;};
uint32_t mysqlDBC::getNIF_IDbyDevice( CSTR device ){ uint32_t tVal = 0; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT id FROM `network_interfaces` WHERE `device_name`='%s'", device );#ifdef DEBUG
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; Assoc::iterator it; cArr = result->at(0); it = cArr->find("id"); if( it != cArr->end() ){ tVal = atoi( it->second.c_str() ); }; }; }; deleteResult( result ); }; return tVal;};
DBC_NODE_DATA *mysqlDBC::getNodeData( uint32_t ID ){ DBC_NODE_DATA * tVal = NULL; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT * FROM nodes WHERE `id`=%d", ID );#ifdef DEBUG_EXTRA
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; tVal = (DBC_NODE_DATA*) malloc(sizeof(DBC_NODE_DATA)); if( tVal != NULL ) { memset( tVal, 0, sizeof(DBC_NODE_DATA)); Assoc::iterator it; cArr = result->at(0); it = cArr->find("id"); if( it != cArr->end() ){ tVal->node_id = atoi( it->second.c_str() ); }; it = cArr->find("type"); if( it != cArr->end() ){ tVal->type = /*(NODE_TYPE)*/ atoi( it->second.c_str() ); }; it = cArr->find("aux_id"); if( it != cArr->end() ){ tVal->aux_id = atoi( it->second.c_str() ); }; it = cArr->find("aux_parameter"); if( it != cArr->end() ){ tVal->aux_parameter = atoi( it->second.c_str() ); }; it = cArr->find("name"); if( it != cArr->end() ){ sprintf( tVal->name, it->second.c_str() ); }; it = cArr->find("ts_s"); if( it != cArr->end() ){ tVal->tss = atoi( it->second.c_str() ); }; it = cArr->find("ts_ms"); if( it != cArr->end() ){ tVal->tsm = atoi( it->second.c_str() ); }; it = cArr->find("online"); if( it != cArr->end() ){ tVal->online = (bool)atoi( it->second.c_str() ); }; }; }; }; deleteResult( result ); }; return tVal;};
DBC_APF_DATA *mysqlDBC::getAPFData( uint32_t APFID ){ DBC_APF_DATA * tVal = NULL; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT * FROM `target_filter_apf` WHERE `id`=%d", APFID );#ifdef DEBUG
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; tVal = (DBC_APF_DATA*) malloc(sizeof(DBC_APF_DATA)); if( tVal != NULL ) { memset( tVal, 0 , sizeof(DBC_APF_DATA)); Assoc::iterator it; cArr = result->at(0); it = cArr->find("mode"); if( it != cArr->end() ){ sprintf( tVal->mode, it->second.c_str() ); }; it = cArr->find("port"); if( it != cArr->end() ){ tVal->port = atoi( it->second.c_str() ); }; it = cArr->find("lat"); if( it != cArr->end() ){ tVal->lat = atof( it->second.c_str() ); }; it = cArr->find("lon"); if( it != cArr->end() ){ tVal->lon = atof( it->second.c_str() ); }; it = cArr->find("alt"); if( it != cArr->end() ){ tVal->alt = atof( it->second.c_str() ); }; it = cArr->find("roll"); if( it != cArr->end() ){ tVal->roll = atof( it->second.c_str() ); }; it = cArr->find("pitch"); if( it != cArr->end() ){ tVal->pitch = atof( it->second.c_str() ); }; it = cArr->find("yaw"); if( it != cArr->end() ){ tVal->yaw = atof( it->second.c_str() ); }; it = cArr->find("dx"); if( it != cArr->end() ){ tVal->dx = atof( it->second.c_str() ); }; it = cArr->find("dy"); if( it != cArr->end() ){ tVal->dy = atof( it->second.c_str() ); }; it = cArr->find("dz"); if( it != cArr->end() ){ tVal->dz = atof( it->second.c_str() ); }; }; }; }; deleteResult( result ); }; return tVal;};
DBC_FH_DATA *mysqlDBC::getFlyHunterData( uint32_t ID ){ DBC_FH_DATA * tVal = NULL; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT * FROM `modules_fly_hunter` WHERE `id`=%d", ID );#ifdef DEBUG
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; tVal = (DBC_FH_DATA*) malloc(sizeof(DBC_FH_DATA)); if( tVal != NULL ) { memset( tVal, 0 , sizeof(DBC_FH_DATA)); Assoc::iterator it; cArr = result->at(0); it = cArr->find("name"); if( it != cArr->end() ){ sprintf( tVal->name, it->second.c_str() ); }; it = cArr->find("lat"); if( it != cArr->end() ){ tVal->lat = atof( it->second.c_str() ); }; it = cArr->find("lon"); if( it != cArr->end() ){ tVal->lon = atof( it->second.c_str() ); }; it = cArr->find("alt"); if( it != cArr->end() ){ tVal->alt = atof( it->second.c_str() ); }; it = cArr->find("dc_module_id"); if( it != cArr->end() ){ tVal->dc_id = atoi( it->second.c_str() ); }; it = cArr->find("uart_id"); if( it != cArr->end() ){ tVal->uart_id = atoi( it->second.c_str() ); }; }; }; }; deleteResult( result ); }; return tVal;};bool mysqlDBC::fillShadow2D( uint32_t ID, SHADOW & SH ){ if( m_bIsConnected ){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT `lv`.`id`, `lm`.`layer`, `lm`.`status` FROM `lrf_mask_vertexes` `lv` LEFT JOIN `lrf_masks` `lm` ON (`lm`.`id` = `lv`.`mask_id`) WHERE `lm`.`sensor_id`=%d ORDER BY `lv`.`id`", ID ); LOG(tQBuf); result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { SH.m_nEnabled = 0xFFFFFFFF; SH.m_nPolygonCount = result->size(); SH.pPolygones = (SHADOW_POLY *) calloc( SH.m_nPolygonCount, sizeof( SHADOW_POLY ) ); if ( SH.pPolygones ) { Assoc * cArr; for ( uint8_t idx = 0; idx < result->size(); idx++ ) { Assoc::iterator it; cArr = result->at(idx); it = cArr->find("id"); if( it != cArr->end() ){ SH.pPolygones[idx].m_nDBID = atoi(it->second.c_str()); }; it = cArr->find("layer"); if( it != cArr->end() ){ SH.pPolygones[idx].bType = atoi(it->second.c_str()); }; it = cArr->find("status"); if( it != cArr->end() ){ SH.m_nEnabled &= ( it->second.c_str()[0] == 'E' )?0xFFFFFFFF:~(1<<SH.pPolygones[idx].bType); }; sprintf(tQBuf, "SELECT * FROM `lrf_mask_vertex_points` WHERE `vertex_id`=%d ORDER BY `id`", SH.pPolygones[idx].m_nDBID ); LOG(tQBuf); AAssoc *v_result = m_pDatabase->Query( tQBuf ); if( v_result!= NULL ) { if( v_result->size() > 0 ) { SH.pPolygones[idx].wCount = v_result->size(); SH.pPolygones[idx].pPoint = (HZ_POINT *) calloc( SH.pPolygones[idx].wCount, sizeof( HZ_POINT ) ); if(SH.pPolygones[idx].pPoint ) { for ( uint32_t zdx =0; zdx < SH.pPolygones[idx].wCount; zdx++ ) { cArr = v_result->at(zdx); it = cArr->find("x"); if( it != cArr->end() ){ SH.pPolygones[idx].pPoint[zdx].wX = atoi(it->second.c_str()); }; it = cArr->find("y"); if( it != cArr->end() ){ SH.pPolygones[idx].pPoint[zdx].wY = atoi(it->second.c_str()); }; LOG("Point Added!"); }; } else { LOG("No mem for Points!"); }; } else { LOG("No Points!"); SH.pPolygones[idx].wCount = 0; SH.pPolygones[idx].pPoint = NULL; }; deleteResult( v_result ); }; }; }; }; deleteResult( result ); }; return true; }; return false;};
DBC_SITE_DATA *mysqlDBC::getSiteData( uint32_t ID ){ DBC_SITE_DATA * tVal = NULL; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT * FROM sites WHERE `id`=%d", ID );#ifdef DEBUG
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; tVal = (DBC_SITE_DATA*) malloc(sizeof(DBC_SITE_DATA)); if( tVal != NULL ) { memset( tVal, 0 , sizeof(DBC_SITE_DATA)); Assoc::iterator it; cArr = result->at(0); it = cArr->find("account_id"); if( it != cArr->end() ){ tVal->account_id = atoi( it->second.c_str() ); }; it = cArr->find("name"); if( it != cArr->end() ){ sprintf( tVal->name, it->second.c_str() ); }; it = cArr->find("server_ident"); if( it != cArr->end() ){ sprintf( tVal->ident, it->second.c_str() ); }; it = cArr->find("anchor_lat"); if( it != cArr->end() ){ tVal->lat = atof( it->second.c_str() ); }; it = cArr->find("anchor_lon"); if( it != cArr->end() ){ tVal->lon = atof( it->second.c_str() ); }; it = cArr->find("anchor_alt"); if( it != cArr->end() ){ tVal->alt = atof( it->second.c_str() ); }; it = cArr->find("hemisphere"); if( it != cArr->end() ){ tVal->SH = ( it->second.c_str()[0] == 'S' ); }; it = cArr->find("map_id"); if( it != cArr->end() ){ tVal->map_id = atoi( it->second.c_str() ); }; it = cArr->find("local_binding"); if( it != cArr->end() ){ tVal->local_binding = (bool) atoi(it->second.c_str()); }; }; }; }; deleteResult( result ); }; return tVal;};
DBC_TARGET_FLITER_DATA *mysqlDBC::getTargetFilterData( uint32_t ID ){ DBC_TARGET_FLITER_DATA * tVal = NULL; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT * FROM target_filters WHERE `id`=%d", ID );#ifdef DEBUG
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; tVal = (DBC_TARGET_FLITER_DATA*) malloc(sizeof(DBC_TARGET_FLITER_DATA)); if( tVal != NULL ) { memset( tVal, 0 , sizeof(DBC_TARGET_FLITER_DATA)); Assoc::iterator it; tVal->id = ID; cArr = result->at(0); it = cArr->find("type"); if( it != cArr->end() ){ tVal->type = (TARGET_FILTER_TYPE) atoi( it->second.c_str() ); }; it = cArr->find("aux_id"); if( it != cArr->end() ){ tVal->aux_id = atoi( it->second.c_str() ); }; }; }; }; deleteResult( result ); }; return tVal;};
DBC_LRF_INI *mysqlDBC::getINIData( uint32_t lrfID ){ DBC_LRF_INI * tVal = NULL; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT * FROM lrf_ini_settings WHERE `sensor_id`=%d", lrfID );#ifdef DEBUG
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; tVal = (DBC_LRF_INI*) malloc(sizeof(DBC_LRF_INI)); if( tVal != NULL ) { memset( tVal, 0 , sizeof(DBC_LRF_INI)); Assoc::iterator it; cArr = result->at(0); it = cArr->find("AUTORESET_ENABLE"); if( it != cArr->end() ){ tVal->_AUTO_RESET_ENABLE = (bool) atoi( it->second.c_str() ); }; it = cArr->find("AUTORESET_INTERLEAVE"); if( it != cArr->end() ){ tVal->_AUTO_RESET_INTERLEAVE = atoi( it->second.c_str() ); }; it = cArr->find("AUTORESET_TIMEOUT"); if( it != cArr->end() ){ tVal->_AUTO_RESET_TIMEOUT = atoi( it->second.c_str() ); }; it = cArr->find("BOARD_TEMPERATURE"); if( it != cArr->end() ){ tVal->_BOARD_TEMPERATURE = atoi( it->second.c_str() ); }; it = cArr->find("BOARD_ZEROSHIFT"); if( it != cArr->end() ){ tVal->_BOARD_ZEROSHIFT = atoi( it->second.c_str() ); }; it = cArr->find("BOARD_SPEED"); if( it != cArr->end() ){ tVal->_BOARD_SPEED = atoi( it->second.c_str() ); }; it = cArr->find("RUN_DIR"); if( it != cArr->end() ){ tVal->_RUN_DIR = atoi( it->second.c_str() ); }; it = cArr->find("JUST_MOVING_TARGETS"); if( it != cArr->end() ){ tVal->_JUST_MOVING_TARGETS = (bool) atoi( it->second.c_str() ); }; it = cArr->find("JUST_MOVING_RADIAL"); if( it != cArr->end() ){ tVal->_JUST_MOVING_RADIAL = (bool) atoi( it->second.c_str() ); }; it = cArr->find("JUST_MOVING_DISTANCE"); if( it != cArr->end() ){ tVal->_JUST_MOVING_DISTANCE = (bool) atoi( it->second.c_str() ); }; it = cArr->find("FREEZ_FIRST_TH"); if( it != cArr->end() ){ tVal->_FREEZ_FIRST_TH = (bool) atoi( it->second.c_str() ); }; it = cArr->find("SAVE_FIRST_TH"); if( it != cArr->end() ){ tVal->_SAVE_FIRST_TH = (bool) atoi( it->second.c_str() ); }; }; }; }; deleteResult( result ); }; return tVal;};
DBC_LRF_DATA *mysqlDBC::getLRFData( uint32_t ID ){ DBC_LRF_DATA * tVal = NULL; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT * FROM lrf_sensors WHERE `id`=%d", ID );#ifdef DEBUG
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; tVal = (DBC_LRF_DATA*) malloc(sizeof(DBC_LRF_DATA)); if( tVal != NULL ) { memset( tVal, 0 , sizeof(DBC_LRF_DATA)); Assoc::iterator it; tVal->id = ID; cArr = result->at(0); it = cArr->find("data_status"); if( it != cArr->end() ){ tVal->data_status = atoi( it->second.c_str() ); }; it = cArr->find("serial"); if( it != cArr->end() ){ strncpy( tVal->serial, it->second.c_str(), sizeof(tVal->serial)-1 ); tVal->serial[sizeof(tVal->serial)-1]=(char)0; }; it = cArr->find("version"); if( it != cArr->end() ){ strncpy( tVal->version, it->second.c_str(), sizeof(tVal->version)-1 ); tVal->version[sizeof(tVal->version)-1]=(char)0; }; it = cArr->find("x"); if( it != cArr->end() ){ tVal->x = atof( it->second.c_str() ); }; it = cArr->find("y"); if( it != cArr->end() ){ tVal->y = atof( it->second.c_str() ); }; it = cArr->find("z"); if( it != cArr->end() ){ tVal->z = atof( it->second.c_str() ); }; it = cArr->find("x_rot"); if( it != cArr->end() ){ tVal->x_rot = atof( it->second.c_str() ); }; it = cArr->find("y_rot"); if( it != cArr->end() ){ tVal->y_rot = atof( it->second.c_str() ); }; it = cArr->find("z_rot"); if( it != cArr->end() ){ tVal->z_rot = atof( it->second.c_str() ); }; it = cArr->find("uart_id"); if( it != cArr->end() ){ tVal->uart_id = atoi( it->second.c_str() ); }; it = cArr->find("device_id"); if( it != cArr->end() ){ tVal->device_id = atoi( it->second.c_str() ); }; it = cArr->find("ip_address"); if( it != cArr->end() ){ sprintf( tVal->master_host, it->second.c_str() ); }; it = cArr->find("aux_ip_address"); if( it != cArr->end() ){ sprintf( tVal->slave_host, it->second.c_str() ); }; it = cArr->find("port"); if( it != cArr->end() ){ tVal->master_port = atoi( it->second.c_str() ); }; it = cArr->find("aux_port"); if( it != cArr->end() ){ tVal->slave_port = atoi( it->second.c_str() ); }; it = cArr->find("auto_draw"); if( it != cArr->end() ){ tVal->auto_draw = atoi( it->second.c_str() ); }; it = cArr->find("filter_id"); if( it != cArr->end() ){ tVal->filter_id = atoi( it->second.c_str() ); }; //it = cArr->find("enabled_lrf");
//if( it != cArr->end() ){
// tVal->enabled_lrf = atoi( it->second.c_str() );
//};
it = cArr->find("max_range"); if( it != cArr->end() ){ tVal->max_range = atof( it->second.c_str() ); }; it = cArr->find("base_shift"); if( it != cArr->end() ){ tVal->base_shift = atoi( it->second.c_str() ); }; it = cArr->find("mirror_shift"); if( it != cArr->end() ){ tVal->mirror_shift = atoi( it->second.c_str() ); }; it = cArr->find("detection_profile_id"); if( it != cArr->end() ){ tVal->detection_profile_id = atoi( it->second.c_str() ); }; it = cArr->find("draw_lrf_id"); if( it != cArr->end() ){ tVal->draw_lrf_id = atoi( it->second.c_str() ); }; it = cArr->find("width_table_id"); if( it != cArr->end() ){ tVal->width_table_id = atoi( it->second.c_str() ); }; it = cArr->find("zoom_table_id"); if( it != cArr->end() ){ tVal->zoom_table_id = atoi( it->second.c_str() ); }; it = cArr->find("embd_cam"); if( it != cArr->end() ){ tVal->embd_cam = atoi( it->second.c_str() ); }; it = cArr->find("embd_cam_auto"); if( it != cArr->end() ){ tVal->embd_cam_auto = (bool)atoi( it->second.c_str() ); }; it = cArr->find("embd_dc"); if( it != cArr->end() ){ tVal->embd_dc = atoi( it->second.c_str() ); }; it = cArr->find("autoreset"); if( it != cArr->end() ){ tVal->autoreset = (bool)atoi( it->second.c_str() ); }; it = cArr->find("force_settings"); if( it != cArr->end() ){ tVal->force_settings = (bool)atoi( it->second.c_str() ); }; }; }; }; deleteResult( result ); }; return tVal;};
uint8_t mysqlDBC::getLRFDataStatus( uint32_t ID ){ uint8_t RetVal = 0; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT `data_status` FROM `lrf_sensors` WHERE `id`=%d", ID );#ifdef DEBUG
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; Assoc::iterator it; cArr = result->at(0); it = cArr->find("data_status"); if( it != cArr->end() ){ RetVal = atoi( it->second.c_str() ); }; }; }; deleteResult( result ); }; return RetVal;};
PLGS_2D_PARAMETERS mysqlDBC::getLRFDetectionProfile( uint32_t lrfID, uint8_t profileID, bool master ){ PLGS_2D_PARAMETERS retVal = NULL; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT * FROM `lrf_detection_profiles` WHERE `aux_id`=%d AND `profile_id`=%d AND `master`=b'%c'", lrfID, profileID,((master)?'1':'0') ); #ifdef DEBUG
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { retVal = (PLGS_2D_PARAMETERS) malloc(sizeof(LGS_2D_PARAMETERS)); memset( retVal, 0, sizeof(LGS_2D_PARAMETERS)); Assoc *cArr; Assoc::iterator it; cArr = result->at(0); it = cArr->find("order"); if( it != cArr->end() ){ retVal->nOrder = atoi(it->second.c_str()); }; it = cArr->find("offset"); if( it != cArr->end() ){ retVal->nOffset = atoi(it->second.c_str()); }; it = cArr->find("delta"); if( it != cArr->end() ){ retVal->nDelta = atoi(it->second.c_str()); }; it = cArr->find("flip"); if( it != cArr->end() ){ retVal->nFlip = atoi(it->second.c_str()); }; it = cArr->find("width"); if( it != cArr->end() ){ retVal->nWidth = atoi(it->second.c_str()); }; it = cArr->find("sst"); if( it != cArr->end() ){ retVal->bSST = atoi(it->second.c_str()); }; it = cArr->find("sun"); if( it != cArr->end() ){ retVal->nSun = atoi(it->second.c_str()); }; }; }; deleteResult( result ); }; return retVal;};CSTR mysqlDBC::getLRFDraw( uint32_t DBID ){ CSTR RetVal = NULL; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT `md5` FROM `lrf_draw` WHERE `node_id`=%d", DBID );#ifdef DEBUG
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; Assoc::iterator it; cArr = result->at(0); it = cArr->find("md5"); if( it != cArr->end() ){ RetVal = strdup( it->second.c_str() ); }; }; }; deleteResult( result ); }; return RetVal;};
uint32_t mysqlDBC::getLRFMaskID( uint32_t deviceID, uint8_t lrfID, uint8_t layer ){ uint32_t RetVal = 0; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT `id` FROM `lrf_masks` WHERE `sensor_id`=%d AND `lrf_id`=%d AND `layer`=%d ", deviceID, lrfID, layer );#ifdef DEBUG
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; Assoc::iterator it; cArr = result->at(0); it = cArr->find("id"); if( it != cArr->end() ){ RetVal = atoi( it->second.c_str() ); }; }; }; deleteResult( result ); }; return RetVal;};/*
DBC_PUSHED_CMD *mysqlDBC::getLRFPushedCMD( uint32_t ID ){ DBC_PUSHED_CMD *RetVal = NULL; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT `pushed_cmd`, `pushed_param` FROM `lrf_sensors` WHERE `id`=%d AND `pushed_cmd` > 0", ID );#ifdef DEBUG
//LOG(tQBuf);
#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { RetVal = (DBC_PUSHED_CMD*)malloc(sizeof(DBC_PUSHED_CMD)); if( RetVal ) { Assoc *cArr; Assoc::iterator it; cArr = result->at(0); it = cArr->find("pushed_cmd"); if( it != cArr->end() ){ RetVal->CMD = atoi( it->second.c_str() ); }; it = cArr->find("pushed_param"); if( it != cArr->end() ){ RetVal->PARAM = atoi( it->second.c_str() ); }; }; }; //Only If Result is Fetched - Clear Current CMD
sprintf(tQBuf, "UPDATE `lrf_sensors` SET `pushed_cmd`=0, `pushed_param`=0 WHERE `id`=%d", ID ); m_pDatabase->SilentQuery( tQBuf ); }; deleteResult( result ); }; return RetVal;};*/
DBC_INT_LIST *mysqlDBC::listModules(){ DBC_INT_LIST * tVal = NULL; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT `id` FROM `server_modules` WHERE `server_id`=%d AND `enabled`=1", m_nServerID );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; tVal = new DBC_INT_LIST(); if( tVal != NULL ) { Assoc::iterator it; for(int i=0;i<result->size();i++) { cArr = result->at(i); it = cArr->find("id"); if( it != cArr->end() ){ tVal->push_back( atoi( it->second.c_str() )); }; }; }; }; }; deleteResult( result ); }; return tVal;};
DBC_INT_LIST *mysqlDBC::listFilters( uint32_t ServerID ){ DBC_INT_LIST * tVal = NULL; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT `id` FROM `target_filters` WHERE `server_id`=%d AND `enabled`=1", ServerID );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; tVal = new DBC_INT_LIST(); if( tVal != NULL ) { Assoc::iterator it; for(int i=0;i<result->size();i++) { cArr = result->at(i); it = cArr->find("id"); if( it != cArr->end() ){ tVal->push_back( atoi( it->second.c_str() )); }; }; }; }; }; deleteResult( result ); }; return tVal;};
DBC_INT_LIST *mysqlDBC::listLRFMaskVertexes( uint32_t MaskID ){ DBC_INT_LIST * tVal = NULL; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT `id` FROM `lrf_mask_vertexes` WHERE `mask_id`=%d", MaskID );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; tVal = new DBC_INT_LIST(); if( tVal != NULL ) { Assoc::iterator it; for(int i=0;i<result->size();i++) { cArr = result->at(i); it = cArr->find("id"); if( it != cArr->end() ){ tVal->push_back( atoi( it->second.c_str() )); }; }; }; }; }; deleteResult( result ); }; return tVal;};
DBC_INT_LIST *mysqlDBC::listLRFMaskVertexPoints( uint32_t VertexID ){ DBC_INT_LIST * tVal = NULL; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT `id` FROM `lrf_mask_vertex_points` WHERE `vertex_id`=%d ORDER BY `id`", VertexID );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; tVal = new DBC_INT_LIST(); if( tVal != NULL ) { Assoc::iterator it; for(int i=0;i<result->size();i++) { cArr = result->at(i); it = cArr->find("id"); if( it != cArr->end() ){ tVal->push_back( atoi( it->second.c_str() )); }; }; }; }; }; deleteResult( result ); }; return tVal;};
DBC_INT_LIST *mysqlDBC::listMediaServerStreams( uint32_t SiteId, uint32_t MediaServerID, uint8_t listMode ){ DBC_INT_LIST * tVal = NULL; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; switch( listMode ){ case LIST_VALID_RECORDS: sprintf(tQBuf, "SELECT id FROM media_server_streams WHERE `valid`=1 AND `site_id`=%d AND `media_server_id`=%d", SiteId, MediaServerID ); break; case LIST_INVALID_RECORDS: sprintf(tQBuf, "SELECT id FROM media_server_streams WHERE `valid`=0 AND `site_id`=%d AND `media_server_id`=%d", SiteId, MediaServerID ); break; default: sprintf(tQBuf, "SELECT id FROM media_server_streams WHERE `site_id`=%d AND `media_server_id`=%d", SiteId, MediaServerID ); };#ifdef DEBUG_ALL
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; tVal = new DBC_INT_LIST(); if( tVal != NULL ) { Assoc::iterator it; for(int i=0;i<result->size();i++) { cArr = result->at(i); it = cArr->find("id"); if( it != cArr->end() ){ tVal->push_back( atoi( it->second.c_str() )); }; }; }; }; }; deleteResult( result ); }; return tVal;};
DBC_INT_LIST *mysqlDBC::listMediaStreams( uint32_t SiteId, uint8_t listMode ){ DBC_INT_LIST * tVal = NULL; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; switch( listMode ){ case LIST_VALID_RECORDS: sprintf(tQBuf, "SELECT `ms`.`id` FROM `nodes` `nd` LEFT JOIN `media_streams` `ms` ON (`ms`.`id`=`nd`.`aux_parameter`) WHERE `nd`.`type` IN (10,11,12,13) AND `nd`.`site_id`=%d AND `ms`.`valid`=1 AND `nd`.`online`=1", SiteId ); break; case LIST_INVALID_RECORDS: sprintf(tQBuf, "SELECT `ms`.`id` FROM `nodes` `nd` LEFT JOIN `media_streams` `ms` ON (`ms`.`id`=`nd`.`aux_parameter`) WHERE `nd`.`type` IN (10,11,12,13) AND `nd`.`site_id`=%d AND `ms`.`valid`=1 AND `nd`.`online`=0", SiteId ); break; default: sprintf(tQBuf, "SELECT `ms`.`id` FROM `nodes` `nd` LEFT JOIN `media_streams` `ms` ON (`ms`.`id`=`nd`.`aux_parameter`) WHERE `nd`.`type` IN (10,11,12,13) AND `nd`.`site_id`=%d AND `ms`.`valid`=1", SiteId ); };#ifdef DEBUG_ALL
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; tVal = new DBC_INT_LIST(); if( tVal != NULL ) { Assoc::iterator it; for(int i=0;i<result->size();i++) { cArr = result->at(i); it = cArr->find("id"); if( it != cArr->end() ){ tVal->push_back( atoi( it->second.c_str() )); }; }; }; }; }; deleteResult( result ); }; return tVal;};
DBC_INT_LIST *mysqlDBC::listDetectionProfileIDs( uint32_t nodeID ){ DBC_INT_LIST * tVal = NULL; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT `profile_id` FROM `lrf_detection_profiles` WHERE `aux_id`=%d ", nodeID );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; tVal = new DBC_INT_LIST(); if( tVal != NULL ) { Assoc::iterator it; for(int i=0;i<result->size();i++) { cArr = result->at(i); it = cArr->find("profile_id"); if( it != cArr->end() ){ tVal->push_back( atoi( it->second.c_str() )); }; }; }; }; }; deleteResult( result ); }; return tVal;};
DBC_INT_LIST *mysqlDBC::listDetectionProfiles( uint32_t nodeID ){ DBC_INT_LIST * tVal = NULL; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT `id` FROM `lrf_detection_profiles` WHERE `aux_id`=%d ", nodeID );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; tVal = new DBC_INT_LIST(); if( tVal != NULL ) { Assoc::iterator it; for(int i=0;i<result->size();i++) { cArr = result->at(i); it = cArr->find("id"); if( it != cArr->end() ){ tVal->push_back( atoi( it->second.c_str() )); }; }; }; }; }; deleteResult( result ); }; return tVal;};
/*
DBC_INT_LIST *mysqlDBC::listSockets( uint32_t NodeID ){ DBC_INT_LIST * tVal = NULL; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT id FROM sockets WHERE `node_id`=%d", NodeID );#ifdef DEBUG
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; tVal = new DBC_INT_LIST(); if( tVal != NULL ) { Assoc::iterator it; for(int i=0;i<result->size();i++) { cArr = result->at(i); it = cArr->find("id"); if( it != cArr->end() ){ tVal->push_back( atoi( it->second.c_str() )); }; }; }; }; }; deleteResult( result ); }; return tVal;};*/
DBC_INT_LIST *mysqlDBC::listResources( uint32_t NodeID ){ DBC_INT_LIST * tVal = NULL; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; if( NodeID ) { sprintf(tQBuf, "SELECT `id` FROM `resources` WHERE `node_id`=%d AND `active`=1 AND `used`=1", NodeID ); } else { sprintf(tQBuf, "SELECT `re`.`id` FROM `resources` `re` LEFT JOIN `nodes` `no` ON( `re`.`node_id` = `no`.`id` ) WHERE `no`.`site_id`=%d AND `re`.`used`=1", m_nSiteID );// AND `re`.`active`=1", m_nSiteID );
};#ifdef DEBUG
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; tVal = new DBC_INT_LIST(); if( tVal != NULL ) { Assoc::iterator it; for(int i=0;i<result->size();i++) { cArr = result->at(i); it = cArr->find("id"); if( it != cArr->end() ){ tVal->push_back( atoi( it->second.c_str() )); }; }; }; }; }; deleteResult( result ); }; return tVal;};
simplePolygone *mysqlDBC::loadLRFMaskVertex( uint32_t vid ){ simplePolygone *tVal = NULL; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT * FROM `lrf_mask_vertexes` WHERE `id`=%d", vid );#ifdef DEBUG
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { tVal = (simplePolygone *) malloc(sizeof(simplePolygone)); if ( tVal ) { Assoc * cArr; memset( tVal, 0, sizeof(simplePolygone)); Assoc::iterator it; cArr = result->at(0); it = cArr->find("r"); if( it != cArr->end() ){ tVal->color[0] = atoi( it->second.c_str() ); }; it = cArr->find("g"); if( it != cArr->end() ){ tVal->color[1] = atoi( it->second.c_str() ); }; it = cArr->find("b"); if( it != cArr->end() ){ tVal->color[2] = atoi( it->second.c_str() ); }; AAssoc *points; sprintf(tQBuf, "SELECT * FROM `lrf_mask_vertex_points` WHERE `vertex_id`=%d ORDER BY `id`", vid );#ifdef DEBUG
LOG(tQBuf);#endif
points = m_pDatabase->Query( tQBuf ); if( points!= NULL ) { if ( points->size() ) { tVal->count = points->size(); tVal->points = (simplePoint *) calloc( points->size(), sizeof(simplePoint) ); if( tVal->points!= NULL ) { for (int i = 0; i < points->size(); i++) { cArr = points->at( i ); it = cArr->find("x"); if( it != cArr->end() ){ tVal->points[i].setX( atoi( it->second.c_str() ) ); }; it = cArr->find("y"); if( it != cArr->end() ){ tVal->points[i].setY( atoi( it->second.c_str() ) ); }; }; }; }; }; deleteResult( points ); }; }; }; deleteResult( result ); }; return tVal;};
DBC_INT_LIST *mysqlDBC::listNetworks( uint32_t nif_id ){ DBC_INT_LIST * tVal = NULL; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT `id` FROM `networks` WHERE `nif_id`=%d", nif_id );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; tVal = new DBC_INT_LIST(); if( tVal != NULL ) { Assoc::iterator it; for(int i=0;i<result->size();i++) { cArr = result->at(i); it = cArr->find("id"); if( it != cArr->end() ){ tVal->push_back( atoi( it->second.c_str() )); }; }; }; }; }; deleteResult( result ); }; return tVal;};
DBC_INT_LIST *mysqlDBC::listNewModules( DBC_INT_LIST * old_ids ){ DBC_INT_LIST * tVal = NULL; char tParam[CTEXT]; //memset( tParam, 0, CTEXT );
sprintf(tParam,"0"); if( old_ids != NULL ) { char tBuffer[CTEXT]; for(int i = 0; i< old_ids->size(); i++ ) { sprintf( tBuffer, "%s,%d", tParam, old_ids->at(i) ); strncpy( tParam, tBuffer, CTEXT ); }; }; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT `id` FROM `server_modules` WHERE `server_id`=%d AND `enabled`=1 AND `id` NOT IN (%s)", m_nServerID, tParam );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; tVal = new DBC_INT_LIST(); if( tVal != NULL ) { Assoc::iterator it; for(int i=0;i<result->size();i++) { cArr = result->at(i); it = cArr->find("id"); if( it != cArr->end() ){ tVal->push_back( atoi( it->second.c_str() )); }; }; }; }; }; deleteResult( result ); }; return tVal;};
uint32_t mysqlDBC::getCamId( CSTR UUID ){ uint32_t RetVal = 0; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT id FROM cameras WHERE `uuid`='%s'", UUID );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; Assoc::iterator it; cArr = result->at(0); it = cArr->find("id"); if( it != cArr->end() ){ RetVal = atoi( it->second.c_str() ); }; }; }; deleteResult( result ); }; return RetVal;};
DBC_CAP_DATA *mysqlDBC::getCamCapPictureData( uint32_t PicID ){ DBC_CAP_DATA *tVal = NULL; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT md5, ext FROM pictures WHERE `id`=%d", PicID );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; tVal = (DBC_CAP_DATA*) malloc(sizeof(DBC_CAP_DATA)); if( tVal != NULL ) { memset( tVal, 0 , sizeof(DBC_CAP_DATA)); Assoc::iterator it; cArr = result->at(0); it = cArr->find("md5"); if( it != cArr->end() ){ strncpy(tVal->md5, it->second.c_str(), 32); }; it = cArr->find("ext"); if( it != cArr->end() ){ strncpy(tVal->ext, it->second.c_str(), 3 ); }; }; }; }; deleteResult( result ); }; return tVal;};
DBC_CAM_DATA *mysqlDBC::getCamData( uint32_t ID ){ DBC_CAM_DATA *tVal = NULL; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT * FROM cameras WHERE `id`=%d", ID );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; tVal = (DBC_CAM_DATA*) malloc(sizeof(DBC_CAM_DATA)); if( tVal != NULL ) { memset( tVal, 0 , sizeof(DBC_CAM_DATA)); tVal->id = ID; Assoc::iterator it; cArr = result->at(0); it = cArr->find("type"); if( it != cArr->end() ){ tVal->type = atoi( it->second.c_str() ); }; it = cArr->find("online"); if( it != cArr->end() ){ tVal->online = (bool) atoi( it->second.c_str() ); }; it = cArr->find("stream_id"); if( it != cArr->end() ){ tVal->stream_id = atoi( it->second.c_str() ); }; it = cArr->find("hardware"); if( it != cArr->end() ){ strncpy( tVal->hardware, it->second.c_str(), 32 ); }; it = cArr->find("name"); if( it != cArr->end() ){ strncpy( tVal->name, it->second.c_str(), 64 ); }; it = cArr->find("status"); if( it != cArr->end() ){ tVal->status = atoi( it->second.c_str() ); }; it = cArr->find("session"); if( it != cArr->end() ){ strncpy( tVal->session, it->second.c_str(), 32 ); }; it = cArr->find("protocol"); if( it != cArr->end() ){ tVal->protocol = atoi( it->second.c_str() ); }; it = cArr->find("protocol_aux"); if( it != cArr->end() ){ tVal->protocol_aux = atoi( it->second.c_str() ); }; it = cArr->find("uart_id"); if( it != cArr->end() ){ tVal->uart_id = atoi( it->second.c_str() ); }; it = cArr->find("x"); if( it != cArr->end() ){ tVal->x = atof( it->second.c_str() ); }; it = cArr->find("y"); if( it != cArr->end() ){ tVal->y = atof( it->second.c_str() ); }; it = cArr->find("z"); if( it != cArr->end() ){ tVal->z = atof( it->second.c_str() ); }; it = cArr->find("x_rot"); if( it != cArr->end() ){ tVal->x_rot = atof( it->second.c_str() ); }; it = cArr->find("y_rot"); if( it != cArr->end() ){ tVal->y_rot = atof( it->second.c_str() ); }; it = cArr->find("z_rot"); if( it != cArr->end() ){ tVal->z_rot = atof( it->second.c_str() ); }; it = cArr->find("imager_type"); if( it != cArr->end() ){ tVal->imager_type = atoi( it->second.c_str() ); }; it = cArr->find("lens_f"); if( it != cArr->end() ){ tVal->lens_f = atoi( it->second.c_str() ); }; it = cArr->find("ptz_speed_step"); if( it != cArr->end() ){ tVal->ptz_speed_step = atof( it->second.c_str() ); }; it = cArr->find("pan_model"); if( it != cArr->end() ){ tVal->pan_model = atoi( it->second.c_str() ); }; it = cArr->find("pan_angles"); if( it != cArr->end() ){ tVal->pan_angles = atoi( it->second.c_str() ); }; it = cArr->find("tilt_model"); if( it != cArr->end() ){ tVal->tilt_model = atoi( it->second.c_str() ); }; it = cArr->find("tilt_angles"); if( it != cArr->end() ){ tVal->tilt_angles = atoi( it->second.c_str() ); }; it = cArr->find("zoom_model"); if( it != cArr->end() ){ tVal->zoom_model = atoi( it->second.c_str() ); }; it = cArr->find("zoom"); if( it != cArr->end() ){ tVal->zoom = atof( it->second.c_str() ); }; //it = cArr->find("max_range");
//if( it != cArr->end() ){
// tVal->max_range = atof( it->second.c_str() );
//};
it = cArr->find("access_login"); if( it != cArr->end() ){ strncpy( tVal->username, it->second.c_str(), 16 ); }; it = cArr->find("access_pass"); if( it != cArr->end() ){ strncpy( tVal->password, it->second.c_str(), 16 ); }; it = cArr->find("uuid"); if( it != cArr->end() ){ strncpy( tVal->uuid, it->second.c_str(), 64 ); }; it = cArr->find("mac"); if( it != cArr->end() ){ strncpy( tVal->mac, it->second.c_str(), 16 ); }; it = cArr->find("ip"); if( it != cArr->end() ){ strncpy( tVal->ip, it->second.c_str(), 16 ); }; it = cArr->find("port"); if( it != cArr->end() ){ tVal->port = atoi( it->second.c_str() ); }; it = cArr->find("onvif_access"); if( it != cArr->end() ){ strncpy( tVal->onvif_access, it->second.c_str(), 5); }; it = cArr->find("onvif_ctrl"); if( it != cArr->end() ){ strncpy( tVal->onvif_ctrl, it->second.c_str(), 250); }; it = cArr->find("ptz_token"); if( it != cArr->end() ){ strncpy( tVal->ptz_token, it->second.c_str(), 64); }; it = cArr->find("trigger_mode"); if( it != cArr->end() ){ tVal->triggering_mode = atoi( it->second.c_str() ); }; it = cArr->find("auth_mode"); if( it != cArr->end() ){ tVal->auth_mode = atoi( it->second.c_str() ); }; }; }; }; deleteResult( result ); }; return tVal;};
DBC_PUSHED_CMD *mysqlDBC::getActivePushedCMD( uint32_t NodeID ){ DBC_PUSHED_CMD *RetVal = NULL; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT * FROM `nodes_qcq` WHERE `node_id`=%d AND `status` > 0 AND `status` < 100", NodeID );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { RetVal = (DBC_PUSHED_CMD*)malloc(sizeof(DBC_PUSHED_CMD)); if( RetVal ) { Assoc * cArr; Assoc::iterator it;
memset( RetVal, 0, sizeof(DBC_PUSHED_CMD)); cArr = result->at(0); it = cArr->find("id"); if( it != cArr->end() ){ RetVal->id = atoi( it->second.c_str() ); }; it = cArr->find("cmd"); if( it != cArr->end() ){ RetVal->CMD = atoi( it->second.c_str() ); }; it = cArr->find("parameter"); if( it != cArr->end() ){ strncpy( RetVal->PARAM, it->second.c_str(), 256 ); RetVal->PARAM[255] = (char)0; }; }; }; }; deleteResult( result ); }; return RetVal;};
DBC_PUSHED_CMD *mysqlDBC::getPushedCMD( uint32_t CmdID ){ DBC_PUSHED_CMD *RetVal = NULL; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT * FROM `nodes_qcq` WHERE `id`=%d", CmdID );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { RetVal = (DBC_PUSHED_CMD*)malloc(sizeof(DBC_PUSHED_CMD)); if( RetVal ) { Assoc * cArr; Assoc::iterator it;
memset( RetVal, 0, sizeof(DBC_PUSHED_CMD)); cArr = result->at(0); it = cArr->find("id"); if( it != cArr->end() ){ RetVal->id = atoi( it->second.c_str() ); }; it = cArr->find("cmd"); if( it != cArr->end() ){ RetVal->CMD = atoi( it->second.c_str() ); }; it = cArr->find("parameter"); if( it != cArr->end() ){ strncpy( RetVal->PARAM, it->second.c_str(), 256 ); RetVal->PARAM[255] = (char)0; }; }; }; }; deleteResult( result ); }; return RetVal;};
DBC_PUSHED_CMD *mysqlDBC::getNodePushedCMD( uint32_t NodeID ){ DBC_PUSHED_CMD *RetVal = NULL; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT * FROM `nodes_qcq` WHERE `node_id`=%d AND `status`=0 LIMIT 1", NodeID );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { RetVal = (DBC_PUSHED_CMD*)malloc(sizeof(DBC_PUSHED_CMD)); if( RetVal ) { Assoc * cArr; Assoc::iterator it;
memset( RetVal, 0, sizeof(DBC_PUSHED_CMD)); cArr = result->at(0); it = cArr->find("id"); if( it != cArr->end() ){ RetVal->id = atoi( it->second.c_str() ); }; it = cArr->find("cmd"); if( it != cArr->end() ){ RetVal->CMD = atoi( it->second.c_str() ); }; it = cArr->find("parameter"); if( it != cArr->end() ){ strncpy( RetVal->PARAM, it->second.c_str(), 256 ); RetVal->PARAM[255] = (char)0; }; //Only If Result is Fetched - Clear Current CMD
//sprintf(tQBuf, "DELETE FROM `nodes_qcq` WHERE `id`=%d", RetVal->id );
//m_pDatabase->SilentQuery( tQBuf );
}; }; }; deleteResult( result ); }; return RetVal;};
bool mysqlDBC::updateNodePushedCMD( uint32_t CmdID, uint8_t status ){ if(m_bIsConnected){ char tQBuf[CTEXT]; sprintf(tQBuf, "UPDATE `nodes_qcq` SET `status`=%d WHERE `id`=%d ", status, CmdID );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); return true; }; return false;};
DBC_MODULE_DATA *mysqlDBC::getModuleData( uint32_t ID ){ DBC_MODULE_DATA *tVal = NULL; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT * FROM server_modules WHERE `id`=%d", ID );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; tVal = (DBC_MODULE_DATA*) malloc(sizeof(DBC_MODULE_DATA)); if( tVal != NULL ) { Assoc::iterator it; cArr = result->at(0); it = cArr->find("id"); if( it != cArr->end() ){ tVal->module_id = atoi( it->second.c_str() ); }; it = cArr->find("aux_id"); if( it != cArr->end() ){ tVal->aux_id = atoi( it->second.c_str() ); }; it = cArr->find("type"); if( it != cArr->end() ){ tVal->type = atoi( it->second.c_str() ); }; it = cArr->find("enabled"); if( it != cArr->end() ){ tVal->enabled = (bool)atoi( it->second.c_str() ); }; }; }; }; deleteResult( result ); }; return tVal;};/*
DBC_SOCKET_DATA *mysqlDBC::getSocketData( uint32_t ID ){ DBC_SOCKET_DATA *tVal = NULL; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT * FROM sockets WHERE `id`=%d", ID );#ifdef DEBUG
//LOG(tQBuf);
#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; tVal = (DBC_SOCKET_DATA*) malloc(sizeof(DBC_SOCKET_DATA)); if( tVal != NULL ) { Assoc::iterator it; cArr = result->at(0); it = cArr->find("id"); if( it != cArr->end() ){ tVal->socket_id = atoi( it->second.c_str() ); }; it = cArr->find("aux_id"); if( it != cArr->end() ){ tVal->aux_id = atoi( it->second.c_str() ); }; it = cArr->find("type"); if( it != cArr->end() ){ tVal->type = atoi( it->second.c_str() ); }; it = cArr->find("binded"); if( it != cArr->end() ){ tVal->binded = (bool)atoi( it->second.c_str() ); }; }; }; }; deleteResult( result ); }; return tVal;};*/
DBC_MEDIA_STREAM_DATA *mysqlDBC::getMediaStreamData( uint32_t ID ){ DBC_MEDIA_STREAM_DATA *tVal = NULL; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT * FROM media_streams WHERE `id`=%d", ID );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; tVal = (DBC_MEDIA_STREAM_DATA*) malloc(sizeof(DBC_MEDIA_STREAM_DATA)); if( tVal != NULL ) { memset( tVal, 0, sizeof(DBC_MEDIA_STREAM_DATA) ); Assoc::iterator it; cArr = result->at(0); tVal->id = ID; it = cArr->find("source_id"); if( it != cArr->end() ){ tVal->source_id = atoi( it->second.c_str() ); }; it = cArr->find("source_type"); if( it != cArr->end() ){ sprintf( tVal->source_type, it->second.c_str() ); }; it = cArr->find("valid"); if( it != cArr->end() ){ tVal->valid = (bool) atoi( it->second.c_str() ); }; it = cArr->find("token"); if( it != cArr->end() ){ sprintf( tVal->token, it->second.c_str() ); }; it = cArr->find("img_width"); if( it != cArr->end() ){ tVal->width = atoi( it->second.c_str() ); }; it = cArr->find("img_height"); if( it != cArr->end() ){ tVal->height = atoi( it->second.c_str() ); }; it = cArr->find("fps"); if( it != cArr->end() ){ tVal->fps = atoi( it->second.c_str() ); }; it = cArr->find("compression_type"); if( it != cArr->end() ){ sprintf(tVal->c_type, it->second.c_str()); }; it = cArr->find("mrl_proto"); if( it != cArr->end() ){ sprintf( tVal->mrl_proto, it->second.c_str() ); }; it = cArr->find("mrl_port"); if( it != cArr->end() ){ tVal->mrl_port = atoi( it->second.c_str() ); }; it = cArr->find("mrl"); if( it != cArr->end() ){ sprintf( tVal->mrl, it->second.c_str() ); }; }; }; }; deleteResult( result ); }; return tVal;};
DBC_MEDIA_SERVER_DATA *mysqlDBC::getMediaServerData( uint32_t ID ){ DBC_MEDIA_SERVER_DATA *tVal = NULL; if(m_bIsConnected){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT * FROM media_servers WHERE `id`=%d", ID );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; tVal = (DBC_MEDIA_SERVER_DATA*) malloc(sizeof(DBC_MEDIA_SERVER_DATA)); if( tVal != NULL ) { Assoc::iterator it; cArr = result->at(0); tVal->id = ID; it = cArr->find("secret_key"); if( it != cArr->end() ){ sprintf( tVal->key, it->second.c_str() ); }; it = cArr->find("ip"); if( it != cArr->end() ){ sprintf( tVal->ip, it->second.c_str() ); }; it = cArr->find("REST_port"); if( it != cArr->end() ){ tVal->port = atoi( it->second.c_str() ); }; it = cArr->find("virtual_host"); if( it != cArr->end() ){ sprintf( tVal->host, it->second.c_str() ); }; it = cArr->find("recording"); if( it != cArr->end() ){ tVal->recording = (bool)atoi( it->second.c_str() ); }; it = cArr->find("local"); if( it != cArr->end() ){ tVal->local = (bool)atoi( it->second.c_str() ); }; it = cArr->find("docRoot"); if( it != cArr->end() ){ sprintf( tVal->docRoot, it->second.c_str() ); }; sprintf( tVal->name,"ZLMedia_%d", tVal->id ); }; }; }; deleteResult( result ); }; return tVal;};
DBC_MEDIA_SERVER_STREAM_DATA *mysqlDBC::getMediaServerStreamDataBySource( uint32_t ID ){ DBC_MEDIA_SERVER_STREAM_DATA *tVal = NULL; if(m_bIsConnected){ char tQBuf[MAX_PATH_LEN]; AAssoc *result; sprintf(tQBuf, "SELECT `id`, `media_stream_id`, `online`, `key`, `mrl` FROM media_server_streams WHERE `media_stream_id`=%d", ID );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; tVal = (DBC_MEDIA_SERVER_STREAM_DATA*) malloc(sizeof(DBC_MEDIA_SERVER_STREAM_DATA)); if( tVal != NULL ) { Assoc::iterator it; cArr = result->at(0); tVal->id = ID; it = cArr->find("media_stream_id"); if( it != cArr->end() ){ tVal->media_stream_id = atoi( it->second.c_str() ); }; it = cArr->find("online"); if( it != cArr->end() ){ tVal->online = atoi( it->second.c_str() ); }; it = cArr->find("key"); if( it != cArr->end() ){ sprintf( tVal->key, it->second.c_str() ); }; it = cArr->find("mrl"); if( it != cArr->end() ){ sprintf( tVal->mrl, it->second.c_str() ); }; }; }; }; deleteResult( result ); }; return tVal;};
DBC_MEDIA_SERVER_STREAM_DATA *mysqlDBC::getMediaServerStreamData( uint32_t ID ){ DBC_MEDIA_SERVER_STREAM_DATA *tVal = NULL; if(m_bIsConnected){ char tQBuf[MAX_PATH_LEN]; AAssoc *result; sprintf(tQBuf, "SELECT `id`, `media_stream_id`, `online`, `key`, `mrl` FROM media_server_streams WHERE `id`=%d", ID );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; tVal = (DBC_MEDIA_SERVER_STREAM_DATA*) malloc(sizeof(DBC_MEDIA_SERVER_STREAM_DATA)); if( tVal != NULL ) { Assoc::iterator it; cArr = result->at(0); tVal->id = ID; it = cArr->find("media_stream_id"); if( it != cArr->end() ){ tVal->media_stream_id = atoi( it->second.c_str() ); }; it = cArr->find("online"); if( it != cArr->end() ){ tVal->online = atoi( it->second.c_str() ); }; it = cArr->find("key"); if( it != cArr->end() ){ sprintf( tVal->key, it->second.c_str() ); }; it = cArr->find("mrl"); if( it != cArr->end() ){ sprintf( tVal->mrl, it->second.c_str() ); }; }; }; }; deleteResult( result ); }; return tVal;};
void mysqlDBC::registerServer( uint32_t SiteID, CSTR identity, int PID, uint32_t *ServID, uint32_t *ServNode ){ if(m_bIsConnected){ m_nSiteID = SiteID; char tQBuf[MAX_PATH_LEN]; sprintf( tQBuf, "INSERT INTO servers SET `site_id`=%d, `identity`='%s', `version_string`='%s', `online`=1, `ts`=UNIX_TIMESTAMP(now()), pid=%d ON DUPLICATE KEY UPDATE `version_string`='%s', `ts`=UNIX_TIMESTAMP(now()), `online`=1, pid=%d", SiteID, identity, _BUILD_STRING_, PID, _BUILD_STRING_, PID );#ifdef DEBUG
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf );
*ServID = getServerID( identity ); m_nServerID = *ServID; if( *ServID ) {
sprintf(tQBuf,"INSERT INTO nodes SET `site_id`=%d, `aux_id`='%d', `type`= 0, `online`=1, `name`='Server Node' ON DUPLICATE KEY UPDATE `online`=1", m_nSiteID, *ServID );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
*ServNode = ( uint32_t ) m_pDatabase->QueryID( tQBuf ); if( *ServNode == 0 ){ *ServNode = getServerNode( *ServID ); }; m_nServerNodeID = *ServNode; // Clenup Nodes and services ...
sprintf(tQBuf,"UPDATE nodes SET `online`=0 WHERE `server_id`=%d ", *ServID ); #ifdef DEBUG_ALL
LOG(tQBuf); #endif
m_pDatabase->SilentQuery( tQBuf ); sprintf(tQBuf,"UPDATE cameras SET `online`=0 WHERE `site_id`=%d ", SiteID ); #ifdef DEBUG_ALL
LOG(tQBuf); #endif
m_pDatabase->SilentQuery( tQBuf );
sprintf(tQBuf,"UPDATE media_streams SET `valid`=0 WHERE `site_id`=%d ", SiteID ); #ifdef DEBUG_ALL
LOG(tQBuf); #endif
m_pDatabase->SilentQuery( tQBuf );
sprintf(tQBuf,"UPDATE media_server_streams SET `valid`=0, `online`=0 WHERE `site_id`=%d ", SiteID ); #ifdef DEBUG_ALL
LOG(tQBuf); #endif
m_pDatabase->SilentQuery( tQBuf ); //cleanResources( tServerNodeID );
setNodeOnline( m_nServerNodeID ); } };};
void mysqlDBC::unregisterServer(){ if( setNodeOffline( m_nServerNodeID ) ){ char tQBuf[CTEXT]; sprintf(tQBuf,"UPDATE servers SET `online`=0, `ts`=UNIX_TIMESTAMP(now()) WHERE `id`=%d", m_nServerID );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); };};
bool mysqlDBC::setNodeOnline( uint32_t NodeID, uint8_t status ){ if(m_bIsConnected){ char tQBuf[CTEXT]; if( NodeID ) { sprintf(tQBuf,"UPDATE nodes SET `online`=%d WHERE `id`=%d", status, NodeID );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); sprintf(tQBuf,"UPDATE `resources` SET `active`=1 WHERE `node_id`=%d", NodeID );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); return true; }; }; return false;};
bool mysqlDBC::setNodeOffline( uint32_t NodeID ){ if(m_bIsConnected){ char tQBuf[CTEXT]; if( NodeID ) { sprintf(tQBuf,"UPDATE nodes SET `online`=0 WHERE `id` = %d", NodeID );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); sprintf(tQBuf,"UPDATE `resources` SET `active`=0 WHERE `node_id` = %d", NodeID );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); return true; }; }; return false;};DBC_RESOURCE_DATA *mysqlDBC::getResourceData( uint32_t ResourceID ){ DBC_RESOURCE_DATA *tVal = NULL; if( m_bIsConnected ){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT `node_id`, `type`, `aux_id`, `device` FROM resources WHERE `id`=%d", ResourceID );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; tVal = (DBC_RESOURCE_DATA*) malloc(sizeof(DBC_RESOURCE_DATA)); if( tVal != NULL ) { Assoc::iterator it; cArr = result->at(0); tVal->id = ResourceID; it = cArr->find("node_id"); if( it != cArr->end() ){ tVal->node_id = atoi( it->second.c_str() ); }; it = cArr->find("type"); if( it != cArr->end() ){ tVal->type = atoi( it->second.c_str() ); }; it = cArr->find("aux_id"); if( it != cArr->end() ){ tVal->aux_id = atoi( it->second.c_str() ); }; it = cArr->find("device"); if( it != cArr->end() ){ strncpy( tVal->device, it->second.c_str(), 64 ); tVal->device[63] = (char)0; }; }; }; }; deleteResult( result ); }; return tVal;};
uint32_t mysqlDBC::getResourceID( uint32_t NodeID, uint8_t type, uint32_t auxID ){ uint32_t RetVal = 0; if(m_bIsConnected){ char tQBuf[CTEXT]; sprintf(tQBuf,"SELECT `id` FROM `resources` WHERE `node_id`=%d AND `type`=%d AND `aux_id`=%d", NodeID, type, auxID );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
AAssoc *result; result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc * cArr; Assoc::iterator it; cArr = result->at(0); it = cArr->find("id"); if( it != cArr->end() ){ RetVal = atoi( it->second.c_str() ); }; }; }; deleteResult( result ); }; return RetVal;};
uint32_t mysqlDBC::getServerID( CSTR identity ){ uint32_t RetVal = 0; if(m_bIsConnected){ char tQBuf[CTEXT]; sprintf(tQBuf,"SELECT id FROM servers WHERE `identity`='%s'", identity );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
AAssoc *result; result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc * cArr; Assoc::iterator it; cArr = result->at(0); it = cArr->find("id"); if( it != cArr->end() ){ RetVal = atoi( it->second.c_str() ); }; }; }; deleteResult( result ); }; return RetVal;};
uint32_t mysqlDBC::getServerNode( uint32_t SID ){ uint32_t RetVal = 0; if(m_bIsConnected){ char tQBuf[CTEXT]; sprintf(tQBuf,"SELECT id FROM nodes WHERE `type`=0 AND `aux_id`=%d", SID );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
AAssoc *result; result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc * cArr; Assoc::iterator it; cArr = result->at(0); it = cArr->find("id"); if( it != cArr->end() ){ RetVal = atoi( it->second.c_str() ); }; }; }; deleteResult( result ); }; return RetVal;};
uint32_t mysqlDBC::addLocalMediaSource( uint32_t SiteID, CSTR path, uint32_t width, uint32_t height ){ uint32_t RetVal = 0; if(m_bIsConnected){ char tQBuf[1024]; char tM5[33]; CSTR tMD5 = MD5String( path ); if( tMD5 != NULL ) { memcpy( tM5, tMD5, 33 ); tM5[32]=(char)0; free( tMD5 ); sprintf( tQBuf, "INSERT INTO media_streams SET `site_id`=%d, `source_id`=0, source_type='A', `valid`=1, `name`='Local Frame Grabber', `token`='%s', `img_width`=%d, `img_height`=%d, `mrl_proto`='v4l2', `mrl_port`='', `picture_proto`='', mrl='%s' ON DUPLICATE KEY UPDATE id=id, `valid`=1",//, img_width=%d, img_height=%d",
SiteID, tM5, width, height, path );//, width, height );
#ifdef DEBUG_ALL
LOG(tQBuf);#endif
RetVal = (uint32_t) m_pDatabase->QueryID( tQBuf ); };
}; return RetVal;};/*
uint32_t mysqlDBC::addNodeSocket( uint32_t NodeID, uint32_t auxID, uint8_t SocketType, uint8_t SocketMode, bool multidrop, CSTR path, CSTR name ){ uint32_t retVal = 0; if(m_bIsConnected){ char tQBuf[2048]; char tM5[33]; CSTR tMD5 = MD5String( path ); if( tMD5 != NULL ) { memcpy( tM5, tMD5, 33 ); free( tMD5 ); if( multidrop ) { sprintf(tQBuf,"INSERT INTO `sockets` SET `node_id`=%d, `type`=%d, `mode`=%d, `multidrop`=1, `md5`='%s', `path`='%s', `name`='%s', `aux_id`=%d ON DUPLICATE KEY UPDATE `id`=`id`, `name`='%s'", NodeID, SocketType, SocketMode, tM5, path, name, auxID, name ); } else { sprintf(tQBuf,"INSERT INTO `sockets` SET `node_id`=%d, `type`=%d, `mode`=%d, `multidrop`=0, `md5`='%s', `path`='%s', `name`='%s', `aux_id`=%d ON DUPLICATE KEY UPDATE `id`=`id`, `name`='%s'", NodeID, SocketType, SocketMode, tM5, path, name, auxID, name ); };#ifdef DEBUG
LOG(tQBuf);#endif
//m_pDatabase->SilentQuery( tQBuf );
retVal = (uint32_t) m_pDatabase->QueryID( tQBuf ); }; }; return retVal;};*/bool mysqlDBC::addNotification( uint32_t MSG_ID, uint8_t DIS_LVL, uint32_t OBJ_ID ){ if(m_bIsConnected){ char tQBuf[2048]; sprintf(tQBuf,"INSERT INTO `notifications` SET `site_id`=%d, `ts`=NOW(), `lvl`=%d, `type`=%d, `obj_id`=%d ON DUPLICATE KEY UPDATE `status`='A', `ts`=NOW()", m_nSiteID, DIS_LVL, MSG_ID, OBJ_ID );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); return true; }; return false;};
uint32_t mysqlDBC::addResource( /*uint32_t NodeID,*/ uint8_t type, CSTR devName, uint32_t auxID ){ uint32_t RetVal = 0; if( m_bIsConnected ){ char tQBuf[2048]; sprintf( tQBuf, "%d:%d:%s", m_nServerNodeID, type, devName ); CSTR tMD5 = MD5String( tQBuf ); if( tMD5 ) { sprintf( tQBuf, "INSERT INTO `resources` SET `node_id`=%d, `type`=%d, `md5`='%s', `aux_id`=%d, `device`='%s', `active`=1 ON DUPLICATE KEY UPDATE `active`=1, `aux_id`=%d", m_nServerNodeID, type, tMD5, auxID, devName, auxID ); //sprintf( tQBuf, "INSERT INTO `resources` SET `node_id`=%d, `type`=%d, `aux_id`=%d, `device`='%s', `active`=1 ON DUPLICATE KEY UPDATE `active`=1, `aux_id`=%d, `device`='%s'", NodeID, type, auxID, devName, auxID, devName );
free( tMD5 );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
RetVal = (uint32_t) m_pDatabase->QueryID( tQBuf ); if( RetVal == 0 ) { RetVal = getResourceID( m_nServerNodeID, type, auxID ); }; }; }; return RetVal;};/*
uint32_t mysqlDBC::getNodeSocketID( uint32_t NodeID, uint32_t auxID, uint8_t SocketType, CSTR path ){ uint32_t retVal = 0; if(m_bIsConnected){ char tQBuf[2048]; char tM5[33]; CSTR tMD5 = MD5String( path ); if( tMD5 != NULL ) { memcpy( tM5, tMD5, 33 ); free( tMD5 ); sprintf( tQBuf,"SELECT id FROM `sockets` WHERE `node_id`=%d AND `type`=%d AND `md5`='%s' AND `aux_id`=%d", NodeID, SocketType, tM5, auxID );#ifdef DEBUG
LOG(tQBuf);#endif
AAssoc *result; result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc * cArr; Assoc::iterator it; cArr = result->at(0); it = cArr->find("id"); if( it != cArr->end() ){ retVal = atoi( it->second.c_str() ); }; }; }; deleteResult( result ); }; }; return retVal;};*/
/*
CSTR mysqlDBC::getSocketName( uint32_t NodeID, uint32_t Type ){ if(m_bIsConnected){ char tQBuf[CTEXT]; sprintf( tQBuf, "SELECT `name` FROM `sockets` WHERE `node_id`=%d AND `type`=%d LIMIT 1", NodeID, Type );#ifdef DEBUG
LOG(tQBuf);#endif
AAssoc *result; result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc * cArr; Assoc::iterator it; cArr = result->at(0); it = cArr->find("name"); if( it != cArr->end() ){ strncpy( tQBuf, it->second.c_str(), CTEXT ); }; }; }; deleteResult( result ); return strdup(tQBuf); }; return NULL;};*/KAFKA_SETTINGS *mysqlDBC::getSettingsKAFKA( uint32_t ModuleID ){ KAFKA_SETTINGS *tVal = NULL; if( m_bIsConnected ) { char tQBuf[CTEXT]; AAssoc *result; sprintf( tQBuf, "SELECT * FROM modules_kafka WHERE module_id = %d", ModuleID );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; tVal = (KAFKA_SETTINGS*) malloc(sizeof(KAFKA_SETTINGS)); if( tVal != NULL ) { memset( tVal, 0, sizeof(KAFKA_SETTINGS) ); Assoc::iterator it; cArr = result->at(0); it = cArr->find("brocker_address"); if( it != cArr->end() ){ strncpy( tVal->brocker_addr, it->second.c_str(), 255 ); }; it = cArr->find("brocker_port"); if( it != cArr->end() ){ tVal->brocker_port = atoi( it->second.c_str() ); }; it = cArr->find("use_ssl"); if( it != cArr->end() ){ tVal->use_ssl = (bool)atoi( it->second.c_str() ); }; it = cArr->find("auth_cert"); if( it != cArr->end() ){ tVal->auth_by_cert = (bool)atoi( it->second.c_str() ); }; it = cArr->find("auth_cred"); if( it != cArr->end() ){ tVal->auth_by_cred = (bool)atoi( it->second.c_str() ); }; it = cArr->find("vault_md5"); if( it != cArr->end() ){ strncpy( tVal->vault_md5, it->second.c_str(), 32 ); }; it = cArr->find("truststore"); if( it != cArr->end() ){ tVal->truststore = (bool)atoi( it->second.c_str() ); }; it = cArr->find("certstore"); if( it != cArr->end() ){ tVal->certstore = (bool)atoi( it->second.c_str() ); }; it = cArr->find("keystore"); if( it != cArr->end() ){ tVal->keystore = (bool)atoi( it->second.c_str() ); }; it = cArr->find("cred_username"); if( it != cArr->end() ){ strncpy( tVal->cred_username, it->second.c_str(), 32 ); }; it = cArr->find("cred_password"); if( it != cArr->end() ){ strncpy( tVal->cred_password, it->second.c_str(), 32 ); }; }; }; }; deleteResult( result ); }; return tVal;};
KAFKA_TEMPLATE *mysqlDBC::getKafkaTemplateForEvent( uint32_t ModuleID, uint32_t ClassID, uint32_t EventID ){ KAFKA_TEMPLATE *tVal = NULL; if( m_bIsConnected ) { char tQBuf[CTEXT]; AAssoc *result; sprintf( tQBuf, "SELECT topic, template FROM module_kafka_settings WHERE module_id=%d AND class_id=%d AND event_id=%d", ModuleID, ClassID, EventID );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; tVal = (KAFKA_TEMPLATE*) malloc(sizeof(KAFKA_TEMPLATE)); if( tVal != NULL ) { Assoc::iterator it; cArr = result->at(0); it = cArr->find("topic"); if( it != cArr->end() ){ memset( tVal->topic, 0, 128 ); strncpy( tVal->topic , it->second.c_str(), 127 ); }; it = cArr->find("template"); if( it != cArr->end() ){ tVal->tpl = (CSTR)malloc( it->second.length() + 1 ); if( tVal->tpl!= NULL) { memset( tVal->tpl, 0, it->second.length() + 1 ); strncpy( tVal->tpl, it->second.c_str(), it->second.length() ); }; }; }; }; }; deleteResult( result ); }; return tVal;};
DBC_UART_DATA *mysqlDBC::getUartData( uint32_t UartID ){ DBC_UART_DATA *tVal = NULL; if( m_bIsConnected ) { char tQBuf[MAX_PATH_LEN]; AAssoc *result; sprintf( tQBuf, "SELECT * FROM uart_settings WHERE id = %d", UartID );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; tVal = (DBC_UART_DATA*) malloc(sizeof(DBC_UART_DATA)); if( tVal != NULL ) { Assoc::iterator it; cArr = result->at(0); it = cArr->find("type"); if( it != cArr->end() ){ tVal->type = atoi( it->second.c_str() ); }; it = cArr->find("speed"); if( it != cArr->end() ){ tVal->speed = atoi( it->second.c_str() ); }; it = cArr->find("mode"); if( it != cArr->end() ){ tVal->mode = atoi( it->second.c_str() ); }; it = cArr->find("port"); if( it != cArr->end() ){ tVal->port = atoi( it->second.c_str() ); }; it = cArr->find("path"); if( it != cArr->end() ){ strncpy( tVal->path, it->second.c_str(), 128 ); }; }; }; }; deleteResult( result ); }; return tVal;};
uint32_t mysqlDBC::getUartID( uint32_t NodeID, uint8_t Type, CSTR path ){ uint32_t RetVal = 0; if(m_bIsConnected){ char tQBuf[CTEXT]; sprintf(tQBuf,"SELECT `id` FROM `uart_settings` WHERE `node_id`=%d AND `type`=%d AND `path`='%s' ", NodeID, Type, path );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
AAssoc *result; result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc * cArr; Assoc::iterator it; cArr = result->at(0); it = cArr->find("id"); if( it != cArr->end() ){ RetVal = atoi( it->second.c_str() ); }; }; }; deleteResult( result ); }; return RetVal;};
bool mysqlDBC::updateMediaServerStream( uint32_t id, CSTR mrl, CSTR key ){ if( m_bIsConnected ) { char tQBuf[MAX_PATH_LEN]; if( key == NULL ) { if( mrl == NULL ) { sprintf( tQBuf,"UPDATE media_server_streams SET `online`=0, `key`='', mrl='', `valid`=0 WHERE `id`=%d", id ); } else { sprintf( tQBuf,"UPDATE media_server_streams SET `online`=0, `key`='', `mrl`='%s', `valid`=1 WHERE `id`=%d", mrl, id ); }; } else { sprintf( tQBuf,"UPDATE media_server_streams SET `online`=1, `key`='%s', `mrl`='%s', `valid`=1 WHERE `id`=%d", key, mrl, id ); };#ifdef DEBUG_ALL
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); return true; }; return false;};
bool mysqlDBC::updateResourceAUX( uint32_t ResID, uint32_t AUX ){ if( m_bIsConnected ) { char tQBuf[MAX_PATH_LEN]; sprintf( tQBuf, "UPDATE `resources` SET `aux_id`=%d WHERE `id`=%d", AUX, ResID );#ifdef DEBUG
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); return true; }; return false;};
//bool mysqlDBC::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 ){
bool mysqlDBC::updateServerUtilisation( DBC_SYS_LOAD_INFO *ptr ){ if( m_bIsConnected ) { char tQBuf[MAX_PATH_LEN]; sprintf( tQBuf, "UPDATE `servers` SET `ts`=UNIX_TIMESTAMP(now()), `cpu_cores`=%d, `stat_cpu1`=%0.2f, `stat_cpu5`=%0.2f, `stat_cpu15`=%0.2f, `stat_mem`=%0.2f, `stat_disk`=%0.2f, `temp0`=%0.1f, `val_mem_tottal`=%" PRIu64 ", `val_mem_current`=%" PRIu64 ", `val_disk_tottal`=%" PRIu64 ", `val_disk_current`=%" PRIu64 " WHERE `id`=%d", ptr->CPU_CORES, ptr->cpu1, ptr->cpu5, ptr->cpu15, ptr->mem, ptr->disk, ptr->temperature, ptr->T_DISK, ptr->C_DISK, ptr->T_MEM, ptr->C_MEM, m_nServerID );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); return true; }; return false;};
uint32_t mysqlDBC::addLocalDCB( uint32_t SiteID, CSTR PATH, CSTR SERIAL, uint8_t CNT, uint32_t status ){ uint32_t RetVal = 0; if( m_bIsConnected ) { char tQBuf[MAX_PATH_LEN]; sprintf( tQBuf, "INSERT INTO modules_dcr SET site_id=%d, status=%d, channels=%d, serial_id='%s' ON DUPLICATE KEY UPDATE status=%d, channels=%d", SiteID, status, CNT, SERIAL, status, CNT );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
uint64_t cid = m_pDatabase->QueryID( tQBuf ); if( cid == 0 ) { AAssoc *result; sprintf( tQBuf, "SELECT id FROM modules_dcr WHERE site_id=%d AND serial_id='%s'", SiteID, SERIAL );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc * cArr; Assoc::iterator it; cArr = result->at(0); it = cArr->find("id"); if( it != cArr->end() ){ cid = atoi( it->second.c_str() ); }; }; deleteResult( result ); }; }; if( cid!= 0 ) { for( uint8_t idx = 0; idx < CNT; idx++ ) { if( status & ( 1 << idx ) ){ sprintf( tQBuf, "INSERT INTO module_dcr_chanels SET dcr_id=%d, channel_id=%d, mode='O', status='C' ON DUPLICATE KEY UPDATE status='C'", (uint32_t) cid, idx ); } else { sprintf( tQBuf, "INSERT INTO module_dcr_chanels SET dcr_id=%d, channel_id=%d, mode='O', status='O' ON DUPLICATE KEY UPDATE status='O'", (uint32_t) cid, idx ); }#ifdef DEBUG_ALL
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); }; }; }; return RetVal;};
uint32_t mysqlDBC::addLocalUART( /*uint32_t NodeID,*/ uint8_t utype, uint32_t speed, uint8_t bit, char parity, float stop_bit, CSTR PATH, uint8_t mode, uint16_t port ){ uint32_t RetVal = 0; if( m_bIsConnected ) { char tQBuf[MAX_PATH_LEN]; sprintf( tQBuf, "INSERT INTO `uart_settings` SET `node_id`=%d, `type`=%d, `speed`=%d, `bit`=%d, `parity`='%c', `stop_bit`=%.1f, `mode`=%d, `port`=%d, `path`='%s' ON DUPLICATE KEY UPDATE `id`=`id`", m_nServerNodeID, utype, speed, bit, parity, stop_bit, mode, port, PATH );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
RetVal = m_pDatabase->QueryID( tQBuf ); if( RetVal == 0 ) { RetVal = getUartID( m_nServerNodeID, utype, PATH ); }; }; return RetVal;};
uint32_t mysqlDBC::addLocalNIF( CSTR device, CSTR mac, NIF_TYPE dtype, NIF_MODE dmode, uint32_t aux_id ){ uint32_t RetVal = 0; if( m_bIsConnected ) { char tQBuf[MAX_PATH_LEN]; char * tKey = MD5String( device ); if( tKey != NULL ) { sprintf( tQBuf, "INSERT INTO `network_interfaces` SET `type`=%d, `key`='%s', `device_name`='%s', `mac`='%s', `mode`=%d, `aux_id`=%d ON DUPLICATE KEY UPDATE `mode`=%d, `aux_id`=%d, `mac`='%s'", dtype, tKey, device, mac, dmode, aux_id, dmode, aux_id, mac );#ifdef DEBUG
LOG(tQBuf);#endif
RetVal = m_pDatabase->QueryID( tQBuf ); if( RetVal == 0 ) { RetVal = getNIF_ID( tKey ); }; free( tKey ); }; }; return RetVal;};
uint32_t mysqlDBC::addLocalWiFi( uint32_t NIF_ID, WIFI_MODE mode, CSTR SSID, CSTR password, WIFI_ENCRIPTION encryption, uint32_t router_id ){ uint32_t RetVal = 0; if( m_bIsConnected ) { char tQBuf[MAX_PATH_LEN]; sprintf( tQBuf, "INSERT INTO `wifis` SET `nif_id`=%d, `mode`=%d, `aux_id`=%d, `SSID`='%s', `password`='%s', `encryption_type`=%d ON DUPLICATE KEY UPDATE `mode`=%d, `aux_id`=%d, `SSID`='%s', `password`='%s', `encryption_type`=%d", NIF_ID, mode, router_id, SSID, password, encryption, mode, router_id, SSID, password, encryption );#ifdef DEBUG
LOG(tQBuf);#endif
RetVal = m_pDatabase->QueryID( tQBuf ); if( RetVal == 0 ) { RetVal = getWiFi_ID( NIF_ID ); }; }; return RetVal;};
uint32_t mysqlDBC::addLRFMask( uint32_t devID, uint8_t lrfID, uint8_t layerID ){ uint32_t RetVal = 0; if( m_bIsConnected ) { char tQBuf[MAX_PATH_LEN]; sprintf( tQBuf, "INSERT INTO `lrf_masks` SET `sensor_id`=%d, `lrf_id`=%d, `layer`=%d ON DUPLICATE KEY UPDATE `id`=`id`", devID, lrfID, layerID );#ifdef DEBUG
LOG(tQBuf);#endif
RetVal = m_pDatabase->QueryID( tQBuf ); if( RetVal == 0 ) { RetVal = getLRFMaskID( devID, lrfID, layerID ); }; }; return RetVal;};
uint32_t mysqlDBC::addLRFMaskPolygone( uint32_t maskID, uint8_t r, uint8_t g, uint8_t b ){ uint32_t RetVal = 0; if( m_bIsConnected ) { char tQBuf[MAX_PATH_LEN]; sprintf( tQBuf, "INSERT INTO `lrf_mask_vertexes` SET `mask_id`=%d, `r`=%d, `g`=%d, `b`=%d", maskID, r, g, b );#ifdef DEBUG
LOG(tQBuf);#endif
RetVal = m_pDatabase->QueryID( tQBuf ); }; return RetVal;};
bool mysqlDBC::addLRFMaskPolygonePoint( uint32_t polyID, int16_t x, int16_t y ){ if( m_bIsConnected ) { char tQBuf[MAX_PATH_LEN]; sprintf( tQBuf, "INSERT INTO `lrf_mask_vertex_points` SET `vertex_id`=%d, `x`=%d, `y`=%d", polyID, x, y );#ifdef DEBUG
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); return true; }; return false;};
uint32_t mysqlDBC::addLocalNetwork( uint32_t NIF_ID, NETWORK_TYPE net_type, CSTR address, CSTR mask, CSTR gateway, CSTR broadcast ){ uint32_t RetVal = 0; if( m_bIsConnected ) { char tQBuf[MAX_PATH_LEN]; sprintf( tQBuf, "INSERT INTO `networks` SET `nif_id`=%d, `type`=%d, `address`='%s', `gateway`='%s', `mask`='%s', `broadcast`='%s' ON DUPLICATE KEY UPDATE `address`='%s', `gateway`='%s', `mask`='%s', `broadcast`='%s'", NIF_ID, net_type, address, gateway, mask, broadcast, address, gateway, mask, broadcast );#ifdef DEBUG
LOG(tQBuf);#endif
RetVal = m_pDatabase->QueryID( tQBuf ); // On Update IF data no need to return ID
//if( RetVal == 0 ) {
// RetVal = getNetworkInterfaceID( tKey );
//};
}; return RetVal;};
uint32_t mysqlDBC::addLocalNetworkInfrastructure( uint32_t NIF_ID, uint32_t OUTBOUND_NIF, bool ena_dhcp, CSTR BRANG, CSTR ERANG, CSTR MASK, CSTR LEASE_TIME ){ uint32_t RetVal = 0; if( m_bIsConnected ) { char tQBuf[MAX_PATH_LEN]; bool ena_routing = true; if( OUTBOUND_NIF == 0 ){ ena_routing = false; }; if( ena_dhcp ){ if ( BRANG == NULL || ERANG == NULL || MASK == NULL || LEASE_TIME == NULL ) { LOG_ERROR("Wrong DHCP parameters to create Network Infrastructure!"); return 0; }; sprintf(tQBuf, "INSERT INTO `network_infrastructure` SET `nif_id`=%d, `enable_routing`=%d, `outbond_nif`=%d, `enable_dhcp`=1, `dhcp_range_begin`='%s', `dhcp_range_end`='%s', `dhcp_range_mask`='%s', `dhcp_lease_time`='%s' ON DUPLICATE KEY UPDATE `enable_routing`=%d, `outbond_nif`=%d, `enable_dhcp`=1, `dhcp_range_begin`='%s', `dhcp_range_end`='%s', `dhcp_range_mask`='%s', `dhcp_lease_time`='%s'", NIF_ID, ena_routing, OUTBOUND_NIF, BRANG, ERANG, MASK, LEASE_TIME, ena_routing, OUTBOUND_NIF, BRANG, ERANG, MASK, LEASE_TIME ); } else { if( ena_routing ){ sprintf(tQBuf, "INSERT INTO `network_infrastructure` SET `nif_id`=%d, `enable_routing`=1, `outbond_nif`=%d ON DUPLICATE KEY UPDATE `enable_routing`=1, `outbond_nif`=%d", NIF_ID, OUTBOUND_NIF, OUTBOUND_NIF ); } else { LOG_ERROR("No Special Service Defined To Network Infrastructure!"); return 0; }; };#ifdef DEBUG_ALL
LOG(tQBuf);#endif
RetVal = m_pDatabase->QueryID( tQBuf ); // On Update IF data no need to return ID
if( RetVal == 0 ) { RetVal = getNetworkInfrastructureID( NIF_ID ); }; }; return RetVal;};/*
bool mysqlDBC::addLRFDraw( uint32_t DBID, uint32_t SIZE, CSTR ID, uint8_t kID, uint8_t type, bool rendered ){ if( m_bIsConnected ) { char tQBuf[MAX_PATH_LEN]; if ( rendered ) { sprintf(tQBuf, "INSERT INTO `lrf_draw` SET `node_id`=%d,`ts`=NOW(),`md5`='%s',`size`=%d, `lrf_id`=%d, `type`=%d, `rendered`='Y' ON DUPLICATE KEY UPDATE `ts`=NOW(),`md5`='%s',`size`=%d, `rendered`='Y'", DBID, ID, SIZE, kID, type, ID, SIZE ); } else { sprintf(tQBuf, "INSERT INTO `lrf_draw` SET `node_id`=%d,`ts`=NOW(),`md5`='%s',`size`=%d, `lrf_id`=%d, `type`=%d ON DUPLICATE KEY UPDATE `ts`=NOW(),`md5`='%s',`size`=%d, `rendered`='N'", DBID, ID, SIZE, kID, type, ID, SIZE ); };#ifdef DEBUG
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); return true; }; return false;}; */ uint32_t mysqlDBC::addEvent( uint32_t SRC, CSTR UUID, uint32_t tss, uint32_t tsms, uint8_t evt_type, uint8_t k_id, uint16_t dig_r, float EL, float AZ, float RANGE, float AREA, float lat, float lon, float alt, uint32_t RefID, CSTR RefUUID ){ uint32_t RetVal = 0; if( m_bIsConnected ) { char tQBuf[MAX_PATH_LEN]; if( RefUUID == NULL ) { sprintf( tQBuf,"INSERT INTO events_archive SET node_id=%d, uuid='%s', ts=%d, ts_ms=%d, evt_type=%d, lrf_id=%d, range_digital=%d, azimuth=%0.6f, elevation=%0.6f, `range`=%0.2f, area=%0.3f, lat=%0.6f, lon=%0.6f, alt=%0.3f", SRC, UUID, tss, tsms, evt_type, k_id, dig_r, AZ, EL, RANGE, AREA, lat, lon, alt ); } else { sprintf( tQBuf,"INSERT INTO events_archive SET node_id=%d, uuid='%s', ts=%d, ts_ms=%d, evt_type=%d, lrf_id=%d, range_digital=%d, azimuth=%0.6f, elevation=%0.6f, `range`=%0.2f, area=%0.3f, lat=%0.6f, lon=%0.6f, alt=%0.3f, ref_uuid='%s'", SRC, UUID, tss, tsms, evt_type, k_id, dig_r, AZ, EL, RANGE, AREA, lat, lon, alt, RefUUID ); };#ifdef DEBUG_ALL
LOG(tQBuf);#endif
RetVal = (uint32_t) m_pDatabase->QueryID( tQBuf ); if( RetVal ) { if (RefUUID == NULL) { sprintf( tQBuf,"INSERT INTO events_cloud SET id=%d, node_id=%d, uuid='%s', ts=%d, ts_ms=%d, evt_type=%d, lrf_id=%d, range_digital=%d, azimuth=%0.6f, elevation=%0.6f, `range`=%0.2f, area=%0.3f, lat=%0.6f, lon=%0.6f, alt=%0.3f", RetVal, SRC, UUID, tss, tsms, evt_type, k_id, dig_r, AZ, EL, RANGE, AREA, lat, lon, alt ); } else { sprintf( tQBuf,"INSERT INTO events_cloud SET id=%d, node_id=%d, uuid='%s', ts=%d, ts_ms=%d, evt_type=%d, lrf_id=%d, range_digital=%d, azimuth=%0.6f, elevation=%0.6f, `range`=%0.2f, area=%0.3f, lat=%0.6f, lon=%0.6f, alt=%0.3f, ref_uuid='%s'", RetVal, SRC, UUID, tss, tsms, evt_type, k_id, dig_r, AZ, EL, RANGE, AREA, lat, lon, alt, RefUUID ); }; m_pDatabase->SilentQuery( tQBuf ); }; // Cleanup Mem Targets Older then 1 Hour
sprintf( tQBuf, "DELETE FROM events_cloud WHERE ts < ( UNIX_TIMESTAMP(NOW()) - 3600 )" ); m_pDatabase->SilentQuery( tQBuf ); }; return RetVal;};
bool mysqlDBC::addDeviceDraw( uint32_t DBID, uint8_t type, uint8_t lrf, void *th_data, uint32_t th_size ){ bool rVal = false; if( th_data != NULL && th_size ){ if( m_bIsConnected ){ CSTR tPData = m_pDatabase->escapeBinary( (uint8_t *) th_data, th_size ); if ( tPData ) { CSTR tQBuf = (CSTR)malloc(BUF_4MB); if( tQBuf ) { sprintf( tQBuf, "DELETE FROM `lrf_draw` WHERE `node_id`=%d AND `lrf_id`=%d AND `type`=%d", DBID, lrf, type ); LOG( tQBuf ); m_pDatabase->SilentQuery( tQBuf ); sprintf( tQBuf, "INSERT INTO lrf_draw(node_id,ts,lrf_id,type,size,data) VALUES(%d,NOW(),%d,%d,%d,'%s')", DBID, lrf, type, th_size, tPData ); m_pDatabase->SilentQuery( tQBuf ); LOG( "Inserted Draw OK!" ); free( tQBuf ); rVal = true; } else { LOG_ERROR("Error Allocating Query Buffer!"); }; free( tPData ); } else { LOG_ERROR( "Error escaping Pic Data!"); }; }; }; return rVal;};
bool mysqlDBC::addVideoEvent( uint32_t evtID, uint32_t videoID, uint32_t clen ){ if( m_bIsConnected ) { char tQBuf[MAX_PATH_LEN]; sprintf( tQBuf, "INSERT INTO `events_2_videos` SET `evt_id`=%d, `video_id`=%d, `frame`=%d", evtID, videoID, clen );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); return true; }; return true;};/*
bool mysqlDBC::addPictureEvent( uint32_t evtID, uint32_t pictureoID ){ if( m_bIsConnected ) { char tQBuf[MAX_PATH_LEN]; sprintf( tQBuf, "INSERT INTO `events_2_pictures` SET `evt_id`=%d, `picture_id`=%d", evtID, pictureoID );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); return true; }; return true;};*/
uint32_t mysqlDBC::addVideoRecord( uint32_t streamID, CSTR md5, CSTR ext, uint32_t ts, uint32_t tsms, uint32_t fps ){ uint32_t tID = 0; if( m_bIsConnected ) { char tQBuf[MAX_PATH_LEN]; sprintf( tQBuf, "INSERT INTO `videos` SET `media_stream_id`=%d, `uts`=%d, `uts_ms`=%d, `md5`='%s', `ext`='%s', `fps`=%d ", streamID, ts, tsms, md5, ext, fps );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
tID = (uint32_t) m_pDatabase->QueryID( tQBuf ); } return tID;};
bool mysqlDBC::addPicture( DBC_SNAPSHOT_DATA *ptr, CSTR ext ){ bool rVal = false; if( ptr != NULL ){ if( m_bIsConnected ){ CSTR tPData = m_pDatabase->escapeBinary( ptr->data, ptr->data_size ); if ( tPData ) { uint32_t pic_id; CSTR tQBuf = (CSTR)malloc(BUF_4MB); if( tQBuf ) { //sprintf( tQBuf, "INSERT INTO `pictures` SET `media_stream_id`=%d, `ts`=NOW(), `md5`='%s', `ext`='%s'",
sprintf( tQBuf, "INSERT INTO pictures(media_stream_id,ts,md5,ext,data) VALUES(%d,NOW(),'%s','%s','%s')", ptr->stream_id, ptr->md5, ext, tPData ); pic_id = (uint32_t) m_pDatabase->QueryID( tQBuf ); if ( pic_id ) { for( DBC_INT_LIST::iterator idx = ptr->assoc_event_ids.begin(); idx < ptr->assoc_event_ids.end(); idx++ ) { sprintf( tQBuf, "INSERT INTO `events_2_pictures` SET `evt_id`=%d, `picture_id`=%d", (*idx), pic_id ); m_pDatabase->SilentQuery( tQBuf ); }; rVal = true; }; free( tQBuf ); } else { LOG_ERROR("Error Allocating Query Buffer!"); }; free( tPData ); } else { LOG_ERROR( "Error escaping Pic Data!"); }; }; }; return rVal;};
bool mysqlDBC::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, uint32_t spikes ){ if( m_bIsConnected ) { char tQBuf[MAX_PATH_LEN]; if( master ) { sprintf( tQBuf, "INSERT INTO `lrf_detection_profiles` SET `aux_id`=%d, `profile_id`=%d, `master`=b'1', `order`=%d, `offset`=%d, `delta`=%d, `flip`=%d, `width`=%d, `sst`=%d, `sun`=%d, `gp`=%d, `spikes`=%d ON DUPLICATE KEY UPDATE `order`=%d, `offset`=%d, `delta`=%d, `flip`=%d, `width`=%d, `sst`=%d, `sun`=%d, `gp`=%d, `spikes`=%d", lrfID, profileID, nOrder, nOffset, nDelta, nFlip, nWidth, bSST, nSun, GP, spikes, nOrder, nOffset, nDelta, nFlip, nWidth, bSST, nSun, GP, spikes ); } else { sprintf( tQBuf, "INSERT INTO `lrf_detection_profiles` SET `aux_id`=%d, `profile_id`=%d, `master`=b'0', `order`=%d, `offset`=%d, `delta`=%d, `flip`=%d, `width`=%d, `sst`=%d, `sun`=%d, `gp`=%d, `spikes`=%d ON DUPLICATE KEY UPDATE `order`=%d, `offset`=%d, `delta`=%d, `flip`=%d, `width`=%d, `sst`=%d, `sun`=%d, `gp`=%d, `spikes`=%d", lrfID, profileID, nOrder, nOffset, nDelta, nFlip, nWidth, bSST, nSun, GP, spikes, nOrder, nOffset, nDelta, nFlip, nWidth, bSST, nSun, GP, spikes ); };#ifdef DEBUG_ALL
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); return true; }; return false;};
bool mysqlDBC::updateLRFSerial( uint32_t lrfID, CSTR Serial ){ if( m_bIsConnected ) { char tQBuf[MAX_PATH_LEN]; CSTR tES = m_pDatabase->escapeString( Serial ); if( tES ) { sprintf( tQBuf, "UPDATE `lrf_sensors` SET `serial`='%s' WHERE `id`=%d", tES, lrfID ); free( tES );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); return true; }; }; return false;};bool mysqlDBC::updateLRFVerison( uint32_t lrfID, CSTR version ){ if( m_bIsConnected ) { char tQBuf[MAX_PATH_LEN]; CSTR tES = m_pDatabase->escapeString( version ); if( tES ) { sprintf( tQBuf, "UPDATE `lrf_sensors` SET `version`='%s' WHERE `id`=%d", tES, lrfID ); free( tES );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); return true; }; }; return false;};
bool mysqlDBC::update3DRuntimeStatus( uint32_t lrfID, ALG_RUN_STATUS *ptr ){ if( m_bIsConnected ) { char tQBuf[MAX_PATH_LEN]; sprintf( tQBuf, "INSERT INTO `lrf_runtime_status` SET `lrf_id`=%d ON DUPLICATE KEY UPDATE `lrf_id`=`lrf_id`", lrfID );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); sprintf( tQBuf, "UPDATE `lrf_runtime_status` SET " "`hw_status`=%d," "`detecting_kernels`=%d," "`th_ready`=%d," "`master_flips`=%d," "`slave_flips`=%d," "`twinc`=%d," "`master_mp_0`=%d," "`master_mp_1`=%d," "`master_mp_2`=%d," "`master_mp_3`=%d," "`master_mp_4`=%d," "`master_mp_5`=%d," "`master_mp_6`=%d," "`master_mp_7`=%d," "`master_gp_0`=%d," "`master_gp_1`=%d," "`master_gp_2`=%d," "`master_gp_3`=%d," "`master_gp_4`=%d," "`master_gp_5`=%d," "`master_gp_6`=%d," "`master_gp_7`=%d," "`master_wp_0`=%d," "`master_wp_1`=%d," "`master_wp_2`=%d," "`master_wp_3`=%d," "`master_wp_4`=%d," "`master_wp_5`=%d," "`master_wp_6`=%d," "`master_wp_7`=%d," "`slave_mp_0`=%d," "`slave_mp_1`=%d," "`slave_mp_2`=%d," "`slave_mp_3`=%d," "`slave_mp_4`=%d," "`slave_mp_5`=%d," "`slave_mp_6`=%d," "`slave_mp_7`=%d," "`slave_gp_0`=%d," "`slave_gp_1`=%d," "`slave_gp_2`=%d," "`slave_gp_3`=%d," "`slave_gp_4`=%d," "`slave_gp_5`=%d," "`slave_gp_6`=%d," "`slave_gp_7`=%d," "`slave_wp_0`=%d," "`slave_wp_1`=%d," "`slave_wp_2`=%d," "`slave_wp_3`=%d," "`slave_wp_4`=%d," "`slave_wp_5`=%d," "`slave_wp_6`=%d," "`slave_wp_7`=%d" " WHERE `lrf_id`=%d", ptr->HW_STATUS, ptr->DETECTING_LRF, ptr->TH_READY, ptr->MASTER_FLIP_CNT, ptr->SLAVE_FLIP_CNT, ptr->TWINC_STATUS, ptr->MASTER_MP[0], ptr->MASTER_MP[1], ptr->MASTER_MP[2], ptr->MASTER_MP[3], ptr->MASTER_MP[4], ptr->MASTER_MP[5], ptr->MASTER_MP[6], ptr->MASTER_MP[7], ptr->MASTER_GP[0], ptr->MASTER_GP[1], ptr->MASTER_GP[2], ptr->MASTER_GP[3], ptr->MASTER_GP[4], ptr->MASTER_GP[5], ptr->MASTER_GP[6], ptr->MASTER_GP[7], ptr->MASTER_WP[0], ptr->MASTER_WP[1], ptr->MASTER_WP[2], ptr->MASTER_WP[3], ptr->MASTER_WP[4], ptr->MASTER_WP[5], ptr->MASTER_WP[6], ptr->MASTER_WP[7], ptr->SLAVE_MP[0], ptr->SLAVE_MP[1], ptr->SLAVE_MP[2], ptr->SLAVE_MP[3], ptr->SLAVE_MP[4], ptr->SLAVE_MP[5], ptr->SLAVE_MP[6], ptr->SLAVE_MP[7], ptr->SLAVE_GP[0], ptr->SLAVE_GP[1], ptr->SLAVE_GP[2], ptr->SLAVE_GP[3], ptr->SLAVE_GP[4], ptr->SLAVE_GP[5], ptr->SLAVE_GP[6], ptr->SLAVE_GP[7], ptr->SLAVE_WP[0], ptr->SLAVE_WP[1], ptr->SLAVE_WP[2], ptr->SLAVE_WP[3], ptr->SLAVE_WP[4], ptr->SLAVE_WP[5], ptr->SLAVE_WP[6], ptr->SLAVE_WP[7], lrfID );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); return true; }; return false;};
bool mysqlDBC::setLRFDataStatus( uint32_t lrfID, uint8_t ST ){ if( m_bIsConnected ) { char tQBuf[MAX_PATH_LEN]; sprintf( tQBuf, "UPDATE `lrf_sensors` SET `data_status`=%d WHERE `id`=%d", ST, lrfID );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); return true; }; return false;};
bool mysqlDBC::setLRFDetectionProfile( uint32_t lrfID, uint8_t profileID ){ if( m_bIsConnected ) { char tQBuf[MAX_PATH_LEN]; sprintf( tQBuf, "UPDATE `lrf_sensors` SET `detection_profile_id`=%d WHERE `id`=%d", profileID, lrfID );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); return true; }; return false;};
bool mysqlDBC::setLRFMaskStatus( uint32_t maskID, bool status ){ if( m_bIsConnected ) { char tQBuf[MAX_PATH_LEN]; char S[2]; if (status ) { S[0] = 'E'; S[1] = (char)0; } else { S[0] = 'D'; S[1] = (char)0; }; sprintf( tQBuf, "UPDATE `lrf_masks` SET `status`='%s' WHERE `id`=%d", S, maskID );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); return true; }; return false;};bool mysqlDBC::setLRFAltSerial( uint32_t lrfID, CSTR Serial ){ if( m_bIsConnected ) { char tQBuf[MAX_PATH_LEN]; sprintf( tQBuf, "UPDATE `lrf_sensors` SET `alt_serial`='%s' WHERE `id`=%d", Serial, lrfID );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); return true; }; return false;};bool mysqlDBC::setLRFAltVerison( uint32_t lrfID, CSTR version ){ if( m_bIsConnected ) { char tQBuf[MAX_PATH_LEN]; sprintf( tQBuf, "UPDATE `lrf_sensors` SET `alt_version`='%s' WHERE `id`=%d", version, lrfID );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); return true; }; return false;};
bool mysqlDBC::setStreamValid( uint32_t streamID, bool status ){ if( m_bIsConnected ) { char tQBuf[MAX_PATH_LEN]; if ( status ) { sprintf(tQBuf, "UPDATE `media_streams` SET `valid`=1 WHERE `id`=%d", streamID); } else { sprintf(tQBuf, "UPDATE `media_streams` SET `valid`=0 WHERE `id`=%d", streamID); };#ifdef DEBUG_ALL
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); return true; }; return false;};
bool mysqlDBC::updateAFPBox( uint32_t filterID, CSTR Tag, float x, float y, float z ){ if( m_bIsConnected ) { char tQBuf[MAX_PATH_LEN]; sprintf( tQBuf, "INSERT INTO `target_filter_apf_boxes` SET `filter_id`=%d, `tag`='%s', `ts`=NOW(), `x`=%0.3f, `y`=%0.3f, `z`=%0.3f ON DUPLICATE KEY UPDATE `ts`=NOW(), `x`=%0.3f, `y`=%0.3f, `z`=%0.3f", filterID, Tag, x,y,z, x,y,z );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
m_pDatabase->SilentQuery( tQBuf ); return true; }; return false;};
DBC_MODULE_EMBED_VIDEO_DATA *mysqlDBC::getEmbedVideoData( uint32_t ID ){ DBC_MODULE_EMBED_VIDEO_DATA *tPtr = NULL; if( m_bIsConnected ) { char tQBuf[MAX_PATH_LEN]; AAssoc *result; sprintf( tQBuf, "SELECT * FROM `module_eve` WHERE `id`=%d", ID );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; tPtr = (DBC_MODULE_EMBED_VIDEO_DATA*)malloc(sizeof(DBC_MODULE_EMBED_VIDEO_DATA)); if( tPtr!= NULL ) { Assoc::iterator it; memset(tPtr,0,sizeof(DBC_MODULE_EMBED_VIDEO_DATA)); cArr = result->at(0); it = cArr->find("output_mode"); if( it != cArr->end() ){ tPtr->output_mode = atoi( it->second.c_str() ); }; it = cArr->find("web_port"); if( it != cArr->end() ){ tPtr->port = atoi( it->second.c_str() ); }; it = cArr->find("width"); if( it != cArr->end() ){ tPtr->width = atoi( it->second.c_str() ); }; it = cArr->find("height"); if( it != cArr->end() ){ tPtr->height = atoi( it->second.c_str() ); }; it = cArr->find("compression_quality"); if( it != cArr->end() ){ tPtr->compression_quality = atoi( it->second.c_str() ); }; it = cArr->find("show_ts"); if( it != cArr->end() ){ tPtr->show_ts = (bool)atoi( it->second.c_str() ); }; it = cArr->find("ts_x"); if( it != cArr->end() ){ tPtr->ts_x = atoi( it->second.c_str() ); }; it = cArr->find("ts_y"); if( it != cArr->end() ){ tPtr->ts_y = atoi( it->second.c_str() ); }; it = cArr->find("ts_font_face"); if( it != cArr->end() ){ tPtr->ts_font_face = atoi( it->second.c_str() ); }; it = cArr->find("ts_font_scale"); if( it != cArr->end() ){ tPtr->ts_font_scale = atof( it->second.c_str() ); }; it = cArr->find("ts_font_thickness"); if( it != cArr->end() ){ tPtr->ts_font_thickness = atoi( it->second.c_str() ); }; it = cArr->find("ts_line_type"); if( it != cArr->end() ){ tPtr->ts_line_type = atoi( it->second.c_str() ); }; it = cArr->find("ts_transperant"); if( it != cArr->end() ){ tPtr->ts_transperant = (bool)atoi( it->second.c_str() ); }; it = cArr->find("show_label"); if( it != cArr->end() ){ tPtr->show_label = (bool)atoi( it->second.c_str() ); }; it = cArr->find("label_x"); if( it != cArr->end() ){ tPtr->label_x = atoi( it->second.c_str() ); }; it = cArr->find("label_y"); if( it != cArr->end() ){ tPtr->label_y = atoi( it->second.c_str() ); }; it = cArr->find("label_font_face"); if( it != cArr->end() ){ tPtr->label_font_face = atoi( it->second.c_str() ); }; it = cArr->find("label_font_scale"); if( it != cArr->end() ){ tPtr->label_font_scale = atof( it->second.c_str() ); }; it = cArr->find("label_font_thickness"); if( it != cArr->end() ){ tPtr->label_font_thickness = atoi( it->second.c_str() ); }; it = cArr->find("label_line_type"); if( it != cArr->end() ){ tPtr->label_line_type = atoi( it->second.c_str() ); }; it = cArr->find("label_transperant"); if( it != cArr->end() ){ tPtr->label_transperant = (bool) atoi( it->second.c_str() ); }; it = cArr->find("show_logo"); if( it != cArr->end() ){ tPtr->show_logo = (bool) atoi( it->second.c_str() ); }; it = cArr->find("logo_w"); if( it != cArr->end() ){ tPtr->logo_w = atoi( it->second.c_str() ); }; it = cArr->find("logo_h"); if( it != cArr->end() ){ tPtr->logo_h = atoi( it->second.c_str() ); }; it = cArr->find("logo_x"); if( it != cArr->end() ){ tPtr->logo_x = atoi( it->second.c_str() ); }; it = cArr->find("logo_y"); if( it != cArr->end() ){ tPtr->logo_y = atoi( it->second.c_str() ); }; it = cArr->find("logo_md5"); if( it != cArr->end() ){ strncpy( tPtr->logo_md5, it->second.c_str(),32); tPtr->logo_md5[32]=(char)0; }; }; }; }; deleteResult( result ); }; return tPtr;};
DBC_EVT_RECORD *mysqlDBC::getEventByUUID( CSTR UUID ){ DBC_EVT_RECORD *tPtr = NULL; if( m_bIsConnected ) { char tQBuf[MAX_PATH_LEN]; AAssoc *result; sprintf( tQBuf, "SELECT * FROM events_cloud WHERE uuid = '%s'", UUID );#ifdef DEBUG_ALL
LOG(tQBuf);#endif
result = m_pDatabase->Query( tQBuf ); if( result!= NULL ) { if( result->size() > 0 ) { Assoc *cArr; tPtr = (DBC_EVT_RECORD*)malloc(sizeof(DBC_EVT_RECORD)); if( tPtr!= NULL ) { Assoc::iterator it; memset(tPtr,0,sizeof(DBC_EVT_RECORD)); cArr = result->at(0); it = cArr->find("id"); if( it != cArr->end() ){ tPtr->id = atoi( it->second.c_str() ); }; it = cArr->find("node_id"); if( it != cArr->end() ){ tPtr->node_id = atoi( it->second.c_str() ); }; it = cArr->find("uuid"); if( it != cArr->end() ){ strncpy( tPtr->uuid, it->second.c_str(),64 ); }; it = cArr->find("ts"); if( it != cArr->end() ){ tPtr->ts_s = atoi( it->second.c_str() ); }; it = cArr->find("ts_ms"); if( it != cArr->end() ){ tPtr->ts_ms = atoi( it->second.c_str() ); }; it = cArr->find("evt_type"); if( it != cArr->end() ){ tPtr->type = atoi( it->second.c_str() ); }; it = cArr->find("range_digital"); if( it != cArr->end() ){ tPtr->range_digital = atoi( it->second.c_str() ); }; it = cArr->find("azimuth"); if( it != cArr->end() ){ tPtr->az = atof( it->second.c_str() ); }; it = cArr->find("elevation"); if( it != cArr->end() ){ tPtr->el = atof( it->second.c_str() ); }; it = cArr->find("range"); if( it != cArr->end() ){ tPtr->ra = atof( it->second.c_str() ); }; it = cArr->find("area"); if( it != cArr->end() ){ tPtr->area = atof( it->second.c_str() ); }; it = cArr->find("lat"); if( it != cArr->end() ){ tPtr->lat = atof( it->second.c_str() ); }; it = cArr->find("lon"); if( it != cArr->end() ){ tPtr->lon = atof( it->second.c_str() ); }; it = cArr->find("alt"); if( it != cArr->end() ){ tPtr->alt = atof( it->second.c_str() ); }; it = cArr->find("ref_id"); if( it != cArr->end() ){ tPtr->ref_id = atoi( it->second.c_str() ); }; it = cArr->find("ref_uuid"); if( it != cArr->end() ){ strncpy( tPtr->ref_uuid, it->second.c_str(),64 ); }; }; }; }; deleteResult( result ); }; return tPtr;};
#undef LOG
#undef LOG_ERROR
|