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.

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