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.

497 lines
16 KiB

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