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.

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