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.

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