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.

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