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.

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