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.

342 lines
10 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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 = NULL;
  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. };
  35. };
  36. void argusNodeFactory::setDBC(ARGUS_DBC * tPtr){
  37. if( (m_pDBC == NULL) && (tPtr != NULL) ) m_pDBC = tPtr;
  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( int 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( m_pDBC, id );
  77. if( tCamera ) {
  78. LOG("Success");
  79. tVal = ( argusNetNode *) tCamera;
  80. };
  81. };
  82. break;
  83. case ARGUS_IP_PTZ_CAMERA:
  84. #ifdef DEBUG
  85. LOG("Creating Network PTZ Camera");
  86. #endif
  87. break;
  88. case ARGUS_IP_UART_GATEWAY:
  89. #ifdef DEBUG
  90. LOG("Creating Ethernet to UART Gateway");
  91. #endif
  92. break;
  93. case ARGUS_IP_VIDEO_SERVER:
  94. #ifdef DEBUG
  95. LOG("Creating Network Video Encoder");
  96. #endif
  97. break;
  98. case ARGUS_LFS_SENSOR:
  99. #ifdef DEBUG
  100. LOG("Creating LFS Sensor");
  101. #endif
  102. break;
  103. case ARGUS_ALS_SENSOR:
  104. #ifdef DEBUG
  105. LOG("Creating ALS Sensor");
  106. #endif
  107. break;
  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. break;
  123. case ARGUS_JAMER:
  124. #ifdef DEBUG
  125. LOG("Creating RF Jamer");
  126. #endif
  127. break;
  128. case ARGUS_NET_PLS_200:
  129. #ifdef DEBUG
  130. LOG("Creating Network-PLS200 Sensor");
  131. #endif
  132. break;
  133. case ARGUS_DRONE_CONTROL:
  134. #ifdef DEBUG
  135. LOG("Creating Drone Controll");
  136. #endif
  137. break;
  138. };
  139. free(tData);
  140. };
  141. };
  142. if( tVal != NULL ) m_vNetNodes.push_back( tVal );
  143. return tVal;
  144. };
  145. void argusNodeFactory::deleteNode( argusNetNode * N ){
  146. if( N ) {
  147. switch( N->getType() ) {
  148. case ARGUS_ANALOG_STATIC_CAMERA:
  149. #ifdef DEBUG
  150. LOG("Destroying Analog Static Camera");
  151. #endif
  152. break;
  153. case ARGUS_ANALOG_PTZ_CAMERA:
  154. #ifdef DEBUG
  155. LOG("Destroying Analog PTZ Camera");
  156. #endif
  157. break;
  158. case ARGUS_IP_STATIC_CAMERA:
  159. #ifdef DEBUG
  160. LOG("Destroying Network Static Camera");
  161. #endif
  162. delete((ARGUS_Camera *) N );
  163. break;
  164. case ARGUS_IP_PTZ_CAMERA:
  165. #ifdef DEBUG
  166. LOG("Destroying Network PTZ Camera");
  167. #endif
  168. delete((ARGUS_Camera *) N );
  169. break;
  170. case ARGUS_IP_UART_GATEWAY:
  171. #ifdef DEBUG
  172. LOG("Destroying Ethernet to UART Gateway");
  173. #endif
  174. break;
  175. case ARGUS_IP_VIDEO_SERVER:
  176. #ifdef DEBUG
  177. LOG("Destroying Network Video Encoder");
  178. #endif
  179. break;
  180. case ARGUS_LFS_SENSOR:
  181. #ifdef DEBUG
  182. LOG("Destroying LFS Sensor");
  183. #endif
  184. break;
  185. case ARGUS_ALS_SENSOR:
  186. #ifdef DEBUG
  187. LOG("Destroying ALS Sensor");
  188. #endif
  189. break;
  190. case ARGUS_PLS_200_SENSOR:
  191. #ifdef DEBUG
  192. LOG("Destroying PLS200 Sensor");
  193. #endif
  194. break;
  195. case ARGUS_PLS_360_SENSOR:
  196. #ifdef DEBUG
  197. LOG("Destroying PLS360 Sensor");
  198. #endif
  199. break;
  200. case ARGUS_3D_SENSOR:
  201. #ifdef DEBUG
  202. LOG("Destroying 3D Sensor");
  203. #endif
  204. break;
  205. case ARGUS_JAMER:
  206. #ifdef DEBUG
  207. LOG("Destroying RF Jamer");
  208. #endif
  209. break;
  210. case ARGUS_NET_PLS_200:
  211. #ifdef DEBUG
  212. LOG("Destroying Network-PLS200 Sensor");
  213. #endif
  214. break;
  215. case ARGUS_DRONE_CONTROL:
  216. #ifdef DEBUG
  217. LOG("Destroying Drone Controll");
  218. #endif
  219. break;
  220. };
  221. };
  222. };
  223. void argusNodeFactory::deleteNode( int id ){
  224. if( m_vNetNodes.size() > id ) {
  225. deleteNode( m_vNetNodes.at( id ) );
  226. m_vNetNodes.erase( m_vNetNodes.begin() + id );
  227. m_vNetNodes.shrink_to_fit();
  228. };
  229. };
  230. void argusNodeFactory::validate( void ){
  231. if(m_pDBC == NULL) return;
  232. DBC_INT_LIST *tList = NULL;
  233. #ifdef MEM_DEBUG
  234. size_t memStart, memEnd, memDiff;
  235. char MEM_MSG[256];
  236. memStart = getCurrentRSS();
  237. #endif
  238. if( m_vNetNodes.size() ) {
  239. DBC_INT_LIST tL;
  240. for( int cm = 0; cm < m_vNetNodes.size(); cm++ ) tL.push_back( m_vNetNodes.at(cm)->getId() );
  241. tList = m_pDBC->listNewNodes( m_nSiteID, &tL );
  242. tL.clear();
  243. } else {
  244. tList = m_pDBC->listNewNodes( m_nSiteID, NULL );
  245. };
  246. if( tList != NULL ) {
  247. LOG("New Nodes Added!");
  248. for( int index=0; index< tList->size(); index++) createNode(tList->at(index));
  249. tList->clear();
  250. delete( tList );
  251. };
  252. #ifdef MEM_DEBUG
  253. memEnd = getCurrentRSS();
  254. memDiff = memEnd - memStart;
  255. sprintf(MEM_MSG,"MEM START: %d MEM DIF1: %d", memStart, memDiff );
  256. LOG( MEM_MSG );
  257. #endif
  258. if( m_vNetNodes.size() ) {
  259. //Get Full List
  260. tList = m_pDBC->listNodes( m_nSiteID );
  261. if( tList != NULL ) {
  262. int cm = 0;
  263. while( cm < m_vNetNodes.size() ) {
  264. //check if module removed
  265. bool tRemoved = true;
  266. for( int lm = 0; lm < tList->size(); lm++ ) {
  267. if( tList->at(lm) == m_vNetNodes.at(cm)->getId() ) {
  268. tRemoved = false;
  269. break;
  270. };
  271. };
  272. if( !tRemoved ) {
  273. // validate module
  274. m_vNetNodes.at(cm)->validate();
  275. cm++;
  276. } else {
  277. deleteNode( cm );
  278. };
  279. };
  280. tList->clear();
  281. delete( tList );
  282. } else {
  283. LOG("All Modules Must be Deleted!");
  284. while( m_vNetNodes.size() ) deleteNode( 0 );
  285. };
  286. };
  287. #ifdef MEM_DEBUG
  288. memEnd = getCurrentRSS();
  289. memDiff = memEnd - memStart;
  290. sprintf(MEM_MSG,"MEM START: %d MEM DIF2: %d", memStart, memDiff );
  291. LOG( MEM_MSG );
  292. #endif
  293. };
  294. uint32_t argusNodeFactory::getNodeCount( ARGUS_NODE_TYPE type ){
  295. uint32_t RetVal = 0;
  296. if( m_vNetNodes.size() ) for( vectorNetNodes::iterator index = m_vNetNodes.begin(); index < m_vNetNodes.end(); index++ ) if( (*index)->getType() == type ) RetVal++;
  297. return RetVal;
  298. };
  299. uint32_t argusNodeFactory::fetchNodes( ARGUS_NODE_TYPE type, argusNetNode **&RA ){
  300. uint32_t RetVal = 0;
  301. if( RA == NULL ) {
  302. RetVal = getNodeCount( type );
  303. if( RetVal > 0 ) {
  304. RA = (argusNetNode **) calloc( RetVal, sizeof(argusNetNode *));
  305. if( RA == NULL ) return 0;
  306. uint32_t cnt = 0;
  307. for( vectorNetNodes::iterator index = m_vNetNodes.begin(); index < m_vNetNodes.end(); index++ ) {
  308. if( (*index)->getType() == type ) {
  309. RA[cnt] = (*index);
  310. cnt++;
  311. };
  312. };
  313. };
  314. } else {
  315. if( m_vNetNodes.size() ) {
  316. for( vectorNetNodes::iterator index = m_vNetNodes.begin(); index < m_vNetNodes.end(); index++ ) {
  317. if( (*index)->getType() == type ) {
  318. RA[RetVal] = (*index);
  319. RetVal++;
  320. };
  321. };
  322. };
  323. };
  324. return RetVal;
  325. };
  326. #undef LOG
  327. #undef LOG_ERROR