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.

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