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.

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