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.

608 lines
20 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
​
​
​
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. case ARGUS_ALS_SENSOR:
  256. case ARGUS_PLS_200_SENSOR:
  257. case ARGUS_PLS_360_SENSOR:{
  258. #ifdef DEBUG
  259. LOG("Creating 2D Sensor");
  260. #endif
  261. device2DSensor *tSensor;
  262. tSensor = new device2DSensor( id );
  263. if( tSensor ) {
  264. #ifdef DEBUG
  265. LOG("Starting Service");
  266. #endif
  267. if( tSensor->startService() ) {
  268. #ifdef DEBUG
  269. LOG("Success");
  270. #endif
  271. tVal = ( deviceNode *) tSensor;
  272. } else {
  273. delete( tSensor );
  274. };
  275. };
  276. break;
  277. };
  278. case ARGUS_3D_SENSOR:{
  279. #ifdef DEBUG
  280. LOG("Creating 3D Sensor");
  281. #endif
  282. device3DSensor *t3DRadar;
  283. t3DRadar = new device3DSensor( id );
  284. if( t3DRadar ) {
  285. LOG("Success");
  286. t3DRadar->startService();
  287. tVal = ( deviceNode *) t3DRadar;
  288. };
  289. break;
  290. };
  291. case ARGUS_JAMER:
  292. #ifdef DEBUG
  293. LOG("Creating RF Jamer");
  294. #endif
  295. break;
  296. case ARGUS_NET_PLS_200:
  297. #ifdef DEBUG
  298. LOG("Creating Network-PLS200 Sensor");
  299. #endif
  300. break;
  301. case ARGUS_DRONE_CONTROL:
  302. #ifdef DEBUG
  303. LOG("Creating Drone Controll");
  304. #endif
  305. break;
  306. };
  307. free(tData);
  308. };
  309. };
  310. if( tVal != NULL ){
  311. #ifdef DEBUG
  312. char tB[64];
  313. sprintf( tB, "Node PTR: %p", tVal );
  314. LOG( tB );
  315. #endif
  316. m_vDeviceNodes.push_back( tVal );
  317. m_mDeviceNodesIDS[id] = tVal;
  318. } else {
  319. #ifdef DEBUG_EXTRA
  320. LOG("Node Creation Failure -> Push to Pending Mode!");
  321. #endif
  322. m_nPendingNodes.push_back( id );
  323. m_nPendingInitCounter = FACTORY_NODE_INIT_PENDING_COUNT;
  324. };
  325. return tVal;
  326. };
  327. void deviceNodeFactory::deleteNode( deviceNode *ptr ){
  328. if( ptr == NULL ) return;
  329. // if some troubles move this to an end of the function!
  330. for( vectorDeviceNodes::iterator index = m_vDeviceNodes.begin() ; index < m_vDeviceNodes.end(); index++ ){
  331. if( (*index) == ptr ) {
  332. m_mDeviceNodesIDS.erase( ptr->getNodeID() );
  333. m_vDeviceNodes.erase( index );
  334. break;
  335. };
  336. };
  337. switch( ptr->getNodeType() ) {
  338. case ARGUS_ANALOG_STATIC_CAMERA:
  339. #ifdef DEBUG
  340. LOG("Destroying Analog Static Camera");
  341. #endif
  342. break;
  343. case ARGUS_ANALOG_PTZ_CAMERA:
  344. #ifdef DEBUG
  345. LOG("Destroying Analog PTZ Camera");
  346. #endif
  347. break;
  348. case ARGUS_IP_STATIC_CAMERA:
  349. #ifdef DEBUG
  350. LOG("Destroying Network Static Camera");
  351. #endif
  352. //SLEEP(2000);
  353. LOG("Actual Destroying Network Static Camera");
  354. delete((deviceNodePTZCamControl *) ptr );
  355. break;
  356. case ARGUS_IP_PTZ_CAMERA:
  357. #ifdef DEBUG
  358. LOG("Destroying Network PTZ Camera");
  359. #endif
  360. //SLEEP(2000);
  361. delete((deviceNodePTZCamControl *) ptr );
  362. #ifdef DEBUG
  363. LOG("Done Successfuly");
  364. #endif
  365. break;
  366. case ARGUS_IP_UART_GATEWAY:
  367. #ifdef DEBUG
  368. LOG("Destroying Ethernet to UART Gateway");
  369. #endif
  370. break;
  371. case ARGUS_IP_VIDEO_SERVER:
  372. #ifdef DEBUG
  373. LOG("Destroying Network Video Encoder");
  374. #endif
  375. break;
  376. case ARGUS_LFS_SENSOR:
  377. #ifdef DEBUG
  378. LOG("Destroying LFS Sensor");
  379. #endif
  380. delete((device2DSensor *) ptr );
  381. break;
  382. case ARGUS_ALS_SENSOR:
  383. #ifdef DEBUG
  384. LOG("Destroying ALS Sensor");
  385. #endif
  386. delete((device2DSensor *) ptr );
  387. break;
  388. case ARGUS_PLS_200_SENSOR:
  389. #ifdef DEBUG
  390. LOG("Destroying PLS200 Sensor");
  391. #endif
  392. delete((device2DSensor *) ptr );
  393. break;
  394. case ARGUS_PLS_360_SENSOR:
  395. #ifdef DEBUG
  396. LOG("Destroying PLS360 Sensor");
  397. #endif
  398. delete((device2DSensor *) ptr );
  399. break;
  400. case ARGUS_3D_SENSOR:
  401. #ifdef DEBUG
  402. LOG("Destroying 3D Sensor");
  403. #endif
  404. delete((device3DSensor *) ptr );
  405. break;
  406. case ARGUS_JAMER:
  407. #ifdef DEBUG
  408. LOG("Destroying RF Jamer");
  409. #endif
  410. break;
  411. case ARGUS_NET_PLS_200:
  412. #ifdef DEBUG
  413. LOG("Destroying Network-PLS200 Sensor");
  414. #endif
  415. break;
  416. case ARGUS_DRONE_CONTROL:
  417. #ifdef DEBUG
  418. LOG("Destroying Drone Controll");
  419. #endif
  420. break;
  421. };
  422. };
  423. /*
  424. @id Database ID of Node to be deleted
  425. */
  426. deviceNode *deviceNodeFactory::getNode( uint32_t id ){
  427. mapDeviceNode2Id::iterator it;
  428. it = m_mDeviceNodesIDS.find( id );
  429. if( it != m_mDeviceNodesIDS.end() ) {
  430. return m_mDeviceNodesIDS[id];
  431. };
  432. return NULL;
  433. };
  434. /*
  435. @id Database ID of Node to be deleted
  436. */
  437. void deviceNodeFactory::deleteNode( uint32_t id ){
  438. deviceNode *tNode = getNode( id );
  439. deleteNode( tNode );
  440. };
  441. bool deviceNodeFactory::validate( void ){
  442. return ( m_bThreadStatus < TH_ENDED );
  443. };
  444. void deviceNodeFactory::m_fThreadProc( void ){
  445. if( m_pDBC == NULL ){
  446. m_bThreadStatus = TH_ENDED;
  447. } else {
  448. m_bThreadStatus = TH_WORKING;
  449. while( m_bThreadStatus < TH_ENDED ) {
  450. DBC_INT_LIST *tList = NULL;
  451. #ifdef DEBUG
  452. #ifdef MEM_DEBUG
  453. size_t memStart, memEnd, memDiff;
  454. char MEM_MSG[256];
  455. memStart = getCurrentRSS();
  456. #endif
  457. #endif
  458. if ( m_nPendingInitCounter ) m_nPendingInitCounter--;
  459. if (m_vDeviceNodes.size()) {
  460. DBC_INT_LIST tL;
  461. for( vectorDeviceNodes::iterator idx = m_vDeviceNodes.begin(); idx < m_vDeviceNodes.end(); idx++ ) tL.push_back( (*idx)->getNodeID() );
  462. tList = m_pDBC->listNewNodes( &tL );
  463. tL.clear();
  464. } else {
  465. tList = m_pDBC->listNewNodes( NULL );
  466. };
  467. if( tList != NULL ) {
  468. #ifdef DEBUG_EXTRA
  469. LOG("Nodes are Added!");
  470. #endif
  471. for( DBC_INT_LIST::iterator idx = tList->begin(); idx != tList->end(); idx++ ) {
  472. if ( m_nPendingNodes.size() ) {
  473. bool mustAdd = true;
  474. for ( DBC_INT_LIST::iterator dx = m_nPendingNodes.begin(); dx != m_nPendingNodes.end(); dx++ ) {
  475. if ( ( *dx == *idx ) && ( m_nPendingInitCounter ) ) mustAdd = false;
  476. };
  477. if ( mustAdd ){
  478. createNode(*idx);
  479. #ifdef DEBUG_EXTRA
  480. } else {
  481. LOG( "Node is in PENDING mode!");
  482. #endif
  483. };
  484. } else {
  485. createNode(*idx);
  486. };
  487. };
  488. tList->clear();
  489. delete( tList );
  490. #ifdef DEBUG_EXTRA
  491. } else {
  492. LOG( "No New Nodes");
  493. #endif
  494. };
  495. #ifdef MEM_DEBUG
  496. memEnd = getCurrentRSS();
  497. memDiff = memEnd - memStart;
  498. sprintf(MEM_MSG,"MEM START: %d MEM DIF1: %d", memStart, memDiff );
  499. LOG( MEM_MSG );
  500. #endif
  501. if( m_vDeviceNodes.size() ) {
  502. //Get Full List
  503. tList = m_pDBC->listNodes();
  504. if( tList != NULL ) {
  505. for( vectorDeviceNodes::iterator idx = m_vDeviceNodes.begin(); idx < m_vDeviceNodes.end(); idx++ ){
  506. bool tRemoved = true;
  507. // Check if Removed By changes in DB
  508. for( DBC_INT_LIST::iterator idz = tList->begin(); idz < tList->end(); idz++ ) if( (*idz) == (*idx)->getNodeID() ) tRemoved = false;
  509. // If Not - check validation
  510. if( !tRemoved ){
  511. #ifdef DEBUG_EXTRA
  512. LOG("Node Among Active Nodes.... make Validation");
  513. #endif
  514. tRemoved = !(*idx)->validate();
  515. };
  516. // If Node is Invalid - Removing
  517. if( tRemoved ) {
  518. #ifdef DEBUG_EXTRA
  519. LOG("Node not passed Validation!");
  520. #endif
  521. deleteNode((*idx));
  522. };
  523. };
  524. tList->clear();
  525. delete( tList );
  526. } else {
  527. #ifdef DEUBG_EXTRA
  528. LOG("All Modules Must be Deleted!");
  529. #endif
  530. for( vectorDeviceNodes::iterator idx = m_vDeviceNodes.begin(); idx < m_vDeviceNodes.end(); idx++ ) deleteNode((*idx));
  531. m_vDeviceNodes.clear();
  532. m_mDeviceNodesIDS.clear();
  533. };
  534. #ifdef DEBUG_EXTRA
  535. } else {
  536. LOG("No Nodes to Validate");
  537. #endif
  538. };
  539. #ifdef DEBUG
  540. #ifdef MEM_DEBUG
  541. memEnd = getCurrentRSS();
  542. memDiff = memEnd - memStart;
  543. sprintf(MEM_MSG,"MEM START: %d MEM DIF2: %d", memStart, memDiff );
  544. LOG( MEM_MSG );
  545. #endif
  546. #endif
  547. // Sleep for 1 second
  548. for( int i = ( 1000 / DEFAULT_THREAD_SLEEP_TIME ); i && ( m_bThreadStatus < TH_ENDED ); i-- ) SLEEP( DEFAULT_THREAD_SLEEP_TIME );
  549. };
  550. };
  551. LOG("EXIT FROM CTRL THREAD");
  552. };
  553. uint32_t deviceNodeFactory::getNodesCount( ARGUS_NODE_TYPE type ){
  554. uint32_t RetVal = 0;
  555. if( m_vDeviceNodes.size() ) for( vectorDeviceNodes::iterator index = m_vDeviceNodes.begin(); index < m_vDeviceNodes.end(); index++ ) if( (*index)->getNodeType() == type ) RetVal++;
  556. return RetVal;
  557. };
  558. uint32_t deviceNodeFactory::fetchNodes( ARGUS_NODE_TYPE type, deviceNode **&RA ){
  559. uint32_t RetVal = 0;
  560. if( RA == NULL ) {
  561. RetVal = getNodesCount( type );
  562. if( RetVal > 0 ) {
  563. RA = (deviceNode **) calloc( RetVal, sizeof(deviceNode *));
  564. if( RA == NULL ) return 0;
  565. uint32_t cnt = 0;
  566. for( vectorDeviceNodes::iterator index = m_vDeviceNodes.begin(); index < m_vDeviceNodes.end(); index++ ) {
  567. if( (*index)->getNodeType() == type ) {
  568. RA[cnt] = (*index);
  569. cnt++;
  570. };
  571. };
  572. };
  573. } else {
  574. if( m_vDeviceNodes.size() ) {
  575. for( vectorDeviceNodes::iterator index = m_vDeviceNodes.begin(); index < m_vDeviceNodes.end(); index++ ) {
  576. if( (*index)->getNodeType() == type ) {
  577. RA[RetVal] = (*index);
  578. RetVal++;
  579. };
  580. };
  581. };
  582. };
  583. return RetVal;
  584. };
  585. #undef LOG
  586. #undef LOG_ERROR