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.

414 lines
12 KiB

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