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.

839 lines
28 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
​
​
​
​
​
​
​
5 years ago
5 years ago
5 years ago
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 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
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 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
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
5 years ago
​
​
​
5 years ago
​
​
​
​
​
5 years ago
​
5 years ago
​
​
​
6 years ago
​
​
  1. /*******************************************************************
  2. *
  3. * DESCRIPTION: ARGUS Kernel source
  4. *
  5. * AUTHOR: gagua
  6. *
  7. * HISTORY:
  8. *
  9. * DATE:5/29/2019
  10. *
  11. *******************************************************************/
  12. #include "rgooseKernel.h"
  13. #include "rgooseFilterAPF.h"
  14. #include <sys/types.h>
  15. #include <sys/sysinfo.h>
  16. #include <sys/statvfs.h>
  17. #define LOG( X ) m_pLog->Log( "KRNL", this, X )
  18. #ifdef DEBUG
  19. #define LOG_ERROR( X ) {\
  20. char _tBfrErrMSG2w34[256];\
  21. sprintf( _tBfrErrMSG2w34, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
  22. m_pLog->Log( "KRNL", this, _LOG_ERROR, _tBfrErrMSG2w34 );\
  23. }
  24. #else
  25. #define LOG_ERROR( X ) m_pLog->Log( "KRNL", this, _LOG_ERROR, X );
  26. #endif
  27. argusKernel *argusKernel::_instance = NULL;
  28. /**
  29. * Returns the single instance of the object.
  30. */
  31. argusKernel* argusKernel::getInstance( bool cold_start, config_setting_t *Settings ) {
  32. // check if the instance has been created yet
  33. if( 0 == _instance ){
  34. // if not, then create it
  35. _instance = new argusKernel( cold_start, Settings );
  36. };
  37. // return the single instance
  38. return _instance;
  39. };
  40. argusKernel::argusKernel( bool cold_start, config_setting_t *Settings ):basicThread(), basicEventHandler(){
  41. m_bExitCause = 0;
  42. m_nServerID = 0;
  43. m_nSiteID = 0;
  44. m_pDBC = NULL;
  45. m_bSkipResignComponents = cold_start;
  46. m_tTimeTSeconds = time( NULL );
  47. m_pLog = basicLogCollection::getInstance();
  48. m_pSettings = basicSettingsProvider::getInstance()->getSubNode( Settings, "KERNEL" );
  49. //m_pServiceAnnouncer = NULL;
  50. m_pEventHeap = NULL;
  51. //m_pOnvifMediaObserver = NULL;
  52. m_pNodeFactory = NULL;
  53. m_pModuleFactory = NULL;
  54. #ifdef SIMULATE_KERNEL_TARGETS
  55. sprintf( m_cCurrentMission,"" );
  56. m_bLandingTO = 0;
  57. m_bJamingTO = 0;
  58. #endif
  59. };
  60. argusKernel::~argusKernel(){
  61. #ifdef DEBUG
  62. LOG("Destructor");
  63. #endif
  64. WaitFinish(true);
  65. #ifdef DEBUG
  66. LOG(" Module Factory...");
  67. #endif
  68. if( m_pModuleFactory != NULL ) delete( m_pModuleFactory );
  69. #ifdef DEBUG
  70. LOG(" Node Factory...");
  71. #endif
  72. if( m_pNodeFactory != NULL ) delete( m_pNodeFactory );
  73. #ifdef DEBUG
  74. LOG("Deleting Filters");
  75. #endif
  76. unloadFilters();
  77. /*
  78. #ifdef DEBUG
  79. LOG("Deleting Resources");
  80. #endif
  81. m_pHardwareManager->unloadResources();
  82. */
  83. if( m_bExitCause == 0 ) {
  84. #ifdef DEBUG
  85. LOG("Unregister Server");
  86. #endif
  87. m_pDBC->unregisterServer( m_nSiteID, m_nServerNodeID );
  88. LOG(" DataBase Connection...");
  89. if( m_pDBC != NULL ) delete( m_pDBC );
  90. m_pDBC = NULL;
  91. } else {
  92. if( m_bExitCause == 4 ) {
  93. m_pHardwareManager->enumerateHardware();
  94. };
  95. };
  96. _instance = NULL;
  97. #ifdef DEBUG
  98. LOG("Destructor Finished");
  99. #endif
  100. };
  101. bool argusKernel::create( void ){
  102. char tBuffer[256];
  103. if( m_pSettings != NULL ) {
  104. config_setting_t * pSetting;
  105. int tVal;
  106. const char * tBuf;
  107. //Connect( CSTR DBName, CSTR DBHost, CSTR DBUser, CSTR DBPassword, uint16_t Port = 3300 );
  108. LOG("Getting Settings ...");
  109. if( !config_setting_lookup_string( m_pSettings, ARGUS_KERNEL_TAG_SERVER_IDENTITY, &tBuf ) ){
  110. char * tVar;
  111. char * tTS;
  112. tTS = getTStr(NULL);
  113. tVar = MD5String(tTS);
  114. free(tTS);
  115. sprintf( m_sIdentity, tVar );
  116. pSetting = config_setting_add( m_pSettings, ARGUS_KERNEL_TAG_SERVER_IDENTITY, CONFIG_TYPE_STRING );
  117. config_setting_set_string( pSetting, tVar );
  118. free( tVar );
  119. basicSettingsProvider::getInstance()->compromise();
  120. LOG("Server Identity not defined - generating new!");
  121. } else {
  122. sprintf( m_sIdentity, tBuf );
  123. sprintf( tBuffer, "Server Identity Read From Settings: %s", tBuf );
  124. LOG( tBuffer );
  125. };
  126. if( !config_setting_lookup_int( m_pSettings, ARGUS_KERNEL_TAG_SITE_ID, &tVal ) ){
  127. tVal = m_nSiteID = 1;
  128. pSetting = config_setting_add( m_pSettings, ARGUS_KERNEL_TAG_SITE_ID, CONFIG_TYPE_INT );
  129. config_setting_set_int( pSetting, tVal );
  130. basicSettingsProvider::getInstance()->compromise();
  131. LOG("Site ID not defined - using [1] as number!");
  132. } else {
  133. m_nSiteID = tVal;
  134. sprintf( tBuffer, "Site ID Read From Settings: %d", m_nSiteID );
  135. LOG( tBuffer );
  136. };
  137. } else {
  138. LOG_ERROR("Failed Read Config Settings!");
  139. return false;
  140. };
  141. if( m_pDBC == NULL ) {
  142. LOG("Explicitly Create DBC Object");
  143. m_pDBC = argusDBC::getInstance( m_pSettings );
  144. };
  145. if( m_pDBC == NULL ){
  146. LOG_ERROR("DBC Object Creation Failure!");
  147. return false;
  148. } else LOG("DBC Object is OK");
  149. if(!m_pDBC->connect()){
  150. LOG_ERROR("DBC Connection Failure!");
  151. SLEEP(5000);
  152. //ToDO: Set Restart Kernel!
  153. return false;
  154. };
  155. #ifdef DEBUG
  156. LOG( "Settings Read Done" );
  157. #endif
  158. m_pDBC->registerServer( m_nSiteID, m_sIdentity );
  159. m_nServerID = m_pDBC->getServerID( m_sIdentity );
  160. m_nServerNodeID = m_pDBC->getServerNode( m_nServerID );
  161. DBC_SITE_DATA *tSiteData = m_pDBC->getSiteData( m_nSiteID );
  162. if( tSiteData ) {
  163. C3D_WGS84_LOC t;
  164. t.lat = tSiteData->lat;
  165. t.lon = tSiteData->lon;
  166. t.alt = tSiteData->alt;
  167. m_pSystemAnchor = systemAnchor::getInstance( tSiteData->SH, &t );
  168. free( tSiteData );
  169. } else {
  170. LOG_ERROR("Error Loading Site DATA!");
  171. };
  172. //Init Subcomponents
  173. m_pHardwareManager = argusHardwareManager::getInstance( m_bSkipResignComponents );
  174. if( m_pHardwareManager!= NULL ) {
  175. m_pHardwareManager->validate();
  176. } else {
  177. LOG_ERROR("Failure to get HardwareManager Instance!");
  178. return false;
  179. };
  180. //m_pServiceAnnouncer = new ssdpAnnouncer( m_pSettings );
  181. if( basicSettingsProvider::getInstance()->isCompromised() ) {
  182. basicSettingsProvider::getInstance()->validate();
  183. };
  184. m_pEventHeap = basicEventHeap::getInstance();
  185. #ifdef DEBUG
  186. LOG( "Load Filters" );
  187. #endif
  188. loadFilters();
  189. #ifdef DEBUG
  190. LOG( "Filters Loaded" );
  191. #endif
  192. m_pNodeFactory = argusNodeFactory::getInstance();
  193. if( m_pNodeFactory ) {
  194. #ifdef DEBUG
  195. LOG( "Load Nodes" );
  196. #endif
  197. if( !m_pNodeFactory->loadNodes( m_nSiteID ) ){
  198. LOG_ERROR("Error While Loading Nodes!");
  199. }
  200. #ifdef DEBUG
  201. else {
  202. LOG( "Nodes Loaded" );
  203. }
  204. #endif
  205. ;
  206. } else {
  207. LOG_ERROR("Failure to get Node Factory Instance!");
  208. return false;
  209. };
  210. m_pModuleFactory = argusModuleFactory::getInstance();
  211. if( m_pModuleFactory ) {
  212. #ifdef DEBUG
  213. LOG( "Load Modules" );
  214. #endif
  215. if( !m_pModuleFactory->loadModules( m_nServerID ) ){
  216. LOG_ERROR("Error While Loading Modules!");
  217. }
  218. #ifdef DEBUG
  219. else {
  220. LOG( "Modules Loaded" );
  221. }
  222. #endif
  223. ;
  224. } else {
  225. LOG_ERROR("Failure to get Module Factory Instance!");
  226. return false;
  227. };
  228. #ifdef DEBUG
  229. LOG( "Kernel Trhead is about to be Created" );
  230. #endif
  231. if( init() == false ){
  232. LOG_ERROR("Error in starting Kernel Thread!");
  233. return false;
  234. };
  235. #ifdef DEBUG
  236. LOG( "Kernel Thread Created" );
  237. sprintf( tBuffer, "Server is registered as id[%d]", m_nServerID );
  238. LOG( tBuffer );
  239. #endif
  240. return true;
  241. };
  242. void argusKernel::loadFilters(){
  243. if( m_pDBC == NULL ) return;
  244. DBC_INT_LIST *tList = m_pDBC->listFilters( m_nServerID );
  245. if( tList != NULL ) {
  246. if( tList->size() > 0 ) {
  247. for( DBC_INT_LIST::iterator idx = tList->begin(); idx < tList->end(); idx++ ) {
  248. DBC_TARGET_FLITER_DATA *tData = NULL;
  249. tData = m_pDBC->getTargetFilterData( (*idx) );
  250. if( tData != NULL ) {
  251. switch( tData->type ) {
  252. case TF_AUTHORISED_PEOPLE_FILTER: {
  253. ARGUS_APF *tFilter = new ARGUS_APF( tData->aux_id );
  254. if( tFilter != NULL ) {
  255. if( tFilter->initFilter() ){
  256. m_vTargetFilters.push_back( (ARGUS_TARGET_FILTER*) tFilter );
  257. } else {
  258. delete( tFilter );
  259. };
  260. };
  261. break;
  262. };
  263. };
  264. free( tData );
  265. };
  266. };
  267. tList->clear();
  268. };
  269. delete( tList );
  270. } else {
  271. #ifdef DEBUG
  272. LOG("No Target Filters Assigned!");
  273. #endif
  274. };
  275. };
  276. void argusKernel::unloadFilters(){
  277. if( m_vTargetFilters.size() > 0 ) {
  278. #ifdef DEBUG
  279. LOG("Have Filters to Unload");
  280. #endif
  281. for( V_TARGET_FILTERS::iterator idx = m_vTargetFilters.begin(); idx < m_vTargetFilters.end(); idx++ ){
  282. switch( (*idx)->getType() ) {
  283. case TF_AUTHORISED_PEOPLE_FILTER:{
  284. delete( (ARGUS_APF*)(*idx) );
  285. break;
  286. };
  287. default:{
  288. char tBuffer[64];
  289. sprintf( tBuffer, "Unknown Filter: %d", (*idx)->getType() );
  290. LOG( tBuffer );
  291. };
  292. };
  293. };
  294. m_vTargetFilters.clear();
  295. LOG("Unload Filters Done!");
  296. } else {
  297. #ifdef DEBUG
  298. LOG("No Filters to Unload!");
  299. #endif
  300. }
  301. };
  302. ARGUS_TARGET_FILTER *argusKernel::getFilter( uint32_t id ){
  303. ARGUS_TARGET_FILTER *RetVal = NULL;
  304. if( m_vTargetFilters.size() > 0 ) {
  305. for( V_TARGET_FILTERS::iterator idx = m_vTargetFilters.begin(); idx < m_vTargetFilters.end(); idx++ ){
  306. if( (*idx)->getID() == id ) {
  307. RetVal = (*idx);
  308. break;
  309. };
  310. };
  311. };
  312. return RetVal;
  313. };
  314. void argusKernel::WaitFinish( bool Force ){
  315. if( Force ){
  316. #ifdef DEBUG
  317. LOG( "Thread End Forced" );
  318. #endif
  319. } else {
  320. // 3 seconds sleep to settle down processes
  321. SLEEP(3000);
  322. };
  323. waitThreadEnd( Force );
  324. #ifdef DEBUG
  325. if( !Force ) LOG( "Thread is Detached" );
  326. #endif
  327. };
  328. /* Main Kernel Thread Procedure */
  329. void argusKernel::m_fThreadProc( void ){
  330. char Buffer[CTEXT];
  331. time_t tTimeTSeconds;
  332. int lastTSS = 0;
  333. int lastTMS = 0;
  334. DBC_EVT_DATA * tEvtPtr;
  335. pid_t pid = gettid();
  336. char pidBuf[16];
  337. sprintf(pidBuf,"KERNEL pid:%d", pid);
  338. LOG( pidBuf );
  339. #ifdef SIMULATE_KERNEL_TARGETS
  340. LOG("SIMULATION ENABLED");
  341. #endif
  342. m_bThreadStatus = TH_WORKING;
  343. while( m_bThreadStatus < TH_ENDED ){
  344. m_tTimeTSeconds = time( NULL );
  345. // Process Once per Second
  346. if( m_tTimeTSeconds != tTimeTSeconds ){
  347. tTimeTSeconds = m_tTimeTSeconds;
  348. struct sysinfo SI;
  349. struct statvfs DI;
  350. float cpu1 = 0.0f;
  351. float cpu5 = 0.0f;
  352. float cpu15 = 0.0f;
  353. float mem = 0.0f;
  354. float disk = 0.0f;
  355. uint64_t tMEM = 0;
  356. uint64_t tDISK = 0;
  357. uint64_t cMEM = 0;
  358. uint64_t cDISK = 0;
  359. uint32_t cCORES = get_nprocs();
  360. if( sysinfo( &SI ) == 0 ){
  361. float f_load = 100.f / (float)( cCORES * ( 1 << SI_LOAD_SHIFT ) );
  362. cpu1 = SI.loads[0] * f_load;
  363. cpu5 = SI.loads[1] * f_load;
  364. cpu15 = SI.loads[2] * f_load;
  365. tMEM = SI.totalram;
  366. cMEM = SI.totalram - SI.freeram;
  367. mem = (float)cMEM / (float)tMEM;
  368. } else {
  369. LOG_ERROR("Error while getting System Info!");
  370. };
  371. const uint32_t MB = 1 << 10;//(1024 * 1024);// * 1024;
  372. if( statvfs("/", &DI) == 0 ){
  373. tDISK = ( DI.f_blocks * DI.f_frsize ) / MB;
  374. cDISK = ( DI.f_bavail * DI.f_frsize ) / MB;
  375. disk = (float)cDISK / (float)tDISK;
  376. } else {
  377. LOG_ERROR("Error while getting Disk Info!");
  378. };
  379. if( !m_pDBC->updateServerUtilisation( m_nServerID, cCORES, cpu1, cpu5, cpu15, mem, disk, tMEM, cMEM, tDISK, cDISK ) ) LOG_ERROR("Cannot update System Utilisation Stats!");
  380. //Get Queued Commands
  381. DBC_KRNL_CMD *tCMD = NULL;
  382. tCMD = m_pDBC->getActiveCommand( m_nSiteID );
  383. if( tCMD != NULL ){
  384. switch( tCMD->cmd ) {
  385. case ARGUS_CMD_KRNL_RELOAD:{
  386. LOG("Reload ARGUS SERVER!");
  387. m_bThreadStatus = TH_ENDED;
  388. m_bExitCause = 1;
  389. m_pDBC->updateCommand( tCMD->id, ARGUS_CMD_STATUS_FINISHED );
  390. break;
  391. };
  392. case ARGUS_CMD_NODES_RELOAD:{
  393. if( m_pNodeFactory != NULL ) {
  394. m_pNodeFactory->reloadNodes( m_nSiteID );
  395. };
  396. m_pDBC->updateCommand( tCMD->id, ARGUS_CMD_STATUS_FINISHED );
  397. break;
  398. };
  399. case ARGUS_CMD_NODE_RELOAD:{
  400. uint32_t tNodeID = atoi( tCMD->param );
  401. if( m_pNodeFactory != NULL ) {
  402. m_pNodeFactory->reloadNode( tNodeID );
  403. };
  404. m_pDBC->updateCommand( tCMD->id, ARGUS_CMD_STATUS_FINISHED );
  405. break;
  406. };
  407. case ARGUS_CMD_HARDWARE_DETECT:{
  408. if( m_pHardwareManager!= NULL ) {
  409. LOG_ERROR( "Restart and Detect HardWare!" );
  410. // Must be shutdowned all service that uses hardware prior to detection!
  411. //m_pHardwareManager->enumerateHardware();
  412. m_bThreadStatus = TH_ENDED;
  413. m_bExitCause = 4; // Go -> Detect Hardware in BACKEND
  414. };
  415. m_pDBC->updateCommand( tCMD->id, ARGUS_CMD_STATUS_FINISHED );
  416. };
  417. };
  418. free( tCMD );
  419. };
  420. // Validate Hardware
  421. if( m_pHardwareManager!= NULL ) {
  422. if( !m_pHardwareManager->validate() ){
  423. LOG_ERROR( "Restart Because of HW!" );
  424. m_bThreadStatus = TH_ENDED;
  425. m_bExitCause = 0; // 0 to real exit from app
  426. };
  427. };
  428. // Validate Modules
  429. if( m_pModuleFactory != NULL ) {
  430. m_pModuleFactory->validate();
  431. };
  432. // Validate Nodes
  433. if( m_pNodeFactory != NULL ) {
  434. m_pNodeFactory->validate();
  435. };
  436. };// ops loop
  437. SLEEP( SLEEP_KERNEL_INTERVAL );
  438. };
  439. };
  440. /*
  441. int argusKernel::isCameraListed( CSTR uid ){
  442. if( m_vCamRecords.size() ){
  443. for( int index = 0; index < m_vCamRecords.size(); index++ ){
  444. if(strstr(m_vCamRecords.at(index)->uuid,uid)!=NULL){
  445. m_vCamRecords.at(index)->online = true;
  446. return index;
  447. };
  448. };
  449. } else {
  450. LOG("No Registered Cameras!");
  451. };
  452. return -1;
  453. };
  454. void argusKernel::validateCameras( void ){
  455. vectorWoWoResults *DiscoverResults = m_pOnvifMediaObserver->getResults();
  456. if( DiscoverResults->size() > 0 ) {
  457. for (int index = 0; index < DiscoverResults->size(); index++) {
  458. char tBuffer[256];
  459. sprintf( tBuffer,"Found Camwera [%s] %s", DiscoverResults->at(index)->XAddrs, DiscoverResults->at(index)->RefID );
  460. LOG( tBuffer );
  461. uint32_t cid = m_pDBC->getCamId( DiscoverResults->at(index)->RefID ); //isCameraListed( DiscoverResults->at(index)->RefID );
  462. if( cid ) {
  463. sprintf( tBuffer, "Camera is Listed as %d", cid );
  464. LOG( tBuffer );
  465. //if( strstr(DiscoverResults->at(index)->XAddrs,m_vCamRecords.at(cid)->ip)==NULL ) {
  466. // LOG( DiscoverResults->at(index)->XAddrs );
  467. m_pDBC->updateIPCam( m_nSiteID, cid, DiscoverResults->at(index)->XAddrs );// DiscoverResults->at(index));
  468. //};
  469. } else {
  470. // Uncknown camera - no checking
  471. LOG("Camera is Not Listed");
  472. m_pDBC->addIPCam( m_nSiteID, DiscoverResults->at(index) );
  473. };
  474. };
  475. } else {
  476. LOG("No Online IP Cameras in Network");
  477. };
  478. };
  479. void argusKernel::validateEvents( int &lastTSS, int &lastTMS ){
  480. DBC_EVT_DATA *tPtr = NULL;
  481. EVENT_CONTAINER *tEvt = NULL;
  482. if(m_vEvtRecords.size()) {
  483. lastTSS = m_vEvtRecords.at(m_vEvtRecords.size()-1)->ts_s;
  484. lastTMS = m_vEvtRecords.at(m_vEvtRecords.size()-1)->ts_ms;
  485. #ifndef ONE_EVENT_PER_LOOP
  486. while( m_vEvtRecords.size() ){
  487. #endif
  488. tPtr = *m_vEvtRecords.begin();
  489. if( tPtr != NULL ) {
  490. if( tEvt != NULL ) {
  491. m_pEventHeap->broadcast( tEvt );
  492. };
  493. free( tPtr );
  494. };
  495. m_vEvtRecords.erase( m_vEvtRecords.begin() );
  496. #ifndef ONE_EVENT_PER_LOOP
  497. };
  498. #endif
  499. };
  500. };
  501. */
  502. bool argusKernel::signalEvent( void ){
  503. //if( m_pDBC->getLastEvents( m_vEvtRecords, 0,0 ) ){
  504. //};
  505. return true;
  506. };
  507. int argusKernel::getNetNodes( ARGUS_NODE_TYPE type, argusNetNode **&RA ){
  508. RA = NULL;
  509. int cnt = 0;
  510. if( m_pNodeFactory != NULL ){
  511. cnt = m_pNodeFactory->getNodesCount( type );
  512. if( cnt ) {
  513. RA = (argusNetNode **) calloc( cnt, sizeof( argusNetNode * ) );
  514. m_pNodeFactory->fetchNodes(type, RA );
  515. };
  516. };
  517. return cnt;
  518. };
  519. argusNetNode *argusKernel::getNetNode( int id ){
  520. if( m_pNodeFactory != NULL ){
  521. return m_pNodeFactory->getNode( id );
  522. };
  523. return NULL;
  524. };
  525. /*
  526. int argusKernel::getModules( ARGUS_MODULE_TYPE type, argusKernelModule **&RA ){
  527. RA = NULL;
  528. int cnt = 0;
  529. if( m_pModuleFactory != NULL ){
  530. cnt = m_pModuleFactory->getModulesCount( type );
  531. if( cnt ) {
  532. RA = (argusKernelModule **) calloc( cnt, sizeof( argusKernelModule * ) );
  533. m_pModuleFactory->fetchModules( type, RA );
  534. };
  535. };
  536. return cnt;
  537. };
  538. argusKernelModule *argusKernel::getModule( int id ){
  539. if( m_pModuleFactory != NULL ){
  540. return m_pModuleFactory->getModule( id );
  541. };
  542. return NULL;
  543. };
  544. */
  545. void argusKernel::dispatchEvent( EVENT_CONTAINER *Evt ){
  546. // Register all events in Database;
  547. //LOG( "New EVENT!!" );
  548. if( m_pDBC == NULL ) return;
  549. if( Evt == NULL ) return;
  550. switch( Evt->m_eClass ) {
  551. case EVT_CLASS_EXTERNAL_CMD:
  552. switch( Evt->m_eType ){
  553. case EVT_FH_JAMER_ON:{
  554. uint32_t TS_A, TS_B;
  555. TS_A = Evt->m_UMSTS / 1000;
  556. TS_B = Evt->m_UMSTS % 1000;
  557. #ifdef SIMULATE_KERNEL_TARGETS
  558. m_bJamingTO = SIMULATE_JAMER_TO;
  559. #endif
  560. FH_CTRL_DATA * tData = (FH_CTRL_DATA *) Evt->m_pEvtData;
  561. if( tData ) {
  562. if( m_pDBC->addEvent(
  563. 0,
  564. Evt->m_UUID,
  565. TS_A,
  566. TS_B,
  567. EVT_FH_JAMER_ON,
  568. 0,
  569. 0,
  570. 0,
  571. 0,
  572. 0,
  573. 0,
  574. 0,
  575. 0,
  576. 0,
  577. tData->evtUUID
  578. ) ){
  579. //Simulate FH Module Event;
  580. EVENT_CONTAINER *ttt;
  581. FH_MISSION_DATA * nnn = (FH_MISSION_DATA *) malloc( sizeof(FH_MISSION_DATA));
  582. if( nnn ){
  583. nnn->location.lat = 0;
  584. nnn->location.lon = 0;
  585. nnn->location.alt = 0;
  586. sprintf( nnn->missionID, tData->evtUUID );
  587. ttt = createBasicEvent( 0, EVT_CLASS_FLY_HUNTER, EVT_FH_JAMER_ON, NULL, NULL, nnn );
  588. if( ttt ) {
  589. m_pEventHeap->broadcast( ttt );
  590. } else {
  591. free( nnn );
  592. };
  593. };
  594. };
  595. free(tData);
  596. };
  597. break;
  598. };
  599. case EVT_FH_MISSION_END:{
  600. FH_CTRL_DATA * tData = (FH_CTRL_DATA *) Evt->m_pEvtData;
  601. if( tData ) {
  602. //DBC_EVT_DATA * tEVT = m_pDBC->getEventByUUID( tData->targetUUID );
  603. if( 1 /*tEVT*/ ) {
  604. uint32_t TS_A, TS_B;
  605. TS_A = Evt->m_UMSTS / 1000;
  606. TS_B = Evt->m_UMSTS % 1000;
  607. if( m_pDBC->addEvent(
  608. 0,
  609. Evt->m_UUID,
  610. TS_A,
  611. TS_B,
  612. EVT_FH_LANDED ) ){
  613. //Simulate FH Module Event;
  614. EVENT_CONTAINER *ttt;
  615. FH_MISSION_DATA * nnn = (FH_MISSION_DATA *) malloc( sizeof(FH_MISSION_DATA));
  616. if( nnn ){
  617. nnn->location.lat = 0;
  618. nnn->location.lon = 0;
  619. nnn->location.alt = 0;
  620. sprintf( nnn->missionID, tData->evtUUID );
  621. ttt = createBasicEvent( 0, EVT_CLASS_FLY_HUNTER, EVT_FH_LANDED, NULL, NULL, nnn );
  622. if( ttt ) {
  623. m_pEventHeap->broadcast( ttt );
  624. } else {
  625. free( nnn );
  626. };
  627. };
  628. };
  629. //free( tEVT );
  630. } else {
  631. LOG_ERROR("Linked Event Was Not Found!");
  632. };
  633. };
  634. break;
  635. }
  636. case EVT_FH_MISSION_BEGIN:{
  637. FH_CTRL_DATA * tData = (FH_CTRL_DATA *) Evt->m_pEvtData;
  638. #ifdef SIMULATE_KERNEL_TARGETS
  639. m_bLandingTO = SIMULATE_LANDING_TO;
  640. #endif
  641. if( tData ) {
  642. #ifdef SIMULATE_KERNEL_TARGETS
  643. sprintf( m_cCurrentMission, tData->evtUUID );
  644. #endif
  645. DBC_EVT_DATA * tEVT = m_pDBC->getEventByUUID( tData->targetUUID );
  646. if( tEVT ) {
  647. uint32_t TS_A, TS_B;
  648. TS_A = Evt->m_UMSTS / 1000;
  649. TS_B = Evt->m_UMSTS % 1000;
  650. if( Evt->m_db_id = m_pDBC->addEvent(
  651. 0,
  652. Evt->m_UUID,
  653. TS_A,
  654. TS_B,
  655. EVT_FH_FLY_TO,
  656. 0,
  657. 0,
  658. 0,
  659. 0,
  660. 0,
  661. tEVT->lat,
  662. tEVT->lon,
  663. tEVT->alt,
  664. tEVT->id,
  665. tEVT->uuid
  666. ) ){
  667. //Simulate FH Module Event;
  668. EVENT_CONTAINER *ttt;
  669. FH_MISSION_DATA * nnn = (FH_MISSION_DATA *) malloc( sizeof(FH_MISSION_DATA));
  670. if( nnn ){
  671. nnn->location.lat = tEVT->lat;
  672. nnn->location.lon = tEVT->lon;
  673. nnn->location.alt = tEVT->alt;
  674. sprintf( nnn->missionID, tData->evtUUID );
  675. ttt = createBasicEvent( 0, EVT_CLASS_FLY_HUNTER, EVT_FH_MISSION_BEGIN, NULL, NULL, nnn );
  676. if( ttt ) {
  677. m_pEventHeap->broadcast( ttt );
  678. } else {
  679. free( nnn );
  680. };
  681. };
  682. };
  683. free( tEVT );
  684. } else {
  685. LOG_ERROR("Linked Event Was Not Found!");
  686. };
  687. };
  688. break;
  689. };
  690. };
  691. break;
  692. case EVT_CLASS_SENSOR_CLD:
  693. case EVT_CLASS_SENSOR_LGS:
  694. case EVT_CLASS_SENSOR_LFS:
  695. case EVT_CLASS_SENSOR_MND:
  696. case EVT_CLASS_SENSOR_PLS_210:
  697. case EVT_CLASS_SENSOR_PLS_360:
  698. case EVT_CLASS_SENSOR_ALS:
  699. case EVT_CLASS_SENSOR_3D:
  700. case EVT_CLASS_SENSOR_ACC:
  701. switch( Evt->m_eType ) {
  702. case EVT_TARGET_1D:{
  703. TARGET_DATA *tDATA =(TARGET_DATA *) Evt->m_pEvtData;
  704. if( tDATA != NULL ) {
  705. uint32_t TS_A, TS_B;
  706. TS_A = Evt->m_UMSTS / 1000;
  707. TS_B = Evt->m_UMSTS % 1000;
  708. Evt->m_db_id = m_pDBC->addEvent(
  709. Evt->m_nSourceUID,
  710. Evt->m_UUID,
  711. TS_A,
  712. TS_B,
  713. Evt->m_eType,
  714. tDATA->digital,
  715. 0,
  716. 0,
  717. tDATA->local_target.r,
  718. tDATA->area,
  719. tDATA->global_target.lat,
  720. tDATA->global_target.lon,
  721. tDATA->global_target.alt
  722. );
  723. };
  724. break;
  725. };
  726. case EVT_TARGET_2D_BLACK:
  727. case EVT_TARGET_2D_WHITE:{
  728. TARGET_DATA *tDATA = (TARGET_DATA *)Evt->m_pEvtData;
  729. if( tDATA != NULL ) {
  730. uint32_t TS_A, TS_B;
  731. TS_A = Evt->m_UMSTS / 1000;
  732. TS_B = Evt->m_UMSTS % 1000;
  733. Evt->m_db_id = m_pDBC->addEvent(
  734. Evt->m_nSourceUID,
  735. Evt->m_UUID,
  736. TS_A,
  737. TS_B,
  738. Evt->m_eType,
  739. tDATA->digital,
  740. tDATA->local_target.tetta,
  741. tDATA->local_target.fi,
  742. tDATA->local_target.r,
  743. tDATA->area,
  744. tDATA->global_target.lat,
  745. tDATA->global_target.lon,
  746. tDATA->global_target.alt
  747. );
  748. };
  749. break;
  750. };
  751. case EVT_TARGET_3D_BLACK:
  752. case EVT_TARGET_3D_WHITE:{
  753. TARGET_DATA *tDATA = (TARGET_DATA *) Evt->m_pEvtData;
  754. if( tDATA != NULL ) {
  755. uint32_t TS_A, TS_B;
  756. TS_A = Evt->m_UMSTS / 1000;
  757. TS_B = Evt->m_UMSTS % 1000;
  758. Evt->m_db_id = m_pDBC->addEvent(
  759. Evt->m_nSourceUID,
  760. Evt->m_UUID,
  761. TS_A,
  762. TS_B,
  763. Evt->m_eType,
  764. tDATA->digital,
  765. tDATA->local_target.tetta,
  766. tDATA->local_target.fi,
  767. tDATA->local_target.r,
  768. tDATA->area,
  769. tDATA->global_target.lat,
  770. tDATA->global_target.lon,
  771. tDATA->global_target.alt
  772. );
  773. };
  774. break;
  775. };
  776. case EVT_FLIP:{
  777. uint32_t TS_A, TS_B;
  778. TS_A = Evt->m_UMSTS / 1000;
  779. TS_B = Evt->m_UMSTS % 1000;
  780. Evt->m_db_id = m_pDBC->addEvent( Evt->m_nSourceUID, Evt->m_UUID, TS_A, TS_B, Evt->m_eType);
  781. break;
  782. };
  783. };
  784. break;
  785. case EVT_CLASS_VIDEO:{
  786. switch( Evt->m_eType ) {
  787. case EVT_CAPTURE_START:{
  788. break;
  789. };
  790. };
  791. break;
  792. };
  793. };
  794. };
  795. #undef LOG
  796. #undef LOG_ERROR