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.

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