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.

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