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.

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