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

2358 lines
86 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
5 years ago
​
5 years ago
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
5 years ago
​
5 years ago
​
5 years ago
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "rgooseDBConnector.h"
  2. #define LOG( X ) m_pLog->Log( "ADBC", this, X )
  3. #ifdef DEBUG
  4. #define LOG_ERROR( X ) {\
  5. char _tBfrErrMSG2w34[256];\
  6. sprintf( _tBfrErrMSG2w34, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
  7. m_pLog->Log( "ADBC", this, _LOG_ERROR, _tBfrErrMSG2w34 );\
  8. }
  9. #else
  10. #define LOG_ERROR( X ) m_pLog->Log( "ADBC", this, _LOG_ERROR, X );
  11. #endif
  12. argusDBC *argusDBC::_instance = NULL;
  13. /**
  14. * Returns the single instance of the object.
  15. */
  16. argusDBC* argusDBC::getInstance( config_setting_t * Settings ) {
  17. // check if the instance has been created yet
  18. if( 0 == _instance ){
  19. // if not, then create it
  20. _instance = new argusDBC( Settings );
  21. };
  22. // return the single instance
  23. return _instance;
  24. };
  25. argusDBC::argusDBC( config_setting_t * Settings ){
  26. m_pLog = basicLogCollection::getInstance();
  27. m_pSettings = basicSettingsProvider::getInstance()->getSubNode( Settings, "DBC" );
  28. m_bIsConnected = false;
  29. m_pDatabase = NULL;
  30. };
  31. argusDBC::~argusDBC(){
  32. m_bIsConnected = false;
  33. if( m_pDatabase != NULL ) delete( m_pDatabase );
  34. m_pDatabase = NULL;
  35. _instance = NULL;
  36. };
  37. bool argusDBC::connect( void ){
  38. config_setting_t * tSetting;
  39. m_bIsConnected = false;
  40. if( m_pSettings!= NULL ) {
  41. tSetting = config_setting_get_member( m_pSettings, "DATABASE_HOST" );
  42. if( tSetting == NULL ){
  43. tSetting = config_setting_add(m_pSettings, "DATABASE_HOST", CONFIG_TYPE_STRING );
  44. config_setting_set_string( tSetting, "localhost" );
  45. basicSettingsProvider::getInstance()->compromise();
  46. LOG("No DB Host Setting! Using default!");
  47. };
  48. sprintf(m_pDbHost, "%s", config_setting_get_string(tSetting));
  49. tSetting = config_setting_get_member( m_pSettings, "DATABASE_NAME" );
  50. if( tSetting == NULL ){
  51. tSetting = config_setting_add(m_pSettings, "DATABASE_NAME", CONFIG_TYPE_STRING );
  52. config_setting_set_string( tSetting, "dfsl_gunter" );
  53. basicSettingsProvider::getInstance()->compromise();
  54. LOG("No DB Database Setting! Using default!");
  55. };
  56. sprintf(m_pDbDatabase, "%s", config_setting_get_string(tSetting));
  57. tSetting = config_setting_get_member( m_pSettings, "DATABASE_USER" );
  58. if( tSetting == NULL ){
  59. tSetting = config_setting_add(m_pSettings, "DATABASE_USER", CONFIG_TYPE_STRING );
  60. config_setting_set_string( tSetting, "dbroot" );
  61. basicSettingsProvider::getInstance()->compromise();
  62. LOG("No DB User Setting! Using default!");
  63. };
  64. sprintf(m_pDbUsername, "%s", config_setting_get_string(tSetting));
  65. tSetting = config_setting_get_member( m_pSettings, "DATABASE_PASSWORD" );
  66. if( tSetting == NULL ){
  67. tSetting = config_setting_add(m_pSettings, "DATABASE_PASSWORD", CONFIG_TYPE_STRING );
  68. config_setting_set_string( tSetting, "123567" );
  69. basicSettingsProvider::getInstance()->compromise();
  70. LOG("No DB Password Setting! Using default!");
  71. };
  72. sprintf(m_pDbPassword, "%s", config_setting_get_string(tSetting));
  73. basicSettingsProvider::getInstance()->validate();
  74. m_pDatabase = new MySQL_Connector();
  75. if( m_pDatabase == NULL )return false;
  76. m_bIsConnected = m_pDatabase->Connect( m_pDbDatabase, m_pDbHost, m_pDbUsername, m_pDbPassword );
  77. } else {
  78. LOG_ERROR("No Settings Provided!");
  79. };
  80. return m_bIsConnected;
  81. };
  82. bool argusDBC::updateIPCam( uint32_t SiteID, CSTR uuid, CSTR Addr ){
  83. if(m_bIsConnected) {
  84. char tQBuf[MAX_PATH_LEN];
  85. char tIpBuf[CTEXT];
  86. char *tPos;
  87. char *tPos2;
  88. #ifdef DEBUG
  89. LOG("Cam Update");
  90. #endif
  91. tPos = strstr(Addr,"//");
  92. if( tPos != NULL ) {
  93. tPos2 = strstr( tPos + 2,"/");
  94. if( tPos2 != NULL ) {
  95. int len;
  96. len = tPos2 - tPos - 2;
  97. strncpy(tIpBuf,tPos + 2,len);
  98. tIpBuf[len] = (char)0;
  99. } else {
  100. LOG_ERROR("Pos 2 - err");
  101. tIpBuf[0] = (char)0;
  102. };
  103. } else {
  104. LOG_ERROR("Pos 0 - err");
  105. tIpBuf[0] = (char)0;
  106. };
  107. sprintf(tQBuf,"UPDATE cameras SET `online`=1,`onvif_ctrl`='%s', `ip`='%s' WHERE `uuid`='%s' AND `site_id`=%d",
  108. Addr,
  109. tIpBuf,
  110. uuid,
  111. SiteID
  112. );
  113. #ifdef DEBUG
  114. LOG(tQBuf);
  115. #endif
  116. m_pDatabase->SilentQuery( tQBuf );
  117. return true;
  118. };
  119. return false;
  120. };
  121. bool argusDBC::updateIPCam( uint32_t SiteID, uint32_t CamID, CSTR Addr ){
  122. if(m_bIsConnected) {
  123. char tQBuf[MAX_PATH_LEN];
  124. char tIpBuf[CTEXT];
  125. char *tPos;
  126. char *tPos2;
  127. #ifdef DEBUG
  128. LOG("Cam Update");
  129. #endif
  130. tPos = strstr(Addr,"//");
  131. if( tPos != NULL ) {
  132. tPos2 = strstr( tPos + 2,"/");
  133. if( tPos2 != NULL ) {
  134. int len;
  135. len = tPos2 - tPos - 2;
  136. strncpy(tIpBuf,tPos + 2,len);
  137. tIpBuf[len] = (char)0;
  138. } else {
  139. LOG_ERROR("Pos 2 - err");
  140. tIpBuf[0] = (char)0;
  141. };
  142. } else {
  143. LOG_ERROR("Pos 0 - err");
  144. tIpBuf[0] = (char)0;
  145. };
  146. sprintf(tQBuf,"UPDATE cameras SET `online`=1, `onvif_ctrl`='%s', `ip`='%s' WHERE id=%d AND `site_id`=%d",
  147. Addr,
  148. tIpBuf,
  149. CamID,
  150. SiteID
  151. );
  152. #ifdef DEBUG
  153. LOG(tQBuf);
  154. #endif
  155. m_pDatabase->SilentQuery( tQBuf );
  156. sprintf(tQBuf,"UPDATE media_streams SET `valid`=1 WHERE source_id=%d AND source_type='D'", CamID );
  157. #ifdef DEBUG
  158. LOG(tQBuf);
  159. #endif
  160. m_pDatabase->SilentQuery( tQBuf );
  161. return true;
  162. };
  163. return false;
  164. };
  165. bool argusDBC::addIPCam( uint32_t SiteID, resultWoWo *tPtr ){
  166. if(m_bIsConnected) {
  167. char tQBuf[1024];
  168. char tIpBuf[32];
  169. char tProto[32];
  170. char tPath[CTEXT];
  171. char *tPos;
  172. char *tPos2;
  173. #ifdef DEBUG
  174. LOG("Add New Camera Record");
  175. #endif
  176. memcpy( tProto, tPtr->XAddrs, 5 );
  177. tProto[5] = (char)0;
  178. if( tProto[4] == ':') tProto[4] = (char)0;
  179. memset( tPath, 0, CTEXT );
  180. tPos = strstr(tPtr->XAddrs,"//");
  181. if( tPos != NULL ) {
  182. tPos2 = strstr( tPos + 2,"/");
  183. if( tPos2 != NULL ) {
  184. int len,len2,len3;
  185. len = tPos2 - tPos - 2;
  186. strncpy( tIpBuf, tPos + 2, len);
  187. tIpBuf[len] = (char)0;
  188. strncpy( tPath, tPos + 2 + len, CTEXT );
  189. } else {
  190. LOG_ERROR("Pos 2 - err");
  191. tIpBuf[0] = (char)0;
  192. };
  193. } else {
  194. LOG_ERROR("Pos 0 - err");
  195. tIpBuf[0] = (char)0;
  196. };
  197. 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'",
  198. tPtr->RefID,
  199. //tPtr->XAddrs,
  200. tPath,
  201. tIpBuf,
  202. SiteID,
  203. tPtr->MAC,
  204. tPtr->Hardware,
  205. tPtr->Name,
  206. tProto,
  207. //tPtr->XAddrs,
  208. tIpBuf
  209. );
  210. #ifdef DEBUG
  211. LOG(tQBuf);
  212. #endif
  213. m_pDatabase->SilentQuery( tQBuf );
  214. return true;
  215. };
  216. return false;
  217. };
  218. bool argusDBC::transferEvtToArchive( uint32_t SECONDS ){
  219. if(m_bIsConnected) {
  220. if( SECONDS > 0 ) {
  221. char tQBuf[CTEXT];
  222. 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 );
  223. m_pDatabase->SilentQuery( tQBuf );
  224. return true;
  225. };
  226. };
  227. return false;
  228. }
  229. bool argusDBC::getLastEvents( vectorEventRecords &VR, uint32_t tss, uint32_t tsms ){
  230. if(m_bIsConnected){
  231. char tQBuf[CTEXT];
  232. AAssoc *result;
  233. sprintf(tQBuf, "SELECT * FROM events_cloud WHERE `ts`>%d AND `ts_ms`>%d", tss, tsms );
  234. result = m_pDatabase->Query( tQBuf );
  235. if( result!= NULL ) {
  236. DBC_EVT_DATA *tPtr;
  237. Assoc *cArr;
  238. for(int i=0;i<result->size();i++) {
  239. cArr = result->at(i);
  240. tPtr = (DBC_EVT_DATA*)malloc(sizeof(DBC_EVT_DATA));
  241. if( tPtr!= NULL ) {
  242. Assoc::iterator it;
  243. memset(tPtr,0,sizeof(DBC_EVT_DATA));
  244. it = cArr->find("id");
  245. if( it != cArr->end() ){
  246. tPtr->id = atoi( it->second.c_str() );
  247. };
  248. it = cArr->find("node_id");
  249. if( it != cArr->end() ){
  250. tPtr->node_id = atoi( it->second.c_str() );
  251. };
  252. it = cArr->find("uuid");
  253. if( it != cArr->end() ){
  254. strncpy( tPtr->uuid, it->second.c_str(),64 );
  255. };
  256. it = cArr->find("ts");
  257. if( it != cArr->end() ){
  258. tPtr->ts_s = atoi( it->second.c_str() );
  259. };
  260. it = cArr->find("ts_ms");
  261. if( it != cArr->end() ){
  262. tPtr->ts_ms = atoi( it->second.c_str() );
  263. };
  264. it = cArr->find("evt_type");
  265. if( it != cArr->end() ){
  266. tPtr->type = atoi( it->second.c_str() );
  267. };
  268. it = cArr->find("range_digital");
  269. if( it != cArr->end() ){
  270. tPtr->range_digital = atoi( it->second.c_str() );
  271. };
  272. it = cArr->find("azimuth");
  273. if( it != cArr->end() ){
  274. tPtr->az = atof( it->second.c_str() );
  275. };
  276. it = cArr->find("elevation");
  277. if( it != cArr->end() ){
  278. tPtr->el = atof( it->second.c_str() );
  279. };
  280. it = cArr->find("range");
  281. if( it != cArr->end() ){
  282. tPtr->ra = atof( it->second.c_str() );
  283. };
  284. it = cArr->find("area");
  285. if( it != cArr->end() ){
  286. tPtr->area = atof( it->second.c_str() );
  287. };
  288. it = cArr->find("lat");
  289. if( it != cArr->end() ){
  290. tPtr->lat = atof( it->second.c_str() );
  291. };
  292. it = cArr->find("lon");
  293. if( it != cArr->end() ){
  294. tPtr->lon = atof( it->second.c_str() );
  295. };
  296. it = cArr->find("alt");
  297. if( it != cArr->end() ){
  298. tPtr->alt = atof( it->second.c_str() );
  299. };
  300. it = cArr->find("ref_uuid");
  301. if( it != cArr->end() ){
  302. strncpy( tPtr->uuid, it->second.c_str(),64 );
  303. };
  304. char tBuf[CLOG];
  305. sprintf(tBuf,"Evt: %d %d %d", tPtr->type, tPtr->ts_s, tPtr->ts_ms );
  306. LOG(tBuf);
  307. VR.push_back(tPtr);
  308. };
  309. };
  310. };
  311. deleteResult( result );
  312. if( m_pDatabase->isConnected()) return true;
  313. };
  314. return false;
  315. };
  316. bool argusDBC::getAllCamRecords( uint32_t SiteID, vectorCamRecords &VR ){
  317. if(m_bIsConnected){
  318. char tQBuf[CTEXT];
  319. AAssoc *result;
  320. sprintf(tQBuf, "SELECT * FROM cameras WHERE `site_id`=%d AND `type`=2 AND `status`=2", SiteID );
  321. #ifdef DEBUG
  322. LOG(tQBuf);
  323. #endif
  324. result = m_pDatabase->Query( tQBuf );
  325. if( result!= NULL ) {
  326. DBC_CAM_DATA *tVal;
  327. Assoc *cArr;
  328. for(int i=0;i<result->size();i++) {
  329. LOG("Cam_Record!");
  330. cArr = result->at(i);
  331. tVal = (DBC_CAM_DATA*)malloc(sizeof(DBC_CAM_DATA));
  332. if( tVal!= NULL ) {
  333. Assoc::iterator it;
  334. memset(tVal,0,sizeof(DBC_CAM_DATA));
  335. it = cArr->find("id");
  336. if( it != cArr->end() ){
  337. tVal->id = atoi( it->second.c_str() );
  338. };
  339. it = cArr->find("site_id");
  340. if( it != cArr->end() ){
  341. tVal->site_id = atoi( it->second.c_str() );
  342. };
  343. it = cArr->find("node_id");
  344. if( it != cArr->end() ){
  345. tVal->node_id = atoi( it->second.c_str() );
  346. };
  347. it = cArr->find("online");
  348. if( it != cArr->end() ){
  349. tVal->online = (bool) atoi( it->second.c_str() );
  350. };
  351. it = cArr->find("type");
  352. if( it != cArr->end() ){
  353. tVal->type = atoi( it->second.c_str() );
  354. };
  355. it = cArr->find("name");
  356. if( it != cArr->end() ){
  357. strncpy( tVal->name, it->second.c_str(), 64 );
  358. };
  359. it = cArr->find("hardware");
  360. if( it != cArr->end() ){
  361. strncpy( tVal->hardware, it->second.c_str(), 32 );
  362. };
  363. it = cArr->find("status");
  364. if( it != cArr->end() ){
  365. tVal->status = atoi( it->second.c_str() );
  366. };
  367. it = cArr->find("session");
  368. if( it != cArr->end() ){
  369. strncpy( tVal->session, it->second.c_str(), 32 );
  370. };
  371. it = cArr->find("protocol");
  372. if( it != cArr->end() ){
  373. tVal->protocol = atoi( it->second.c_str() );
  374. };
  375. it = cArr->find("protocol_aux");
  376. if( it != cArr->end() ){
  377. strncpy( tVal->protocol_aux, it->second.c_str(), 64 );
  378. };
  379. it = cArr->find("lat");
  380. if( it != cArr->end() ){
  381. tVal->lat = atof( it->second.c_str() );
  382. };
  383. it = cArr->find("lon");
  384. if( it != cArr->end() ){
  385. tVal->lon = atof( it->second.c_str() );
  386. };
  387. it = cArr->find("alt");
  388. if( it != cArr->end() ){
  389. tVal->alt = atof( it->second.c_str() );
  390. };
  391. it = cArr->find("picth");
  392. if( it != cArr->end() ){
  393. tVal->pitch = atof( it->second.c_str() );
  394. };
  395. it = cArr->find("roll");
  396. if( it != cArr->end() ){
  397. tVal->roll = atof( it->second.c_str() );
  398. };
  399. it = cArr->find("yaw");
  400. if( it != cArr->end() ){
  401. tVal->yaw = atof( it->second.c_str() );
  402. };
  403. it = cArr->find("imager_type");
  404. if( it != cArr->end() ){
  405. tVal->imager_type = atoi( it->second.c_str() );
  406. };
  407. it = cArr->find("min_f");
  408. if( it != cArr->end() ){
  409. tVal->min_f = atof( it->second.c_str() );
  410. };
  411. it = cArr->find("max_f");
  412. if( it != cArr->end() ){
  413. tVal->max_f = atof( it->second.c_str() );
  414. };
  415. it = cArr->find("access_login");
  416. if( it != cArr->end() ){
  417. strncpy( tVal->username, it->second.c_str(), 16 );
  418. };
  419. it = cArr->find("access_pass");
  420. if( it != cArr->end() ){
  421. strncpy( tVal->password, it->second.c_str(), 16 );
  422. };
  423. it = cArr->find("uuid");
  424. if( it != cArr->end() ){
  425. strncpy( tVal->uuid, it->second.c_str(), CLOG );
  426. };
  427. it = cArr->find("mac");
  428. if( it != cArr->end() ){
  429. strncpy( tVal->mac, it->second.c_str(), 16 );
  430. };
  431. it = cArr->find("ip");
  432. if( it != cArr->end() ){
  433. strncpy( tVal->ip, it->second.c_str(), 16 );
  434. };
  435. it = cArr->find("port");
  436. if( it != cArr->end() ){
  437. tVal->port = atoi( it->second.c_str() );
  438. };
  439. it = cArr->find("onvif_access");
  440. if( it != cArr->end() ){
  441. strncpy( tVal->onvif_access, it->second.c_str(), 5);
  442. };
  443. it = cArr->find("onvif_ctrl");
  444. if( it != cArr->end() ){
  445. strncpy( tVal->onvif_ctrl, it->second.c_str(), 250);
  446. };
  447. it = cArr->find("ptz_token");
  448. if( it != cArr->end() ){
  449. strncpy( tVal->ptz_token, it->second.c_str(), 64);
  450. };
  451. VR.push_back(tVal);
  452. };
  453. //??
  454. //delete(cArr);
  455. };
  456. };
  457. deleteResult( result );
  458. #ifdef DEBUG
  459. sprintf( tQBuf,"Now %d Camera Records in System", VR.size());
  460. LOG(tQBuf);
  461. #endif
  462. if( m_pDatabase->isConnected()) return true;
  463. };
  464. return false;
  465. };
  466. DBC_INT_LIST *argusDBC::listNodes( uint32_t SiteID ){
  467. DBC_INT_LIST * tVal = NULL;
  468. if(m_bIsConnected){
  469. char tQBuf[CTEXT];
  470. AAssoc *result;
  471. sprintf(tQBuf, "SELECT id FROM nodes WHERE `site_id`=%d AND `type` > 0", SiteID );
  472. #ifdef DEBUG
  473. //LOG(tQBuf);
  474. #endif
  475. result = m_pDatabase->Query( tQBuf );
  476. if( result!= NULL ) {
  477. if( result->size() > 0 ) {
  478. Assoc *cArr;
  479. tVal = new DBC_INT_LIST();
  480. if( tVal != NULL ) {
  481. Assoc::iterator it;
  482. for(int i=0;i<result->size();i++) {
  483. cArr = result->at(i);
  484. it = cArr->find("id");
  485. if( it != cArr->end() ){
  486. tVal->push_back( atoi( it->second.c_str() ));
  487. };
  488. };
  489. };
  490. };
  491. };
  492. deleteResult( result );
  493. };
  494. return tVal;
  495. };
  496. DBC_INT_LIST *argusDBC::listNewNodes( uint32_t SiteID, DBC_INT_LIST *old_ids ){
  497. DBC_INT_LIST * tVal = NULL;
  498. char tParam[CTEXT];
  499. //memset( tParam, 0, CTEXT );
  500. sprintf(tParam,"0");
  501. if( old_ids != NULL ) {
  502. char tBuffer[CTEXT];
  503. for(int i = 0; i< old_ids->size(); i++ ) {
  504. sprintf( tBuffer, "%s,%d", tParam, old_ids->at(i) );
  505. strncpy( tParam, tBuffer, CTEXT );
  506. };
  507. };
  508. if( m_bIsConnected ){
  509. char tQBuf[CTEXT];
  510. AAssoc *result;
  511. sprintf(tQBuf, "SELECT id FROM nodes WHERE `site_id`=%d AND `type` > 0 AND `id` NOT IN(%s)", SiteID, tParam );
  512. #ifdef DEBUG
  513. //LOG(tQBuf);
  514. #endif
  515. result = m_pDatabase->Query( tQBuf );
  516. if( result!= NULL ) {
  517. if( result->size() > 0 ) {
  518. Assoc *cArr;
  519. tVal = new DBC_INT_LIST();
  520. if( tVal != NULL ) {
  521. Assoc::iterator it;
  522. for(int i=0;i<result->size();i++) {
  523. cArr = result->at(i);
  524. it = cArr->find("id");
  525. if( it != cArr->end() ){
  526. tVal->push_back( atoi( it->second.c_str() ));
  527. };
  528. };
  529. };
  530. };
  531. };
  532. deleteResult( result );
  533. };
  534. return tVal;
  535. };
  536. DBC_INT_LIST *argusDBC::listCamMediaStreams( uint32_t CAMID ){
  537. DBC_INT_LIST * tVal = NULL;
  538. if(m_bIsConnected){
  539. char tQBuf[CTEXT];
  540. AAssoc *result;
  541. sprintf(tQBuf, "SELECT id FROM media_streams WHERE `source_id`=%d AND `valid`=1", CAMID );
  542. #ifdef DEBUG
  543. LOG(tQBuf);
  544. #endif
  545. result = m_pDatabase->Query( tQBuf );
  546. if( result!= NULL ) {
  547. if( result->size() > 0 ) {
  548. Assoc *cArr;
  549. tVal = new DBC_INT_LIST();
  550. if( tVal != NULL ) {
  551. Assoc::iterator it;
  552. for(int i=0;i<result->size();i++) {
  553. cArr = result->at(i);
  554. it = cArr->find("id");
  555. if( it != cArr->end() ){
  556. tVal->push_back( atoi( it->second.c_str() ));
  557. };
  558. };
  559. };
  560. };
  561. };
  562. deleteResult( result );
  563. };
  564. return tVal;
  565. };
  566. DBC_NODE_DATA *argusDBC::getNodeData( uint32_t ID ){
  567. DBC_NODE_DATA * tVal = NULL;
  568. if(m_bIsConnected){
  569. char tQBuf[CTEXT];
  570. AAssoc *result;
  571. sprintf(tQBuf, "SELECT * FROM nodes WHERE `id`=%d", ID );
  572. #ifdef DEBUG
  573. LOG(tQBuf);
  574. #endif
  575. result = m_pDatabase->Query( tQBuf );
  576. if( result!= NULL ) {
  577. if( result->size() > 0 ) {
  578. Assoc *cArr;
  579. tVal = (DBC_NODE_DATA*) malloc(sizeof(DBC_NODE_DATA));
  580. if( tVal != NULL ) {
  581. Assoc::iterator it;
  582. cArr = result->at(0);
  583. it = cArr->find("id");
  584. if( it != cArr->end() ){
  585. tVal->node_id = atoi( it->second.c_str() );
  586. };
  587. it = cArr->find("type");
  588. if( it != cArr->end() ){
  589. tVal->type = (ARGUS_NODE_TYPE) atoi( it->second.c_str() );
  590. };
  591. it = cArr->find("aux_id");
  592. if( it != cArr->end() ){
  593. tVal->aux_id = atoi( it->second.c_str() );
  594. };
  595. it = cArr->find("name");
  596. if( it != cArr->end() ){
  597. sprintf( tVal->name, it->second.c_str() );
  598. };
  599. it = cArr->find("ts_s");
  600. if( it != cArr->end() ){
  601. tVal->tss = atoi( it->second.c_str() );
  602. };
  603. it = cArr->find("ts_ms");
  604. if( it != cArr->end() ){
  605. tVal->tsm = atoi( it->second.c_str() );
  606. };
  607. it = cArr->find("online");
  608. if( it != cArr->end() ){
  609. tVal->online = (bool)atoi( it->second.c_str() );
  610. };
  611. };
  612. };
  613. };
  614. deleteResult( result );
  615. };
  616. return tVal;
  617. };
  618. DBC_APF_DATA *argusDBC::getAPFData( uint32_t APFID ){
  619. DBC_APF_DATA * tVal = NULL;
  620. if(m_bIsConnected){
  621. char tQBuf[CTEXT];
  622. AAssoc *result;
  623. sprintf(tQBuf, "SELECT * FROM `target_filter_apf` WHERE `id`=%d", APFID );
  624. #ifdef DEBUG
  625. LOG(tQBuf);
  626. #endif
  627. result = m_pDatabase->Query( tQBuf );
  628. if( result!= NULL ) {
  629. if( result->size() > 0 ) {
  630. Assoc *cArr;
  631. tVal = (DBC_APF_DATA*) malloc(sizeof(DBC_APF_DATA));
  632. if( tVal != NULL ) {
  633. memset( tVal, 0 , sizeof(DBC_APF_DATA));
  634. Assoc::iterator it;
  635. cArr = result->at(0);
  636. it = cArr->find("mode");
  637. if( it != cArr->end() ){
  638. sprintf( tVal->mode, it->second.c_str() );
  639. };
  640. it = cArr->find("port");
  641. if( it != cArr->end() ){
  642. tVal->port = atoi( it->second.c_str() );
  643. };
  644. it = cArr->find("lat");
  645. if( it != cArr->end() ){
  646. tVal->lat = atof( it->second.c_str() );
  647. };
  648. it = cArr->find("lon");
  649. if( it != cArr->end() ){
  650. tVal->lon = atof( it->second.c_str() );
  651. };
  652. it = cArr->find("alt");
  653. if( it != cArr->end() ){
  654. tVal->alt = atof( it->second.c_str() );
  655. };
  656. it = cArr->find("roll");
  657. if( it != cArr->end() ){
  658. tVal->roll = atof( it->second.c_str() );
  659. };
  660. it = cArr->find("pitch");
  661. if( it != cArr->end() ){
  662. tVal->pitch = atof( it->second.c_str() );
  663. };
  664. it = cArr->find("yaw");
  665. if( it != cArr->end() ){
  666. tVal->yaw = atof( it->second.c_str() );
  667. };
  668. it = cArr->find("dx");
  669. if( it != cArr->end() ){
  670. tVal->dx = atof( it->second.c_str() );
  671. };
  672. it = cArr->find("dy");
  673. if( it != cArr->end() ){
  674. tVal->dy = atof( it->second.c_str() );
  675. };
  676. it = cArr->find("dz");
  677. if( it != cArr->end() ){
  678. tVal->dz = atof( it->second.c_str() );
  679. };
  680. };
  681. };
  682. };
  683. deleteResult( result );
  684. };
  685. return tVal;
  686. };
  687. DBC_FH_DATA *argusDBC::getFlyHunterData( uint32_t ID ){
  688. DBC_FH_DATA * tVal = NULL;
  689. if(m_bIsConnected){
  690. char tQBuf[CTEXT];
  691. AAssoc *result;
  692. sprintf(tQBuf, "SELECT * FROM `modules_fly_hunter` WHERE `id`=%d", ID );
  693. #ifdef DEBUG
  694. LOG(tQBuf);
  695. #endif
  696. result = m_pDatabase->Query( tQBuf );
  697. if( result!= NULL ) {
  698. if( result->size() > 0 ) {
  699. Assoc *cArr;
  700. tVal = (DBC_FH_DATA*) malloc(sizeof(DBC_FH_DATA));
  701. if( tVal != NULL ) {
  702. memset( tVal, 0 , sizeof(DBC_FH_DATA));
  703. Assoc::iterator it;
  704. cArr = result->at(0);
  705. it = cArr->find("name");
  706. if( it != cArr->end() ){
  707. sprintf( tVal->name, it->second.c_str() );
  708. };
  709. it = cArr->find("lat");
  710. if( it != cArr->end() ){
  711. tVal->lat = atof( it->second.c_str() );
  712. };
  713. it = cArr->find("lon");
  714. if( it != cArr->end() ){
  715. tVal->lon = atof( it->second.c_str() );
  716. };
  717. it = cArr->find("alt");
  718. if( it != cArr->end() ){
  719. tVal->alt = atof( it->second.c_str() );
  720. };
  721. it = cArr->find("dc_module_id");
  722. if( it != cArr->end() ){
  723. tVal->dc_id = atoi( it->second.c_str() );
  724. };
  725. it = cArr->find("uart_id");
  726. if( it != cArr->end() ){
  727. tVal->uart_id = atoi( it->second.c_str() );
  728. };
  729. };
  730. };
  731. };
  732. deleteResult( result );
  733. };
  734. return tVal;
  735. };
  736. DBC_SITE_DATA *argusDBC::getSiteData( uint32_t ID ){
  737. DBC_SITE_DATA * tVal = NULL;
  738. if(m_bIsConnected){
  739. char tQBuf[CTEXT];
  740. AAssoc *result;
  741. sprintf(tQBuf, "SELECT * FROM sites WHERE `id`=%d", ID );
  742. #ifdef DEBUG
  743. LOG(tQBuf);
  744. #endif
  745. result = m_pDatabase->Query( tQBuf );
  746. if( result!= NULL ) {
  747. if( result->size() > 0 ) {
  748. Assoc *cArr;
  749. tVal = (DBC_SITE_DATA*) malloc(sizeof(DBC_SITE_DATA));
  750. if( tVal != NULL ) {
  751. memset( tVal, 0 , sizeof(DBC_SITE_DATA));
  752. Assoc::iterator it;
  753. cArr = result->at(0);
  754. it = cArr->find("account_id");
  755. if( it != cArr->end() ){
  756. tVal->account_id = atoi( it->second.c_str() );
  757. };
  758. it = cArr->find("name");
  759. if( it != cArr->end() ){
  760. sprintf( tVal->name, it->second.c_str() );
  761. };
  762. it = cArr->find("server_ident");
  763. if( it != cArr->end() ){
  764. sprintf( tVal->ident, it->second.c_str() );
  765. };
  766. it = cArr->find("anchor_lat");
  767. if( it != cArr->end() ){
  768. tVal->lat = atof( it->second.c_str() );
  769. };
  770. it = cArr->find("anchor_lon");
  771. if( it != cArr->end() ){
  772. tVal->lon = atof( it->second.c_str() );
  773. };
  774. it = cArr->find("anchor_alt");
  775. if( it != cArr->end() ){
  776. tVal->alt = atof( it->second.c_str() );
  777. };
  778. it = cArr->find("hemisphere");
  779. if( it != cArr->end() ){
  780. tVal->SH = ( it->second.c_str()[0] == 'S' );
  781. };
  782. it = cArr->find("map_id");
  783. if( it != cArr->end() ){
  784. tVal->map_id = atoi( it->second.c_str() );
  785. };
  786. };
  787. };
  788. };
  789. deleteResult( result );
  790. };
  791. return tVal;
  792. };
  793. DBC_TARGET_FLITER_DATA *argusDBC::getTargetFilterData( uint32_t ID ){
  794. DBC_TARGET_FLITER_DATA * tVal = NULL;
  795. if(m_bIsConnected){
  796. char tQBuf[CTEXT];
  797. AAssoc *result;
  798. sprintf(tQBuf, "SELECT * FROM target_filters WHERE `id`=%d", ID );
  799. #ifdef DEBUG
  800. LOG(tQBuf);
  801. #endif
  802. result = m_pDatabase->Query( tQBuf );
  803. if( result!= NULL ) {
  804. if( result->size() > 0 ) {
  805. Assoc *cArr;
  806. tVal = (DBC_TARGET_FLITER_DATA*) malloc(sizeof(DBC_TARGET_FLITER_DATA));
  807. if( tVal != NULL ) {
  808. memset( tVal, 0 , sizeof(DBC_TARGET_FLITER_DATA));
  809. Assoc::iterator it;
  810. tVal->id = ID;
  811. cArr = result->at(0);
  812. it = cArr->find("type");
  813. if( it != cArr->end() ){
  814. tVal->type = atoi( it->second.c_str() );
  815. };
  816. it = cArr->find("aux_id");
  817. if( it != cArr->end() ){
  818. tVal->aux_id = atoi( it->second.c_str() );
  819. };
  820. };
  821. };
  822. };
  823. deleteResult( result );
  824. };
  825. return tVal;
  826. };
  827. DBC_LRF_DATA *argusDBC::getLRFData( uint32_t ID ){
  828. DBC_LRF_DATA * tVal = NULL;
  829. if(m_bIsConnected){
  830. char tQBuf[CTEXT];
  831. AAssoc *result;
  832. sprintf(tQBuf, "SELECT * FROM lrf_sensors WHERE `id`=%d", ID );
  833. #ifdef DEBUG
  834. LOG(tQBuf);
  835. #endif
  836. result = m_pDatabase->Query( tQBuf );
  837. if( result!= NULL ) {
  838. if( result->size() > 0 ) {
  839. Assoc *cArr;
  840. tVal = (DBC_LRF_DATA*) malloc(sizeof(DBC_LRF_DATA));
  841. if( tVal != NULL ) {
  842. memset( tVal, 0 , sizeof(DBC_LRF_DATA));
  843. Assoc::iterator it;
  844. tVal->id = ID;
  845. cArr = result->at(0);
  846. it = cArr->find("lat");
  847. if( it != cArr->end() ){
  848. tVal->lat = atof( it->second.c_str() );
  849. };
  850. it = cArr->find("lon");
  851. if( it != cArr->end() ){
  852. tVal->lon = atof( it->second.c_str() );
  853. };
  854. it = cArr->find("alt");
  855. if( it != cArr->end() ){
  856. tVal->alt = atof( it->second.c_str() );
  857. };
  858. it = cArr->find("pitch");
  859. if( it != cArr->end() ){
  860. tVal->pitch = atof( it->second.c_str() );
  861. };
  862. it = cArr->find("yaw");
  863. if( it != cArr->end() ){
  864. tVal->yaw = atof( it->second.c_str() );
  865. };
  866. it = cArr->find("roll");
  867. if( it != cArr->end() ){
  868. tVal->roll = atof( it->second.c_str() );
  869. };
  870. it = cArr->find("uart_id");
  871. if( it != cArr->end() ){
  872. tVal->uart_id = atoi( it->second.c_str() );
  873. };
  874. it = cArr->find("device_id");
  875. if( it != cArr->end() ){
  876. tVal->device_id = atoi( it->second.c_str() );
  877. };
  878. it = cArr->find("ip_address");
  879. if( it != cArr->end() ){
  880. sprintf( tVal->master_host, it->second.c_str() );
  881. };
  882. it = cArr->find("aux_ip_address");
  883. if( it != cArr->end() ){
  884. sprintf( tVal->slave_host, it->second.c_str() );
  885. };
  886. it = cArr->find("port");
  887. if( it != cArr->end() ){
  888. tVal->master_port = atoi( it->second.c_str() );
  889. };
  890. it = cArr->find("aux_port");
  891. if( it != cArr->end() ){
  892. tVal->slave_port = atoi( it->second.c_str() );
  893. };
  894. it = cArr->find("auto_draw");
  895. if( it != cArr->end() ){
  896. tVal->auto_draw = atoi( it->second.c_str() );
  897. };
  898. it = cArr->find("filter_id");
  899. if( it != cArr->end() ){
  900. tVal->filter_id = atoi( it->second.c_str() );
  901. };
  902. //it = cArr->find("enabled_lrf");
  903. //if( it != cArr->end() ){
  904. // tVal->enabled_lrf = atoi( it->second.c_str() );
  905. //};
  906. it = cArr->find("max_range");
  907. if( it != cArr->end() ){
  908. tVal->max_range = atof( it->second.c_str() );
  909. };
  910. };
  911. };
  912. };
  913. deleteResult( result );
  914. };
  915. return tVal;
  916. };
  917. DBC_INT_LIST *argusDBC::listModules( uint32_t ServerID ){
  918. DBC_INT_LIST * tVal = NULL;
  919. if(m_bIsConnected){
  920. char tQBuf[CTEXT];
  921. AAssoc *result;
  922. sprintf(tQBuf, "SELECT id FROM server_modules WHERE `server_id`=%d AND `enabled`=1", ServerID );
  923. #ifdef DEBUG
  924. //LOG(tQBuf);
  925. #endif
  926. result = m_pDatabase->Query( tQBuf );
  927. if( result!= NULL ) {
  928. if( result->size() > 0 ) {
  929. Assoc *cArr;
  930. tVal = new DBC_INT_LIST();
  931. if( tVal != NULL ) {
  932. Assoc::iterator it;
  933. for(int i=0;i<result->size();i++) {
  934. cArr = result->at(i);
  935. it = cArr->find("id");
  936. if( it != cArr->end() ){
  937. tVal->push_back( atoi( it->second.c_str() ));
  938. };
  939. };
  940. };
  941. };
  942. };
  943. deleteResult( result );
  944. };
  945. return tVal;
  946. };
  947. DBC_INT_LIST *argusDBC::listFilters( uint32_t SiteID, uint32_t ServerID ){
  948. DBC_INT_LIST * tVal = NULL;
  949. if(m_bIsConnected){
  950. char tQBuf[CTEXT];
  951. AAssoc *result;
  952. sprintf(tQBuf, "SELECT id FROM server_modules WHERE `server_id`=%d AND `enabled`=1", ServerID );
  953. #ifdef DEBUG
  954. LOG(tQBuf);
  955. #endif
  956. result = m_pDatabase->Query( tQBuf );
  957. if( result!= NULL ) {
  958. if( result->size() > 0 ) {
  959. Assoc *cArr;
  960. tVal = new DBC_INT_LIST();
  961. if( tVal != NULL ) {
  962. Assoc::iterator it;
  963. for(int i=0;i<result->size();i++) {
  964. cArr = result->at(i);
  965. it = cArr->find("id");
  966. if( it != cArr->end() ){
  967. tVal->push_back( atoi( it->second.c_str() ));
  968. };
  969. };
  970. };
  971. };
  972. };
  973. deleteResult( result );
  974. };
  975. return tVal;
  976. };
  977. DBC_INT_LIST *argusDBC::listMediaStreams( uint32_t SiteId, uint32_t MediaServerID, uint8_t listMode ){
  978. DBC_INT_LIST * tVal = NULL;
  979. if(m_bIsConnected){
  980. char tQBuf[CTEXT];
  981. AAssoc *result;
  982. switch( listMode ){
  983. 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;
  984. 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;
  985. default: sprintf(tQBuf, "SELECT id FROM media_server_streams WHERE `site_id`=%d AND `media_server_id`=%d", SiteId, MediaServerID );
  986. };
  987. #ifdef DEBUG
  988. //LOG(tQBuf);
  989. #endif
  990. result = m_pDatabase->Query( tQBuf );
  991. if( result!= NULL ) {
  992. if( result->size() > 0 ) {
  993. Assoc *cArr;
  994. tVal = new DBC_INT_LIST();
  995. if( tVal != NULL ) {
  996. Assoc::iterator it;
  997. for(int i=0;i<result->size();i++) {
  998. cArr = result->at(i);
  999. it = cArr->find("id");
  1000. if( it != cArr->end() ){
  1001. tVal->push_back( atoi( it->second.c_str() ));
  1002. };
  1003. };
  1004. };
  1005. };
  1006. };
  1007. deleteResult( result );
  1008. };
  1009. return tVal;
  1010. };
  1011. DBC_INT_LIST *argusDBC::listSockets( uint32_t NodeID ){
  1012. DBC_INT_LIST * tVal = NULL;
  1013. if(m_bIsConnected){
  1014. char tQBuf[CTEXT];
  1015. AAssoc *result;
  1016. sprintf(tQBuf, "SELECT id FROM sockets WHERE `node_id`=%d", NodeID );
  1017. #ifdef DEBUG
  1018. LOG(tQBuf);
  1019. #endif
  1020. result = m_pDatabase->Query( tQBuf );
  1021. if( result!= NULL ) {
  1022. if( result->size() > 0 ) {
  1023. Assoc *cArr;
  1024. tVal = new DBC_INT_LIST();
  1025. if( tVal != NULL ) {
  1026. Assoc::iterator it;
  1027. for(int i=0;i<result->size();i++) {
  1028. cArr = result->at(i);
  1029. it = cArr->find("id");
  1030. if( it != cArr->end() ){
  1031. tVal->push_back( atoi( it->second.c_str() ));
  1032. };
  1033. };
  1034. };
  1035. };
  1036. };
  1037. deleteResult( result );
  1038. };
  1039. return tVal;
  1040. };
  1041. DBC_INT_LIST *argusDBC::listNewModules( uint32_t ServerID, DBC_INT_LIST * old_ids ){
  1042. DBC_INT_LIST * tVal = NULL;
  1043. char tParam[CTEXT];
  1044. //memset( tParam, 0, CTEXT );
  1045. sprintf(tParam,"0");
  1046. if( old_ids != NULL ) {
  1047. char tBuffer[CTEXT];
  1048. for(int i = 0; i< old_ids->size(); i++ ) {
  1049. sprintf( tBuffer, "%s,%d", tParam, old_ids->at(i) );
  1050. strncpy( tParam, tBuffer, CTEXT );
  1051. };
  1052. };
  1053. if(m_bIsConnected){
  1054. char tQBuf[CTEXT];
  1055. AAssoc *result;
  1056. sprintf(tQBuf, "SELECT id FROM server_modules WHERE `server_id`=%d AND `enabled`=1 AND `id` NOT IN (%s)", ServerID, tParam );
  1057. #ifdef DEBUG
  1058. //LOG(tQBuf);
  1059. #endif
  1060. result = m_pDatabase->Query( tQBuf );
  1061. if( result!= NULL ) {
  1062. if( result->size() > 0 ) {
  1063. Assoc *cArr;
  1064. tVal = new DBC_INT_LIST();
  1065. if( tVal != NULL ) {
  1066. Assoc::iterator it;
  1067. for(int i=0;i<result->size();i++) {
  1068. cArr = result->at(i);
  1069. it = cArr->find("id");
  1070. if( it != cArr->end() ){
  1071. tVal->push_back( atoi( it->second.c_str() ));
  1072. };
  1073. };
  1074. };
  1075. };
  1076. };
  1077. deleteResult( result );
  1078. };
  1079. return tVal;
  1080. };
  1081. uint32_t argusDBC::getCamId( CSTR UUID ){
  1082. uint32_t RetVal = 0;
  1083. if(m_bIsConnected){
  1084. char tQBuf[CTEXT];
  1085. AAssoc *result;
  1086. sprintf(tQBuf, "SELECT id FROM cameras WHERE `uuid`='%s'", UUID );
  1087. #ifdef DEBUG
  1088. LOG(tQBuf);
  1089. #endif
  1090. result = m_pDatabase->Query( tQBuf );
  1091. if( result!= NULL ) {
  1092. if( result->size() > 0 ) {
  1093. Assoc *cArr;
  1094. Assoc::iterator it;
  1095. cArr = result->at(0);
  1096. it = cArr->find("id");
  1097. if( it != cArr->end() ){
  1098. RetVal = atoi( it->second.c_str() );
  1099. };
  1100. };
  1101. };
  1102. deleteResult( result );
  1103. };
  1104. return RetVal;
  1105. };
  1106. DBC_CAM_DATA *argusDBC::getCamData( uint32_t ID ){
  1107. DBC_CAM_DATA *tVal = NULL;
  1108. if(m_bIsConnected){
  1109. char tQBuf[CTEXT];
  1110. AAssoc *result;
  1111. sprintf(tQBuf, "SELECT * FROM cameras WHERE `id`=%d", ID );
  1112. #ifdef DEBUG
  1113. LOG(tQBuf);
  1114. #endif
  1115. result = m_pDatabase->Query( tQBuf );
  1116. if( result!= NULL ) {
  1117. if( result->size() > 0 ) {
  1118. Assoc *cArr;
  1119. tVal = (DBC_CAM_DATA*) malloc(sizeof(DBC_CAM_DATA));
  1120. if( tVal != NULL ) {
  1121. memset( tVal, 0 , sizeof(DBC_CAM_DATA));
  1122. tVal->id = ID;
  1123. Assoc::iterator it;
  1124. cArr = result->at(0);
  1125. it = cArr->find("site_id");
  1126. if( it != cArr->end() ){
  1127. tVal->site_id = atoi( it->second.c_str() );
  1128. };
  1129. it = cArr->find("node_id");
  1130. if( it != cArr->end() ){
  1131. tVal->node_id = atoi( it->second.c_str() );
  1132. };
  1133. it = cArr->find("online");
  1134. if( it != cArr->end() ){
  1135. tVal->online = (bool) atoi( it->second.c_str() );
  1136. };
  1137. it = cArr->find("type");
  1138. if( it != cArr->end() ){
  1139. tVal->type = atoi( it->second.c_str() );
  1140. };
  1141. it = cArr->find("name");
  1142. if( it != cArr->end() ){
  1143. strncpy( tVal->name, it->second.c_str(), 64 );
  1144. };
  1145. it = cArr->find("hardware");
  1146. if( it != cArr->end() ){
  1147. strncpy( tVal->hardware, it->second.c_str(), 32 );
  1148. };
  1149. it = cArr->find("status");
  1150. if( it != cArr->end() ){
  1151. tVal->status = atoi( it->second.c_str() );
  1152. };
  1153. it = cArr->find("session");
  1154. if( it != cArr->end() ){
  1155. strncpy( tVal->session, it->second.c_str(), 32 );
  1156. };
  1157. it = cArr->find("protocol");
  1158. if( it != cArr->end() ){
  1159. tVal->protocol = atoi( it->second.c_str() );
  1160. };
  1161. it = cArr->find("protocol_aux");
  1162. if( it != cArr->end() ){
  1163. strncpy( tVal->protocol_aux, it->second.c_str(), 64 );
  1164. };
  1165. it = cArr->find("uart_id");
  1166. if( it != cArr->end() ){
  1167. tVal->uart_id = atoi( it->second.c_str() );
  1168. };
  1169. it = cArr->find("lat");
  1170. if( it != cArr->end() ){
  1171. tVal->lat = atof( it->second.c_str() );
  1172. };
  1173. it = cArr->find("lon");
  1174. if( it != cArr->end() ){
  1175. tVal->lon = atof( it->second.c_str() );
  1176. };
  1177. it = cArr->find("alt");
  1178. if( it != cArr->end() ){
  1179. tVal->alt = atof( it->second.c_str() );
  1180. };
  1181. it = cArr->find("picth");
  1182. if( it != cArr->end() ){
  1183. tVal->pitch = atof( it->second.c_str() );
  1184. };
  1185. it = cArr->find("roll");
  1186. if( it != cArr->end() ){
  1187. tVal->roll = atof( it->second.c_str() );
  1188. };
  1189. it = cArr->find("yaw");
  1190. if( it != cArr->end() ){
  1191. tVal->yaw = atof( it->second.c_str() );
  1192. };
  1193. it = cArr->find("imager_type");
  1194. if( it != cArr->end() ){
  1195. tVal->imager_type = atoi( it->second.c_str() );
  1196. };
  1197. it = cArr->find("min_f");
  1198. if( it != cArr->end() ){
  1199. tVal->min_f = atof( it->second.c_str() );
  1200. };
  1201. it = cArr->find("max_f");
  1202. if( it != cArr->end() ){
  1203. tVal->max_f = atof( it->second.c_str() );
  1204. };
  1205. it = cArr->find("pan_model");
  1206. if( it != cArr->end() ){
  1207. tVal->pan_model = atoi( it->second.c_str() );
  1208. };
  1209. it = cArr->find("pan_angles");
  1210. if( it != cArr->end() ){
  1211. tVal->pan_angles = atoi( it->second.c_str() );
  1212. };
  1213. it = cArr->find("tilt_model");
  1214. if( it != cArr->end() ){
  1215. tVal->tilt_model = atoi( it->second.c_str() );
  1216. };
  1217. it = cArr->find("tilt_angles");
  1218. if( it != cArr->end() ){
  1219. tVal->tilt_angles = atoi( it->second.c_str() );
  1220. };
  1221. it = cArr->find("max_range");
  1222. if( it != cArr->end() ){
  1223. tVal->max_range = atof( it->second.c_str() );
  1224. };
  1225. it = cArr->find("access_login");
  1226. if( it != cArr->end() ){
  1227. strncpy( tVal->username, it->second.c_str(), 16 );
  1228. };
  1229. it = cArr->find("access_pass");
  1230. if( it != cArr->end() ){
  1231. strncpy( tVal->password, it->second.c_str(), 16 );
  1232. };
  1233. it = cArr->find("uuid");
  1234. if( it != cArr->end() ){
  1235. strncpy( tVal->uuid, it->second.c_str(), 64 );
  1236. };
  1237. it = cArr->find("mac");
  1238. if( it != cArr->end() ){
  1239. strncpy( tVal->mac, it->second.c_str(), 16 );
  1240. };
  1241. it = cArr->find("ip");
  1242. if( it != cArr->end() ){
  1243. strncpy( tVal->ip, it->second.c_str(), 16 );
  1244. };
  1245. it = cArr->find("port");
  1246. if( it != cArr->end() ){
  1247. tVal->port = atoi( it->second.c_str() );
  1248. };
  1249. it = cArr->find("onvif_access");
  1250. if( it != cArr->end() ){
  1251. strncpy( tVal->onvif_access, it->second.c_str(), 5);
  1252. };
  1253. it = cArr->find("onvif_ctrl");
  1254. if( it != cArr->end() ){
  1255. strncpy( tVal->onvif_ctrl, it->second.c_str(), 250);
  1256. };
  1257. it = cArr->find("ptz_token");
  1258. if( it != cArr->end() ){
  1259. strncpy( tVal->ptz_token, it->second.c_str(), 64);
  1260. };
  1261. };
  1262. };
  1263. };
  1264. deleteResult( result );
  1265. };
  1266. return tVal;
  1267. };
  1268. DBC_MODULE_DATA *argusDBC::getModuleData( uint32_t ID ){
  1269. DBC_MODULE_DATA *tVal = NULL;
  1270. if(m_bIsConnected){
  1271. char tQBuf[CTEXT];
  1272. AAssoc *result;
  1273. sprintf(tQBuf, "SELECT * FROM server_modules WHERE `id`=%d", ID );
  1274. #ifdef DEBUG
  1275. LOG(tQBuf);
  1276. #endif
  1277. result = m_pDatabase->Query( tQBuf );
  1278. if( result!= NULL ) {
  1279. if( result->size() > 0 ) {
  1280. Assoc *cArr;
  1281. tVal = (DBC_MODULE_DATA*) malloc(sizeof(DBC_MODULE_DATA));
  1282. if( tVal != NULL ) {
  1283. Assoc::iterator it;
  1284. cArr = result->at(0);
  1285. it = cArr->find("id");
  1286. if( it != cArr->end() ){
  1287. tVal->module_id = atoi( it->second.c_str() );
  1288. };
  1289. it = cArr->find("aux_id");
  1290. if( it != cArr->end() ){
  1291. tVal->aux_id = atoi( it->second.c_str() );
  1292. };
  1293. it = cArr->find("type");
  1294. if( it != cArr->end() ){
  1295. tVal->type = atoi( it->second.c_str() );
  1296. };
  1297. it = cArr->find("enabled");
  1298. if( it != cArr->end() ){
  1299. tVal->enabled = (bool)atoi( it->second.c_str() );
  1300. };
  1301. };
  1302. };
  1303. };
  1304. deleteResult( result );
  1305. };
  1306. return tVal;
  1307. };
  1308. DBC_SOCKET_DATA *argusDBC::getSocketData( uint32_t ID ){
  1309. DBC_SOCKET_DATA *tVal = NULL;
  1310. if(m_bIsConnected){
  1311. char tQBuf[CTEXT];
  1312. AAssoc *result;
  1313. sprintf(tQBuf, "SELECT * FROM sockets WHERE `id`=%d", ID );
  1314. #ifdef DEBUG
  1315. LOG(tQBuf);
  1316. #endif
  1317. result = m_pDatabase->Query( tQBuf );
  1318. if( result!= NULL ) {
  1319. if( result->size() > 0 ) {
  1320. Assoc *cArr;
  1321. tVal = (DBC_SOCKET_DATA*) malloc(sizeof(DBC_SOCKET_DATA));
  1322. if( tVal != NULL ) {
  1323. Assoc::iterator it;
  1324. cArr = result->at(0);
  1325. it = cArr->find("id");
  1326. if( it != cArr->end() ){
  1327. tVal->socket_id = atoi( it->second.c_str() );
  1328. };
  1329. it = cArr->find("aux_id");
  1330. if( it != cArr->end() ){
  1331. tVal->aux_id = atoi( it->second.c_str() );
  1332. };
  1333. it = cArr->find("type");
  1334. if( it != cArr->end() ){
  1335. tVal->type = atoi( it->second.c_str() );
  1336. };
  1337. it = cArr->find("binded");
  1338. if( it != cArr->end() ){
  1339. tVal->binded = (bool)atoi( it->second.c_str() );
  1340. };
  1341. };
  1342. };
  1343. };
  1344. deleteResult( result );
  1345. };
  1346. return tVal;
  1347. };
  1348. DBC_MEDIA_STREAM_DATA *argusDBC::getMediaStreamData( uint32_t ID ){
  1349. DBC_MEDIA_STREAM_DATA *tVal = NULL;
  1350. if(m_bIsConnected){
  1351. char tQBuf[CTEXT];
  1352. AAssoc *result;
  1353. sprintf(tQBuf, "SELECT * FROM media_streams WHERE `id`=%d", ID );
  1354. #ifdef DEBUG
  1355. //LOG(tQBuf);
  1356. #endif
  1357. result = m_pDatabase->Query( tQBuf );
  1358. if( result!= NULL ) {
  1359. if( result->size() > 0 ) {
  1360. Assoc *cArr;
  1361. tVal = (DBC_MEDIA_STREAM_DATA*) malloc(sizeof(DBC_MEDIA_STREAM_DATA));
  1362. if( tVal != NULL ) {
  1363. Assoc::iterator it;
  1364. cArr = result->at(0);
  1365. tVal->id = ID;
  1366. it = cArr->find("source_id");
  1367. if( it != cArr->end() ){
  1368. tVal->source_id = atoi( it->second.c_str() );
  1369. };
  1370. it = cArr->find("site_id");
  1371. if( it != cArr->end() ){
  1372. tVal->site_id = atoi( it->second.c_str() );
  1373. };
  1374. it = cArr->find("source_type");
  1375. if( it != cArr->end() ){
  1376. sprintf( tVal->source_type, it->second.c_str() );
  1377. };
  1378. it = cArr->find("valid");
  1379. if( it != cArr->end() ){
  1380. tVal->valid = (bool) atoi( it->second.c_str() );
  1381. };
  1382. it = cArr->find("token");
  1383. if( it != cArr->end() ){
  1384. sprintf( tVal->token, it->second.c_str() );
  1385. };
  1386. it = cArr->find("mrl_proto");
  1387. if( it != cArr->end() ){
  1388. sprintf( tVal->mrl_proto, it->second.c_str() );
  1389. };
  1390. it = cArr->find("mrl_port");
  1391. if( it != cArr->end() ){
  1392. tVal->mrl_port = atoi( it->second.c_str() );
  1393. };
  1394. it = cArr->find("mrl");
  1395. if( it != cArr->end() ){
  1396. sprintf( tVal->mrl, it->second.c_str() );
  1397. };
  1398. };
  1399. };
  1400. };
  1401. deleteResult( result );
  1402. };
  1403. return tVal;
  1404. };
  1405. DBC_MEDIA_SERVER_DATA *argusDBC::getMediaServerData( uint32_t ID ){
  1406. DBC_MEDIA_SERVER_DATA *tVal = NULL;
  1407. if(m_bIsConnected){
  1408. char tQBuf[CTEXT];
  1409. AAssoc *result;
  1410. sprintf(tQBuf, "SELECT * FROM media_servers WHERE `id`=%d", ID );
  1411. #ifdef DEBUG
  1412. LOG(tQBuf);
  1413. #endif
  1414. result = m_pDatabase->Query( tQBuf );
  1415. if( result!= NULL ) {
  1416. if( result->size() > 0 ) {
  1417. Assoc *cArr;
  1418. tVal = (DBC_MEDIA_SERVER_DATA*) malloc(sizeof(DBC_MEDIA_SERVER_DATA));
  1419. if( tVal != NULL ) {
  1420. Assoc::iterator it;
  1421. cArr = result->at(0);
  1422. tVal->id = ID;
  1423. it = cArr->find("secret_key");
  1424. if( it != cArr->end() ){
  1425. sprintf( tVal->key, it->second.c_str() );
  1426. };
  1427. it = cArr->find("ip");
  1428. if( it != cArr->end() ){
  1429. sprintf( tVal->ip, it->second.c_str() );
  1430. };
  1431. it = cArr->find("REST_port");
  1432. if( it != cArr->end() ){
  1433. tVal->port = atoi( it->second.c_str() );
  1434. };
  1435. it = cArr->find("virtual_host");
  1436. if( it != cArr->end() ){
  1437. sprintf( tVal->host, it->second.c_str() );
  1438. };
  1439. it = cArr->find("recording");
  1440. if( it != cArr->end() ){
  1441. tVal->recording = (bool)atoi( it->second.c_str() );
  1442. };
  1443. it = cArr->find("local");
  1444. if( it != cArr->end() ){
  1445. tVal->local = (bool)atoi( it->second.c_str() );
  1446. };
  1447. it = cArr->find("docRoot");
  1448. if( it != cArr->end() ){
  1449. sprintf( tVal->docRoot, it->second.c_str() );
  1450. };
  1451. sprintf( tVal->name,"ZLMedia_%d", tVal->id );
  1452. };
  1453. };
  1454. };
  1455. deleteResult( result );
  1456. };
  1457. return tVal;
  1458. };
  1459. DBC_MEDIA_SERVER_STREAM_DATA *argusDBC::getMediaServerStreamDataBySource( uint32_t ID ){
  1460. DBC_MEDIA_SERVER_STREAM_DATA *tVal = NULL;
  1461. if(m_bIsConnected){
  1462. char tQBuf[MAX_PATH_LEN];
  1463. AAssoc *result;
  1464. sprintf(tQBuf, "SELECT `id`, `media_stream_id`, `online`, `key`, `mrl` FROM media_server_streams WHERE `media_stream_id`=%d", ID );
  1465. #ifdef DEBUG
  1466. //LOG(tQBuf);
  1467. #endif
  1468. result = m_pDatabase->Query( tQBuf );
  1469. if( result!= NULL ) {
  1470. if( result->size() > 0 ) {
  1471. Assoc *cArr;
  1472. tVal = (DBC_MEDIA_SERVER_STREAM_DATA*) malloc(sizeof(DBC_MEDIA_SERVER_STREAM_DATA));
  1473. if( tVal != NULL ) {
  1474. Assoc::iterator it;
  1475. cArr = result->at(0);
  1476. tVal->id = ID;
  1477. it = cArr->find("media_stream_id");
  1478. if( it != cArr->end() ){
  1479. tVal->media_stream_id = atoi( it->second.c_str() );
  1480. };
  1481. it = cArr->find("online");
  1482. if( it != cArr->end() ){
  1483. tVal->online = atoi( it->second.c_str() );
  1484. };
  1485. it = cArr->find("key");
  1486. if( it != cArr->end() ){
  1487. sprintf( tVal->key, it->second.c_str() );
  1488. };
  1489. it = cArr->find("mrl");
  1490. if( it != cArr->end() ){
  1491. sprintf( tVal->mrl, it->second.c_str() );
  1492. };
  1493. };
  1494. };
  1495. };
  1496. deleteResult( result );
  1497. };
  1498. return tVal;
  1499. };
  1500. DBC_MEDIA_SERVER_STREAM_DATA *argusDBC::getMediaServerStreamData( uint32_t ID ){
  1501. DBC_MEDIA_SERVER_STREAM_DATA *tVal = NULL;
  1502. if(m_bIsConnected){
  1503. char tQBuf[MAX_PATH_LEN];
  1504. AAssoc *result;
  1505. sprintf(tQBuf, "SELECT `id`, `media_stream_id`, `online`, `key`, `mrl` FROM media_server_streams WHERE `id`=%d", ID );
  1506. #ifdef DEBUG
  1507. //LOG(tQBuf);
  1508. #endif
  1509. result = m_pDatabase->Query( tQBuf );
  1510. if( result!= NULL ) {
  1511. if( result->size() > 0 ) {
  1512. Assoc *cArr;
  1513. tVal = (DBC_MEDIA_SERVER_STREAM_DATA*) malloc(sizeof(DBC_MEDIA_SERVER_STREAM_DATA));
  1514. if( tVal != NULL ) {
  1515. Assoc::iterator it;
  1516. cArr = result->at(0);
  1517. tVal->id = ID;
  1518. it = cArr->find("media_stream_id");
  1519. if( it != cArr->end() ){
  1520. tVal->media_stream_id = atoi( it->second.c_str() );
  1521. };
  1522. it = cArr->find("online");
  1523. if( it != cArr->end() ){
  1524. tVal->online = atoi( it->second.c_str() );
  1525. };
  1526. it = cArr->find("key");
  1527. if( it != cArr->end() ){
  1528. sprintf( tVal->key, it->second.c_str() );
  1529. };
  1530. it = cArr->find("mrl");
  1531. if( it != cArr->end() ){
  1532. sprintf( tVal->mrl, it->second.c_str() );
  1533. };
  1534. };
  1535. };
  1536. };
  1537. deleteResult( result );
  1538. };
  1539. return tVal;
  1540. };
  1541. void argusDBC::registerServer(uint32_t SiteID, CSTR identity ){
  1542. if(m_bIsConnected){
  1543. char tQBuf[CTEXT];
  1544. sprintf(tQBuf,"INSERT INTO servers SET `site_id`=%d, `identity`='%s', `online`=1 ON DUPLICATE KEY UPDATE `online`=1", SiteID, identity );
  1545. #ifdef DEBUG
  1546. LOG(tQBuf);
  1547. #endif
  1548. m_pDatabase->SilentQuery( tQBuf );
  1549. // Clenup Nodes and services ...
  1550. sprintf(tQBuf,"UPDATE nodes SET `online`=0 WHERE `site_id`=%d ", SiteID );
  1551. #ifdef DEBUG
  1552. LOG(tQBuf);
  1553. #endif
  1554. m_pDatabase->SilentQuery( tQBuf );
  1555. sprintf(tQBuf,"UPDATE cameras SET `online`=0 WHERE `site_id`=%d ", SiteID );
  1556. #ifdef DEBUG
  1557. LOG(tQBuf);
  1558. #endif
  1559. m_pDatabase->SilentQuery( tQBuf );
  1560. sprintf(tQBuf,"UPDATE media_streams SET `valid`=0 WHERE `site_id`=%d ", SiteID );
  1561. #ifdef DEBUG
  1562. LOG(tQBuf);
  1563. #endif
  1564. m_pDatabase->SilentQuery( tQBuf );
  1565. sprintf(tQBuf,"UPDATE media_server_streams SET `valid`=0, `online`=0 WHERE `site_id`=%d ", SiteID );
  1566. #ifdef DEBUG
  1567. LOG(tQBuf);
  1568. #endif
  1569. m_pDatabase->SilentQuery( tQBuf );
  1570. uint32_t sid = getServerID( identity );
  1571. if( sid ) {
  1572. 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 );
  1573. #ifdef DEBUG
  1574. LOG(tQBuf);
  1575. #endif
  1576. m_pDatabase->SilentQuery( tQBuf );
  1577. };
  1578. };
  1579. };
  1580. void argusDBC::unregisterServer(uint32_t ServerID, uint32_t NodeID ){
  1581. if(m_bIsConnected){
  1582. char tQBuf[CTEXT];
  1583. sprintf(tQBuf,"UPDATE servers SET `online`=0 WHERE `id` = %d", ServerID );
  1584. #ifdef DEBUG
  1585. LOG(tQBuf);
  1586. #endif
  1587. m_pDatabase->SilentQuery( tQBuf );
  1588. setNodeOffline( NodeID );
  1589. };
  1590. };
  1591. void argusDBC::setNodeOnline( uint32_t NodeID ){
  1592. if(m_bIsConnected){
  1593. char tQBuf[CTEXT];
  1594. if( NodeID ) {
  1595. sprintf(tQBuf,"UPDATE nodes SET `online`=1 WHERE `id` = %d", NodeID );
  1596. #ifdef DEBUG
  1597. LOG(tQBuf);
  1598. #endif
  1599. m_pDatabase->SilentQuery( tQBuf );
  1600. //sprintf(tQBuf,"UPDATE sockets SET `state`=1 WHERE `node_id` = %d", NodeID );
  1601. #ifdef DEBUG
  1602. //LOG(tQBuf);
  1603. #endif
  1604. //m_pDatabase->SilentQuery( tQBuf );
  1605. };
  1606. };
  1607. };
  1608. void argusDBC::setNodeOffline( uint32_t NodeID ){
  1609. if(m_bIsConnected){
  1610. char tQBuf[CTEXT];
  1611. if( NodeID ) {
  1612. sprintf(tQBuf,"UPDATE nodes SET `online`=0 WHERE `id` = %d", NodeID );
  1613. #ifdef DEBUG
  1614. LOG(tQBuf);
  1615. #endif
  1616. m_pDatabase->SilentQuery( tQBuf );
  1617. //sprintf(tQBuf,"UPDATE sockets SET `state`=0 WHERE `node_id` = %d", NodeID );
  1618. #ifdef DEBUG
  1619. //LOG(tQBuf);
  1620. #endif
  1621. //m_pDatabase->SilentQuery( tQBuf );
  1622. };
  1623. };
  1624. };
  1625. uint32_t argusDBC::getServerID( CSTR identity ){
  1626. uint32_t RetVal = 0;
  1627. if(m_bIsConnected){
  1628. char tQBuf[CTEXT];
  1629. sprintf(tQBuf,"SELECT id FROM servers WHERE `identity`='%s'", identity );
  1630. #ifdef DEBUG
  1631. LOG(tQBuf);
  1632. #endif
  1633. AAssoc *result;
  1634. result = m_pDatabase->Query( tQBuf );
  1635. if( result!= NULL ) {
  1636. if( result->size() > 0 ) {
  1637. Assoc * cArr;
  1638. Assoc::iterator it;
  1639. cArr = result->at(0);
  1640. it = cArr->find("id");
  1641. if( it != cArr->end() ){
  1642. RetVal = atoi( it->second.c_str() );
  1643. };
  1644. };
  1645. };
  1646. deleteResult( result );
  1647. };
  1648. return RetVal;
  1649. };
  1650. uint32_t argusDBC::getServerNode( uint32_t SID ){
  1651. uint32_t RetVal = 0;
  1652. if(m_bIsConnected){
  1653. char tQBuf[CTEXT];
  1654. sprintf(tQBuf,"SELECT id FROM nodes WHERE `type`=0 AND `aux_id`=%d", SID );
  1655. #ifdef DEBUG
  1656. LOG(tQBuf);
  1657. #endif
  1658. AAssoc *result;
  1659. result = m_pDatabase->Query( tQBuf );
  1660. if( result!= NULL ) {
  1661. if( result->size() > 0 ) {
  1662. Assoc * cArr;
  1663. Assoc::iterator it;
  1664. cArr = result->at(0);
  1665. it = cArr->find("id");
  1666. if( it != cArr->end() ){
  1667. RetVal = atoi( it->second.c_str() );
  1668. };
  1669. };
  1670. };
  1671. deleteResult( result );
  1672. };
  1673. return RetVal;
  1674. };
  1675. uint32_t argusDBC::addLocalMediaSource( uint32_t SiteID, CSTR path, uint32_t width, uint32_t height ){
  1676. uint32_t RetVal = 0;
  1677. if(m_bIsConnected){
  1678. char tQBuf[1024];
  1679. char tM5[33];
  1680. CSTR tMD5 = MD5String( path );
  1681. if( tMD5 != NULL ) {
  1682. memcpy( tM5, tMD5, 33 );
  1683. tM5[32]=(char)0;
  1684. free( tMD5 );
  1685. 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",
  1686. SiteID, tM5, width, height, path, width, height );
  1687. #ifdef DEBUG
  1688. LOG(tQBuf);
  1689. #endif
  1690. RetVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
  1691. };
  1692. };
  1693. LOG("Func Finished");
  1694. return RetVal;
  1695. };
  1696. uint32_t argusDBC::addNodeSocket( uint32_t NodeID, uint32_t auxID, uint8_t SocketType, uint8_t SocketMode, bool multidrop, CSTR path, CSTR name ){
  1697. uint32_t retVal = 0;
  1698. if(m_bIsConnected){
  1699. char tQBuf[2048];
  1700. char tM5[33];
  1701. CSTR tMD5 = MD5String( path );
  1702. if( tMD5 != NULL ) {
  1703. memcpy( tM5, tMD5, 33 );
  1704. free( tMD5 );
  1705. if( multidrop ) {
  1706. 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'",
  1707. NodeID, SocketType, SocketMode, tM5, path, name, auxID, name );
  1708. } else {
  1709. 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'",
  1710. NodeID, SocketType, SocketMode, tM5, path, name, auxID, name );
  1711. };
  1712. #ifdef DEBUG
  1713. LOG(tQBuf);
  1714. #endif
  1715. //m_pDatabase->SilentQuery( tQBuf );
  1716. retVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
  1717. };
  1718. };
  1719. return retVal;
  1720. };
  1721. uint32_t argusDBC::getNodeSocketID( uint32_t NodeID, uint32_t auxID, uint8_t SocketType, CSTR path ){
  1722. uint32_t retVal = 0;
  1723. if(m_bIsConnected){
  1724. char tQBuf[2048];
  1725. char tM5[33];
  1726. CSTR tMD5 = MD5String( path );
  1727. if( tMD5 != NULL ) {
  1728. memcpy( tM5, tMD5, 33 );
  1729. free( tMD5 );
  1730. sprintf( tQBuf,"SELECT id FROM `sockets` WHERE `node_id`=%d AND `type`=%d AND `md5`='%s' AND `aux_id`=%d", NodeID, SocketType, tM5, auxID );
  1731. #ifdef DEBUG
  1732. LOG(tQBuf);
  1733. #endif
  1734. AAssoc *result;
  1735. result = m_pDatabase->Query( tQBuf );
  1736. if( result!= NULL ) {
  1737. if( result->size() > 0 ) {
  1738. Assoc * cArr;
  1739. Assoc::iterator it;
  1740. cArr = result->at(0);
  1741. it = cArr->find("id");
  1742. if( it != cArr->end() ){
  1743. retVal = atoi( it->second.c_str() );
  1744. };
  1745. };
  1746. };
  1747. deleteResult( result );
  1748. };
  1749. };
  1750. return retVal;
  1751. };
  1752. CSTR argusDBC::getNodeIP4( uint32_t NodeID ){
  1753. return getSocketName( NodeID, ARGUS_NODE_SOCK_TYPE_NETWORK_IPV4 );
  1754. };
  1755. CSTR argusDBC::getNodeIP6( uint32_t NodeID ){
  1756. return getSocketName( NodeID, ARGUS_NODE_SOCK_TYPE_NETWORK_IPV6 );
  1757. };
  1758. CSTR argusDBC::getSocketPath( uint32_t NodeID, uint32_t Type ){
  1759. if(m_bIsConnected){
  1760. char tQBuf[CTEXT];
  1761. sprintf( tQBuf, "SELECT `path` FROM `sockets` WHERE `node_id`=%d AND `type`=%d LIMIT 1",
  1762. NodeID, Type );
  1763. #ifdef DEBUG
  1764. LOG(tQBuf);
  1765. #endif
  1766. AAssoc *result;
  1767. result = m_pDatabase->Query( tQBuf );
  1768. if( result!= NULL ) {
  1769. if( result->size() > 0 ) {
  1770. Assoc * cArr;
  1771. Assoc::iterator it;
  1772. cArr = result->at(0);
  1773. it = cArr->find("path");
  1774. if( it != cArr->end() ){
  1775. strncpy( tQBuf, it->second.c_str(), CTEXT );
  1776. };
  1777. };
  1778. };
  1779. deleteResult( result );
  1780. return strdup(tQBuf);
  1781. };
  1782. return NULL;
  1783. };
  1784. CSTR argusDBC::getSocketName( uint32_t NodeID, uint32_t Type ){
  1785. if(m_bIsConnected){
  1786. char tQBuf[CTEXT];
  1787. sprintf( tQBuf, "SELECT `name` FROM `sockets` WHERE `node_id`=%d AND `type`=%d LIMIT 1",
  1788. NodeID, Type );
  1789. #ifdef DEBUG
  1790. LOG(tQBuf);
  1791. #endif
  1792. AAssoc *result;
  1793. result = m_pDatabase->Query( tQBuf );
  1794. if( result!= NULL ) {
  1795. if( result->size() > 0 ) {
  1796. Assoc * cArr;
  1797. Assoc::iterator it;
  1798. cArr = result->at(0);
  1799. it = cArr->find("name");
  1800. if( it != cArr->end() ){
  1801. strncpy( tQBuf, it->second.c_str(), CTEXT );
  1802. };
  1803. };
  1804. };
  1805. deleteResult( result );
  1806. return strdup(tQBuf);
  1807. };
  1808. return NULL;
  1809. };
  1810. KAFKA_SETTINGS *argusDBC::getSettingsKAFKA( uint32_t ModuleID ){
  1811. KAFKA_SETTINGS *tVal = NULL;
  1812. if( m_bIsConnected ) {
  1813. char tQBuf[CTEXT];
  1814. AAssoc *result;
  1815. sprintf( tQBuf, "SELECT brocker_address, brocker_port FROM modules_kafka WHERE module_id = %d", ModuleID );
  1816. #ifdef DEBUG
  1817. LOG(tQBuf);
  1818. #endif
  1819. result = m_pDatabase->Query( tQBuf );
  1820. if( result!= NULL ) {
  1821. if( result->size() > 0 ) {
  1822. Assoc *cArr;
  1823. tVal = (KAFKA_SETTINGS*) malloc(sizeof(KAFKA_SETTINGS));
  1824. if( tVal != NULL ) {
  1825. Assoc::iterator it;
  1826. cArr = result->at(0);
  1827. it = cArr->find("brocker_address");
  1828. if( it != cArr->end() ){
  1829. strncpy( tVal->brocker_addr, it->second.c_str(), 255 );
  1830. };
  1831. it = cArr->find("brocker_port");
  1832. if( it != cArr->end() ){
  1833. tVal->brocker_port = atoi( it->second.c_str() );
  1834. };
  1835. };
  1836. };
  1837. };
  1838. deleteResult( result );
  1839. };
  1840. return tVal;
  1841. };
  1842. KAFKA_TEMPLATE *argusDBC::getKafkaTemplateForEvent( uint32_t ModuleID, uint32_t ClassID, uint32_t EventID ){
  1843. KAFKA_TEMPLATE *tVal = NULL;
  1844. if( m_bIsConnected ) {
  1845. char tQBuf[CTEXT];
  1846. AAssoc *result;
  1847. sprintf( tQBuf, "SELECT topic, template FROM module_kafka_settings WHERE module_id=%d AND class_id=%d AND event_id=%d", ModuleID, ClassID, EventID );
  1848. #ifdef DEBUG
  1849. LOG(tQBuf);
  1850. #endif
  1851. result = m_pDatabase->Query( tQBuf );
  1852. if( result!= NULL ) {
  1853. if( result->size() > 0 ) {
  1854. Assoc *cArr;
  1855. tVal = (KAFKA_TEMPLATE*) malloc(sizeof(KAFKA_TEMPLATE));
  1856. if( tVal != NULL ) {
  1857. Assoc::iterator it;
  1858. cArr = result->at(0);
  1859. it = cArr->find("topic");
  1860. if( it != cArr->end() ){
  1861. memset( tVal->topic, 0, 128 );
  1862. strncpy( tVal->topic , it->second.c_str(), 127 );
  1863. };
  1864. it = cArr->find("template");
  1865. if( it != cArr->end() ){
  1866. tVal->tpl = (CSTR)malloc( it->second.length() + 1 );
  1867. if( tVal->tpl!= NULL) {
  1868. memset( tVal->tpl, 0, it->second.length() + 1 );
  1869. strncpy( tVal->tpl, it->second.c_str(), it->second.length() );
  1870. };
  1871. };
  1872. };
  1873. };
  1874. };
  1875. deleteResult( result );
  1876. };
  1877. return tVal;
  1878. };
  1879. DBC_UART_DATA *argusDBC::getUartData( uint32_t UartID ){
  1880. DBC_UART_DATA *tVal = NULL;
  1881. if( m_bIsConnected ) {
  1882. char tQBuf[MAX_PATH_LEN];
  1883. AAssoc *result;
  1884. sprintf( tQBuf, "SELECT * FROM uart_settings WHERE id = %d", UartID );
  1885. #ifdef DEBUG
  1886. //LOG(tQBuf);
  1887. #endif
  1888. result = m_pDatabase->Query( tQBuf );
  1889. if( result!= NULL ) {
  1890. if( result->size() > 0 ) {
  1891. Assoc *cArr;
  1892. tVal = (DBC_UART_DATA*) malloc(sizeof(DBC_UART_DATA));
  1893. if( tVal != NULL ) {
  1894. Assoc::iterator it;
  1895. cArr = result->at(0);
  1896. it = cArr->find("type");
  1897. if( it != cArr->end() ){
  1898. tVal->type = atoi( it->second.c_str() );
  1899. };
  1900. it = cArr->find("speed");
  1901. if( it != cArr->end() ){
  1902. tVal->speed = atoi( it->second.c_str() );
  1903. };
  1904. it = cArr->find("mode");
  1905. if( it != cArr->end() ){
  1906. tVal->mode = atoi( it->second.c_str() );
  1907. };
  1908. it = cArr->find("port");
  1909. if( it != cArr->end() ){
  1910. tVal->port = atoi( it->second.c_str() );
  1911. };
  1912. it = cArr->find("path");
  1913. if( it != cArr->end() ){
  1914. strncpy( tVal->path, it->second.c_str(), 128 );
  1915. };
  1916. };
  1917. };
  1918. };
  1919. deleteResult( result );
  1920. };
  1921. return tVal;
  1922. };
  1923. bool argusDBC::updateMediaServerStream( uint32_t id, CSTR mrl, CSTR key ){
  1924. if( m_bIsConnected ) {
  1925. char tQBuf[MAX_PATH_LEN];
  1926. #ifdef DEBUG
  1927. LOG("Stream Update");
  1928. #endif
  1929. if( key == NULL ) {
  1930. if( mrl == NULL ) {
  1931. sprintf( tQBuf,"UPDATE media_server_streams SET `online`=0, `key`='', mrl='', `valid`=0 WHERE `id`=%d", id );
  1932. } else {
  1933. sprintf( tQBuf,"UPDATE media_server_streams SET `online`=0, `key`='', `mrl`='%s', `valid`=1 WHERE `id`=%d", mrl, id );
  1934. };
  1935. } else {
  1936. sprintf( tQBuf,"UPDATE media_server_streams SET `online`=1, `key`='%s', `mrl`='%s', `valid`=1 WHERE `id`=%d",
  1937. key,
  1938. mrl,
  1939. id
  1940. );
  1941. };
  1942. #ifdef DEBUG
  1943. LOG(tQBuf);
  1944. #endif
  1945. m_pDatabase->SilentQuery( tQBuf );
  1946. return true;
  1947. };
  1948. return false;
  1949. };
  1950. bool argusDBC::addLocalDCB( uint32_t SiteID, CSTR PATH, CSTR SERIAL, uint8_t CNT, uint32_t status ){
  1951. if( m_bIsConnected ) {
  1952. char tQBuf[MAX_PATH_LEN];
  1953. LOG("Before Sff");
  1954. 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",
  1955. SiteID,
  1956. status,
  1957. CNT,
  1958. SERIAL,
  1959. status,
  1960. CNT
  1961. );
  1962. #ifdef DEBUG
  1963. LOG(tQBuf);
  1964. #endif
  1965. uint64_t cid = m_pDatabase->QueryID( tQBuf );
  1966. if( cid == 0 ) {
  1967. AAssoc *result;
  1968. sprintf( tQBuf, "SELECT id FROM modules_dcr WHERE site_id=%d AND serial_id='%s'",
  1969. SiteID,
  1970. SERIAL
  1971. );
  1972. #ifdef DEBUG
  1973. LOG(tQBuf);
  1974. #endif
  1975. result = m_pDatabase->Query( tQBuf );
  1976. if( result!= NULL ) {
  1977. if( result->size() > 0 ) {
  1978. Assoc * cArr;
  1979. Assoc::iterator it;
  1980. cArr = result->at(0);
  1981. it = cArr->find("id");
  1982. if( it != cArr->end() ){
  1983. cid = atoi( it->second.c_str() );
  1984. };
  1985. };
  1986. deleteResult( result );
  1987. };
  1988. };
  1989. if( cid!= 0 ) {
  1990. for( uint8_t idx = 0; idx < CNT; idx++ ) {
  1991. if( status & ( 1 << idx ) ){
  1992. sprintf( tQBuf, "INSERT INTO module_dcr_chanels SET dcr_id=%d, channel_id=%d, mode='O', status='C' ON DUPLICATE KEY UPDATE status='C'",
  1993. (uint32_t) cid,
  1994. idx
  1995. );
  1996. } else {
  1997. sprintf( tQBuf, "INSERT INTO module_dcr_chanels SET dcr_id=%d, channel_id=%d, mode='O', status='O' ON DUPLICATE KEY UPDATE status='O'",
  1998. (uint32_t) cid,
  1999. idx
  2000. );
  2001. }
  2002. #ifdef DEBUG
  2003. LOG(tQBuf);
  2004. #endif
  2005. m_pDatabase->SilentQuery( tQBuf );
  2006. };
  2007. };
  2008. return true;
  2009. };
  2010. return false;
  2011. };
  2012. bool argusDBC::addDraw( uint32_t DBID, uint16_t SIZE, CSTR ID ){
  2013. if( m_bIsConnected ) {
  2014. char tQBuf[MAX_PATH_LEN];
  2015. 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",
  2016. DBID,
  2017. ID,
  2018. SIZE,
  2019. ID,
  2020. SIZE
  2021. );
  2022. #ifdef DEBUG
  2023. LOG(tQBuf);
  2024. #endif
  2025. m_pDatabase->SilentQuery( tQBuf );
  2026. return true;
  2027. };
  2028. return false;
  2029. };
  2030. uint32_t argusDBC::addEvent( uint32_t SRC, CSTR UUID, uint32_t tss, uint32_t tsms, uint8_t evt_type, uint16_t dig_r, float AZ, float EL, float RANGE, float AREA, float lat, float lon, float alt, uint32_t RefID, CSTR RefUUID ){
  2031. uint32_t RetVal = 0;
  2032. if( m_bIsConnected ) {
  2033. char tQBuf[MAX_PATH_LEN];
  2034. if( RefUUID == NULL ) {
  2035. sprintf( tQBuf,"INSERT INTO events_cloud SET node_id=%d, uuid='%s', ts=%d, ts_ms=%d, evt_type=%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",
  2036. SRC,
  2037. UUID,
  2038. tss,
  2039. tsms,
  2040. evt_type,
  2041. dig_r,
  2042. AZ,
  2043. EL,
  2044. RANGE,
  2045. AREA,
  2046. lat,
  2047. lon,
  2048. alt
  2049. );
  2050. } else {
  2051. sprintf( tQBuf,"INSERT INTO events_cloud SET node_id=%d, uuid='%s', ts=%d, ts_ms=%d, evt_type=%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'",
  2052. SRC,
  2053. UUID,
  2054. tss,
  2055. tsms,
  2056. evt_type,
  2057. dig_r,
  2058. AZ,
  2059. EL,
  2060. RANGE,
  2061. AREA,
  2062. lat,
  2063. lon,
  2064. alt,
  2065. RefUUID
  2066. );
  2067. };
  2068. #ifdef DEBUG
  2069. // LOG(tQBuf);
  2070. #endif
  2071. RetVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
  2072. };
  2073. return RetVal;
  2074. };
  2075. bool argusDBC::addVideoEvent( uint32_t evtID, uint32_t videoID ){
  2076. if( m_bIsConnected ) {
  2077. char tQBuf[MAX_PATH_LEN];
  2078. sprintf( tQBuf, "INSERT INTO `events_video_records` SET `evt_id`=%d, `video_id`=%d", evtID, videoID );
  2079. m_pDatabase->SilentQuery( tQBuf );
  2080. return true;
  2081. };
  2082. return true;
  2083. };
  2084. uint32_t argusDBC::addVideoRecord( uint32_t streamID, CSTR md5, uint32_t partID ){
  2085. uint32_t tID = 0;
  2086. if( m_bIsConnected ) {
  2087. char tQBuf[MAX_PATH_LEN];
  2088. sprintf( tQBuf, "INSERT INTO `video_records` SET `media_stream_id`=%d, `ts`=NOW(), `md5`='%s', `part_id`=%d ", streamID, md5, partID );
  2089. tID = (uint32_t) m_pDatabase->QueryID( tQBuf );
  2090. }
  2091. return tID;
  2092. };
  2093. DBC_KRNL_CMD *argusDBC::getActiveCommand( uint32_t SiteID ){
  2094. DBC_KRNL_CMD *tPtr = NULL;
  2095. if( m_bIsConnected ) {
  2096. char tQBuf[MAX_PATH_LEN];
  2097. AAssoc *result;
  2098. sprintf( tQBuf, "SELECT * FROM `cmd_queue` WHERE `status`=0 AND `site_id`=%d", SiteID );
  2099. result = m_pDatabase->Query( tQBuf );
  2100. if( result != NULL ) {
  2101. if( result->size() > 0 ) {
  2102. Assoc *cArr;
  2103. tPtr = (DBC_KRNL_CMD*)malloc(sizeof(DBC_KRNL_CMD));
  2104. if( tPtr!= NULL ) {
  2105. Assoc::iterator it;
  2106. memset(tPtr,0,sizeof(DBC_KRNL_CMD));
  2107. cArr = result->at(0);
  2108. it = cArr->find("id");
  2109. if( it != cArr->end() ){
  2110. tPtr->id = atoi( it->second.c_str() );
  2111. };
  2112. it = cArr->find("cmd");
  2113. if( it != cArr->end() ){
  2114. tPtr->cmd = atoi( it->second.c_str() );
  2115. };
  2116. it = cArr->find("param");
  2117. if( it != cArr->end() ){
  2118. strncpy( tPtr->param, it->second.c_str(), 255 );
  2119. };
  2120. it = cArr->find("aux_param");
  2121. if( it != cArr->end() ){
  2122. strncpy( tPtr->aux_param, it->second.c_str(), 255 );
  2123. };
  2124. };
  2125. };
  2126. };
  2127. deleteResult( result );
  2128. };
  2129. return tPtr;
  2130. };
  2131. bool argusDBC::updateCommand( uint32_t CMD_ID, uint8_t STATUS ){
  2132. if( m_bIsConnected ) {
  2133. char tQBuf[MAX_PATH_LEN];
  2134. sprintf( tQBuf, "UPDATE `cmd_queue` SET `status`=%d WHERE id=%d", STATUS, CMD_ID );
  2135. m_pDatabase->SilentQuery( tQBuf );
  2136. return true;
  2137. };
  2138. return false;
  2139. };
  2140. 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 ){
  2141. if( m_bIsConnected ) {
  2142. char tQBuf[MAX_PATH_LEN];
  2143. 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",
  2144. nOrder,
  2145. nOffset,
  2146. nDelta,
  2147. nFlip,
  2148. nWidth,
  2149. bSST,
  2150. nSun,
  2151. lrf_id );
  2152. #ifdef DEBUG
  2153. LOG(tQBuf);
  2154. #endif
  2155. m_pDatabase->SilentQuery( tQBuf );
  2156. return true;
  2157. };
  2158. return false;
  2159. };
  2160. 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 ){
  2161. if( m_bIsConnected ) {
  2162. char tQBuf[MAX_PATH_LEN];
  2163. 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",
  2164. nOrder,
  2165. nOffset,
  2166. nDelta,
  2167. nFlip,
  2168. nWidth,
  2169. bSST,
  2170. nSun,
  2171. lrf_id );
  2172. #ifdef DEBUG
  2173. LOG(tQBuf);
  2174. #endif
  2175. m_pDatabase->SilentQuery( tQBuf );
  2176. return true;
  2177. };
  2178. return false;
  2179. };
  2180. bool argusDBC::updateAFPBox( uint32_t filterID, CSTR Tag, float x, float y, float z ){
  2181. if( m_bIsConnected ) {
  2182. char tQBuf[MAX_PATH_LEN];
  2183. 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",
  2184. filterID,
  2185. Tag,
  2186. x,y,z,
  2187. x,y,z
  2188. );
  2189. #ifdef DEBUG
  2190. //LOG(tQBuf);
  2191. #endif
  2192. m_pDatabase->SilentQuery( tQBuf );
  2193. return true;
  2194. };
  2195. return false;
  2196. };
  2197. DBC_EVT_DATA *argusDBC::getEventByUUID( CSTR UUID ){
  2198. DBC_EVT_DATA *tPtr = NULL;
  2199. if( m_bIsConnected ) {
  2200. char tQBuf[MAX_PATH_LEN];
  2201. AAssoc *result;
  2202. sprintf( tQBuf, "SELECT * FROM events_cloud WHERE uuid = '%s'", UUID );
  2203. #ifdef DEBUG
  2204. //LOG(tQBuf);
  2205. #endif
  2206. result = m_pDatabase->Query( tQBuf );
  2207. if( result!= NULL ) {
  2208. if( result->size() > 0 ) {
  2209. Assoc *cArr;
  2210. tPtr = (DBC_EVT_DATA*)malloc(sizeof(DBC_EVT_DATA));
  2211. if( tPtr!= NULL ) {
  2212. Assoc::iterator it;
  2213. memset(tPtr,0,sizeof(DBC_EVT_DATA));
  2214. cArr = result->at(0);
  2215. it = cArr->find("id");
  2216. if( it != cArr->end() ){
  2217. tPtr->id = atoi( it->second.c_str() );
  2218. };
  2219. it = cArr->find("node_id");
  2220. if( it != cArr->end() ){
  2221. tPtr->node_id = atoi( it->second.c_str() );
  2222. };
  2223. it = cArr->find("uuid");
  2224. if( it != cArr->end() ){
  2225. strncpy( tPtr->uuid, it->second.c_str(),64 );
  2226. };
  2227. it = cArr->find("ts");
  2228. if( it != cArr->end() ){
  2229. tPtr->ts_s = atoi( it->second.c_str() );
  2230. };
  2231. it = cArr->find("ts_ms");
  2232. if( it != cArr->end() ){
  2233. tPtr->ts_ms = atoi( it->second.c_str() );
  2234. };
  2235. it = cArr->find("evt_type");
  2236. if( it != cArr->end() ){
  2237. tPtr->type = atoi( it->second.c_str() );
  2238. };
  2239. it = cArr->find("range_digital");
  2240. if( it != cArr->end() ){
  2241. tPtr->range_digital = atoi( it->second.c_str() );
  2242. };
  2243. it = cArr->find("azimuth");
  2244. if( it != cArr->end() ){
  2245. tPtr->az = atof( it->second.c_str() );
  2246. };
  2247. it = cArr->find("elevation");
  2248. if( it != cArr->end() ){
  2249. tPtr->el = atof( it->second.c_str() );
  2250. };
  2251. it = cArr->find("range");
  2252. if( it != cArr->end() ){
  2253. tPtr->ra = atof( it->second.c_str() );
  2254. };
  2255. it = cArr->find("area");
  2256. if( it != cArr->end() ){
  2257. tPtr->area = atof( it->second.c_str() );
  2258. };
  2259. it = cArr->find("lat");
  2260. if( it != cArr->end() ){
  2261. tPtr->lat = atof( it->second.c_str() );
  2262. };
  2263. it = cArr->find("lon");
  2264. if( it != cArr->end() ){
  2265. tPtr->lon = atof( it->second.c_str() );
  2266. };
  2267. it = cArr->find("alt");
  2268. if( it != cArr->end() ){
  2269. tPtr->alt = atof( it->second.c_str() );
  2270. };
  2271. it = cArr->find("ref_id");
  2272. if( it != cArr->end() ){
  2273. tPtr->ref_id = atoi( it->second.c_str() );
  2274. };
  2275. it = cArr->find("ref_uuid");
  2276. if( it != cArr->end() ){
  2277. strncpy( tPtr->ref_uuid, it->second.c_str(),64 );
  2278. };
  2279. };
  2280. };
  2281. };
  2282. deleteResult( result );
  2283. };
  2284. return tPtr;
  2285. };
  2286. #undef LOG
  2287. #undef LOG_ERROR