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.

826 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_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_PUSHED_CMD *tCMD = m_pDBC->getNodePushedCMD( m_nServerNodeID );
  364. //tCMD = m_pDBC->getActiveSiteCommand( m_nSiteID );
  365. if( tCMD != NULL ){
  366. switch( tCMD->CMD ) {
  367. case ARGUS_CMD_KRNL_RELOAD:{
  368. LOG("Reload ARGUS SERVER!");
  369. m_bThreadStatus = TH_ENDED;
  370. m_bExitCause = 1;
  371. break;
  372. };
  373. case ARGUS_CMD_KRNL_RESTART:{
  374. LOG("Restart ARGUS SERVER!");
  375. m_bThreadStatus = TH_ENDED;
  376. m_bExitCause = 0;
  377. break;
  378. };
  379. case ARGUS_CMD_NODES_RELOAD:{
  380. if( m_pNodeFactory != NULL ) {
  381. m_pNodeFactory->reloadNodes( m_nSiteID );
  382. };
  383. break;
  384. };
  385. case ARGUS_CMD_NODE_RELOAD:{
  386. uint32_t tNodeID = atoi( tCMD->PARAM );
  387. if( m_pNodeFactory != NULL ) {
  388. m_pNodeFactory->reloadNode( tNodeID );
  389. };
  390. break;
  391. };
  392. case ARGUS_CMD_KRNL_PNP:{
  393. if( m_pHardwareManager!= NULL ) {
  394. LOG_ERROR( "Restart and Detect HardWare!" );
  395. // Must be shutdowned all service that uses hardware prior to detection!
  396. // m_pHardwareManager->enumerateHardware();
  397. m_bThreadStatus = TH_ENDED;
  398. m_bExitCause = 4; // Go -> Detect Hardware in BACKEND
  399. };
  400. break;
  401. };
  402. };
  403. free( tCMD );
  404. };
  405. // Validate Hardware
  406. if( m_pHardwareManager!= NULL ) {
  407. if( !m_pHardwareManager->validate() ){
  408. LOG_ERROR( "Restart Because of HW!" );
  409. m_bThreadStatus = TH_ENDED;
  410. m_bExitCause = 0; // 0 to real exit from app
  411. };
  412. };
  413. // Validate Modules
  414. if( m_pModuleFactory != NULL ) {
  415. m_pModuleFactory->validate();
  416. };
  417. // Validate Nodes
  418. if( m_pNodeFactory != NULL ) {
  419. m_pNodeFactory->validate();
  420. };
  421. };// ops loop
  422. SLEEP( SLEEP_KERNEL_INTERVAL );
  423. };
  424. };
  425. /*
  426. int argusKernel::isCameraListed( CSTR uid ){
  427. if( m_vCamRecords.size() ){
  428. for( int index = 0; index < m_vCamRecords.size(); index++ ){
  429. if(strstr(m_vCamRecords.at(index)->uuid,uid)!=NULL){
  430. m_vCamRecords.at(index)->online = true;
  431. return index;
  432. };
  433. };
  434. } else {
  435. LOG("No Registered Cameras!");
  436. };
  437. return -1;
  438. };
  439. void argusKernel::validateCameras( void ){
  440. vectorWoWoResults *DiscoverResults = m_pOnvifMediaObserver->getResults();
  441. if( DiscoverResults->size() > 0 ) {
  442. for (int index = 0; index < DiscoverResults->size(); index++) {
  443. char tBuffer[256];
  444. sprintf( tBuffer,"Found Camwera [%s] %s", DiscoverResults->at(index)->XAddrs, DiscoverResults->at(index)->RefID );
  445. LOG( tBuffer );
  446. uint32_t cid = m_pDBC->getCamId( DiscoverResults->at(index)->RefID ); //isCameraListed( DiscoverResults->at(index)->RefID );
  447. if( cid ) {
  448. sprintf( tBuffer, "Camera is Listed as %d", cid );
  449. LOG( tBuffer );
  450. //if( strstr(DiscoverResults->at(index)->XAddrs,m_vCamRecords.at(cid)->ip)==NULL ) {
  451. // LOG( DiscoverResults->at(index)->XAddrs );
  452. m_pDBC->updateIPCam( m_nSiteID, cid, DiscoverResults->at(index)->XAddrs );// DiscoverResults->at(index));
  453. //};
  454. } else {
  455. // Uncknown camera - no checking
  456. LOG("Camera is Not Listed");
  457. m_pDBC->addIPCam( m_nSiteID, DiscoverResults->at(index) );
  458. };
  459. };
  460. } else {
  461. LOG("No Online IP Cameras in Network");
  462. };
  463. };
  464. void argusKernel::validateEvents( int &lastTSS, int &lastTMS ){
  465. DBC_EVT_DATA *tPtr = NULL;
  466. EVENT_CONTAINER *tEvt = NULL;
  467. if(m_vEvtRecords.size()) {
  468. lastTSS = m_vEvtRecords.at(m_vEvtRecords.size()-1)->ts_s;
  469. lastTMS = m_vEvtRecords.at(m_vEvtRecords.size()-1)->ts_ms;
  470. #ifndef ONE_EVENT_PER_LOOP
  471. while( m_vEvtRecords.size() ){
  472. #endif
  473. tPtr = *m_vEvtRecords.begin();
  474. if( tPtr != NULL ) {
  475. if( tEvt != NULL ) {
  476. m_pEventHeap->broadcast( tEvt );
  477. };
  478. free( tPtr );
  479. };
  480. m_vEvtRecords.erase( m_vEvtRecords.begin() );
  481. #ifndef ONE_EVENT_PER_LOOP
  482. };
  483. #endif
  484. };
  485. };
  486. */
  487. bool argusKernel::signalEvent( void ){
  488. //if( m_pDBC->getLastEvents( m_vEvtRecords, 0,0 ) ){
  489. //};
  490. return true;
  491. };
  492. int argusKernel::getNetNodes( ARGUS_NODE_TYPE type, argusNetNode **&RA ){
  493. RA = NULL;
  494. int cnt = 0;
  495. if( m_pNodeFactory != NULL ){
  496. cnt = m_pNodeFactory->getNodesCount( type );
  497. if( cnt ) {
  498. RA = (argusNetNode **) calloc( cnt, sizeof( argusNetNode * ) );
  499. m_pNodeFactory->fetchNodes(type, RA );
  500. };
  501. };
  502. return cnt;
  503. };
  504. argusNetNode *argusKernel::getNetNode( int id ){
  505. if( m_pNodeFactory != NULL ){
  506. return m_pNodeFactory->getNode( id );
  507. };
  508. return NULL;
  509. };
  510. /*
  511. int argusKernel::getModules( ARGUS_MODULE_TYPE type, argusKernelModule **&RA ){
  512. RA = NULL;
  513. int cnt = 0;
  514. if( m_pModuleFactory != NULL ){
  515. cnt = m_pModuleFactory->getModulesCount( type );
  516. if( cnt ) {
  517. RA = (argusKernelModule **) calloc( cnt, sizeof( argusKernelModule * ) );
  518. m_pModuleFactory->fetchModules( type, RA );
  519. };
  520. };
  521. return cnt;
  522. };
  523. argusKernelModule *argusKernel::getModule( int id ){
  524. if( m_pModuleFactory != NULL ){
  525. return m_pModuleFactory->getModule( id );
  526. };
  527. return NULL;
  528. };
  529. */
  530. void argusKernel::dispatchEvent( EVENT_CONTAINER *Evt ){
  531. // Register all events in Database;
  532. //LOG( "New EVENT!!" );
  533. if( m_pDBC == NULL ) return;
  534. if( Evt == NULL ) return;
  535. switch( Evt->m_eClass ) {
  536. case EVT_CLASS_EXTERNAL_CMD:
  537. switch( Evt->m_eType ){
  538. case EVT_FH_JAMER_ON:{
  539. uint32_t TS_A, TS_B;
  540. TS_A = Evt->m_UMSTS / 1000;
  541. TS_B = Evt->m_UMSTS % 1000;
  542. #ifdef SIMULATE_KERNEL_TARGETS
  543. m_bJamingTO = SIMULATE_JAMER_TO;
  544. #endif
  545. FH_CTRL_DATA * tData = (FH_CTRL_DATA *) Evt->m_pEvtData;
  546. if( tData ) {
  547. if( m_pDBC->addEvent(
  548. 0,
  549. Evt->m_UUID,
  550. TS_A,
  551. TS_B,
  552. EVT_FH_JAMER_ON,
  553. 0,
  554. 0,
  555. 0,
  556. 0,
  557. 0,
  558. 0,
  559. 0,
  560. 0,
  561. 0,
  562. tData->evtUUID
  563. ) ){
  564. //Simulate FH Module Event;
  565. EVENT_CONTAINER *ttt;
  566. FH_MISSION_DATA * nnn = (FH_MISSION_DATA *) malloc( sizeof(FH_MISSION_DATA));
  567. if( nnn ){
  568. nnn->location.lat = 0;
  569. nnn->location.lon = 0;
  570. nnn->location.alt = 0;
  571. sprintf( nnn->missionID, tData->evtUUID );
  572. ttt = createBasicEvent( 0, EVT_CLASS_FLY_HUNTER, EVT_FH_JAMER_ON, NULL, NULL, nnn );
  573. if( ttt ) {
  574. m_pEventHeap->broadcast( ttt );
  575. } else {
  576. free( nnn );
  577. };
  578. };
  579. };
  580. free(tData);
  581. };
  582. break;
  583. };
  584. case EVT_FH_MISSION_END:{
  585. FH_CTRL_DATA * tData = (FH_CTRL_DATA *) Evt->m_pEvtData;
  586. if( tData ) {
  587. //DBC_EVT_DATA * tEVT = m_pDBC->getEventByUUID( tData->targetUUID );
  588. if( 1 /*tEVT*/ ) {
  589. uint32_t TS_A, TS_B;
  590. TS_A = Evt->m_UMSTS / 1000;
  591. TS_B = Evt->m_UMSTS % 1000;
  592. if( m_pDBC->addEvent(
  593. 0,
  594. Evt->m_UUID,
  595. TS_A,
  596. TS_B,
  597. EVT_FH_LANDED ) ){
  598. //Simulate FH Module Event;
  599. EVENT_CONTAINER *ttt;
  600. FH_MISSION_DATA * nnn = (FH_MISSION_DATA *) malloc( sizeof(FH_MISSION_DATA));
  601. if( nnn ){
  602. nnn->location.lat = 0;
  603. nnn->location.lon = 0;
  604. nnn->location.alt = 0;
  605. sprintf( nnn->missionID, tData->evtUUID );
  606. ttt = createBasicEvent( 0, EVT_CLASS_FLY_HUNTER, EVT_FH_LANDED, NULL, NULL, nnn );
  607. if( ttt ) {
  608. m_pEventHeap->broadcast( ttt );
  609. } else {
  610. free( nnn );
  611. };
  612. };
  613. };
  614. //free( tEVT );
  615. } else {
  616. LOG_ERROR("Linked Event Was Not Found!");
  617. };
  618. };
  619. break;
  620. }
  621. case EVT_FH_MISSION_BEGIN:{
  622. FH_CTRL_DATA * tData = (FH_CTRL_DATA *) Evt->m_pEvtData;
  623. #ifdef SIMULATE_KERNEL_TARGETS
  624. m_bLandingTO = SIMULATE_LANDING_TO;
  625. #endif
  626. if( tData ) {
  627. #ifdef SIMULATE_KERNEL_TARGETS
  628. sprintf( m_cCurrentMission, tData->evtUUID );
  629. #endif
  630. DBC_EVT_DATA * tEVT = m_pDBC->getEventByUUID( tData->targetUUID );
  631. if( tEVT ) {
  632. uint32_t TS_A, TS_B;
  633. TS_A = Evt->m_UMSTS / 1000;
  634. TS_B = Evt->m_UMSTS % 1000;
  635. if( Evt->m_db_id = m_pDBC->addEvent(
  636. 0,
  637. Evt->m_UUID,
  638. TS_A,
  639. TS_B,
  640. EVT_FH_FLY_TO,
  641. 0,
  642. 0,
  643. 0,
  644. 0,
  645. 0,
  646. tEVT->lat,
  647. tEVT->lon,
  648. tEVT->alt,
  649. tEVT->id,
  650. tEVT->uuid
  651. ) ){
  652. //Simulate FH Module Event;
  653. EVENT_CONTAINER *ttt;
  654. FH_MISSION_DATA * nnn = (FH_MISSION_DATA *) malloc( sizeof(FH_MISSION_DATA));
  655. if( nnn ){
  656. nnn->location.lat = tEVT->lat;
  657. nnn->location.lon = tEVT->lon;
  658. nnn->location.alt = tEVT->alt;
  659. sprintf( nnn->missionID, tData->evtUUID );
  660. ttt = createBasicEvent( 0, EVT_CLASS_FLY_HUNTER, EVT_FH_MISSION_BEGIN, NULL, NULL, nnn );
  661. if( ttt ) {
  662. m_pEventHeap->broadcast( ttt );
  663. } else {
  664. free( nnn );
  665. };
  666. };
  667. };
  668. free( tEVT );
  669. } else {
  670. LOG_ERROR("Linked Event Was Not Found!");
  671. };
  672. };
  673. break;
  674. };
  675. };
  676. break;
  677. case EVT_CLASS_SENSOR_CLD:
  678. case EVT_CLASS_SENSOR_LGS:
  679. case EVT_CLASS_SENSOR_LFS:
  680. case EVT_CLASS_SENSOR_MND:
  681. case EVT_CLASS_SENSOR_PLS_210:
  682. case EVT_CLASS_SENSOR_PLS_360:
  683. case EVT_CLASS_SENSOR_ALS:
  684. case EVT_CLASS_SENSOR_3D:
  685. case EVT_CLASS_SENSOR_ACC:
  686. switch( Evt->m_eType ) {
  687. case EVT_TARGET_1D:{
  688. TARGET_DATA *tDATA =(TARGET_DATA *) Evt->m_pEvtData;
  689. if( tDATA != NULL ) {
  690. uint32_t TS_A, TS_B;
  691. TS_A = Evt->m_UMSTS / 1000;
  692. TS_B = Evt->m_UMSTS % 1000;
  693. Evt->m_db_id = m_pDBC->addEvent(
  694. Evt->m_nSourceUID,
  695. Evt->m_UUID,
  696. TS_A,
  697. TS_B,
  698. Evt->m_eType,
  699. tDATA->digital,
  700. 0,
  701. 0,
  702. tDATA->local_target.r,
  703. tDATA->area,
  704. tDATA->global_target.lat,
  705. tDATA->global_target.lon,
  706. tDATA->global_target.alt
  707. );
  708. };
  709. break;
  710. };
  711. case EVT_TARGET_2D_BLACK:
  712. case EVT_TARGET_2D_WHITE:{
  713. TARGET_DATA *tDATA = (TARGET_DATA *)Evt->m_pEvtData;
  714. if( tDATA != NULL ) {
  715. uint32_t TS_A, TS_B;
  716. TS_A = Evt->m_UMSTS / 1000;
  717. TS_B = Evt->m_UMSTS % 1000;
  718. Evt->m_db_id = m_pDBC->addEvent(
  719. Evt->m_nSourceUID,
  720. Evt->m_UUID,
  721. TS_A,
  722. TS_B,
  723. Evt->m_eType,
  724. tDATA->digital,
  725. tDATA->local_target.tetta,
  726. tDATA->local_target.fi,
  727. tDATA->local_target.r,
  728. tDATA->area,
  729. tDATA->global_target.lat,
  730. tDATA->global_target.lon,
  731. tDATA->global_target.alt
  732. );
  733. };
  734. break;
  735. };
  736. case EVT_TARGET_3D_BLACK:
  737. case EVT_TARGET_3D_WHITE:{
  738. TARGET_DATA *tDATA = (TARGET_DATA *) Evt->m_pEvtData;
  739. if( tDATA != NULL ) {
  740. uint32_t TS_A, TS_B;
  741. TS_A = Evt->m_UMSTS / 1000;
  742. TS_B = Evt->m_UMSTS % 1000;
  743. Evt->m_db_id = m_pDBC->addEvent(
  744. Evt->m_nSourceUID,
  745. Evt->m_UUID,
  746. TS_A,
  747. TS_B,
  748. Evt->m_eType,
  749. tDATA->digital,
  750. tDATA->local_target.tetta,
  751. tDATA->local_target.fi,
  752. tDATA->local_target.r,
  753. tDATA->area,
  754. tDATA->global_target.lat,
  755. tDATA->global_target.lon,
  756. tDATA->global_target.alt
  757. );
  758. };
  759. break;
  760. };
  761. case EVT_FLIP:{
  762. uint32_t TS_A, TS_B;
  763. TS_A = Evt->m_UMSTS / 1000;
  764. TS_B = Evt->m_UMSTS % 1000;
  765. Evt->m_db_id = m_pDBC->addEvent( Evt->m_nSourceUID, Evt->m_UUID, TS_A, TS_B, Evt->m_eType);
  766. break;
  767. };
  768. };
  769. break;
  770. case EVT_CLASS_VIDEO:{
  771. switch( Evt->m_eType ) {
  772. case EVT_CAPTURE_START:{
  773. break;
  774. };
  775. };
  776. break;
  777. };
  778. };
  779. };
  780. #undef LOG
  781. #undef LOG_ERROR