/******************************************************************* * * DESCRIPTION: ARGUS Kernel source * * AUTHOR: gagua * * HISTORY: * * DATE:5/29/2019 * *******************************************************************/ #include "RGoose_Kernel.h" #include #define LOG( X ) m_pLog->Log( "KRNL", this, X ) #define LOG_ERROR( X ) m_pLog->Log( "KRNL", this, _LOG_ERROR, X ) ARGUS_Kernel::ARGUS_Kernel( config_setting_t *Settings ):basicThread(){ m_bExitCause = 0; m_nSiteID = 0; m_tTimeTSeconds = time( NULL ); m_pLog = basicLogCollection::getInstance(); m_pEventHeap = basicEventHeap::getInstance(); m_pSettings = basicSettingsProvider::getInstance()->getSubNode( Settings, "KERNEL" ); if( basicSettingsProvider::getInstance()->isCompromised() ) { basicSettingsProvider::getInstance()->validate(); }; }; ARGUS_Kernel::~ARGUS_Kernel(){ #ifdef DEBUG LOG("Destructor"); #endif WaitFinish(true); #ifdef DEBUG LOG("Deleting Components"); #endif #ifdef DEBUG LOG("Destructor Finished"); #endif }; bool ARGUS_Kernel::create( void ){ char tBuffer[256]; if( m_pSettings != NULL ) { config_setting_t * pSetting; int tVal; const char * tBuf; //Connect( CSTR DBName, CSTR DBHost, CSTR DBUser, CSTR DBPassword, uint16_t Port = 3300 ); LOG("Getting Settings ..."); if( !config_setting_lookup_string( m_pSettings, ARGUS_KERNEL_TAG_SERVER_IDENTITY, &tBuf ) ){ char * tVar; char * tTS; tTS = getTStr(NULL); tVar = MD5String(tTS); free(tTS); sprintf( m_sIdentity, tVar ); pSetting = config_setting_add( m_pSettings, ARGUS_KERNEL_TAG_SERVER_IDENTITY, CONFIG_TYPE_STRING ); config_setting_set_string( pSetting, tVar ); free( tVar ); basicSettingsProvider::getInstance()->compromise(); LOG("Server Identity not defined - generating new!"); } else { sprintf( m_sIdentity, tBuf ); sprintf( tBuffer, "Server Identity Read From Settings: %s", tBuf ); LOG( tBuffer ); }; if( !config_setting_lookup_int( m_pSettings, ARGUS_KERNEL_TAG_SITE_ID, &tVal ) ){ tVal = m_nSiteID = 1; pSetting = config_setting_add( m_pSettings, ARGUS_KERNEL_TAG_SITE_ID, CONFIG_TYPE_INT ); config_setting_set_int( pSetting, tVal ); basicSettingsProvider::getInstance()->compromise(); LOG("Site ID not defined - using [1] as number!"); } else { m_nSiteID = tVal; sprintf( tBuffer, "Site ID Read From Settings: %d", m_nSiteID ); LOG( tBuffer ); }; /* #ifdef __EU_PROJECT__ if( !config_setting_lookup_bool( m_pSettings, KNL_SETTINGS_SAFE_SHORE, &tVal ) ){ tVal = m_bSafeShoreSupport = true; pSetting = config_setting_add( m_pSettings, KNL_SETTINGS_SAFE_SHORE, CONFIG_TYPE_BOOL ); config_setting_set_bool( pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("Safe-Shore support not defined"); } else { m_bSafeShoreSupport = (bool)tVal; sprintf( tBuffer, "Safe-Shore support Read From Settings: %d", tVal ); LOG( tBuffer ); }; #endif if( !config_setting_lookup_bool( m_pSettings, KNL_SETTINGS_DEFENDER, &tVal ) ){ tVal = m_bDefenderSupport = true; pSetting = config_setting_add( m_pSettings, KNL_SETTINGS_DEFENDER, CONFIG_TYPE_BOOL ); config_setting_set_bool( pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("Defender support not defined"); } else { m_bDefenderSupport = (bool)tVal; sprintf( tBuffer, "Defender support Read From Settings: %d", tVal ); LOG( tBuffer ); }; if (!config_setting_lookup_int(m_pSettings, KNL_SETTINGS_DETECTOR_WIDTH, &tVal )){ tVal = m_nWidth = 1000; pSetting = config_setting_add(m_pSettings, KNL_SETTINGS_DETECTOR_WIDTH, CONFIG_TYPE_INT); config_setting_set_int(pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No Detector Width"); } else { m_nWidth = tVal; sprintf( tBuffer, "Detector Width Read From Settings: %d", tVal ); LOG( tBuffer ); }; if (!config_setting_lookup_int(m_pSettings, KNL_SETTINGS_FILTER_KERNELS, &tVal )){ tVal = m_nKernelFilter = 0x000000ff; pSetting = config_setting_add(m_pSettings, KNL_SETTINGS_FILTER_KERNELS, CONFIG_TYPE_INT); config_setting_set_int(pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No Fltered Kernels Defined - All LRF Will Work"); } else { m_nKernelFilter = tVal; sprintf( tBuffer, "Filter Kernels Read From Settings: %d", tVal ); LOG( tBuffer ); }; if (!config_setting_lookup_int(m_pSettings, KNL_SETTINGS_DETECTOR_SST, &tVal )){ tVal = m_nSST = 0; pSetting = config_setting_add(m_pSettings, KNL_SETTINGS_DETECTOR_SST, CONFIG_TYPE_INT); config_setting_set_int(pSetting, tVal ); m_pSettingsProvider->compromise(); LOG("No Detector SST"); } else { m_nSST = tVal; sprintf( tBuffer, "Detector SST Read From Settings: %d", tVal ); LOG( tBuffer ); }; if( m_pSettingsProvider->isCompromised() ) { LOG("Save Settings"); m_pSettingsProvider->validate(); }; */ } else { LOG_ERROR("Failed Read Config Settings!"); return false; }; #ifdef DEBUG LOG( "Settings Read Done" ); #endif #ifdef DEBUG LOG( "Kernel Trhead is about to be Created" ); #endif if( init() == false ){ LOG_ERROR("Error in starting Kernel Thread!"); return false; }; #ifdef DEBUG LOG( "Kernel Thread Created" ); #endif return true; }; void ARGUS_Kernel::WaitFinish( bool Force ){ if( Force ){ #ifdef DEBUG LOG( "Thread End Forced" ); #endif } else { // 3 seconds sleep to settle down processes SLEEP(3000); }; waitThreadEnd( Force ); #ifdef DEBUG LOG( "Thread is Detached" ); #endif }; /* Main Kernel Thread Procedure */ void ARGUS_Kernel::m_fThreadProc( void ){ char Buffer[CTEXT]; time_t tTimeTSeconds; int lastTSS = 0; int lastTMS = 0; #ifdef DEBUG pid_t pid = gettid(); char pidBuf[16]; sprintf(pidBuf,"pid:%d", pid); LOG(pidBuf); #endif m_bThreadStatus = TH_WORKING; while( m_bThreadStatus < TH_ENDED ){ m_tTimeTSeconds = time( NULL ); if( m_tTimeTSeconds != tTimeTSeconds ){ // Each Second Process tTimeTSeconds = m_tTimeTSeconds; }; SLEEP( SLEEP_KERNEL_INTERVAL ); }; }; bool ARGUS_Kernel::setStatus( int A ){ m_bThreadStatus = (thredStatus)A; }; #undef LOG #undef LOG_ERROR