diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-08-24 04:54:47 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-08-24 04:54:47 +0200 |
commit | 677cd7bcd2ec48d7ffd756ee8cf33a9de06a32de (patch) | |
tree | 6719428d9032fe0eccaf67ecf904e2c22dfdabc6 /src | |
parent | f9baebd7f99d762433479aa1b62e20a1c04a5385 (diff) | |
download | abrt-677cd7bcd2ec48d7ffd756ee8cf33a9de06a32de.tar.gz abrt-677cd7bcd2ec48d7ffd756ee8cf33a9de06a32de.tar.xz abrt-677cd7bcd2ec48d7ffd756ee8cf33a9de06a32de.zip |
class CMiddleWare no longer exists, it's a set of functions and lone data member now
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/Daemon/CrashWatcher.cpp | 34 | ||||
-rw-r--r-- | src/Daemon/CrashWatcher.h | 2 | ||||
-rw-r--r-- | src/Daemon/Daemon.cpp | 41 | ||||
-rw-r--r-- | src/Daemon/MiddleWare.cpp | 145 | ||||
-rw-r--r-- | src/Daemon/MiddleWare.h | 415 |
5 files changed, 300 insertions, 337 deletions
diff --git a/src/Daemon/CrashWatcher.cpp b/src/Daemon/CrashWatcher.cpp index c1d7f50d..ca6ff43e 100644 --- a/src/Daemon/CrashWatcher.cpp +++ b/src/Daemon/CrashWatcher.cpp @@ -59,7 +59,7 @@ vector_crash_infos_t CCrashWatcher::GetCrashInfos(const std::string &pUID) try { vector_pair_string_string_t UUIDsUIDs; - UUIDsUIDs = g_pMW->GetUUIDsOfCrash(pUID); + UUIDsUIDs = ::GetUUIDsOfCrash(pUID); unsigned int ii; for (ii = 0; ii < UUIDsUIDs.size(); ii++) @@ -67,7 +67,7 @@ vector_crash_infos_t CCrashWatcher::GetCrashInfos(const std::string &pUID) mw_result_t res; map_crash_info_t info; - res = g_pMW->GetCrashInfo(UUIDsUIDs[ii].first, UUIDsUIDs[ii].second, info); + res = GetCrashInfo(UUIDsUIDs[ii].first, UUIDsUIDs[ii].second, info); switch (res) { case MW_OK: @@ -76,15 +76,15 @@ vector_crash_infos_t CCrashWatcher::GetCrashInfos(const std::string &pUID) case MW_ERROR: Warning("Can not find debug dump directory for UUID: " + UUIDsUIDs[ii].first + ", deleting from database"); Status("Can not find debug dump directory for UUID: " + UUIDsUIDs[ii].first + ", deleting from database"); - g_pMW->DeleteCrashInfo(UUIDsUIDs[ii].first, UUIDsUIDs[ii].second); + ::DeleteCrashInfo(UUIDsUIDs[ii].first, UUIDsUIDs[ii].second); break; case MW_FILE_ERROR: { std::string debugDumpDir; Warning("Can not open file in debug dump directory for UUID: " + UUIDsUIDs[ii].first + ", deleting "); Status("Can not open file in debug dump directory for UUID: " + UUIDsUIDs[ii].first + ", deleting "); - debugDumpDir = g_pMW->DeleteCrashInfo(UUIDsUIDs[ii].first, UUIDsUIDs[ii].second); - g_pMW->DeleteDebugDumpDir(debugDumpDir); + debugDumpDir = ::DeleteCrashInfo(UUIDsUIDs[ii].first, UUIDsUIDs[ii].second); + ::DeleteDebugDumpDir(debugDumpDir); } break; default: @@ -102,7 +102,7 @@ vector_crash_infos_t CCrashWatcher::GetCrashInfos(const std::string &pUID) Status(e.what()); } - //retval = g_pMW->GetCrashInfos(pUID); + //retval = ::GetCrashInfos(pUID); //Notify("Sent crash info"); return retval; } @@ -121,7 +121,7 @@ static void *create_report(void *arg) try { mw_result_t res; - res = g_pMW->CreateCrashReport(thread_data->UUID, thread_data->UID, crashReport); + res = ::CreateCrashReport(thread_data->UUID, thread_data->UID, crashReport); switch (res) { case MW_OK: @@ -138,8 +138,8 @@ static void *create_report(void *arg) { std::string debugDumpDir; g_cw->Warning(std::string("Corrupted crash with UUID ")+thread_data->UUID+", deleting."); - debugDumpDir = g_pMW->DeleteCrashInfo(thread_data->UUID, thread_data->UID); - g_pMW->DeleteDebugDumpDir(debugDumpDir); + debugDumpDir = ::DeleteCrashInfo(thread_data->UUID, thread_data->UID); + ::DeleteDebugDumpDir(debugDumpDir); } break; } @@ -204,7 +204,7 @@ report_status_t CCrashWatcher::Report(map_crash_report_t pReport, const std::str report_status_t rs; try { - rs = g_pMW->Report(pReport, pUID); + rs = ::Report(pReport, pUID); } catch (CABRTException& e) { @@ -224,8 +224,8 @@ bool CCrashWatcher::DeleteDebugDump(const std::string& pUUID, const std::string& try { std::string debugDumpDir; - debugDumpDir = g_pMW->DeleteCrashInfo(pUUID,pUID); - g_pMW->DeleteDebugDumpDir(debugDumpDir); + debugDumpDir = ::DeleteCrashInfo(pUUID,pUID); + ::DeleteDebugDumpDir(debugDumpDir); } catch (CABRTException& e) { @@ -253,7 +253,7 @@ vector_map_string_string_t CCrashWatcher::GetPluginsInfo() { try { - return g_pMW->GetPluginsInfo(); + return ::GetPluginsInfo(); } catch (CABRTException &e) { @@ -272,7 +272,7 @@ map_plugin_settings_t CCrashWatcher::GetPluginSettings(const std::string& pName, { try { - return g_pMW->GetPluginSettings(pName, pUID); + return ::GetPluginSettings(pName, pUID); } catch(CABRTException &e) { @@ -291,7 +291,7 @@ void CCrashWatcher::RegisterPlugin(const std::string& pName) { try { - g_pMW->RegisterPlugin(pName); + ::RegisterPlugin(pName); } catch(CABRTException &e) { @@ -307,7 +307,7 @@ void CCrashWatcher::UnRegisterPlugin(const std::string& pName) { try { - g_pMW->UnRegisterPlugin(pName); + ::UnRegisterPlugin(pName); } catch(CABRTException &e) { @@ -323,7 +323,7 @@ void CCrashWatcher::SetPluginSettings(const std::string& pName, const std::strin { try { - g_pMW->SetPluginSettings(pName, pUID, pSettings); + ::SetPluginSettings(pName, pUID, pSettings); } catch(CABRTException &e) { diff --git a/src/Daemon/CrashWatcher.h b/src/Daemon/CrashWatcher.h index 104532ad..ae600abb 100644 --- a/src/Daemon/CrashWatcher.h +++ b/src/Daemon/CrashWatcher.h @@ -81,8 +81,6 @@ extern CCrashWatcher *g_cw; /* conduit for these messages */ extern CCommLayerServer *g_pCommLayer; -extern CMiddleWare *g_pMW; - /* * Map to cache the results from CreateReport_t * <UID, <UUID, result>> diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp index 9021c9c7..48d69887 100644 --- a/src/Daemon/Daemon.cpp +++ b/src/Daemon/Daemon.cpp @@ -53,7 +53,6 @@ static CSettings* g_pSettings; CCrashWatcher *g_cw; CCommLayerServer *g_pCommLayer; -CMiddleWare *g_pMW; /* * Map to cache the results from CreateReport_t * <UID, <UUID, result>> @@ -120,7 +119,7 @@ static gboolean cron_activation_periodic_cb(gpointer data) { cron_callback_data_t* cronPeriodicCallbackData = static_cast<cron_callback_data_t*>(data); g_cw->Debug("Activating plugin: " + cronPeriodicCallbackData->m_sPluginName); - g_pMW->RunAction(DEBUG_DUMPS_DIR, + ::RunAction(DEBUG_DUMPS_DIR, cronPeriodicCallbackData->m_sPluginName, cronPeriodicCallbackData->m_sPluginArgs); return TRUE; @@ -129,7 +128,7 @@ static gboolean cron_activation_one_cb(gpointer data) { cron_callback_data_t* cronOneCallbackData = static_cast<cron_callback_data_t*>(data); g_cw->Debug("Activating plugin: " + cronOneCallbackData->m_sPluginName); - g_pMW->RunAction(DEBUG_DUMPS_DIR, + ::RunAction(DEBUG_DUMPS_DIR, cronOneCallbackData->m_sPluginName, cronOneCallbackData->m_sPluginArgs); return FALSE; @@ -151,31 +150,31 @@ static gboolean cron_activation_reshedule_cb(gpointer data) static void SetUpMW() { - g_pMW->SetOpenGPGCheck(g_pSettings->GetOpenGPGCheck()); - g_pMW->SetDatabase(g_pSettings->GetDatabase()); + ::SetOpenGPGCheck(g_pSettings->GetOpenGPGCheck()); + ::SetDatabase(g_pSettings->GetDatabase()); CSettings::set_strings_t openGPGPublicKeys = g_pSettings->GetOpenGPGPublicKeys(); CSettings::set_strings_t::iterator it_k; for (it_k = openGPGPublicKeys.begin(); it_k != openGPGPublicKeys.end(); it_k++) { - g_pMW->AddOpenGPGPublicKey(*it_k); + ::AddOpenGPGPublicKey(*it_k); } CSettings::set_strings_t blackList = g_pSettings->GetBlackList(); CSettings::set_strings_t::iterator it_b; for (it_b = blackList.begin(); it_b != blackList.end(); it_b++) { - g_pMW->AddBlackListedPackage(*it_b); + ::AddBlackListedPackage(*it_b); } CSettings::set_strings_t enabledPlugins = g_pSettings->GetEnabledPlugins(); CSettings::set_strings_t::iterator it_p; for (it_p = enabledPlugins.begin(); it_p != enabledPlugins.end(); it_p++) { - g_pMW->RegisterPlugin(*it_p); + ::RegisterPlugin(*it_p); } CSettings::vector_pair_strings_t actionsAndReporters = g_pSettings->GetActionsAndReporters(); CSettings::vector_pair_strings_t::iterator it_ar; for (it_ar = actionsAndReporters.begin(); it_ar != actionsAndReporters.end(); it_ar++) { - g_pMW->AddActionOrReporter((*it_ar).first, (*it_ar).second); + ::AddActionOrReporter((*it_ar).first, (*it_ar).second); } CSettings::map_analyzer_actions_and_reporters_t analyzerActionsAndReporters = g_pSettings->GetAnalyzerActionsAndReporters(); @@ -185,7 +184,7 @@ static void SetUpMW() CSettings::vector_pair_strings_t::iterator it_ar; for (it_ar = it_aar->second.begin(); it_ar != it_aar->second.end(); it_ar++) { - g_pMW->AddAnalyzerActionOrReporter(it_aar->first, (*it_ar).first, (*it_ar).second); + ::AddAnalyzerActionOrReporter(it_aar->first, (*it_ar).first, (*it_ar).second); } } } @@ -320,12 +319,12 @@ static void FindNewDumps(const std::string& pPath) try { mw_result_t res; - res = g_pMW->SaveDebugDump(*itt, crashinfo); + res = ::SaveDebugDump(*itt, crashinfo); switch (res) { case MW_OK: g_cw->Debug("Saving into database (" + *itt + ")."); - g_pMW->RunActionsAndReporters(crashinfo[CD_MWDDD][CD_CONTENT]); + ::RunActionsAndReporters(crashinfo[CD_MWDDD][CD_CONTENT]); break; case MW_IN_DB: g_cw->Debug("Already saved in database (" + *itt + ")."); @@ -339,7 +338,7 @@ static void FindNewDumps(const std::string& pPath) case MW_FILE_ERROR: default: g_cw->Warning("Corrupted, bad or already saved crash, deleting."); - g_pMW->DeleteDebugDumpDir(*itt); + ::DeleteDebugDumpDir(*itt); break; } } @@ -472,12 +471,12 @@ static gboolean handle_event_cb(GIOChannel *gio, GIOCondition condition, gpointe try { mw_result_t res; - res = g_pMW->SaveDebugDump(std::string(DEBUG_DUMPS_DIR) + "/" + name, crashinfo); + res = ::SaveDebugDump(std::string(DEBUG_DUMPS_DIR) + "/" + name, crashinfo); switch (res) { case MW_OK: g_cw->Debug("New crash, saving..."); - g_pMW->RunActionsAndReporters(crashinfo[CD_MWDDD][CD_CONTENT]); + ::RunActionsAndReporters(crashinfo[CD_MWDDD][CD_CONTENT]); /* send message to dbus */ g_pCommLayer->Crash(crashinfo[CD_PACKAGE][CD_CONTENT]); break; @@ -486,7 +485,7 @@ static gboolean handle_event_cb(GIOChannel *gio, GIOCondition condition, gpointe /* send message to dbus */ g_cw->Debug("Already saved crash, deleting..."); g_pCommLayer->Crash(crashinfo[CD_PACKAGE][CD_CONTENT]); - g_pMW->DeleteDebugDumpDir(std::string(DEBUG_DUMPS_DIR) + "/" + name); + ::DeleteDebugDumpDir(std::string(DEBUG_DUMPS_DIR) + "/" + name); break; case MW_BLACKLISTED: case MW_CORRUPTED: @@ -496,7 +495,7 @@ static gboolean handle_event_cb(GIOChannel *gio, GIOCondition condition, gpointe case MW_FILE_ERROR: default: g_cw->Warning("Corrupted or bad crash, deleting..."); - g_pMW->DeleteDebugDumpDir(std::string(DEBUG_DUMPS_DIR) + "/" + name); + ::DeleteDebugDumpDir(std::string(DEBUG_DUMPS_DIR) + "/" + name); break; } } @@ -518,7 +517,7 @@ static gboolean handle_event_cb(GIOChannel *gio, GIOCondition condition, gpointe else { g_cw->Debug(std::string("DebugDumps size has exceeded the limit, deleting the last dump: ") + name); - g_pMW->DeleteDebugDumpDir(std::string(DEBUG_DUMPS_DIR) + "/" + name); + ::DeleteDebugDumpDir(std::string(DEBUG_DUMPS_DIR) + "/" + name); } } else @@ -597,7 +596,7 @@ int main(int argc, char** argv) /* (comment here) */ g_pMainloop = g_main_loop_new(NULL, FALSE); /* (comment here) */ - g_pMW = new CMiddleWare(PLUGINS_CONF_DIR, PLUGINS_LIB_DIR); + CMiddleWare(PLUGINS_CONF_DIR, PLUGINS_LIB_DIR); SetUpMW(); SetUpCron(); FindNewDumps(DEBUG_DUMPS_DIR); @@ -632,7 +631,7 @@ int main(int argc, char** argv) g_io_channel_unref(pGio); delete g_pCommLayer; /* This restores /proc/sys/kernel/core_pattern, among other things: */ - delete g_pMW; + CMiddleWare_deinit(); g_main_loop_unref(g_pMainloop); delete g_pSettings; if (pthread_mutex_destroy(&g_pJobsMutex) != 0) @@ -670,7 +669,7 @@ int main(int argc, char** argv) g_io_channel_unref(pGio); delete g_pCommLayer; /* This restores /proc/sys/kernel/core_pattern, among other things: */ - delete g_pMW; + CMiddleWare_deinit(); g_main_loop_unref(g_pMainloop); delete g_pSettings; diff --git a/src/Daemon/MiddleWare.cpp b/src/Daemon/MiddleWare.cpp index 54ed2917..ac80d6bd 100644 --- a/src/Daemon/MiddleWare.cpp +++ b/src/Daemon/MiddleWare.cpp @@ -66,7 +66,10 @@ static std::string m_sPluginsConfDir; static bool m_bOpenGPGCheck; -CMiddleWare::CMiddleWare(const std::string& pPluginsConfDir, +static void RunAnalyzerActions(const std::string& pAnalyzer, const std::string& pDebugDumpDir); + + +void CMiddleWare(const std::string& pPluginsConfDir, const std::string& pPluginsLibDir) { m_sPluginsConfDir = pPluginsConfDir; @@ -75,13 +78,19 @@ CMiddleWare::CMiddleWare(const std::string& pPluginsConfDir, m_pPluginManager->LoadPlugins(); } -CMiddleWare::~CMiddleWare() +void CMiddleWare_deinit() { m_pPluginManager->UnLoadPlugins(); delete m_pPluginManager; } -void CMiddleWare::DebugDumpToCrashReport(const std::string& pDebugDumpDir, map_crash_report_t& pCrashReport) +/** + * A method, which transforms a debugdump direcortry to inner crash + * report form. This form is used for later reporting. + * @param pDebugDumpDir A debugdump dir containing all necessary data. + * @param pCrashReport A created crash report. + */ +static void DebugDumpToCrashReport(const std::string& pDebugDumpDir, map_crash_report_t& pCrashReport) { std::string fileName; std::string content; @@ -97,7 +106,7 @@ void CMiddleWare::DebugDumpToCrashReport(const std::string& pDebugDumpDir, map_c !dd.Exist(FILENAME_EXECUTABLE)) { dd.Close(); - throw CABRTException(EXCEP_ERROR, "CMiddleWare::DebugDumpToCrashReport(): One or more of important file(s)'re missing."); + throw CABRTException(EXCEP_ERROR, "DebugDumpToCrashReport(): One or more of important file(s)'re missing."); } pCrashReport.clear(); dd.InitGetNextFile(); @@ -141,51 +150,70 @@ void CMiddleWare::DebugDumpToCrashReport(const std::string& pDebugDumpDir, map_c dd.Close(); } -void CMiddleWare::RegisterPlugin(const std::string& pName) +void RegisterPlugin(const std::string& pName) { m_pPluginManager->RegisterPlugin(pName); } -void CMiddleWare::UnRegisterPlugin(const std::string& pName) +void UnRegisterPlugin(const std::string& pName) { m_pPluginManager->UnRegisterPlugin(pName); } -void CMiddleWare::SetPluginSettings(const std::string& pName, +void SetPluginSettings(const std::string& pName, const std::string& pUID, const map_plugin_settings_t& pSettings) { m_pPluginManager->SetPluginSettings(pName, pUID, pSettings); } -map_plugin_settings_t CMiddleWare::GetPluginSettings(const std::string& pName, +map_plugin_settings_t GetPluginSettings(const std::string& pName, const std::string& pUID) { return m_pPluginManager->GetPluginSettings(pName, pUID); } -std::string CMiddleWare::GetLocalUUID(const std::string& pAnalyzer, +/** + * Get a local UUID from particular analyzer plugin. + * @param pAnalyzer A name of an analyzer plugin. + * @param pDebugDumpDir A debugdump dir containing all necessary data. + * @return A local UUID. + */ +static std::string GetLocalUUID(const std::string& pAnalyzer, const std::string& pDebugDumpDir) { CAnalyzer* analyzer = m_pPluginManager->GetAnalyzer(pAnalyzer); return analyzer->GetLocalUUID(pDebugDumpDir); } -std::string CMiddleWare::GetGlobalUUID(const std::string& pAnalyzer, +/** + * Get a global UUID from particular analyzer plugin. + * @param pAnalyzer A name of an analyzer plugin. + * @param pDebugDumpDir A debugdump dir containing all necessary data. + * @return A global UUID. + */ +static std::string GetGlobalUUID(const std::string& pAnalyzer, const std::string& pDebugDumpDir) { CAnalyzer* analyzer = m_pPluginManager->GetAnalyzer(pAnalyzer); return analyzer->GetGlobalUUID(pDebugDumpDir); } -void CMiddleWare::CreateReport(const std::string& pAnalyzer, +/** + * Take care of getting all additional data needed + * for computing UUIDs and creating a report for particular analyzer + * plugin. This report could be send somewhere afterwards. + * @param pAnalyzer A name of an analyzer plugin. + * @param pDebugDumpPath A debugdump dir containing all necessary data. + */ +static void CreateReport(const std::string& pAnalyzer, const std::string& pDebugDumpDir) { CAnalyzer* analyzer = m_pPluginManager->GetAnalyzer(pAnalyzer); analyzer->CreateReport(pDebugDumpDir); } -mw_result_t CMiddleWare::CreateCrashReport(const std::string& pUUID, +mw_result_t CreateCrashReport(const std::string& pUUID, const std::string& pUID, map_crash_report_t& pCrashReport) { @@ -198,7 +226,7 @@ mw_result_t CMiddleWare::CreateCrashReport(const std::string& pUUID, if (pUUID == "" || row.m_sUUID != pUUID) { - comm_layer_inner_warning("CMiddleWare::CreateCrashReport(): UUID '"+pUUID+"' is not in database."); + comm_layer_inner_warning("CreateCrashReport(): UUID '"+pUUID+"' is not in database."); return MW_IN_DB_ERROR; } @@ -227,7 +255,7 @@ mw_result_t CMiddleWare::CreateCrashReport(const std::string& pUUID, } catch (CABRTException& e) { - comm_layer_inner_warning("CMiddleWare::CreateCrashReport(): " + e.what()); + comm_layer_inner_warning("CreateCrashReport(): " + e.what()); if (e.type() == EXCEP_DD_OPEN) { return MW_ERROR; @@ -246,7 +274,7 @@ mw_result_t CMiddleWare::CreateCrashReport(const std::string& pUUID, return MW_OK; } -void CMiddleWare::RunAction(const std::string& pActionDir, +void RunAction(const std::string& pActionDir, const std::string& pPluginName, const std::string& pPluginArgs) { @@ -258,13 +286,13 @@ void CMiddleWare::RunAction(const std::string& pActionDir, } catch (CABRTException& e) { - comm_layer_inner_warning("CMiddleWare::RunAction(): " + e.what()); + comm_layer_inner_warning("RunAction(): " + e.what()); comm_layer_inner_status("Execution of '"+pPluginName+"' was not successful: " + e.what()); } } -void CMiddleWare::RunActionsAndReporters(const std::string& pDebugDumpDir) +void RunActionsAndReporters(const std::string& pDebugDumpDir) { vector_pair_string_string_t::iterator it_ar; for (it_ar = m_vectorActionsAndReporters.begin(); it_ar != m_vectorActionsAndReporters.end(); it_ar++) @@ -287,13 +315,13 @@ void CMiddleWare::RunActionsAndReporters(const std::string& pDebugDumpDir) } catch (CABRTException& e) { - comm_layer_inner_warning("CMiddleWare::RunActionsAndReporters(): " + e.what()); + comm_layer_inner_warning("RunActionsAndReporters(): " + e.what()); comm_layer_inner_status("Activation of plugin '"+(*it_ar).first+"' was not successful: " + e.what()); } } } -report_status_t CMiddleWare::Report(const map_crash_report_t& pCrashReport, +report_status_t Report(const map_crash_report_t& pCrashReport, const std::string& pUID) { report_status_t ret; @@ -303,7 +331,7 @@ report_status_t CMiddleWare::Report(const map_crash_report_t& pCrashReport, pCrashReport.find(CD_MWUID) == pCrashReport.end() || pCrashReport.find(CD_MWUUID) == pCrashReport.end()) { - throw CABRTException(EXCEP_ERROR, "CMiddleWare::Report(): System data are missing in crash report."); + throw CABRTException(EXCEP_ERROR, "Report(): System data are missing in crash report."); } std::string analyzer = pCrashReport.find(CD_MWANALYZER)->second[CD_CONTENT]; @@ -374,7 +402,7 @@ report_status_t CMiddleWare::Report(const map_crash_report_t& pCrashReport, { ret[ret_key].push_back("0"); ret[ret_key].push_back(e.what()); - comm_layer_inner_warning("CMiddleWare::Report(): " + e.what()); + comm_layer_inner_warning("Report(): " + e.what()); comm_layer_inner_status("Reporting via '"+(*it_r).first+"' was not successful: " + e.what()); } } @@ -389,7 +417,7 @@ report_status_t CMiddleWare::Report(const map_crash_report_t& pCrashReport, return ret; } -void CMiddleWare::DeleteDebugDumpDir(const std::string& pDebugDumpDir) +void DeleteDebugDumpDir(const std::string& pDebugDumpDir) { CDebugDump dd; dd.Open(pDebugDumpDir); @@ -397,7 +425,7 @@ void CMiddleWare::DeleteDebugDumpDir(const std::string& pDebugDumpDir) dd.Close(); } -std::string CMiddleWare::DeleteCrashInfo(const std::string& pUUID, +std::string DeleteCrashInfo(const std::string& pUUID, const std::string& pUID) { database_row_t row; @@ -410,8 +438,15 @@ std::string CMiddleWare::DeleteCrashInfo(const std::string& pUUID, return row.m_sDebugDumpDir; } - -bool CMiddleWare::IsDebugDumpSaved(const std::string& pUID, +/** + * Check whether particular debugdump directory is saved + * in database. This check is done together with an UID of an user. + * @param pUID an UID of an user. + * @param pDebugDumpDir A debugdump dir containing all necessary data. + * @return It returns true if debugdump dir is already saved, otherwise + * it returns false. + */ +static bool IsDebugDumpSaved(const std::string& pUID, const std::string& pDebugDumpDir) { CDatabase* database = m_pPluginManager->GetDatabase(m_sDatabase); @@ -434,7 +469,14 @@ bool CMiddleWare::IsDebugDumpSaved(const std::string& pUID, return found; } -mw_result_t CMiddleWare::SavePackageDescriptionToDebugDump(const std::string& pExecutable, +/** + * Get a package name from executable name and save + * package description to particular debugdump directory of a crash. + * @param pExecutable A name of crashed application. + * @param pDebugDumpDir A debugdump dir containing all necessary data. + * @return It return results of operation. See mw_result_t. + */ +static mw_result_t SavePackageDescriptionToDebugDump(const std::string& pExecutable, const std::string& pDebugDumpDir) { std::string package; @@ -488,7 +530,7 @@ mw_result_t CMiddleWare::SavePackageDescriptionToDebugDump(const std::string& pE } catch (CABRTException& e) { - comm_layer_inner_warning("CMiddleWare::SavePackageDescriptionToDebugDump(): " + e.what()); + comm_layer_inner_warning("SavePackageDescriptionToDebugDump(): " + e.what()); if (e.type() == EXCEP_DD_SAVE) { dd.Close(); @@ -500,7 +542,13 @@ mw_result_t CMiddleWare::SavePackageDescriptionToDebugDump(const std::string& pE return MW_OK; } -void CMiddleWare::RunAnalyzerActions(const std::string& pAnalyzer, const std::string& pDebugDumpDir) +/** + * Execute all action plugins, which are associated to + * particular analyzer plugin. + * @param pAnalyzer A name of an analyzer plugin. + * @param pDebugDumpPath A debugdump dir containing all necessary data. + */ +static void RunAnalyzerActions(const std::string& pAnalyzer, const std::string& pDebugDumpDir) { if (m_mapAnalyzerActionsAndReporters.find(pAnalyzer) != m_mapAnalyzerActionsAndReporters.end()) { @@ -520,14 +568,25 @@ void CMiddleWare::RunAnalyzerActions(const std::string& pAnalyzer, const std::st } catch (CABRTException& e) { - comm_layer_inner_warning("CMiddleWare::RunAnalyzerActions(): " + e.what()); + comm_layer_inner_warning("RunAnalyzerActions(): " + e.what()); comm_layer_inner_status("Action performed by '"+(*it_a).first+"' was not successful: " + e.what()); } } } } -mw_result_t CMiddleWare::SaveDebugDumpToDatabase(const std::string& pUUID, +/** + * Save a debugdump into database. If saving is + * successful, then crash info is filled. Otherwise the crash info is + * not changed. + * @param pUUID A local UUID of a crash. + * @param pUID An UID of an user. + * @param pTime Time when a crash occurs. + * @param pDebugDumpPath A debugdump path. + * @param pCrashInfo A filled crash info. + * @return It return results of operation. See mw_result_t. + */ +static mw_result_t SaveDebugDumpToDatabase(const std::string& pUUID, const std::string& pUID, const std::string& pTime, const std::string& pDebugDumpDir, @@ -554,13 +613,13 @@ mw_result_t CMiddleWare::SaveDebugDumpToDatabase(const std::string& pUUID, return res; } -mw_result_t CMiddleWare::SaveDebugDump(const std::string& pDebugDumpDir) +mw_result_t SaveDebugDump(const std::string& pDebugDumpDir) { map_crash_info_t info; return SaveDebugDump(pDebugDumpDir, info); } -mw_result_t CMiddleWare::SaveDebugDump(const std::string& pDebugDumpDir, +mw_result_t SaveDebugDump(const std::string& pDebugDumpDir, map_crash_info_t& pCrashInfo) { std::string lUUID; @@ -582,7 +641,7 @@ mw_result_t CMiddleWare::SaveDebugDump(const std::string& pDebugDumpDir, } catch (CABRTException& e) { - comm_layer_inner_warning("CMiddleWare::SaveDebugDump(): " + e.what()); + comm_layer_inner_warning("SaveDebugDump(): " + e.what()); if (e.type() == EXCEP_DD_SAVE) { dd.Close(); @@ -605,7 +664,7 @@ mw_result_t CMiddleWare::SaveDebugDump(const std::string& pDebugDumpDir, return SaveDebugDumpToDatabase(lUUID, UID, time, pDebugDumpDir, pCrashInfo); } -mw_result_t CMiddleWare::GetCrashInfo(const std::string& pUUID, +mw_result_t GetCrashInfo(const std::string& pUUID, const std::string& pUID, map_crash_info_t& pCrashInfo) { @@ -631,7 +690,7 @@ mw_result_t CMiddleWare::GetCrashInfo(const std::string& pUUID, } catch (CABRTException& e) { - comm_layer_inner_warning("CMiddleWare::GetCrashInfo(): " + e.what()); + comm_layer_inner_warning("GetCrashInfo(): " + e.what()); if (e.type() == EXCEP_DD_LOAD) { dd.Close(); @@ -653,7 +712,7 @@ mw_result_t CMiddleWare::GetCrashInfo(const std::string& pUUID, return MW_OK; } -vector_pair_string_string_t CMiddleWare::GetUUIDsOfCrash(const std::string& pUID) +vector_pair_string_string_t GetUUIDsOfCrash(const std::string& pUID) { CDatabase* database = m_pPluginManager->GetDatabase(m_sDatabase); vector_database_rows_t rows; @@ -671,39 +730,39 @@ vector_pair_string_string_t CMiddleWare::GetUUIDsOfCrash(const std::string& pUID return UUIDsUIDs; } -vector_map_string_string_t CMiddleWare::GetPluginsInfo() +vector_map_string_string_t GetPluginsInfo() { return m_pPluginManager->GetPluginsInfo(); } -void CMiddleWare::SetOpenGPGCheck(bool pCheck) +void SetOpenGPGCheck(bool pCheck) { m_bOpenGPGCheck = pCheck; } -void CMiddleWare::SetDatabase(const std::string& pDatabase) +void SetDatabase(const std::string& pDatabase) { m_sDatabase = pDatabase; } -void CMiddleWare::AddOpenGPGPublicKey(const std::string& pKey) +void AddOpenGPGPublicKey(const std::string& pKey) { m_RPM.LoadOpenGPGPublicKey(pKey); } -void CMiddleWare::AddBlackListedPackage(const std::string& pPackage) +void AddBlackListedPackage(const std::string& pPackage) { m_setBlackList.insert(pPackage); } -void CMiddleWare::AddAnalyzerActionOrReporter(const std::string& pAnalyzer, +void AddAnalyzerActionOrReporter(const std::string& pAnalyzer, const std::string& pAnalyzerOrReporter, const std::string& pArgs) { m_mapAnalyzerActionsAndReporters[pAnalyzer].push_back(make_pair(pAnalyzerOrReporter, pArgs)); } -void CMiddleWare::AddActionOrReporter(const std::string& pActionOrReporter, +void AddActionOrReporter(const std::string& pActionOrReporter, const std::string& pArgs) { m_vectorActionsAndReporters.push_back(make_pair(pActionOrReporter, pArgs)); diff --git a/src/Daemon/MiddleWare.h b/src/Daemon/MiddleWare.h index cfbf6683..4b15af3e 100644 --- a/src/Daemon/MiddleWare.h +++ b/src/Daemon/MiddleWare.h @@ -56,262 +56,169 @@ typedef enum { typedef std::map<std::string, vector_strings_t> report_status_t; typedef std::map<std::string, vector_pair_string_string_t> map_analyzer_actions_and_reporters_t; +void CMiddleWare(const std::string& pPluginsConfDir, + const std::string& pPluginsLibDir); +void CMiddleWare_deinit(); /** - * A very important class :-). It manages part of user demands like creating - * reports, or reporting stuff somewhere etc. + * Register particular plugin. + * @param pName A plugin name. */ -class CMiddleWare -{ - private: - /** - * A method, which gets a local UUID from particular analyzer plugin. - * @param pAnalyzer A name of an analyzer plugin. - * @param pDebugDumpDir A debugdump dir containing all necessary data. - * @return A local UUID. - */ - std::string GetLocalUUID(const std::string& pAnalyzer, - const std::string& pDebugDumpDir); - /** - * A method, which gets a global UUID from particular analyzer plugin. - * @param pAnalyzer A name of an analyzer plugin. - * @param pDebugDumpDir A debugdump dir containing all necessary data. - * @return A global UUID. - */ - std::string GetGlobalUUID(const std::string& pAnalyzer, - const std::string& pDebugDumpDir); - /** - * A method, which takes care of getting all additional data needed - * for computing UUIDs and creating a report for particular analyzer - * plugin. This report could be send somewhere afterwards. - * @param pAnalyzer A name of an analyzer plugin. - * @param pDebugDumpPath A debugdump dir containing all necessary data. - */ - void CreateReport(const std::string& pAnalyzer, - const std::string& pDebugDumpDir); - /** - * A method, which executes all action plugins, which are associated to - * particular analyzer plugin. - * @param pAnalyzer A name of an analyzer plugin. - * @param pDebugDumpPath A debugdump dir containing all necessary data. - */ - void RunAnalyzerActions(const std::string& pAnalyzer, - const std::string& pDebugDumpDir); - /** - * A method, which transforms a debugdump direcortry to inner crash - * report form. This form is used for later reporting. - * @param pDebugDumpDir A debugdump dir containing all necessary data. - * @param pCrashReport A created crash report. - */ - void DebugDumpToCrashReport(const std::string& pDebugDumpDir, - map_crash_report_t& pCrashReport); - /** - * A method, which checks is particular debugdump directory is saved - * in database. This check is done together with an UID of an user. - * @param pUID an UID of an user. - * @param pDebugDumpDir A debugdump dir containing all necessary data. - * @return It returns true if debugdump dir is already saved, otherwise - * it returns false. - */ - bool IsDebugDumpSaved(const std::string& pUID, - const std::string& pDebugDumpDir); - /** - * A method, which gets a package name from executable name and saves - * package description to particular debugdump directory of a crash. - * @param pExecutable A name of crashed application. - * @param pDebugDumpDir A debugdump dir containing all necessary data. - * @return It return results of operation. See mw_result_t. - */ - mw_result_t SavePackageDescriptionToDebugDump(const std::string& pExecutable, - const std::string& pDebugDumpDir); - /** - * A method, which save a debugdump into database. If a saving is - * successful, then a crash info is filled. Otherwise the crash info is - * not changed. - * @param pUUID A local UUID of a crash. - * @param pUID An UID of an user. - * @param pTime Time when a crash occurs. - * @param pDebugDumpPath A debugdump path. - * @param pCrashInfo A filled crash info. - * @return It return results of operation. See mw_result_t. - */ - mw_result_t SaveDebugDumpToDatabase(const std::string& pUUID, - const std::string& pUID, - const std::string& pTime, - const std::string& pDebugDumpDir, - map_crash_info_t& pCrashInfo); - - public: - /** - * A constructor. - * @param pPluginsConfDir A plugins configuration directory. - * @param pPluginsLibDir A plugins library directory. - */ - CMiddleWare(const std::string& pPluginsConfDir, - const std::string& pPluginsLibDir); - /** - * A destructor. - */ - ~CMiddleWare(); - /** - * A method, which registers particular plugin. - * @param pName A plugin name. - */ - void RegisterPlugin(const std::string& pName); - /** - * A method, which unregister particular plugin. - * @param pName A plugin name. - */ - void UnRegisterPlugin(const std::string& pName); - /** - * A method, which sets up a plugin. The settings are also saved in home - * directory of an user. - * @param pName A plugin name. - * @param pUID An uid of user. - * @param pSettings A plugin's settings. - */ - void SetPluginSettings(const std::string& pName, - const std::string& pUID, - const map_plugin_settings_t& pSettings); - /** - * A method, which returns plugin's settings according to user. - * @param pName A plugin name. - * @param pUID An uid of user. - * @return Plugin's settings accorting to user. - */ - map_plugin_settings_t GetPluginSettings(const std::string& pName, - const std::string& pUID); - /** - * A method, which gets all plugins info (event those plugins which are - * disabled). It can be send via DBus to GUI and displayed to an user. - * Then a user can fill all needed informations like URLs etc. - * @return A vector of maps <key, vaule>. - */ - vector_map_string_string_t GetPluginsInfo(); - /** - * A method, which takes care of getting all additional data needed - * for computing UUIDs and creating a report for particular analyzer - * plugin. This report could be send somewhere afterwards. If a creation - * is successful, then a crash report is filled. - * @param pAnalyzer A name of an analyzer plugin. - * @param pDebugDumpPath A debugdump dir containing all necessary data. - * @param pCrashReport A filled crash report. - * @return It return results of operation. See mw_result_t. - */ - mw_result_t CreateCrashReport(const std::string& pUUID, - const std::string& pUID, - map_crash_report_t& pCrashReport); - /** - * A method, which activate particular action plugin. - * @param pActionDir A directory, which is passed as working to a action plugin. - * @param pPluginName An action plugin name. - * @param pPluginArgs Action plugin's arguments. - */ - void RunAction(const std::string& pActionDir, - const std::string& pPluginName, - const std::string& pPluginArgs); - /** - * A method, which activate all action and reporter plugins when any - * crash occurs. - * @param pDebugDumpDir A debugdump dir containing all necessary data. - */ - void RunActionsAndReporters(const std::string& pDebugDumpDir); - /** - * A method, which reports a crash report to particular receiver. It - * takes an user uid, tries to find user config file and load it. If it - * fails, then default config is used. If pUID is emply string, default - * config is used. - * ...). - * @param pCrashReport A crash report. - * @param pUID An user uid - * @return A report status, which reporters ends sucessfuly with messages. - */ - report_status_t Report(const map_crash_report_t& pCrashReport, - const std::string& pUID); - /** - * A method, which deletes particular debugdump directory. - * @param pDebugDumpDir A debugdump directory. - */ - void DeleteDebugDumpDir(const std::string& pDebugDumpDir); - /** - * A method, which delete a row from database. If a deleting is - * successfull, it returns a debugdump directort, which is not - * deleted. Otherwise, it returns empty string. - * @param pUUID A local UUID of a crash. - * @param pUID An UID of an user. - * @return A debugdump directory. - */ - std::string DeleteCrashInfo(const std::string& pUUID, - const std::string& pUID); - /** - * A method, whis saves debugdump into database. - * @param pDebugDumpDir A debugdump directory. - * @return It return results of operation. See mw_result_t. - */ - mw_result_t SaveDebugDump(const std::string& pDebugDumpDir); - /** - * A method, whis saves debugdump into database. If saving is sucessful - * it fills crash info. - * @param pDebugDumpDir A debugdump directory. - * @param pCrashInfo A crash info. - * @return It return results of operation. See mw_result_t. - */ - mw_result_t SaveDebugDump(const std::string& pDebugDumpDir, - map_crash_info_t& pCrashInfo); - /** - * A method, which gets one crash info. If a getting is successful, - * then a crash info is filled. - * @param pUUID A local UUID of a crash. - * @param pUID An UID of an user. - * @param pCrashInfo A crash info. - * @return It return results of operation. See mw_result_t. - */ - mw_result_t GetCrashInfo(const std::string& pUUID, - const std::string& pUID, - map_crash_info_t& pCrashInfo); - /** - * A method, which gets all local UUIDs and UIDs of crashes. These crashes - * occurred when a particular user was logged in. - * @param pUID an UID of an user. - * @return A vector of pairs (local UUID, UID). - */ - vector_pair_string_string_t GetUUIDsOfCrash(const std::string& pUID); - /** - * A method, which set a GPG finger print check. - * @param pCheck Is it enabled? - */ - void SetOpenGPGCheck(bool pCheck); - /** - * A method, which sets a name of database. - * @param pDatabase A database name. - */ - void SetDatabase(const std::string& pDatabase); - /** - * A method, which adds one path to a GPG public key into MW's set. - * @param pKey A path to a GPG public key. - */ - void AddOpenGPGPublicKey(const std::string& pKey); - /** - * A method, which adds one blacklisted package. - */ - void AddBlackListedPackage(const std::string& pPackage); - /** - * A method, which adds one association among alanyzer plugin and its - * action and reporter plugins. - * @param pAnalyzer A name of an analyzer plugin. - * @param pActionOrReporter A name of an action or reporter plugin. - * @param pArgs An arguments for action or reporter plugin. - */ - void AddAnalyzerActionOrReporter(const std::string& pAnalyzer, - const std::string& pActionOrReporter, - const std::string& pArgs); - /** - * A method, which adds action and reporter plugins, which are activated - * when any crash occurs. - * @param pActionOrReporter A name of an action or reporter plugin. - * @param pArgs An arguments for action or reporter plugin. - */ - void AddActionOrReporter(const std::string& pActionOrReporter, +void RegisterPlugin(const std::string& pName); +/** + * A method, which unregister particular plugin. + * @param pName A plugin name. + */ +void UnRegisterPlugin(const std::string& pName); +/** + * A method, which sets up a plugin. The settings are also saved in home + * directory of an user. + * @param pName A plugin name. + * @param pUID An uid of user. + * @param pSettings A plugin's settings. + */ +void SetPluginSettings(const std::string& pName, + const std::string& pUID, + const map_plugin_settings_t& pSettings); +/** + * A method, which returns plugin's settings according to user. + * @param pName A plugin name. + * @param pUID An uid of user. + * @return Plugin's settings accorting to user. + */ +map_plugin_settings_t GetPluginSettings(const std::string& pName, + const std::string& pUID); +/** + * A method, which gets all plugins info (event those plugins which are + * disabled). It can be send via DBus to GUI and displayed to an user. + * Then a user can fill all needed informations like URLs etc. + * @return A vector of maps <key, vaule>. + */ +vector_map_string_string_t GetPluginsInfo(); +/** + * A method, which takes care of getting all additional data needed + * for computing UUIDs and creating a report for particular analyzer + * plugin. This report could be send somewhere afterwards. If a creation + * is successful, then a crash report is filled. + * @param pAnalyzer A name of an analyzer plugin. + * @param pDebugDumpPath A debugdump dir containing all necessary data. + * @param pCrashReport A filled crash report. + * @return It return results of operation. See mw_result_t. + */ +mw_result_t CreateCrashReport(const std::string& pUUID, + const std::string& pUID, + map_crash_report_t& pCrashReport); +/** + * A method, which activate particular action plugin. + * @param pActionDir A directory, which is passed as working to a action plugin. + * @param pPluginName An action plugin name. + * @param pPluginArgs Action plugin's arguments. + */ +void RunAction(const std::string& pActionDir, + const std::string& pPluginName, + const std::string& pPluginArgs); +/** + * A method, which activate all action and reporter plugins when any + * crash occurs. + * @param pDebugDumpDir A debugdump dir containing all necessary data. + */ +void RunActionsAndReporters(const std::string& pDebugDumpDir); +/** + * A method, which reports a crash report to particular receiver. It + * takes an user uid, tries to find user config file and load it. If it + * fails, then default config is used. If pUID is emply string, default + * config is used. + * ...). + * @param pCrashReport A crash report. + * @param pUID An user uid + * @return A report status, which reporters ends sucessfuly with messages. + */ +report_status_t Report(const map_crash_report_t& pCrashReport, + const std::string& pUID); +/** + * A method, which deletes particular debugdump directory. + * @param pDebugDumpDir A debugdump directory. + */ +void DeleteDebugDumpDir(const std::string& pDebugDumpDir); +/** + * A method, which delete a row from database. If a deleting is + * successfull, it returns a debugdump directort, which is not + * deleted. Otherwise, it returns empty string. + * @param pUUID A local UUID of a crash. + * @param pUID An UID of an user. + * @return A debugdump directory. + */ +std::string DeleteCrashInfo(const std::string& pUUID, + const std::string& pUID); +/** + * A method, whis saves debugdump into database. + * @param pDebugDumpDir A debugdump directory. + * @return It return results of operation. See mw_result_t. + */ +mw_result_t SaveDebugDump(const std::string& pDebugDumpDir); +/** + * A method, whis saves debugdump into database. If saving is sucessful + * it fills crash info. + * @param pDebugDumpDir A debugdump directory. + * @param pCrashInfo A crash info. + * @return It return results of operation. See mw_result_t. + */ +mw_result_t SaveDebugDump(const std::string& pDebugDumpDir, + map_crash_info_t& pCrashInfo); +/** + * Get one crash info. If getting is successful, + * then crash info is filled. + * @param pUUID A local UUID of a crash. + * @param pUID An UID of an user. + * @param pCrashInfo A crash info. + * @return It return results of operation. See mw_result_t. + */ +mw_result_t GetCrashInfo(const std::string& pUUID, + const std::string& pUID, + map_crash_info_t& pCrashInfo); +/** + * Gets all local UUIDs and UIDs of crashes. These crashes + * occurred when a particular user was logged in. + * @param pUID an UID of an user. + * @return A vector of pairs (local UUID, UID). + */ +vector_pair_string_string_t GetUUIDsOfCrash(const std::string& pUID); +/** + * Sets a GPG finger print check. + * @param pCheck Is it enabled? + */ +void SetOpenGPGCheck(bool pCheck); +/** + * Sets a name of database. + * @param pDatabase A database name. + */ +void SetDatabase(const std::string& pDatabase); +/** + * Adds one path to a GPG public key into MW's set. + * @param pKey A path to a GPG public key. + */ +void AddOpenGPGPublicKey(const std::string& pKey); +/** + * Adds one blacklisted package. + */ +void AddBlackListedPackage(const std::string& pPackage); +/** + * Adds one association among alanyzer plugin and its + * action and reporter plugins. + * @param pAnalyzer A name of an analyzer plugin. + * @param pActionOrReporter A name of an action or reporter plugin. + * @param pArgs An arguments for action or reporter plugin. + */ +void AddAnalyzerActionOrReporter(const std::string& pAnalyzer, + const std::string& pActionOrReporter, const std::string& pArgs); -}; +/** + * Add action and reporter plugins, which are activated + * when any crash occurs. + * @param pActionOrReporter A name of an action or reporter plugin. + * @param pArgs An arguments for action or reporter plugin. + */ +void AddActionOrReporter(const std::string& pActionOrReporter, + const std::string& pArgs); + #endif /*MIDDLEWARE_H_*/ |