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.

1610 lines
57 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
2 years ago
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
12 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
12 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
2 years ago
​
​
​
​
​
​
​
2 years ago
​
2 years ago
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
2 years ago
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
2 years ago
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "serverMySQL_dataBinder.h"
  2. #define LOG( X ) m_pLog->Log( "MDBC", 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( "MDBC", this, _LOG_ERROR, _tBfrErrMSG2w34 );\
  8. }
  9. #else
  10. #define LOG_ERROR( X ) m_pLog->Log( "MDBC", this, _LOG_ERROR, X );
  11. #endif
  12. servaMySQLDBC *servaMySQLDBC::_instance = NULL;
  13. /**
  14. * Returns the single instance of the object.
  15. */
  16. servaMySQLDBC* servaMySQLDBC::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 servaMySQLDBC( Settings );
  21. };
  22. // return the single instance
  23. return _instance;
  24. };
  25. servaMySQLDBC::servaMySQLDBC( config_setting_t * Settings ):serverDataBinder(){
  26. m_pLog = basicLogCollection::getInstance();
  27. m_pSettings = basicSettingsProvider::getInstance()->getSubNode( Settings, "DBC" );
  28. m_bIsConnected = false;
  29. m_pDatabase = NULL;
  30. };
  31. servaMySQLDBC::~servaMySQLDBC(){
  32. m_bIsConnected = false;
  33. if( m_pDatabase != NULL ) delete( m_pDatabase );
  34. m_pDatabase = NULL;
  35. _instance = NULL;
  36. };
  37. uint64_t servaMySQLDBC::addMediaQueueRecord( CSTR uuid, uint64_t module_id, uint64_t session_id, uint32_t ts, uint16_t tsms, uint16_t width, uint16_t height, uint8_t fps, CSTR fmt ){
  38. uint64_t RetVal = 0;
  39. if(m_bIsConnected){
  40. char tQBuf[4096];
  41. sprintf( tQBuf, "INSERT INTO `media_queue` SET `module_id`=%" PRIu64 ", `session_id`=%" PRIu64 ", `ts`=%d, `tsms`=%d, `uuid`='%s', `width`=%d, `height`=%d, `fps`=%d, `fmt`='%s', `status`=0, `process`=0",
  42. module_id, session_id, ts, tsms, uuid, width, height, fps, fmt
  43. );
  44. #ifdef DEBUG_ALL
  45. LOG(tQBuf);
  46. #endif
  47. RetVal = m_pDatabase->QueryID( tQBuf );
  48. };
  49. return RetVal;
  50. };
  51. bool servaMySQLDBC::connect( void ){
  52. config_setting_t * tSetting;
  53. m_bIsConnected = false;
  54. if( m_pSettings!= NULL ) {
  55. tSetting = config_setting_get_member( m_pSettings, "DATABASE_HOST" );
  56. if( tSetting == NULL ){
  57. tSetting = config_setting_add(m_pSettings, "DATABASE_HOST", CONFIG_TYPE_STRING );
  58. config_setting_set_string( tSetting, "localhost" );
  59. basicSettingsProvider::getInstance()->compromise();
  60. LOG("No DB Host Setting! Using default!");
  61. };
  62. sprintf(m_pDbHost, "%s", config_setting_get_string(tSetting));
  63. tSetting = config_setting_get_member(m_pSettings, "DATABASE_NAME");
  64. if( tSetting == NULL ){
  65. tSetting = config_setting_add(m_pSettings, "DATABASE_NAME", CONFIG_TYPE_STRING );
  66. config_setting_set_string( tSetting, "dfsl_gunter" );
  67. basicSettingsProvider::getInstance()->compromise();
  68. LOG("No DB Database Setting! Using default!");
  69. };
  70. sprintf(m_pDbDatabase, "%s", config_setting_get_string(tSetting));
  71. tSetting = config_setting_get_member( m_pSettings, "DATABASE_USER" );
  72. if( tSetting == NULL ){
  73. tSetting = config_setting_add(m_pSettings, "DATABASE_USER", CONFIG_TYPE_STRING );
  74. config_setting_set_string( tSetting, "dbroot" );
  75. basicSettingsProvider::getInstance()->compromise();
  76. LOG("No DB User Setting! Using default!");
  77. };
  78. sprintf(m_pDbUsername, "%s", config_setting_get_string(tSetting));
  79. tSetting = config_setting_get_member( m_pSettings, "DATABASE_PASSWORD" );
  80. if( tSetting == NULL ){
  81. tSetting = config_setting_add(m_pSettings, "DATABASE_PASSWORD", CONFIG_TYPE_STRING );
  82. config_setting_set_string( tSetting, "123567" );
  83. basicSettingsProvider::getInstance()->compromise();
  84. LOG("No DB Password Setting! Using default!");
  85. };
  86. sprintf(m_pDbPassword, "%s", config_setting_get_string(tSetting));
  87. basicSettingsProvider::getInstance()->validate();
  88. m_pDatabase = new MySQL_Connector();
  89. if( m_pDatabase == NULL )return false;
  90. m_bIsConnected = m_pDatabase->Connect( m_pDbDatabase, m_pDbHost, m_pDbUsername, m_pDbPassword );
  91. } else {
  92. LOG_ERROR("No Settings Provided!");
  93. };
  94. return m_bIsConnected;
  95. };
  96. bool servaMySQLDBC::closeAllOnGoingSessions(){
  97. if( m_bIsConnected ){
  98. char tQBuf[MAX_PATH_LEN];
  99. sprintf( tQBuf, "UPDATE `sessions` SET `final`='Y' WHERE `final`='N'" );
  100. #ifdef DEBUG_ALL
  101. LOG(tQBuf);
  102. #endif
  103. m_pDatabase->SilentQuery( tQBuf );
  104. };
  105. return true;
  106. };
  107. bool servaMySQLDBC::cleanWebCmd(){
  108. if( m_bIsConnected ){
  109. char tQBuf[MAX_PATH_LEN];
  110. sprintf( tQBuf, "DELETE FROM `mem_web_queue` WHERE `status`>100" );
  111. #ifdef DEBUG_ALL
  112. LOG(tQBuf);
  113. #endif
  114. m_pDatabase->SilentQuery( tQBuf );
  115. };
  116. return true;
  117. };
  118. bool servaMySQLDBC::deleteSession(uint64_t id ){
  119. if( m_bIsConnected ){
  120. char tQBuf[MAX_PATH_LEN];
  121. sprintf( tQBuf, "DELETE FROM `sessions` WHERE `id`=%"PRIu64, id );
  122. #ifdef DEBUG_ALL
  123. LOG(tQBuf);
  124. #endif
  125. m_pDatabase->SilentQuery( tQBuf );
  126. };
  127. return true;
  128. };
  129. CSTR servaMySQLDBC::getMediaUUID( uint64_t id ){
  130. CSTR RetVal = NULL;
  131. if( m_bIsConnected ){
  132. char tQBuf[MAX_PATH_LEN];
  133. AAssoc *result;
  134. sprintf( tQBuf, "SELECT `uuid` FROM `media_queue` WHERE `id`=%"PRIu64, id );
  135. #ifdef DEBUG_ALL
  136. LOG(tQBuf);
  137. #endif
  138. result = m_pDatabase->Query( tQBuf );
  139. if( result!= NULL ) {
  140. if( result->size() > 0 ) {
  141. Assoc *cArr;
  142. Assoc::iterator it;
  143. cArr = result->at(0);
  144. it = cArr->find("uuid");
  145. if( it != cArr->end() ){
  146. RetVal = strdup( it->second.c_str() );
  147. };
  148. };
  149. };
  150. deleteResult( result );
  151. };
  152. return RetVal;
  153. };
  154. MODBUS_MANAGER_DATA *servaMySQLDBC::getModBusManagerData(){
  155. MODBUS_MANAGER_DATA *RetVal = NULL;
  156. if( m_bIsConnected ){
  157. char tQBuf[MAX_PATH_LEN];
  158. sprintf( tQBuf, "SELECT `modbus_auto_rise`,`modbus_health_level`,`modbus_hazard_level` FROM `system_props` WHERE `id`=1" );
  159. #ifdef DEBUG_ALL
  160. LOG(tQBuf);
  161. #endif
  162. AAssoc *result;
  163. result = m_pDatabase->Query( tQBuf );
  164. if( result!= NULL ) {
  165. if( result->size() > 0 ) {
  166. RetVal = (MODBUS_MANAGER_DATA *)malloc(sizeof(MODBUS_MANAGER_DATA));
  167. if ( RetVal ) {
  168. memset( RetVal, 0, sizeof( MODBUS_MANAGER_DATA ));
  169. Assoc *cArr;
  170. Assoc::iterator it;
  171. cArr = result->at(0);
  172. it = cArr->find("modbus_auto_rise");
  173. if( it != cArr->end() ){
  174. RetVal->automaticAlarmRisingTO = atoi(it->second.c_str());
  175. };
  176. it = cArr->find("modbus_health_level");
  177. if( it != cArr->end() ){
  178. RetVal->helthSignalLevel = atoi(it->second.c_str());
  179. };
  180. it = cArr->find("modbus_hazard_level");
  181. if( it != cArr->end() ){
  182. RetVal->hazardSignalLevel = atoi(it->second.c_str());
  183. };
  184. };
  185. };
  186. deleteResult( result );
  187. };
  188. };
  189. return RetVal;
  190. };
  191. MODBUS_RTU_INFO *servaMySQLDBC::getModBusRTU( uint64_t id ){
  192. MODBUS_RTU_INFO *RetVal = NULL;
  193. if( m_bIsConnected ){
  194. char tQBuf[MAX_PATH_LEN];
  195. AAssoc *result;
  196. sprintf(tQBuf, "SELECT * FROM `modbus_modules` WHERE `id`=%" PRIu64, id );
  197. #ifdef DEBUG_ALL
  198. LOG(tQBuf);
  199. #endif
  200. result = m_pDatabase->Query( tQBuf );
  201. if( result!= NULL ) {
  202. if( result->size() > 0 ) {
  203. RetVal = (MODBUS_RTU_INFO *)malloc(sizeof(MODBUS_RTU_INFO));
  204. if ( RetVal ) {
  205. memset( RetVal, 0, sizeof( MODBUS_RTU_INFO ));
  206. RetVal->id = id;
  207. RetVal->input_base_addr = 0x00;
  208. RetVal->output_base_addr = 0x10;
  209. Assoc *cArr;
  210. Assoc::iterator it;
  211. cArr = result->at(0);
  212. it = cArr->find("platform_id");
  213. if( it != cArr->end() ){
  214. RetVal->platform_id = atoll(it->second.c_str());
  215. };
  216. it = cArr->find("ip4");
  217. if( it != cArr->end() ){
  218. strncpy( RetVal->ip, it->second.c_str(), 15 );
  219. RetVal->ip[15] = (char)0;
  220. };
  221. it = cArr->find("port");
  222. if( it != cArr->end() ){
  223. RetVal->port = atoi( it->second.c_str() );
  224. };
  225. it = cArr->find("status");
  226. if( it != cArr->end() ){
  227. RetVal->status = atoi( it->second.c_str() );
  228. };
  229. it = cArr->find("values");
  230. if( it != cArr->end() ){
  231. RetVal->c_OutBits = atoi( it->second.c_str() ) & 0xFF;
  232. RetVal->c_InBits = ( atoi( it->second.c_str() ) >> 8 ) & 0xFF;
  233. };
  234. it = cArr->find("crossbar_a");
  235. if( it != cArr->end() ){
  236. RetVal->crossbar[0] = atoi( it->second.c_str() ) & 0xFF;
  237. };
  238. it = cArr->find("crossbar_b");
  239. if( it != cArr->end() ){
  240. RetVal->crossbar[1] = atoi( it->second.c_str() ) & 0xFF;
  241. };
  242. it = cArr->find("crossbar_c");
  243. if( it != cArr->end() ){
  244. RetVal->crossbar[2] = atoi( it->second.c_str() ) & 0xFF;
  245. };
  246. it = cArr->find("crossbar_d");
  247. if( it != cArr->end() ){
  248. RetVal->crossbar[3] = atoi( it->second.c_str() ) & 0xFF;
  249. };
  250. };
  251. };
  252. deleteResult( result );
  253. };
  254. };
  255. return RetVal;
  256. };
  257. MODBUS_RTU_INFO *servaMySQLDBC::getModBusRTU_Platform( uint64_t id ){
  258. MODBUS_RTU_INFO *RetVal = NULL;
  259. if( m_bIsConnected ){
  260. char tQBuf[MAX_PATH_LEN];
  261. AAssoc *result;
  262. sprintf(tQBuf, "SELECT * FROM `modbus_modules` WHERE `platform_id`=%" PRIu64, id );
  263. #ifdef DEBUG_ALL
  264. LOG(tQBuf);
  265. #endif
  266. result = m_pDatabase->Query( tQBuf );
  267. if( result!= NULL ) {
  268. if( result->size() > 0 ) {
  269. RetVal = (MODBUS_RTU_INFO *)malloc(sizeof(MODBUS_RTU_INFO));
  270. if ( RetVal ) {
  271. memset( RetVal, 0, sizeof( MODBUS_RTU_INFO ));
  272. RetVal->id = id;
  273. RetVal->input_base_addr = 0x00;
  274. RetVal->output_base_addr = 0x10;
  275. Assoc *cArr;
  276. Assoc::iterator it;
  277. cArr = result->at(0);
  278. it = cArr->find("platform_id");
  279. if( it != cArr->end() ){
  280. RetVal->platform_id = atoll(it->second.c_str());
  281. };
  282. it = cArr->find("ip4");
  283. if( it != cArr->end() ){
  284. strncpy( RetVal->ip, it->second.c_str(), 15 );
  285. RetVal->ip[15] = (char)0;
  286. };
  287. it = cArr->find("port");
  288. if( it != cArr->end() ){
  289. RetVal->port = atoi( it->second.c_str() );
  290. };
  291. it = cArr->find("status");
  292. if( it != cArr->end() ){
  293. RetVal->status = atoi( it->second.c_str() );
  294. };
  295. it = cArr->find("values");
  296. if( it != cArr->end() ){
  297. RetVal->c_OutBits = atoi( it->second.c_str() ) & 0xFF;
  298. RetVal->c_InBits = ( atoi( it->second.c_str() ) >> 8 ) & 0xFF;
  299. };
  300. it = cArr->find("crossbar_a");
  301. if( it != cArr->end() ){
  302. RetVal->crossbar[0] = atoi( it->second.c_str() ) & 0xFF;
  303. };
  304. it = cArr->find("crossbar_b");
  305. if( it != cArr->end() ){
  306. RetVal->crossbar[1] = atoi( it->second.c_str() ) & 0xFF;
  307. };
  308. it = cArr->find("crossbar_c");
  309. if( it != cArr->end() ){
  310. RetVal->crossbar[2] = atoi( it->second.c_str() ) & 0xFF;
  311. };
  312. it = cArr->find("crossbar_d");
  313. if( it != cArr->end() ){
  314. RetVal->crossbar[3] = atoi( it->second.c_str() ) & 0xFF;
  315. };
  316. };
  317. };
  318. deleteResult( result );
  319. };
  320. };
  321. return RetVal;
  322. };
  323. DBC_IS_MODULE_DATA *servaMySQLDBC::getModuleData( uint64_t id ){
  324. DBC_IS_MODULE_DATA *RetVal = NULL;
  325. if( m_bIsConnected ){
  326. char tQBuf[MAX_PATH_LEN];
  327. AAssoc *result;
  328. sprintf(tQBuf, "SELECT * FROM `metro_modules` WHERE `id`=%" PRIu64, id );
  329. #ifdef DEBUG_ALL
  330. LOG(tQBuf);
  331. #endif
  332. result = m_pDatabase->Query( tQBuf );
  333. if( result!= NULL ) {
  334. if( result->size() > 0 ) {
  335. RetVal = (DBC_IS_MODULE_DATA *)malloc(sizeof(DBC_IS_MODULE_DATA));
  336. if ( RetVal ) {
  337. memset( RetVal, 0, sizeof( DBC_IS_MODULE_DATA ));
  338. RetVal->id = id;
  339. Assoc *cArr;
  340. Assoc::iterator it;
  341. cArr = result->at(0);
  342. it = cArr->find("track_id");
  343. if( it != cArr->end() ){
  344. RetVal->track_id = atoll(it->second.c_str());
  345. };
  346. it = cArr->find("side");
  347. if( it != cArr->end() ){
  348. RetVal->side = it->second.c_str()[0];
  349. };
  350. it = cArr->find("status");
  351. if( it != cArr->end() ){
  352. RetVal->status = it->second.c_str()[0];
  353. };
  354. it = cArr->find("IP4");
  355. if( it != cArr->end() ){
  356. strncpy( RetVal->ip4, it->second.c_str(), 15 );
  357. RetVal->ip4[15] = (char)0;
  358. };
  359. };
  360. };
  361. deleteResult( result );
  362. };
  363. };
  364. return RetVal;
  365. };
  366. char servaMySQLDBC::getMojoWM( uint64_t id ){
  367. char RetVal = 'N';
  368. if( m_bIsConnected ){
  369. char tQBuf[MAX_PATH_LEN];
  370. AAssoc *result;
  371. sprintf( tQBuf, "SELECT `status` FROM `metro_modules` WHERE `id`=%" PRIu64 "", id );
  372. #ifdef DEBUG_ALL
  373. LOG(tQBuf);
  374. #endif
  375. result = m_pDatabase->Query( tQBuf );
  376. if( result!= NULL ) {
  377. if( result->size() > 0 ) {
  378. Assoc *cArr;
  379. Assoc::iterator it;
  380. cArr = result->at(0);
  381. it = cArr->find("status");
  382. if( it != cArr->end() ){
  383. RetVal = it->second.c_str()[0];
  384. };
  385. };
  386. deleteResult( result );
  387. };
  388. };
  389. return RetVal;
  390. };
  391. DBC_RPC_WEB_CMD *servaMySQLDBC::fetchWebCmd( uint64_t id ){
  392. DBC_RPC_WEB_CMD *RetVal = NULL;
  393. if( m_bIsConnected ){
  394. char tQBuf[MAX_PATH_LEN];
  395. AAssoc *result;
  396. sprintf(tQBuf, "SELECT `id`,`cmd`,`aux_id`,`param` FROM `mem_web_queue` WHERE `module_id`=%" PRIu64 " AND `status`=0 LIMIT 1", id );
  397. #ifdef DEBUG_ALL
  398. LOG(tQBuf);
  399. #endif
  400. result = m_pDatabase->Query( tQBuf );
  401. if( result!= NULL ) {
  402. if( result->size() > 0 ) {
  403. RetVal = (DBC_RPC_WEB_CMD *)malloc(sizeof(DBC_RPC_WEB_CMD));
  404. if ( RetVal ) {
  405. memset( RetVal, 0, sizeof( DBC_RPC_WEB_CMD ));
  406. Assoc *cArr;
  407. Assoc::iterator it;
  408. cArr = result->at(0);
  409. it = cArr->find("id");
  410. if( it != cArr->end() ){
  411. RetVal->id = atoll( it->second.c_str() );
  412. };
  413. it = cArr->find("cmd");
  414. if( it != cArr->end() ){
  415. RetVal->cmd = atoi( it->second.c_str() );
  416. };
  417. it = cArr->find("aux_id");
  418. if( it != cArr->end() ){
  419. RetVal->aux_id = atoll( it->second.c_str() );
  420. };
  421. it = cArr->find("param");
  422. if( it != cArr->end() ){
  423. strncpy( RetVal->param, it->second.c_str(), 64 );
  424. RetVal->param[64] = (char) 0;
  425. };
  426. };
  427. };
  428. deleteResult( result );
  429. };
  430. };
  431. return RetVal;
  432. };
  433. uint64_t servaMySQLDBC::getBottomLRF( uint64_t id ){
  434. uint64_t RetVal = 0;
  435. if( m_bIsConnected ){
  436. char tQBuf[MAX_PATH_LEN];
  437. AAssoc *result;
  438. sprintf( tQBuf, "SELECT `id` FROM `lrf_sensors` WHERE `role`='B' AND `mojo_id`=%d", id );
  439. #ifdef DEBUG_ALL
  440. LOG(tQBuf);
  441. #endif
  442. result = m_pDatabase->Query( tQBuf );
  443. if( result!= NULL ) {
  444. if( result->size() > 0 ) {
  445. Assoc *cArr;
  446. Assoc::iterator it;
  447. cArr = result->at(0);
  448. it = cArr->find("id");
  449. if( it != cArr->end() ){
  450. RetVal = atoll( it->second.c_str() );
  451. };
  452. };
  453. };
  454. deleteResult( result );
  455. };
  456. return RetVal;
  457. };
  458. uint32_t servaMySQLDBC::getCloudLTS( uint8_t Obj, uint64_t id ){
  459. uint32_t RetVal = 0;
  460. if( m_bIsConnected ){
  461. char tQBuf[MAX_PATH_LEN];
  462. AAssoc *result;
  463. sprintf( tQBuf, "SELECT `ts` FROM `mem_online_cloud` WHERE `object_id`=%" PRIu64 " AND `object_type`=%d", id, Obj );
  464. #ifdef DEBUG_ALL
  465. LOG(tQBuf);
  466. #endif
  467. result = m_pDatabase->Query( tQBuf );
  468. if( result!= NULL ) {
  469. if( result->size() > 0 ) {
  470. Assoc *cArr;
  471. Assoc::iterator it;
  472. cArr = result->at(0);
  473. it = cArr->find("ts");
  474. if( it != cArr->end() ){
  475. RetVal = atoi( it->second.c_str() );
  476. };
  477. };
  478. };
  479. deleteResult( result );
  480. };
  481. return RetVal;
  482. };
  483. uint8_t servaMySQLDBC::getCloudStatus( uint8_t Obj, uint64_t id ){
  484. uint8_t RetVal = 0;
  485. if( m_bIsConnected ){
  486. char tQBuf[MAX_PATH_LEN];
  487. AAssoc *result;
  488. sprintf( tQBuf, "SELECT `status` FROM `mem_online_cloud` WHERE `object_id`=%" PRIu64 " AND `object_type`=%d", id, Obj );
  489. #ifdef DEBUG_ALL
  490. LOG(tQBuf);
  491. #endif
  492. result = m_pDatabase->Query( tQBuf );
  493. if( result!= NULL ) {
  494. if( result->size() > 0 ) {
  495. Assoc *cArr;
  496. Assoc::iterator it;
  497. cArr = result->at(0);
  498. it = cArr->find("status");
  499. if( it != cArr->end() ){
  500. RetVal = atoi( it->second.c_str() );
  501. };
  502. };
  503. };
  504. deleteResult( result );
  505. };
  506. return RetVal;
  507. };
  508. bool servaMySQLDBC::getDBLoggingSettings( void ){
  509. bool RetVal = false;
  510. if( m_bIsConnected ){
  511. char tQBuf[MAX_PATH_LEN];
  512. AAssoc *result;
  513. sprintf( tQBuf, "SELECT `use_db_logging` FROM `system_props` WHERE `id`=1" );
  514. #ifdef DEBUG_ALL
  515. LOG(tQBuf);
  516. #endif
  517. result = m_pDatabase->Query( tQBuf );
  518. if( result!= NULL ) {
  519. if( result->size() > 0 ) {
  520. Assoc *cArr;
  521. Assoc::iterator it;
  522. cArr = result->at(0);
  523. it = cArr->find("use_db_logging");
  524. if( it != cArr->end() ){
  525. RetVal = (bool) atoi( it->second.c_str() );
  526. };
  527. };
  528. };
  529. deleteResult( result );
  530. };
  531. return RetVal;
  532. };
  533. uint64_t servaMySQLDBC::getRecentMediaId(){
  534. uint64_t RetVal = 0;
  535. if( m_bIsConnected ){
  536. char tQBuf[MAX_PATH_LEN];
  537. AAssoc *result;
  538. sprintf( tQBuf, "SELECT `id` FROM `media_queue` WHERE `status`=1 ORDER BY `ts` LIMIT 1" );
  539. #ifdef DEBUG_ALL
  540. LOG(tQBuf);
  541. #endif
  542. result = m_pDatabase->Query( tQBuf );
  543. if( result!= NULL ) {
  544. if( result->size() > 0 ) {
  545. Assoc *cArr;
  546. Assoc::iterator it;
  547. cArr = result->at(0);
  548. it = cArr->find("id");
  549. if( it != cArr->end() ){
  550. RetVal = atoll( it->second.c_str() );
  551. };
  552. };
  553. };
  554. deleteResult( result );
  555. };
  556. return RetVal;
  557. };
  558. DBC_RPC_MEDIA_INFO *servaMySQLDBC::getRemoteMediaInfo( uint64_t id ){
  559. DBC_RPC_MEDIA_INFO *RetVal = NULL;
  560. if( m_bIsConnected ){
  561. char tQBuf[MAX_PATH_LEN];
  562. AAssoc *result;
  563. sprintf( tQBuf, "SELECT * FROM `media_queue` WHERE `id`=%" PRIu64, id );
  564. #ifdef DEBUG_ALL
  565. LOG(tQBuf);
  566. #endif
  567. result = m_pDatabase->Query( tQBuf );
  568. if( result!= NULL ) {
  569. if (result->size() > 0) {
  570. Assoc *cArr;
  571. Assoc::iterator it;
  572. RetVal = ( DBC_RPC_MEDIA_INFO *) malloc(sizeof(DBC_RPC_MEDIA_INFO));
  573. if ( RetVal ) {
  574. cArr = result->at(0);
  575. it = cArr->find("module_id");
  576. if( it != cArr->end() ){
  577. RetVal->module_id = atoll( it->second.c_str() );
  578. };
  579. it = cArr->find("session_id");
  580. if( it != cArr->end() ){
  581. RetVal->session_id = atoll( it->second.c_str() );
  582. };
  583. it = cArr->find("uuid");
  584. if( it != cArr->end() ){
  585. strncpy( RetVal->uuid, it->second.c_str(), 64 );
  586. RetVal->uuid[64] = (char)0;
  587. };
  588. it = cArr->find("width");
  589. if( it != cArr->end() ){
  590. RetVal->width = atoi( it->second.c_str() );
  591. };
  592. it = cArr->find("height");
  593. if( it != cArr->end() ){
  594. RetVal->height = atoi( it->second.c_str() );
  595. };
  596. it = cArr->find("fps");
  597. if( it != cArr->end() ){
  598. RetVal->fps = atoi( it->second.c_str() );
  599. };
  600. it = cArr->find("fmt");
  601. if( it != cArr->end() ){
  602. strncpy( RetVal->fmt, it->second.c_str(), 5 );
  603. RetVal->fmt[5] = (char)0;
  604. };
  605. };
  606. };
  607. };
  608. deleteResult( result );
  609. };
  610. return RetVal;
  611. };
  612. DBC_RPC_MEDIA_INFO_EX *servaMySQLDBC::getRemoteMediaInfoEx( uint64_t id ){
  613. DBC_RPC_MEDIA_INFO_EX *RetVal = NULL;
  614. if( m_bIsConnected ){
  615. char tQBuf[MAX_PATH_LEN];
  616. AAssoc *result;
  617. sprintf( tQBuf, "SELECT * FROM `media_queue` WHERE `id`=%" PRIu64, id );
  618. #ifdef DEBUG_ALL
  619. LOG(tQBuf);
  620. #endif
  621. result = m_pDatabase->Query( tQBuf );
  622. if( result!= NULL ) {
  623. if (result->size() > 0) {
  624. Assoc *cArr;
  625. Assoc::iterator it;
  626. RetVal = ( DBC_RPC_MEDIA_INFO_EX *) malloc(sizeof(DBC_RPC_MEDIA_INFO_EX));
  627. if ( RetVal ) {
  628. cArr = result->at(0);
  629. it = cArr->find("module_id");
  630. if( it != cArr->end() ){
  631. RetVal->module_id = atoll( it->second.c_str() );
  632. };
  633. it = cArr->find("session_id");
  634. if( it != cArr->end() ){
  635. RetVal->session_id = atoll( it->second.c_str() );
  636. };
  637. it = cArr->find("ts");
  638. if( it != cArr->end() ){
  639. RetVal->ts = atoi( it->second.c_str() );
  640. };
  641. it = cArr->find("tsms");
  642. if( it != cArr->end() ){
  643. RetVal->tms = atoi( it->second.c_str() );
  644. };
  645. it = cArr->find("uuid");
  646. if( it != cArr->end() ){
  647. strncpy( RetVal->uuid, it->second.c_str(), 64 );
  648. RetVal->uuid[64] = (char)0;
  649. };
  650. it = cArr->find("width");
  651. if( it != cArr->end() ){
  652. RetVal->width = atoi( it->second.c_str() );
  653. };
  654. it = cArr->find("height");
  655. if( it != cArr->end() ){
  656. RetVal->height = atoi( it->second.c_str() );
  657. };
  658. it = cArr->find("fps");
  659. if( it != cArr->end() ){
  660. RetVal->fps = atoi( it->second.c_str() );
  661. };
  662. it = cArr->find("fmt");
  663. if( it != cArr->end() ){
  664. strncpy( RetVal->fmt, it->second.c_str(), 5 );
  665. RetVal->fmt[5] = (char)0;
  666. };
  667. };
  668. };
  669. };
  670. deleteResult( result );
  671. };
  672. return RetVal;
  673. };
  674. DBC_SERVA_CONFIG *servaMySQLDBC::getServaConfig( ){
  675. DBC_SERVA_CONFIG *RetVal = NULL;
  676. if( m_bIsConnected ){
  677. char tQBuf[MAX_PATH_LEN];
  678. AAssoc *result;
  679. sprintf( tQBuf, "SELECT * FROM `system_props` WHERE `id`=1" );
  680. #ifdef DEBUG_ALL
  681. LOG(tQBuf);
  682. #endif
  683. result = m_pDatabase->Query( tQBuf );
  684. if( result!= NULL ) {
  685. if (result->size() > 0) {
  686. Assoc *cArr;
  687. Assoc::iterator it;
  688. RetVal = ( DBC_SERVA_CONFIG *) malloc(sizeof(DBC_SERVA_CONFIG));
  689. if ( RetVal ) {
  690. memset( RetVal, 0, sizeof(DBC_SERVA_CONFIG));
  691. cArr = result->at(0);
  692. it = cArr->find("encoder_limit");
  693. if( it != cArr->end() ){
  694. RetVal->encoderLimit = atoi( it->second.c_str() );
  695. };
  696. it = cArr->find("histo_days");
  697. if( it != cArr->end() ){
  698. RetVal->historyDaysLimit = atoi( it->second.c_str() );
  699. };
  700. it = cArr->find("histo_perc");
  701. if( it != cArr->end() ){
  702. RetVal->historyPreserveFreeSpacePerc = atoi( it->second.c_str() );
  703. };
  704. it = cArr->find("histo_megs");
  705. if( it != cArr->end() ){
  706. RetVal->historyPreserveFreeSpaceMB = atoi( it->second.c_str() );
  707. };
  708. it = cArr->find("histo_limit");
  709. if( it != cArr->end() ){
  710. RetVal->historyAutoDeleteLimit = atoi( it->second.c_str() );
  711. };
  712. //RetVal->lts = time(NULL);
  713. //it = cArr->find("uuid");
  714. //if( it != cArr->end() ){
  715. // strncpy( RetVal->uuid, it->second.c_str(), 64 );
  716. // RetVal->uuid[64] = (char)0;
  717. //};
  718. };
  719. };
  720. };
  721. deleteResult( result );
  722. };
  723. return RetVal;
  724. };
  725. SESSION_DATA *servaMySQLDBC::getSessionData( uint64_t id ){
  726. SESSION_DATA *RetVal = NULL;
  727. if( m_bIsConnected ){
  728. char tQBuf[MAX_PATH_LEN];
  729. AAssoc *result;
  730. sprintf( tQBuf, "SELECT * FROM `sessions` WHERE `id`=%" PRIu64, id );
  731. #ifdef DEBUG_ALL
  732. LOG(tQBuf);
  733. #endif
  734. result = m_pDatabase->Query( tQBuf );
  735. if( result!= NULL ) {
  736. if (result->size() > 0) {
  737. Assoc *cArr;
  738. Assoc::iterator it;
  739. RetVal = ( SESSION_DATA *) malloc(sizeof(SESSION_DATA));
  740. if ( RetVal ) {
  741. memset( RetVal, 0, sizeof(SESSION_DATA));
  742. RetVal->db_id = id;
  743. cArr = result->at(0);
  744. it = cArr->find("ts");
  745. if( it != cArr->end() ){
  746. RetVal->sts = atoi( it->second.c_str() );
  747. };
  748. it = cArr->find("ts_ms");
  749. if( it != cArr->end() ){
  750. RetVal->sms = atoi( it->second.c_str() );
  751. };
  752. it = cArr->find("track_id");
  753. if( it != cArr->end() ){
  754. RetVal->track_id = atoi( it->second.c_str() );
  755. };
  756. //it = cArr->find("lts");
  757. //if( it != cArr->end() ){
  758. // RetVal->lts = atoi( it->second.c_str() );
  759. //};
  760. RetVal->lts = time(NULL);
  761. it = cArr->find("uuid");
  762. if( it != cArr->end() ){
  763. strncpy( RetVal->uuid, it->second.c_str(), 64 );
  764. RetVal->uuid[64] = (char)0;
  765. };
  766. };
  767. };
  768. };
  769. deleteResult( result );
  770. };
  771. return RetVal;
  772. };
  773. uint64_t servaMySQLDBC::getSessionOlderThan( uint32_t ts, uint8_t min_lvl ){
  774. uint64_t RetVal = 0;
  775. if( m_bIsConnected ){
  776. char tQBuf[MAX_PATH_LEN];
  777. AAssoc *result;
  778. sprintf( tQBuf, "SELECT `id` FROM `sessions` WHERE `ts`<=%d AND `status`<=%d AND `final`='Y' LIMIT 1", ts, min_lvl );
  779. #ifdef DEBUG_ALL
  780. LOG(tQBuf);
  781. #endif
  782. result = m_pDatabase->Query( tQBuf );
  783. if( result!= NULL ) {
  784. if( result->size() > 0 ) {
  785. Assoc *cArr;
  786. Assoc::iterator it;
  787. cArr = result->at(0);
  788. it = cArr->find("id");
  789. if( it != cArr->end() ){
  790. RetVal = atoll( it->second.c_str() );
  791. };
  792. };
  793. };
  794. deleteResult( result );
  795. };
  796. return RetVal;
  797. };
  798. uint64_t servaMySQLDBC::getSessionOldest( uint8_t min_lvl ){
  799. uint64_t RetVal = 0;
  800. if( m_bIsConnected ){
  801. char tQBuf[MAX_PATH_LEN];
  802. AAssoc *result;
  803. sprintf( tQBuf, "SELECT `id` FROM `sessions` WHERE `status`<=%d AND `final`='Y' ORDER BY `ts` LIMIT 1", min_lvl );
  804. #ifdef DEBUG_ALL
  805. LOG(tQBuf);
  806. #endif
  807. result = m_pDatabase->Query( tQBuf );
  808. if( result!= NULL ) {
  809. if( result->size() > 0 ) {
  810. Assoc *cArr;
  811. Assoc::iterator it;
  812. cArr = result->at(0);
  813. it = cArr->find("id");
  814. if( it != cArr->end() ){
  815. RetVal = atoll( it->second.c_str() );
  816. };
  817. };
  818. };
  819. deleteResult( result );
  820. };
  821. return RetVal;
  822. };
  823. uint16_t servaMySQLDBC::getSessionTimeOut(){
  824. uint16_t RetVal = 120;
  825. if( m_bIsConnected ){
  826. char tQBuf[MAX_PATH_LEN];
  827. AAssoc *result;
  828. sprintf( tQBuf, "SELECT `session_end` FROM `system_props` WHERE `id`=1" );
  829. #ifdef DEBUG_ALL
  830. LOG(tQBuf);
  831. #endif
  832. result = m_pDatabase->Query( tQBuf );
  833. if( result!= NULL ) {
  834. if( result->size() > 0 ) {
  835. Assoc *cArr;
  836. Assoc::iterator it;
  837. cArr = result->at(0);
  838. it = cArr->find("session_end");
  839. if( it != cArr->end() ){
  840. RetVal = atoi( it->second.c_str() ) - 1;
  841. if ( RetVal ) {
  842. RetVal *=60;
  843. } else RetVal = 30;
  844. };
  845. };
  846. };
  847. deleteResult( result );
  848. };
  849. return RetVal;
  850. };
  851. uint64_t servaMySQLDBC::getSessionTrackId( uint64_t id ){
  852. uint64_t RetVal = 0;
  853. if( m_bIsConnected ){
  854. char tQBuf[MAX_PATH_LEN];
  855. AAssoc *result;
  856. sprintf( tQBuf, "SELECT `track_id` FROM `sessions` WHERE `id`=%" PRIu64, id );
  857. #ifdef DEBUG_ALL
  858. LOG(tQBuf);
  859. #endif
  860. result = m_pDatabase->Query( tQBuf );
  861. if( result!= NULL ) {
  862. if( result->size() > 0 ) {
  863. Assoc *cArr;
  864. Assoc::iterator it;
  865. cArr = result->at(0);
  866. it = cArr->find("track_id");
  867. if( it != cArr->end() ){
  868. RetVal = atoll( it->second.c_str() );
  869. };
  870. };
  871. };
  872. deleteResult( result );
  873. };
  874. return RetVal;
  875. };
  876. SCADA_TRACK_INFO *servaMySQLDBC::getTrackSCADA( uint64_t id ){
  877. SCADA_TRACK_INFO * RetVal = NULL;
  878. if( m_bIsConnected ){
  879. RetVal = (SCADA_TRACK_INFO *) malloc( sizeof(SCADA_TRACK_INFO));
  880. if ( RetVal ) {
  881. char tQBuf[MAX_PATH_LEN];
  882. AAssoc *result;
  883. memset( RetVal, 0, sizeof(SCADA_TRACK_INFO) );
  884. sprintf( tQBuf, "SELECT `platform_id`,`side` FROM `metro_tracks` WHERE `id`=%" PRIu64, id );
  885. #ifdef DEBUG_ALL
  886. LOG(tQBuf);
  887. #endif
  888. result = m_pDatabase->Query( tQBuf );
  889. if( result!= NULL ) {
  890. if( result->size() > 0 ) {
  891. Assoc *cArr;
  892. Assoc::iterator it;
  893. cArr = result->at(0);
  894. it = cArr->find("platform_id");
  895. if( it != cArr->end() ){
  896. RetVal->platform_id = atoll(it->second.c_str());
  897. };
  898. it = cArr->find("side");
  899. if( it != cArr->end() ){
  900. RetVal->side = it->second.c_str()[0];
  901. };
  902. };
  903. };
  904. deleteResult( result );
  905. }
  906. };
  907. return RetVal;
  908. };
  909. uint64_t servaMySQLDBC::getTrackIdByMojo( uint64_t id ){
  910. uint64_t RetVal = 0;
  911. if( m_bIsConnected ){
  912. char tQBuf[MAX_PATH_LEN];
  913. AAssoc *result;
  914. sprintf( tQBuf, "SELECT `track_id` FROM `metro_modules` WHERE `id`=%" PRIu64, id );
  915. #ifdef DEBUG_ALL
  916. LOG(tQBuf);
  917. #endif
  918. result = m_pDatabase->Query( tQBuf );
  919. if( result!= NULL ) {
  920. if( result->size() > 0 ) {
  921. Assoc *cArr;
  922. Assoc::iterator it;
  923. cArr = result->at(0);
  924. it = cArr->find("track_id");
  925. if( it != cArr->end() ){
  926. RetVal = atoll( it->second.c_str() );
  927. };
  928. };
  929. };
  930. deleteResult( result );
  931. };
  932. return RetVal;
  933. };
  934. uint64_t servaMySQLDBC::getUpperLRF( uint64_t id ){
  935. uint64_t RetVal = 0;
  936. if( m_bIsConnected ){
  937. char tQBuf[MAX_PATH_LEN];
  938. AAssoc *result;
  939. sprintf( tQBuf, "SELECT `id` FROM `lrf_sensors` WHERE `role`='U' AND `mojo_id`=%d", id );
  940. #ifdef DEBUG_ALL
  941. LOG(tQBuf);
  942. #endif
  943. result = m_pDatabase->Query( tQBuf );
  944. if( result!= NULL ) {
  945. if( result->size() > 0 ) {
  946. Assoc *cArr;
  947. Assoc::iterator it;
  948. cArr = result->at(0);
  949. it = cArr->find("id");
  950. if( it != cArr->end() ){
  951. RetVal = atoll( it->second.c_str() );
  952. };
  953. };
  954. };
  955. deleteResult( result );
  956. };
  957. return RetVal;
  958. };
  959. DBC_UINT64_LIST *servaMySQLDBC::listMediaQueueItems( uint8_t status ){
  960. DBC_UINT64_LIST * tVal = NULL;
  961. if( m_bIsConnected ){
  962. char tQBuf[MAX_PATH_LEN];
  963. AAssoc *result;
  964. sprintf( tQBuf, "SELECT `id` FROM `media_queue` WHERE `status`=%d", status );
  965. #ifdef DEBUG_ALL
  966. LOG(tQBuf);
  967. #endif
  968. result = m_pDatabase->Query( tQBuf );
  969. if( result!= NULL ) {
  970. if( result->size() > 0 ) {
  971. Assoc *cArr;
  972. tVal = new DBC_UINT64_LIST();
  973. if( tVal != NULL ) {
  974. Assoc::iterator it;
  975. for(int i=0;i<result->size();i++) {
  976. cArr = result->at(i);
  977. it = cArr->find("id");
  978. if( it != cArr->end() ){
  979. tVal->push_back( atoll( it->second.c_str() ));
  980. };
  981. };
  982. };
  983. };
  984. };
  985. deleteResult( result );
  986. };
  987. return tVal;
  988. };
  989. DBC_UINT64_LIST *servaMySQLDBC::listMetroModules( char status ){
  990. DBC_UINT64_LIST * tVal = NULL;
  991. if( m_bIsConnected ){
  992. char tQBuf[MAX_PATH_LEN];
  993. AAssoc *result;
  994. sprintf(tQBuf, "SELECT `id` FROM `metro_modules` WHERE `status`='%c'", status );
  995. #ifdef DEBUG_ALL
  996. LOG(tQBuf);
  997. #endif
  998. result = m_pDatabase->Query( tQBuf );
  999. if( result!= NULL ) {
  1000. if( result->size() > 0 ) {
  1001. Assoc *cArr;
  1002. tVal = new DBC_UINT64_LIST();
  1003. if( tVal != NULL ) {
  1004. Assoc::iterator it;
  1005. for(int i=0;i<result->size();i++) {
  1006. cArr = result->at(i);
  1007. it = cArr->find("id");
  1008. if( it != cArr->end() ){
  1009. tVal->push_back( atoll( it->second.c_str() ));
  1010. };
  1011. };
  1012. };
  1013. };
  1014. };
  1015. deleteResult( result );
  1016. };
  1017. return tVal;
  1018. };
  1019. DBC_UINT64_LIST *servaMySQLDBC::listModBusRTUs( uint8_t status, char mode){
  1020. DBC_UINT64_LIST * tVal = NULL;
  1021. if( m_bIsConnected ){
  1022. char tQBuf[MAX_PATH_LEN];
  1023. AAssoc *result;
  1024. if ( status ) {
  1025. sprintf(tQBuf, "SELECT `id` FROM `modbus_modules` WHERE `wm`='%c', `status`=%d", mode, status);
  1026. } else {
  1027. sprintf(tQBuf, "SELECT `id` FROM `modbus_modules` WHERE `wm`='%c'", mode);
  1028. };
  1029. #ifdef DEBUG_ALL
  1030. LOG(tQBuf);
  1031. #endif
  1032. result = m_pDatabase->Query( tQBuf );
  1033. if( result!= NULL ) {
  1034. if( result->size() > 0 ) {
  1035. Assoc *cArr;
  1036. tVal = new DBC_UINT64_LIST();
  1037. if( tVal != NULL ) {
  1038. Assoc::iterator it;
  1039. for(int i=0;i<result->size();i++) {
  1040. cArr = result->at(i);
  1041. it = cArr->find("id");
  1042. if( it != cArr->end() ){
  1043. tVal->push_back( atoll( it->second.c_str() ));
  1044. };
  1045. };
  1046. };
  1047. };
  1048. };
  1049. deleteResult( result );
  1050. };
  1051. return tVal;
  1052. };
  1053. DBC_UINT64_LIST *servaMySQLDBC::listPlatformModules( uint64_t id ){
  1054. DBC_UINT64_LIST * tVal = NULL;
  1055. if( m_bIsConnected ){
  1056. char tQBuf[MAX_PATH_LEN];
  1057. AAssoc *result;
  1058. sprintf(tQBuf, "SELECT `mod`.`id` FROM `metro_modules` `mod` LEFT JOIN `metro_tracks` `tra` ON ( `tra`.`id` = `mod`.`track_id` ) WHERE `mod`.`status`='E' AND `tra`.`platform_id`=%" PRIu64, id );
  1059. #ifdef DEBUG_ALL
  1060. LOG(tQBuf);
  1061. #endif
  1062. result = m_pDatabase->Query( tQBuf );
  1063. if( result!= NULL ) {
  1064. if( result->size() > 0 ) {
  1065. Assoc *cArr;
  1066. tVal = new DBC_UINT64_LIST();
  1067. if( tVal != NULL ) {
  1068. Assoc::iterator it;
  1069. for(int i=0;i<result->size();i++) {
  1070. cArr = result->at(i);
  1071. it = cArr->find("id");
  1072. if( it != cArr->end() ){
  1073. tVal->push_back( atoll( it->second.c_str() ));
  1074. };
  1075. };
  1076. };
  1077. };
  1078. };
  1079. deleteResult( result );
  1080. };
  1081. return tVal;
  1082. };
  1083. DBC_UINT64_LIST *servaMySQLDBC::listPlatforms( char mode ){
  1084. DBC_UINT64_LIST * tVal = NULL;
  1085. if( m_bIsConnected ){
  1086. char tQBuf[MAX_PATH_LEN];
  1087. AAssoc *result;
  1088. sprintf(tQBuf, "SELECT `id` FROM `metro_platforms` WHERE `status`='%c'", mode );
  1089. #ifdef DEBUG_ALL
  1090. LOG(tQBuf);
  1091. #endif
  1092. result = m_pDatabase->Query( tQBuf );
  1093. if( result!= NULL ) {
  1094. if( result->size() > 0 ) {
  1095. Assoc *cArr;
  1096. tVal = new DBC_UINT64_LIST();
  1097. if( tVal != NULL ) {
  1098. Assoc::iterator it;
  1099. for(int i=0;i<result->size();i++) {
  1100. cArr = result->at(i);
  1101. it = cArr->find("id");
  1102. if( it != cArr->end() ){
  1103. tVal->push_back( atoll( it->second.c_str() ));
  1104. };
  1105. };
  1106. };
  1107. };
  1108. };
  1109. deleteResult( result );
  1110. };
  1111. return tVal;
  1112. };
  1113. bool servaMySQLDBC::putIntoLog( CSTR A, CSTR B, CSTR C ){
  1114. if( m_bIsConnected ){
  1115. char tQBuf[MAX_PATH_LEN];
  1116. CSTR LL = m_pDatabase->escapeString( C );
  1117. if ( LL ) {
  1118. sprintf(tQBuf, "INSERT INTO `server_log_messages` SET lvl = '%s', `ts`='%s', `msg`='%s'", A, B, LL );
  1119. free( LL );
  1120. #ifdef DEBUG_ALL
  1121. LOG(tQBuf);
  1122. #endif
  1123. m_pDatabase->SilentQuery( tQBuf );
  1124. return true;
  1125. };
  1126. };
  1127. return false;
  1128. };
  1129. uint64_t servaMySQLDBC::registerMojo( CSTR A, CSTR B ){
  1130. uint64_t RetVal = 0;
  1131. char tQBuf[MAX_PATH_LEN];
  1132. if( m_bIsConnected ){
  1133. AAssoc *result;
  1134. sprintf( tQBuf, "SELECT `id` FROM `metro_modules` WHERE `IP4`='%s' AND `identity`='%s'", A, B );
  1135. #ifdef DEBUG_ALL
  1136. LOG(tQBuf);
  1137. #endif
  1138. result = m_pDatabase->Query( tQBuf );
  1139. if( result!= NULL ) {
  1140. if( result->size() > 0 ) {
  1141. Assoc *cArr;
  1142. Assoc::iterator it;
  1143. cArr = result->at(0);
  1144. it = cArr->find("id");
  1145. if( it != cArr->end() ){
  1146. RetVal = atoll( it->second.c_str() );
  1147. };
  1148. };
  1149. };
  1150. deleteResult( result );
  1151. };
  1152. //if ( RetVal ) {
  1153. // sprintf( tQBuf, "INSERT INTO `mem_online_cloud` SET `id` FROM `metro_modules` WHERE `IP4`='%s' AND `identity`='%s'", A, B );
  1154. // m_pDatabase->SilentQuery( tQBuf );
  1155. //};
  1156. return RetVal;
  1157. };
  1158. bool servaMySQLDBC::registerServer( uint32_t SiteID, CSTR identity, int PID, uint32_t *ServID, uint32_t *ServNode ){
  1159. if(m_bIsConnected){
  1160. //m_nSiteID = SiteID;
  1161. char tQBuf[MAX_PATH_LEN];
  1162. sprintf( tQBuf, "INSERT INTO servers SET `site_id`=%d, `identity`='%s', `version_string`='%s', `online`=1, `ts`=UNIX_TIMESTAMP(now()), pid=%d ON DUPLICATE KEY UPDATE `version_string`='%s', `ts`=UNIX_TIMESTAMP(now()), `online`=1, pid=%d",
  1163. SiteID, identity, _BUILD_STRING_, PID, _BUILD_STRING_, PID );
  1164. #ifdef DEBUG_ALL
  1165. LOG(tQBuf);
  1166. #endif
  1167. m_pDatabase->SilentQuery( tQBuf );
  1168. //*ServID = getServerID( identity );
  1169. //m_nServerID = *ServID;
  1170. if( *ServID ) {
  1171. //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, *ServID );
  1172. #ifdef DEBUG_ALL
  1173. LOG(tQBuf);
  1174. #endif
  1175. *ServNode = ( uint32_t ) m_pDatabase->QueryID( tQBuf );
  1176. //if( *ServNode == 0 ){
  1177. // *ServNode = getServerNode( *ServID );
  1178. //};
  1179. //m_nServerNodeID = *ServNode;
  1180. // Clenup Nodes and services ...
  1181. sprintf(tQBuf,"UPDATE nodes SET `online`=0 WHERE `server_id`=%d ", *ServID );
  1182. #ifdef DEBUG_ALL
  1183. LOG(tQBuf);
  1184. #endif
  1185. m_pDatabase->SilentQuery( tQBuf );
  1186. sprintf(tQBuf,"UPDATE cameras SET `online`=0 WHERE `site_id`=%d ", SiteID );
  1187. #ifdef DEBUG_ALL
  1188. LOG(tQBuf);
  1189. #endif
  1190. m_pDatabase->SilentQuery( tQBuf );
  1191. sprintf(tQBuf,"UPDATE media_streams SET `valid`=0 WHERE `site_id`=%d ", SiteID );
  1192. #ifdef DEBUG_ALL
  1193. LOG(tQBuf);
  1194. #endif
  1195. m_pDatabase->SilentQuery( tQBuf );
  1196. sprintf(tQBuf,"UPDATE media_server_streams SET `valid`=0, `online`=0 WHERE `site_id`=%d ", SiteID );
  1197. #ifdef DEBUG_ALL
  1198. LOG(tQBuf);
  1199. #endif
  1200. m_pDatabase->SilentQuery( tQBuf );
  1201. //cleanResources( tServerNodeID );
  1202. return setNodeOnline( 0, 1 );//m_nServerNodeID );
  1203. }
  1204. };
  1205. return false;
  1206. };
  1207. uint32_t servaMySQLDBC::registerVideoTransfer( uint32_t srcNode, CSTR uuid, uint32_t dataSize, CSTR fmt, uint32_t ts ){
  1208. if(m_bIsConnected){
  1209. char tQBuf[MAX_PATH_LEN];
  1210. sprintf( tQBuf, "INSERT INTO `media_queue` SET `src`=%d, `uuid`='%s', `size`=%d, `fmt`='%s', `ts`=%d",
  1211. srcNode, uuid, dataSize, fmt, ts );
  1212. #ifdef DEBUG_ALL
  1213. LOG(tQBuf);
  1214. #endif
  1215. return ( uint32_t ) m_pDatabase->QueryID( tQBuf );
  1216. };
  1217. return 0;
  1218. };
  1219. bool servaMySQLDBC::removeRemoteMediaInfo( uint64_t id ){
  1220. if( m_bIsConnected ) {
  1221. char tQBuf[MAX_PATH_LEN];
  1222. sprintf( tQBuf, "DELETE FROM `media_queue` WHERE `id`=%" PRIu64, id );
  1223. #ifdef DEBUG_ALL
  1224. LOG(tQBuf);
  1225. #endif
  1226. m_pDatabase->SilentQuery( tQBuf );
  1227. return true;
  1228. };
  1229. return false;
  1230. };
  1231. bool servaMySQLDBC::removeWebCmd( uint64_t id ){
  1232. if( m_bIsConnected ) {
  1233. char tQBuf[MAX_PATH_LEN];
  1234. sprintf( tQBuf, "DELETE FROM `mem_web_queue` WHERE `id`=%" PRIu64, id );
  1235. #ifdef DEBUG_ALL
  1236. LOG(tQBuf);
  1237. #endif
  1238. m_pDatabase->SilentQuery( tQBuf );
  1239. return true;
  1240. };
  1241. return false;
  1242. };
  1243. bool servaMySQLDBC::unregisterServer(){
  1244. if( setNodeOffline( 0 ) ) { //m_nServerNodeID ) ){
  1245. char tQBuf[CTEXT];
  1246. sprintf(tQBuf,"UPDATE servers SET `online`=0, `ts`=UNIX_TIMESTAMP(now()) WHERE `id`=%d", 1 );//m_nServerID );
  1247. #ifdef DEBUG_ALL
  1248. LOG(tQBuf);
  1249. #endif
  1250. m_pDatabase->SilentQuery( tQBuf );
  1251. return true;
  1252. };
  1253. return false;
  1254. };
  1255. bool servaMySQLDBC::setNodeOnline( uint32_t NodeID, uint8_t status ){
  1256. if(m_bIsConnected){
  1257. char tQBuf[CTEXT];
  1258. if( NodeID ) {
  1259. sprintf(tQBuf,"UPDATE nodes SET `online`=%d WHERE `id`=%d", status, NodeID );
  1260. #ifdef DEBUG_ALL
  1261. LOG(tQBuf);
  1262. #endif
  1263. m_pDatabase->SilentQuery( tQBuf );
  1264. sprintf(tQBuf,"UPDATE `resources` SET `active`=1 WHERE `node_id`=%d", NodeID );
  1265. #ifdef DEBUG_ALL
  1266. LOG(tQBuf);
  1267. #endif
  1268. m_pDatabase->SilentQuery( tQBuf );
  1269. return true;
  1270. };
  1271. };
  1272. return false;
  1273. };
  1274. bool servaMySQLDBC::setNodeOffline( uint32_t NodeID ){
  1275. if(m_bIsConnected){
  1276. char tQBuf[CTEXT];
  1277. if( NodeID ) {
  1278. sprintf(tQBuf,"UPDATE nodes SET `online`=0 WHERE `id` = %d", NodeID );
  1279. #ifdef DEBUG_ALL
  1280. LOG(tQBuf);
  1281. #endif
  1282. m_pDatabase->SilentQuery( tQBuf );
  1283. sprintf(tQBuf,"UPDATE `resources` SET `active`=0 WHERE `node_id` = %d", NodeID );
  1284. #ifdef DEBUG_ALL
  1285. LOG(tQBuf);
  1286. #endif
  1287. m_pDatabase->SilentQuery( tQBuf );
  1288. return true;
  1289. };
  1290. };
  1291. return false;
  1292. };
  1293. bool servaMySQLDBC::sessionClose( uint64_t session_id ){
  1294. if( m_bIsConnected ){
  1295. char tQBuf[CTEXT];
  1296. sprintf(tQBuf, "UPDATE `sessions` SET `lts`=UNIX_TIMESTAMP(now()), `final`='Y' WHERE `id`=%" PRIu64, session_id );
  1297. #ifdef DEBUG_ALL
  1298. LOG(tQBuf);
  1299. #endif
  1300. m_pDatabase->SilentQuery(tQBuf);
  1301. return true;
  1302. };
  1303. return false;
  1304. };
  1305. uint64_t servaMySQLDBC::sessionCreate( uint64_t track_id, uint32_t ts, uint16_t tsms, CSTR uuid, char src ){
  1306. if( m_bIsConnected ){
  1307. char tQBuf[CTEXT];
  1308. sprintf( tQBuf, "INSERT INTO `sessions` SET `ts`=%d, `ts_ms`=%d, `lts`=UNIX_TIMESTAMP(now()), `track_id`=%" PRIu64 ", `uuid`='%s', `src`='%c'",
  1309. ts, tsms, track_id, uuid, src );
  1310. #ifdef DEBUG_ALL
  1311. LOG(tQBuf);
  1312. #endif
  1313. return m_pDatabase->QueryID(tQBuf);
  1314. };
  1315. return 0;
  1316. };
  1317. bool servaMySQLDBC::sessionStatAddEvt( uint64_t session_id ){
  1318. if( m_bIsConnected ){
  1319. char tQBuf[CTEXT];
  1320. sprintf(tQBuf, "UPDATE `sessions` SET `evt_cnt`=`evt_cnt`+1 WHERE `id`=%" PRIu64, session_id );
  1321. #ifdef DEBUG_ALL
  1322. LOG(tQBuf);
  1323. #endif
  1324. m_pDatabase->SilentQuery( tQBuf );
  1325. return true;
  1326. };
  1327. return false;
  1328. };
  1329. bool servaMySQLDBC::sessionStatAddVid( uint64_t session_id ){
  1330. if( m_bIsConnected ){
  1331. char tQBuf[CTEXT];
  1332. sprintf(tQBuf, "UPDATE `sessions` SET `vid_cnt`=`vid_cnt`+1 WHERE `id`=%" PRIu64, session_id );
  1333. #ifdef DEBUG_ALL
  1334. LOG(tQBuf);
  1335. #endif
  1336. m_pDatabase->SilentQuery( tQBuf );
  1337. return true;
  1338. };
  1339. return false;
  1340. };
  1341. bool servaMySQLDBC::setCloudStatus( uint8_t Obj, uint64_t id, uint32_t status, CSTR sid ){
  1342. if( m_bIsConnected ){
  1343. char tQBuf[CTEXT];
  1344. uint32_t CTS = time( NULL );
  1345. if( sid ) {
  1346. sprintf(tQBuf, "INSERT INTO `mem_online_cloud` SET `object_id`=%" PRIu64 ", `object_type`=%d, `status`=%d, `ts`=%d, `SID`='%s' ON DUPLICATE KEY UPDATE `status`=%d, `ts`=%d, `SID`='%s'",
  1347. id, Obj, status, CTS, sid, status, CTS, sid );
  1348. } else {
  1349. sprintf(tQBuf, "INSERT INTO `mem_online_cloud` SET `object_id`=%" PRIu64 ", `object_type`=%d, `status`=%d, `ts`=%d ON DUPLICATE KEY UPDATE `status`=%d, `ts`=%d",
  1350. id, Obj, status, CTS, status, CTS );
  1351. };
  1352. #ifdef DEBUG_ALL
  1353. LOG(tQBuf);
  1354. #endif
  1355. m_pDatabase->SilentQuery( tQBuf );
  1356. return true;
  1357. };
  1358. return false;
  1359. };
  1360. bool servaMySQLDBC::updateEncodeFormat( uint64_t id, CSTR ext ){
  1361. if( m_bIsConnected ) {
  1362. char tQBuf[1096];
  1363. sprintf(tQBuf, "UPDATE `media_queue` SET `fmt`='%s' WHERE `id`=%" PRIu64, ext, id );
  1364. #ifdef DEBUG_ALL
  1365. LOG(tQBuf);
  1366. #endif
  1367. m_pDatabase->SilentQuery( tQBuf );
  1368. return true;
  1369. };
  1370. return false;
  1371. };
  1372. bool servaMySQLDBC::updateEncodeStatus( uint64_t dbid, uint8_t status, uint8_t perc ){
  1373. if( m_bIsConnected ) {
  1374. char tQBuf[1096];
  1375. sprintf(tQBuf, "UPDATE `media_queue` SET `status`=%d, `process`=%d WHERE `id`=%" PRIu64,
  1376. status, perc, dbid
  1377. );
  1378. #ifdef DEBUG_ALL
  1379. LOG(tQBuf);
  1380. #endif
  1381. m_pDatabase->SilentQuery( tQBuf );
  1382. return true;
  1383. };
  1384. return false;
  1385. };
  1386. bool servaMySQLDBC::updateModBusRTU( uint64_t dbid, uint8_t status, uint8_t inputs, uint8_t outputs ) {
  1387. if( m_bIsConnected ) {
  1388. uint16_t values = inputs;
  1389. values = (values << 8 ) | outputs;
  1390. char tQBuf[MAX_PATH_LEN];
  1391. sprintf( tQBuf, "UPDATE `modbus_modules` SET `status`=%d, `values`=%d WHERE `id`=%" PRIu64, status, values, dbid );
  1392. #ifdef DEBUG_ALL
  1393. LOG(tQBuf);
  1394. #endif
  1395. m_pDatabase->SilentQuery( tQBuf );
  1396. return true;
  1397. };
  1398. return false;
  1399. };
  1400. bool servaMySQLDBC::updateModuleData( uint64_t DBID, uint32_t UPPER_ID, uint32_t BOTTOM_ID, uint32_t CAM_ID, uint32_t CAM_STREAM_ID, CSTR vstr, CSTR lstr ){
  1401. if( m_bIsConnected ) {
  1402. char tQBuf[MAX_PATH_LEN];
  1403. sprintf( tQBuf, "UPDATE `metro_modules` SET `cam_stream`=%d, `top_id`=%d, `bottom_id`=%d, `cam_id`=%d, `tls_version`='%s', `lls_version`='%s' WHERE `id`=%" PRIu64, CAM_STREAM_ID, UPPER_ID, BOTTOM_ID, CAM_ID, vstr, lstr, DBID );
  1404. #ifdef DEBUG_ALL
  1405. LOG(tQBuf);
  1406. #endif
  1407. m_pDatabase->SilentQuery( tQBuf );
  1408. return true;
  1409. };
  1410. return false;
  1411. };
  1412. bool servaMySQLDBC::setServerStatValue( SERVER_STAT_ENUM ptp, uint64_t value ){
  1413. if( m_bIsConnected ) {
  1414. char tQBuf[MAX_PATH_LEN];
  1415. sprintf( tQBuf, "INSERT INTO `mem_server_stats` SET `prop_enumerating`=%d, `prop_type`=1, `prop_value`='%" PRIu64 "' ON DUPLICATE KEY UPDATE `prop_value`='%" PRIu64 "'", ptp, value, value );
  1416. #ifdef DEBUG_ALL
  1417. LOG(tQBuf);
  1418. #endif
  1419. m_pDatabase->SilentQuery( tQBuf );
  1420. return true;
  1421. };
  1422. return false;
  1423. };
  1424. bool servaMySQLDBC::setServerStatValue( SERVER_STAT_ENUM ptp, int64_t value ){
  1425. if( m_bIsConnected ) {
  1426. char tQBuf[MAX_PATH_LEN];
  1427. sprintf( tQBuf, "INSERT INTO `mem_server_stats` SET `prop_enumerating`=%d, `prop_type`=1, `prop_value`='%" PRIi64 "' ON DUPLICATE KEY UPDATE `prop_value`='%" PRIi64 "'", ptp, value, value );
  1428. #ifdef DEBUG_ALL
  1429. LOG(tQBuf);
  1430. #endif
  1431. m_pDatabase->SilentQuery( tQBuf );
  1432. return true;
  1433. };
  1434. return false;
  1435. };
  1436. bool servaMySQLDBC::setServerStatValue( SERVER_STAT_ENUM ptp, uint32_t value ){
  1437. if( m_bIsConnected ) {
  1438. char tQBuf[MAX_PATH_LEN];
  1439. sprintf( tQBuf, "INSERT INTO `mem_server_stats` SET `prop_enumerating`=%d, `prop_type`=2, `prop_value`='%d' ON DUPLICATE KEY UPDATE `prop_value`='%d'", ptp, value, value );
  1440. #ifdef DEBUG_ALL
  1441. LOG(tQBuf);
  1442. #endif
  1443. m_pDatabase->SilentQuery( tQBuf );
  1444. return true;
  1445. };
  1446. return false;
  1447. };
  1448. bool servaMySQLDBC::setServerStatValue( SERVER_STAT_ENUM ptp, int32_t value ){
  1449. if( m_bIsConnected ) {
  1450. char tQBuf[MAX_PATH_LEN];
  1451. sprintf( tQBuf, "INSERT INTO `mem_server_stats` SET `prop_enumerating`=%d, `prop_type`=2, `prop_value`='%d' ON DUPLICATE KEY UPDATE `prop_value`='%d'", ptp, value, value );
  1452. #ifdef DEBUG_ALL
  1453. LOG(tQBuf);
  1454. #endif
  1455. m_pDatabase->SilentQuery( tQBuf );
  1456. return true;
  1457. };
  1458. return false;
  1459. };
  1460. bool servaMySQLDBC::setServerStatValue( SERVER_STAT_ENUM ptp, float value ){
  1461. if( m_bIsConnected ) {
  1462. char tQBuf[MAX_PATH_LEN];
  1463. sprintf( tQBuf, "INSERT INTO `mem_server_stats` SET `prop_enumerating`=%d, `prop_type`=3, `prop_value`='%.5f' ON DUPLICATE KEY UPDATE `prop_value`='%.5f'", ptp, value, value );
  1464. #ifdef DEBUG_ALL
  1465. LOG(tQBuf);
  1466. #endif
  1467. m_pDatabase->SilentQuery( tQBuf );
  1468. return true;
  1469. };
  1470. return false;
  1471. };
  1472. bool servaMySQLDBC::setServerStatValue( SERVER_STAT_ENUM ptp, CSTR value ){
  1473. if( m_bIsConnected ) {
  1474. char tQBuf[MAX_PATH_LEN];
  1475. sprintf( tQBuf, "INSERT INTO `mem_server_stats` SET `prop_enumerating`=%d, `prop_type`=4, `prop_value`='%s' ON DUPLICATE KEY UPDATE `prop_value`='%s'", ptp, value, value );
  1476. #ifdef DEBUG_ALL
  1477. LOG(tQBuf);
  1478. #endif
  1479. m_pDatabase->SilentQuery( tQBuf );
  1480. return true;
  1481. };
  1482. return false;
  1483. };
  1484. bool servaMySQLDBC::setSystemProp( CSTR ptr, CSTR ptt ){
  1485. if( m_bIsConnected ) {
  1486. char tQBuf[MAX_PATH_LEN];
  1487. sprintf( tQBuf, "UPDATE `system_props` SET `%s`='%s' WHERE `id`=1", ptr, ptt );
  1488. #ifdef DEBUG_ALL
  1489. LOG(tQBuf);
  1490. #endif
  1491. m_pDatabase->SilentQuery( tQBuf );
  1492. return true;
  1493. };
  1494. return false;
  1495. };
  1496. bool servaMySQLDBC::updateServerUtilisation( DBC_SYS_LOAD_INFO *ptr ){
  1497. bool rval = true;
  1498. if ( ptr == NULL ) return false;
  1499. if ( rval ) rval = setServerStatValue( SERVER_LTS, ptr->C_TS );
  1500. if ( rval ) rval = setServerStatValue( SERVER_CPU_1, ptr->cpu1 );
  1501. if ( rval ) rval = setServerStatValue( SERVER_CPU_5, ptr->cpu5 );
  1502. if ( rval ) rval = setServerStatValue( SERVER_CPU_15, ptr->cpu15 );
  1503. if ( rval ) rval = setServerStatValue( SERVER_MEM_T, ptr->T_MEM );
  1504. if ( rval ) rval = setServerStatValue( SERVER_MEM_C, ptr->C_MEM );
  1505. if ( rval ) rval = setServerStatValue( SERVER_MEM, ptr->mem );
  1506. if ( rval ) rval = setServerStatValue( SERVER_DISK_T, ptr->T_DISK );
  1507. if ( rval ) rval = setServerStatValue( SERVER_DISK_C, ptr->C_DISK );
  1508. if ( rval ) rval = setServerStatValue( SERVER_DISK, ptr->disk );
  1509. if ( rval ) rval = setServerStatValue( SERVER_SYS_TEMP, ptr->temperature );
  1510. if ( rval ) rval = setServerStatValue( SERVER_CPU_CORES, ptr->CPU_CORES );
  1511. return rval;
  1512. };
  1513. bool servaMySQLDBC::updateSessionStatus( uint64_t id, uint8_t status ){
  1514. if( m_bIsConnected ) {
  1515. char tQBuf[MAX_PATH_LEN];
  1516. sprintf( tQBuf, "UPDATE `sessions` SET `status`=%d, `lts`=UNIX_TIMESTAMP(now()) WHERE `id`=%" PRIu64, status, id );
  1517. #ifdef DEBUG_ALL
  1518. LOG(tQBuf);
  1519. #endif
  1520. m_pDatabase->SilentQuery( tQBuf );
  1521. return true;
  1522. };
  1523. return false;
  1524. };
  1525. bool servaMySQLDBC::updateWebCmdStatus( uint64_t id, uint8_t status ){
  1526. if( m_bIsConnected ) {
  1527. char tQBuf[MAX_PATH_LEN];
  1528. sprintf( tQBuf, "UPDATE `mem_web_queue` SET `status`=%d WHERE `id`=%" PRIu64, status, id );
  1529. #ifdef DEBUG_ALL
  1530. LOG(tQBuf);
  1531. #endif
  1532. m_pDatabase->SilentQuery( tQBuf );
  1533. return true;
  1534. };
  1535. return false;
  1536. };
  1537. #undef LOG
  1538. #undef LOG_ERROR