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.

322 lines
9.2 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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 = NULL;
  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. };
  36. };
  37. void argusNodeFactory::setDBC(ARGUS_DBC * tPtr){
  38. if( (m_pDBC == NULL) && (tPtr != NULL) ) m_pDBC = tPtr;
  39. };
  40. bool argusNodeFactory::loadNodes( uint32_t SiteID ){
  41. if(m_pDBC == NULL) return false;
  42. LOG("Loading Nodes!");
  43. m_nSiteID = SiteID;
  44. DBC_INT_LIST *tList = NULL;
  45. tList = m_pDBC->listNodes( SiteID );
  46. if( tList != NULL ) {
  47. for(int index=0; index< tList->size(); index++) {
  48. createNode( tList->at(index) );
  49. };
  50. tList->clear();
  51. delete( tList );
  52. return true;
  53. };
  54. return false;
  55. };
  56. argusNetNode *argusNodeFactory::createNode( int id ){
  57. argusNetNode *tVal = NULL;
  58. if( m_pDBC != NULL ){
  59. DBC_NODE_DATA *tData = NULL;
  60. tData = m_pDBC->getNodeData( id );
  61. if( tData!= NULL ) {
  62. switch( tData->type ) {
  63. case ARGUS_ANALOG_STATIC_CAMERA:
  64. #ifdef DEBUG
  65. LOG("Creating Analog Static Camera");
  66. #endif
  67. break;
  68. case ARGUS_ANALOG_PTZ_CAMERA:
  69. #ifdef DEBUG
  70. LOG("Creating Analog PTZ Camera");
  71. #endif
  72. break;
  73. case ARGUS_IP_STATIC_CAMERA:{
  74. #ifdef DEBUG
  75. LOG("Creating Network Static Camera");
  76. #endif
  77. ARGUS_IPCAM *tCamera;
  78. tCamera = new ARGUS_IPCAM( m_pDBC, tData->aux_id );
  79. if( tCamera ) {
  80. LOG("Success");
  81. tVal = ( argusNetNode *) tCamera;
  82. };
  83. };
  84. break;
  85. case ARGUS_IP_PTZ_CAMERA:
  86. #ifdef DEBUG
  87. LOG("Creating Network PTZ Camera");
  88. #endif
  89. break;
  90. case ARGUS_IP_UART_GATEWAY:
  91. #ifdef DEBUG
  92. LOG("Creating Ethernet to UART Gateway");
  93. #endif
  94. break;
  95. case ARGUS_IP_VIDEO_SERVER:
  96. #ifdef DEBUG
  97. LOG("Creating Network Video Encoder");
  98. #endif
  99. break;
  100. case ARGUS_LFS_SENSOR:
  101. #ifdef DEBUG
  102. LOG("Creating LFS Sensor");
  103. #endif
  104. break;
  105. case ARGUS_ALS_SENSOR:
  106. #ifdef DEBUG
  107. LOG("Creating ALS Sensor");
  108. #endif
  109. break;
  110. case ARGUS_PLS_200_SENSOR:
  111. #ifdef DEBUG
  112. LOG("Creating PLS200 Sensor");
  113. #endif
  114. break;
  115. case ARGUS_PLS_360_SENSOR:
  116. #ifdef DEBUG
  117. LOG("Creating PLS360 Sensor");
  118. #endif
  119. break;
  120. case ARGUS_3D_SENSOR:
  121. #ifdef DEBUG
  122. LOG("Creating 3D Sensor");
  123. #endif
  124. ARGUS_3DSensor *tSENSOR;
  125. tSENSOR = new ARGUS_3DSensor( m_pDBC, tData->aux_id );
  126. if( tSENSOR ) {
  127. LOG("Success");
  128. tSENSOR->startService();
  129. tVal = ( argusNetNode *) tSENSOR;
  130. };
  131. break;
  132. case ARGUS_JAMER:
  133. #ifdef DEBUG
  134. LOG("Creating RF Jamer");
  135. #endif
  136. break;
  137. case ARGUS_NET_PLS_200:
  138. #ifdef DEBUG
  139. LOG("Creating Network-PLS200 Sensor");
  140. #endif
  141. break;
  142. case ARGUS_DRONE_CONTROL:
  143. #ifdef DEBUG
  144. LOG("Creating Drone Controll");
  145. #endif
  146. break;
  147. };
  148. free(tData);
  149. };
  150. };
  151. if( tVal != NULL ) m_vNetNodes.push_back( tVal );
  152. return tVal;
  153. };
  154. void argusNodeFactory::deleteNode( argusNetNode * N ){
  155. if( N ) {
  156. switch( N->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 *) N );
  172. break;
  173. case ARGUS_IP_PTZ_CAMERA:
  174. #ifdef DEBUG
  175. LOG("Destroying Network PTZ Camera");
  176. #endif
  177. delete((ARGUS_Camera *) N );
  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. void argusNodeFactory::deleteNode( int id ){
  233. if( m_vNetNodes.size() > id ) {
  234. deleteNode( m_vNetNodes.at( id ) );
  235. m_vNetNodes.erase( m_vNetNodes.begin() + id );
  236. m_vNetNodes.shrink_to_fit();
  237. };
  238. };
  239. void argusNodeFactory::validate( void ){
  240. if(m_pDBC == NULL) return;
  241. DBC_INT_LIST *tList = NULL;
  242. #ifdef MEM_DEBUG
  243. size_t memStart, memEnd, memDiff;
  244. char MEM_MSG[256];
  245. memStart = getCurrentRSS();
  246. #endif
  247. if( m_vNetNodes.size() ) {
  248. DBC_INT_LIST tL;
  249. for( int cm = 0; cm < m_vNetNodes.size(); cm++ ) tL.push_back( m_vNetNodes.at(cm)->getId() );
  250. tList = m_pDBC->listNewNodes( m_nSiteID, &tL );
  251. tL.clear();
  252. } else {
  253. tList = m_pDBC->listNewNodes( m_nSiteID, NULL );
  254. };
  255. if( tList != NULL ) {
  256. LOG("New Nodes Added!");
  257. for( int index=0; index< tList->size(); index++) createNode(tList->at(index));
  258. tList->clear();
  259. delete( tList );
  260. };
  261. #ifdef MEM_DEBUG
  262. memEnd = getCurrentRSS();
  263. memDiff = memEnd - memStart;
  264. sprintf(MEM_MSG,"MEM START: %d MEM DIF1: %d", memStart, memDiff );
  265. LOG( MEM_MSG );
  266. #endif
  267. if( m_vNetNodes.size() ) {
  268. //Get Full List
  269. tList = m_pDBC->listNodes( m_nSiteID );
  270. if( tList != NULL ) {
  271. int cm = 0;
  272. while( cm < m_vNetNodes.size() ) {
  273. //check if module removed
  274. bool tRemoved = true;
  275. for( int lm = 0; lm < tList->size(); lm++ ) {
  276. if( tList->at(lm) == m_vNetNodes.at(cm)->getId() ) {
  277. tRemoved = false;
  278. break;
  279. };
  280. };
  281. if( !tRemoved ) {
  282. // validate module
  283. m_vNetNodes.at(cm)->validate();
  284. cm++;
  285. } else {
  286. deleteNode( cm );
  287. };
  288. };
  289. tList->clear();
  290. delete( tList );
  291. } else {
  292. LOG("All Modules Must be Deleted!");
  293. while( m_vNetNodes.size() ) deleteNode( 0 );
  294. };
  295. };
  296. #ifdef MEM_DEBUG
  297. memEnd = getCurrentRSS();
  298. memDiff = memEnd - memStart;
  299. sprintf(MEM_MSG,"MEM START: %d MEM DIF2: %d", memStart, memDiff );
  300. LOG( MEM_MSG );
  301. #endif
  302. };
  303. uint32_t argusNodeFactory::getNodeCount( ARGUS_NODE_TYPE type ){
  304. };
  305. bool argusNodeFactory::fetchNodes( ARGUS_NODE_TYPE type, argusNetNode **&RA ){
  306. };
  307. #undef LOG
  308. #undef LOG_ERROR