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.

644 lines
21 KiB

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