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.

4019 lines
145 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
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
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_nSiteID = 0;
  30. m_pDatabase = NULL;
  31. };
  32. argusDBC::~argusDBC(){
  33. m_bIsConnected = false;
  34. if( m_pDatabase != NULL ) delete( m_pDatabase );
  35. m_pDatabase = NULL;
  36. _instance = NULL;
  37. };
  38. bool argusDBC::connect( void ){
  39. config_setting_t * tSetting;
  40. m_bIsConnected = false;
  41. if( m_pSettings!= NULL ) {
  42. tSetting = config_setting_get_member( m_pSettings, "DATABASE_HOST" );
  43. if( tSetting == NULL ){
  44. tSetting = config_setting_add(m_pSettings, "DATABASE_HOST", CONFIG_TYPE_STRING );
  45. config_setting_set_string( tSetting, "localhost" );
  46. basicSettingsProvider::getInstance()->compromise();
  47. LOG("No DB Host Setting! Using default!");
  48. };
  49. sprintf(m_pDbHost, "%s", config_setting_get_string(tSetting));
  50. tSetting = config_setting_get_member( m_pSettings, "DATABASE_NAME" );
  51. if( tSetting == NULL ){
  52. tSetting = config_setting_add(m_pSettings, "DATABASE_NAME", CONFIG_TYPE_STRING );
  53. config_setting_set_string( tSetting, "dfsl_gunter" );
  54. basicSettingsProvider::getInstance()->compromise();
  55. LOG("No DB Database Setting! Using default!");
  56. };
  57. sprintf(m_pDbDatabase, "%s", config_setting_get_string(tSetting));
  58. tSetting = config_setting_get_member( m_pSettings, "DATABASE_USER" );
  59. if( tSetting == NULL ){
  60. tSetting = config_setting_add(m_pSettings, "DATABASE_USER", CONFIG_TYPE_STRING );
  61. config_setting_set_string( tSetting, "dbroot" );
  62. basicSettingsProvider::getInstance()->compromise();
  63. LOG("No DB User Setting! Using default!");
  64. };
  65. sprintf(m_pDbUsername, "%s", config_setting_get_string(tSetting));
  66. tSetting = config_setting_get_member( m_pSettings, "DATABASE_PASSWORD" );
  67. if( tSetting == NULL ){
  68. tSetting = config_setting_add(m_pSettings, "DATABASE_PASSWORD", CONFIG_TYPE_STRING );
  69. config_setting_set_string( tSetting, "123567" );
  70. basicSettingsProvider::getInstance()->compromise();
  71. LOG("No DB Password Setting! Using default!");
  72. };
  73. sprintf(m_pDbPassword, "%s", config_setting_get_string(tSetting));
  74. basicSettingsProvider::getInstance()->validate();
  75. m_pDatabase = new MySQL_Connector();
  76. if( m_pDatabase == NULL )return false;
  77. m_bIsConnected = m_pDatabase->Connect( m_pDbDatabase, m_pDbHost, m_pDbUsername, m_pDbPassword );
  78. } else {
  79. LOG_ERROR("No Settings Provided!");
  80. };
  81. return m_bIsConnected;
  82. };
  83. bool argusDBC::cleanResources( uint32_t ServerNodeID, bool all ){
  84. if(m_bIsConnected) {
  85. char tQBuf[MAX_PATH_LEN];
  86. if( all ) {
  87. sprintf( tQBuf, "UPDATE `resources` SET `active`=0 WHERE `node_id`=%d", ServerNodeID );
  88. } else {
  89. sprintf( tQBuf, "UPDATE `resources` SET `active`=0 WHERE ( `node_id`=%d ) AND ( `type`=100 OR `type`=101 OR `type`=103 OR `type`=120 )", ServerNodeID );
  90. };
  91. #ifdef DEBUG_EXTRA
  92. LOG(tQBuf);
  93. #endif
  94. m_pDatabase->SilentQuery( tQBuf );
  95. return true;
  96. };
  97. return false;
  98. };
  99. bool argusDBC::cleanLRFMask( uint32_t maskID, bool deleteMask ){
  100. if(m_bIsConnected) {
  101. char tQBuf[MAX_PATH_LEN];
  102. sprintf( tQBuf, "DELETE FROM `lrf_mask_trace_zones` WHERE `zone_id` IN ( SELECT `id` FROM `lrf_mask_traces` WHERE `mask_id`=%d )", maskID );
  103. #ifdef DEBUG_EXTRA
  104. LOG(tQBuf);
  105. #endif
  106. m_pDatabase->SilentQuery( tQBuf );
  107. sprintf( tQBuf, "DELETE FROM `lrf_mask_traces` WHERE `mask_id`=%d", maskID );
  108. #ifdef DEBUG_EXTRA
  109. LOG(tQBuf);
  110. #endif
  111. m_pDatabase->SilentQuery( tQBuf );
  112. sprintf( tQBuf, "DELETE FROM `lrf_mask_vertex_points` WHERE `vertex_id` IN ( SELECT `id` FROM `lrf_mask_vertexes` WHERE `mask_id`=%d )", maskID );
  113. #ifdef DEBUG_EXTRA
  114. LOG(tQBuf);
  115. #endif
  116. m_pDatabase->SilentQuery( tQBuf );
  117. sprintf( tQBuf, "DELETE FROM `lrf_mask_vertexes` WHERE `mask_id`=%d", maskID );
  118. #ifdef DEBUG_EXTRA
  119. LOG(tQBuf);
  120. #endif
  121. m_pDatabase->SilentQuery( tQBuf );
  122. //Delete Mask Itself!
  123. if ( deleteMask ) {
  124. sprintf( tQBuf, "DELETE FROM `lrf_masks` WHERE `id`=%d", maskID );
  125. #ifdef DEBUG_EXTRA
  126. LOG(tQBuf);
  127. #endif
  128. m_pDatabase->SilentQuery( tQBuf );
  129. };
  130. return true;
  131. };
  132. return false;
  133. };
  134. bool argusDBC::updateIPCam( uint32_t SiteID, CSTR uuid, CSTR Addr ){
  135. if(m_bIsConnected) {
  136. char tQBuf[MAX_PATH_LEN];
  137. char tIpBuf[CTEXT];
  138. char *tPos;
  139. char *tPos2;
  140. tPos = strstr(Addr,"//");
  141. if( tPos != NULL ) {
  142. tPos2 = strstr( tPos + 2,"/");
  143. if( tPos2 != NULL ) {
  144. int len;
  145. len = tPos2 - tPos - 2;
  146. strncpy(tIpBuf,tPos + 2,len);
  147. tIpBuf[len] = (char)0;
  148. } else {
  149. LOG_ERROR("Pos 2 - err");
  150. tIpBuf[0] = (char)0;
  151. };
  152. } else {
  153. LOG_ERROR("Pos 0 - err");
  154. tIpBuf[0] = (char)0;
  155. };
  156. sprintf(tQBuf,"UPDATE cameras SET `online`=1,`onvif_ctrl`='%s', `ip`='%s' WHERE `uuid`='%s' AND `site_id`=%d",
  157. Addr,
  158. tIpBuf,
  159. uuid,
  160. SiteID
  161. );
  162. #ifdef DEBUG_EXTRA
  163. LOG(tQBuf);
  164. #endif
  165. m_pDatabase->SilentQuery( tQBuf );
  166. return true;
  167. };
  168. return false;
  169. };
  170. bool argusDBC::updateIPCam( uint32_t SiteID, uint32_t CamID, CSTR Addr ){
  171. if(m_bIsConnected) {
  172. char tQBuf[MAX_PATH_LEN];
  173. char tIpBuf[CTEXT];
  174. char *tPos;
  175. char *tPos2;
  176. tPos = strstr(Addr,"//");
  177. if( tPos != NULL ) {
  178. tPos2 = strstr( tPos + 2,"/");
  179. if( tPos2 != NULL ) {
  180. int len;
  181. len = tPos2 - tPos - 2;
  182. strncpy(tIpBuf,tPos + 2,len);
  183. tIpBuf[len] = (char)0;
  184. } else {
  185. LOG_ERROR("Pos 2 - err");
  186. tIpBuf[0] = (char)0;
  187. };
  188. } else {
  189. LOG_ERROR("Pos 0 - err");
  190. tIpBuf[0] = (char)0;
  191. };
  192. sprintf(tQBuf,"UPDATE cameras SET `online`=1, `onvif_ctrl`='%s', `ip`='%s' WHERE id=%d AND `site_id`=%d",
  193. Addr,
  194. tIpBuf,
  195. CamID,
  196. SiteID
  197. );
  198. #ifdef DEBUG_EXTRA
  199. LOG(tQBuf);
  200. #endif
  201. m_pDatabase->SilentQuery( tQBuf );
  202. sprintf(tQBuf,"UPDATE media_streams SET `valid`=1 WHERE source_id=%d AND source_type='D'", CamID );
  203. #ifdef DEBUG_EXTRA
  204. LOG(tQBuf);
  205. #endif
  206. m_pDatabase->SilentQuery( tQBuf );
  207. return true;
  208. };
  209. return false;
  210. };
  211. /*
  212. bool argusDBC::addIPCam( uint32_t SiteID, resultWoWo *tPtr ){
  213. if(m_bIsConnected) {
  214. char tQBuf[1024];
  215. char tIpBuf[32];
  216. char tProto[32];
  217. char tPath[CTEXT];
  218. char *tPos;
  219. char *tPos2;
  220. memcpy( tProto, tPtr->XAddrs, 5 );
  221. tProto[5] = (char)0;
  222. if( tProto[4] == ':') tProto[4] = (char)0;
  223. memset( tPath, 0, CTEXT );
  224. tPos = strstr(tPtr->XAddrs,"//");
  225. if( tPos != NULL ) {
  226. tPos2 = strstr( tPos + 2,"/");
  227. if( tPos2 != NULL ) {
  228. int len,len2,len3;
  229. len = tPos2 - tPos - 2;
  230. strncpy( tIpBuf, tPos + 2, len);
  231. tIpBuf[len] = (char)0;
  232. strncpy( tPath, tPos + 2 + len, CTEXT );
  233. } else {
  234. LOG_ERROR("Pos 2 - err");
  235. tIpBuf[0] = (char)0;
  236. };
  237. } else {
  238. LOG_ERROR("Pos 0 - err");
  239. tIpBuf[0] = (char)0;
  240. };
  241. 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'",
  242. tPtr->RefID,
  243. //tPtr->XAddrs,
  244. tPath,
  245. tIpBuf,
  246. SiteID,
  247. tPtr->MAC,
  248. tPtr->Hardware,
  249. tPtr->Name,
  250. tProto,
  251. //tPtr->XAddrs,
  252. tIpBuf
  253. );
  254. #ifdef DEBUG_EXTRA
  255. LOG(tQBuf);
  256. #endif
  257. m_pDatabase->SilentQuery( tQBuf );
  258. return true;
  259. };
  260. return false;
  261. };
  262. */
  263. bool argusDBC::addIPCam( uint32_t SiteID, OBSERVER_RESULT *tPtr ){
  264. if(m_bIsConnected) {
  265. char tQBuf[1024];
  266. char tIpBuf[32];
  267. char tProto[32];
  268. char tPath[CTEXT];
  269. char *tPos;
  270. char *tPos2;
  271. memcpy( tProto, tPtr->XAddrs, 5 );
  272. tProto[5] = (char)0;
  273. if( tProto[4] == ':') tProto[4] = (char)0;
  274. memset( tPath, 0, CTEXT );
  275. tPos = strstr(tPtr->XAddrs,"//");
  276. if( tPos != NULL ) {
  277. tPos2 = strstr( tPos + 2,"/");
  278. if( tPos2 != NULL ) {
  279. int len,len2,len3;
  280. len = tPos2 - tPos - 2;
  281. strncpy( tIpBuf, tPos + 2, len);
  282. tIpBuf[len] = (char)0;
  283. strncpy( tPath, tPos + 2 + len, CTEXT );
  284. } else {
  285. LOG_ERROR("Pos 2 - err");
  286. tIpBuf[0] = (char)0;
  287. };
  288. } else {
  289. LOG_ERROR("Pos 0 - err");
  290. tIpBuf[0] = (char)0;
  291. };
  292. 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'",
  293. tPtr->RefID,
  294. //tPtr->XAddrs,
  295. tPath,
  296. tIpBuf,
  297. SiteID,
  298. tPtr->MAC,
  299. tPtr->Hardware,
  300. tPtr->Name,
  301. tProto,
  302. //tPtr->XAddrs,
  303. tIpBuf
  304. );
  305. #ifdef DEBUG_EXTRA
  306. LOG(tQBuf);
  307. #endif
  308. m_pDatabase->SilentQuery( tQBuf );
  309. return true;
  310. };
  311. return false;
  312. };
  313. bool argusDBC::transferEvtToArchive( uint32_t SECONDS ){
  314. if(m_bIsConnected) {
  315. if( SECONDS > 0 ) {
  316. char tQBuf[CTEXT];
  317. 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 );
  318. m_pDatabase->SilentQuery( tQBuf );
  319. return true;
  320. };
  321. };
  322. return false;
  323. }
  324. /*
  325. bool argusDBC::getLastEvents( vectorEventRecords &VR, uint32_t tss, uint32_t tsms ){
  326. if(m_bIsConnected){
  327. char tQBuf[CTEXT];
  328. AAssoc *result;
  329. sprintf(tQBuf, "SELECT * FROM events_cloud WHERE `ts`>%d AND `ts_ms`>%d", tss, tsms );
  330. result = m_pDatabase->Query( tQBuf );
  331. if( result!= NULL ) {
  332. DBC_EVT_DATA *tPtr;
  333. Assoc *cArr;
  334. for(int i=0;i<result->size();i++) {
  335. cArr = result->at(i);
  336. tPtr = (DBC_EVT_DATA*)malloc(sizeof(DBC_EVT_DATA));
  337. if( tPtr!= NULL ) {
  338. Assoc::iterator it;
  339. memset(tPtr,0,sizeof(DBC_EVT_DATA));
  340. it = cArr->find("id");
  341. if( it != cArr->end() ){
  342. tPtr->id = atoi( it->second.c_str() );
  343. };
  344. it = cArr->find("node_id");
  345. if( it != cArr->end() ){
  346. tPtr->node_id = atoi( it->second.c_str() );
  347. };
  348. it = cArr->find("uuid");
  349. if( it != cArr->end() ){
  350. strncpy( tPtr->uuid, it->second.c_str(),64 );
  351. };
  352. it = cArr->find("ts");
  353. if( it != cArr->end() ){
  354. tPtr->ts_s = atoi( it->second.c_str() );
  355. };
  356. it = cArr->find("ts_ms");
  357. if( it != cArr->end() ){
  358. tPtr->ts_ms = atoi( it->second.c_str() );
  359. };
  360. it = cArr->find("evt_type");
  361. if( it != cArr->end() ){
  362. tPtr->type = atoi( it->second.c_str() );
  363. };
  364. it = cArr->find("range_digital");
  365. if( it != cArr->end() ){
  366. tPtr->range_digital = atoi( it->second.c_str() );
  367. };
  368. it = cArr->find("azimuth");
  369. if( it != cArr->end() ){
  370. tPtr->az = atof( it->second.c_str() );
  371. };
  372. it = cArr->find("elevation");
  373. if( it != cArr->end() ){
  374. tPtr->el = atof( it->second.c_str() );
  375. };
  376. it = cArr->find("range");
  377. if( it != cArr->end() ){
  378. tPtr->ra = atof( it->second.c_str() );
  379. };
  380. it = cArr->find("area");
  381. if( it != cArr->end() ){
  382. tPtr->area = atof( it->second.c_str() );
  383. };
  384. it = cArr->find("lat");
  385. if( it != cArr->end() ){
  386. tPtr->lat = atof( it->second.c_str() );
  387. };
  388. it = cArr->find("lon");
  389. if( it != cArr->end() ){
  390. tPtr->lon = atof( it->second.c_str() );
  391. };
  392. it = cArr->find("alt");
  393. if( it != cArr->end() ){
  394. tPtr->alt = atof( it->second.c_str() );
  395. };
  396. it = cArr->find("ref_uuid");
  397. if( it != cArr->end() ){
  398. strncpy( tPtr->uuid, it->second.c_str(),64 );
  399. };
  400. char tBuf[CLOG];
  401. sprintf(tBuf,"Evt: %d %d %d", tPtr->type, tPtr->ts_s, tPtr->ts_ms );
  402. LOG(tBuf);
  403. VR.push_back(tPtr);
  404. };
  405. };
  406. };
  407. deleteResult( result );
  408. if( m_pDatabase->isConnected()) return true;
  409. };
  410. return false;
  411. };
  412. */
  413. bool argusDBC::getAllCamRecords( uint32_t SiteID, vectorCamRecords &VR ){
  414. if(m_bIsConnected){
  415. char tQBuf[CTEXT];
  416. AAssoc *result;
  417. sprintf(tQBuf, "SELECT * FROM cameras WHERE `site_id`=%d AND `type`=2 AND `status`=2", SiteID );
  418. #ifdef DEBUG_EXTRA
  419. LOG(tQBuf);
  420. #endif
  421. result = m_pDatabase->Query( tQBuf );
  422. if( result!= NULL ) {
  423. DBC_CAM_DATA *tVal;
  424. Assoc *cArr;
  425. for(int i=0;i<result->size();i++) {
  426. LOG("Cam_Record!");
  427. cArr = result->at(i);
  428. tVal = (DBC_CAM_DATA*)malloc(sizeof(DBC_CAM_DATA));
  429. if( tVal!= NULL ) {
  430. Assoc::iterator it;
  431. memset(tVal,0,sizeof(DBC_CAM_DATA));
  432. it = cArr->find("id");
  433. if( it != cArr->end() ){
  434. tVal->id = atoi( it->second.c_str() );
  435. };
  436. it = cArr->find("site_id");
  437. if( it != cArr->end() ){
  438. tVal->site_id = atoi( it->second.c_str() );
  439. };
  440. it = cArr->find("node_id");
  441. if( it != cArr->end() ){
  442. tVal->node_id = atoi( it->second.c_str() );
  443. };
  444. it = cArr->find("online");
  445. if( it != cArr->end() ){
  446. tVal->online = (bool) atoi( it->second.c_str() );
  447. };
  448. it = cArr->find("type");
  449. if( it != cArr->end() ){
  450. tVal->type = atoi( it->second.c_str() );
  451. };
  452. it = cArr->find("name");
  453. if( it != cArr->end() ){
  454. strncpy( tVal->name, it->second.c_str(), 64 );
  455. };
  456. it = cArr->find("hardware");
  457. if( it != cArr->end() ){
  458. strncpy( tVal->hardware, it->second.c_str(), 32 );
  459. };
  460. it = cArr->find("status");
  461. if( it != cArr->end() ){
  462. tVal->status = atoi( it->second.c_str() );
  463. };
  464. it = cArr->find("session");
  465. if( it != cArr->end() ){
  466. strncpy( tVal->session, it->second.c_str(), 32 );
  467. };
  468. it = cArr->find("protocol");
  469. if( it != cArr->end() ){
  470. tVal->protocol = atoi( it->second.c_str() );
  471. };
  472. it = cArr->find("protocol_aux");
  473. if( it != cArr->end() ){
  474. tVal->protocol_aux = atoi( it->second.c_str() );
  475. };
  476. it = cArr->find("x");
  477. if( it != cArr->end() ){
  478. tVal->x = atof( it->second.c_str() );
  479. };
  480. it = cArr->find("y");
  481. if( it != cArr->end() ){
  482. tVal->y = atof( it->second.c_str() );
  483. };
  484. it = cArr->find("z");
  485. if( it != cArr->end() ){
  486. tVal->z = atof( it->second.c_str() );
  487. };
  488. it = cArr->find("x_rot");
  489. if( it != cArr->end() ){
  490. tVal->x_rot = atof( it->second.c_str() );
  491. };
  492. it = cArr->find("y_rot");
  493. if( it != cArr->end() ){
  494. tVal->y_rot = atof( it->second.c_str() );
  495. };
  496. it = cArr->find("z_rot");
  497. if( it != cArr->end() ){
  498. tVal->z_rot = atof( it->second.c_str() );
  499. };
  500. it = cArr->find("imager_type");
  501. if( it != cArr->end() ){
  502. tVal->imager_type = atoi( it->second.c_str() );
  503. };
  504. it = cArr->find("min_f");
  505. if( it != cArr->end() ){
  506. tVal->min_f = atof( it->second.c_str() );
  507. };
  508. it = cArr->find("max_f");
  509. if( it != cArr->end() ){
  510. tVal->max_f = atof( it->second.c_str() );
  511. };
  512. it = cArr->find("access_login");
  513. if( it != cArr->end() ){
  514. strncpy( tVal->username, it->second.c_str(), 16 );
  515. };
  516. it = cArr->find("access_pass");
  517. if( it != cArr->end() ){
  518. strncpy( tVal->password, it->second.c_str(), 16 );
  519. };
  520. it = cArr->find("uuid");
  521. if( it != cArr->end() ){
  522. strncpy( tVal->uuid, it->second.c_str(), CLOG );
  523. };
  524. it = cArr->find("mac");
  525. if( it != cArr->end() ){
  526. strncpy( tVal->mac, it->second.c_str(), 16 );
  527. };
  528. it = cArr->find("ip");
  529. if( it != cArr->end() ){
  530. strncpy( tVal->ip, it->second.c_str(), 16 );
  531. };
  532. it = cArr->find("port");
  533. if( it != cArr->end() ){
  534. tVal->port = atoi( it->second.c_str() );
  535. };
  536. it = cArr->find("onvif_access");
  537. if( it != cArr->end() ){
  538. strncpy( tVal->onvif_access, it->second.c_str(), 5);
  539. };
  540. it = cArr->find("onvif_ctrl");
  541. if( it != cArr->end() ){
  542. strncpy( tVal->onvif_ctrl, it->second.c_str(), 250);
  543. };
  544. it = cArr->find("ptz_token");
  545. if( it != cArr->end() ){
  546. strncpy( tVal->ptz_token, it->second.c_str(), 64);
  547. };
  548. VR.push_back(tVal);
  549. };
  550. //??
  551. //delete(cArr);
  552. };
  553. };
  554. deleteResult( result );
  555. #ifdef DEBUG
  556. sprintf( tQBuf,"Now %d Camera Records in System", VR.size());
  557. LOG(tQBuf);
  558. #endif
  559. if( m_pDatabase->isConnected()) return true;
  560. };
  561. return false;
  562. };
  563. DBC_INT_LIST *argusDBC::listNodes( uint32_t SiteID ){
  564. DBC_INT_LIST * tVal = NULL;
  565. if( m_bIsConnected ){
  566. char tQBuf[1024];
  567. AAssoc *result;
  568. sprintf( tQBuf, "SELECT `id` FROM `nodes` WHERE `site_id`=%d AND `type` > 0", SiteID );
  569. #ifdef DEBUG_EXTRA
  570. LOG(tQBuf);
  571. #endif
  572. result = m_pDatabase->Query( tQBuf );
  573. if( result!= NULL ) {
  574. if( result->size() > 0 ) {
  575. Assoc *cArr;
  576. tVal = new DBC_INT_LIST();
  577. if( tVal != NULL ) {
  578. Assoc::iterator it;
  579. for(int i=0; i <result->size();i++) {
  580. cArr = result->at(i);
  581. it = cArr->find("id");
  582. if( it != cArr->end() ){
  583. tVal->push_back( atoi( it->second.c_str() ));
  584. };
  585. };
  586. };
  587. };
  588. };
  589. deleteResult( result );
  590. };
  591. return tVal;
  592. };
  593. DBC_INT_LIST *argusDBC::listNewNodes( uint32_t SiteID, DBC_INT_LIST *old_ids ){
  594. DBC_INT_LIST * tVal = NULL;
  595. char tParam[CTEXT];
  596. //memset( tParam, 0, CTEXT );
  597. sprintf(tParam,"0");
  598. if( old_ids != NULL ) {
  599. char tBuffer[CTEXT];
  600. for(int i = 0; i< old_ids->size(); i++ ) {
  601. sprintf( tBuffer, "%s,%d", tParam, old_ids->at(i) );
  602. strncpy( tParam, tBuffer, CTEXT );
  603. };
  604. };
  605. if( m_bIsConnected ){
  606. char tQBuf[CTEXT];
  607. AAssoc *result;
  608. sprintf(tQBuf, "SELECT id FROM nodes WHERE `site_id`=%d AND `type` > 0 AND `id` NOT IN(%s)", SiteID, tParam );
  609. #ifdef DEBUG_EXTRA
  610. LOG(tQBuf);
  611. #endif
  612. result = m_pDatabase->Query( tQBuf );
  613. if( result!= NULL ) {
  614. if( result->size() > 0 ) {
  615. Assoc *cArr;
  616. tVal = new DBC_INT_LIST();
  617. if( tVal != NULL ) {
  618. Assoc::iterator it;
  619. for(int i=0;i<result->size();i++) {
  620. cArr = result->at(i);
  621. it = cArr->find("id");
  622. if( it != cArr->end() ){
  623. tVal->push_back( atoi( it->second.c_str() ));
  624. };
  625. };
  626. };
  627. };
  628. };
  629. deleteResult( result );
  630. };
  631. return tVal;
  632. };
  633. void argusDBC::lazyEventArchiver( uint32_t DalayTime ){
  634. if( m_bIsConnected ){
  635. char tQBuf[CTEXT];
  636. AAssoc *result;
  637. uint32_t LastID = 0;
  638. sprintf( tQBuf, "SELECT * FROM `events_cloud` WHERE ( UNIX_TIMESTAMP(NOW()) - `ts` ) > %d ORDER BY `id` ASC LIMIT 10", DalayTime );
  639. #ifdef DEBUG_EXTRA
  640. LOG(tQBuf);
  641. #endif
  642. result = m_pDatabase->Query( tQBuf );
  643. if( result!= NULL ) {
  644. if( result->size() > 0 ) {
  645. Assoc *cArr;
  646. for(int i=0;i<result->size();i++){
  647. uint32_t nodeid=0;
  648. char uuid[64]={0};
  649. uint32_t ts=0;
  650. uint32_t ts_ms=0;
  651. uint32_t evt_t=0;
  652. uint32_t range_d=0;
  653. float az=.0f, el=.0f, ra=.0f, ar=.0f, lat=.0f, lon=.0f, alt=.0f;
  654. uint32_t ref_id=0;
  655. char ref_uuid[64]={0};
  656. Assoc::iterator it;
  657. cArr = result->at(i);
  658. it = cArr->find("id");
  659. if( it != cArr->end() ){
  660. LastID = atoi( it->second.c_str());
  661. };
  662. it = cArr->find("node_id");
  663. if( it != cArr->end() ){
  664. nodeid = atoi( it->second.c_str());
  665. };
  666. it = cArr->find("uuid");
  667. if( it != cArr->end() ){
  668. strncpy( uuid, it->second.c_str(), 64 );
  669. };
  670. it = cArr->find("ts");
  671. if( it != cArr->end() ){
  672. ts = atoi( it->second.c_str());
  673. };
  674. it = cArr->find("ts_ms");
  675. if( it != cArr->end() ){
  676. ts_ms = atoi( it->second.c_str());
  677. };
  678. it = cArr->find("evt_type");
  679. if( it != cArr->end() ){
  680. evt_t = atoi( it->second.c_str());
  681. };
  682. it = cArr->find("range_digital");
  683. if( it != cArr->end() ){
  684. range_d = atoi( it->second.c_str());
  685. };
  686. it = cArr->find("azimuth");
  687. if( it != cArr->end() ){
  688. az = (float)atof( it->second.c_str());
  689. };
  690. it = cArr->find("elevation");
  691. if( it != cArr->end() ){
  692. el = (float)atof( it->second.c_str());
  693. };
  694. it = cArr->find("range");
  695. if( it != cArr->end() ){
  696. ra = (float)atof( it->second.c_str());
  697. };
  698. it = cArr->find("area");
  699. if( it != cArr->end() ){
  700. ar = (float)atof( it->second.c_str());
  701. };
  702. it = cArr->find("lat");
  703. if( it != cArr->end() ){
  704. lat = (float)atof( it->second.c_str());
  705. };
  706. it = cArr->find("lon");
  707. if( it != cArr->end() ){
  708. lon = (float)atof( it->second.c_str());
  709. };
  710. it = cArr->find("alt");
  711. if( it != cArr->end() ){
  712. alt = (float)atof( it->second.c_str());
  713. };
  714. it = cArr->find("ref_id");
  715. if( it != cArr->end() ){
  716. ref_id = atoi( it->second.c_str());
  717. };
  718. it = cArr->find("ref_uuid");
  719. if( it != cArr->end() ){
  720. strncpy( ref_uuid, it->second.c_str(), 64 );
  721. };
  722. sprintf(tQBuf, "INSERT INTO `events_archive` SET `node_id`=%d, `uuid`='%s', `ts`=%d, `ts_ms`=%d, `evt_type`=%d, `range_digital`=%d, `azimuth`=%0.8f, `elevation`=%0.8f, `range`=%0.2f, `area`=%0.5f, `lat`=%0.8f, `lon`=%0.8f, `alt`=%0.3f, `ref_id`=%d, `ref_uuid`='%s'",
  723. nodeid,
  724. uuid,
  725. ts,
  726. ts_ms,
  727. evt_t,
  728. range_d,
  729. az,
  730. el,
  731. ra,
  732. ar,
  733. lat,
  734. lon,
  735. alt,
  736. ref_id,
  737. ref_uuid
  738. );
  739. uint32_t IID = (uint32_t) m_pDatabase->QueryID(tQBuf);
  740. sprintf(tQBuf,"UPDATE `events_2_pictures` SET `event_id`=%d WHERE `event_id`=%d", IID, LastID );
  741. //m_pDatabase->SilentQuery(tQBuf);
  742. sprintf(tQBuf,"UPDATE `events_2_videos` SET `event_id`=%d WHERE `event_id`=%d", IID, LastID );
  743. //m_pDatabase->SilentQuery(tQBuf);
  744. };
  745. };
  746. };
  747. deleteResult( result );
  748. };
  749. };
  750. DBC_INT_LIST *argusDBC::listCamMediaStreams( uint32_t CAMID ){
  751. DBC_INT_LIST * tVal = NULL;
  752. if(m_bIsConnected){
  753. char tQBuf[CTEXT];
  754. AAssoc *result;
  755. sprintf(tQBuf, "SELECT id FROM media_streams WHERE `source_id`=%d AND `valid`=1", CAMID );
  756. #ifdef DEBUG_EXTRA
  757. LOG(tQBuf);
  758. #endif
  759. result = m_pDatabase->Query( tQBuf );
  760. if( result!= NULL ) {
  761. if( result->size() > 0 ) {
  762. Assoc *cArr;
  763. tVal = new DBC_INT_LIST();
  764. if( tVal != NULL ) {
  765. Assoc::iterator it;
  766. for(int i=0;i<result->size();i++) {
  767. cArr = result->at(i);
  768. it = cArr->find("id");
  769. if( it != cArr->end() ){
  770. tVal->push_back( atoi( it->second.c_str() ));
  771. };
  772. };
  773. };
  774. };
  775. };
  776. deleteResult( result );
  777. };
  778. return tVal;
  779. };
  780. DBC_NETWORK_DATA *argusDBC::getNetworkData( uint32_t net_id ){
  781. DBC_NETWORK_DATA * tVal = NULL;
  782. if(m_bIsConnected){
  783. char tQBuf[CTEXT];
  784. AAssoc *result;
  785. sprintf(tQBuf, "SELECT * FROM `networks` WHERE `id`=%d", net_id );
  786. #ifdef DEBUG_EXTRA
  787. LOG(tQBuf);
  788. #endif
  789. result = m_pDatabase->Query( tQBuf );
  790. if( result!= NULL ) {
  791. if( result->size() > 0 ) {
  792. Assoc *cArr;
  793. tVal = (DBC_NETWORK_DATA*) malloc(sizeof(DBC_NETWORK_DATA));
  794. if( tVal != NULL ) {
  795. memset(tVal, 0, sizeof(DBC_NETWORK_DATA));
  796. Assoc::iterator it;
  797. tVal->id = net_id;
  798. cArr = result->at(0);
  799. it = cArr->find("nif_id");
  800. if( it != cArr->end() ){
  801. tVal->nif_id = atoi(it->second.c_str());
  802. };
  803. it = cArr->find("type");
  804. if( it != cArr->end() ){
  805. tVal->type = (ARGUS_NETWORK_TYPE) atoi(it->second.c_str());
  806. };
  807. it = cArr->find("address");
  808. if( it != cArr->end() ){
  809. strncpy( tVal->address, it->second.c_str(), 65 );
  810. tVal->address[64]=(char)0;
  811. };
  812. it = cArr->find("gateway");
  813. if( it != cArr->end() ){
  814. strncpy(tVal->gateway, it->second.c_str(), 65);
  815. tVal->gateway[64]=(char)0;
  816. };
  817. it = cArr->find("mask");
  818. if( it != cArr->end() ){
  819. strncpy( tVal->netmask, it->second.c_str(), 65 );
  820. tVal->netmask[64]=(char)0;
  821. };
  822. it = cArr->find("broadcast");
  823. if( it != cArr->end() ){
  824. strncpy( tVal->broadcast, it->second.c_str(), 65 );
  825. tVal->broadcast[64]=(char)0;
  826. };
  827. };
  828. };
  829. };
  830. deleteResult( result );
  831. };
  832. return tVal;
  833. };
  834. DBC_NET_IF_DATA *argusDBC::getNIF_Data( uint32_t nif_id ){
  835. DBC_NET_IF_DATA * tVal = NULL;
  836. if(m_bIsConnected){
  837. char tQBuf[CTEXT];
  838. AAssoc *result;
  839. sprintf(tQBuf, "SELECT `type`, `mode`, `device_name`, `mac`, `aux_id` FROM `network_interfaces` WHERE `id`=%d", nif_id );
  840. #ifdef DEBUG_EXTRA
  841. LOG(tQBuf);
  842. #endif
  843. result = m_pDatabase->Query( tQBuf );
  844. if( result!= NULL ) {
  845. if( result->size() > 0 ) {
  846. Assoc *cArr;
  847. tVal = (DBC_NET_IF_DATA*) malloc(sizeof(DBC_NET_IF_DATA));
  848. if( tVal != NULL ) {
  849. Assoc::iterator it;
  850. tVal->id = nif_id;
  851. cArr = result->at(0);
  852. it = cArr->find("type");
  853. if( it != cArr->end() ){
  854. tVal->type = atoi(it->second.c_str());
  855. };
  856. it = cArr->find("mode");
  857. if( it != cArr->end() ){
  858. tVal->mode = atoi(it->second.c_str());
  859. };
  860. it = cArr->find("device_name");
  861. if( it != cArr->end() ){
  862. strncpy( tVal->device_name, it->second.c_str(),11);
  863. tVal->device_name[10]=(char)0;
  864. };
  865. it = cArr->find("mac");
  866. if( it != cArr->end() ){
  867. strncpy( tVal->mac, it->second.c_str(), 33 );
  868. tVal->mac[32]=(char)0;
  869. };
  870. it = cArr->find("aux_id");
  871. if( it != cArr->end() ){
  872. tVal->aux_id = atoi(it->second.c_str());
  873. };
  874. };
  875. };
  876. };
  877. deleteResult( result );
  878. };
  879. return tVal;
  880. };
  881. uint32_t argusDBC::getNetworkInfrastructureID( uint32_t nif_id ){
  882. uint32_t tVal = 0;
  883. if(m_bIsConnected){
  884. char tQBuf[CTEXT];
  885. AAssoc *result;
  886. sprintf(tQBuf, "SELECT id FROM `network_infrastructure` WHERE `nif_id`=%d", nif_id );
  887. #ifdef DEBUG
  888. LOG(tQBuf);
  889. #endif
  890. result = m_pDatabase->Query( tQBuf );
  891. if( result!= NULL ) {
  892. if( result->size() > 0 ) {
  893. Assoc *cArr;
  894. Assoc::iterator it;
  895. cArr = result->at(0);
  896. it = cArr->find("id");
  897. if( it != cArr->end() ){
  898. tVal = atoi( it->second.c_str() );
  899. };
  900. };
  901. };
  902. deleteResult( result );
  903. };
  904. return tVal;
  905. };
  906. uint32_t argusDBC::getWiFi_ID( uint32_t nif_id ){
  907. uint32_t tVal = 0;
  908. if(m_bIsConnected){
  909. char tQBuf[CTEXT];
  910. AAssoc *result;
  911. sprintf(tQBuf, "SELECT `id` FROM `wifis` WHERE `nif_id`=%d", nif_id );
  912. #ifdef DEBUG
  913. LOG(tQBuf);
  914. #endif
  915. result = m_pDatabase->Query( tQBuf );
  916. if( result!= NULL ) {
  917. if( result->size() > 0 ) {
  918. Assoc *cArr;
  919. Assoc::iterator it;
  920. cArr = result->at(0);
  921. it = cArr->find("id");
  922. if( it != cArr->end() ){
  923. tVal = atoi( it->second.c_str() );
  924. };
  925. };
  926. };
  927. deleteResult( result );
  928. };
  929. return tVal;
  930. };
  931. uint32_t argusDBC::getNIF_ID( CSTR key ){
  932. uint32_t tVal = 0;
  933. if(m_bIsConnected){
  934. char tQBuf[CTEXT];
  935. AAssoc *result;
  936. sprintf(tQBuf, "SELECT id FROM `network_interfaces` WHERE `key`='%s'", key );
  937. #ifdef DEBUG_EXTRA
  938. LOG(tQBuf);
  939. #endif
  940. result = m_pDatabase->Query( tQBuf );
  941. if( result!= NULL ) {
  942. if( result->size() > 0 ) {
  943. Assoc *cArr;
  944. Assoc::iterator it;
  945. cArr = result->at(0);
  946. it = cArr->find("id");
  947. if( it != cArr->end() ){
  948. tVal = atoi( it->second.c_str() );
  949. };
  950. };
  951. };
  952. deleteResult( result );
  953. };
  954. return tVal;
  955. };
  956. uint32_t argusDBC::getNIF_IDbyDevice( CSTR device ){
  957. uint32_t tVal = 0;
  958. if(m_bIsConnected){
  959. char tQBuf[CTEXT];
  960. AAssoc *result;
  961. sprintf(tQBuf, "SELECT id FROM `network_interfaces` WHERE `device_name`='%s'", device );
  962. #ifdef DEBUG
  963. LOG(tQBuf);
  964. #endif
  965. result = m_pDatabase->Query( tQBuf );
  966. if( result!= NULL ) {
  967. if( result->size() > 0 ) {
  968. Assoc *cArr;
  969. Assoc::iterator it;
  970. cArr = result->at(0);
  971. it = cArr->find("id");
  972. if( it != cArr->end() ){
  973. tVal = atoi( it->second.c_str() );
  974. };
  975. };
  976. };
  977. deleteResult( result );
  978. };
  979. return tVal;
  980. };
  981. DBC_NODE_DATA *argusDBC::getNodeData( uint32_t ID ){
  982. DBC_NODE_DATA * tVal = NULL;
  983. if(m_bIsConnected){
  984. char tQBuf[CTEXT];
  985. AAssoc *result;
  986. sprintf(tQBuf, "SELECT * FROM nodes WHERE `id`=%d", ID );
  987. #ifdef DEBUG_EXTRA
  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 = (DBC_NODE_DATA*) malloc(sizeof(DBC_NODE_DATA));
  995. if( tVal != NULL ) {
  996. memset( tVal, 0, sizeof(DBC_NODE_DATA));
  997. Assoc::iterator it;
  998. cArr = result->at(0);
  999. it = cArr->find("id");
  1000. if( it != cArr->end() ){
  1001. tVal->node_id = atoi( it->second.c_str() );
  1002. };
  1003. it = cArr->find("type");
  1004. if( it != cArr->end() ){
  1005. tVal->type = (ARGUS_NODE_TYPE) atoi( it->second.c_str() );
  1006. };
  1007. it = cArr->find("aux_id");
  1008. if( it != cArr->end() ){
  1009. tVal->aux_id = atoi( it->second.c_str() );
  1010. };
  1011. it = cArr->find("aux_parameter");
  1012. if( it != cArr->end() ){
  1013. tVal->aux_parameter = atoi( it->second.c_str() );
  1014. };
  1015. it = cArr->find("name");
  1016. if( it != cArr->end() ){
  1017. sprintf( tVal->name, it->second.c_str() );
  1018. };
  1019. it = cArr->find("ts_s");
  1020. if( it != cArr->end() ){
  1021. tVal->tss = atoi( it->second.c_str() );
  1022. };
  1023. it = cArr->find("ts_ms");
  1024. if( it != cArr->end() ){
  1025. tVal->tsm = atoi( it->second.c_str() );
  1026. };
  1027. it = cArr->find("online");
  1028. if( it != cArr->end() ){
  1029. tVal->online = (bool)atoi( it->second.c_str() );
  1030. };
  1031. };
  1032. };
  1033. };
  1034. deleteResult( result );
  1035. };
  1036. return tVal;
  1037. };
  1038. DBC_APF_DATA *argusDBC::getAPFData( uint32_t APFID ){
  1039. DBC_APF_DATA * tVal = NULL;
  1040. if(m_bIsConnected){
  1041. char tQBuf[CTEXT];
  1042. AAssoc *result;
  1043. sprintf(tQBuf, "SELECT * FROM `target_filter_apf` WHERE `id`=%d", APFID );
  1044. #ifdef DEBUG
  1045. LOG(tQBuf);
  1046. #endif
  1047. result = m_pDatabase->Query( tQBuf );
  1048. if( result!= NULL ) {
  1049. if( result->size() > 0 ) {
  1050. Assoc *cArr;
  1051. tVal = (DBC_APF_DATA*) malloc(sizeof(DBC_APF_DATA));
  1052. if( tVal != NULL ) {
  1053. memset( tVal, 0 , sizeof(DBC_APF_DATA));
  1054. Assoc::iterator it;
  1055. cArr = result->at(0);
  1056. it = cArr->find("mode");
  1057. if( it != cArr->end() ){
  1058. sprintf( tVal->mode, it->second.c_str() );
  1059. };
  1060. it = cArr->find("port");
  1061. if( it != cArr->end() ){
  1062. tVal->port = atoi( it->second.c_str() );
  1063. };
  1064. it = cArr->find("lat");
  1065. if( it != cArr->end() ){
  1066. tVal->lat = atof( it->second.c_str() );
  1067. };
  1068. it = cArr->find("lon");
  1069. if( it != cArr->end() ){
  1070. tVal->lon = atof( it->second.c_str() );
  1071. };
  1072. it = cArr->find("alt");
  1073. if( it != cArr->end() ){
  1074. tVal->alt = atof( it->second.c_str() );
  1075. };
  1076. it = cArr->find("roll");
  1077. if( it != cArr->end() ){
  1078. tVal->roll = atof( it->second.c_str() );
  1079. };
  1080. it = cArr->find("pitch");
  1081. if( it != cArr->end() ){
  1082. tVal->pitch = atof( it->second.c_str() );
  1083. };
  1084. it = cArr->find("yaw");
  1085. if( it != cArr->end() ){
  1086. tVal->yaw = atof( it->second.c_str() );
  1087. };
  1088. it = cArr->find("dx");
  1089. if( it != cArr->end() ){
  1090. tVal->dx = atof( it->second.c_str() );
  1091. };
  1092. it = cArr->find("dy");
  1093. if( it != cArr->end() ){
  1094. tVal->dy = atof( it->second.c_str() );
  1095. };
  1096. it = cArr->find("dz");
  1097. if( it != cArr->end() ){
  1098. tVal->dz = atof( it->second.c_str() );
  1099. };
  1100. };
  1101. };
  1102. };
  1103. deleteResult( result );
  1104. };
  1105. return tVal;
  1106. };
  1107. DBC_FH_DATA *argusDBC::getFlyHunterData( uint32_t ID ){
  1108. DBC_FH_DATA * tVal = NULL;
  1109. if(m_bIsConnected){
  1110. char tQBuf[CTEXT];
  1111. AAssoc *result;
  1112. sprintf(tQBuf, "SELECT * FROM `modules_fly_hunter` WHERE `id`=%d", ID );
  1113. #ifdef DEBUG
  1114. LOG(tQBuf);
  1115. #endif
  1116. result = m_pDatabase->Query( tQBuf );
  1117. if( result!= NULL ) {
  1118. if( result->size() > 0 ) {
  1119. Assoc *cArr;
  1120. tVal = (DBC_FH_DATA*) malloc(sizeof(DBC_FH_DATA));
  1121. if( tVal != NULL ) {
  1122. memset( tVal, 0 , sizeof(DBC_FH_DATA));
  1123. Assoc::iterator it;
  1124. cArr = result->at(0);
  1125. it = cArr->find("name");
  1126. if( it != cArr->end() ){
  1127. sprintf( tVal->name, it->second.c_str() );
  1128. };
  1129. it = cArr->find("lat");
  1130. if( it != cArr->end() ){
  1131. tVal->lat = atof( it->second.c_str() );
  1132. };
  1133. it = cArr->find("lon");
  1134. if( it != cArr->end() ){
  1135. tVal->lon = atof( it->second.c_str() );
  1136. };
  1137. it = cArr->find("alt");
  1138. if( it != cArr->end() ){
  1139. tVal->alt = atof( it->second.c_str() );
  1140. };
  1141. it = cArr->find("dc_module_id");
  1142. if( it != cArr->end() ){
  1143. tVal->dc_id = atoi( it->second.c_str() );
  1144. };
  1145. it = cArr->find("uart_id");
  1146. if( it != cArr->end() ){
  1147. tVal->uart_id = atoi( it->second.c_str() );
  1148. };
  1149. };
  1150. };
  1151. };
  1152. deleteResult( result );
  1153. };
  1154. return tVal;
  1155. };
  1156. DBC_SITE_DATA *argusDBC::getSiteData( uint32_t ID ){
  1157. DBC_SITE_DATA * tVal = NULL;
  1158. if(m_bIsConnected){
  1159. char tQBuf[CTEXT];
  1160. AAssoc *result;
  1161. sprintf(tQBuf, "SELECT * FROM sites WHERE `id`=%d", ID );
  1162. #ifdef DEBUG
  1163. LOG(tQBuf);
  1164. #endif
  1165. result = m_pDatabase->Query( tQBuf );
  1166. if( result!= NULL ) {
  1167. if( result->size() > 0 ) {
  1168. Assoc *cArr;
  1169. tVal = (DBC_SITE_DATA*) malloc(sizeof(DBC_SITE_DATA));
  1170. if( tVal != NULL ) {
  1171. memset( tVal, 0 , sizeof(DBC_SITE_DATA));
  1172. Assoc::iterator it;
  1173. cArr = result->at(0);
  1174. it = cArr->find("account_id");
  1175. if( it != cArr->end() ){
  1176. tVal->account_id = atoi( it->second.c_str() );
  1177. };
  1178. it = cArr->find("name");
  1179. if( it != cArr->end() ){
  1180. sprintf( tVal->name, it->second.c_str() );
  1181. };
  1182. it = cArr->find("server_ident");
  1183. if( it != cArr->end() ){
  1184. sprintf( tVal->ident, it->second.c_str() );
  1185. };
  1186. it = cArr->find("anchor_lat");
  1187. if( it != cArr->end() ){
  1188. tVal->lat = atof( it->second.c_str() );
  1189. };
  1190. it = cArr->find("anchor_lon");
  1191. if( it != cArr->end() ){
  1192. tVal->lon = atof( it->second.c_str() );
  1193. };
  1194. it = cArr->find("anchor_alt");
  1195. if( it != cArr->end() ){
  1196. tVal->alt = atof( it->second.c_str() );
  1197. };
  1198. it = cArr->find("hemisphere");
  1199. if( it != cArr->end() ){
  1200. tVal->SH = ( it->second.c_str()[0] == 'S' );
  1201. };
  1202. it = cArr->find("map_id");
  1203. if( it != cArr->end() ){
  1204. tVal->map_id = atoi( it->second.c_str() );
  1205. };
  1206. };
  1207. };
  1208. };
  1209. deleteResult( result );
  1210. };
  1211. return tVal;
  1212. };
  1213. DBC_TARGET_FLITER_DATA *argusDBC::getTargetFilterData( uint32_t ID ){
  1214. DBC_TARGET_FLITER_DATA * tVal = NULL;
  1215. if(m_bIsConnected){
  1216. char tQBuf[CTEXT];
  1217. AAssoc *result;
  1218. sprintf(tQBuf, "SELECT * FROM target_filters WHERE `id`=%d", ID );
  1219. #ifdef DEBUG
  1220. LOG(tQBuf);
  1221. #endif
  1222. result = m_pDatabase->Query( tQBuf );
  1223. if( result!= NULL ) {
  1224. if( result->size() > 0 ) {
  1225. Assoc *cArr;
  1226. tVal = (DBC_TARGET_FLITER_DATA*) malloc(sizeof(DBC_TARGET_FLITER_DATA));
  1227. if( tVal != NULL ) {
  1228. memset( tVal, 0 , sizeof(DBC_TARGET_FLITER_DATA));
  1229. Assoc::iterator it;
  1230. tVal->id = ID;
  1231. cArr = result->at(0);
  1232. it = cArr->find("type");
  1233. if( it != cArr->end() ){
  1234. tVal->type = atoi( it->second.c_str() );
  1235. };
  1236. it = cArr->find("aux_id");
  1237. if( it != cArr->end() ){
  1238. tVal->aux_id = atoi( it->second.c_str() );
  1239. };
  1240. };
  1241. };
  1242. };
  1243. deleteResult( result );
  1244. };
  1245. return tVal;
  1246. };
  1247. DBC_LRF_DATA *argusDBC::getLRFData( uint32_t ID ){
  1248. DBC_LRF_DATA * tVal = NULL;
  1249. if(m_bIsConnected){
  1250. char tQBuf[CTEXT];
  1251. AAssoc *result;
  1252. sprintf(tQBuf, "SELECT * FROM lrf_sensors WHERE `id`=%d", ID );
  1253. #ifdef DEBUG
  1254. LOG(tQBuf);
  1255. #endif
  1256. result = m_pDatabase->Query( tQBuf );
  1257. if( result!= NULL ) {
  1258. if( result->size() > 0 ) {
  1259. Assoc *cArr;
  1260. tVal = (DBC_LRF_DATA*) malloc(sizeof(DBC_LRF_DATA));
  1261. if( tVal != NULL ) {
  1262. memset( tVal, 0 , sizeof(DBC_LRF_DATA));
  1263. Assoc::iterator it;
  1264. tVal->id = ID;
  1265. cArr = result->at(0);
  1266. it = cArr->find("data_status");
  1267. if( it != cArr->end() ){
  1268. tVal->data_status = atoi( it->second.c_str() );
  1269. };
  1270. it = cArr->find("serial");
  1271. if( it != cArr->end() ){
  1272. strncpy( tVal->serial, it->second.c_str(), sizeof(tVal->serial)-1 );
  1273. tVal->serial[sizeof(tVal->serial)-1]=(char)0;
  1274. };
  1275. it = cArr->find("version");
  1276. if( it != cArr->end() ){
  1277. strncpy( tVal->version, it->second.c_str(), sizeof(tVal->version)-1 );
  1278. tVal->version[sizeof(tVal->version)-1]=(char)0;
  1279. };
  1280. it = cArr->find("x");
  1281. if( it != cArr->end() ){
  1282. tVal->x = atof( it->second.c_str() );
  1283. };
  1284. it = cArr->find("y");
  1285. if( it != cArr->end() ){
  1286. tVal->y = atof( it->second.c_str() );
  1287. };
  1288. it = cArr->find("z");
  1289. if( it != cArr->end() ){
  1290. tVal->z = atof( it->second.c_str() );
  1291. };
  1292. it = cArr->find("x_rot");
  1293. if( it != cArr->end() ){
  1294. tVal->x_rot = atof( it->second.c_str() );
  1295. };
  1296. it = cArr->find("y_rot");
  1297. if( it != cArr->end() ){
  1298. tVal->y_rot = atof( it->second.c_str() );
  1299. };
  1300. it = cArr->find("z_rot");
  1301. if( it != cArr->end() ){
  1302. tVal->z_rot = atof( it->second.c_str() );
  1303. };
  1304. it = cArr->find("uart_id");
  1305. if( it != cArr->end() ){
  1306. tVal->uart_id = atoi( it->second.c_str() );
  1307. };
  1308. it = cArr->find("device_id");
  1309. if( it != cArr->end() ){
  1310. tVal->device_id = atoi( it->second.c_str() );
  1311. };
  1312. it = cArr->find("ip_address");
  1313. if( it != cArr->end() ){
  1314. sprintf( tVal->master_host, it->second.c_str() );
  1315. };
  1316. it = cArr->find("aux_ip_address");
  1317. if( it != cArr->end() ){
  1318. sprintf( tVal->slave_host, it->second.c_str() );
  1319. };
  1320. it = cArr->find("port");
  1321. if( it != cArr->end() ){
  1322. tVal->master_port = atoi( it->second.c_str() );
  1323. };
  1324. it = cArr->find("aux_port");
  1325. if( it != cArr->end() ){
  1326. tVal->slave_port = atoi( it->second.c_str() );
  1327. };
  1328. it = cArr->find("auto_draw");
  1329. if( it != cArr->end() ){
  1330. tVal->auto_draw = atoi( it->second.c_str() );
  1331. };
  1332. it = cArr->find("filter_id");
  1333. if( it != cArr->end() ){
  1334. tVal->filter_id = atoi( it->second.c_str() );
  1335. };
  1336. //it = cArr->find("enabled_lrf");
  1337. //if( it != cArr->end() ){
  1338. // tVal->enabled_lrf = atoi( it->second.c_str() );
  1339. //};
  1340. it = cArr->find("max_range");
  1341. if( it != cArr->end() ){
  1342. tVal->max_range = atof( it->second.c_str() );
  1343. };
  1344. it = cArr->find("base_shift");
  1345. if( it != cArr->end() ){
  1346. tVal->base_shift = atoi( it->second.c_str() );
  1347. };
  1348. it = cArr->find("mirror_shift");
  1349. if( it != cArr->end() ){
  1350. tVal->mirror_shift = atoi( it->second.c_str() );
  1351. };
  1352. it = cArr->find("detection_profile_id");
  1353. if( it != cArr->end() ){
  1354. tVal->detection_profile_id = atoi( it->second.c_str() );
  1355. };
  1356. it = cArr->find("draw_lrf_id");
  1357. if( it != cArr->end() ){
  1358. tVal->draw_lrf_id = atoi( it->second.c_str() );
  1359. };
  1360. it = cArr->find("width_table_id");
  1361. if( it != cArr->end() ){
  1362. tVal->width_table_id = atoi( it->second.c_str() );
  1363. };
  1364. it = cArr->find("zoom_table_id");
  1365. if( it != cArr->end() ){
  1366. tVal->zoom_table_id = atoi( it->second.c_str() );
  1367. };
  1368. it = cArr->find("embd_cam");
  1369. if( it != cArr->end() ){
  1370. tVal->embd_cam = atoi( it->second.c_str() );
  1371. };
  1372. it = cArr->find("embd_cam_auto");
  1373. if( it != cArr->end() ){
  1374. tVal->embd_cam_auto = (bool)atoi( it->second.c_str() );
  1375. };
  1376. it = cArr->find("embd_dc");
  1377. if( it != cArr->end() ){
  1378. tVal->embd_dc = atoi( it->second.c_str() );
  1379. };
  1380. it = cArr->find("autoreset");
  1381. if( it != cArr->end() ){
  1382. tVal->autoreset = (bool)atoi( it->second.c_str() );
  1383. };
  1384. };
  1385. };
  1386. };
  1387. deleteResult( result );
  1388. };
  1389. return tVal;
  1390. };
  1391. uint8_t argusDBC::getLRFDataStatus( uint32_t ID ){
  1392. uint8_t RetVal = 0;
  1393. if(m_bIsConnected){
  1394. char tQBuf[CTEXT];
  1395. AAssoc *result;
  1396. sprintf(tQBuf, "SELECT `data_status` FROM `lrf_sensors` WHERE `id`=%d", ID );
  1397. #ifdef DEBUG
  1398. LOG(tQBuf);
  1399. #endif
  1400. result = m_pDatabase->Query( tQBuf );
  1401. if( result!= NULL ) {
  1402. if( result->size() > 0 ) {
  1403. Assoc *cArr;
  1404. Assoc::iterator it;
  1405. cArr = result->at(0);
  1406. it = cArr->find("data_status");
  1407. if( it != cArr->end() ){
  1408. RetVal = atoi( it->second.c_str() );
  1409. };
  1410. };
  1411. };
  1412. deleteResult( result );
  1413. };
  1414. return RetVal;
  1415. };
  1416. uint32_t argusDBC::getLRFMaskID( uint32_t deviceID, uint8_t lrfID, uint8_t layer ){
  1417. uint32_t RetVal = 0;
  1418. if(m_bIsConnected){
  1419. char tQBuf[CTEXT];
  1420. AAssoc *result;
  1421. sprintf(tQBuf, "SELECT `id` FROM `lrf_masks` WHERE `sensor_id`=%d AND `lrf_id`=%d AND `layer`=%d ", deviceID, lrfID, layer );
  1422. #ifdef DEBUG
  1423. LOG(tQBuf);
  1424. #endif
  1425. result = m_pDatabase->Query( tQBuf );
  1426. if( result!= NULL ) {
  1427. if( result->size() > 0 ) {
  1428. Assoc *cArr;
  1429. Assoc::iterator it;
  1430. cArr = result->at(0);
  1431. it = cArr->find("id");
  1432. if( it != cArr->end() ){
  1433. RetVal = atoi( it->second.c_str() );
  1434. };
  1435. };
  1436. };
  1437. deleteResult( result );
  1438. };
  1439. return RetVal;
  1440. };
  1441. /*
  1442. DBC_PUSHED_CMD *argusDBC::getLRFPushedCMD( uint32_t ID ){
  1443. DBC_PUSHED_CMD *RetVal = NULL;
  1444. if(m_bIsConnected){
  1445. char tQBuf[CTEXT];
  1446. AAssoc *result;
  1447. sprintf(tQBuf, "SELECT `pushed_cmd`, `pushed_param` FROM `lrf_sensors` WHERE `id`=%d AND `pushed_cmd` > 0", ID );
  1448. #ifdef DEBUG
  1449. //LOG(tQBuf);
  1450. #endif
  1451. result = m_pDatabase->Query( tQBuf );
  1452. if( result!= NULL ) {
  1453. if( result->size() > 0 ) {
  1454. RetVal = (DBC_PUSHED_CMD*)malloc(sizeof(DBC_PUSHED_CMD));
  1455. if( RetVal ) {
  1456. Assoc *cArr;
  1457. Assoc::iterator it;
  1458. cArr = result->at(0);
  1459. it = cArr->find("pushed_cmd");
  1460. if( it != cArr->end() ){
  1461. RetVal->CMD = atoi( it->second.c_str() );
  1462. };
  1463. it = cArr->find("pushed_param");
  1464. if( it != cArr->end() ){
  1465. RetVal->PARAM = atoi( it->second.c_str() );
  1466. };
  1467. };
  1468. };
  1469. //Only If Result is Fetched - Clear Current CMD
  1470. sprintf(tQBuf, "UPDATE `lrf_sensors` SET `pushed_cmd`=0, `pushed_param`=0 WHERE `id`=%d", ID );
  1471. m_pDatabase->SilentQuery( tQBuf );
  1472. };
  1473. deleteResult( result );
  1474. };
  1475. return RetVal;
  1476. };
  1477. */
  1478. DBC_INT_LIST *argusDBC::listModules( uint32_t ServerID ){
  1479. DBC_INT_LIST * tVal = NULL;
  1480. if(m_bIsConnected){
  1481. char tQBuf[CTEXT];
  1482. AAssoc *result;
  1483. sprintf(tQBuf, "SELECT `id` FROM `server_modules` WHERE `server_id`=%d AND `enabled`=1", ServerID );
  1484. #ifdef DEBUG
  1485. //LOG(tQBuf);
  1486. #endif
  1487. result = m_pDatabase->Query( tQBuf );
  1488. if( result!= NULL ) {
  1489. if( result->size() > 0 ) {
  1490. Assoc *cArr;
  1491. tVal = new DBC_INT_LIST();
  1492. if( tVal != NULL ) {
  1493. Assoc::iterator it;
  1494. for(int i=0;i<result->size();i++) {
  1495. cArr = result->at(i);
  1496. it = cArr->find("id");
  1497. if( it != cArr->end() ){
  1498. tVal->push_back( atoi( it->second.c_str() ));
  1499. };
  1500. };
  1501. };
  1502. };
  1503. };
  1504. deleteResult( result );
  1505. };
  1506. return tVal;
  1507. };
  1508. DBC_INT_LIST *argusDBC::listFilters( uint32_t ServerID ){
  1509. DBC_INT_LIST * tVal = NULL;
  1510. if(m_bIsConnected){
  1511. char tQBuf[CTEXT];
  1512. AAssoc *result;
  1513. sprintf(tQBuf, "SELECT `id` FROM `target_filters` WHERE `server_id`=%d AND `enabled`=1", ServerID );
  1514. #ifdef DEBUG_ALL
  1515. LOG(tQBuf);
  1516. #endif
  1517. result = m_pDatabase->Query( tQBuf );
  1518. if( result!= NULL ) {
  1519. if( result->size() > 0 ) {
  1520. Assoc *cArr;
  1521. tVal = new DBC_INT_LIST();
  1522. if( tVal != NULL ) {
  1523. Assoc::iterator it;
  1524. for(int i=0;i<result->size();i++) {
  1525. cArr = result->at(i);
  1526. it = cArr->find("id");
  1527. if( it != cArr->end() ){
  1528. tVal->push_back( atoi( it->second.c_str() ));
  1529. };
  1530. };
  1531. };
  1532. };
  1533. };
  1534. deleteResult( result );
  1535. };
  1536. return tVal;
  1537. };
  1538. DBC_INT_LIST *argusDBC::listLRFMaskVertexes( uint32_t MaskID ){
  1539. DBC_INT_LIST * tVal = NULL;
  1540. if(m_bIsConnected){
  1541. char tQBuf[CTEXT];
  1542. AAssoc *result;
  1543. sprintf(tQBuf, "SELECT `id` FROM `lrf_mask_vertexes` WHERE `mask_id`=%d", MaskID );
  1544. #ifdef DEBUG_ALL
  1545. LOG(tQBuf);
  1546. #endif
  1547. result = m_pDatabase->Query( tQBuf );
  1548. if( result!= NULL ) {
  1549. if( result->size() > 0 ) {
  1550. Assoc *cArr;
  1551. tVal = new DBC_INT_LIST();
  1552. if( tVal != NULL ) {
  1553. Assoc::iterator it;
  1554. for(int i=0;i<result->size();i++) {
  1555. cArr = result->at(i);
  1556. it = cArr->find("id");
  1557. if( it != cArr->end() ){
  1558. tVal->push_back( atoi( it->second.c_str() ));
  1559. };
  1560. };
  1561. };
  1562. };
  1563. };
  1564. deleteResult( result );
  1565. };
  1566. return tVal;
  1567. };
  1568. DBC_INT_LIST *argusDBC::listLRFMaskVertexPoints( uint32_t VertexID ){
  1569. DBC_INT_LIST * tVal = NULL;
  1570. if(m_bIsConnected){
  1571. char tQBuf[CTEXT];
  1572. AAssoc *result;
  1573. sprintf(tQBuf, "SELECT `id` FROM `lrf_mask_vertex_points` WHERE `vertex_id`=%d ORDER BY `id`", VertexID );
  1574. #ifdef DEBUG_ALL
  1575. LOG(tQBuf);
  1576. #endif
  1577. result = m_pDatabase->Query( tQBuf );
  1578. if( result!= NULL ) {
  1579. if( result->size() > 0 ) {
  1580. Assoc *cArr;
  1581. tVal = new DBC_INT_LIST();
  1582. if( tVal != NULL ) {
  1583. Assoc::iterator it;
  1584. for(int i=0;i<result->size();i++) {
  1585. cArr = result->at(i);
  1586. it = cArr->find("id");
  1587. if( it != cArr->end() ){
  1588. tVal->push_back( atoi( it->second.c_str() ));
  1589. };
  1590. };
  1591. };
  1592. };
  1593. };
  1594. deleteResult( result );
  1595. };
  1596. return tVal;
  1597. };
  1598. DBC_INT_LIST *argusDBC::listMediaServerStreams( uint32_t SiteId, uint32_t MediaServerID, uint8_t listMode ){
  1599. DBC_INT_LIST * tVal = NULL;
  1600. if(m_bIsConnected){
  1601. char tQBuf[CTEXT];
  1602. AAssoc *result;
  1603. switch( listMode ){
  1604. 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;
  1605. 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;
  1606. default: sprintf(tQBuf, "SELECT id FROM media_server_streams WHERE `site_id`=%d AND `media_server_id`=%d", SiteId, MediaServerID );
  1607. };
  1608. #ifdef DEBUG_ALL
  1609. LOG(tQBuf);
  1610. #endif
  1611. result = m_pDatabase->Query( tQBuf );
  1612. if( result!= NULL ) {
  1613. if( result->size() > 0 ) {
  1614. Assoc *cArr;
  1615. tVal = new DBC_INT_LIST();
  1616. if( tVal != NULL ) {
  1617. Assoc::iterator it;
  1618. for(int i=0;i<result->size();i++) {
  1619. cArr = result->at(i);
  1620. it = cArr->find("id");
  1621. if( it != cArr->end() ){
  1622. tVal->push_back( atoi( it->second.c_str() ));
  1623. };
  1624. };
  1625. };
  1626. };
  1627. };
  1628. deleteResult( result );
  1629. };
  1630. return tVal;
  1631. };
  1632. DBC_INT_LIST *argusDBC::listMediaStreams( uint32_t SiteId, uint8_t listMode ){
  1633. DBC_INT_LIST * tVal = NULL;
  1634. if(m_bIsConnected){
  1635. char tQBuf[CTEXT];
  1636. AAssoc *result;
  1637. switch( listMode ){
  1638. case LIST_VALID_RECORDS:
  1639. sprintf(tQBuf, "SELECT id FROM media_streams WHERE `valid`=1 AND `site_id`=%d", SiteId );
  1640. break;
  1641. case LIST_INVALID_RECORDS:
  1642. sprintf(tQBuf, "SELECT id FROM media_streams WHERE `valid`=0 AND `site_id`=%d", SiteId );
  1643. break;
  1644. default:
  1645. sprintf(tQBuf, "SELECT id FROM media_streams WHERE `site_id`=%d", SiteId );
  1646. };
  1647. #ifdef DEBUG_ALL
  1648. LOG(tQBuf);
  1649. #endif
  1650. result = m_pDatabase->Query( tQBuf );
  1651. if( result!= NULL ) {
  1652. if( result->size() > 0 ) {
  1653. Assoc *cArr;
  1654. tVal = new DBC_INT_LIST();
  1655. if( tVal != NULL ) {
  1656. Assoc::iterator it;
  1657. for(int i=0;i<result->size();i++) {
  1658. cArr = result->at(i);
  1659. it = cArr->find("id");
  1660. if( it != cArr->end() ){
  1661. tVal->push_back( atoi( it->second.c_str() ));
  1662. };
  1663. };
  1664. };
  1665. };
  1666. };
  1667. deleteResult( result );
  1668. };
  1669. return tVal;
  1670. };
  1671. DBC_INT_LIST *argusDBC::listDetectionProfileIDs( uint32_t nodeID ){
  1672. DBC_INT_LIST * tVal = NULL;
  1673. if(m_bIsConnected){
  1674. char tQBuf[CTEXT];
  1675. AAssoc *result;
  1676. sprintf(tQBuf, "SELECT `profile_id` FROM `lrf_detection_profiles` WHERE `aux_id`=%d ", nodeID );
  1677. #ifdef DEBUG_ALL
  1678. LOG(tQBuf);
  1679. #endif
  1680. result = m_pDatabase->Query( tQBuf );
  1681. if( result!= NULL ) {
  1682. if( result->size() > 0 ) {
  1683. Assoc *cArr;
  1684. tVal = new DBC_INT_LIST();
  1685. if( tVal != NULL ) {
  1686. Assoc::iterator it;
  1687. for(int i=0;i<result->size();i++) {
  1688. cArr = result->at(i);
  1689. it = cArr->find("profile_id");
  1690. if( it != cArr->end() ){
  1691. tVal->push_back( atoi( it->second.c_str() ));
  1692. };
  1693. };
  1694. };
  1695. };
  1696. };
  1697. deleteResult( result );
  1698. };
  1699. return tVal;
  1700. };
  1701. DBC_INT_LIST *argusDBC::listDetectionProfiles( uint32_t nodeID ){
  1702. DBC_INT_LIST * tVal = NULL;
  1703. if(m_bIsConnected){
  1704. char tQBuf[CTEXT];
  1705. AAssoc *result;
  1706. sprintf(tQBuf, "SELECT `id` FROM `lrf_detection_profiles` WHERE `aux_id`=%d ", nodeID );
  1707. #ifdef DEBUG_ALL
  1708. LOG(tQBuf);
  1709. #endif
  1710. result = m_pDatabase->Query( tQBuf );
  1711. if( result!= NULL ) {
  1712. if( result->size() > 0 ) {
  1713. Assoc *cArr;
  1714. tVal = new DBC_INT_LIST();
  1715. if( tVal != NULL ) {
  1716. Assoc::iterator it;
  1717. for(int i=0;i<result->size();i++) {
  1718. cArr = result->at(i);
  1719. it = cArr->find("id");
  1720. if( it != cArr->end() ){
  1721. tVal->push_back( atoi( it->second.c_str() ));
  1722. };
  1723. };
  1724. };
  1725. };
  1726. };
  1727. deleteResult( result );
  1728. };
  1729. return tVal;
  1730. };
  1731. /*
  1732. DBC_INT_LIST *argusDBC::listSockets( uint32_t NodeID ){
  1733. DBC_INT_LIST * tVal = NULL;
  1734. if(m_bIsConnected){
  1735. char tQBuf[CTEXT];
  1736. AAssoc *result;
  1737. sprintf(tQBuf, "SELECT id FROM sockets WHERE `node_id`=%d", NodeID );
  1738. #ifdef DEBUG
  1739. LOG(tQBuf);
  1740. #endif
  1741. result = m_pDatabase->Query( tQBuf );
  1742. if( result!= NULL ) {
  1743. if( result->size() > 0 ) {
  1744. Assoc *cArr;
  1745. tVal = new DBC_INT_LIST();
  1746. if( tVal != NULL ) {
  1747. Assoc::iterator it;
  1748. for(int i=0;i<result->size();i++) {
  1749. cArr = result->at(i);
  1750. it = cArr->find("id");
  1751. if( it != cArr->end() ){
  1752. tVal->push_back( atoi( it->second.c_str() ));
  1753. };
  1754. };
  1755. };
  1756. };
  1757. };
  1758. deleteResult( result );
  1759. };
  1760. return tVal;
  1761. };
  1762. */
  1763. DBC_INT_LIST *argusDBC::listResources( uint32_t NodeID ){
  1764. DBC_INT_LIST * tVal = NULL;
  1765. if(m_bIsConnected){
  1766. char tQBuf[CTEXT];
  1767. AAssoc *result;
  1768. if( NodeID ) {
  1769. sprintf(tQBuf, "SELECT `id` FROM `resources` WHERE `node_id`=%d AND `active`=1 AND `used`=1", NodeID );
  1770. } else {
  1771. sprintf(tQBuf, "SELECT `re`.`id` FROM `resources` `re` LEFT JOIN `nodes` `no` ON( `re`.`node_id` = `no`.`id` ) WHERE `no`.`site_id`=%d AND `re`.`active`=1 AND `re`.`used`=1", m_nSiteID );
  1772. };
  1773. #ifdef DEBUG
  1774. LOG(tQBuf);
  1775. #endif
  1776. result = m_pDatabase->Query( tQBuf );
  1777. if( result!= NULL ) {
  1778. if( result->size() > 0 ) {
  1779. Assoc *cArr;
  1780. tVal = new DBC_INT_LIST();
  1781. if( tVal != NULL ) {
  1782. Assoc::iterator it;
  1783. for(int i=0;i<result->size();i++) {
  1784. cArr = result->at(i);
  1785. it = cArr->find("id");
  1786. if( it != cArr->end() ){
  1787. tVal->push_back( atoi( it->second.c_str() ));
  1788. };
  1789. };
  1790. };
  1791. };
  1792. };
  1793. deleteResult( result );
  1794. };
  1795. return tVal;
  1796. };
  1797. simplePolygone *argusDBC::loadLRFMaskVertex( uint32_t vid ){
  1798. simplePolygone *tVal = NULL;
  1799. if(m_bIsConnected){
  1800. char tQBuf[CTEXT];
  1801. AAssoc *result;
  1802. sprintf(tQBuf, "SELECT * FROM `lrf_mask_vertexes` WHERE `id`=%d", vid );
  1803. #ifdef DEBUG
  1804. LOG(tQBuf);
  1805. #endif
  1806. result = m_pDatabase->Query( tQBuf );
  1807. if( result!= NULL ) {
  1808. if( result->size() > 0 ) {
  1809. tVal = (simplePolygone *) malloc(sizeof(simplePolygone));
  1810. if ( tVal ) {
  1811. Assoc * cArr;
  1812. memset( tVal, 0, sizeof(simplePolygone));
  1813. Assoc::iterator it;
  1814. cArr = result->at(0);
  1815. it = cArr->find("r");
  1816. if( it != cArr->end() ){
  1817. tVal->color[0] = atoi( it->second.c_str() );
  1818. };
  1819. it = cArr->find("g");
  1820. if( it != cArr->end() ){
  1821. tVal->color[1] = atoi( it->second.c_str() );
  1822. };
  1823. it = cArr->find("b");
  1824. if( it != cArr->end() ){
  1825. tVal->color[2] = atoi( it->second.c_str() );
  1826. };
  1827. AAssoc *points;
  1828. sprintf(tQBuf, "SELECT * FROM `lrf_mask_vertex_points` WHERE `vertex_id`=%d ORDER BY `id`", vid );
  1829. #ifdef DEBUG
  1830. LOG(tQBuf);
  1831. #endif
  1832. points = m_pDatabase->Query( tQBuf );
  1833. if( points!= NULL ) {
  1834. if ( points->size() ) {
  1835. tVal->count = points->size();
  1836. tVal->points = (simplePoint *) calloc( points->size(), sizeof(simplePoint) );
  1837. if( tVal->points!= NULL ) {
  1838. for (int i = 0; i < points->size(); i++) {
  1839. cArr = points->at( i );
  1840. it = cArr->find("x");
  1841. if( it != cArr->end() ){
  1842. tVal->points[i].setX( atoi( it->second.c_str() ) );
  1843. };
  1844. it = cArr->find("y");
  1845. if( it != cArr->end() ){
  1846. tVal->points[i].setY( atoi( it->second.c_str() ) );
  1847. };
  1848. };
  1849. };
  1850. };
  1851. };
  1852. deleteResult( points );
  1853. };
  1854. };
  1855. };
  1856. deleteResult( result );
  1857. };
  1858. return tVal;
  1859. };
  1860. DBC_INT_LIST *argusDBC::listNetworks( uint32_t nif_id ){
  1861. DBC_INT_LIST * tVal = NULL;
  1862. if(m_bIsConnected){
  1863. char tQBuf[CTEXT];
  1864. AAssoc *result;
  1865. sprintf(tQBuf, "SELECT `id` FROM `networks` WHERE `nif_id`=%d", nif_id );
  1866. #ifdef DEBUG_ALL
  1867. LOG(tQBuf);
  1868. #endif
  1869. result = m_pDatabase->Query( tQBuf );
  1870. if( result!= NULL ) {
  1871. if( result->size() > 0 ) {
  1872. Assoc *cArr;
  1873. tVal = new DBC_INT_LIST();
  1874. if( tVal != NULL ) {
  1875. Assoc::iterator it;
  1876. for(int i=0;i<result->size();i++) {
  1877. cArr = result->at(i);
  1878. it = cArr->find("id");
  1879. if( it != cArr->end() ){
  1880. tVal->push_back( atoi( it->second.c_str() ));
  1881. };
  1882. };
  1883. };
  1884. };
  1885. };
  1886. deleteResult( result );
  1887. };
  1888. return tVal;
  1889. };
  1890. DBC_INT_LIST *argusDBC::listNewModules( uint32_t ServerID, DBC_INT_LIST * old_ids ){
  1891. DBC_INT_LIST * tVal = NULL;
  1892. char tParam[CTEXT];
  1893. //memset( tParam, 0, CTEXT );
  1894. sprintf(tParam,"0");
  1895. if( old_ids != NULL ) {
  1896. char tBuffer[CTEXT];
  1897. for(int i = 0; i< old_ids->size(); i++ ) {
  1898. sprintf( tBuffer, "%s,%d", tParam, old_ids->at(i) );
  1899. strncpy( tParam, tBuffer, CTEXT );
  1900. };
  1901. };
  1902. if(m_bIsConnected){
  1903. char tQBuf[CTEXT];
  1904. AAssoc *result;
  1905. sprintf(tQBuf, "SELECT `id` FROM `server_modules` WHERE `server_id`=%d AND `enabled`=1 AND `id` NOT IN (%s)", ServerID, tParam );
  1906. #ifdef DEBUG_ALL
  1907. LOG(tQBuf);
  1908. #endif
  1909. result = m_pDatabase->Query( tQBuf );
  1910. if( result!= NULL ) {
  1911. if( result->size() > 0 ) {
  1912. Assoc *cArr;
  1913. tVal = new DBC_INT_LIST();
  1914. if( tVal != NULL ) {
  1915. Assoc::iterator it;
  1916. for(int i=0;i<result->size();i++) {
  1917. cArr = result->at(i);
  1918. it = cArr->find("id");
  1919. if( it != cArr->end() ){
  1920. tVal->push_back( atoi( it->second.c_str() ));
  1921. };
  1922. };
  1923. };
  1924. };
  1925. };
  1926. deleteResult( result );
  1927. };
  1928. return tVal;
  1929. };
  1930. uint32_t argusDBC::getCamId( CSTR UUID ){
  1931. uint32_t RetVal = 0;
  1932. if(m_bIsConnected){
  1933. char tQBuf[CTEXT];
  1934. AAssoc *result;
  1935. sprintf(tQBuf, "SELECT id FROM cameras WHERE `uuid`='%s'", UUID );
  1936. #ifdef DEBUG_ALL
  1937. LOG(tQBuf);
  1938. #endif
  1939. result = m_pDatabase->Query( tQBuf );
  1940. if( result!= NULL ) {
  1941. if( result->size() > 0 ) {
  1942. Assoc *cArr;
  1943. Assoc::iterator it;
  1944. cArr = result->at(0);
  1945. it = cArr->find("id");
  1946. if( it != cArr->end() ){
  1947. RetVal = atoi( it->second.c_str() );
  1948. };
  1949. };
  1950. };
  1951. deleteResult( result );
  1952. };
  1953. return RetVal;
  1954. };
  1955. DBC_CAM_DATA *argusDBC::getCamData( uint32_t ID ){
  1956. DBC_CAM_DATA *tVal = NULL;
  1957. if(m_bIsConnected){
  1958. char tQBuf[CTEXT];
  1959. AAssoc *result;
  1960. sprintf(tQBuf, "SELECT * FROM cameras WHERE `id`=%d", ID );
  1961. #ifdef DEBUG_ALL
  1962. LOG(tQBuf);
  1963. #endif
  1964. result = m_pDatabase->Query( tQBuf );
  1965. if( result!= NULL ) {
  1966. if( result->size() > 0 ) {
  1967. Assoc *cArr;
  1968. tVal = (DBC_CAM_DATA*) malloc(sizeof(DBC_CAM_DATA));
  1969. if( tVal != NULL ) {
  1970. memset( tVal, 0 , sizeof(DBC_CAM_DATA));
  1971. tVal->id = ID;
  1972. Assoc::iterator it;
  1973. cArr = result->at(0);
  1974. it = cArr->find("site_id");
  1975. if( it != cArr->end() ){
  1976. tVal->site_id = atoi( it->second.c_str() );
  1977. };
  1978. it = cArr->find("node_id");
  1979. if( it != cArr->end() ){
  1980. tVal->node_id = atoi( it->second.c_str() );
  1981. };
  1982. it = cArr->find("online");
  1983. if( it != cArr->end() ){
  1984. tVal->online = (bool) atoi( it->second.c_str() );
  1985. };
  1986. it = cArr->find("type");
  1987. if( it != cArr->end() ){
  1988. tVal->type = atoi( it->second.c_str() );
  1989. };
  1990. it = cArr->find("name");
  1991. if( it != cArr->end() ){
  1992. strncpy( tVal->name, it->second.c_str(), 64 );
  1993. };
  1994. it = cArr->find("hardware");
  1995. if( it != cArr->end() ){
  1996. strncpy( tVal->hardware, it->second.c_str(), 32 );
  1997. };
  1998. it = cArr->find("status");
  1999. if( it != cArr->end() ){
  2000. tVal->status = atoi( it->second.c_str() );
  2001. };
  2002. it = cArr->find("session");
  2003. if( it != cArr->end() ){
  2004. strncpy( tVal->session, it->second.c_str(), 32 );
  2005. };
  2006. it = cArr->find("protocol");
  2007. if( it != cArr->end() ){
  2008. tVal->protocol = atoi( it->second.c_str() );
  2009. };
  2010. it = cArr->find("protocol_aux");
  2011. if( it != cArr->end() ){
  2012. tVal->protocol_aux = atoi( it->second.c_str() );
  2013. };
  2014. it = cArr->find("uart_id");
  2015. if( it != cArr->end() ){
  2016. tVal->uart_id = atoi( it->second.c_str() );
  2017. };
  2018. it = cArr->find("x");
  2019. if( it != cArr->end() ){
  2020. tVal->x = atof( it->second.c_str() );
  2021. };
  2022. it = cArr->find("y");
  2023. if( it != cArr->end() ){
  2024. tVal->y = atof( it->second.c_str() );
  2025. };
  2026. it = cArr->find("z");
  2027. if( it != cArr->end() ){
  2028. tVal->z = atof( it->second.c_str() );
  2029. };
  2030. it = cArr->find("x_rot");
  2031. if( it != cArr->end() ){
  2032. tVal->x_rot = atof( it->second.c_str() );
  2033. };
  2034. it = cArr->find("x_rot");
  2035. if( it != cArr->end() ){
  2036. tVal->y_rot = atof( it->second.c_str() );
  2037. };
  2038. it = cArr->find("x_rot");
  2039. if( it != cArr->end() ){
  2040. tVal->z_rot = atof( it->second.c_str() );
  2041. };
  2042. it = cArr->find("imager_type");
  2043. if( it != cArr->end() ){
  2044. tVal->imager_type = atoi( it->second.c_str() );
  2045. };
  2046. it = cArr->find("min_f");
  2047. if( it != cArr->end() ){
  2048. tVal->min_f = atof( it->second.c_str() );
  2049. };
  2050. it = cArr->find("max_f");
  2051. if( it != cArr->end() ){
  2052. tVal->max_f = atof( it->second.c_str() );
  2053. };
  2054. it = cArr->find("ptz_speed_step");
  2055. if( it != cArr->end() ){
  2056. tVal->ptz_speed_step = atof( it->second.c_str() );
  2057. };
  2058. it = cArr->find("pan_model");
  2059. if( it != cArr->end() ){
  2060. tVal->pan_model = atoi( it->second.c_str() );
  2061. };
  2062. it = cArr->find("pan_angles");
  2063. if( it != cArr->end() ){
  2064. tVal->pan_angles = atoi( it->second.c_str() );
  2065. };
  2066. it = cArr->find("tilt_model");
  2067. if( it != cArr->end() ){
  2068. tVal->tilt_model = atoi( it->second.c_str() );
  2069. };
  2070. it = cArr->find("tilt_angles");
  2071. if( it != cArr->end() ){
  2072. tVal->tilt_angles = atoi( it->second.c_str() );
  2073. };
  2074. it = cArr->find("max_range");
  2075. if( it != cArr->end() ){
  2076. tVal->max_range = atof( it->second.c_str() );
  2077. };
  2078. it = cArr->find("access_login");
  2079. if( it != cArr->end() ){
  2080. strncpy( tVal->username, it->second.c_str(), 16 );
  2081. };
  2082. it = cArr->find("access_pass");
  2083. if( it != cArr->end() ){
  2084. strncpy( tVal->password, it->second.c_str(), 16 );
  2085. };
  2086. it = cArr->find("uuid");
  2087. if( it != cArr->end() ){
  2088. strncpy( tVal->uuid, it->second.c_str(), 64 );
  2089. };
  2090. it = cArr->find("mac");
  2091. if( it != cArr->end() ){
  2092. strncpy( tVal->mac, it->second.c_str(), 16 );
  2093. };
  2094. it = cArr->find("ip");
  2095. if( it != cArr->end() ){
  2096. strncpy( tVal->ip, it->second.c_str(), 16 );
  2097. };
  2098. it = cArr->find("port");
  2099. if( it != cArr->end() ){
  2100. tVal->port = atoi( it->second.c_str() );
  2101. };
  2102. it = cArr->find("onvif_access");
  2103. if( it != cArr->end() ){
  2104. strncpy( tVal->onvif_access, it->second.c_str(), 5);
  2105. };
  2106. it = cArr->find("onvif_ctrl");
  2107. if( it != cArr->end() ){
  2108. strncpy( tVal->onvif_ctrl, it->second.c_str(), 250);
  2109. };
  2110. it = cArr->find("ptz_token");
  2111. if( it != cArr->end() ){
  2112. strncpy( tVal->ptz_token, it->second.c_str(), 64);
  2113. };
  2114. };
  2115. };
  2116. };
  2117. deleteResult( result );
  2118. };
  2119. return tVal;
  2120. };
  2121. DBC_PUSHED_CMD *argusDBC::getNodePushedCMD( uint32_t NodeID ){
  2122. DBC_PUSHED_CMD *RetVal = NULL;
  2123. if(m_bIsConnected){
  2124. char tQBuf[CTEXT];
  2125. AAssoc *result;
  2126. sprintf(tQBuf, "SELECT * FROM `nodes_qcq` WHERE `node_id`=%d AND `status`=0 LIMIT 1", NodeID );
  2127. #ifdef DEBUG_ALL
  2128. LOG(tQBuf);
  2129. #endif
  2130. result = m_pDatabase->Query( tQBuf );
  2131. if( result!= NULL ) {
  2132. if( result->size() > 0 ) {
  2133. RetVal = (DBC_PUSHED_CMD*)malloc(sizeof(DBC_PUSHED_CMD));
  2134. if( RetVal ) {
  2135. Assoc * cArr;
  2136. Assoc::iterator it;
  2137. memset( RetVal, 0, sizeof(DBC_PUSHED_CMD));
  2138. cArr = result->at(0);
  2139. it = cArr->find("id");
  2140. if( it != cArr->end() ){
  2141. RetVal->id = atoi( it->second.c_str() );
  2142. };
  2143. it = cArr->find("cmd");
  2144. if( it != cArr->end() ){
  2145. RetVal->CMD = atoi( it->second.c_str() );
  2146. };
  2147. it = cArr->find("parameter");
  2148. if( it != cArr->end() ){
  2149. strncpy( RetVal->PARAM, it->second.c_str(), 256 );
  2150. RetVal->PARAM[255] = (char)0;
  2151. };
  2152. //Only If Result is Fetched - Clear Current CMD
  2153. sprintf(tQBuf, "DELETE FROM `nodes_qcq` WHERE `id`=%d", RetVal->id );
  2154. m_pDatabase->SilentQuery( tQBuf );
  2155. };
  2156. };
  2157. };
  2158. deleteResult( result );
  2159. };
  2160. return RetVal;
  2161. };
  2162. DBC_MODULE_DATA *argusDBC::getModuleData( uint32_t ID ){
  2163. DBC_MODULE_DATA *tVal = NULL;
  2164. if(m_bIsConnected){
  2165. char tQBuf[CTEXT];
  2166. AAssoc *result;
  2167. sprintf(tQBuf, "SELECT * FROM server_modules WHERE `id`=%d", ID );
  2168. #ifdef DEBUG_ALL
  2169. LOG(tQBuf);
  2170. #endif
  2171. result = m_pDatabase->Query( tQBuf );
  2172. if( result!= NULL ) {
  2173. if( result->size() > 0 ) {
  2174. Assoc *cArr;
  2175. tVal = (DBC_MODULE_DATA*) malloc(sizeof(DBC_MODULE_DATA));
  2176. if( tVal != NULL ) {
  2177. Assoc::iterator it;
  2178. cArr = result->at(0);
  2179. it = cArr->find("id");
  2180. if( it != cArr->end() ){
  2181. tVal->module_id = atoi( it->second.c_str() );
  2182. };
  2183. it = cArr->find("aux_id");
  2184. if( it != cArr->end() ){
  2185. tVal->aux_id = atoi( it->second.c_str() );
  2186. };
  2187. it = cArr->find("type");
  2188. if( it != cArr->end() ){
  2189. tVal->type = atoi( it->second.c_str() );
  2190. };
  2191. it = cArr->find("enabled");
  2192. if( it != cArr->end() ){
  2193. tVal->enabled = (bool)atoi( it->second.c_str() );
  2194. };
  2195. };
  2196. };
  2197. };
  2198. deleteResult( result );
  2199. };
  2200. return tVal;
  2201. };
  2202. /*
  2203. DBC_SOCKET_DATA *argusDBC::getSocketData( uint32_t ID ){
  2204. DBC_SOCKET_DATA *tVal = NULL;
  2205. if(m_bIsConnected){
  2206. char tQBuf[CTEXT];
  2207. AAssoc *result;
  2208. sprintf(tQBuf, "SELECT * FROM sockets WHERE `id`=%d", ID );
  2209. #ifdef DEBUG
  2210. //LOG(tQBuf);
  2211. #endif
  2212. result = m_pDatabase->Query( tQBuf );
  2213. if( result!= NULL ) {
  2214. if( result->size() > 0 ) {
  2215. Assoc *cArr;
  2216. tVal = (DBC_SOCKET_DATA*) malloc(sizeof(DBC_SOCKET_DATA));
  2217. if( tVal != NULL ) {
  2218. Assoc::iterator it;
  2219. cArr = result->at(0);
  2220. it = cArr->find("id");
  2221. if( it != cArr->end() ){
  2222. tVal->socket_id = atoi( it->second.c_str() );
  2223. };
  2224. it = cArr->find("aux_id");
  2225. if( it != cArr->end() ){
  2226. tVal->aux_id = atoi( it->second.c_str() );
  2227. };
  2228. it = cArr->find("type");
  2229. if( it != cArr->end() ){
  2230. tVal->type = atoi( it->second.c_str() );
  2231. };
  2232. it = cArr->find("binded");
  2233. if( it != cArr->end() ){
  2234. tVal->binded = (bool)atoi( it->second.c_str() );
  2235. };
  2236. };
  2237. };
  2238. };
  2239. deleteResult( result );
  2240. };
  2241. return tVal;
  2242. };
  2243. */
  2244. DBC_MEDIA_STREAM_DATA *argusDBC::getMediaStreamData( uint32_t ID ){
  2245. DBC_MEDIA_STREAM_DATA *tVal = NULL;
  2246. if(m_bIsConnected){
  2247. char tQBuf[CTEXT];
  2248. AAssoc *result;
  2249. sprintf(tQBuf, "SELECT * FROM media_streams WHERE `id`=%d", ID );
  2250. #ifdef DEBUG_ALL
  2251. LOG(tQBuf);
  2252. #endif
  2253. result = m_pDatabase->Query( tQBuf );
  2254. if( result!= NULL ) {
  2255. if( result->size() > 0 ) {
  2256. Assoc *cArr;
  2257. tVal = (DBC_MEDIA_STREAM_DATA*) malloc(sizeof(DBC_MEDIA_STREAM_DATA));
  2258. if( tVal != NULL ) {
  2259. Assoc::iterator it;
  2260. cArr = result->at(0);
  2261. tVal->id = ID;
  2262. it = cArr->find("source_id");
  2263. if( it != cArr->end() ){
  2264. tVal->source_id = atoi( it->second.c_str() );
  2265. };
  2266. it = cArr->find("site_id");
  2267. if( it != cArr->end() ){
  2268. tVal->site_id = atoi( it->second.c_str() );
  2269. };
  2270. it = cArr->find("source_type");
  2271. if( it != cArr->end() ){
  2272. sprintf( tVal->source_type, it->second.c_str() );
  2273. };
  2274. it = cArr->find("valid");
  2275. if( it != cArr->end() ){
  2276. tVal->valid = (bool) atoi( it->second.c_str() );
  2277. };
  2278. it = cArr->find("token");
  2279. if( it != cArr->end() ){
  2280. sprintf( tVal->token, it->second.c_str() );
  2281. };
  2282. it = cArr->find("img_width");
  2283. if( it != cArr->end() ){
  2284. tVal->width = atoi( it->second.c_str() );
  2285. };
  2286. it = cArr->find("img_height");
  2287. if( it != cArr->end() ){
  2288. tVal->height = atoi( it->second.c_str() );
  2289. };
  2290. it = cArr->find("mrl_proto");
  2291. if( it != cArr->end() ){
  2292. sprintf( tVal->mrl_proto, it->second.c_str() );
  2293. };
  2294. it = cArr->find("mrl_port");
  2295. if( it != cArr->end() ){
  2296. tVal->mrl_port = atoi( it->second.c_str() );
  2297. };
  2298. it = cArr->find("mrl");
  2299. if( it != cArr->end() ){
  2300. sprintf( tVal->mrl, it->second.c_str() );
  2301. };
  2302. };
  2303. };
  2304. };
  2305. deleteResult( result );
  2306. };
  2307. return tVal;
  2308. };
  2309. DBC_MEDIA_SERVER_DATA *argusDBC::getMediaServerData( uint32_t ID ){
  2310. DBC_MEDIA_SERVER_DATA *tVal = NULL;
  2311. if(m_bIsConnected){
  2312. char tQBuf[CTEXT];
  2313. AAssoc *result;
  2314. sprintf(tQBuf, "SELECT * FROM media_servers WHERE `id`=%d", ID );
  2315. #ifdef DEBUG_ALL
  2316. LOG(tQBuf);
  2317. #endif
  2318. result = m_pDatabase->Query( tQBuf );
  2319. if( result!= NULL ) {
  2320. if( result->size() > 0 ) {
  2321. Assoc *cArr;
  2322. tVal = (DBC_MEDIA_SERVER_DATA*) malloc(sizeof(DBC_MEDIA_SERVER_DATA));
  2323. if( tVal != NULL ) {
  2324. Assoc::iterator it;
  2325. cArr = result->at(0);
  2326. tVal->id = ID;
  2327. it = cArr->find("secret_key");
  2328. if( it != cArr->end() ){
  2329. sprintf( tVal->key, it->second.c_str() );
  2330. };
  2331. it = cArr->find("ip");
  2332. if( it != cArr->end() ){
  2333. sprintf( tVal->ip, it->second.c_str() );
  2334. };
  2335. it = cArr->find("REST_port");
  2336. if( it != cArr->end() ){
  2337. tVal->port = atoi( it->second.c_str() );
  2338. };
  2339. it = cArr->find("virtual_host");
  2340. if( it != cArr->end() ){
  2341. sprintf( tVal->host, it->second.c_str() );
  2342. };
  2343. it = cArr->find("recording");
  2344. if( it != cArr->end() ){
  2345. tVal->recording = (bool)atoi( it->second.c_str() );
  2346. };
  2347. it = cArr->find("local");
  2348. if( it != cArr->end() ){
  2349. tVal->local = (bool)atoi( it->second.c_str() );
  2350. };
  2351. it = cArr->find("docRoot");
  2352. if( it != cArr->end() ){
  2353. sprintf( tVal->docRoot, it->second.c_str() );
  2354. };
  2355. sprintf( tVal->name,"ZLMedia_%d", tVal->id );
  2356. };
  2357. };
  2358. };
  2359. deleteResult( result );
  2360. };
  2361. return tVal;
  2362. };
  2363. DBC_MEDIA_SERVER_STREAM_DATA *argusDBC::getMediaServerStreamDataBySource( uint32_t ID ){
  2364. DBC_MEDIA_SERVER_STREAM_DATA *tVal = NULL;
  2365. if(m_bIsConnected){
  2366. char tQBuf[MAX_PATH_LEN];
  2367. AAssoc *result;
  2368. sprintf(tQBuf, "SELECT `id`, `media_stream_id`, `online`, `key`, `mrl` FROM media_server_streams WHERE `media_stream_id`=%d", ID );
  2369. #ifdef DEBUG_ALL
  2370. LOG(tQBuf);
  2371. #endif
  2372. result = m_pDatabase->Query( tQBuf );
  2373. if( result!= NULL ) {
  2374. if( result->size() > 0 ) {
  2375. Assoc *cArr;
  2376. tVal = (DBC_MEDIA_SERVER_STREAM_DATA*) malloc(sizeof(DBC_MEDIA_SERVER_STREAM_DATA));
  2377. if( tVal != NULL ) {
  2378. Assoc::iterator it;
  2379. cArr = result->at(0);
  2380. tVal->id = ID;
  2381. it = cArr->find("media_stream_id");
  2382. if( it != cArr->end() ){
  2383. tVal->media_stream_id = atoi( it->second.c_str() );
  2384. };
  2385. it = cArr->find("online");
  2386. if( it != cArr->end() ){
  2387. tVal->online = atoi( it->second.c_str() );
  2388. };
  2389. it = cArr->find("key");
  2390. if( it != cArr->end() ){
  2391. sprintf( tVal->key, it->second.c_str() );
  2392. };
  2393. it = cArr->find("mrl");
  2394. if( it != cArr->end() ){
  2395. sprintf( tVal->mrl, it->second.c_str() );
  2396. };
  2397. };
  2398. };
  2399. };
  2400. deleteResult( result );
  2401. };
  2402. return tVal;
  2403. };
  2404. DBC_MEDIA_SERVER_STREAM_DATA *argusDBC::getMediaServerStreamData( uint32_t ID ){
  2405. DBC_MEDIA_SERVER_STREAM_DATA *tVal = NULL;
  2406. if(m_bIsConnected){
  2407. char tQBuf[MAX_PATH_LEN];
  2408. AAssoc *result;
  2409. sprintf(tQBuf, "SELECT `id`, `media_stream_id`, `online`, `key`, `mrl` FROM media_server_streams WHERE `id`=%d", ID );
  2410. #ifdef DEBUG_ALL
  2411. LOG(tQBuf);
  2412. #endif
  2413. result = m_pDatabase->Query( tQBuf );
  2414. if( result!= NULL ) {
  2415. if( result->size() > 0 ) {
  2416. Assoc *cArr;
  2417. tVal = (DBC_MEDIA_SERVER_STREAM_DATA*) malloc(sizeof(DBC_MEDIA_SERVER_STREAM_DATA));
  2418. if( tVal != NULL ) {
  2419. Assoc::iterator it;
  2420. cArr = result->at(0);
  2421. tVal->id = ID;
  2422. it = cArr->find("media_stream_id");
  2423. if( it != cArr->end() ){
  2424. tVal->media_stream_id = atoi( it->second.c_str() );
  2425. };
  2426. it = cArr->find("online");
  2427. if( it != cArr->end() ){
  2428. tVal->online = atoi( it->second.c_str() );
  2429. };
  2430. it = cArr->find("key");
  2431. if( it != cArr->end() ){
  2432. sprintf( tVal->key, it->second.c_str() );
  2433. };
  2434. it = cArr->find("mrl");
  2435. if( it != cArr->end() ){
  2436. sprintf( tVal->mrl, it->second.c_str() );
  2437. };
  2438. };
  2439. };
  2440. };
  2441. deleteResult( result );
  2442. };
  2443. return tVal;
  2444. };
  2445. void argusDBC::registerServer(uint32_t SiteID, CSTR identity, int PID ){
  2446. if(m_bIsConnected){
  2447. m_nSiteID = SiteID;
  2448. char tQBuf[CTEXT];
  2449. sprintf(tQBuf,"INSERT INTO servers SET `site_id`=%d, `identity`='%s', `online`=1, `ts`=UNIX_TIMESTAMP(now()), pid=%d ON DUPLICATE KEY UPDATE `ts`=UNIX_TIMESTAMP(now()), `online`=1, pid=%d", SiteID, identity, PID, PID );
  2450. #ifdef DEBUG_ALL
  2451. LOG(tQBuf);
  2452. #endif
  2453. m_pDatabase->SilentQuery( tQBuf );
  2454. // Clenup Nodes and services ...
  2455. sprintf(tQBuf,"UPDATE nodes SET `online`=0 WHERE `site_id`=%d ", SiteID );
  2456. #ifdef DEBUG_ALL
  2457. LOG(tQBuf);
  2458. #endif
  2459. m_pDatabase->SilentQuery( tQBuf );
  2460. sprintf(tQBuf,"UPDATE cameras SET `online`=0 WHERE `site_id`=%d ", SiteID );
  2461. #ifdef DEBUG_ALL
  2462. LOG(tQBuf);
  2463. #endif
  2464. m_pDatabase->SilentQuery( tQBuf );
  2465. sprintf(tQBuf,"UPDATE media_streams SET `valid`=0 WHERE `site_id`=%d ", SiteID );
  2466. #ifdef DEBUG_ALL
  2467. LOG(tQBuf);
  2468. #endif
  2469. m_pDatabase->SilentQuery( tQBuf );
  2470. sprintf(tQBuf,"UPDATE media_server_streams SET `valid`=0, `online`=0 WHERE `site_id`=%d ", SiteID );
  2471. #ifdef DEBUG_ALL
  2472. LOG(tQBuf);
  2473. #endif
  2474. m_pDatabase->SilentQuery( tQBuf );
  2475. uint32_t tServerID = getServerID( identity );
  2476. if( tServerID ) {
  2477. sprintf(tQBuf,"INSERT INTO nodes SET `site_id`=%d, `aux_id`='%d', `type`= 0, `online`=1, `name`='Server Node' ON DUPLICATE KEY UPDATE `online`=1", m_nSiteID, tServerID );
  2478. #ifdef DEBUG_ALL
  2479. LOG(tQBuf);
  2480. #endif
  2481. uint32_t tServerNodeID = ( uint32_t ) m_pDatabase->QueryID( tQBuf );
  2482. if( tServerNodeID == 0 ){
  2483. tServerNodeID = getServerNode( tServerID );
  2484. };
  2485. //cleanResources( tServerNodeID );
  2486. setNodeOnline( tServerNodeID );
  2487. };
  2488. };
  2489. };
  2490. void argusDBC::unregisterServer(uint32_t ServerID, uint32_t NodeID ){
  2491. if( setNodeOffline( NodeID ) ){
  2492. char tQBuf[CTEXT];
  2493. sprintf(tQBuf,"UPDATE servers SET `online`=0, `ts`=UNIX_TIMESTAMP(now()) WHERE `id`=%d", ServerID );
  2494. #ifdef DEBUG_ALL
  2495. LOG(tQBuf);
  2496. #endif
  2497. m_pDatabase->SilentQuery( tQBuf );
  2498. };
  2499. };
  2500. bool argusDBC::setNodeOnline( uint32_t NodeID, uint8_t status ){
  2501. if(m_bIsConnected){
  2502. char tQBuf[CTEXT];
  2503. if( NodeID ) {
  2504. sprintf(tQBuf,"UPDATE nodes SET `online`=%d WHERE `id`=%d", status, NodeID );
  2505. #ifdef DEBUG_ALL
  2506. LOG(tQBuf);
  2507. #endif
  2508. m_pDatabase->SilentQuery( tQBuf );
  2509. sprintf(tQBuf,"UPDATE `resources` SET `active`=1 WHERE `node_id`=%d", NodeID );
  2510. #ifdef DEBUG_ALL
  2511. LOG(tQBuf);
  2512. #endif
  2513. m_pDatabase->SilentQuery( tQBuf );
  2514. return true;
  2515. };
  2516. };
  2517. return false;
  2518. };
  2519. bool argusDBC::setNodeOffline( uint32_t NodeID ){
  2520. if(m_bIsConnected){
  2521. char tQBuf[CTEXT];
  2522. if( NodeID ) {
  2523. sprintf(tQBuf,"UPDATE nodes SET `online`=0 WHERE `id` = %d", NodeID );
  2524. #ifdef DEBUG_ALL
  2525. LOG(tQBuf);
  2526. #endif
  2527. m_pDatabase->SilentQuery( tQBuf );
  2528. sprintf(tQBuf,"UPDATE `resources` SET `active`=0 WHERE `node_id` = %d", NodeID );
  2529. #ifdef DEBUG_ALL
  2530. LOG(tQBuf);
  2531. #endif
  2532. m_pDatabase->SilentQuery( tQBuf );
  2533. return true;
  2534. };
  2535. };
  2536. return false;
  2537. };
  2538. DBC_RESOURCE_DATA *argusDBC::getResourceData( uint32_t ResourceID ){
  2539. DBC_RESOURCE_DATA *tVal = NULL;
  2540. if( m_bIsConnected ){
  2541. char tQBuf[CTEXT];
  2542. AAssoc *result;
  2543. sprintf(tQBuf, "SELECT `node_id`, `type`, `aux_id`, `device` FROM resources WHERE `id`=%d", ResourceID );
  2544. #ifdef DEBUG_ALL
  2545. LOG(tQBuf);
  2546. #endif
  2547. result = m_pDatabase->Query( tQBuf );
  2548. if( result!= NULL ) {
  2549. if( result->size() > 0 ) {
  2550. Assoc *cArr;
  2551. tVal = (DBC_RESOURCE_DATA*) malloc(sizeof(DBC_RESOURCE_DATA));
  2552. if( tVal != NULL ) {
  2553. Assoc::iterator it;
  2554. cArr = result->at(0);
  2555. tVal->id = ResourceID;
  2556. it = cArr->find("node_id");
  2557. if( it != cArr->end() ){
  2558. tVal->node_id = atoi( it->second.c_str() );
  2559. };
  2560. it = cArr->find("type");
  2561. if( it != cArr->end() ){
  2562. tVal->type = atoi( it->second.c_str() );
  2563. };
  2564. it = cArr->find("aux_id");
  2565. if( it != cArr->end() ){
  2566. tVal->aux_id = atoi( it->second.c_str() );
  2567. };
  2568. it = cArr->find("device");
  2569. if( it != cArr->end() ){
  2570. strncpy( tVal->device, it->second.c_str(), 64 );
  2571. tVal->device[63] = (char)0;
  2572. };
  2573. };
  2574. };
  2575. };
  2576. deleteResult( result );
  2577. };
  2578. return tVal;
  2579. };
  2580. uint32_t argusDBC::getResourceID( uint32_t NodeID, uint8_t type, uint32_t auxID ){
  2581. uint32_t RetVal = 0;
  2582. if(m_bIsConnected){
  2583. char tQBuf[CTEXT];
  2584. sprintf(tQBuf,"SELECT `id` FROM `resources` WHERE `node_id`=%d AND `type`=%d AND `aux_id`=%d", NodeID, type, auxID );
  2585. #ifdef DEBUG_ALL
  2586. LOG(tQBuf);
  2587. #endif
  2588. AAssoc *result;
  2589. result = m_pDatabase->Query( tQBuf );
  2590. if( result!= NULL ) {
  2591. if( result->size() > 0 ) {
  2592. Assoc * cArr;
  2593. Assoc::iterator it;
  2594. cArr = result->at(0);
  2595. it = cArr->find("id");
  2596. if( it != cArr->end() ){
  2597. RetVal = atoi( it->second.c_str() );
  2598. };
  2599. };
  2600. };
  2601. deleteResult( result );
  2602. };
  2603. return RetVal;
  2604. };
  2605. uint32_t argusDBC::getServerID( CSTR identity ){
  2606. uint32_t RetVal = 0;
  2607. if(m_bIsConnected){
  2608. char tQBuf[CTEXT];
  2609. sprintf(tQBuf,"SELECT id FROM servers WHERE `identity`='%s'", identity );
  2610. #ifdef DEBUG_ALL
  2611. LOG(tQBuf);
  2612. #endif
  2613. AAssoc *result;
  2614. result = m_pDatabase->Query( tQBuf );
  2615. if( result!= NULL ) {
  2616. if( result->size() > 0 ) {
  2617. Assoc * cArr;
  2618. Assoc::iterator it;
  2619. cArr = result->at(0);
  2620. it = cArr->find("id");
  2621. if( it != cArr->end() ){
  2622. RetVal = atoi( it->second.c_str() );
  2623. };
  2624. };
  2625. };
  2626. deleteResult( result );
  2627. };
  2628. return RetVal;
  2629. };
  2630. uint32_t argusDBC::getServerNode( uint32_t SID ){
  2631. uint32_t RetVal = 0;
  2632. if(m_bIsConnected){
  2633. char tQBuf[CTEXT];
  2634. sprintf(tQBuf,"SELECT id FROM nodes WHERE `type`=0 AND `aux_id`=%d", SID );
  2635. #ifdef DEBUG_ALL
  2636. LOG(tQBuf);
  2637. #endif
  2638. AAssoc *result;
  2639. result = m_pDatabase->Query( tQBuf );
  2640. if( result!= NULL ) {
  2641. if( result->size() > 0 ) {
  2642. Assoc * cArr;
  2643. Assoc::iterator it;
  2644. cArr = result->at(0);
  2645. it = cArr->find("id");
  2646. if( it != cArr->end() ){
  2647. RetVal = atoi( it->second.c_str() );
  2648. };
  2649. };
  2650. };
  2651. deleteResult( result );
  2652. };
  2653. return RetVal;
  2654. };
  2655. uint32_t argusDBC::addLocalMediaSource( uint32_t SiteID, CSTR path, uint32_t width, uint32_t height ){
  2656. uint32_t RetVal = 0;
  2657. if(m_bIsConnected){
  2658. char tQBuf[1024];
  2659. char tM5[33];
  2660. CSTR tMD5 = MD5String( path );
  2661. if( tMD5 != NULL ) {
  2662. memcpy( tM5, tMD5, 33 );
  2663. tM5[32]=(char)0;
  2664. free( tMD5 );
  2665. 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",
  2666. SiteID, tM5, width, height, path, width, height );
  2667. #ifdef DEBUG_ALL
  2668. LOG(tQBuf);
  2669. #endif
  2670. RetVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
  2671. };
  2672. };
  2673. return RetVal;
  2674. };
  2675. /*
  2676. uint32_t argusDBC::addNodeSocket( uint32_t NodeID, uint32_t auxID, uint8_t SocketType, uint8_t SocketMode, bool multidrop, CSTR path, CSTR name ){
  2677. uint32_t retVal = 0;
  2678. if(m_bIsConnected){
  2679. char tQBuf[2048];
  2680. char tM5[33];
  2681. CSTR tMD5 = MD5String( path );
  2682. if( tMD5 != NULL ) {
  2683. memcpy( tM5, tMD5, 33 );
  2684. free( tMD5 );
  2685. if( multidrop ) {
  2686. 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'",
  2687. NodeID, SocketType, SocketMode, tM5, path, name, auxID, name );
  2688. } else {
  2689. 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'",
  2690. NodeID, SocketType, SocketMode, tM5, path, name, auxID, name );
  2691. };
  2692. #ifdef DEBUG
  2693. LOG(tQBuf);
  2694. #endif
  2695. //m_pDatabase->SilentQuery( tQBuf );
  2696. retVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
  2697. };
  2698. };
  2699. return retVal;
  2700. };
  2701. */
  2702. bool argusDBC::addNotification( uint32_t MSG_ID, uint8_t DIS_LVL, uint32_t OBJ_ID ){
  2703. if(m_bIsConnected){
  2704. char tQBuf[2048];
  2705. 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 );
  2706. #ifdef DEBUG_ALL
  2707. LOG(tQBuf);
  2708. #endif
  2709. m_pDatabase->SilentQuery( tQBuf );
  2710. return true;
  2711. };
  2712. return false;
  2713. };
  2714. uint32_t argusDBC::addResource( uint32_t NodeID, uint8_t type, CSTR devName, uint32_t auxID ){
  2715. uint32_t RetVal = 0;
  2716. if( m_bIsConnected ){
  2717. char tQBuf[2048];
  2718. //CSTR tMD5 = MD5String( devName );
  2719. //if( tMD5 ) {
  2720. //sprintf( tQBuf, "INSERT INTO `resources` SET `node_id`=%d, `type`=%d, `md5`='%s', `aux_id`=%d, `device`='%s', `active`=1 ON DUPLICATE KEY UPDATE `active`=1, `aux_id`=%d, `device`='%s'", NodeID, type, tMD5, auxID, devName, auxID, devName );
  2721. sprintf( tQBuf, "INSERT INTO `resources` SET `node_id`=%d, `type`=%d, `aux_id`=%d, `device`='%s', `active`=1 ON DUPLICATE KEY UPDATE `active`=1, `aux_id`=%d, `device`='%s'", NodeID, type, auxID, devName, auxID, devName );
  2722. // free( tMD5 );
  2723. #ifdef DEBUG_ALL
  2724. LOG(tQBuf);
  2725. #endif
  2726. RetVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
  2727. if( RetVal == 0 ) {
  2728. RetVal = getResourceID( NodeID, type, auxID );
  2729. };
  2730. //};
  2731. };
  2732. return RetVal;
  2733. };
  2734. /*
  2735. uint32_t argusDBC::getNodeSocketID( uint32_t NodeID, uint32_t auxID, uint8_t SocketType, CSTR path ){
  2736. uint32_t retVal = 0;
  2737. if(m_bIsConnected){
  2738. char tQBuf[2048];
  2739. char tM5[33];
  2740. CSTR tMD5 = MD5String( path );
  2741. if( tMD5 != NULL ) {
  2742. memcpy( tM5, tMD5, 33 );
  2743. free( tMD5 );
  2744. sprintf( tQBuf,"SELECT id FROM `sockets` WHERE `node_id`=%d AND `type`=%d AND `md5`='%s' AND `aux_id`=%d", NodeID, SocketType, tM5, auxID );
  2745. #ifdef DEBUG
  2746. LOG(tQBuf);
  2747. #endif
  2748. AAssoc *result;
  2749. result = m_pDatabase->Query( tQBuf );
  2750. if( result!= NULL ) {
  2751. if( result->size() > 0 ) {
  2752. Assoc * cArr;
  2753. Assoc::iterator it;
  2754. cArr = result->at(0);
  2755. it = cArr->find("id");
  2756. if( it != cArr->end() ){
  2757. retVal = atoi( it->second.c_str() );
  2758. };
  2759. };
  2760. };
  2761. deleteResult( result );
  2762. };
  2763. };
  2764. return retVal;
  2765. };
  2766. */
  2767. /*
  2768. CSTR argusDBC::getSocketName( uint32_t NodeID, uint32_t Type ){
  2769. if(m_bIsConnected){
  2770. char tQBuf[CTEXT];
  2771. sprintf( tQBuf, "SELECT `name` FROM `sockets` WHERE `node_id`=%d AND `type`=%d LIMIT 1",
  2772. NodeID, Type );
  2773. #ifdef DEBUG
  2774. LOG(tQBuf);
  2775. #endif
  2776. AAssoc *result;
  2777. result = m_pDatabase->Query( tQBuf );
  2778. if( result!= NULL ) {
  2779. if( result->size() > 0 ) {
  2780. Assoc * cArr;
  2781. Assoc::iterator it;
  2782. cArr = result->at(0);
  2783. it = cArr->find("name");
  2784. if( it != cArr->end() ){
  2785. strncpy( tQBuf, it->second.c_str(), CTEXT );
  2786. };
  2787. };
  2788. };
  2789. deleteResult( result );
  2790. return strdup(tQBuf);
  2791. };
  2792. return NULL;
  2793. };
  2794. */
  2795. KAFKA_SETTINGS *argusDBC::getSettingsKAFKA( uint32_t ModuleID ){
  2796. KAFKA_SETTINGS *tVal = NULL;
  2797. if( m_bIsConnected ) {
  2798. char tQBuf[CTEXT];
  2799. AAssoc *result;
  2800. sprintf( tQBuf, "SELECT brocker_address, brocker_port FROM modules_kafka WHERE module_id = %d", ModuleID );
  2801. #ifdef DEBUG_ALL
  2802. LOG(tQBuf);
  2803. #endif
  2804. result = m_pDatabase->Query( tQBuf );
  2805. if( result!= NULL ) {
  2806. if( result->size() > 0 ) {
  2807. Assoc *cArr;
  2808. tVal = (KAFKA_SETTINGS*) malloc(sizeof(KAFKA_SETTINGS));
  2809. if( tVal != NULL ) {
  2810. Assoc::iterator it;
  2811. cArr = result->at(0);
  2812. it = cArr->find("brocker_address");
  2813. if( it != cArr->end() ){
  2814. strncpy( tVal->brocker_addr, it->second.c_str(), 255 );
  2815. };
  2816. it = cArr->find("brocker_port");
  2817. if( it != cArr->end() ){
  2818. tVal->brocker_port = atoi( it->second.c_str() );
  2819. };
  2820. };
  2821. };
  2822. };
  2823. deleteResult( result );
  2824. };
  2825. return tVal;
  2826. };
  2827. KAFKA_TEMPLATE *argusDBC::getKafkaTemplateForEvent( uint32_t ModuleID, uint32_t ClassID, uint32_t EventID ){
  2828. KAFKA_TEMPLATE *tVal = NULL;
  2829. if( m_bIsConnected ) {
  2830. char tQBuf[CTEXT];
  2831. AAssoc *result;
  2832. sprintf( tQBuf, "SELECT topic, template FROM module_kafka_settings WHERE module_id=%d AND class_id=%d AND event_id=%d", ModuleID, ClassID, EventID );
  2833. #ifdef DEBUG_ALL
  2834. LOG(tQBuf);
  2835. #endif
  2836. result = m_pDatabase->Query( tQBuf );
  2837. if( result!= NULL ) {
  2838. if( result->size() > 0 ) {
  2839. Assoc *cArr;
  2840. tVal = (KAFKA_TEMPLATE*) malloc(sizeof(KAFKA_TEMPLATE));
  2841. if( tVal != NULL ) {
  2842. Assoc::iterator it;
  2843. cArr = result->at(0);
  2844. it = cArr->find("topic");
  2845. if( it != cArr->end() ){
  2846. memset( tVal->topic, 0, 128 );
  2847. strncpy( tVal->topic , it->second.c_str(), 127 );
  2848. };
  2849. it = cArr->find("template");
  2850. if( it != cArr->end() ){
  2851. tVal->tpl = (CSTR)malloc( it->second.length() + 1 );
  2852. if( tVal->tpl!= NULL) {
  2853. memset( tVal->tpl, 0, it->second.length() + 1 );
  2854. strncpy( tVal->tpl, it->second.c_str(), it->second.length() );
  2855. };
  2856. };
  2857. };
  2858. };
  2859. };
  2860. deleteResult( result );
  2861. };
  2862. return tVal;
  2863. };
  2864. DBC_UART_DATA *argusDBC::getUartData( uint32_t UartID ){
  2865. DBC_UART_DATA *tVal = NULL;
  2866. if( m_bIsConnected ) {
  2867. char tQBuf[MAX_PATH_LEN];
  2868. AAssoc *result;
  2869. sprintf( tQBuf, "SELECT * FROM uart_settings WHERE id = %d", UartID );
  2870. #ifdef DEBUG_ALL
  2871. LOG(tQBuf);
  2872. #endif
  2873. result = m_pDatabase->Query( tQBuf );
  2874. if( result!= NULL ) {
  2875. if( result->size() > 0 ) {
  2876. Assoc *cArr;
  2877. tVal = (DBC_UART_DATA*) malloc(sizeof(DBC_UART_DATA));
  2878. if( tVal != NULL ) {
  2879. Assoc::iterator it;
  2880. cArr = result->at(0);
  2881. it = cArr->find("type");
  2882. if( it != cArr->end() ){
  2883. tVal->type = atoi( it->second.c_str() );
  2884. };
  2885. it = cArr->find("speed");
  2886. if( it != cArr->end() ){
  2887. tVal->speed = atoi( it->second.c_str() );
  2888. };
  2889. it = cArr->find("mode");
  2890. if( it != cArr->end() ){
  2891. tVal->mode = atoi( it->second.c_str() );
  2892. };
  2893. it = cArr->find("port");
  2894. if( it != cArr->end() ){
  2895. tVal->port = atoi( it->second.c_str() );
  2896. };
  2897. it = cArr->find("path");
  2898. if( it != cArr->end() ){
  2899. strncpy( tVal->path, it->second.c_str(), 128 );
  2900. };
  2901. };
  2902. };
  2903. };
  2904. deleteResult( result );
  2905. };
  2906. return tVal;
  2907. };
  2908. uint32_t argusDBC::getUartID( uint32_t NodeID, uint8_t Type, CSTR path ){
  2909. uint32_t RetVal = 0;
  2910. if(m_bIsConnected){
  2911. char tQBuf[CTEXT];
  2912. sprintf(tQBuf,"SELECT `id` FROM `uart_settings` WHERE `node_id`=%d AND `type`=%d AND `path`='%s' ", NodeID, Type, path );
  2913. #ifdef DEBUG_ALL
  2914. LOG(tQBuf);
  2915. #endif
  2916. AAssoc *result;
  2917. result = m_pDatabase->Query( tQBuf );
  2918. if( result!= NULL ) {
  2919. if( result->size() > 0 ) {
  2920. Assoc * cArr;
  2921. Assoc::iterator it;
  2922. cArr = result->at(0);
  2923. it = cArr->find("id");
  2924. if( it != cArr->end() ){
  2925. RetVal = atoi( it->second.c_str() );
  2926. };
  2927. };
  2928. };
  2929. deleteResult( result );
  2930. };
  2931. return RetVal;
  2932. };
  2933. bool argusDBC::updateMediaServerStream( uint32_t id, CSTR mrl, CSTR key ){
  2934. if( m_bIsConnected ) {
  2935. char tQBuf[MAX_PATH_LEN];
  2936. if( key == NULL ) {
  2937. if( mrl == NULL ) {
  2938. sprintf( tQBuf,"UPDATE media_server_streams SET `online`=0, `key`='', mrl='', `valid`=0 WHERE `id`=%d", id );
  2939. } else {
  2940. sprintf( tQBuf,"UPDATE media_server_streams SET `online`=0, `key`='', `mrl`='%s', `valid`=1 WHERE `id`=%d", mrl, id );
  2941. };
  2942. } else {
  2943. sprintf( tQBuf,"UPDATE media_server_streams SET `online`=1, `key`='%s', `mrl`='%s', `valid`=1 WHERE `id`=%d",
  2944. key,
  2945. mrl,
  2946. id
  2947. );
  2948. };
  2949. #ifdef DEBUG_ALL
  2950. LOG(tQBuf);
  2951. #endif
  2952. m_pDatabase->SilentQuery( tQBuf );
  2953. return true;
  2954. };
  2955. return false;
  2956. };
  2957. bool argusDBC::updateResourceAUX( uint32_t ResID, uint32_t AUX ){
  2958. if( m_bIsConnected ) {
  2959. char tQBuf[MAX_PATH_LEN];
  2960. sprintf( tQBuf, "UPDATE `resources` SET `aux_id`=%d WHERE `id`=%d", AUX, ResID );
  2961. #ifdef DEBUG
  2962. LOG(tQBuf);
  2963. #endif
  2964. m_pDatabase->SilentQuery( tQBuf );
  2965. return true;
  2966. };
  2967. return false;
  2968. };
  2969. bool argusDBC::updateServerUtilisation( uint32_t ServerID, uint32_t nCores, float cpu1, float cpu5, float cpu15, float mem, float disk, uint64_t dtsize, uint64_t dcsize, uint64_t mtsize, uint64_t mcsize ){
  2970. if( m_bIsConnected ) {
  2971. char tQBuf[MAX_PATH_LEN];
  2972. sprintf( tQBuf, "UPDATE `servers` SET `ts`=UNIX_TIMESTAMP(now()), `cpu_cores`=%d, `stat_cpu1`=%0.2f, `stat_cpu5`=%0.2f, `stat_cpu15`=%0.2f, `stat_mem`=%0.2f, `stat_disk`=%0.2f, `val_mem_tottal`=%" PRIu64 ", `val_mem_current`=%" PRIu64 ", `val_disk_tottal`=%" PRIu64 ", `val_disk_current`=%" PRIu64 " WHERE `id`=%d",
  2973. nCores,
  2974. cpu1,
  2975. cpu5,
  2976. cpu15,
  2977. mem,
  2978. disk,
  2979. dtsize,
  2980. dcsize,
  2981. mtsize,
  2982. mcsize,
  2983. ServerID
  2984. );
  2985. #ifdef DEBUG_ALL
  2986. LOG(tQBuf);
  2987. #endif
  2988. m_pDatabase->SilentQuery( tQBuf );
  2989. return true;
  2990. };
  2991. return false;
  2992. };
  2993. uint32_t argusDBC::addLocalDCB( uint32_t SiteID, CSTR PATH, CSTR SERIAL, uint8_t CNT, uint32_t status ){
  2994. uint32_t RetVal = 0;
  2995. if( m_bIsConnected ) {
  2996. char tQBuf[MAX_PATH_LEN];
  2997. 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",
  2998. SiteID,
  2999. status,
  3000. CNT,
  3001. SERIAL,
  3002. status,
  3003. CNT
  3004. );
  3005. #ifdef DEBUG_ALL
  3006. LOG(tQBuf);
  3007. #endif
  3008. uint64_t cid = m_pDatabase->QueryID( tQBuf );
  3009. if( cid == 0 ) {
  3010. AAssoc *result;
  3011. sprintf( tQBuf, "SELECT id FROM modules_dcr WHERE site_id=%d AND serial_id='%s'",
  3012. SiteID,
  3013. SERIAL
  3014. );
  3015. #ifdef DEBUG_ALL
  3016. LOG(tQBuf);
  3017. #endif
  3018. result = m_pDatabase->Query( tQBuf );
  3019. if( result!= NULL ) {
  3020. if( result->size() > 0 ) {
  3021. Assoc * cArr;
  3022. Assoc::iterator it;
  3023. cArr = result->at(0);
  3024. it = cArr->find("id");
  3025. if( it != cArr->end() ){
  3026. cid = atoi( it->second.c_str() );
  3027. };
  3028. };
  3029. deleteResult( result );
  3030. };
  3031. };
  3032. if( cid!= 0 ) {
  3033. for( uint8_t idx = 0; idx < CNT; idx++ ) {
  3034. if( status & ( 1 << idx ) ){
  3035. sprintf( tQBuf, "INSERT INTO module_dcr_chanels SET dcr_id=%d, channel_id=%d, mode='O', status='C' ON DUPLICATE KEY UPDATE status='C'",
  3036. (uint32_t) cid,
  3037. idx
  3038. );
  3039. } else {
  3040. sprintf( tQBuf, "INSERT INTO module_dcr_chanels SET dcr_id=%d, channel_id=%d, mode='O', status='O' ON DUPLICATE KEY UPDATE status='O'",
  3041. (uint32_t) cid,
  3042. idx
  3043. );
  3044. }
  3045. #ifdef DEBUG_ALL
  3046. LOG(tQBuf);
  3047. #endif
  3048. m_pDatabase->SilentQuery( tQBuf );
  3049. };
  3050. };
  3051. };
  3052. return RetVal;
  3053. };
  3054. uint32_t argusDBC::addLocalUART( uint32_t NodeID, uint8_t utype, uint32_t speed, uint8_t bit, char parity, float stop_bit, CSTR PATH, uint8_t mode, uint16_t port ){
  3055. uint32_t RetVal = 0;
  3056. if( m_bIsConnected ) {
  3057. char tQBuf[MAX_PATH_LEN];
  3058. sprintf( tQBuf, "INSERT INTO `uart_settings` SET `node_id`=%d, `type`=%d, `speed`=%d, `bit`=%d, `parity`='%c', `stop_bit`=%.1f, `mode`=%d, `port`=%d, `path`='%s' ON DUPLICATE KEY UPDATE `id`=`id`",
  3059. NodeID,
  3060. utype,
  3061. speed,
  3062. bit,
  3063. parity,
  3064. stop_bit,
  3065. mode,
  3066. port,
  3067. PATH
  3068. );
  3069. #ifdef DEBUG_ALL
  3070. LOG(tQBuf);
  3071. #endif
  3072. RetVal = m_pDatabase->QueryID( tQBuf );
  3073. if( RetVal == 0 ) {
  3074. RetVal = getUartID( NodeID, utype, PATH );
  3075. };
  3076. };
  3077. return RetVal;
  3078. };
  3079. uint32_t argusDBC::addLocalNIF( CSTR device, CSTR mac, ARGUS_NIF_TYPE dtype, ARGUS_NIF_MODE dmode, uint32_t aux_id ){
  3080. uint32_t RetVal = 0;
  3081. if( m_bIsConnected ) {
  3082. char tQBuf[MAX_PATH_LEN];
  3083. char * tKey = MD5String( device );
  3084. if( tKey != NULL ) {
  3085. sprintf( tQBuf, "INSERT INTO `network_interfaces` SET `type`=%d, `key`='%s', `device_name`='%s', `mac`='%s', `mode`=%d, `aux_id`=%d ON DUPLICATE KEY UPDATE `mode`=%d, `aux_id`=%d, `mac`='%s'",
  3086. dtype,
  3087. tKey,
  3088. device,
  3089. mac,
  3090. dmode,
  3091. aux_id,
  3092. dmode,
  3093. aux_id,
  3094. mac
  3095. );
  3096. #ifdef DEBUG
  3097. LOG(tQBuf);
  3098. #endif
  3099. RetVal = m_pDatabase->QueryID( tQBuf );
  3100. if( RetVal == 0 ) {
  3101. RetVal = getNIF_ID( tKey );
  3102. };
  3103. free( tKey );
  3104. };
  3105. };
  3106. return RetVal;
  3107. };
  3108. uint32_t argusDBC::addLocalWiFi( uint32_t NIF_ID, ARGUS_WIFI_MODE mode, CSTR SSID, CSTR password, ARGUS_WIFI_ENCRIPTION encryption, uint32_t router_id ){
  3109. uint32_t RetVal = 0;
  3110. if( m_bIsConnected ) {
  3111. char tQBuf[MAX_PATH_LEN];
  3112. sprintf( tQBuf, "INSERT INTO `wifis` SET `nif_id`=%d, `mode`=%d, `aux_id`=%d, `SSID`='%s', `password`='%s', `encryption_type`=%d ON DUPLICATE KEY UPDATE `mode`=%d, `aux_id`=%d, `SSID`='%s', `password`='%s', `encryption_type`=%d",
  3113. NIF_ID,
  3114. mode,
  3115. router_id,
  3116. SSID,
  3117. password,
  3118. encryption,
  3119. mode,
  3120. router_id,
  3121. SSID,
  3122. password,
  3123. encryption
  3124. );
  3125. #ifdef DEBUG
  3126. LOG(tQBuf);
  3127. #endif
  3128. RetVal = m_pDatabase->QueryID( tQBuf );
  3129. if( RetVal == 0 ) {
  3130. RetVal = getWiFi_ID( NIF_ID );
  3131. };
  3132. };
  3133. return RetVal;
  3134. };
  3135. uint32_t argusDBC::addLRFMask( uint32_t devID, uint8_t lrfID, uint8_t layerID ){
  3136. uint32_t RetVal = 0;
  3137. if( m_bIsConnected ) {
  3138. char tQBuf[MAX_PATH_LEN];
  3139. sprintf( tQBuf, "INSERT INTO `lrf_masks` SET `sensor_id`=%d, `lrf_id`=%d, `layer`=%d ON DUPLICATE KEY UPDATE `id`=`id`",
  3140. devID,
  3141. lrfID,
  3142. layerID
  3143. );
  3144. #ifdef DEBUG
  3145. LOG(tQBuf);
  3146. #endif
  3147. RetVal = m_pDatabase->QueryID( tQBuf );
  3148. if( RetVal == 0 ) {
  3149. RetVal = getLRFMaskID( devID, lrfID, layerID );
  3150. };
  3151. };
  3152. return RetVal;
  3153. };
  3154. uint32_t argusDBC::addLRFMaskPolygone( uint32_t maskID, uint8_t r, uint8_t g, uint8_t b ){
  3155. uint32_t RetVal = 0;
  3156. if( m_bIsConnected ) {
  3157. char tQBuf[MAX_PATH_LEN];
  3158. sprintf( tQBuf, "INSERT INTO `lrf_mask_vertexes` SET `mask_id`=%d, `r`=%d, `g`=%d, `b`=%d",
  3159. maskID,
  3160. r,
  3161. g,
  3162. b
  3163. );
  3164. #ifdef DEBUG
  3165. LOG(tQBuf);
  3166. #endif
  3167. RetVal = m_pDatabase->QueryID( tQBuf );
  3168. };
  3169. return RetVal;
  3170. };
  3171. bool argusDBC::addLRFMaskPolygonePoint( uint32_t polyID, uint16_t x, uint16_t y ){
  3172. if( m_bIsConnected ) {
  3173. char tQBuf[MAX_PATH_LEN];
  3174. sprintf( tQBuf, "INSERT INTO `lrf_mask_vertex_points` SET `vertex_id`=%d, `x`=%d, `y`=%d",
  3175. polyID,
  3176. x,
  3177. y
  3178. );
  3179. #ifdef DEBUG
  3180. LOG(tQBuf);
  3181. #endif
  3182. m_pDatabase->SilentQuery( tQBuf );
  3183. return true;
  3184. };
  3185. return false;
  3186. };
  3187. uint32_t argusDBC::addLocalNetwork( uint32_t NIF_ID, ARGUS_NETWORK_TYPE net_type, CSTR address, CSTR mask, CSTR gateway, CSTR broadcast ){
  3188. uint32_t RetVal = 0;
  3189. if( m_bIsConnected ) {
  3190. char tQBuf[MAX_PATH_LEN];
  3191. sprintf( tQBuf, "INSERT INTO `networks` SET `nif_id`=%d, `type`=%d, `address`='%s', `gateway`='%s', `mask`='%s', `broadcast`='%s' ON DUPLICATE KEY UPDATE `address`='%s', `gateway`='%s', `mask`='%s', `broadcast`='%s'",
  3192. NIF_ID,
  3193. net_type,
  3194. address,
  3195. gateway,
  3196. mask,
  3197. broadcast,
  3198. address,
  3199. gateway,
  3200. mask,
  3201. broadcast
  3202. );
  3203. #ifdef DEBUG
  3204. LOG(tQBuf);
  3205. #endif
  3206. RetVal = m_pDatabase->QueryID( tQBuf );
  3207. // On Update IF data no need to return ID
  3208. //if( RetVal == 0 ) {
  3209. // RetVal = getNetworkInterfaceID( tKey );
  3210. //};
  3211. };
  3212. return RetVal;
  3213. };
  3214. uint32_t argusDBC::addLocalNetworkInfrastructure( uint32_t NIF_ID, uint32_t OUTBOUND_NIF, bool ena_dhcp, CSTR BRANG, CSTR ERANG, CSTR MASK, CSTR LEASE_TIME ){
  3215. uint32_t RetVal = 0;
  3216. if( m_bIsConnected ) {
  3217. char tQBuf[MAX_PATH_LEN];
  3218. bool ena_routing = true;
  3219. if( OUTBOUND_NIF == 0 ){
  3220. ena_routing = false;
  3221. };
  3222. if( ena_dhcp ){
  3223. if ( BRANG == NULL || ERANG == NULL || MASK == NULL || LEASE_TIME == NULL ) {
  3224. LOG_ERROR("Wrong DHCP parameters to create Network Infrastructure!");
  3225. return 0;
  3226. };
  3227. sprintf(tQBuf, "INSERT INTO `network_infrastructure` SET `nif_id`=%d, `enable_routing`=%d, `outbond_nif`=%d, `enable_dhcp`=1, `dhcp_range_begin`='%s', `dhcp_range_end`='%s', `dhcp_range_mask`='%s', `dhcp_lease_time`='%s' ON DUPLICATE KEY UPDATE `enable_routing`=%d, `outbond_nif`=%d, `enable_dhcp`=1, `dhcp_range_begin`='%s', `dhcp_range_end`='%s', `dhcp_range_mask`='%s', `dhcp_lease_time`='%s'",
  3228. NIF_ID,
  3229. ena_routing,
  3230. OUTBOUND_NIF,
  3231. BRANG,
  3232. ERANG,
  3233. MASK,
  3234. LEASE_TIME,
  3235. ena_routing,
  3236. OUTBOUND_NIF,
  3237. BRANG,
  3238. ERANG,
  3239. MASK,
  3240. LEASE_TIME
  3241. );
  3242. } else {
  3243. if( ena_routing ){
  3244. sprintf(tQBuf, "INSERT INTO `network_infrastructure` SET `nif_id`=%d, `enable_routing`=1, `outbond_nif`=%d ON DUPLICATE KEY UPDATE `enable_routing`=1, `outbond_nif`=%d",
  3245. NIF_ID,
  3246. OUTBOUND_NIF,
  3247. OUTBOUND_NIF
  3248. );
  3249. } else {
  3250. LOG_ERROR("No Special Service Defined To Network Infrastructure!");
  3251. return 0;
  3252. };
  3253. };
  3254. #ifdef DEBUG_ALL
  3255. LOG(tQBuf);
  3256. #endif
  3257. RetVal = m_pDatabase->QueryID( tQBuf );
  3258. // On Update IF data no need to return ID
  3259. if( RetVal == 0 ) {
  3260. RetVal = getNetworkInfrastructureID( NIF_ID );
  3261. };
  3262. };
  3263. return RetVal;
  3264. };
  3265. bool argusDBC::addDraw( uint32_t DBID, uint32_t SIZE, CSTR ID, uint8_t kID, uint8_t type, bool rendered ){
  3266. if( m_bIsConnected ) {
  3267. char tQBuf[MAX_PATH_LEN];
  3268. if ( rendered ) {
  3269. sprintf(tQBuf, "INSERT INTO `lrf_draw` SET `node_id`=%d,`ts`=NOW(),`md5`='%s',`size`=%d, `lrf_id`=%d, `type`=%d, `rendered`='Y' ON DUPLICATE KEY UPDATE `ts`=NOW(),`md5`='%s',`size`=%d, `rendered`='Y'",
  3270. DBID,
  3271. ID,
  3272. SIZE,
  3273. kID,
  3274. type,
  3275. ID,
  3276. SIZE
  3277. );
  3278. } else {
  3279. sprintf(tQBuf, "INSERT INTO `lrf_draw` SET `node_id`=%d,`ts`=NOW(),`md5`='%s',`size`=%d, `lrf_id`=%d, `type`=%d ON DUPLICATE KEY UPDATE `ts`=NOW(),`md5`='%s',`size`=%d, `rendered`='N'",
  3280. DBID,
  3281. ID,
  3282. SIZE,
  3283. kID,
  3284. type,
  3285. ID,
  3286. SIZE
  3287. );
  3288. };
  3289. #ifdef DEBUG
  3290. LOG(tQBuf);
  3291. #endif
  3292. m_pDatabase->SilentQuery( tQBuf );
  3293. return true;
  3294. };
  3295. return false;
  3296. };
  3297. uint32_t argusDBC::addEvent( uint32_t SRC, CSTR UUID, uint32_t tss, uint32_t tsms, uint8_t evt_type, uint8_t k_id, uint16_t dig_r, float EL, float AZ, float RANGE, float AREA, float lat, float lon, float alt, uint32_t RefID, CSTR RefUUID ){
  3298. uint32_t RetVal = 0;
  3299. if( m_bIsConnected ) {
  3300. char tQBuf[MAX_PATH_LEN];
  3301. if( RefUUID == NULL ) {
  3302. sprintf( tQBuf,"INSERT INTO events_cloud SET node_id=%d, uuid='%s', ts=%d, ts_ms=%d, evt_type=%d, lrf_id=%d, range_digital=%d, azimuth=%0.6f, elevation=%0.6f, `range`=%0.2f, area=%0.3f, lat=%0.6f, lon=%0.6f, alt=%0.3f",
  3303. SRC,
  3304. UUID,
  3305. tss,
  3306. tsms,
  3307. evt_type,
  3308. k_id,
  3309. dig_r,
  3310. AZ,
  3311. EL,
  3312. RANGE,
  3313. AREA,
  3314. lat,
  3315. lon,
  3316. alt
  3317. );
  3318. } else {
  3319. sprintf( tQBuf,"INSERT INTO events_cloud SET node_id=%d, uuid='%s', ts=%d, ts_ms=%d, evt_type=%d, lrf_id=%d, range_digital=%d, azimuth=%0.6f, elevation=%0.6f, `range`=%0.2f, area=%0.3f, lat=%0.6f, lon=%0.6f, alt=%0.3f, ref_uuid='%s'",
  3320. SRC,
  3321. UUID,
  3322. tss,
  3323. tsms,
  3324. evt_type,
  3325. k_id,
  3326. dig_r,
  3327. AZ,
  3328. EL,
  3329. RANGE,
  3330. AREA,
  3331. lat,
  3332. lon,
  3333. alt,
  3334. RefUUID
  3335. );
  3336. };
  3337. #ifdef DEBUG_ALL
  3338. LOG(tQBuf);
  3339. #endif
  3340. RetVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
  3341. };
  3342. return RetVal;
  3343. };
  3344. bool argusDBC::addVideoEvent( uint32_t evtID, uint32_t videoID ){
  3345. if( m_bIsConnected ) {
  3346. char tQBuf[MAX_PATH_LEN];
  3347. sprintf( tQBuf, "INSERT INTO `events_2_videos` SET `evt_id`=%d, `video_id`=%d", evtID, videoID );
  3348. #ifdef DEBUG_ALL
  3349. LOG(tQBuf);
  3350. #endif
  3351. m_pDatabase->SilentQuery( tQBuf );
  3352. return true;
  3353. };
  3354. return true;
  3355. };
  3356. bool argusDBC::addPictureEvent( uint32_t evtID, uint32_t pictureoID ){
  3357. if( m_bIsConnected ) {
  3358. char tQBuf[MAX_PATH_LEN];
  3359. sprintf( tQBuf, "INSERT INTO `events_2_pictures` SET `evt_id`=%d, `picture_id`=%d", evtID, pictureoID );
  3360. #ifdef DEBUG_ALL
  3361. LOG(tQBuf);
  3362. #endif
  3363. m_pDatabase->SilentQuery( tQBuf );
  3364. return true;
  3365. };
  3366. return true;
  3367. };
  3368. uint32_t argusDBC::addVideoRecord( uint32_t streamID, CSTR md5, uint32_t partID ){
  3369. uint32_t tID = 0;
  3370. if( m_bIsConnected ) {
  3371. char tQBuf[MAX_PATH_LEN];
  3372. sprintf( tQBuf, "INSERT INTO `videos` SET `media_stream_id`=%d, `ts`=NOW(), `md5`='%s', `part_id`=%d ", streamID, md5, partID );
  3373. #ifdef DEBUG_ALL
  3374. LOG(tQBuf);
  3375. #endif
  3376. tID = (uint32_t) m_pDatabase->QueryID( tQBuf );
  3377. }
  3378. return tID;
  3379. };
  3380. uint32_t argusDBC::addPicture( uint32_t streamID, CSTR md5, CSTR ext ){
  3381. uint32_t tID = 0;
  3382. if( m_bIsConnected ) {
  3383. char tQBuf[MAX_PATH_LEN];
  3384. sprintf( tQBuf, "INSERT INTO `videos` SET `media_stream_id`=%d, `ts`=NOW(), `md5`='%s', `ext`='%s'", streamID, md5, ext );
  3385. #ifdef DEBUG_ALL
  3386. LOG(tQBuf);
  3387. #endif
  3388. tID = (uint32_t) m_pDatabase->QueryID( tQBuf );
  3389. }
  3390. return tID;
  3391. };
  3392. 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 ){
  3393. if( m_bIsConnected ) {
  3394. char tQBuf[MAX_PATH_LEN];
  3395. if( master ) {
  3396. 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'",
  3397. nOrder,
  3398. nOffset,
  3399. nDelta,
  3400. nFlip,
  3401. nWidth,
  3402. bSST,
  3403. nSun,
  3404. GP,
  3405. spikes,
  3406. lrfID,
  3407. profileID );
  3408. } else {
  3409. 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'",
  3410. nOrder,
  3411. nOffset,
  3412. nDelta,
  3413. nFlip,
  3414. nWidth,
  3415. bSST,
  3416. nSun,
  3417. GP,
  3418. spikes,
  3419. lrfID,
  3420. profileID );
  3421. };
  3422. #ifdef DEBUG_ALL
  3423. LOG(tQBuf);
  3424. #endif
  3425. m_pDatabase->SilentQuery( tQBuf );
  3426. return true;
  3427. };
  3428. return false;
  3429. };
  3430. bool argusDBC::updateLRFSerial( uint32_t lrfID, CSTR Serial ){
  3431. if( m_bIsConnected ) {
  3432. char tQBuf[MAX_PATH_LEN];
  3433. CSTR tES = m_pDatabase->escapeString( Serial );
  3434. if( tES ) {
  3435. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `serial`='%s' WHERE `id`=%d", tES, lrfID );
  3436. free( tES );
  3437. #ifdef DEBUG_ALL
  3438. LOG(tQBuf);
  3439. #endif
  3440. m_pDatabase->SilentQuery( tQBuf );
  3441. return true;
  3442. };
  3443. };
  3444. return false;
  3445. };
  3446. bool argusDBC::updateLRFVerison( uint32_t lrfID, CSTR version ){
  3447. if( m_bIsConnected ) {
  3448. char tQBuf[MAX_PATH_LEN];
  3449. CSTR tES = m_pDatabase->escapeString( version );
  3450. if( tES ) {
  3451. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `version`='%s' WHERE `id`=%d", tES, lrfID );
  3452. free( tES );
  3453. #ifdef DEBUG_ALL
  3454. LOG(tQBuf);
  3455. #endif
  3456. m_pDatabase->SilentQuery( tQBuf );
  3457. return true;
  3458. };
  3459. };
  3460. return false;
  3461. };
  3462. bool argusDBC::update3DRuntimeStatus( uint32_t lrfID, ALG_RUN_STATUS *ptr ){
  3463. if( m_bIsConnected ) {
  3464. char tQBuf[MAX_PATH_LEN];
  3465. sprintf( tQBuf, "INSERT INTO `lrf_runtime_status` SET `lrf_id`=%d ON DUPLICATE KEY UPDATE `lrf_id`=`lrf_id`", lrfID );
  3466. #ifdef DEBUG_ALL
  3467. LOG(tQBuf);
  3468. #endif
  3469. m_pDatabase->SilentQuery( tQBuf );
  3470. sprintf( tQBuf,
  3471. "UPDATE `lrf_runtime_status` SET "
  3472. "`hw_status`=%d,"
  3473. "`detecting_kernels`=%d,"
  3474. "`th_ready`=%d,"
  3475. "`master_flips`=%d,"
  3476. "`slave_flips`=%d,"
  3477. "`twinc`=%d,"
  3478. "`master_mp_0`=%d,"
  3479. "`master_mp_1`=%d,"
  3480. "`master_mp_2`=%d,"
  3481. "`master_mp_3`=%d,"
  3482. "`master_mp_4`=%d,"
  3483. "`master_mp_5`=%d,"
  3484. "`master_mp_6`=%d,"
  3485. "`master_mp_7`=%d,"
  3486. "`master_gp_0`=%d,"
  3487. "`master_gp_1`=%d,"
  3488. "`master_gp_2`=%d,"
  3489. "`master_gp_3`=%d,"
  3490. "`master_gp_4`=%d,"
  3491. "`master_gp_5`=%d,"
  3492. "`master_gp_6`=%d,"
  3493. "`master_gp_7`=%d,"
  3494. "`master_wp_0`=%d,"
  3495. "`master_wp_1`=%d,"
  3496. "`master_wp_2`=%d,"
  3497. "`master_wp_3`=%d,"
  3498. "`master_wp_4`=%d,"
  3499. "`master_wp_5`=%d,"
  3500. "`master_wp_6`=%d,"
  3501. "`master_wp_7`=%d,"
  3502. "`slave_mp_0`=%d,"
  3503. "`slave_mp_1`=%d,"
  3504. "`slave_mp_2`=%d,"
  3505. "`slave_mp_3`=%d,"
  3506. "`slave_mp_4`=%d,"
  3507. "`slave_mp_5`=%d,"
  3508. "`slave_mp_6`=%d,"
  3509. "`slave_mp_7`=%d,"
  3510. "`slave_gp_0`=%d,"
  3511. "`slave_gp_1`=%d,"
  3512. "`slave_gp_2`=%d,"
  3513. "`slave_gp_3`=%d,"
  3514. "`slave_gp_4`=%d,"
  3515. "`slave_gp_5`=%d,"
  3516. "`slave_gp_6`=%d,"
  3517. "`slave_gp_7`=%d,"
  3518. "`slave_wp_0`=%d,"
  3519. "`slave_wp_1`=%d,"
  3520. "`slave_wp_2`=%d,"
  3521. "`slave_wp_3`=%d,"
  3522. "`slave_wp_4`=%d,"
  3523. "`slave_wp_5`=%d,"
  3524. "`slave_wp_6`=%d,"
  3525. "`slave_wp_7`=%d"
  3526. " WHERE `lrf_id`=%d",
  3527. ptr->HW_STATUS,
  3528. ptr->DETECTING_LRF,
  3529. ptr->TH_READY,
  3530. ptr->MASTER_FLIP_CNT,
  3531. ptr->SLAVE_FLIP_CNT,
  3532. ptr->TWINC_STATUS,
  3533. ptr->MASTER_MP[0],
  3534. ptr->MASTER_MP[1],
  3535. ptr->MASTER_MP[2],
  3536. ptr->MASTER_MP[3],
  3537. ptr->MASTER_MP[4],
  3538. ptr->MASTER_MP[5],
  3539. ptr->MASTER_MP[6],
  3540. ptr->MASTER_MP[7],
  3541. ptr->MASTER_GP[0],
  3542. ptr->MASTER_GP[1],
  3543. ptr->MASTER_GP[2],
  3544. ptr->MASTER_GP[3],
  3545. ptr->MASTER_GP[4],
  3546. ptr->MASTER_GP[5],
  3547. ptr->MASTER_GP[6],
  3548. ptr->MASTER_GP[7],
  3549. ptr->MASTER_WP[0],
  3550. ptr->MASTER_WP[1],
  3551. ptr->MASTER_WP[2],
  3552. ptr->MASTER_WP[3],
  3553. ptr->MASTER_WP[4],
  3554. ptr->MASTER_WP[5],
  3555. ptr->MASTER_WP[6],
  3556. ptr->MASTER_WP[7],
  3557. ptr->SLAVE_MP[0],
  3558. ptr->SLAVE_MP[1],
  3559. ptr->SLAVE_MP[2],
  3560. ptr->SLAVE_MP[3],
  3561. ptr->SLAVE_MP[4],
  3562. ptr->SLAVE_MP[5],
  3563. ptr->SLAVE_MP[6],
  3564. ptr->SLAVE_MP[7],
  3565. ptr->SLAVE_GP[0],
  3566. ptr->SLAVE_GP[1],
  3567. ptr->SLAVE_GP[2],
  3568. ptr->SLAVE_GP[3],
  3569. ptr->SLAVE_GP[4],
  3570. ptr->SLAVE_GP[5],
  3571. ptr->SLAVE_GP[6],
  3572. ptr->SLAVE_GP[7],
  3573. ptr->SLAVE_WP[0],
  3574. ptr->SLAVE_WP[1],
  3575. ptr->SLAVE_WP[2],
  3576. ptr->SLAVE_WP[3],
  3577. ptr->SLAVE_WP[4],
  3578. ptr->SLAVE_WP[5],
  3579. ptr->SLAVE_WP[6],
  3580. ptr->SLAVE_WP[7],
  3581. lrfID
  3582. );
  3583. #ifdef DEBUG_ALL
  3584. LOG(tQBuf);
  3585. #endif
  3586. m_pDatabase->SilentQuery( tQBuf );
  3587. return true;
  3588. };
  3589. return false;
  3590. };
  3591. bool argusDBC::setLRFDataStatus( uint32_t lrfID, uint8_t ST ){
  3592. if( m_bIsConnected ) {
  3593. char tQBuf[MAX_PATH_LEN];
  3594. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `data_status`=%d WHERE `id`=%d", ST, lrfID );
  3595. #ifdef DEBUG_ALL
  3596. LOG(tQBuf);
  3597. #endif
  3598. m_pDatabase->SilentQuery( tQBuf );
  3599. return true;
  3600. };
  3601. return false;
  3602. };
  3603. bool argusDBC::setLRFDetectionProfile( uint32_t lrfID, uint8_t profileID ){
  3604. if( m_bIsConnected ) {
  3605. char tQBuf[MAX_PATH_LEN];
  3606. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `detection_profile_id`=%d WHERE `id`=%d", profileID, lrfID );
  3607. #ifdef DEBUG_ALL
  3608. LOG(tQBuf);
  3609. #endif
  3610. m_pDatabase->SilentQuery( tQBuf );
  3611. return true;
  3612. };
  3613. return false;
  3614. };
  3615. bool argusDBC::setLRFMaskStatus( uint32_t maskID, bool status ){
  3616. if( m_bIsConnected ) {
  3617. char tQBuf[MAX_PATH_LEN];
  3618. char S[2];
  3619. if (status ) {
  3620. S[0] = 'E';
  3621. S[1] = (char)0;
  3622. } else {
  3623. S[0] = 'D';
  3624. S[1] = (char)0;
  3625. };
  3626. sprintf( tQBuf, "UPDATE `lrf_masks` SET `status`='%s' WHERE `id`=%d", S, maskID );
  3627. #ifdef DEBUG_ALL
  3628. LOG(tQBuf);
  3629. #endif
  3630. m_pDatabase->SilentQuery( tQBuf );
  3631. return true;
  3632. };
  3633. return false;
  3634. };
  3635. bool argusDBC::setLRFAltSerial( uint32_t lrfID, CSTR Serial ){
  3636. if( m_bIsConnected ) {
  3637. char tQBuf[MAX_PATH_LEN];
  3638. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `alt_serial`='%s' WHERE `id`=%d", Serial, lrfID );
  3639. #ifdef DEBUG_ALL
  3640. LOG(tQBuf);
  3641. #endif
  3642. m_pDatabase->SilentQuery( tQBuf );
  3643. return true;
  3644. };
  3645. return false;
  3646. };
  3647. bool argusDBC::setLRFAltVerison( uint32_t lrfID, CSTR version ){
  3648. if( m_bIsConnected ) {
  3649. char tQBuf[MAX_PATH_LEN];
  3650. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `alt_version`='%s' WHERE `id`=%d", version, lrfID );
  3651. #ifdef DEBUG_ALL
  3652. LOG(tQBuf);
  3653. #endif
  3654. m_pDatabase->SilentQuery( tQBuf );
  3655. return true;
  3656. };
  3657. return false;
  3658. };
  3659. bool argusDBC::setStreamValid( uint32_t streamID ){
  3660. if( m_bIsConnected ) {
  3661. char tQBuf[MAX_PATH_LEN];
  3662. sprintf( tQBuf, "UPDATE `media_streams` SET `valid`=1 WHERE `id`=%d", streamID );
  3663. #ifdef DEBUG_ALL
  3664. LOG(tQBuf);
  3665. #endif
  3666. m_pDatabase->SilentQuery( tQBuf );
  3667. return true;
  3668. };
  3669. return false;
  3670. };
  3671. bool argusDBC::updateAFPBox( uint32_t filterID, CSTR Tag, float x, float y, float z ){
  3672. if( m_bIsConnected ) {
  3673. char tQBuf[MAX_PATH_LEN];
  3674. 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",
  3675. filterID,
  3676. Tag,
  3677. x,y,z,
  3678. x,y,z
  3679. );
  3680. #ifdef DEBUG_ALL
  3681. LOG(tQBuf);
  3682. #endif
  3683. m_pDatabase->SilentQuery( tQBuf );
  3684. return true;
  3685. };
  3686. return false;
  3687. };
  3688. DBC_MODULE_EMBED_VIDEO_DATA *argusDBC::getEmbedVideoData( uint32_t ID ){
  3689. DBC_MODULE_EMBED_VIDEO_DATA *tPtr = NULL;
  3690. if( m_bIsConnected ) {
  3691. char tQBuf[MAX_PATH_LEN];
  3692. AAssoc *result;
  3693. sprintf( tQBuf, "SELECT * FROM `module_embed_video_settings` WHERE `id`=%d", ID );
  3694. #ifdef DEBUG_ALL
  3695. LOG(tQBuf);
  3696. #endif
  3697. result = m_pDatabase->Query( tQBuf );
  3698. if( result!= NULL ) {
  3699. if( result->size() > 0 ) {
  3700. Assoc *cArr;
  3701. tPtr = (DBC_MODULE_EMBED_VIDEO_DATA*)malloc(sizeof(DBC_MODULE_EMBED_VIDEO_DATA));
  3702. if( tPtr!= NULL ) {
  3703. Assoc::iterator it;
  3704. memset(tPtr,0,sizeof(DBC_MODULE_EMBED_VIDEO_DATA));
  3705. cArr = result->at(0);
  3706. it = cArr->find("web_port");
  3707. if( it != cArr->end() ){
  3708. tPtr->port = atoi( it->second.c_str() );
  3709. };
  3710. it = cArr->find("width");
  3711. if( it != cArr->end() ){
  3712. tPtr->width = atoi( it->second.c_str() );
  3713. };
  3714. it = cArr->find("height");
  3715. if( it != cArr->end() ){
  3716. tPtr->height = atoi( it->second.c_str() );
  3717. };
  3718. it = cArr->find("compression_quality");
  3719. if( it != cArr->end() ){
  3720. tPtr->compression_quality = atoi( it->second.c_str() );
  3721. };
  3722. it = cArr->find("show_ts");
  3723. if( it != cArr->end() ){
  3724. tPtr->show_ts = (bool)atoi( it->second.c_str() );
  3725. };
  3726. it = cArr->find("ts_x");
  3727. if( it != cArr->end() ){
  3728. tPtr->ts_x = atoi( it->second.c_str() );
  3729. };
  3730. it = cArr->find("ts_y");
  3731. if( it != cArr->end() ){
  3732. tPtr->ts_y = atoi( it->second.c_str() );
  3733. };
  3734. it = cArr->find("ts_font_face");
  3735. if( it != cArr->end() ){
  3736. tPtr->ts_font_face = atoi( it->second.c_str() );
  3737. };
  3738. it = cArr->find("ts_font_scale");
  3739. if( it != cArr->end() ){
  3740. tPtr->ts_font_scale = atof( it->second.c_str() );
  3741. };
  3742. it = cArr->find("ts_font_thickness");
  3743. if( it != cArr->end() ){
  3744. tPtr->ts_font_thickness = atoi( it->second.c_str() );
  3745. };
  3746. it = cArr->find("ts_line_type");
  3747. if( it != cArr->end() ){
  3748. tPtr->ts_line_type = atoi( it->second.c_str() );
  3749. };
  3750. it = cArr->find("ts_transperant");
  3751. if( it != cArr->end() ){
  3752. tPtr->ts_transperant = (bool)atoi( it->second.c_str() );
  3753. };
  3754. it = cArr->find("show_label");
  3755. if( it != cArr->end() ){
  3756. tPtr->show_label = (bool)atoi( it->second.c_str() );
  3757. };
  3758. it = cArr->find("label_x");
  3759. if( it != cArr->end() ){
  3760. tPtr->label_x = atoi( it->second.c_str() );
  3761. };
  3762. it = cArr->find("label_y");
  3763. if( it != cArr->end() ){
  3764. tPtr->label_y = atoi( it->second.c_str() );
  3765. };
  3766. it = cArr->find("label_font_face");
  3767. if( it != cArr->end() ){
  3768. tPtr->label_font_face = atoi( it->second.c_str() );
  3769. };
  3770. it = cArr->find("label_font_scale");
  3771. if( it != cArr->end() ){
  3772. tPtr->label_font_scale = atof( it->second.c_str() );
  3773. };
  3774. it = cArr->find("label_font_thickness");
  3775. if( it != cArr->end() ){
  3776. tPtr->label_font_thickness = atoi( it->second.c_str() );
  3777. };
  3778. it = cArr->find("label_line_type");
  3779. if( it != cArr->end() ){
  3780. tPtr->label_line_type = atoi( it->second.c_str() );
  3781. };
  3782. it = cArr->find("label_transperant");
  3783. if( it != cArr->end() ){
  3784. tPtr->label_transperant = (bool) atoi( it->second.c_str() );
  3785. };
  3786. it = cArr->find("show_logo");
  3787. if( it != cArr->end() ){
  3788. tPtr->show_logo = (bool) atoi( it->second.c_str() );
  3789. };
  3790. it = cArr->find("logo_w");
  3791. if( it != cArr->end() ){
  3792. tPtr->logo_w = atoi( it->second.c_str() );
  3793. };
  3794. it = cArr->find("logo_h");
  3795. if( it != cArr->end() ){
  3796. tPtr->logo_h = atoi( it->second.c_str() );
  3797. };
  3798. it = cArr->find("logo_x");
  3799. if( it != cArr->end() ){
  3800. tPtr->logo_x = atoi( it->second.c_str() );
  3801. };
  3802. it = cArr->find("logo_y");
  3803. if( it != cArr->end() ){
  3804. tPtr->logo_y = atoi( it->second.c_str() );
  3805. };
  3806. it = cArr->find("logo_md5");
  3807. if( it != cArr->end() ){
  3808. strncpy( tPtr->logo_md5, it->second.c_str(),32);
  3809. tPtr->logo_md5[32]=(char)0;
  3810. };
  3811. };
  3812. };
  3813. };
  3814. deleteResult( result );
  3815. };
  3816. return tPtr;
  3817. };
  3818. DBC_EVT_RECORD *argusDBC::getEventByUUID( CSTR UUID ){
  3819. DBC_EVT_RECORD *tPtr = NULL;
  3820. if( m_bIsConnected ) {
  3821. char tQBuf[MAX_PATH_LEN];
  3822. AAssoc *result;
  3823. sprintf( tQBuf, "SELECT * FROM events_cloud WHERE uuid = '%s'", UUID );
  3824. #ifdef DEBUG_ALL
  3825. LOG(tQBuf);
  3826. #endif
  3827. result = m_pDatabase->Query( tQBuf );
  3828. if( result!= NULL ) {
  3829. if( result->size() > 0 ) {
  3830. Assoc *cArr;
  3831. tPtr = (DBC_EVT_RECORD*)malloc(sizeof(DBC_EVT_RECORD));
  3832. if( tPtr!= NULL ) {
  3833. Assoc::iterator it;
  3834. memset(tPtr,0,sizeof(DBC_EVT_RECORD));
  3835. cArr = result->at(0);
  3836. it = cArr->find("id");
  3837. if( it != cArr->end() ){
  3838. tPtr->id = atoi( it->second.c_str() );
  3839. };
  3840. it = cArr->find("node_id");
  3841. if( it != cArr->end() ){
  3842. tPtr->node_id = atoi( it->second.c_str() );
  3843. };
  3844. it = cArr->find("uuid");
  3845. if( it != cArr->end() ){
  3846. strncpy( tPtr->uuid, it->second.c_str(),64 );
  3847. };
  3848. it = cArr->find("ts");
  3849. if( it != cArr->end() ){
  3850. tPtr->ts_s = atoi( it->second.c_str() );
  3851. };
  3852. it = cArr->find("ts_ms");
  3853. if( it != cArr->end() ){
  3854. tPtr->ts_ms = atoi( it->second.c_str() );
  3855. };
  3856. it = cArr->find("evt_type");
  3857. if( it != cArr->end() ){
  3858. tPtr->type = atoi( it->second.c_str() );
  3859. };
  3860. it = cArr->find("range_digital");
  3861. if( it != cArr->end() ){
  3862. tPtr->range_digital = atoi( it->second.c_str() );
  3863. };
  3864. it = cArr->find("azimuth");
  3865. if( it != cArr->end() ){
  3866. tPtr->az = atof( it->second.c_str() );
  3867. };
  3868. it = cArr->find("elevation");
  3869. if( it != cArr->end() ){
  3870. tPtr->el = atof( it->second.c_str() );
  3871. };
  3872. it = cArr->find("range");
  3873. if( it != cArr->end() ){
  3874. tPtr->ra = atof( it->second.c_str() );
  3875. };
  3876. it = cArr->find("area");
  3877. if( it != cArr->end() ){
  3878. tPtr->area = atof( it->second.c_str() );
  3879. };
  3880. it = cArr->find("lat");
  3881. if( it != cArr->end() ){
  3882. tPtr->lat = atof( it->second.c_str() );
  3883. };
  3884. it = cArr->find("lon");
  3885. if( it != cArr->end() ){
  3886. tPtr->lon = atof( it->second.c_str() );
  3887. };
  3888. it = cArr->find("alt");
  3889. if( it != cArr->end() ){
  3890. tPtr->alt = atof( it->second.c_str() );
  3891. };
  3892. it = cArr->find("ref_id");
  3893. if( it != cArr->end() ){
  3894. tPtr->ref_id = atoi( it->second.c_str() );
  3895. };
  3896. it = cArr->find("ref_uuid");
  3897. if( it != cArr->end() ){
  3898. strncpy( tPtr->ref_uuid, it->second.c_str(),64 );
  3899. };
  3900. };
  3901. };
  3902. };
  3903. deleteResult( result );
  3904. };
  3905. return tPtr;
  3906. };
  3907. #undef LOG
  3908. #undef LOG_ERROR