@ -32,6 +32,7 @@ argusDBC::argusDBC( config_setting_t * Settings ){
m_pLog = basicLogCollection : : getInstance ( ) ;
m_pSettings = basicSettingsProvider : : getInstance ( ) - > getSubNode ( Settings , " DBC " ) ;
m_bIsConnected = false ;
m_nSiteID = 0 ;
m_pDatabase = NULL ;
} ;
@ -88,6 +89,23 @@ bool argusDBC::connect( void ){
return m_bIsConnected ;
} ;
bool argusDBC : : cleanResources ( uint32_t SiteID , uint32_t ServerNodeID , bool all ) {
if ( m_bIsConnected ) {
char tQBuf [ MAX_PATH_LEN ] ;
if ( all ) {
sprintf ( tQBuf , " UPDATE `resources` SET `active`=0 WHERE `site_id`=%d AND `node_id`=%d " , SiteID , ServerNodeID ) ;
} else {
sprintf ( tQBuf , " UPDATE `resources` SET `active`=0 WHERE `site_id`=%d AND `node_id`=%d AND ( `type`=100 OR `type`=101 OR `type`=103 OR `type`=120 ) " , SiteID , ServerNodeID ) ;
} ;
# ifdef DEBUG
LOG ( tQBuf ) ;
# endif
m_pDatabase - > SilentQuery ( tQBuf ) ;
return true ;
} ;
return false ;
} ;
bool argusDBC : : updateIPCam ( uint32_t SiteID , CSTR uuid , CSTR Addr ) {
if ( m_bIsConnected ) {
char tQBuf [ MAX_PATH_LEN ] ;
@ -227,6 +245,60 @@ bool argusDBC::addIPCam( uint32_t SiteID, resultWoWo *tPtr ){
return false ;
} ;
bool argusDBC : : addIPCam ( uint32_t SiteID , OBSERVER_RESULT * tPtr ) {
if ( m_bIsConnected ) {
char tQBuf [ 1024 ] ;
char tIpBuf [ 32 ] ;
char tProto [ 32 ] ;
char tPath [ CTEXT ] ;
char * tPos ;
char * tPos2 ;
# ifdef DEBUG
LOG ( " Add New Camera Record " ) ;
# endif
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
LOG ( tQBuf ) ;
# endif
m_pDatabase - > SilentQuery ( tQBuf ) ;
return true ;
} ;
return false ;
} ;
bool argusDBC : : transferEvtToArchive ( uint32_t SECONDS ) {
if ( m_bIsConnected ) {
if ( SECONDS > 0 ) {
@ -867,6 +939,20 @@ DBC_LRF_DATA *argusDBC::getLRFData( uint32_t ID ){
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 ( " lat " ) ;
if ( it ! = cArr - > end ( ) ) {
tVal - > lat = atof ( it - > second . c_str ( ) ) ;
@ -932,6 +1018,42 @@ DBC_LRF_DATA *argusDBC::getLRFData( uint32_t ID ){
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 ( " 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 ( ) ) ;
} ;
} ;
} ;
} ;
@ -940,6 +1062,59 @@ DBC_LRF_DATA *argusDBC::getLRFData( uint32_t ID ){
return tVal ;
} ;
uint8_t argusDBC : : getLRFDataStatus ( uint32_t ID ) {
uint8_t RetVal = 0 ;
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 ;
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 ;
} ;
uint8_t argusDBC : : getLRFPushedCMD ( uint32_t ID ) {
uint8_t RetVal = 0 ;
if ( m_bIsConnected ) {
char tQBuf [ CTEXT ] ;
AAssoc * result ;
sprintf ( tQBuf , " SELECT `pushed_cmd` 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 ( " pushed_cmd " ) ;
if ( it ! = cArr - > end ( ) ) {
RetVal = atoi ( it - > second . c_str ( ) ) ;
} ;
} ;
} ;
deleteResult ( result ) ;
sprintf ( tQBuf , " UPDATE `lrf_sensors` SET `pushed_cmd`=0 WHERE `id`=%d " , ID ) ;
m_pDatabase - > SilentQuery ( tQBuf ) ;
} ;
return RetVal ;
} ;
DBC_INT_LIST * argusDBC : : listModules ( uint32_t ServerID ) {
DBC_INT_LIST * tVal = NULL ;
if ( m_bIsConnected ) {
@ -947,7 +1122,7 @@ DBC_INT_LIST *argusDBC::listModules( uint32_t ServerID ){
AAssoc * result ;
sprintf ( tQBuf , " SELECT id FROM server_modules WHERE `server_id`=%d AND `enabled`=1 " , ServerID ) ;
# ifdef DEBUG
//LOG(tQBuf);
LOG ( tQBuf ) ;
# endif
result = m_pDatabase - > Query ( tQBuf ) ;
if ( result ! = NULL ) {
@ -1037,6 +1212,69 @@ DBC_INT_LIST *argusDBC::listMediaStreams( uint32_t SiteId, uint32_t MediaServerI
return tVal ;
} ;
DBC_INT_LIST * argusDBC : : 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
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 * argusDBC : : 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
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 * argusDBC : : listSockets ( uint32_t NodeID ) {
DBC_INT_LIST * tVal = NULL ;
if ( m_bIsConnected ) {
@ -1067,6 +1305,43 @@ DBC_INT_LIST *argusDBC::listSockets( uint32_t NodeID ){
} ;
return tVal ;
} ;
*/
DBC_INT_LIST * argusDBC : : 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 " , NodeID ) ;
} else {
sprintf ( tQBuf , " SELECT `id` FROM `resources` WHERE `site_id`=%d AND `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 ;
} ;
DBC_INT_LIST * argusDBC : : listNewModules ( uint32_t ServerID , DBC_INT_LIST * old_ids ) {
DBC_INT_LIST * tVal = NULL ;
@ -1085,7 +1360,7 @@ DBC_INT_LIST *argusDBC::listNewModules( uint32_t ServerID, DBC_INT_LIST * old_id
AAssoc * result ;
sprintf ( tQBuf , " SELECT id FROM server_modules WHERE `server_id`=%d AND `enabled`=1 AND `id` NOT IN (%s) " , ServerID , tParam ) ;
# ifdef DEBUG
//LOG(tQBuf);
LOG ( tQBuf ) ;
# endif
result = m_pDatabase - > Query ( tQBuf ) ;
if ( result ! = NULL ) {
@ -1337,7 +1612,7 @@ DBC_MODULE_DATA *argusDBC::getModuleData( uint32_t ID ){
} ;
return tVal ;
} ;
/*
DBC_SOCKET_DATA * argusDBC : : getSocketData ( uint32_t ID ) {
DBC_SOCKET_DATA * tVal = NULL ;
if ( m_bIsConnected ) {
@ -1345,7 +1620,7 @@ DBC_SOCKET_DATA *argusDBC::getSocketData( uint32_t ID ){
AAssoc * result ;
sprintf ( tQBuf , " SELECT * FROM sockets WHERE `id`=%d " , ID ) ;
# ifdef DEBUG
LOG ( tQBuf ) ;
//LOG(tQBuf);
# endif
result = m_pDatabase - > Query ( tQBuf ) ;
if ( result ! = NULL ) {
@ -1378,6 +1653,7 @@ DBC_SOCKET_DATA *argusDBC::getSocketData( uint32_t ID ){
} ;
return tVal ;
} ;
*/
DBC_MEDIA_STREAM_DATA * argusDBC : : getMediaStreamData ( uint32_t ID ) {
DBC_MEDIA_STREAM_DATA * tVal = NULL ;
@ -1578,10 +1854,12 @@ DBC_MEDIA_SERVER_STREAM_DATA *argusDBC::getMediaServerStreamData( uint32_t ID ){
void argusDBC : : registerServer ( uint32_t SiteID , CSTR identity ) {
if ( m_bIsConnected ) {
m_nSiteID = SiteID ;
char tQBuf [ CTEXT ] ;
sprintf ( tQBuf , " INSERT INTO servers SET `site_id`=%d, `identity`='%s', `online`=1 ON DUPLICATE KEY UPDATE `online`=1 " , SiteID , identity ) ;
# ifdef DEBUG
LOG ( tQBuf ) ;
//LOG(tQBuf);
# endif
m_pDatabase - > SilentQuery ( tQBuf ) ;
@ -1589,34 +1867,35 @@ void argusDBC::registerServer(uint32_t SiteID, CSTR identity ){
// Clenup Nodes and services ...
sprintf ( tQBuf , " UPDATE nodes SET `online`=0 WHERE `site_id`=%d " , SiteID ) ;
# ifdef DEBUG
LOG ( tQBuf ) ;
//LOG(tQBuf);
# endif
m_pDatabase - > SilentQuery ( tQBuf ) ;
sprintf ( tQBuf , " UPDATE cameras SET `online`=0 WHERE `site_id`=%d " , SiteID ) ;
# ifdef DEBUG
LOG ( tQBuf ) ;
//LOG(tQBuf);
# endif
m_pDatabase - > SilentQuery ( tQBuf ) ;
sprintf ( tQBuf , " UPDATE media_streams SET `valid`=0 WHERE `site_id`=%d " , SiteID ) ;
# ifdef DEBUG
LOG ( tQBuf ) ;
//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
LOG ( tQBuf ) ;
//LOG(tQBuf);
# endif
m_pDatabase - > SilentQuery ( tQBuf ) ;
uint32_t sid = getServerID ( identity ) ;
if ( sid ) {
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 " , SiteID , sid ) ;
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_n SiteID, sid ) ;
# ifdef DEBUG
LOG ( tQBuf ) ;
//LOG(tQBuf);
# endif
m_pDatabase - > SilentQuery ( tQBuf ) ;
cleanResources ( m_nSiteID , sid ) ;
} ;
} ;
} ;
@ -1626,47 +1905,116 @@ void argusDBC::unregisterServer(uint32_t ServerID, uint32_t NodeID ){
char tQBuf [ CTEXT ] ;
sprintf ( tQBuf , " UPDATE servers SET `online`=0 WHERE `id` = %d " , ServerID ) ;
# ifdef DEBUG
LOG ( tQBuf ) ;
//LOG(tQBuf);
# endif
m_pDatabase - > SilentQuery ( tQBuf ) ;
setNodeOffline ( NodeID ) ;
} ;
} ;
void argusDBC : : setNodeOnline ( uint32_t NodeID ) {
bool argusDBC : : setNodeOnline ( uint32_t NodeID , uint8_t status ) {
if ( m_bIsConnected ) {
char tQBuf [ CTEXT ] ;
if ( NodeID ) {
sprintf ( tQBuf , " UPDATE nodes SET `online`=1 WHERE `id` = %d " , NodeID ) ;
sprintf ( tQBuf , " UPDATE nodes SET `online`=%d WHERE `id` = %d " , status , NodeID ) ;
# ifdef DEBUG
LOG ( tQBuf ) ;
//LOG(tQBuf);
# endif
m_pDatabase - > SilentQuery ( tQBuf ) ;
//sprintf(tQBuf,"UPDATE sockets SET `state`=1 WHERE `node_id` = %d", NodeID );
sprintf ( tQBuf , " UPDATE `resources` SET `active`=1 WHERE `node_id` = %d " , NodeID ) ;
# ifdef DEBUG
//LOG(tQBuf);
# endif
//m_pDatabase->SilentQuery( tQBuf );
m_pDatabase - > SilentQuery ( tQBuf ) ;
return true ;
} ;
} ;
return false ;
} ;
void argusDBC : : setNodeOffline ( uint32_t NodeID ) {
bool argusDBC : : 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
LOG ( tQBuf ) ;
//LOG(tQBuf);
# endif
m_pDatabase - > SilentQuery ( tQBuf ) ;
//sprintf(tQBuf,"UPDATE sockets SET `state`=0 WHERE `node_id` = %d", NodeID );
sprintf ( tQBuf , " UPDATE `resources` SET `active`=0 WHERE `node_id` = %d " , NodeID ) ;
# ifdef DEBUG
//LOG(tQBuf);
# endif
//m_pDatabase->SilentQuery( tQBuf );
m_pDatabase - > SilentQuery ( tQBuf ) ;
return true ;
} ;
} ;
return false ;
} ;
DBC_RESOURCE_DATA * argusDBC : : 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
//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 argusDBC : : getResourceID ( uint32_t SiteID , 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 `site_id`=%d AND `node_id`=%d AND `type`=%d AND `aux_id`=%d " , SiteID , NodeID , type , auxID ) ;
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 argusDBC : : getServerID ( CSTR identity ) {
@ -1734,16 +2082,15 @@ uint32_t argusDBC::addLocalMediaSource( uint32_t SiteID, CSTR path, uint32_t wid
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
LOG ( tQBuf ) ;
//LOG(tQBuf);
# endif
RetVal = ( uint32_t ) m_pDatabase - > QueryID ( tQBuf ) ;
} ;
} ;
LOG ( " Func Finished " ) ;
return RetVal ;
} ;
/*
uint32_t argusDBC : : 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 ) {
@ -1769,7 +2116,40 @@ uint32_t argusDBC::addNodeSocket( uint32_t NodeID, uint32_t auxID, uint8_t Socke
} ;
return retVal ;
} ;
*/
bool argusDBC : : 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
LOG ( tQBuf ) ;
# endif
m_pDatabase - > SilentQuery ( tQBuf ) ;
return true ;
} ;
return false ;
} ;
uint32_t argusDBC : : addResource ( uint32_t SiteID , uint32_t NodeID , uint8_t type , CSTR devName , uint32_t auxID ) {
uint32_t RetVal = 0 ;
if ( m_bIsConnected ) {
char tQBuf [ 2048 ] ;
CSTR tMD5 = MD5String ( devName ) ;
if ( tMD5 ) {
sprintf ( tQBuf , " INSERT INTO `resources` SET `site_id`=%d, `node_id`=%d, `type`=%d, `md5`='%s', `aux_id`=%d, `device`='%s' ON DUPLICATE KEY UPDATE `active`=1 " , SiteID , NodeID , type , tMD5 , auxID , devName ) ;
free ( tMD5 ) ;
# ifdef DEBUG
//LOG(tQBuf);
# endif
RetVal = ( uint32_t ) m_pDatabase - > QueryID ( tQBuf ) ;
if ( RetVal = = 0 ) {
RetVal = getResourceID ( SiteID , NodeID , type , auxID ) ;
} ;
} ;
} ;
return RetVal ;
} ;
/*
uint32_t argusDBC : : getNodeSocketID ( uint32_t NodeID , uint32_t auxID , uint8_t SocketType , CSTR path ) {
uint32_t retVal = 0 ;
if ( m_bIsConnected ) {
@ -1801,20 +2181,19 @@ uint32_t argusDBC::getNodeSocketID( uint32_t NodeID, uint32_t auxID, uint8_t So
} ;
return retVal ;
} ;
*/
CSTR argusDBC : : getNodeIP4 ( uint32_t NodeID ) {
return getSocketNam e ( NodeID , ARGUS_NODE_SOCK_TYP E_NETWORK_IPV4 ) ;
return getResourceDevic e ( NodeID , ARGUS_HARDWAR E_NETWORK_IPV4 ) ;
} ;
CSTR argusDBC : : getNodeIP6 ( uint32_t NodeID ) {
return getSocketNam e ( NodeID , ARGUS_NODE_SOCK_TYP E_NETWORK_IPV6 ) ;
return getResourceDevic e ( NodeID , ARGUS_HARDWAR E_NETWORK_IPV6 ) ;
} ;
CSTR argusDBC : : getSocketPath ( uint32_t NodeID , uint32_t Type ) {
CSTR argusDBC : : getResourceDevice ( uint32_t NodeID , uint32_t Type ) {
if ( m_bIsConnected ) {
char tQBuf [ CTEXT ] ;
sprintf ( tQBuf , " SELECT `path` FROM `sockets` WHERE `node_id`=%d AND `type`=%d LIMIT 1 " ,
NodeID , Type ) ;
sprintf ( tQBuf , " SELECT `device` FROM `resources` WHERE `node_id`=%d AND `type`=%d LIMIT 1 " , NodeID , Type ) ;
# ifdef DEBUG
LOG ( tQBuf ) ;
# endif
@ -1836,7 +2215,7 @@ CSTR argusDBC::getSocketPath( uint32_t NodeID, uint32_t Type ){
} ;
return NULL ;
} ;
/*
CSTR argusDBC : : getSocketName ( uint32_t NodeID , uint32_t Type ) {
if ( m_bIsConnected ) {
char tQBuf [ CTEXT ] ;
@ -1863,7 +2242,7 @@ CSTR argusDBC::getSocketName( uint32_t NodeID, uint32_t Type ){
} ;
return NULL ;
} ;
*/
KAFKA_SETTINGS * argusDBC : : getSettingsKAFKA ( uint32_t ModuleID ) {
KAFKA_SETTINGS * tVal = NULL ;
if ( m_bIsConnected ) {
@ -1980,6 +2359,29 @@ DBC_UART_DATA *argusDBC::getUartData( uint32_t UartID ){
return tVal ;
} ;
uint32_t argusDBC : : getUartID ( uint32_t RessourceID ) {
uint32_t RetVal = 0 ;
if ( m_bIsConnected ) {
char tQBuf [ CTEXT ] ;
sprintf ( tQBuf , " SELECT `id` FROM `uart_settings` WHERE `resource_id`=%d " , RessourceID ) ;
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 argusDBC : : updateMediaServerStream ( uint32_t id , CSTR mrl , CSTR key ) {
if ( m_bIsConnected ) {
char tQBuf [ MAX_PATH_LEN ] ;
@ -2008,10 +2410,23 @@ bool argusDBC::updateMediaServerStream( uint32_t id, CSTR mrl, CSTR key ){
return false ;
} ;
bool argusDBC : : addLocalDCB ( uint32_t SiteID , CSTR PATH , CSTR SERIAL , uint8_t CNT , uint32_t status ) {
bool argusDBC : : 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 ;
} ;
uint32_t argusDBC : : 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 ] ;
LOG ( " Before Sff " ) ;
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 ,
@ -2021,7 +2436,7 @@ LOG("Before Sff");
CNT
) ;
# ifdef DEBUG
LOG ( tQBuf ) ;
//LOG(tQBuf);
# endif
uint64_t cid = m_pDatabase - > QueryID ( tQBuf ) ;
if ( cid = = 0 ) {
@ -2031,7 +2446,7 @@ LOG("Before Sff");
SERIAL
) ;
# ifdef DEBUG
LOG ( tQBuf ) ;
//LOG(tQBuf);
# endif
result = m_pDatabase - > Query ( tQBuf ) ;
if ( result ! = NULL ) {
@ -2061,19 +2476,45 @@ LOG("Before Sff");
) ;
}
# ifdef DEBUG
LOG ( tQBuf ) ;
//LOG(tQBuf);
# endif
m_pDatabase - > SilentQuery ( tQBuf ) ;
} ;
} ;
return true ;
} ;
return false ;
return RetVal ;
} ;
uint32_t argusDBC : : addLocalUART ( uint32_t ResID , 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 `resource_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` " ,
ResID ,
utype ,
speed ,
bit ,
parity ,
stop_bit ,
mode ,
port ,
PATH
) ;
# ifdef DEBUG
//LOG(tQBuf);
# endif
RetVal = m_pDatabase - > QueryID ( tQBuf ) ;
if ( RetVal = = 0 ) {
RetVal = getUartID ( ResID ) ;
} ;
} ;
return RetVal ;
} ;
bool argusDBC : : addDraw ( uint32_t DBID , uint16_t SIZE , CSTR ID ) {
if ( m_bIsConnected ) {
char tQBuf [ MAX_PATH_LEN ] ;
sprintf ( tQBuf , " INSERT INTO `lrf_draw` SET `node_id`=%d,`ts`=NOW(),`md5`='%s',`size`=%d ON DUPLICATE KEY UPDATE `ts`=NOW(),`md5`='%s',`size`=%d " ,
sprintf ( tQBuf , " INSERT INTO `lrf_draw` SET `node_id`=%d,`ts`=NOW(),`md5`='%s',`size`=%d ON DUPLICATE KEY UPDATE `ts`=NOW(),`md5`='%s',`size`=%d, `rendered`='N' " ,
DBID ,
ID ,
SIZE ,
@ -2081,7 +2522,7 @@ bool argusDBC::addDraw( uint32_t DBID, uint16_t SIZE, CSTR ID ){
SIZE
) ;
# ifdef DEBUG
LOG ( tQBuf ) ;
//LOG(tQBuf);
# endif
m_pDatabase - > SilentQuery ( tQBuf ) ;
return true ;
@ -2203,18 +2644,37 @@ bool argusDBC::updateCommand( uint32_t CMD_ID, uint8_t STATUS ){
return false ;
} ;
bool argusDBC : : updateMasterDetectorLRF ( uint32_t lrf_id , uint16_t nOrder , uint16_t nOffset , uint16_t nDelta , uint16_t nWidth , uint16_t nFlip , uint16_t nSun , uint8_t bSST ) {
bool argusDBC : : 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 ] ;
sprintf ( tQBuf , " UPDATE `lrf_sensors` SET `m_order`=%d, `m_offset`=%d, `m_delta`=%d, `m_flip`=%d, `m_width`=%d, `m_sst`=%d, `m_sun`=%d WHERE id=%d " ,
nOrder ,
nOffset ,
nDelta ,
nFlip ,
nWidth ,
bSST ,
nSun ,
lrf_id ) ;
if ( master ) {
sprintf ( tQBuf , " UPDATE `lrf_detection_profiles` SET `order`=%d, `offset`=%d, `delta`=%d, `flip`=%d, `width`=%d, `sst`=%d, `sun`=%d, `gp`=%d, `spikes`=%d WHERE `aux_id`=%d AND `profile_id`=%d AND `master`=b'1' " ,
nOrder ,
nOffset ,
nDelta ,
nFlip ,
nWidth ,
bSST ,
nSun ,
GP ,
spikes ,
lrfID ,
profileID ) ;
} else {
sprintf ( tQBuf , " UPDATE `lrf_detection_profiles` SET `order`=%d, `offset`=%d, `delta`=%d, `flip`=%d, `width`=%d, `sst`=%d, `sun`=%d, `gp`=%d, `spikes`=%d WHERE `aux_id`=%d AND `profile_id`=%d AND `master`=b'0' " ,
nOrder ,
nOffset ,
nDelta ,
nFlip ,
nWidth ,
bSST ,
nSun ,
GP ,
spikes ,
lrfID ,
profileID ) ;
} ;
# ifdef DEBUG
LOG ( tQBuf ) ;
# endif
@ -2224,20 +2684,82 @@ bool argusDBC::updateMasterDetectorLRF( uint32_t lrf_id, uint16_t nOrder, uint16
return false ;
} ;
bool argusDBC : : updateSlaveDetectorLRF ( uint32_t lrf_id , uint16_t nOrder , uint16_t nOffset , uint16_t nDelta , uint16_t nWidth , uint16_t nFlip , uint16_t nSun , uint8_t bSST ) {
bool argusDBC : : updateLRFSerial ( uint32_t lrfID , CSTR Serial ) {
if ( m_bIsConnected ) {
char tQBuf [ MAX_PATH_LEN ] ;
sprintf ( tQBuf , " UPDATE `lrf_sensors` SET `s_order`=%d, `s_offset`=%d, `s_delta`=%d, `s_flip`=%d, `s_width`=%d, `s_sst`=%d, `s_sun`=%d WHERE id=%d " ,
nOrder ,
nOffset ,
nDelta ,
nFlip ,
nWidth ,
bSST ,
nSun ,
lrf_id ) ;
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
LOG ( tQBuf ) ;
LOG ( tQBuf ) ;
# endif
m_pDatabase - > SilentQuery ( tQBuf ) ;
return true ;
} ;
} ;
return false ;
} ;
bool argusDBC : : 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
LOG ( tQBuf ) ;
# endif
m_pDatabase - > SilentQuery ( tQBuf ) ;
return true ;
} ;
} ;
return false ;
} ;
bool argusDBC : : 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
LOG ( tQBuf ) ;
# endif
m_pDatabase - > SilentQuery ( tQBuf ) ;
return true ;
} ;
return false ;
} ;
bool argusDBC : : 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
LOG ( tQBuf ) ;
# endif
m_pDatabase - > SilentQuery ( tQBuf ) ;
return true ;
} ;
return false ;
} ;
bool argusDBC : : 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
LOG ( tQBuf ) ;
# endif
m_pDatabase - > SilentQuery ( tQBuf ) ;
return true ;
} ;
return false ;
} ;
bool argusDBC : : 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
LOG ( tQBuf ) ;
# endif
m_pDatabase - > SilentQuery ( tQBuf ) ;
return true ;