diff options
author | Jiri Moskovcak <jmoskovc@redhat.com> | 2009-04-24 12:18:31 +0200 |
---|---|---|
committer | Jiri Moskovcak <jmoskovc@redhat.com> | 2009-04-24 12:18:31 +0200 |
commit | 68ba4945437e12eaa1dead6df27b58ea408f63e8 (patch) | |
tree | a608d71e76dc82bf9ffdec95452c429d5aec29d2 /lib | |
parent | 7b2d4874b7bd992ef3f09124b7ebbc346eba01f4 (diff) | |
download | abrt-68ba4945437e12eaa1dead6df27b58ea408f63e8.tar.gz abrt-68ba4945437e12eaa1dead6df27b58ea408f63e8.tar.xz abrt-68ba4945437e12eaa1dead6df27b58ea408f63e8.zip |
final touch on commlayer, minor fixes in exceptions (zprikryl)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/CommLayer/CommLayer.h | 2 | ||||
-rw-r--r-- | lib/CommLayer/CommLayerInner.cpp | 69 | ||||
-rw-r--r-- | lib/CommLayer/CommLayerInner.h | 102 | ||||
-rw-r--r-- | lib/CommLayer/CommLayerServer.cpp | 2 | ||||
-rw-r--r-- | lib/CommLayer/Observer.h | 2 | ||||
-rw-r--r-- | lib/MiddleWare/Makefile.am | 2 | ||||
-rw-r--r-- | lib/MiddleWare/PluginManager.cpp | 29 | ||||
-rw-r--r-- | lib/MiddleWare/test.cpp | 11 | ||||
-rw-r--r-- | lib/Plugins/CCpp.cpp | 12 | ||||
-rw-r--r-- | lib/Plugins/Makefile.am | 2 | ||||
-rw-r--r-- | lib/Utils/ABRTException.h | 3 |
11 files changed, 141 insertions, 95 deletions
diff --git a/lib/CommLayer/CommLayer.h b/lib/CommLayer/CommLayer.h index 19c0aa7f..044d36d2 100644 --- a/lib/CommLayer/CommLayer.h +++ b/lib/CommLayer/CommLayer.h @@ -2,6 +2,6 @@ #define COMMLAYER_H_ #include "CommLayerInner.h" -extern "C" CCommLayerInner* get_commlayer(); +//extern "C" CCommLayerInner* get_commlayer(); #endif /* COMMLAYER_H_ */ diff --git a/lib/CommLayer/CommLayerInner.cpp b/lib/CommLayer/CommLayerInner.cpp index 41fd3c17..a7c5123d 100644 --- a/lib/CommLayer/CommLayerInner.cpp +++ b/lib/CommLayer/CommLayerInner.cpp @@ -1,28 +1,57 @@ #include "CommLayerInner.h" -CCommLayerInner::CCommLayerInner(CObserver *pObs) -: DEBUGINFO(pObs), - WARNING(pObs), - STATUS(pObs) +namespace CommLayerInner { - m_pObs = pObs; -} -CCommLayerInner::~CCommLayerInner() -{ -} + static CDebug* g_pDebug = NULL; + static CWarning* g_pWarning = NULL; + static CStatus* g_pStatus = NULL; -CDebug& CCommLayerInner::Debug() -{ - return DEBUGINFO; -} -CWarning& CCommLayerInner::Warning() -{ - return WARNING; -} + void init_debug(CObserver* pObserver) + { + if (!g_pDebug) + { + g_pDebug = new CDebug(pObserver); + } + } -CStatusUpdate& CCommLayerInner::Status() -{ - return STATUS; + void init_warning(CObserver* pObserver) + { + if (!g_pWarning) + { + g_pWarning = new CWarning(pObserver); + } + } + + void init_status(CObserver* pObserver) + { + if (!g_pStatus) + { + g_pStatus = new CStatus(pObserver); + } + } + + void debug(const std::string& pMessage) + { + if (g_pDebug) + { + g_pDebug->Message(pMessage); + } + } + void warning(const std::string& pMessage) + { + if (g_pWarning) + { + g_pWarning->Message(pMessage); + } + } + + void status(const std::string& pMessage) + { + if (g_pStatus) + { + g_pStatus->Message(pMessage); + } + } } diff --git a/lib/CommLayer/CommLayerInner.h b/lib/CommLayer/CommLayerInner.h index 2cca9357..7edd2578 100644 --- a/lib/CommLayer/CommLayerInner.h +++ b/lib/CommLayer/CommLayerInner.h @@ -4,60 +4,62 @@ #include <iostream> #include "Observer.h" -class CDebug +namespace CommLayerInner { - private: - CObserver *m_pObs; - public: - CDebug(CObserver *pObs){ m_pObs = pObs; } - - void operator << (const std::string& pMsg) - { - if(m_pObs) - m_pObs->Debug(pMsg); - } -}; -class CWarning -{ - private: - CObserver *m_pObs; - public: - CWarning(CObserver *pObs){ m_pObs = pObs; } - - void operator << (const std::string& pMsg) - { - if(m_pObs) - m_pObs->Warning(pMsg); - } -}; + class CDebug + { + private: + CObserver *m_pObs; + public: + CDebug(CObserver *pObs) : + m_pObs(pObs) + {} + void Message(const std::string& pMsg) + { + if(m_pObs) + m_pObs->Debug(pMsg); + } + }; -class CStatusUpdate -{ - private: - CObserver *m_pObs; - public: - CStatusUpdate(CObserver *pObs){ m_pObs = pObs; } - - void operator << (const std::string& pMsg) - { - if(m_pObs) - m_pObs->StatusUpdate(pMsg); - } -}; + class CWarning + { + private: + CObserver *m_pObs; + public: + CWarning(CObserver *pObs) : + m_pObs(pObs) + {} + void Message(const std::string& pMsg) + { + if(m_pObs) + m_pObs->Warning(pMsg); + } + }; + + class CStatus + { + private: + CObserver *m_pObs; + public: + CStatus(CObserver *pObs) : + m_pObs(pObs) + {} + void Message(const std::string& pMsg) + { + if(m_pObs) + m_pObs->Status(pMsg); + } + }; + + + void init_debug(CObserver* pObserver); + void init_warning(CObserver* pObserver); + void init_status(CObserver* pObserver); -class CCommLayerInner{ - private: - CObserver *m_pObs; - public: - CDebug DEBUGINFO; - CWarning WARNING; - CStatusUpdate STATUS; - CCommLayerInner(CObserver *pObs); - ~CCommLayerInner(); - CDebug& Debug(); - CWarning& Warning(); - CStatusUpdate& Status(); + void debug(const std::string& pMessage); + void warning(const std::string& pMessage); + void status(const std::string& pMessage); }; #endif /* COMMLAYERINNER_H_ */ diff --git a/lib/CommLayer/CommLayerServer.cpp b/lib/CommLayer/CommLayerServer.cpp index 271f7539..328986e7 100644 --- a/lib/CommLayer/CommLayerServer.cpp +++ b/lib/CommLayer/CommLayerServer.cpp @@ -20,5 +20,5 @@ void CCommLayerServer::Detach(CObserver *pObs) void CCommLayerServer::Notify(const std::string& pMessage) { if(m_pObserver) - m_pObserver->StatusUpdate(pMessage); + m_pObserver->Status(pMessage); } diff --git a/lib/CommLayer/Observer.h b/lib/CommLayer/Observer.h index 6f276d79..a26b7b74 100644 --- a/lib/CommLayer/Observer.h +++ b/lib/CommLayer/Observer.h @@ -7,7 +7,7 @@ class CObserver { public: //CObserver(); virtual ~CObserver() {} - virtual void StatusUpdate(const std::string& pMessage) = 0; + virtual void Status(const std::string& pMessage) = 0; virtual void Debug(const std::string& pMessage) = 0; virtual void Warning(const std::string& pMessage) = 0; /* this should be implemented in daemon */ diff --git a/lib/MiddleWare/Makefile.am b/lib/MiddleWare/Makefile.am index 1a35bcc0..c6aa8cf5 100644 --- a/lib/MiddleWare/Makefile.am +++ b/lib/MiddleWare/Makefile.am @@ -8,7 +8,7 @@ libABRTMiddleWare_la_SOURCES = MiddleWare.cpp MiddleWare.h PluginManager.cpp \ Reporter.h Analyzer.h libABRTMiddleWare_la_LIBADD = $(DL_LIBS) ../Utils/libABRTUtils.la $(RPM_LIBS) libABRTMiddleWare_la_LDFLAGS = -version-info 0:1:0 -libABRTMiddleWare_la_CPPFLAGS = -I$(srcdir)/../Utils $(RPM_CFLAGS) +libABRTMiddleWare_la_CPPFLAGS = -I$(srcdir)/../Utils -I$(srcdir)/../CommLayer $(RPM_CFLAGS) check_PROGRAMS = test test_SOURCES = test.cpp diff --git a/lib/MiddleWare/PluginManager.cpp b/lib/MiddleWare/PluginManager.cpp index 2ab314bb..f3d89e52 100644 --- a/lib/MiddleWare/PluginManager.cpp +++ b/lib/MiddleWare/PluginManager.cpp @@ -21,7 +21,8 @@ #include <iostream> #include "PluginManager.h" -#include <ABRTException.h> +#include "ABRTException.h" +#include "CommLayer.h" #include <dirent.h> #include <stdio.h> #include <sys/types.h> @@ -83,7 +84,7 @@ void CPluginManager::LoadPlugin(const std::string& pName) { throw CABRTException(EXCEP_PLUGIN, "CPluginManager::LoadPlugin(): non-compatible plugin"); } - std::cerr << "Plugin " << pName << " (" << abrtPlugin->GetVersion() << ") " << "succesfully loaded." << std::endl; + CommLayerInner::debug("Plugin " + pName + " (" + abrtPlugin->GetVersion() + ") succesfully loaded."); m_mapABRTPlugins[pName] = abrtPlugin; } catch (CABRTException& e) @@ -92,8 +93,8 @@ void CPluginManager::LoadPlugin(const std::string& pName) { delete abrtPlugin; } - std::cerr << e.what() << std::endl; - std::cerr << "Failed to load plugin " << pName << std::endl; + CommLayerInner::debug("CPluginManager::LoadPlugin(): " + e.what()); + CommLayerInner::debug("Failed to load plugin " + pName); } } } @@ -105,7 +106,7 @@ void CPluginManager::UnLoadPlugin(const std::string& pName) UnRegisterPlugin(pName); delete m_mapABRTPlugins[pName]; m_mapABRTPlugins.erase(pName); - std::cerr << "Plugin " << pName << " sucessfully unloaded." << std::endl; + CommLayerInner::debug("Plugin " + pName + " sucessfully unloaded."); } } @@ -125,16 +126,16 @@ void CPluginManager::RegisterPlugin(const std::string& pName) } catch (std::string sError) { - std::cerr << "Can not initialize plugin " << pName << "(" - << plugin_type_str_t[m_mapABRTPlugins[pName]->GetType()] - << ")" << std::endl; + CommLayerInner::debug("Can not initialize plugin " + pName + "(" + + std::string(plugin_type_str_t[m_mapABRTPlugins[pName]->GetType()]) + + ")"); UnLoadPlugin(pName); return; } m_mapPlugins[pName] = plugin; - std::cerr << "Registred plugin " << pName << "(" - << plugin_type_str_t[m_mapABRTPlugins[pName]->GetType()] - << ")" << std::endl; + CommLayerInner::debug("Registred plugin " + pName + "(" + + std::string(plugin_type_str_t[m_mapABRTPlugins[pName]->GetType()]) + + ")"); } } } @@ -148,9 +149,9 @@ void CPluginManager::UnRegisterPlugin(const std::string& pName) m_mapPlugins[pName]->DeInit(); delete m_mapPlugins[pName]; m_mapPlugins.erase(pName); - std::cerr << "UnRegistred plugin " << pName << "(" - << plugin_type_str_t[m_mapABRTPlugins[pName]->GetType()] - << ")" << std::endl; + CommLayerInner::debug("UnRegistred plugin " + pName + "(" + + std::string(plugin_type_str_t[m_mapABRTPlugins[pName]->GetType()]) + + ")"); } } } diff --git a/lib/MiddleWare/test.cpp b/lib/MiddleWare/test.cpp index c44b5cc8..79cadd3e 100644 --- a/lib/MiddleWare/test.cpp +++ b/lib/MiddleWare/test.cpp @@ -37,19 +37,19 @@ int main(int argc, char** argv) } try { - //std::string(CONF_DIR) + "/abrt.conf" CMiddleWare middleWare(PLUGINS_CONF_DIR, PLUGINS_LIB_DIR); - /* Create DebugDump */ - /* Try to save it into DB */ middleWare.RegisterPlugin("CCpp"); + middleWare.RegisterPlugin("Mailx"); middleWare.RegisterPlugin("Logger"); middleWare.RegisterPlugin("RunApp"); middleWare.RegisterPlugin("SQLite3"); middleWare.SetDatabase("SQLite3"); middleWare.SetOpenGPGCheck(false); - middleWare.AddAnalyzerReporter("CCpp", "Logger"); - middleWare.AddAnalyzerAction("CCpp", "RunApp", "date,action_date"); + middleWare.AddReporter("Logger"); + middleWare.AddAnalyzerReporter("CCpp", "Mailx"); + middleWare.AddAnalyzerAction("CCpp", "RunApp", "date"); + /* Try to save it into DB */ map_crash_info_t crashInfo; if (middleWare.SaveDebugDump(argv[1], crashInfo)) { @@ -58,6 +58,7 @@ int main(int argc, char** argv) crashInfo[CD_EXECUTABLE][CD_CONTENT] << ", " << crashInfo[CD_COUNT][CD_CONTENT] << ", " << std::endl; + middleWare.Report(argv[1]); /* Get Report, so user can change data (remove private stuff) * If we do not want user interaction, just send data immediately */ diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp index 286f730f..7aacc2fc 100644 --- a/lib/Plugins/CCpp.cpp +++ b/lib/Plugins/CCpp.cpp @@ -23,6 +23,7 @@ #include "ABRTException.h" #include "DebugDump.h" #include "PluginSettings.h" +#include "CommLayer.h" #include <fstream> #include <sstream> #include <iostream> @@ -88,6 +89,8 @@ std::string CAnalyzerCCpp::CreateHash(const std::string& pInput) void CAnalyzerCCpp::InstallDebugInfos(const std::string& pPackage) { + CommLayerInner::status("Installing debug infos..."); + std::string packageName = pPackage.substr(0, pPackage.rfind("-", pPackage.rfind("-")-1)); char buff[1024]; int pipein[2], pipeout[2]; @@ -192,6 +195,8 @@ void CAnalyzerCCpp::InstallDebugInfos(const std::string& pPackage) void CAnalyzerCCpp::GetBacktrace(const std::string& pDebugDumpDir, std::string& pBacktrace) { + CommLayerInner::status("Getting backtrace..."); + std::string tmpFile = "/tmp/" + pDebugDumpDir.substr(pDebugDumpDir.rfind("/")); std::ofstream fTmp; std::string UID; @@ -417,6 +422,8 @@ void CAnalyzerCCpp::ExecVP(const char* pCommand, char* const pArgs[], const std: std::string CAnalyzerCCpp::GetLocalUUID(const std::string& pDebugDumpDir) { + CommLayerInner::status("Getting global universal unique identification..."); + CDebugDump dd; std::string UID; std::string executable; @@ -439,6 +446,8 @@ std::string CAnalyzerCCpp::GetLocalUUID(const std::string& pDebugDumpDir) } std::string CAnalyzerCCpp::GetGlobalUUID(const std::string& pDebugDumpDir) { + CommLayerInner::status("Getting local universal unique identification..."); + std::string backtrace; std::string executable; std::string package; @@ -455,9 +464,12 @@ std::string CAnalyzerCCpp::GetGlobalUUID(const std::string& pDebugDumpDir) void CAnalyzerCCpp::CreateReport(const std::string& pDebugDumpDir) { + CommLayerInner::status("Starting report creation..."); + std::string package; std::string backtrace; CDebugDump dd; + dd.Open(pDebugDumpDir); if (dd.Exist(FILENAME_BACKTRACE)) { diff --git a/lib/Plugins/Makefile.am b/lib/Plugins/Makefile.am index 7288c369..3b91de2e 100644 --- a/lib/Plugins/Makefile.am +++ b/lib/Plugins/Makefile.am @@ -17,7 +17,7 @@ dist_pluginsconf_DATA = CCpp.conf Mailx.conf SQLite3.conf Logger.conf Kerneloops libCCpp_la_SOURCES = CCpp.cpp CCpp.h PluginSettings.h libCCpp_la_LDFLAGS = -avoid-version libCCpp_la_LIBADD = $(NSS_LIBS) -libCCpp_la_CPPFLAGS = -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils -DCCPP_HOOK_PATH=\"${libexecdir}/hookCCpp\" -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" $(NSS_CFLAGS) +libCCpp_la_CPPFLAGS = -I$(srcdir)/../MiddleWare -I$(srcdir)/../Utils -I$(srcdir)/../CommLayer -DCCPP_HOOK_PATH=\"${libexecdir}/hookCCpp\" -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" $(NSS_CFLAGS) # Kerneloops libKerneloops_la_SOURCES = Kerneloops.cpp Kerneloops.h KerneloopsSysLog.cpp KerneloopsSysLog.h PluginSettings.h diff --git a/lib/Utils/ABRTException.h b/lib/Utils/ABRTException.h index 32a8dd12..730faf3b 100644 --- a/lib/Utils/ABRTException.h +++ b/lib/Utils/ABRTException.h @@ -13,12 +13,13 @@ typedef enum {EXCEP_UNKNOW, EXCEP_ERROR, EXCEP_FATAL} abrt_exception_t; -class CABRTException +class CABRTException : public std::exception { private: std::string m_sWhat; abrt_exception_t m_Type; public: + virtual ~CABRTException() throw() {} CABRTException(const abrt_exception_t& pType, const char* pWhat) : m_sWhat(pWhat), m_Type(pType) |