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.

545 lines
17 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
6 years ago
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
5 years ago
​
​
​
​
​
​
5 years ago
​
​
6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
6 years ago
​
​
​
​
​
6 years ago
​
​
​
​
​
​
​
​
​
​
​
6 years ago
6 years ago
​
6 years ago
6 years ago
​
6 years ago
​
​
6 years ago
​
6 years ago
​
​
​
​
6 years ago
​
6 years ago
6 years ago
​
6 years ago
6 years ago
​
6 years ago
6 years ago
​
6 years ago
6 years ago
​
6 years ago
6 years ago
​
6 years ago
6 years ago
​
6 years ago
6 years ago
​
6 years ago
6 years ago
​
6 years ago
6 years ago
​
6 years ago
6 years ago
​
​
6 years ago
​
​
​
​
​
​
​
6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "rgooseNodeFactory.h"
  2. #include "rgooseIPCamera.h"
  3. #include "rgooseNode3D.h"
  4. #include "rgooseNode2D.h"
  5. #include "rgooseNodePTZCamControl.h"
  6. #include "rgooseNodeStaticCamControl.h"
  7. #ifdef MEM_DEBUG
  8. #include "../alg/generic/heapDebug.h"
  9. #endif
  10. #define LOG( X ) m_pLog->Log( "NFAC", this, X )
  11. #define LOG_ERROR( X ) m_pLog->Log( "NFAC", this, _LOG_ERROR, X )
  12. argusNodeFactory * argusNodeFactory::_instance = 0;
  13. /**
  14. * Returns the single instance of the object.
  15. */
  16. argusNodeFactory* argusNodeFactory::getInstance() {
  17. // check if the instance has been created yet
  18. if (0 == _instance) {
  19. // if not, then create it
  20. _instance = new argusNodeFactory;
  21. }
  22. // return the single instance
  23. return _instance;
  24. };
  25. argusNodeFactory::argusNodeFactory(){
  26. m_pLog = basicLogCollection::getInstance();
  27. m_pDBC = argusDBC::getInstance();
  28. LOG("CONSTRUCTION");
  29. };
  30. argusNodeFactory::~argusNodeFactory(){
  31. unloadNodes();
  32. _instance = NULL;
  33. };
  34. bool argusNodeFactory::unloadNodes( void ){
  35. if( m_pDBC != NULL ){
  36. if( m_vNetNodes.size() > 0 ){
  37. for( vectorNetNodes::iterator index = m_vNetNodes.begin(); index < m_vNetNodes.end(); index++ ){
  38. LOG(" Unload Node... BEGIN");
  39. switch( (*index)->getType() ){
  40. case ARGUS_ANALOG_STATIC_CAMERA:
  41. LOG(" Static Analog Cam");
  42. delete( (ARGUS_CAM*) (*index) );
  43. break;
  44. case ARGUS_ANALOG_PTZ_CAMERA:
  45. LOG(" PTZ Analog Cam");
  46. delete( (ARGUS_PTZCAM*) (*index) );
  47. break;
  48. case ARGUS_IP_PTZ_CAMERA:{
  49. LOG(" PTZ IP Cam");
  50. delete( (ARGUS_PTZCAM*) (*index) );
  51. break;
  52. };
  53. case ARGUS_IP_STATIC_CAMERA:{
  54. LOG(" Static IP Cam");
  55. delete( (ARGUS_CAM*) (*index) );
  56. break;
  57. };
  58. case ARGUS_IP_UART_GATEWAY:{
  59. LOG(" UART Gateway");
  60. delete( (argusNetNode*) (*index) );
  61. break;
  62. };
  63. case ARGUS_ALS_SENSOR:
  64. case ARGUS_PLS_200_SENSOR:
  65. case ARGUS_PLS_360_SENSOR:
  66. case ARGUS_LFS_SENSOR:{
  67. LOG(" 2D LRF");
  68. delete( (ARGUS_2DSensor*) (*index) );
  69. LOG(" 2D LRF done");
  70. break;
  71. };
  72. case ARGUS_3D_SENSOR:{
  73. LOG(" 3D LRF");
  74. delete( (argus3DLIDAR*) (*index) );
  75. break;
  76. };
  77. };
  78. LOG(" Unload Node... DONE!");
  79. };
  80. m_vNetNodes.clear();
  81. m_mNetNodesIDS.clear();
  82. };
  83. };
  84. return true;
  85. };
  86. /*
  87. bool argusNodeFactory::loadNodes( uint32_t SiteID ){
  88. LOG("Node Loader");
  89. if(m_pDBC == NULL) return false;
  90. m_nSiteID = SiteID;
  91. DBC_INT_LIST *tList = m_pDBC->listNodes( SiteID );
  92. if( tList != NULL ) {
  93. for( DBC_INT_LIST::iterator idx = tList->begin(); idx < tList->end(); idx++ ){
  94. uint32_t id = *idx;
  95. char msg[64];
  96. sprintf( msg, "Creating Node[%d]", id );
  97. createNode( id );
  98. };
  99. tList->clear();
  100. delete( tList );
  101. return true;
  102. };
  103. return false;
  104. };
  105. */
  106. bool argusNodeFactory::loadNodes( uint32_t SiteID ){
  107. if( m_pDBC == NULL ) return false;
  108. m_nSiteID = SiteID;
  109. DBC_INT_LIST *tList = m_pDBC->listNodes( SiteID );
  110. if( tList != NULL ) {
  111. for( DBC_INT_LIST::iterator idx = tList->begin(); idx < tList->end(); idx++ ) createNode((*idx));
  112. tList->clear();
  113. delete( tList );
  114. }
  115. #ifdef DEBUG
  116. else {
  117. LOG("No Nodes Defined");
  118. }
  119. #endif
  120. return true;
  121. };
  122. bool argusNodeFactory::reloadNodes( uint32_t SiteID ){
  123. if(!unloadNodes()) return false;
  124. return loadNodes( SiteID );
  125. };
  126. bool argusNodeFactory::reloadNode( uint32_t NodeID ){
  127. deleteNode( NodeID );
  128. argusNetNode *tNode = createNode( NodeID );
  129. if( tNode ) {
  130. return true;
  131. };
  132. return false;
  133. };
  134. argusNetNode *argusNodeFactory::createNode( uint32_t id ){
  135. argusNetNode *tVal = NULL;
  136. LOG("Create Node!");
  137. if( m_pDBC != NULL ){
  138. DBC_NODE_DATA *tData = NULL;
  139. tData = m_pDBC->getNodeData( id );
  140. if( tData!= NULL ) {
  141. switch( tData->type ) {
  142. case ARGUS_ANALOG_STATIC_CAMERA:{
  143. #ifdef DEBUG
  144. LOG("Creating Analog Static Camera");
  145. #endif
  146. ARGUS_CAM *tCamera;
  147. tCamera = new ARGUS_CAM( id );
  148. if( tCamera ) {
  149. LOG("Starting Service");
  150. tCamera->startService();
  151. tVal = ( argusNetNode *) tCamera;
  152. LOG("Success");
  153. };
  154. break;
  155. };
  156. case ARGUS_ANALOG_PTZ_CAMERA:{
  157. #ifdef DEBUG
  158. LOG("Creating Analog PTZ Camera");
  159. #endif
  160. ARGUS_PTZCAM *tCamera;
  161. tCamera = new ARGUS_PTZCAM( id );
  162. if( tCamera ) {
  163. LOG("Starting Service");
  164. tCamera->startService();
  165. tVal = ( argusNetNode *) tCamera;
  166. LOG("Success");
  167. };
  168. break;
  169. };
  170. case ARGUS_IP_STATIC_CAMERA:{
  171. #ifdef DEBUG
  172. LOG("Creating IP Static Camera");
  173. #endif
  174. ARGUS_CAM *tCamera;
  175. tCamera = new ARGUS_CAM( id );
  176. if( tCamera ) {
  177. #ifdef DEBUG
  178. LOG("Starting Service");
  179. #endif
  180. if( tCamera->startService() ){
  181. tVal = ( argusNetNode *) tCamera;
  182. #ifdef DEBUG
  183. LOG("Success");
  184. #endif
  185. } else {
  186. #ifdef DEBUG
  187. LOG_ERROR("Error Sterting Service");
  188. #endif
  189. delete( tCamera );
  190. };
  191. };
  192. break;
  193. };
  194. case ARGUS_IP_PTZ_CAMERA:{
  195. #ifdef DEBUG
  196. LOG("Creating IP PTZ Camera");
  197. #endif
  198. ARGUS_PTZCAM *tCamera;
  199. tCamera = new ARGUS_PTZCAM( id );
  200. if( tCamera ) {
  201. #ifdef DEBUG
  202. LOG("Starting Service");
  203. #endif
  204. if( tCamera->startService() ){
  205. tVal = ( argusNetNode *) tCamera;
  206. #ifdef DEBUG
  207. LOG("Success");
  208. #endif
  209. } else {
  210. #ifdef DEBUG
  211. LOG_ERROR("Error Starting Service!");
  212. #endif
  213. delete( tCamera );
  214. };
  215. };
  216. break;
  217. };
  218. case ARGUS_IP_UART_GATEWAY:{
  219. #ifdef DEBUG
  220. LOG("Creating Ethernet to UART Gateway");
  221. #endif
  222. tVal = new argusNetNode( id );
  223. break;
  224. };
  225. case ARGUS_IP_VIDEO_SERVER:
  226. #ifdef DEBUG
  227. LOG("Creating Network Video Encoder");
  228. #endif
  229. break;
  230. case ARGUS_LFS_SENSOR:{
  231. #ifdef DEBUG
  232. LOG("Creating LFS Sensor");
  233. #endif
  234. ARGUS_2DSensor *tSensor;
  235. tSensor = new ARGUS_2DSensor( id );
  236. if( tSensor ) {
  237. LOG("Success");
  238. tSensor->startService();
  239. tVal = ( argusNetNode *) tSensor;
  240. };
  241. break;
  242. };
  243. case ARGUS_ALS_SENSOR:{
  244. #ifdef DEBUG
  245. LOG("Creating ALS Sensor");
  246. #endif
  247. ARGUS_2DSensor *tSensor;
  248. tSensor = new ARGUS_2DSensor( id );
  249. if( tSensor ) {
  250. LOG("Success");
  251. tSensor->startService();
  252. tVal = ( argusNetNode *) tSensor;
  253. };
  254. break;
  255. };
  256. case ARGUS_PLS_200_SENSOR:{
  257. #ifdef DEBUG
  258. LOG("Creating PLS200 Sensor");
  259. #endif
  260. ARGUS_2DSensor *tSensor;
  261. tSensor = new ARGUS_2DSensor( id );
  262. if( tSensor ) {
  263. LOG("Success");
  264. tSensor->startService();
  265. tVal = ( argusNetNode *) tSensor;
  266. };
  267. break;
  268. };
  269. case ARGUS_PLS_360_SENSOR:{
  270. #ifdef DEBUG
  271. LOG("Creating PLS360 Sensor");
  272. #endif
  273. ARGUS_2DSensor *tSensor;
  274. tSensor = new ARGUS_2DSensor( id );
  275. if( tSensor ) {
  276. LOG("Success");
  277. tSensor->startService();
  278. tVal = ( argusNetNode *) tSensor;
  279. };
  280. break;
  281. };
  282. case ARGUS_3D_SENSOR:{
  283. #ifdef DEBUG
  284. LOG("Creating 3D Sensor");
  285. #endif
  286. argus3DLIDAR *t3DRadar;
  287. t3DRadar = new argus3DLIDAR( id );
  288. if( t3DRadar ) {
  289. LOG("Success");
  290. t3DRadar->startService();
  291. tVal = ( argusNetNode *) t3DRadar;
  292. };
  293. break;
  294. };
  295. case ARGUS_JAMER:
  296. #ifdef DEBUG
  297. LOG("Creating RF Jamer");
  298. #endif
  299. break;
  300. case ARGUS_NET_PLS_200:
  301. #ifdef DEBUG
  302. LOG("Creating Network-PLS200 Sensor");
  303. #endif
  304. break;
  305. case ARGUS_DRONE_CONTROL:
  306. #ifdef DEBUG
  307. LOG("Creating Drone Controll");
  308. #endif
  309. break;
  310. };
  311. free(tData);
  312. };
  313. };
  314. if( tVal != NULL ){
  315. m_vNetNodes.push_back( tVal );
  316. m_mNetNodesIDS[id] = tVal;
  317. };
  318. return tVal;
  319. };
  320. void argusNodeFactory::deleteNode( argusNetNode *ptr ){
  321. if( ptr == NULL ) return;
  322. // if some troubles move this to an end of the function!
  323. for( vectorNetNodes::iterator index = m_vNetNodes.begin() ; index < m_vNetNodes.end(); index++ ){
  324. if( (*index) == ptr ) {
  325. m_mNetNodesIDS.erase( ptr->getDbId() );
  326. m_vNetNodes.erase( index );
  327. break;
  328. };
  329. };
  330. switch( ptr->getType() ) {
  331. case ARGUS_ANALOG_STATIC_CAMERA:
  332. #ifdef DEBUG
  333. LOG("Destroying Analog Static Camera");
  334. #endif
  335. break;
  336. case ARGUS_ANALOG_PTZ_CAMERA:
  337. #ifdef DEBUG
  338. LOG("Destroying Analog PTZ Camera");
  339. #endif
  340. break;
  341. case ARGUS_IP_STATIC_CAMERA:
  342. #ifdef DEBUG
  343. LOG("Destroying Network Static Camera");
  344. #endif
  345. SLEEP(2000);
  346. LOG("Actual Destroying Network Static Camera");
  347. delete((ARGUS_PTZCAM *) ptr );
  348. break;
  349. case ARGUS_IP_PTZ_CAMERA:
  350. #ifdef DEBUG
  351. LOG("Destroying Network PTZ Camera");
  352. #endif
  353. SLEEP(2000);
  354. delete((ARGUS_PTZCAM *) ptr );
  355. #ifdef DEBUG
  356. LOG("Done Successfuly");
  357. #endif
  358. break;
  359. case ARGUS_IP_UART_GATEWAY:
  360. #ifdef DEBUG
  361. LOG("Destroying Ethernet to UART Gateway");
  362. #endif
  363. break;
  364. case ARGUS_IP_VIDEO_SERVER:
  365. #ifdef DEBUG
  366. LOG("Destroying Network Video Encoder");
  367. #endif
  368. break;
  369. case ARGUS_LFS_SENSOR:
  370. #ifdef DEBUG
  371. LOG("Destroying LFS Sensor");
  372. #endif
  373. break;
  374. case ARGUS_ALS_SENSOR:
  375. #ifdef DEBUG
  376. LOG("Destroying ALS Sensor");
  377. #endif
  378. break;
  379. case ARGUS_PLS_200_SENSOR:
  380. #ifdef DEBUG
  381. LOG("Destroying PLS200 Sensor");
  382. #endif
  383. break;
  384. case ARGUS_PLS_360_SENSOR:
  385. #ifdef DEBUG
  386. LOG("Destroying PLS360 Sensor");
  387. #endif
  388. break;
  389. case ARGUS_3D_SENSOR:
  390. #ifdef DEBUG
  391. LOG("Destroying 3D Sensor");
  392. #endif
  393. break;
  394. case ARGUS_JAMER:
  395. #ifdef DEBUG
  396. LOG("Destroying RF Jamer");
  397. #endif
  398. break;
  399. case ARGUS_NET_PLS_200:
  400. #ifdef DEBUG
  401. LOG("Destroying Network-PLS200 Sensor");
  402. #endif
  403. break;
  404. case ARGUS_DRONE_CONTROL:
  405. #ifdef DEBUG
  406. LOG("Destroying Drone Controll");
  407. #endif
  408. break;
  409. };
  410. };
  411. /*
  412. @id Database ID of Node to be deleted
  413. */
  414. argusNetNode *argusNodeFactory::getNode( uint32_t id ){
  415. mapNode2Id::iterator it;
  416. it = m_mNetNodesIDS.find( id );
  417. if( it != m_mNetNodesIDS.end() ) {
  418. return m_mNetNodesIDS[id];
  419. };
  420. return NULL;
  421. };
  422. /*
  423. @id Database ID of Node to be deleted
  424. */
  425. void argusNodeFactory::deleteNode( uint32_t id ){
  426. argusNetNode *tNode = getNode( id );
  427. deleteNode( tNode );
  428. };
  429. void argusNodeFactory::validate( void ){
  430. if(m_pDBC == NULL) return;
  431. DBC_INT_LIST *tList = NULL;
  432. #ifdef MEM_DEBUG
  433. size_t memStart, memEnd, memDiff;
  434. char MEM_MSG[256];
  435. memStart = getCurrentRSS();
  436. #endif
  437. if( m_vNetNodes.size() ) {
  438. DBC_INT_LIST tL;
  439. for( vectorNetNodes::iterator idx = m_vNetNodes.begin(); idx < m_vNetNodes.end(); idx++ ) tL.push_back( (*idx)->getDbId() );
  440. tList = m_pDBC->listNewNodes( m_nSiteID, &tL );
  441. tL.clear();
  442. } else {
  443. tList = m_pDBC->listNewNodes( m_nSiteID, NULL );
  444. };
  445. if( tList != NULL ) {
  446. LOG("New Nodes Added!");
  447. for( DBC_INT_LIST::iterator idx = tList->begin(); idx < tList->end(); idx++ ) createNode( *idx );
  448. tList->clear();
  449. delete( tList );
  450. }
  451. #ifdef DEBUG_EXTRA
  452. else {
  453. LOG( "No New Nodes Added");
  454. }
  455. #endif
  456. #ifdef MEM_DEBUG
  457. memEnd = getCurrentRSS();
  458. memDiff = memEnd - memStart;
  459. sprintf(MEM_MSG,"MEM START: %d MEM DIF1: %d", memStart, memDiff );
  460. LOG( MEM_MSG );
  461. #endif
  462. if( m_vNetNodes.size() ) {
  463. //Get Full List
  464. tList = m_pDBC->listNodes( m_nSiteID );
  465. if( tList != NULL ) {
  466. for( vectorNetNodes::iterator idx = m_vNetNodes.begin(); idx < m_vNetNodes.end(); idx++ ){
  467. bool tRemoved = true;
  468. for( DBC_INT_LIST::iterator idz = tList->begin(); idz < tList->end(); idz++ ) if( (*idz) == (*idx)->getDbId() ) tRemoved = false;
  469. tRemoved = !(*idx)->validate();
  470. if( tRemoved ) {
  471. deleteNode((*idx));
  472. };
  473. };
  474. tList->clear();
  475. delete( tList );
  476. } else {
  477. LOG("All Modules Must be Deleted!");
  478. for( vectorNetNodes::iterator idx = m_vNetNodes.begin(); idx < m_vNetNodes.end(); idx++ ) deleteNode((*idx));
  479. m_vNetNodes.clear();
  480. m_mNetNodesIDS.clear();
  481. };
  482. }
  483. #ifdef DEBUG
  484. else {
  485. LOG("No Nodes to Validate");
  486. }
  487. #endif
  488. #ifdef MEM_DEBUG
  489. memEnd = getCurrentRSS();
  490. memDiff = memEnd - memStart;
  491. sprintf(MEM_MSG,"MEM START: %d MEM DIF2: %d", memStart, memDiff );
  492. LOG( MEM_MSG );
  493. #endif
  494. };
  495. uint32_t argusNodeFactory::getNodesCount( ARGUS_NODE_TYPE type ){
  496. uint32_t RetVal = 0;
  497. if( m_vNetNodes.size() ) for( vectorNetNodes::iterator index = m_vNetNodes.begin(); index < m_vNetNodes.end(); index++ ) if( (*index)->getType() == type ) RetVal++;
  498. return RetVal;
  499. };
  500. uint32_t argusNodeFactory::fetchNodes( ARGUS_NODE_TYPE type, argusNetNode **&RA ){
  501. uint32_t RetVal = 0;
  502. if( RA == NULL ) {
  503. RetVal = getNodesCount( type );
  504. if( RetVal > 0 ) {
  505. RA = (argusNetNode **) calloc( RetVal, sizeof(argusNetNode *));
  506. if( RA == NULL ) return 0;
  507. uint32_t cnt = 0;
  508. for( vectorNetNodes::iterator index = m_vNetNodes.begin(); index < m_vNetNodes.end(); index++ ) {
  509. if( (*index)->getType() == type ) {
  510. RA[cnt] = (*index);
  511. cnt++;
  512. };
  513. };
  514. };
  515. } else {
  516. if( m_vNetNodes.size() ) {
  517. for( vectorNetNodes::iterator index = m_vNetNodes.begin(); index < m_vNetNodes.end(); index++ ) {
  518. if( (*index)->getType() == type ) {
  519. RA[RetVal] = (*index);
  520. RetVal++;
  521. };
  522. };
  523. };
  524. };
  525. return RetVal;
  526. };
  527. #undef LOG
  528. #undef LOG_ERROR