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.

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