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.

4422 lines
158 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
​
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. it = cArr->find("trigger_mode");
  2424. if( it != cArr->end() ){
  2425. tVal->triggering_mode = atoi( it->second.c_str() );
  2426. };
  2427. };
  2428. };
  2429. };
  2430. deleteResult( result );
  2431. };
  2432. return tVal;
  2433. };
  2434. DBC_PUSHED_CMD *argusDBC::getNodePushedCMD( uint32_t NodeID ){
  2435. DBC_PUSHED_CMD *RetVal = NULL;
  2436. if(m_bIsConnected){
  2437. char tQBuf[CTEXT];
  2438. AAssoc *result;
  2439. sprintf(tQBuf, "SELECT * FROM `nodes_qcq` WHERE `node_id`=%d AND `status`=0 LIMIT 1", NodeID );
  2440. #ifdef DEBUG_ALL
  2441. LOG(tQBuf);
  2442. #endif
  2443. result = m_pDatabase->Query( tQBuf );
  2444. if( result!= NULL ) {
  2445. if( result->size() > 0 ) {
  2446. RetVal = (DBC_PUSHED_CMD*)malloc(sizeof(DBC_PUSHED_CMD));
  2447. if( RetVal ) {
  2448. Assoc * cArr;
  2449. Assoc::iterator it;
  2450. memset( RetVal, 0, sizeof(DBC_PUSHED_CMD));
  2451. cArr = result->at(0);
  2452. it = cArr->find("id");
  2453. if( it != cArr->end() ){
  2454. RetVal->id = atoi( it->second.c_str() );
  2455. };
  2456. it = cArr->find("cmd");
  2457. if( it != cArr->end() ){
  2458. RetVal->CMD = atoi( it->second.c_str() );
  2459. };
  2460. it = cArr->find("parameter");
  2461. if( it != cArr->end() ){
  2462. strncpy( RetVal->PARAM, it->second.c_str(), 256 );
  2463. RetVal->PARAM[255] = (char)0;
  2464. };
  2465. //Only If Result is Fetched - Clear Current CMD
  2466. sprintf(tQBuf, "DELETE FROM `nodes_qcq` WHERE `id`=%d", RetVal->id );
  2467. m_pDatabase->SilentQuery( tQBuf );
  2468. };
  2469. };
  2470. };
  2471. deleteResult( result );
  2472. };
  2473. return RetVal;
  2474. };
  2475. DBC_MODULE_DATA *argusDBC::getModuleData( uint32_t ID ){
  2476. DBC_MODULE_DATA *tVal = NULL;
  2477. if(m_bIsConnected){
  2478. char tQBuf[CTEXT];
  2479. AAssoc *result;
  2480. sprintf(tQBuf, "SELECT * FROM server_modules WHERE `id`=%d", ID );
  2481. #ifdef DEBUG_ALL
  2482. LOG(tQBuf);
  2483. #endif
  2484. result = m_pDatabase->Query( tQBuf );
  2485. if( result!= NULL ) {
  2486. if( result->size() > 0 ) {
  2487. Assoc *cArr;
  2488. tVal = (DBC_MODULE_DATA*) malloc(sizeof(DBC_MODULE_DATA));
  2489. if( tVal != NULL ) {
  2490. Assoc::iterator it;
  2491. cArr = result->at(0);
  2492. it = cArr->find("id");
  2493. if( it != cArr->end() ){
  2494. tVal->module_id = atoi( it->second.c_str() );
  2495. };
  2496. it = cArr->find("aux_id");
  2497. if( it != cArr->end() ){
  2498. tVal->aux_id = atoi( it->second.c_str() );
  2499. };
  2500. it = cArr->find("type");
  2501. if( it != cArr->end() ){
  2502. tVal->type = atoi( it->second.c_str() );
  2503. };
  2504. it = cArr->find("enabled");
  2505. if( it != cArr->end() ){
  2506. tVal->enabled = (bool)atoi( it->second.c_str() );
  2507. };
  2508. };
  2509. };
  2510. };
  2511. deleteResult( result );
  2512. };
  2513. return tVal;
  2514. };
  2515. /*
  2516. DBC_SOCKET_DATA *argusDBC::getSocketData( uint32_t ID ){
  2517. DBC_SOCKET_DATA *tVal = NULL;
  2518. if(m_bIsConnected){
  2519. char tQBuf[CTEXT];
  2520. AAssoc *result;
  2521. sprintf(tQBuf, "SELECT * FROM sockets WHERE `id`=%d", ID );
  2522. #ifdef DEBUG
  2523. //LOG(tQBuf);
  2524. #endif
  2525. result = m_pDatabase->Query( tQBuf );
  2526. if( result!= NULL ) {
  2527. if( result->size() > 0 ) {
  2528. Assoc *cArr;
  2529. tVal = (DBC_SOCKET_DATA*) malloc(sizeof(DBC_SOCKET_DATA));
  2530. if( tVal != NULL ) {
  2531. Assoc::iterator it;
  2532. cArr = result->at(0);
  2533. it = cArr->find("id");
  2534. if( it != cArr->end() ){
  2535. tVal->socket_id = atoi( it->second.c_str() );
  2536. };
  2537. it = cArr->find("aux_id");
  2538. if( it != cArr->end() ){
  2539. tVal->aux_id = atoi( it->second.c_str() );
  2540. };
  2541. it = cArr->find("type");
  2542. if( it != cArr->end() ){
  2543. tVal->type = atoi( it->second.c_str() );
  2544. };
  2545. it = cArr->find("binded");
  2546. if( it != cArr->end() ){
  2547. tVal->binded = (bool)atoi( it->second.c_str() );
  2548. };
  2549. };
  2550. };
  2551. };
  2552. deleteResult( result );
  2553. };
  2554. return tVal;
  2555. };
  2556. */
  2557. DBC_MEDIA_STREAM_DATA *argusDBC::getMediaStreamData( uint32_t ID ){
  2558. DBC_MEDIA_STREAM_DATA *tVal = NULL;
  2559. if(m_bIsConnected){
  2560. char tQBuf[CTEXT];
  2561. AAssoc *result;
  2562. sprintf(tQBuf, "SELECT * FROM media_streams WHERE `id`=%d", ID );
  2563. #ifdef DEBUG_ALL
  2564. LOG(tQBuf);
  2565. #endif
  2566. result = m_pDatabase->Query( tQBuf );
  2567. if( result!= NULL ) {
  2568. if( result->size() > 0 ) {
  2569. Assoc *cArr;
  2570. tVal = (DBC_MEDIA_STREAM_DATA*) malloc(sizeof(DBC_MEDIA_STREAM_DATA));
  2571. if( tVal != NULL ) {
  2572. Assoc::iterator it;
  2573. cArr = result->at(0);
  2574. tVal->id = ID;
  2575. it = cArr->find("source_id");
  2576. if( it != cArr->end() ){
  2577. tVal->source_id = atoi( it->second.c_str() );
  2578. };
  2579. it = cArr->find("site_id");
  2580. if( it != cArr->end() ){
  2581. tVal->site_id = atoi( it->second.c_str() );
  2582. };
  2583. it = cArr->find("source_type");
  2584. if( it != cArr->end() ){
  2585. sprintf( tVal->source_type, it->second.c_str() );
  2586. };
  2587. it = cArr->find("valid");
  2588. if( it != cArr->end() ){
  2589. tVal->valid = (bool) atoi( it->second.c_str() );
  2590. };
  2591. it = cArr->find("token");
  2592. if( it != cArr->end() ){
  2593. sprintf( tVal->token, it->second.c_str() );
  2594. };
  2595. it = cArr->find("img_width");
  2596. if( it != cArr->end() ){
  2597. tVal->width = atoi( it->second.c_str() );
  2598. };
  2599. it = cArr->find("img_height");
  2600. if( it != cArr->end() ){
  2601. tVal->height = atoi( it->second.c_str() );
  2602. };
  2603. it = cArr->find("mrl_proto");
  2604. if( it != cArr->end() ){
  2605. sprintf( tVal->mrl_proto, it->second.c_str() );
  2606. };
  2607. it = cArr->find("mrl_port");
  2608. if( it != cArr->end() ){
  2609. tVal->mrl_port = atoi( it->second.c_str() );
  2610. };
  2611. it = cArr->find("mrl");
  2612. if( it != cArr->end() ){
  2613. sprintf( tVal->mrl, it->second.c_str() );
  2614. };
  2615. };
  2616. };
  2617. };
  2618. deleteResult( result );
  2619. };
  2620. return tVal;
  2621. };
  2622. DBC_MEDIA_SERVER_DATA *argusDBC::getMediaServerData( uint32_t ID ){
  2623. DBC_MEDIA_SERVER_DATA *tVal = NULL;
  2624. if(m_bIsConnected){
  2625. char tQBuf[CTEXT];
  2626. AAssoc *result;
  2627. sprintf(tQBuf, "SELECT * FROM media_servers WHERE `id`=%d", ID );
  2628. #ifdef DEBUG_ALL
  2629. LOG(tQBuf);
  2630. #endif
  2631. result = m_pDatabase->Query( tQBuf );
  2632. if( result!= NULL ) {
  2633. if( result->size() > 0 ) {
  2634. Assoc *cArr;
  2635. tVal = (DBC_MEDIA_SERVER_DATA*) malloc(sizeof(DBC_MEDIA_SERVER_DATA));
  2636. if( tVal != NULL ) {
  2637. Assoc::iterator it;
  2638. cArr = result->at(0);
  2639. tVal->id = ID;
  2640. it = cArr->find("secret_key");
  2641. if( it != cArr->end() ){
  2642. sprintf( tVal->key, it->second.c_str() );
  2643. };
  2644. it = cArr->find("ip");
  2645. if( it != cArr->end() ){
  2646. sprintf( tVal->ip, it->second.c_str() );
  2647. };
  2648. it = cArr->find("REST_port");
  2649. if( it != cArr->end() ){
  2650. tVal->port = atoi( it->second.c_str() );
  2651. };
  2652. it = cArr->find("virtual_host");
  2653. if( it != cArr->end() ){
  2654. sprintf( tVal->host, it->second.c_str() );
  2655. };
  2656. it = cArr->find("recording");
  2657. if( it != cArr->end() ){
  2658. tVal->recording = (bool)atoi( it->second.c_str() );
  2659. };
  2660. it = cArr->find("local");
  2661. if( it != cArr->end() ){
  2662. tVal->local = (bool)atoi( it->second.c_str() );
  2663. };
  2664. it = cArr->find("docRoot");
  2665. if( it != cArr->end() ){
  2666. sprintf( tVal->docRoot, it->second.c_str() );
  2667. };
  2668. sprintf( tVal->name,"ZLMedia_%d", tVal->id );
  2669. };
  2670. };
  2671. };
  2672. deleteResult( result );
  2673. };
  2674. return tVal;
  2675. };
  2676. DBC_MEDIA_SERVER_STREAM_DATA *argusDBC::getMediaServerStreamDataBySource( uint32_t ID ){
  2677. DBC_MEDIA_SERVER_STREAM_DATA *tVal = NULL;
  2678. if(m_bIsConnected){
  2679. char tQBuf[MAX_PATH_LEN];
  2680. AAssoc *result;
  2681. sprintf(tQBuf, "SELECT `id`, `media_stream_id`, `online`, `key`, `mrl` FROM media_server_streams WHERE `media_stream_id`=%d", ID );
  2682. #ifdef DEBUG_ALL
  2683. LOG(tQBuf);
  2684. #endif
  2685. result = m_pDatabase->Query( tQBuf );
  2686. if( result!= NULL ) {
  2687. if( result->size() > 0 ) {
  2688. Assoc *cArr;
  2689. tVal = (DBC_MEDIA_SERVER_STREAM_DATA*) malloc(sizeof(DBC_MEDIA_SERVER_STREAM_DATA));
  2690. if( tVal != NULL ) {
  2691. Assoc::iterator it;
  2692. cArr = result->at(0);
  2693. tVal->id = ID;
  2694. it = cArr->find("media_stream_id");
  2695. if( it != cArr->end() ){
  2696. tVal->media_stream_id = atoi( it->second.c_str() );
  2697. };
  2698. it = cArr->find("online");
  2699. if( it != cArr->end() ){
  2700. tVal->online = atoi( it->second.c_str() );
  2701. };
  2702. it = cArr->find("key");
  2703. if( it != cArr->end() ){
  2704. sprintf( tVal->key, it->second.c_str() );
  2705. };
  2706. it = cArr->find("mrl");
  2707. if( it != cArr->end() ){
  2708. sprintf( tVal->mrl, it->second.c_str() );
  2709. };
  2710. };
  2711. };
  2712. };
  2713. deleteResult( result );
  2714. };
  2715. return tVal;
  2716. };
  2717. DBC_MEDIA_SERVER_STREAM_DATA *argusDBC::getMediaServerStreamData( uint32_t ID ){
  2718. DBC_MEDIA_SERVER_STREAM_DATA *tVal = NULL;
  2719. if(m_bIsConnected){
  2720. char tQBuf[MAX_PATH_LEN];
  2721. AAssoc *result;
  2722. sprintf(tQBuf, "SELECT `id`, `media_stream_id`, `online`, `key`, `mrl` FROM media_server_streams WHERE `id`=%d", ID );
  2723. #ifdef DEBUG_ALL
  2724. LOG(tQBuf);
  2725. #endif
  2726. result = m_pDatabase->Query( tQBuf );
  2727. if( result!= NULL ) {
  2728. if( result->size() > 0 ) {
  2729. Assoc *cArr;
  2730. tVal = (DBC_MEDIA_SERVER_STREAM_DATA*) malloc(sizeof(DBC_MEDIA_SERVER_STREAM_DATA));
  2731. if( tVal != NULL ) {
  2732. Assoc::iterator it;
  2733. cArr = result->at(0);
  2734. tVal->id = ID;
  2735. it = cArr->find("media_stream_id");
  2736. if( it != cArr->end() ){
  2737. tVal->media_stream_id = atoi( it->second.c_str() );
  2738. };
  2739. it = cArr->find("online");
  2740. if( it != cArr->end() ){
  2741. tVal->online = atoi( it->second.c_str() );
  2742. };
  2743. it = cArr->find("key");
  2744. if( it != cArr->end() ){
  2745. sprintf( tVal->key, it->second.c_str() );
  2746. };
  2747. it = cArr->find("mrl");
  2748. if( it != cArr->end() ){
  2749. sprintf( tVal->mrl, it->second.c_str() );
  2750. };
  2751. };
  2752. };
  2753. };
  2754. deleteResult( result );
  2755. };
  2756. return tVal;
  2757. };
  2758. void argusDBC::registerServer(uint32_t SiteID, CSTR identity, int PID ){
  2759. if(m_bIsConnected){
  2760. m_nSiteID = SiteID;
  2761. char tQBuf[CTEXT];
  2762. 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 );
  2763. #ifdef DEBUG_ALL
  2764. LOG(tQBuf);
  2765. #endif
  2766. m_pDatabase->SilentQuery( tQBuf );
  2767. // Clenup Nodes and services ...
  2768. sprintf(tQBuf,"UPDATE nodes SET `online`=0 WHERE `site_id`=%d ", SiteID );
  2769. #ifdef DEBUG_ALL
  2770. LOG(tQBuf);
  2771. #endif
  2772. m_pDatabase->SilentQuery( tQBuf );
  2773. sprintf(tQBuf,"UPDATE cameras SET `online`=0 WHERE `site_id`=%d ", SiteID );
  2774. #ifdef DEBUG_ALL
  2775. LOG(tQBuf);
  2776. #endif
  2777. m_pDatabase->SilentQuery( tQBuf );
  2778. sprintf(tQBuf,"UPDATE media_streams SET `valid`=0 WHERE `site_id`=%d ", SiteID );
  2779. #ifdef DEBUG_ALL
  2780. LOG(tQBuf);
  2781. #endif
  2782. m_pDatabase->SilentQuery( tQBuf );
  2783. sprintf(tQBuf,"UPDATE media_server_streams SET `valid`=0, `online`=0 WHERE `site_id`=%d ", SiteID );
  2784. #ifdef DEBUG_ALL
  2785. LOG(tQBuf);
  2786. #endif
  2787. m_pDatabase->SilentQuery( tQBuf );
  2788. uint32_t tServerID = getServerID( identity );
  2789. if( tServerID ) {
  2790. 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 );
  2791. #ifdef DEBUG_ALL
  2792. LOG(tQBuf);
  2793. #endif
  2794. uint32_t tServerNodeID = ( uint32_t ) m_pDatabase->QueryID( tQBuf );
  2795. if( tServerNodeID == 0 ){
  2796. tServerNodeID = getServerNode( tServerID );
  2797. };
  2798. //cleanResources( tServerNodeID );
  2799. setNodeOnline( tServerNodeID );
  2800. };
  2801. };
  2802. };
  2803. void argusDBC::unregisterServer(uint32_t ServerID, uint32_t NodeID ){
  2804. if( setNodeOffline( NodeID ) ){
  2805. char tQBuf[CTEXT];
  2806. sprintf(tQBuf,"UPDATE servers SET `online`=0, `ts`=UNIX_TIMESTAMP(now()) WHERE `id`=%d", ServerID );
  2807. #ifdef DEBUG_ALL
  2808. LOG(tQBuf);
  2809. #endif
  2810. m_pDatabase->SilentQuery( tQBuf );
  2811. };
  2812. };
  2813. bool argusDBC::setNodeOnline( uint32_t NodeID, uint8_t status ){
  2814. if(m_bIsConnected){
  2815. char tQBuf[CTEXT];
  2816. if( NodeID ) {
  2817. sprintf(tQBuf,"UPDATE nodes SET `online`=%d WHERE `id`=%d", status, NodeID );
  2818. #ifdef DEBUG_ALL
  2819. LOG(tQBuf);
  2820. #endif
  2821. m_pDatabase->SilentQuery( tQBuf );
  2822. sprintf(tQBuf,"UPDATE `resources` SET `active`=1 WHERE `node_id`=%d", NodeID );
  2823. #ifdef DEBUG_ALL
  2824. LOG(tQBuf);
  2825. #endif
  2826. m_pDatabase->SilentQuery( tQBuf );
  2827. return true;
  2828. };
  2829. };
  2830. return false;
  2831. };
  2832. bool argusDBC::setNodeOffline( uint32_t NodeID ){
  2833. if(m_bIsConnected){
  2834. char tQBuf[CTEXT];
  2835. if( NodeID ) {
  2836. sprintf(tQBuf,"UPDATE nodes SET `online`=0 WHERE `id` = %d", NodeID );
  2837. #ifdef DEBUG_ALL
  2838. LOG(tQBuf);
  2839. #endif
  2840. m_pDatabase->SilentQuery( tQBuf );
  2841. sprintf(tQBuf,"UPDATE `resources` SET `active`=0 WHERE `node_id` = %d", NodeID );
  2842. #ifdef DEBUG_ALL
  2843. LOG(tQBuf);
  2844. #endif
  2845. m_pDatabase->SilentQuery( tQBuf );
  2846. return true;
  2847. };
  2848. };
  2849. return false;
  2850. };
  2851. DBC_RESOURCE_DATA *argusDBC::getResourceData( uint32_t ResourceID ){
  2852. DBC_RESOURCE_DATA *tVal = NULL;
  2853. if( m_bIsConnected ){
  2854. char tQBuf[CTEXT];
  2855. AAssoc *result;
  2856. sprintf(tQBuf, "SELECT `node_id`, `type`, `aux_id`, `device` FROM resources WHERE `id`=%d", ResourceID );
  2857. #ifdef DEBUG_ALL
  2858. LOG(tQBuf);
  2859. #endif
  2860. result = m_pDatabase->Query( tQBuf );
  2861. if( result!= NULL ) {
  2862. if( result->size() > 0 ) {
  2863. Assoc *cArr;
  2864. tVal = (DBC_RESOURCE_DATA*) malloc(sizeof(DBC_RESOURCE_DATA));
  2865. if( tVal != NULL ) {
  2866. Assoc::iterator it;
  2867. cArr = result->at(0);
  2868. tVal->id = ResourceID;
  2869. it = cArr->find("node_id");
  2870. if( it != cArr->end() ){
  2871. tVal->node_id = atoi( it->second.c_str() );
  2872. };
  2873. it = cArr->find("type");
  2874. if( it != cArr->end() ){
  2875. tVal->type = atoi( it->second.c_str() );
  2876. };
  2877. it = cArr->find("aux_id");
  2878. if( it != cArr->end() ){
  2879. tVal->aux_id = atoi( it->second.c_str() );
  2880. };
  2881. it = cArr->find("device");
  2882. if( it != cArr->end() ){
  2883. strncpy( tVal->device, it->second.c_str(), 64 );
  2884. tVal->device[63] = (char)0;
  2885. };
  2886. };
  2887. };
  2888. };
  2889. deleteResult( result );
  2890. };
  2891. return tVal;
  2892. };
  2893. uint32_t argusDBC::getResourceID( uint32_t NodeID, uint8_t type, uint32_t auxID ){
  2894. uint32_t RetVal = 0;
  2895. if(m_bIsConnected){
  2896. char tQBuf[CTEXT];
  2897. sprintf(tQBuf,"SELECT `id` FROM `resources` WHERE `node_id`=%d AND `type`=%d AND `aux_id`=%d", NodeID, type, auxID );
  2898. #ifdef DEBUG_ALL
  2899. LOG(tQBuf);
  2900. #endif
  2901. AAssoc *result;
  2902. result = m_pDatabase->Query( tQBuf );
  2903. if( result!= NULL ) {
  2904. if( result->size() > 0 ) {
  2905. Assoc * cArr;
  2906. Assoc::iterator it;
  2907. cArr = result->at(0);
  2908. it = cArr->find("id");
  2909. if( it != cArr->end() ){
  2910. RetVal = atoi( it->second.c_str() );
  2911. };
  2912. };
  2913. };
  2914. deleteResult( result );
  2915. };
  2916. return RetVal;
  2917. };
  2918. uint32_t argusDBC::getServerID( CSTR identity ){
  2919. uint32_t RetVal = 0;
  2920. if(m_bIsConnected){
  2921. char tQBuf[CTEXT];
  2922. sprintf(tQBuf,"SELECT id FROM servers WHERE `identity`='%s'", identity );
  2923. #ifdef DEBUG_ALL
  2924. LOG(tQBuf);
  2925. #endif
  2926. AAssoc *result;
  2927. result = m_pDatabase->Query( tQBuf );
  2928. if( result!= NULL ) {
  2929. if( result->size() > 0 ) {
  2930. Assoc * cArr;
  2931. Assoc::iterator it;
  2932. cArr = result->at(0);
  2933. it = cArr->find("id");
  2934. if( it != cArr->end() ){
  2935. RetVal = atoi( it->second.c_str() );
  2936. };
  2937. };
  2938. };
  2939. deleteResult( result );
  2940. };
  2941. return RetVal;
  2942. };
  2943. uint32_t argusDBC::getServerNode( uint32_t SID ){
  2944. uint32_t RetVal = 0;
  2945. if(m_bIsConnected){
  2946. char tQBuf[CTEXT];
  2947. sprintf(tQBuf,"SELECT id FROM nodes WHERE `type`=0 AND `aux_id`=%d", SID );
  2948. #ifdef DEBUG_ALL
  2949. LOG(tQBuf);
  2950. #endif
  2951. AAssoc *result;
  2952. result = m_pDatabase->Query( tQBuf );
  2953. if( result!= NULL ) {
  2954. if( result->size() > 0 ) {
  2955. Assoc * cArr;
  2956. Assoc::iterator it;
  2957. cArr = result->at(0);
  2958. it = cArr->find("id");
  2959. if( it != cArr->end() ){
  2960. RetVal = atoi( it->second.c_str() );
  2961. };
  2962. };
  2963. };
  2964. deleteResult( result );
  2965. };
  2966. return RetVal;
  2967. };
  2968. uint32_t argusDBC::addLocalMediaSource( uint32_t SiteID, CSTR path, uint32_t width, uint32_t height ){
  2969. uint32_t RetVal = 0;
  2970. if(m_bIsConnected){
  2971. char tQBuf[1024];
  2972. char tM5[33];
  2973. CSTR tMD5 = MD5String( path );
  2974. if( tMD5 != NULL ) {
  2975. memcpy( tM5, tMD5, 33 );
  2976. tM5[32]=(char)0;
  2977. free( tMD5 );
  2978. 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",
  2979. SiteID, tM5, width, height, path, width, height );
  2980. #ifdef DEBUG_ALL
  2981. LOG(tQBuf);
  2982. #endif
  2983. RetVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
  2984. };
  2985. };
  2986. return RetVal;
  2987. };
  2988. /*
  2989. uint32_t argusDBC::addNodeSocket( uint32_t NodeID, uint32_t auxID, uint8_t SocketType, uint8_t SocketMode, bool multidrop, CSTR path, CSTR name ){
  2990. uint32_t retVal = 0;
  2991. if(m_bIsConnected){
  2992. char tQBuf[2048];
  2993. char tM5[33];
  2994. CSTR tMD5 = MD5String( path );
  2995. if( tMD5 != NULL ) {
  2996. memcpy( tM5, tMD5, 33 );
  2997. free( tMD5 );
  2998. if( multidrop ) {
  2999. 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'",
  3000. NodeID, SocketType, SocketMode, tM5, path, name, auxID, name );
  3001. } else {
  3002. 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'",
  3003. NodeID, SocketType, SocketMode, tM5, path, name, auxID, name );
  3004. };
  3005. #ifdef DEBUG
  3006. LOG(tQBuf);
  3007. #endif
  3008. //m_pDatabase->SilentQuery( tQBuf );
  3009. retVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
  3010. };
  3011. };
  3012. return retVal;
  3013. };
  3014. */
  3015. bool argusDBC::addNotification( uint32_t MSG_ID, uint8_t DIS_LVL, uint32_t OBJ_ID ){
  3016. if(m_bIsConnected){
  3017. char tQBuf[2048];
  3018. 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 );
  3019. #ifdef DEBUG_ALL
  3020. LOG(tQBuf);
  3021. #endif
  3022. m_pDatabase->SilentQuery( tQBuf );
  3023. return true;
  3024. };
  3025. return false;
  3026. };
  3027. uint32_t argusDBC::addResource( uint32_t NodeID, uint8_t type, CSTR devName, uint32_t auxID ){
  3028. uint32_t RetVal = 0;
  3029. if( m_bIsConnected ){
  3030. char tQBuf[2048];
  3031. //CSTR tMD5 = MD5String( devName );
  3032. //if( tMD5 ) {
  3033. //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 );
  3034. 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 );
  3035. // free( tMD5 );
  3036. #ifdef DEBUG_ALL
  3037. LOG(tQBuf);
  3038. #endif
  3039. RetVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
  3040. if( RetVal == 0 ) {
  3041. RetVal = getResourceID( NodeID, type, auxID );
  3042. };
  3043. //};
  3044. };
  3045. return RetVal;
  3046. };
  3047. /*
  3048. uint32_t argusDBC::getNodeSocketID( uint32_t NodeID, uint32_t auxID, uint8_t SocketType, CSTR path ){
  3049. uint32_t retVal = 0;
  3050. if(m_bIsConnected){
  3051. char tQBuf[2048];
  3052. char tM5[33];
  3053. CSTR tMD5 = MD5String( path );
  3054. if( tMD5 != NULL ) {
  3055. memcpy( tM5, tMD5, 33 );
  3056. free( tMD5 );
  3057. sprintf( tQBuf,"SELECT id FROM `sockets` WHERE `node_id`=%d AND `type`=%d AND `md5`='%s' AND `aux_id`=%d", NodeID, SocketType, tM5, auxID );
  3058. #ifdef DEBUG
  3059. LOG(tQBuf);
  3060. #endif
  3061. AAssoc *result;
  3062. result = m_pDatabase->Query( tQBuf );
  3063. if( result!= NULL ) {
  3064. if( result->size() > 0 ) {
  3065. Assoc * cArr;
  3066. Assoc::iterator it;
  3067. cArr = result->at(0);
  3068. it = cArr->find("id");
  3069. if( it != cArr->end() ){
  3070. retVal = atoi( it->second.c_str() );
  3071. };
  3072. };
  3073. };
  3074. deleteResult( result );
  3075. };
  3076. };
  3077. return retVal;
  3078. };
  3079. */
  3080. /*
  3081. CSTR argusDBC::getSocketName( uint32_t NodeID, uint32_t Type ){
  3082. if(m_bIsConnected){
  3083. char tQBuf[CTEXT];
  3084. sprintf( tQBuf, "SELECT `name` FROM `sockets` WHERE `node_id`=%d AND `type`=%d LIMIT 1",
  3085. NodeID, Type );
  3086. #ifdef DEBUG
  3087. LOG(tQBuf);
  3088. #endif
  3089. AAssoc *result;
  3090. result = m_pDatabase->Query( tQBuf );
  3091. if( result!= NULL ) {
  3092. if( result->size() > 0 ) {
  3093. Assoc * cArr;
  3094. Assoc::iterator it;
  3095. cArr = result->at(0);
  3096. it = cArr->find("name");
  3097. if( it != cArr->end() ){
  3098. strncpy( tQBuf, it->second.c_str(), CTEXT );
  3099. };
  3100. };
  3101. };
  3102. deleteResult( result );
  3103. return strdup(tQBuf);
  3104. };
  3105. return NULL;
  3106. };
  3107. */
  3108. KAFKA_SETTINGS *argusDBC::getSettingsKAFKA( uint32_t ModuleID ){
  3109. KAFKA_SETTINGS *tVal = NULL;
  3110. if( m_bIsConnected ) {
  3111. char tQBuf[CTEXT];
  3112. AAssoc *result;
  3113. sprintf( tQBuf, "SELECT brocker_address, brocker_port FROM modules_kafka WHERE module_id = %d", ModuleID );
  3114. #ifdef DEBUG_ALL
  3115. LOG(tQBuf);
  3116. #endif
  3117. result = m_pDatabase->Query( tQBuf );
  3118. if( result!= NULL ) {
  3119. if( result->size() > 0 ) {
  3120. Assoc *cArr;
  3121. tVal = (KAFKA_SETTINGS*) malloc(sizeof(KAFKA_SETTINGS));
  3122. if( tVal != NULL ) {
  3123. Assoc::iterator it;
  3124. cArr = result->at(0);
  3125. it = cArr->find("brocker_address");
  3126. if( it != cArr->end() ){
  3127. strncpy( tVal->brocker_addr, it->second.c_str(), 255 );
  3128. };
  3129. it = cArr->find("brocker_port");
  3130. if( it != cArr->end() ){
  3131. tVal->brocker_port = atoi( it->second.c_str() );
  3132. };
  3133. };
  3134. };
  3135. };
  3136. deleteResult( result );
  3137. };
  3138. return tVal;
  3139. };
  3140. KAFKA_TEMPLATE *argusDBC::getKafkaTemplateForEvent( uint32_t ModuleID, uint32_t ClassID, uint32_t EventID ){
  3141. KAFKA_TEMPLATE *tVal = NULL;
  3142. if( m_bIsConnected ) {
  3143. char tQBuf[CTEXT];
  3144. AAssoc *result;
  3145. sprintf( tQBuf, "SELECT topic, template FROM module_kafka_settings WHERE module_id=%d AND class_id=%d AND event_id=%d", ModuleID, ClassID, EventID );
  3146. #ifdef DEBUG_ALL
  3147. LOG(tQBuf);
  3148. #endif
  3149. result = m_pDatabase->Query( tQBuf );
  3150. if( result!= NULL ) {
  3151. if( result->size() > 0 ) {
  3152. Assoc *cArr;
  3153. tVal = (KAFKA_TEMPLATE*) malloc(sizeof(KAFKA_TEMPLATE));
  3154. if( tVal != NULL ) {
  3155. Assoc::iterator it;
  3156. cArr = result->at(0);
  3157. it = cArr->find("topic");
  3158. if( it != cArr->end() ){
  3159. memset( tVal->topic, 0, 128 );
  3160. strncpy( tVal->topic , it->second.c_str(), 127 );
  3161. };
  3162. it = cArr->find("template");
  3163. if( it != cArr->end() ){
  3164. tVal->tpl = (CSTR)malloc( it->second.length() + 1 );
  3165. if( tVal->tpl!= NULL) {
  3166. memset( tVal->tpl, 0, it->second.length() + 1 );
  3167. strncpy( tVal->tpl, it->second.c_str(), it->second.length() );
  3168. };
  3169. };
  3170. };
  3171. };
  3172. };
  3173. deleteResult( result );
  3174. };
  3175. return tVal;
  3176. };
  3177. DBC_UART_DATA *argusDBC::getUartData( uint32_t UartID ){
  3178. DBC_UART_DATA *tVal = NULL;
  3179. if( m_bIsConnected ) {
  3180. char tQBuf[MAX_PATH_LEN];
  3181. AAssoc *result;
  3182. sprintf( tQBuf, "SELECT * FROM uart_settings WHERE id = %d", UartID );
  3183. #ifdef DEBUG_ALL
  3184. LOG(tQBuf);
  3185. #endif
  3186. result = m_pDatabase->Query( tQBuf );
  3187. if( result!= NULL ) {
  3188. if( result->size() > 0 ) {
  3189. Assoc *cArr;
  3190. tVal = (DBC_UART_DATA*) malloc(sizeof(DBC_UART_DATA));
  3191. if( tVal != NULL ) {
  3192. Assoc::iterator it;
  3193. cArr = result->at(0);
  3194. it = cArr->find("type");
  3195. if( it != cArr->end() ){
  3196. tVal->type = atoi( it->second.c_str() );
  3197. };
  3198. it = cArr->find("speed");
  3199. if( it != cArr->end() ){
  3200. tVal->speed = atoi( it->second.c_str() );
  3201. };
  3202. it = cArr->find("mode");
  3203. if( it != cArr->end() ){
  3204. tVal->mode = atoi( it->second.c_str() );
  3205. };
  3206. it = cArr->find("port");
  3207. if( it != cArr->end() ){
  3208. tVal->port = atoi( it->second.c_str() );
  3209. };
  3210. it = cArr->find("path");
  3211. if( it != cArr->end() ){
  3212. strncpy( tVal->path, it->second.c_str(), 128 );
  3213. };
  3214. };
  3215. };
  3216. };
  3217. deleteResult( result );
  3218. };
  3219. return tVal;
  3220. };
  3221. uint32_t argusDBC::getUartID( uint32_t NodeID, uint8_t Type, CSTR path ){
  3222. uint32_t RetVal = 0;
  3223. if(m_bIsConnected){
  3224. char tQBuf[CTEXT];
  3225. sprintf(tQBuf,"SELECT `id` FROM `uart_settings` WHERE `node_id`=%d AND `type`=%d AND `path`='%s' ", NodeID, Type, path );
  3226. #ifdef DEBUG_ALL
  3227. LOG(tQBuf);
  3228. #endif
  3229. AAssoc *result;
  3230. result = m_pDatabase->Query( tQBuf );
  3231. if( result!= NULL ) {
  3232. if( result->size() > 0 ) {
  3233. Assoc * cArr;
  3234. Assoc::iterator it;
  3235. cArr = result->at(0);
  3236. it = cArr->find("id");
  3237. if( it != cArr->end() ){
  3238. RetVal = atoi( it->second.c_str() );
  3239. };
  3240. };
  3241. };
  3242. deleteResult( result );
  3243. };
  3244. return RetVal;
  3245. };
  3246. bool argusDBC::updateMediaServerStream( uint32_t id, CSTR mrl, CSTR key ){
  3247. if( m_bIsConnected ) {
  3248. char tQBuf[MAX_PATH_LEN];
  3249. if( key == NULL ) {
  3250. if( mrl == NULL ) {
  3251. sprintf( tQBuf,"UPDATE media_server_streams SET `online`=0, `key`='', mrl='', `valid`=0 WHERE `id`=%d", id );
  3252. } else {
  3253. sprintf( tQBuf,"UPDATE media_server_streams SET `online`=0, `key`='', `mrl`='%s', `valid`=1 WHERE `id`=%d", mrl, id );
  3254. };
  3255. } else {
  3256. sprintf( tQBuf,"UPDATE media_server_streams SET `online`=1, `key`='%s', `mrl`='%s', `valid`=1 WHERE `id`=%d",
  3257. key,
  3258. mrl,
  3259. id
  3260. );
  3261. };
  3262. #ifdef DEBUG_ALL
  3263. LOG(tQBuf);
  3264. #endif
  3265. m_pDatabase->SilentQuery( tQBuf );
  3266. return true;
  3267. };
  3268. return false;
  3269. };
  3270. bool argusDBC::updateResourceAUX( uint32_t ResID, uint32_t AUX ){
  3271. if( m_bIsConnected ) {
  3272. char tQBuf[MAX_PATH_LEN];
  3273. sprintf( tQBuf, "UPDATE `resources` SET `aux_id`=%d WHERE `id`=%d", AUX, ResID );
  3274. #ifdef DEBUG
  3275. LOG(tQBuf);
  3276. #endif
  3277. m_pDatabase->SilentQuery( tQBuf );
  3278. return true;
  3279. };
  3280. return false;
  3281. };
  3282. 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 ){
  3283. if( m_bIsConnected ) {
  3284. char tQBuf[MAX_PATH_LEN];
  3285. 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",
  3286. nCores,
  3287. cpu1,
  3288. cpu5,
  3289. cpu15,
  3290. mem,
  3291. disk,
  3292. dtsize,
  3293. dcsize,
  3294. mtsize,
  3295. mcsize,
  3296. ServerID
  3297. );
  3298. #ifdef DEBUG_ALL
  3299. LOG(tQBuf);
  3300. #endif
  3301. m_pDatabase->SilentQuery( tQBuf );
  3302. return true;
  3303. };
  3304. return false;
  3305. };
  3306. uint32_t argusDBC::addLocalDCB( uint32_t SiteID, CSTR PATH, CSTR SERIAL, uint8_t CNT, uint32_t status ){
  3307. uint32_t RetVal = 0;
  3308. if( m_bIsConnected ) {
  3309. char tQBuf[MAX_PATH_LEN];
  3310. 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",
  3311. SiteID,
  3312. status,
  3313. CNT,
  3314. SERIAL,
  3315. status,
  3316. CNT
  3317. );
  3318. #ifdef DEBUG_ALL
  3319. LOG(tQBuf);
  3320. #endif
  3321. uint64_t cid = m_pDatabase->QueryID( tQBuf );
  3322. if( cid == 0 ) {
  3323. AAssoc *result;
  3324. sprintf( tQBuf, "SELECT id FROM modules_dcr WHERE site_id=%d AND serial_id='%s'",
  3325. SiteID,
  3326. SERIAL
  3327. );
  3328. #ifdef DEBUG_ALL
  3329. LOG(tQBuf);
  3330. #endif
  3331. result = m_pDatabase->Query( tQBuf );
  3332. if( result!= NULL ) {
  3333. if( result->size() > 0 ) {
  3334. Assoc * cArr;
  3335. Assoc::iterator it;
  3336. cArr = result->at(0);
  3337. it = cArr->find("id");
  3338. if( it != cArr->end() ){
  3339. cid = atoi( it->second.c_str() );
  3340. };
  3341. };
  3342. deleteResult( result );
  3343. };
  3344. };
  3345. if( cid!= 0 ) {
  3346. for( uint8_t idx = 0; idx < CNT; idx++ ) {
  3347. if( status & ( 1 << idx ) ){
  3348. sprintf( tQBuf, "INSERT INTO module_dcr_chanels SET dcr_id=%d, channel_id=%d, mode='O', status='C' ON DUPLICATE KEY UPDATE status='C'",
  3349. (uint32_t) cid,
  3350. idx
  3351. );
  3352. } else {
  3353. sprintf( tQBuf, "INSERT INTO module_dcr_chanels SET dcr_id=%d, channel_id=%d, mode='O', status='O' ON DUPLICATE KEY UPDATE status='O'",
  3354. (uint32_t) cid,
  3355. idx
  3356. );
  3357. }
  3358. #ifdef DEBUG_ALL
  3359. LOG(tQBuf);
  3360. #endif
  3361. m_pDatabase->SilentQuery( tQBuf );
  3362. };
  3363. };
  3364. };
  3365. return RetVal;
  3366. };
  3367. 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 ){
  3368. uint32_t RetVal = 0;
  3369. if( m_bIsConnected ) {
  3370. char tQBuf[MAX_PATH_LEN];
  3371. 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`",
  3372. NodeID,
  3373. utype,
  3374. speed,
  3375. bit,
  3376. parity,
  3377. stop_bit,
  3378. mode,
  3379. port,
  3380. PATH
  3381. );
  3382. #ifdef DEBUG_ALL
  3383. LOG(tQBuf);
  3384. #endif
  3385. RetVal = m_pDatabase->QueryID( tQBuf );
  3386. if( RetVal == 0 ) {
  3387. RetVal = getUartID( NodeID, utype, PATH );
  3388. };
  3389. };
  3390. return RetVal;
  3391. };
  3392. uint32_t argusDBC::addLocalNIF( CSTR device, CSTR mac, ARGUS_NIF_TYPE dtype, ARGUS_NIF_MODE dmode, uint32_t aux_id ){
  3393. uint32_t RetVal = 0;
  3394. if( m_bIsConnected ) {
  3395. char tQBuf[MAX_PATH_LEN];
  3396. char * tKey = MD5String( device );
  3397. if( tKey != NULL ) {
  3398. 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'",
  3399. dtype,
  3400. tKey,
  3401. device,
  3402. mac,
  3403. dmode,
  3404. aux_id,
  3405. dmode,
  3406. aux_id,
  3407. mac
  3408. );
  3409. #ifdef DEBUG
  3410. LOG(tQBuf);
  3411. #endif
  3412. RetVal = m_pDatabase->QueryID( tQBuf );
  3413. if( RetVal == 0 ) {
  3414. RetVal = getNIF_ID( tKey );
  3415. };
  3416. free( tKey );
  3417. };
  3418. };
  3419. return RetVal;
  3420. };
  3421. uint32_t argusDBC::addLocalWiFi( uint32_t NIF_ID, ARGUS_WIFI_MODE mode, CSTR SSID, CSTR password, ARGUS_WIFI_ENCRIPTION encryption, uint32_t router_id ){
  3422. uint32_t RetVal = 0;
  3423. if( m_bIsConnected ) {
  3424. char tQBuf[MAX_PATH_LEN];
  3425. 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",
  3426. NIF_ID,
  3427. mode,
  3428. router_id,
  3429. SSID,
  3430. password,
  3431. encryption,
  3432. mode,
  3433. router_id,
  3434. SSID,
  3435. password,
  3436. encryption
  3437. );
  3438. #ifdef DEBUG
  3439. LOG(tQBuf);
  3440. #endif
  3441. RetVal = m_pDatabase->QueryID( tQBuf );
  3442. if( RetVal == 0 ) {
  3443. RetVal = getWiFi_ID( NIF_ID );
  3444. };
  3445. };
  3446. return RetVal;
  3447. };
  3448. uint32_t argusDBC::addLRFMask( uint32_t devID, uint8_t lrfID, uint8_t layerID ){
  3449. uint32_t RetVal = 0;
  3450. if( m_bIsConnected ) {
  3451. char tQBuf[MAX_PATH_LEN];
  3452. sprintf( tQBuf, "INSERT INTO `lrf_masks` SET `sensor_id`=%d, `lrf_id`=%d, `layer`=%d ON DUPLICATE KEY UPDATE `id`=`id`",
  3453. devID,
  3454. lrfID,
  3455. layerID
  3456. );
  3457. #ifdef DEBUG
  3458. LOG(tQBuf);
  3459. #endif
  3460. RetVal = m_pDatabase->QueryID( tQBuf );
  3461. if( RetVal == 0 ) {
  3462. RetVal = getLRFMaskID( devID, lrfID, layerID );
  3463. };
  3464. };
  3465. return RetVal;
  3466. };
  3467. uint32_t argusDBC::addLRFMaskPolygone( uint32_t maskID, uint8_t r, uint8_t g, uint8_t b ){
  3468. uint32_t RetVal = 0;
  3469. if( m_bIsConnected ) {
  3470. char tQBuf[MAX_PATH_LEN];
  3471. sprintf( tQBuf, "INSERT INTO `lrf_mask_vertexes` SET `mask_id`=%d, `r`=%d, `g`=%d, `b`=%d",
  3472. maskID,
  3473. r,
  3474. g,
  3475. b
  3476. );
  3477. #ifdef DEBUG
  3478. LOG(tQBuf);
  3479. #endif
  3480. RetVal = m_pDatabase->QueryID( tQBuf );
  3481. };
  3482. return RetVal;
  3483. };
  3484. bool argusDBC::addLRFMaskPolygonePoint( uint32_t polyID, uint16_t x, uint16_t y ){
  3485. if( m_bIsConnected ) {
  3486. char tQBuf[MAX_PATH_LEN];
  3487. sprintf( tQBuf, "INSERT INTO `lrf_mask_vertex_points` SET `vertex_id`=%d, `x`=%d, `y`=%d",
  3488. polyID,
  3489. x,
  3490. y
  3491. );
  3492. #ifdef DEBUG
  3493. LOG(tQBuf);
  3494. #endif
  3495. m_pDatabase->SilentQuery( tQBuf );
  3496. return true;
  3497. };
  3498. return false;
  3499. };
  3500. uint32_t argusDBC::addLocalNetwork( uint32_t NIF_ID, ARGUS_NETWORK_TYPE net_type, CSTR address, CSTR mask, CSTR gateway, CSTR broadcast ){
  3501. uint32_t RetVal = 0;
  3502. if( m_bIsConnected ) {
  3503. char tQBuf[MAX_PATH_LEN];
  3504. 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'",
  3505. NIF_ID,
  3506. net_type,
  3507. address,
  3508. gateway,
  3509. mask,
  3510. broadcast,
  3511. address,
  3512. gateway,
  3513. mask,
  3514. broadcast
  3515. );
  3516. #ifdef DEBUG
  3517. LOG(tQBuf);
  3518. #endif
  3519. RetVal = m_pDatabase->QueryID( tQBuf );
  3520. // On Update IF data no need to return ID
  3521. //if( RetVal == 0 ) {
  3522. // RetVal = getNetworkInterfaceID( tKey );
  3523. //};
  3524. };
  3525. return RetVal;
  3526. };
  3527. uint32_t argusDBC::addLocalNetworkInfrastructure( uint32_t NIF_ID, uint32_t OUTBOUND_NIF, bool ena_dhcp, CSTR BRANG, CSTR ERANG, CSTR MASK, CSTR LEASE_TIME ){
  3528. uint32_t RetVal = 0;
  3529. if( m_bIsConnected ) {
  3530. char tQBuf[MAX_PATH_LEN];
  3531. bool ena_routing = true;
  3532. if( OUTBOUND_NIF == 0 ){
  3533. ena_routing = false;
  3534. };
  3535. if( ena_dhcp ){
  3536. if ( BRANG == NULL || ERANG == NULL || MASK == NULL || LEASE_TIME == NULL ) {
  3537. LOG_ERROR("Wrong DHCP parameters to create Network Infrastructure!");
  3538. return 0;
  3539. };
  3540. 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'",
  3541. NIF_ID,
  3542. ena_routing,
  3543. OUTBOUND_NIF,
  3544. BRANG,
  3545. ERANG,
  3546. MASK,
  3547. LEASE_TIME,
  3548. ena_routing,
  3549. OUTBOUND_NIF,
  3550. BRANG,
  3551. ERANG,
  3552. MASK,
  3553. LEASE_TIME
  3554. );
  3555. } else {
  3556. if( ena_routing ){
  3557. 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",
  3558. NIF_ID,
  3559. OUTBOUND_NIF,
  3560. OUTBOUND_NIF
  3561. );
  3562. } else {
  3563. LOG_ERROR("No Special Service Defined To Network Infrastructure!");
  3564. return 0;
  3565. };
  3566. };
  3567. #ifdef DEBUG_ALL
  3568. LOG(tQBuf);
  3569. #endif
  3570. RetVal = m_pDatabase->QueryID( tQBuf );
  3571. // On Update IF data no need to return ID
  3572. if( RetVal == 0 ) {
  3573. RetVal = getNetworkInfrastructureID( NIF_ID );
  3574. };
  3575. };
  3576. return RetVal;
  3577. };
  3578. bool argusDBC::addLRFDraw( uint32_t DBID, uint32_t SIZE, CSTR ID, uint8_t kID, uint8_t type, bool rendered ){
  3579. if( m_bIsConnected ) {
  3580. char tQBuf[MAX_PATH_LEN];
  3581. if ( rendered ) {
  3582. 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'",
  3583. DBID,
  3584. ID,
  3585. SIZE,
  3586. kID,
  3587. type,
  3588. ID,
  3589. SIZE
  3590. );
  3591. } else {
  3592. 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'",
  3593. DBID,
  3594. ID,
  3595. SIZE,
  3596. kID,
  3597. type,
  3598. ID,
  3599. SIZE
  3600. );
  3601. };
  3602. #ifdef DEBUG
  3603. LOG(tQBuf);
  3604. #endif
  3605. m_pDatabase->SilentQuery( tQBuf );
  3606. return true;
  3607. };
  3608. return false;
  3609. };
  3610. 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 ){
  3611. uint32_t RetVal = 0;
  3612. if( m_bIsConnected ) {
  3613. char tQBuf[MAX_PATH_LEN];
  3614. if( RefUUID == NULL ) {
  3615. 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",
  3616. SRC,
  3617. UUID,
  3618. tss,
  3619. tsms,
  3620. evt_type,
  3621. k_id,
  3622. dig_r,
  3623. AZ,
  3624. EL,
  3625. RANGE,
  3626. AREA,
  3627. lat,
  3628. lon,
  3629. alt
  3630. );
  3631. } else {
  3632. 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'",
  3633. SRC,
  3634. UUID,
  3635. tss,
  3636. tsms,
  3637. evt_type,
  3638. k_id,
  3639. dig_r,
  3640. AZ,
  3641. EL,
  3642. RANGE,
  3643. AREA,
  3644. lat,
  3645. lon,
  3646. alt,
  3647. RefUUID
  3648. );
  3649. };
  3650. #ifdef DEBUG_ALL
  3651. LOG(tQBuf);
  3652. #endif
  3653. RetVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
  3654. if( RetVal ) {
  3655. if (RefUUID == NULL) {
  3656. 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",
  3657. RetVal,
  3658. SRC,
  3659. UUID,
  3660. tss,
  3661. tsms,
  3662. evt_type,
  3663. k_id,
  3664. dig_r,
  3665. AZ,
  3666. EL,
  3667. RANGE,
  3668. AREA,
  3669. lat,
  3670. lon,
  3671. alt
  3672. );
  3673. } else {
  3674. 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'",
  3675. RetVal,
  3676. SRC,
  3677. UUID,
  3678. tss,
  3679. tsms,
  3680. evt_type,
  3681. k_id,
  3682. dig_r,
  3683. AZ,
  3684. EL,
  3685. RANGE,
  3686. AREA,
  3687. lat,
  3688. lon,
  3689. alt,
  3690. RefUUID
  3691. );
  3692. };
  3693. m_pDatabase->SilentQuery( tQBuf );
  3694. };
  3695. // Cleanup Mem Targets Older then 1 Hour
  3696. sprintf( tQBuf, "DELETE FROM events_cloud WHERE ts < ( UNIX_TIMESTAMP(NOW()) - 3600 )" );
  3697. m_pDatabase->SilentQuery( tQBuf );
  3698. };
  3699. return RetVal;
  3700. };
  3701. bool argusDBC::addVideoEvent( uint32_t evtID, uint32_t videoID ){
  3702. if( m_bIsConnected ) {
  3703. char tQBuf[MAX_PATH_LEN];
  3704. sprintf( tQBuf, "INSERT INTO `events_2_videos` SET `evt_id`=%d, `video_id`=%d", evtID, videoID );
  3705. #ifdef DEBUG_ALL
  3706. LOG(tQBuf);
  3707. #endif
  3708. m_pDatabase->SilentQuery( tQBuf );
  3709. return true;
  3710. };
  3711. return true;
  3712. };
  3713. /*
  3714. bool argusDBC::addPictureEvent( uint32_t evtID, uint32_t pictureoID ){
  3715. if( m_bIsConnected ) {
  3716. char tQBuf[MAX_PATH_LEN];
  3717. sprintf( tQBuf, "INSERT INTO `events_2_pictures` SET `evt_id`=%d, `picture_id`=%d", evtID, pictureoID );
  3718. #ifdef DEBUG_ALL
  3719. LOG(tQBuf);
  3720. #endif
  3721. m_pDatabase->SilentQuery( tQBuf );
  3722. return true;
  3723. };
  3724. return true;
  3725. };
  3726. */
  3727. uint32_t argusDBC::addVideoRecord( uint32_t streamID, CSTR md5, uint32_t partID ){
  3728. uint32_t tID = 0;
  3729. if( m_bIsConnected ) {
  3730. char tQBuf[MAX_PATH_LEN];
  3731. sprintf( tQBuf, "INSERT INTO `videos` SET `media_stream_id`=%d, `ts`=NOW(), `md5`='%s', `part_id`=%d ", streamID, md5, partID );
  3732. #ifdef DEBUG_ALL
  3733. LOG(tQBuf);
  3734. #endif
  3735. tID = (uint32_t) m_pDatabase->QueryID( tQBuf );
  3736. }
  3737. return tID;
  3738. };
  3739. bool argusDBC::addPicture( DBC_SNAPSHOT_DATA *ptr, CSTR ext ){
  3740. bool rVal = false;
  3741. if( ptr != NULL ){
  3742. if( m_bIsConnected ){
  3743. CSTR tPData = m_pDatabase->escapeBinary( ptr->data, ptr->data_size );
  3744. if ( tPData ) {
  3745. uint32_t pic_id;
  3746. CSTR tQBuf = (CSTR)malloc(BUF_4MB);
  3747. if( tQBuf ) {
  3748. //sprintf( tQBuf, "INSERT INTO `pictures` SET `media_stream_id`=%d, `ts`=NOW(), `md5`='%s', `ext`='%s'",
  3749. sprintf( tQBuf, "INSERT INTO pictures(media_stream_id,ts,md5,ext,data) VALUES(%d,NOW(),'%s','%s','%s')",
  3750. ptr->stream_id, ptr->md5, ext, tPData );
  3751. pic_id = (uint32_t) m_pDatabase->QueryID( tQBuf );
  3752. if ( pic_id ) {
  3753. for( DBC_INT_LIST::iterator idx = ptr->assoc_event_ids.begin(); idx < ptr->assoc_event_ids.end(); idx++ ) {
  3754. sprintf( tQBuf, "INSERT INTO `events_2_pictures` SET `evt_id`=%d, `picture_id`=%d", (*idx), pic_id );
  3755. m_pDatabase->SilentQuery( tQBuf );
  3756. };
  3757. rVal = true;
  3758. };
  3759. free( tQBuf );
  3760. } else {
  3761. LOG_ERROR("Error Allocating Query Buffer!");
  3762. };
  3763. free( tPData );
  3764. } else {
  3765. LOG_ERROR( "Error escaping Pic Data!");
  3766. };
  3767. };
  3768. };
  3769. return rVal;
  3770. };
  3771. 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 ){
  3772. if( m_bIsConnected ) {
  3773. char tQBuf[MAX_PATH_LEN];
  3774. if( master ) {
  3775. 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'",
  3776. nOrder,
  3777. nOffset,
  3778. nDelta,
  3779. nFlip,
  3780. nWidth,
  3781. bSST,
  3782. nSun,
  3783. GP,
  3784. spikes,
  3785. lrfID,
  3786. profileID );
  3787. } else {
  3788. 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'",
  3789. nOrder,
  3790. nOffset,
  3791. nDelta,
  3792. nFlip,
  3793. nWidth,
  3794. bSST,
  3795. nSun,
  3796. GP,
  3797. spikes,
  3798. lrfID,
  3799. profileID );
  3800. };
  3801. #ifdef DEBUG_ALL
  3802. LOG(tQBuf);
  3803. #endif
  3804. m_pDatabase->SilentQuery( tQBuf );
  3805. return true;
  3806. };
  3807. return false;
  3808. };
  3809. bool argusDBC::updateLRFSerial( uint32_t lrfID, CSTR Serial ){
  3810. if( m_bIsConnected ) {
  3811. char tQBuf[MAX_PATH_LEN];
  3812. CSTR tES = m_pDatabase->escapeString( Serial );
  3813. if( tES ) {
  3814. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `serial`='%s' WHERE `id`=%d", tES, lrfID );
  3815. free( tES );
  3816. #ifdef DEBUG_ALL
  3817. LOG(tQBuf);
  3818. #endif
  3819. m_pDatabase->SilentQuery( tQBuf );
  3820. return true;
  3821. };
  3822. };
  3823. return false;
  3824. };
  3825. bool argusDBC::updateLRFVerison( uint32_t lrfID, CSTR version ){
  3826. if( m_bIsConnected ) {
  3827. char tQBuf[MAX_PATH_LEN];
  3828. CSTR tES = m_pDatabase->escapeString( version );
  3829. if( tES ) {
  3830. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `version`='%s' WHERE `id`=%d", tES, lrfID );
  3831. free( tES );
  3832. #ifdef DEBUG_ALL
  3833. LOG(tQBuf);
  3834. #endif
  3835. m_pDatabase->SilentQuery( tQBuf );
  3836. return true;
  3837. };
  3838. };
  3839. return false;
  3840. };
  3841. bool argusDBC::update3DRuntimeStatus( uint32_t lrfID, ALG_RUN_STATUS *ptr ){
  3842. if( m_bIsConnected ) {
  3843. char tQBuf[MAX_PATH_LEN];
  3844. sprintf( tQBuf, "INSERT INTO `lrf_runtime_status` SET `lrf_id`=%d ON DUPLICATE KEY UPDATE `lrf_id`=`lrf_id`", lrfID );
  3845. #ifdef DEBUG_ALL
  3846. LOG(tQBuf);
  3847. #endif
  3848. m_pDatabase->SilentQuery( tQBuf );
  3849. sprintf( tQBuf,
  3850. "UPDATE `lrf_runtime_status` SET "
  3851. "`hw_status`=%d,"
  3852. "`detecting_kernels`=%d,"
  3853. "`th_ready`=%d,"
  3854. "`master_flips`=%d,"
  3855. "`slave_flips`=%d,"
  3856. "`twinc`=%d,"
  3857. "`master_mp_0`=%d,"
  3858. "`master_mp_1`=%d,"
  3859. "`master_mp_2`=%d,"
  3860. "`master_mp_3`=%d,"
  3861. "`master_mp_4`=%d,"
  3862. "`master_mp_5`=%d,"
  3863. "`master_mp_6`=%d,"
  3864. "`master_mp_7`=%d,"
  3865. "`master_gp_0`=%d,"
  3866. "`master_gp_1`=%d,"
  3867. "`master_gp_2`=%d,"
  3868. "`master_gp_3`=%d,"
  3869. "`master_gp_4`=%d,"
  3870. "`master_gp_5`=%d,"
  3871. "`master_gp_6`=%d,"
  3872. "`master_gp_7`=%d,"
  3873. "`master_wp_0`=%d,"
  3874. "`master_wp_1`=%d,"
  3875. "`master_wp_2`=%d,"
  3876. "`master_wp_3`=%d,"
  3877. "`master_wp_4`=%d,"
  3878. "`master_wp_5`=%d,"
  3879. "`master_wp_6`=%d,"
  3880. "`master_wp_7`=%d,"
  3881. "`slave_mp_0`=%d,"
  3882. "`slave_mp_1`=%d,"
  3883. "`slave_mp_2`=%d,"
  3884. "`slave_mp_3`=%d,"
  3885. "`slave_mp_4`=%d,"
  3886. "`slave_mp_5`=%d,"
  3887. "`slave_mp_6`=%d,"
  3888. "`slave_mp_7`=%d,"
  3889. "`slave_gp_0`=%d,"
  3890. "`slave_gp_1`=%d,"
  3891. "`slave_gp_2`=%d,"
  3892. "`slave_gp_3`=%d,"
  3893. "`slave_gp_4`=%d,"
  3894. "`slave_gp_5`=%d,"
  3895. "`slave_gp_6`=%d,"
  3896. "`slave_gp_7`=%d,"
  3897. "`slave_wp_0`=%d,"
  3898. "`slave_wp_1`=%d,"
  3899. "`slave_wp_2`=%d,"
  3900. "`slave_wp_3`=%d,"
  3901. "`slave_wp_4`=%d,"
  3902. "`slave_wp_5`=%d,"
  3903. "`slave_wp_6`=%d,"
  3904. "`slave_wp_7`=%d"
  3905. " WHERE `lrf_id`=%d",
  3906. ptr->HW_STATUS,
  3907. ptr->DETECTING_LRF,
  3908. ptr->TH_READY,
  3909. ptr->MASTER_FLIP_CNT,
  3910. ptr->SLAVE_FLIP_CNT,
  3911. ptr->TWINC_STATUS,
  3912. ptr->MASTER_MP[0],
  3913. ptr->MASTER_MP[1],
  3914. ptr->MASTER_MP[2],
  3915. ptr->MASTER_MP[3],
  3916. ptr->MASTER_MP[4],
  3917. ptr->MASTER_MP[5],
  3918. ptr->MASTER_MP[6],
  3919. ptr->MASTER_MP[7],
  3920. ptr->MASTER_GP[0],
  3921. ptr->MASTER_GP[1],
  3922. ptr->MASTER_GP[2],
  3923. ptr->MASTER_GP[3],
  3924. ptr->MASTER_GP[4],
  3925. ptr->MASTER_GP[5],
  3926. ptr->MASTER_GP[6],
  3927. ptr->MASTER_GP[7],
  3928. ptr->MASTER_WP[0],
  3929. ptr->MASTER_WP[1],
  3930. ptr->MASTER_WP[2],
  3931. ptr->MASTER_WP[3],
  3932. ptr->MASTER_WP[4],
  3933. ptr->MASTER_WP[5],
  3934. ptr->MASTER_WP[6],
  3935. ptr->MASTER_WP[7],
  3936. ptr->SLAVE_MP[0],
  3937. ptr->SLAVE_MP[1],
  3938. ptr->SLAVE_MP[2],
  3939. ptr->SLAVE_MP[3],
  3940. ptr->SLAVE_MP[4],
  3941. ptr->SLAVE_MP[5],
  3942. ptr->SLAVE_MP[6],
  3943. ptr->SLAVE_MP[7],
  3944. ptr->SLAVE_GP[0],
  3945. ptr->SLAVE_GP[1],
  3946. ptr->SLAVE_GP[2],
  3947. ptr->SLAVE_GP[3],
  3948. ptr->SLAVE_GP[4],
  3949. ptr->SLAVE_GP[5],
  3950. ptr->SLAVE_GP[6],
  3951. ptr->SLAVE_GP[7],
  3952. ptr->SLAVE_WP[0],
  3953. ptr->SLAVE_WP[1],
  3954. ptr->SLAVE_WP[2],
  3955. ptr->SLAVE_WP[3],
  3956. ptr->SLAVE_WP[4],
  3957. ptr->SLAVE_WP[5],
  3958. ptr->SLAVE_WP[6],
  3959. ptr->SLAVE_WP[7],
  3960. lrfID
  3961. );
  3962. #ifdef DEBUG_ALL
  3963. LOG(tQBuf);
  3964. #endif
  3965. m_pDatabase->SilentQuery( tQBuf );
  3966. return true;
  3967. };
  3968. return false;
  3969. };
  3970. bool argusDBC::setLRFDataStatus( uint32_t lrfID, uint8_t ST ){
  3971. if( m_bIsConnected ) {
  3972. char tQBuf[MAX_PATH_LEN];
  3973. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `data_status`=%d WHERE `id`=%d", ST, lrfID );
  3974. #ifdef DEBUG_ALL
  3975. LOG(tQBuf);
  3976. #endif
  3977. m_pDatabase->SilentQuery( tQBuf );
  3978. return true;
  3979. };
  3980. return false;
  3981. };
  3982. bool argusDBC::setLRFDetectionProfile( uint32_t lrfID, uint8_t profileID ){
  3983. if( m_bIsConnected ) {
  3984. char tQBuf[MAX_PATH_LEN];
  3985. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `detection_profile_id`=%d WHERE `id`=%d", profileID, lrfID );
  3986. #ifdef DEBUG_ALL
  3987. LOG(tQBuf);
  3988. #endif
  3989. m_pDatabase->SilentQuery( tQBuf );
  3990. return true;
  3991. };
  3992. return false;
  3993. };
  3994. bool argusDBC::setLRFMaskStatus( uint32_t maskID, bool status ){
  3995. if( m_bIsConnected ) {
  3996. char tQBuf[MAX_PATH_LEN];
  3997. char S[2];
  3998. if (status ) {
  3999. S[0] = 'E';
  4000. S[1] = (char)0;
  4001. } else {
  4002. S[0] = 'D';
  4003. S[1] = (char)0;
  4004. };
  4005. sprintf( tQBuf, "UPDATE `lrf_masks` SET `status`='%s' WHERE `id`=%d", S, maskID );
  4006. #ifdef DEBUG_ALL
  4007. LOG(tQBuf);
  4008. #endif
  4009. m_pDatabase->SilentQuery( tQBuf );
  4010. return true;
  4011. };
  4012. return false;
  4013. };
  4014. bool argusDBC::setLRFAltSerial( uint32_t lrfID, CSTR Serial ){
  4015. if( m_bIsConnected ) {
  4016. char tQBuf[MAX_PATH_LEN];
  4017. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `alt_serial`='%s' WHERE `id`=%d", Serial, lrfID );
  4018. #ifdef DEBUG_ALL
  4019. LOG(tQBuf);
  4020. #endif
  4021. m_pDatabase->SilentQuery( tQBuf );
  4022. return true;
  4023. };
  4024. return false;
  4025. };
  4026. bool argusDBC::setLRFAltVerison( uint32_t lrfID, CSTR version ){
  4027. if( m_bIsConnected ) {
  4028. char tQBuf[MAX_PATH_LEN];
  4029. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `alt_version`='%s' WHERE `id`=%d", version, lrfID );
  4030. #ifdef DEBUG_ALL
  4031. LOG(tQBuf);
  4032. #endif
  4033. m_pDatabase->SilentQuery( tQBuf );
  4034. return true;
  4035. };
  4036. return false;
  4037. };
  4038. bool argusDBC::setStreamValid( uint32_t streamID ){
  4039. if( m_bIsConnected ) {
  4040. char tQBuf[MAX_PATH_LEN];
  4041. sprintf( tQBuf, "UPDATE `media_streams` SET `valid`=1 WHERE `id`=%d", streamID );
  4042. #ifdef DEBUG_ALL
  4043. LOG(tQBuf);
  4044. #endif
  4045. m_pDatabase->SilentQuery( tQBuf );
  4046. return true;
  4047. };
  4048. return false;
  4049. };
  4050. bool argusDBC::updateAFPBox( uint32_t filterID, CSTR Tag, float x, float y, float z ){
  4051. if( m_bIsConnected ) {
  4052. char tQBuf[MAX_PATH_LEN];
  4053. 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",
  4054. filterID,
  4055. Tag,
  4056. x,y,z,
  4057. x,y,z
  4058. );
  4059. #ifdef DEBUG_ALL
  4060. LOG(tQBuf);
  4061. #endif
  4062. m_pDatabase->SilentQuery( tQBuf );
  4063. return true;
  4064. };
  4065. return false;
  4066. };
  4067. DBC_MODULE_EMBED_VIDEO_DATA *argusDBC::getEmbedVideoData( uint32_t ID ){
  4068. DBC_MODULE_EMBED_VIDEO_DATA *tPtr = NULL;
  4069. if( m_bIsConnected ) {
  4070. char tQBuf[MAX_PATH_LEN];
  4071. AAssoc *result;
  4072. sprintf( tQBuf, "SELECT * FROM `module_embed_video_settings` WHERE `id`=%d", ID );
  4073. #ifdef DEBUG_ALL
  4074. LOG(tQBuf);
  4075. #endif
  4076. result = m_pDatabase->Query( tQBuf );
  4077. if( result!= NULL ) {
  4078. if( result->size() > 0 ) {
  4079. Assoc *cArr;
  4080. tPtr = (DBC_MODULE_EMBED_VIDEO_DATA*)malloc(sizeof(DBC_MODULE_EMBED_VIDEO_DATA));
  4081. if( tPtr!= NULL ) {
  4082. Assoc::iterator it;
  4083. memset(tPtr,0,sizeof(DBC_MODULE_EMBED_VIDEO_DATA));
  4084. cArr = result->at(0);
  4085. it = cArr->find("web_port");
  4086. if( it != cArr->end() ){
  4087. tPtr->port = atoi( it->second.c_str() );
  4088. };
  4089. it = cArr->find("width");
  4090. if( it != cArr->end() ){
  4091. tPtr->width = atoi( it->second.c_str() );
  4092. };
  4093. it = cArr->find("height");
  4094. if( it != cArr->end() ){
  4095. tPtr->height = atoi( it->second.c_str() );
  4096. };
  4097. it = cArr->find("compression_quality");
  4098. if( it != cArr->end() ){
  4099. tPtr->compression_quality = atoi( it->second.c_str() );
  4100. };
  4101. it = cArr->find("show_ts");
  4102. if( it != cArr->end() ){
  4103. tPtr->show_ts = (bool)atoi( it->second.c_str() );
  4104. };
  4105. it = cArr->find("ts_x");
  4106. if( it != cArr->end() ){
  4107. tPtr->ts_x = atoi( it->second.c_str() );
  4108. };
  4109. it = cArr->find("ts_y");
  4110. if( it != cArr->end() ){
  4111. tPtr->ts_y = atoi( it->second.c_str() );
  4112. };
  4113. it = cArr->find("ts_font_face");
  4114. if( it != cArr->end() ){
  4115. tPtr->ts_font_face = atoi( it->second.c_str() );
  4116. };
  4117. it = cArr->find("ts_font_scale");
  4118. if( it != cArr->end() ){
  4119. tPtr->ts_font_scale = atof( it->second.c_str() );
  4120. };
  4121. it = cArr->find("ts_font_thickness");
  4122. if( it != cArr->end() ){
  4123. tPtr->ts_font_thickness = atoi( it->second.c_str() );
  4124. };
  4125. it = cArr->find("ts_line_type");
  4126. if( it != cArr->end() ){
  4127. tPtr->ts_line_type = atoi( it->second.c_str() );
  4128. };
  4129. it = cArr->find("ts_transperant");
  4130. if( it != cArr->end() ){
  4131. tPtr->ts_transperant = (bool)atoi( it->second.c_str() );
  4132. };
  4133. it = cArr->find("show_label");
  4134. if( it != cArr->end() ){
  4135. tPtr->show_label = (bool)atoi( it->second.c_str() );
  4136. };
  4137. it = cArr->find("label_x");
  4138. if( it != cArr->end() ){
  4139. tPtr->label_x = atoi( it->second.c_str() );
  4140. };
  4141. it = cArr->find("label_y");
  4142. if( it != cArr->end() ){
  4143. tPtr->label_y = atoi( it->second.c_str() );
  4144. };
  4145. it = cArr->find("label_font_face");
  4146. if( it != cArr->end() ){
  4147. tPtr->label_font_face = atoi( it->second.c_str() );
  4148. };
  4149. it = cArr->find("label_font_scale");
  4150. if( it != cArr->end() ){
  4151. tPtr->label_font_scale = atof( it->second.c_str() );
  4152. };
  4153. it = cArr->find("label_font_thickness");
  4154. if( it != cArr->end() ){
  4155. tPtr->label_font_thickness = atoi( it->second.c_str() );
  4156. };
  4157. it = cArr->find("label_line_type");
  4158. if( it != cArr->end() ){
  4159. tPtr->label_line_type = atoi( it->second.c_str() );
  4160. };
  4161. it = cArr->find("label_transperant");
  4162. if( it != cArr->end() ){
  4163. tPtr->label_transperant = (bool) atoi( it->second.c_str() );
  4164. };
  4165. it = cArr->find("show_logo");
  4166. if( it != cArr->end() ){
  4167. tPtr->show_logo = (bool) atoi( it->second.c_str() );
  4168. };
  4169. it = cArr->find("logo_w");
  4170. if( it != cArr->end() ){
  4171. tPtr->logo_w = atoi( it->second.c_str() );
  4172. };
  4173. it = cArr->find("logo_h");
  4174. if( it != cArr->end() ){
  4175. tPtr->logo_h = atoi( it->second.c_str() );
  4176. };
  4177. it = cArr->find("logo_x");
  4178. if( it != cArr->end() ){
  4179. tPtr->logo_x = atoi( it->second.c_str() );
  4180. };
  4181. it = cArr->find("logo_y");
  4182. if( it != cArr->end() ){
  4183. tPtr->logo_y = atoi( it->second.c_str() );
  4184. };
  4185. it = cArr->find("logo_md5");
  4186. if( it != cArr->end() ){
  4187. strncpy( tPtr->logo_md5, it->second.c_str(),32);
  4188. tPtr->logo_md5[32]=(char)0;
  4189. };
  4190. };
  4191. };
  4192. };
  4193. deleteResult( result );
  4194. };
  4195. return tPtr;
  4196. };
  4197. DBC_EVT_RECORD *argusDBC::getEventByUUID( CSTR UUID ){
  4198. DBC_EVT_RECORD *tPtr = NULL;
  4199. if( m_bIsConnected ) {
  4200. char tQBuf[MAX_PATH_LEN];
  4201. AAssoc *result;
  4202. sprintf( tQBuf, "SELECT * FROM events_cloud WHERE uuid = '%s'", UUID );
  4203. #ifdef DEBUG_ALL
  4204. LOG(tQBuf);
  4205. #endif
  4206. result = m_pDatabase->Query( tQBuf );
  4207. if( result!= NULL ) {
  4208. if( result->size() > 0 ) {
  4209. Assoc *cArr;
  4210. tPtr = (DBC_EVT_RECORD*)malloc(sizeof(DBC_EVT_RECORD));
  4211. if( tPtr!= NULL ) {
  4212. Assoc::iterator it;
  4213. memset(tPtr,0,sizeof(DBC_EVT_RECORD));
  4214. cArr = result->at(0);
  4215. it = cArr->find("id");
  4216. if( it != cArr->end() ){
  4217. tPtr->id = atoi( it->second.c_str() );
  4218. };
  4219. it = cArr->find("node_id");
  4220. if( it != cArr->end() ){
  4221. tPtr->node_id = atoi( it->second.c_str() );
  4222. };
  4223. it = cArr->find("uuid");
  4224. if( it != cArr->end() ){
  4225. strncpy( tPtr->uuid, it->second.c_str(),64 );
  4226. };
  4227. it = cArr->find("ts");
  4228. if( it != cArr->end() ){
  4229. tPtr->ts_s = atoi( it->second.c_str() );
  4230. };
  4231. it = cArr->find("ts_ms");
  4232. if( it != cArr->end() ){
  4233. tPtr->ts_ms = atoi( it->second.c_str() );
  4234. };
  4235. it = cArr->find("evt_type");
  4236. if( it != cArr->end() ){
  4237. tPtr->type = atoi( it->second.c_str() );
  4238. };
  4239. it = cArr->find("range_digital");
  4240. if( it != cArr->end() ){
  4241. tPtr->range_digital = atoi( it->second.c_str() );
  4242. };
  4243. it = cArr->find("azimuth");
  4244. if( it != cArr->end() ){
  4245. tPtr->az = atof( it->second.c_str() );
  4246. };
  4247. it = cArr->find("elevation");
  4248. if( it != cArr->end() ){
  4249. tPtr->el = atof( it->second.c_str() );
  4250. };
  4251. it = cArr->find("range");
  4252. if( it != cArr->end() ){
  4253. tPtr->ra = atof( it->second.c_str() );
  4254. };
  4255. it = cArr->find("area");
  4256. if( it != cArr->end() ){
  4257. tPtr->area = atof( it->second.c_str() );
  4258. };
  4259. it = cArr->find("lat");
  4260. if( it != cArr->end() ){
  4261. tPtr->lat = atof( it->second.c_str() );
  4262. };
  4263. it = cArr->find("lon");
  4264. if( it != cArr->end() ){
  4265. tPtr->lon = atof( it->second.c_str() );
  4266. };
  4267. it = cArr->find("alt");
  4268. if( it != cArr->end() ){
  4269. tPtr->alt = atof( it->second.c_str() );
  4270. };
  4271. it = cArr->find("ref_id");
  4272. if( it != cArr->end() ){
  4273. tPtr->ref_id = atoi( it->second.c_str() );
  4274. };
  4275. it = cArr->find("ref_uuid");
  4276. if( it != cArr->end() ){
  4277. strncpy( tPtr->ref_uuid, it->second.c_str(),64 );
  4278. };
  4279. };
  4280. };
  4281. };
  4282. deleteResult( result );
  4283. };
  4284. return tPtr;
  4285. };
  4286. #undef LOG
  4287. #undef LOG_ERROR