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.

801 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. tL.clear();
  595. }
  596. else
  597. {
  598. tList = m_pDBC->listNewNodes(NULL);
  599. };
  600. if (tList != NULL)
  601. {
  602. #ifdef DEBUG_EXTRA
  603. LOG("Nodes are Added!");
  604. #endif
  605. for (DBC_INT_LIST::iterator idx = tList->begin(); idx != tList->end(); idx++)
  606. {
  607. if (m_nPendingNodes.size())
  608. {
  609. bool mustAdd = true;
  610. for (DBC_INT_LIST::iterator dx = m_nPendingNodes.begin(); dx != m_nPendingNodes.end(); dx++)
  611. {
  612. if ((*dx == *idx) && (m_nPendingInitCounter))
  613. {
  614. mustAdd = false;
  615. }
  616. };
  617. if (mustAdd)
  618. {
  619. createNode(*idx);
  620. #ifdef DEBUG_EXTRA
  621. }
  622. else
  623. {
  624. LOG("Node is in PENDING mode!");
  625. #endif
  626. };
  627. }
  628. else
  629. {
  630. createNode(*idx);
  631. };
  632. };
  633. tList->clear();
  634. delete(tList);
  635. #ifdef DEBUG_EXTRA
  636. }
  637. else
  638. {
  639. LOG("No New Nodes");
  640. #endif
  641. };
  642. #ifdef MEM_DEBUG
  643. memEnd = getCurrentRSS();
  644. memDiff = memEnd - memStart;
  645. sprintf(MEM_MSG, "MEM START: %d MEM DIF1: %d", memStart, memDiff);
  646. LOG(MEM_MSG);
  647. #endif
  648. if (m_vDeviceNodes.size())
  649. {
  650. // Get Full List
  651. tList = m_pDBC->listNodes();
  652. if (tList != NULL)
  653. {
  654. for (vectorDeviceNodes::iterator idx = m_vDeviceNodes.begin(); idx < m_vDeviceNodes.end(); idx++)
  655. {
  656. bool tRemoved = true;
  657. // Check if Removed By changes in DB
  658. for (DBC_INT_LIST::iterator idz = tList->begin(); idz < tList->end(); idz++)
  659. {
  660. if ((*idz) == (int)(*idx)->getNodeID())
  661. {
  662. tRemoved = false;
  663. }
  664. }
  665. // If Not - check validation
  666. if (! tRemoved)
  667. {
  668. #ifdef DEBUG_EXTRA
  669. LOG("Node Among Active Nodes.... make Validation");
  670. #endif
  671. tRemoved = ! (*idx)->validate();
  672. };
  673. // If Node is Invalid - Removing
  674. if (tRemoved)
  675. {
  676. #ifdef DEBUG_EXTRA
  677. LOG("Node not passed Validation!");
  678. #endif
  679. deleteNode(*idx);
  680. };
  681. };
  682. tList->clear();
  683. delete(tList);
  684. }
  685. else
  686. {
  687. #ifdef DEUBG_EXTRA
  688. LOG("All Modules Must be Deleted!");
  689. #endif
  690. for (vectorDeviceNodes::iterator idx = m_vDeviceNodes.begin(); idx < m_vDeviceNodes.end(); idx++)
  691. {
  692. deleteNode(*idx);
  693. }
  694. m_vDeviceNodes.clear();
  695. m_mDeviceNodesIDS.clear();
  696. };
  697. #ifdef DEBUG_EXTRA
  698. }
  699. else
  700. {
  701. LOG("No Nodes to Validate");
  702. #endif
  703. };
  704. #ifdef DEBUG
  705. #ifdef MEM_DEBUG
  706. memEnd = getCurrentRSS();
  707. memDiff = memEnd - memStart;
  708. sprintf(MEM_MSG, "MEM START: %d MEM DIF2: %d", memStart, memDiff);
  709. LOG(MEM_MSG);
  710. #endif
  711. #endif
  712. // Sleep for 1 second
  713. for (int i = (1000 / DEFAULT_THREAD_SLEEP_TIME); i && (m_bThreadStatus < TH_ENDED); i--)
  714. {
  715. SLEEP(DEFAULT_THREAD_SLEEP_TIME);
  716. }
  717. };
  718. };
  719. LOG("EXIT FROM CTRL THREAD");
  720. }
  721. uint32_t deviceNodeFactory::getNodesCount(ARGUS_NODE_TYPE type)
  722. {
  723. uint32_t RetVal = 0;
  724. if (m_vDeviceNodes.size())
  725. {
  726. for (vectorDeviceNodes::iterator index = m_vDeviceNodes.begin(); index < m_vDeviceNodes.end(); index++)
  727. {
  728. if ((*index)->getNodeType() == type)
  729. {
  730. RetVal++;
  731. }
  732. }
  733. }
  734. return RetVal;
  735. }
  736. uint32_t deviceNodeFactory::fetchNodes(ARGUS_NODE_TYPE type, deviceNode **& RA)
  737. {
  738. uint32_t RetVal = 0;
  739. if (RA == NULL)
  740. {
  741. uint32_t cnt = getNodesCount(type);
  742. if (cnt > 0)
  743. {
  744. RA = (deviceNode **) calloc(cnt, sizeof(deviceNode *));
  745. if (RA == NULL)
  746. {
  747. return 0;
  748. }
  749. // memset( RA, 0, cnt * sizeof(deviceNode *) );
  750. for (vectorDeviceNodes::iterator index = m_vDeviceNodes.begin(); index < m_vDeviceNodes.end(); index++)
  751. {
  752. if ((*index)->getNodeType() == type)
  753. {
  754. RA[RetVal] = (*index);
  755. RetVal++;
  756. };
  757. };
  758. };
  759. }
  760. else
  761. {
  762. if (m_vDeviceNodes.size())
  763. {
  764. for (vectorDeviceNodes::iterator index = m_vDeviceNodes.begin(); index < m_vDeviceNodes.end(); index++)
  765. {
  766. if ((*index)->getNodeType() == type)
  767. {
  768. RA[RetVal] = (*index);
  769. RetVal++;
  770. };
  771. };
  772. };
  773. };
  774. return RetVal;
  775. }
  776. #undef LOG
  777. #undef LOG_ERROR