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.

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