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.

803 lines
16 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "deviceNodeFactory.h"
  2. #ifdef USE_MYSQL
  3. #include "MySQL_dataBinder.h"
  4. #else
  5. #include "SQLite_dataBinder.h"
  6. #endif
  7. #include "deviceNode2D.h"
  8. #include "deviceNode3D.h"
  9. #include "deviceNodeEthernet2Serial.h"
  10. #include "deviceNodePresetCamControl.h"
  11. #include "deviceNodePTZCamControl.h"
  12. #include "deviceNodeStaticCamControl.h"
  13. #ifdef MEM_DEBUG
  14. #include "../alg/generic/heapDebug.h"
  15. #endif
  16. #define LOG(X) m_pLog->Log("NFAC", this, X)
  17. #define LOG_ERROR(X) m_pLog->Log("NFAC", this, _LOG_ERROR, X)
  18. deviceNodeFactory * deviceNodeFactory::_instance = NULL;
  19. /**
  20. * Returns the single instance of the object.
  21. */
  22. deviceNodeFactory * deviceNodeFactory::getInstance()
  23. {
  24. if (NULL == _instance)
  25. {
  26. _instance = new deviceNodeFactory();
  27. };
  28. return _instance;
  29. }
  30. deviceNodeFactory::deviceNodeFactory() :
  31. basicThread()
  32. {
  33. m_pLog = basicLogCollection::getInstance();
  34. #ifdef USE_MYSQL
  35. m_pDBC = mysqlDBC::getInstance();
  36. #else
  37. m_pDBC = sqliteDBC::getInstance();
  38. #endif
  39. m_nPendingInitCounter = 0;
  40. init();
  41. }
  42. deviceNodeFactory::~deviceNodeFactory()
  43. {
  44. waitThreadEnd(true);
  45. unloadNodes();
  46. _instance = NULL;
  47. }
  48. bool deviceNodeFactory::unloadNodes(void)
  49. {
  50. if (m_pDBC != NULL)
  51. {
  52. if (m_vDeviceNodes.size() > 0)
  53. {
  54. for (vectorDeviceNodes::iterator index = m_vDeviceNodes.begin(); index < m_vDeviceNodes.end(); index++)
  55. {
  56. LOG(" Unload Node... BEGIN");
  57. switch ((*index)->getNodeType())
  58. {
  59. case ARGUS_ANALOG_STATIC_CAMERA:
  60. LOG(" Static Analog Cam");
  61. delete((deviceNodeStaticCamControl *) (*index));
  62. break;
  63. case ARGUS_ANALOG_PTZ_CAMERA:
  64. LOG(" PTZ Analog Cam");
  65. delete((deviceNodePTZCamControl *) (*index));
  66. break;
  67. case ARGUS_IP_PTZ_CAMERA:
  68. {
  69. LOG(" PTZ IP Cam");
  70. delete((deviceNodePTZCamControl *) (*index));
  71. break;
  72. };
  73. case ARGUS_IP_STATIC_CAMERA:
  74. {
  75. LOG(" Static IP Cam");
  76. delete((deviceNodeStaticCamControl *) (*index));
  77. break;
  78. };
  79. case ARGUS_IP_PRESET_CAMERA:
  80. {
  81. LOG(" Preset IP Cam");
  82. delete((deviceNodePresetCamControl *) (*index));
  83. break;
  84. };
  85. case ARGUS_ANALOG_PRESET_CAMERA:
  86. {
  87. LOG(" Preset Analog Cam");
  88. // delete( (deviceNodeStaticCamControl*) (*index) );
  89. break;
  90. };
  91. case ARGUS_IP_UART_GATEWAY:
  92. {
  93. LOG(" UART Gateway");
  94. delete((deviceETH2UART *) (*index));
  95. break;
  96. };
  97. case ARGUS_ALS_SENSOR:
  98. case ARGUS_PLS_200_SENSOR:
  99. case ARGUS_PLS_360_SENSOR:
  100. case ARGUS_LFS_SENSOR:
  101. {
  102. LOG(" 2D LRF");
  103. delete((device2DSensor *) (*index));
  104. LOG(" 2D LRF done");
  105. break;
  106. };
  107. case ARGUS_3D_SENSOR:
  108. {
  109. LOG(" 3D LRF");
  110. delete((device3DSensor *) (*index));
  111. break;
  112. };
  113. default: break;
  114. };
  115. LOG(" Unload Node... DONE!");
  116. };
  117. m_vDeviceNodes.clear();
  118. m_mDeviceNodesIDS.clear();
  119. };
  120. };
  121. return true;
  122. }
  123. /*
  124. bool deviceNodeFactory::loadNodes( uint32_t SiteID ){
  125. LOG("Node Loader");
  126. if(m_pDBC == NULL) return false;
  127. m_nSiteID = SiteID;
  128. DBC_INT_LIST *tList = m_pDBC->listNodes( SiteID );
  129. if( tList != NULL ) {
  130. for( DBC_INT_LIST::iterator idx = tList->begin(); idx < tList->end(); idx++ ){
  131. uint32_t id = *idx;
  132. char msg[64];
  133. sprintf( msg, "Creating Node[%d]", id );
  134. createNode( id );
  135. };
  136. tList->clear();
  137. delete( tList );
  138. return true;
  139. };
  140. return false;
  141. };
  142. */
  143. bool deviceNodeFactory::loadNodes()
  144. {
  145. if (m_pDBC == NULL)
  146. {
  147. return false;
  148. }
  149. DBC_INT_LIST * tList = m_pDBC->listNodes(false);
  150. m_nPendingInitCounter = 0;
  151. if (tList != NULL)
  152. {
  153. for (DBC_INT_LIST::iterator idx = tList->begin(); idx < tList->end(); idx++)
  154. {
  155. createNode(*idx);
  156. }
  157. tList->clear();
  158. delete(tList);
  159. }
  160. #ifdef DEBUG
  161. else
  162. {
  163. LOG("No Nodes Defined");
  164. }
  165. #endif
  166. return true;
  167. }
  168. bool deviceNodeFactory::reloadNodes()
  169. {
  170. if (! unloadNodes())
  171. {
  172. return false;
  173. }
  174. return loadNodes();
  175. }
  176. bool deviceNodeFactory::reloadNode(uint32_t NodeID)
  177. {
  178. deleteNode(NodeID);
  179. deviceNode * tNode = createNode(NodeID);
  180. if (tNode)
  181. {
  182. return true;
  183. };
  184. return false;
  185. }
  186. deviceNode * deviceNodeFactory::createNode(uint32_t id)
  187. {
  188. deviceNode * tVal = NULL;
  189. if (m_pDBC != NULL)
  190. {
  191. DBC_NODE_DATA * tData = NULL;
  192. tData = m_pDBC->getNodeData(id);
  193. if (tData != NULL)
  194. {
  195. #ifdef DEBUG
  196. char tB[256];
  197. sprintf(tB, "Node id: %d AUX id: %d", id, tData->aux_id);
  198. LOG(tB);
  199. sprintf(tB, "Node type: %d", tData->type);
  200. LOG(tB);
  201. sprintf(tB, "Node Name: %s", tData->name);
  202. LOG(tB);
  203. #endif
  204. switch (tData->type)
  205. {
  206. case ARGUS_ANALOG_STATIC_CAMERA:
  207. {
  208. #ifdef DEBUG
  209. LOG("Creating Analog Static Camera");
  210. #endif
  211. deviceNodeStaticCamControl * tCamera;
  212. tCamera = new deviceNodeStaticCamControl(id);
  213. if (tCamera)
  214. {
  215. LOG("Starting Service");
  216. tCamera->startService();
  217. tVal = (deviceNode *) tCamera;
  218. LOG("Success");
  219. };
  220. break;
  221. };
  222. case ARGUS_ANALOG_PTZ_CAMERA:
  223. {
  224. #ifdef DEBUG
  225. LOG("Creating Analog PTZ Camera");
  226. #endif
  227. deviceNodePTZCamControl * tCamera;
  228. tCamera = new deviceNodePTZCamControl(id);
  229. if (tCamera)
  230. {
  231. LOG("Starting Service");
  232. tCamera->startService();
  233. tVal = (deviceNode *) tCamera;
  234. LOG("Success");
  235. };
  236. break;
  237. };
  238. case ARGUS_IP_STATIC_CAMERA:
  239. {
  240. #ifdef DEBUG
  241. LOG("Creating IP Static Camera");
  242. #endif
  243. deviceNodeStaticCamControl * tCamera;
  244. tCamera = new deviceNodeStaticCamControl(id);
  245. if (tCamera)
  246. {
  247. #ifdef DEBUG
  248. LOG("Starting Service");
  249. #endif
  250. if (tCamera->startService())
  251. {
  252. tVal = (deviceNode *) tCamera;
  253. #ifdef DEBUG
  254. LOG("Success");
  255. #endif
  256. }
  257. else
  258. {
  259. #ifdef DEBUG
  260. LOG_ERROR("Error Sterting Service");
  261. #endif
  262. delete(tCamera);
  263. };
  264. };
  265. break;
  266. };
  267. case ARGUS_IP_PTZ_CAMERA:
  268. {
  269. #ifdef DEBUG
  270. LOG("Creating IP PTZ Camera");
  271. #endif
  272. deviceNodePTZCamControl * tCamera;
  273. tCamera = new deviceNodePTZCamControl(id);
  274. if (tCamera)
  275. {
  276. #ifdef DEBUG
  277. LOG("Starting Service");
  278. #endif
  279. if (tCamera->startService())
  280. {
  281. tVal = (deviceNode *) tCamera;
  282. #ifdef DEBUG
  283. LOG("Success");
  284. #endif
  285. }
  286. else
  287. {
  288. #ifdef DEBUG
  289. LOG_ERROR("Error Starting Service!");
  290. #endif
  291. delete(tCamera);
  292. };
  293. };
  294. break;
  295. };
  296. case ARGUS_IP_PRESET_CAMERA:
  297. {
  298. #ifdef DEBUG
  299. LOG("Creating IP Preset Camera");
  300. #endif
  301. deviceNodePresetCamControl * tCamera;
  302. tCamera = new deviceNodePresetCamControl(id);
  303. if (tCamera)
  304. {
  305. #ifdef DEBUG
  306. LOG("Starting Service");
  307. #endif
  308. if (tCamera->startService())
  309. {
  310. tVal = (deviceNode *) tCamera;
  311. #ifdef DEBUG
  312. LOG("Success");
  313. #endif
  314. }
  315. else
  316. {
  317. #ifdef DEBUG
  318. LOG_ERROR("Error Starting Service!");
  319. #endif
  320. delete(tCamera);
  321. };
  322. };
  323. break;
  324. };
  325. case ARGUS_IP_UART_GATEWAY:
  326. {
  327. #ifdef DEBUG
  328. LOG("Creating Ethernet to UART Gateway");
  329. #endif
  330. deviceETH2UART * tGW;
  331. tGW = new deviceETH2UART(id);
  332. if (tGW)
  333. {
  334. if (tGW->create())
  335. {
  336. tVal = (deviceNode *) tGW;
  337. }
  338. else
  339. {
  340. delete(tGW);
  341. };
  342. };
  343. break;
  344. };
  345. case ARGUS_IP_VIDEO_SERVER:
  346. #ifdef DEBUG
  347. LOG("Creating Network Video Encoder");
  348. #endif
  349. break;
  350. case ARGUS_LFS_SENSOR:
  351. case ARGUS_ALS_SENSOR:
  352. case ARGUS_PLS_200_SENSOR:
  353. case ARGUS_PLS_360_SENSOR:
  354. {
  355. #ifdef DEBUG
  356. LOG("Creating 2D Sensor");
  357. #endif
  358. device2DSensor * tSensor;
  359. tSensor = new device2DSensor(id);
  360. if (tSensor)
  361. {
  362. #ifdef DEBUG
  363. LOG("Starting Service");
  364. #endif
  365. if (tSensor->startService())
  366. {
  367. #ifdef DEBUG
  368. LOG("Success");
  369. #endif
  370. tVal = (deviceNode *) tSensor;
  371. }
  372. else
  373. {
  374. delete(tSensor);
  375. };
  376. };
  377. break;
  378. };
  379. case ARGUS_3D_SENSOR:
  380. {
  381. #ifdef DEBUG
  382. LOG("Creating 3D Sensor");
  383. #endif
  384. device3DSensor * t3DRadar;
  385. t3DRadar = new device3DSensor(id);
  386. if (t3DRadar)
  387. {
  388. LOG("Success");
  389. t3DRadar->startService();
  390. tVal = (deviceNode *) t3DRadar;
  391. };
  392. break;
  393. };
  394. case ARGUS_JAMER:
  395. #ifdef DEBUG
  396. LOG("Creating RF Jamer");
  397. #endif
  398. break;
  399. case ARGUS_NET_PLS_200:
  400. #ifdef DEBUG
  401. LOG("Creating Network-PLS200 Sensor");
  402. #endif
  403. break;
  404. case ARGUS_DRONE_CONTROL:
  405. #ifdef DEBUG
  406. LOG("Creating Drone Controll");
  407. #endif
  408. break;
  409. };
  410. free(tData);
  411. };
  412. };
  413. if (tVal != NULL)
  414. {
  415. #ifdef DEBUG
  416. char tB[64];
  417. sprintf(tB, "Node PTR: %p", (void *)tVal);
  418. LOG(tB);
  419. #endif
  420. m_vDeviceNodes.push_back(tVal);
  421. m_mDeviceNodesIDS[id] = tVal;
  422. }
  423. else
  424. {
  425. #ifdef DEBUG_EXTRA
  426. LOG("Node Creation Failure -> Push to Pending Mode!");
  427. #endif
  428. m_nPendingNodes.push_back(id);
  429. m_nPendingInitCounter = FACTORY_NODE_INIT_PENDING_COUNT;
  430. };
  431. return tVal;
  432. }
  433. void deviceNodeFactory::deleteNode(deviceNode * ptr)
  434. {
  435. if (ptr == NULL)
  436. {
  437. return;
  438. }
  439. // if some troubles move this to an end of the function!
  440. for (vectorDeviceNodes::iterator index = m_vDeviceNodes.begin(); index != m_vDeviceNodes.end(); index++)
  441. {
  442. if ((*index) == ptr)
  443. {
  444. m_mDeviceNodesIDS.erase(ptr->getNodeID());
  445. m_vDeviceNodes.erase(index);
  446. break;
  447. };
  448. };
  449. switch (ptr->getNodeType())
  450. {
  451. case ARGUS_ANALOG_STATIC_CAMERA:
  452. #ifdef DEBUG
  453. LOG("Destroying Analog Static Camera");
  454. #endif
  455. break;
  456. case ARGUS_ANALOG_PTZ_CAMERA:
  457. #ifdef DEBUG
  458. LOG("Destroying Analog PTZ Camera");
  459. #endif
  460. break;
  461. case ARGUS_IP_STATIC_CAMERA:
  462. #ifdef DEBUG
  463. LOG("Destroying Network Static Camera");
  464. #endif
  465. // SLEEP(2000);
  466. LOG("Actual Destroying Network Static Camera");
  467. delete((deviceNodePTZCamControl *) ptr);
  468. break;
  469. case ARGUS_IP_PTZ_CAMERA:
  470. #ifdef DEBUG
  471. LOG("Destroying Network PTZ Camera");
  472. #endif
  473. // SLEEP(2000);
  474. delete((deviceNodePTZCamControl *) ptr);
  475. #ifdef DEBUG
  476. LOG("Done Successfuly");
  477. #endif
  478. break;
  479. case ARGUS_IP_UART_GATEWAY:
  480. #ifdef DEBUG
  481. LOG("Destroying Ethernet to UART Gateway");
  482. #endif
  483. break;
  484. case ARGUS_IP_VIDEO_SERVER:
  485. #ifdef DEBUG
  486. LOG("Destroying Network Video Encoder");
  487. #endif
  488. break;
  489. case ARGUS_LFS_SENSOR:
  490. #ifdef DEBUG
  491. LOG("Destroying LFS Sensor");
  492. #endif
  493. delete((device2DSensor *) ptr);
  494. break;
  495. case ARGUS_ALS_SENSOR:
  496. #ifdef DEBUG
  497. LOG("Destroying ALS Sensor");
  498. #endif
  499. delete((device2DSensor *) ptr);
  500. break;
  501. case ARGUS_PLS_200_SENSOR:
  502. #ifdef DEBUG
  503. LOG("Destroying PLS200 Sensor");
  504. #endif
  505. delete((device2DSensor *) ptr);
  506. break;
  507. case ARGUS_PLS_360_SENSOR:
  508. #ifdef DEBUG
  509. LOG("Destroying PLS360 Sensor");
  510. #endif
  511. delete((device2DSensor *) ptr);
  512. break;
  513. case ARGUS_3D_SENSOR:
  514. #ifdef DEBUG
  515. LOG("Destroying 3D Sensor");
  516. #endif
  517. delete((device3DSensor *) ptr);
  518. break;
  519. case ARGUS_JAMER:
  520. #ifdef DEBUG
  521. LOG("Destroying RF Jamer");
  522. #endif
  523. break;
  524. case ARGUS_NET_PLS_200:
  525. #ifdef DEBUG
  526. LOG("Destroying Network-PLS200 Sensor");
  527. #endif
  528. break;
  529. case ARGUS_DRONE_CONTROL:
  530. #ifdef DEBUG
  531. LOG("Destroying Drone Controll");
  532. #endif
  533. break;
  534. default: break;
  535. };
  536. }
  537. /*
  538. @id Database ID of Node to be deleted
  539. */
  540. deviceNode * deviceNodeFactory::getNode(uint32_t id)
  541. {
  542. mapDeviceNode2Id::iterator it;
  543. it = m_mDeviceNodesIDS.find(id);
  544. if (it != m_mDeviceNodesIDS.end())
  545. {
  546. return m_mDeviceNodesIDS[id];
  547. };
  548. return NULL;
  549. }
  550. /*
  551. @id Database ID of Node to be deleted
  552. */
  553. void deviceNodeFactory::deleteNode(uint32_t id)
  554. {
  555. deviceNode * tNode = getNode(id);
  556. deleteNode(tNode);
  557. }
  558. bool deviceNodeFactory::validate(void)
  559. {
  560. return (m_bThreadStatus < TH_ENDED);
  561. }
  562. void deviceNodeFactory::m_fThreadProc(void)
  563. {
  564. if (m_pDBC == NULL)
  565. {
  566. m_bThreadStatus = TH_ENDED;
  567. }
  568. else
  569. {
  570. pthread_setname_np( pthread_self(), "NodeFactory" );
  571. m_bThreadStatus = TH_WORKING;
  572. while (m_bThreadStatus < TH_ENDED)
  573. {
  574. DBC_INT_LIST * tList = NULL;
  575. #ifdef DEBUG
  576. #ifdef MEM_DEBUG
  577. size_t memStart, memEnd, memDiff;
  578. char MEM_MSG[256];
  579. memStart = getCurrentRSS();
  580. #endif
  581. #endif
  582. if (m_nPendingInitCounter)
  583. {
  584. m_nPendingInitCounter--;
  585. }
  586. if (m_vDeviceNodes.size())
  587. {
  588. DBC_INT_LIST tL;
  589. for (vectorDeviceNodes::iterator idx = m_vDeviceNodes.begin(); idx < m_vDeviceNodes.end(); idx++)
  590. {
  591. tL.push_back((*idx)->getNodeID());
  592. }
  593. tList = m_pDBC->listNewNodes(&tL);
  594. //ToDo: Must be Written ad method to Delete on the fly Disabled Nodes
  595. // To provide this this performance without restarting App
  596. // tL may be used to query Database if a Node is disabled
  597. tL.clear();
  598. }
  599. else
  600. {
  601. tList = m_pDBC->listNewNodes(NULL);
  602. };
  603. if (tList != NULL)
  604. {
  605. #ifdef DEBUG_EXTRA
  606. LOG("Nodes are Added!");
  607. #endif
  608. for (DBC_INT_LIST::iterator idx = tList->begin(); idx != tList->end(); idx++)
  609. {
  610. if (m_nPendingNodes.size())
  611. {
  612. bool mustAdd = true;
  613. for (DBC_INT_LIST::iterator dx = m_nPendingNodes.begin(); dx != m_nPendingNodes.end(); dx++)
  614. {
  615. if ((*dx == *idx) && (m_nPendingInitCounter))
  616. {
  617. mustAdd = false;
  618. }
  619. };
  620. if (mustAdd)
  621. {
  622. createNode(*idx);
  623. #ifdef DEBUG_EXTRA
  624. }
  625. else
  626. {
  627. LOG("Node is in PENDING mode!");
  628. #endif
  629. };
  630. }
  631. else
  632. {
  633. createNode(*idx);
  634. };
  635. };
  636. tList->clear();
  637. delete(tList);
  638. #ifdef DEBUG_EXTRA
  639. }
  640. else
  641. {
  642. LOG("No New Nodes");
  643. #endif
  644. };
  645. #ifdef MEM_DEBUG
  646. memEnd = getCurrentRSS();
  647. memDiff = memEnd - memStart;
  648. sprintf(MEM_MSG, "MEM START: %d MEM DIF1: %d", memStart, memDiff);
  649. LOG(MEM_MSG);
  650. #endif
  651. if (m_vDeviceNodes.size())
  652. {
  653. // Get Full List
  654. tList = m_pDBC->listNodes();
  655. if (tList != NULL)
  656. {
  657. for (vectorDeviceNodes::iterator idx = m_vDeviceNodes.begin(); idx < m_vDeviceNodes.end(); idx++)
  658. {
  659. bool tRemoved = true;
  660. // Check if Removed By changes in DB
  661. for (DBC_INT_LIST::iterator idz = tList->begin(); idz < tList->end(); idz++)
  662. {
  663. if ((*idz) == (int)(*idx)->getNodeID())
  664. {
  665. tRemoved = false;
  666. }
  667. }
  668. // If Not - check validation
  669. if (! tRemoved)
  670. {
  671. #ifdef DEBUG_EXTRA
  672. LOG("Node Among Active Nodes.... make Validation");
  673. #endif
  674. tRemoved = ! (*idx)->validate();
  675. };
  676. // If Node is Invalid - Removing
  677. if (tRemoved)
  678. {
  679. #ifdef DEBUG_EXTRA
  680. LOG("Node not passed Validation!");
  681. #endif
  682. deleteNode(*idx);
  683. };
  684. };
  685. tList->clear();
  686. delete(tList);
  687. }
  688. else
  689. {
  690. #ifdef DEUBG_EXTRA
  691. LOG("All Modules Must be Deleted!");
  692. #endif
  693. for (vectorDeviceNodes::iterator idx = m_vDeviceNodes.begin(); idx < m_vDeviceNodes.end(); idx++)
  694. {
  695. deleteNode(*idx);
  696. }
  697. m_vDeviceNodes.clear();
  698. m_mDeviceNodesIDS.clear();
  699. };
  700. #ifdef DEBUG_EXTRA
  701. }
  702. else
  703. {
  704. LOG("No Nodes to Validate");
  705. #endif
  706. };
  707. #ifdef DEBUG
  708. #ifdef MEM_DEBUG
  709. memEnd = getCurrentRSS();
  710. memDiff = memEnd - memStart;
  711. sprintf(MEM_MSG, "MEM START: %d MEM DIF2: %d", memStart, memDiff);
  712. LOG(MEM_MSG);
  713. #endif
  714. #endif
  715. // Sleep for 1 second
  716. for (int i = (1000 / DEFAULT_THREAD_SLEEP_TIME); i && (m_bThreadStatus < TH_ENDED); i--)
  717. {
  718. SLEEP(DEFAULT_THREAD_SLEEP_TIME);
  719. }
  720. };
  721. };
  722. LOG("EXIT FROM CTRL THREAD");
  723. }
  724. uint32_t deviceNodeFactory::getNodesCount(ARGUS_NODE_TYPE type)
  725. {
  726. uint32_t RetVal = 0;
  727. if (m_vDeviceNodes.size())
  728. {
  729. for (vectorDeviceNodes::iterator index = m_vDeviceNodes.begin(); index < m_vDeviceNodes.end(); index++)
  730. {
  731. if ((*index)->getNodeType() == type)
  732. {
  733. RetVal++;
  734. }
  735. }
  736. }
  737. return RetVal;
  738. }
  739. uint32_t deviceNodeFactory::fetchNodes(ARGUS_NODE_TYPE type, deviceNode **& RA)
  740. {
  741. uint32_t RetVal = 0;
  742. if (RA == NULL)
  743. {
  744. uint32_t cnt = getNodesCount(type);
  745. if (cnt > 0)
  746. {
  747. RA = (deviceNode **) calloc(cnt, sizeof(deviceNode *));
  748. if (RA == NULL)
  749. {
  750. return 0;
  751. }
  752. // memset( RA, 0, cnt * sizeof(deviceNode *) );
  753. for (vectorDeviceNodes::iterator index = m_vDeviceNodes.begin(); index < m_vDeviceNodes.end(); index++)
  754. {
  755. if ((*index)->getNodeType() == type)
  756. {
  757. RA[RetVal] = (*index);
  758. RetVal++;
  759. };
  760. };
  761. };
  762. }
  763. else
  764. {
  765. if (m_vDeviceNodes.size())
  766. {
  767. for (vectorDeviceNodes::iterator index = m_vDeviceNodes.begin(); index < m_vDeviceNodes.end(); index++)
  768. {
  769. if ((*index)->getNodeType() == type)
  770. {
  771. RA[RetVal] = (*index);
  772. RetVal++;
  773. };
  774. };
  775. };
  776. };
  777. return RetVal;
  778. }
  779. #undef LOG
  780. #undef LOG_ERROR