diff options
author | Jiri Moskovcak <jmoskovc@redhat.com> | 2009-04-23 14:42:40 +0200 |
---|---|---|
committer | Jiri Moskovcak <jmoskovc@redhat.com> | 2009-04-23 14:42:40 +0200 |
commit | bcf4c69ca5fdd6489ca1c09890971fc8f647aa1b (patch) | |
tree | e5fedc350ae9368faf77360ea4fb3c0f6d264210 /lib/CommLayer | |
parent | 99047bce024f1d23c953649cf56ff67e754e44ef (diff) | |
download | abrt-bcf4c69ca5fdd6489ca1c09890971fc8f647aa1b.tar.gz abrt-bcf4c69ca5fdd6489ca1c09890971fc8f647aa1b.tar.xz abrt-bcf4c69ca5fdd6489ca1c09890971fc8f647aa1b.zip |
Added intercomm layer so plugins can send various information to the daemon.
Diffstat (limited to 'lib/CommLayer')
-rw-r--r-- | lib/CommLayer/CommLayer.h | 7 | ||||
-rw-r--r-- | lib/CommLayer/CommLayerInner.cpp | 28 | ||||
-rw-r--r-- | lib/CommLayer/CommLayerInner.h | 63 | ||||
-rw-r--r-- | lib/CommLayer/CommLayerServer.cpp | 10 | ||||
-rw-r--r-- | lib/CommLayer/CommLayerServer.h | 28 | ||||
-rw-r--r-- | lib/CommLayer/CommLayerServerDBus.cpp | 71 | ||||
-rw-r--r-- | lib/CommLayer/CommLayerServerDBus.h | 6 | ||||
-rw-r--r-- | lib/CommLayer/CommLayerServerSocket.cpp | 4 | ||||
-rw-r--r-- | lib/CommLayer/CommLayerServerSocket.h | 2 | ||||
-rw-r--r-- | lib/CommLayer/Makefile.am | 3 | ||||
-rw-r--r-- | lib/CommLayer/Observer.h | 16 |
11 files changed, 156 insertions, 82 deletions
diff --git a/lib/CommLayer/CommLayer.h b/lib/CommLayer/CommLayer.h new file mode 100644 index 00000000..19c0aa7f --- /dev/null +++ b/lib/CommLayer/CommLayer.h @@ -0,0 +1,7 @@ +#ifndef COMMLAYER_H_ +#define COMMLAYER_H_ + +#include "CommLayerInner.h" +extern "C" CCommLayerInner* get_commlayer(); + +#endif /* COMMLAYER_H_ */ diff --git a/lib/CommLayer/CommLayerInner.cpp b/lib/CommLayer/CommLayerInner.cpp new file mode 100644 index 00000000..41fd3c17 --- /dev/null +++ b/lib/CommLayer/CommLayerInner.cpp @@ -0,0 +1,28 @@ +#include "CommLayerInner.h" + +CCommLayerInner::CCommLayerInner(CObserver *pObs) +: DEBUGINFO(pObs), + WARNING(pObs), + STATUS(pObs) +{ + m_pObs = pObs; +} + +CCommLayerInner::~CCommLayerInner() +{ +} + +CDebug& CCommLayerInner::Debug() +{ + return DEBUGINFO; +} + +CWarning& CCommLayerInner::Warning() +{ + return WARNING; +} + +CStatusUpdate& CCommLayerInner::Status() +{ + return STATUS; +} diff --git a/lib/CommLayer/CommLayerInner.h b/lib/CommLayer/CommLayerInner.h new file mode 100644 index 00000000..2cca9357 --- /dev/null +++ b/lib/CommLayer/CommLayerInner.h @@ -0,0 +1,63 @@ +#ifndef COMMLAYERINNER_H_ +#define COMMLAYERINNER_H_ + +#include <iostream> +#include "Observer.h" + +class CDebug +{ + 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 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 CCommLayerInner{ + private: + CObserver *m_pObs; + public: + CDebug DEBUGINFO; + CWarning WARNING; + CStatusUpdate STATUS; + CCommLayerInner(CObserver *pObs); + ~CCommLayerInner(); + CDebug& Debug(); + CWarning& Warning(); + CStatusUpdate& Status(); +}; + +#endif /* COMMLAYERINNER_H_ */ diff --git a/lib/CommLayer/CommLayerServer.cpp b/lib/CommLayer/CommLayerServer.cpp index 1ebae6d3..271f7539 100644 --- a/lib/CommLayer/CommLayerServer.cpp +++ b/lib/CommLayer/CommLayerServer.cpp @@ -1,30 +1,24 @@ #include "CommLayerServer.h" #include <iostream> -CCommLayerServer::CCommLayerServer(CMiddleWare *pMW) +CCommLayerServer::CCommLayerServer() { - m_pMW = pMW; - std::cerr << "CCommLayerServer init.." << std::endl; } CCommLayerServer::~CCommLayerServer() { - std::cout << "CCommLayerServer::Cleaning up.." << std::endl; } void CCommLayerServer::Attach(CObserver *pObs) { - std::cerr << "CCommLayerServer::Attach" << std::endl; m_pObserver = pObs; } void CCommLayerServer::Detach(CObserver *pObs) { - std::cerr << "CCommLayerServer::Detach" << std::endl; m_pObserver = NULL; } void CCommLayerServer::Notify(const std::string& pMessage) { - std::cerr << "CCommLayerServer::Notify" << std::endl; if(m_pObserver) - m_pObserver->Update(pMessage); + m_pObserver->StatusUpdate(pMessage); } diff --git a/lib/CommLayer/CommLayerServer.h b/lib/CommLayer/CommLayerServer.h index fc76cc95..f781813a 100644 --- a/lib/CommLayer/CommLayerServer.h +++ b/lib/CommLayer/CommLayerServer.h @@ -1,10 +1,13 @@ +#ifndef COMMLAYERSERVER_H_ +#define COMMLAYERSERVER_H_ + #include <vector> #include <map> #include <string> #include <sstream> #include <iostream> -#include "MiddleWare.h" #include "Observer.h" +#include "CrashTypes.h" /* just a helper function */ template< class T > @@ -16,29 +19,32 @@ to_string( T x ) return o.str(); } + class CCommLayerServer{ - private: + protected: /* FIXME more observers? */ //std::vector<Observer *obs>; CObserver *m_pObserver; public: - CMiddleWare *m_pMW; - CCommLayerServer(CMiddleWare *pMW); + //CMiddleWare *m_pMW; + //CCommLayerServer(CMiddleWare *pMW); + CCommLayerServer(); virtual ~CCommLayerServer(); /* observer */ void Attach(CObserver *pObs); void Detach(CObserver *pObs); void Notify(const std::string& pMessage); - /* - virtual dbus_vector_crash_infos_t GetCrashInfos(const std::string &pUID) = 0; - virtual dbus_vector_map_crash_infos_t GetCrashInfosMap(const std::string &pDBusSender) = 0; - virtual dbus_map_report_info_t CreateReport(const std::string &pUUID,const std::string &pDBusSender) = 0; - virtual bool Report(dbus_map_report_info_t pReport) = 0; - virtual bool DeleteDebugDump(const std::string& pUUID, const std::string& pDBusSender) = 0; - */ + + virtual vector_crash_infos_t GetCrashInfos(const std::string &pDBusSender) = 0; + virtual map_crash_report_t CreateReport(const std::string &pUUID,const std::string &pDBusSender) = 0; + virtual bool Report(map_crash_report_t pReport) = 0; + virtual bool DeleteDebugDump(const std::string& pUUID, const std::string& pDBusSender) = 0; + public: /* just stubs to be called when not implemented in specific comm layer */ virtual void Crash(const std::string& arg1) {} virtual void AnalyzeComplete(map_crash_report_t arg1) {} virtual void Error(const std::string& arg1) {} }; + +#endif //COMMLAYERSERVER_H_ diff --git a/lib/CommLayer/CommLayerServerDBus.cpp b/lib/CommLayer/CommLayerServerDBus.cpp index b4df14b9..b9024f69 100644 --- a/lib/CommLayer/CommLayerServerDBus.cpp +++ b/lib/CommLayer/CommLayerServerDBus.cpp @@ -11,91 +11,52 @@ DBus::Connection *CCommLayerServerDBus::init_dbus(CCommLayerServerDBus *self) return server->m_pConn; } -CCommLayerServerDBus::CCommLayerServerDBus(CMiddleWare *pMW) -: CCommLayerServer(pMW), +CCommLayerServerDBus::CCommLayerServerDBus() +: CCommLayerServer(), DBus::ObjectAdaptor(*init_dbus(this), CC_DBUS_PATH) { - std::cerr << "CCommLayerDBus init.." << std::endl; - m_pConn->request_name(CC_DBUS_NAME); + try + { + m_pConn->request_name(CC_DBUS_NAME); + } + catch(DBus::Error err) + { + throw std::string("Error while requesting dbus name - have you reloaded the dbus settings?"); + } } CCommLayerServerDBus::~CCommLayerServerDBus() { - std::cout << "Cleaning up dbus" << std::endl; delete m_pDispatcher; } vector_crash_infos_t CCommLayerServerDBus::GetCrashInfos(const std::string &pDBusSender) { - vector_crash_infos_t retval; + vector_crash_infos_t crashInfos; unsigned long unix_uid = m_pConn->sender_unix_uid(pDBusSender.c_str()); - try - { - retval = m_pMW->GetCrashInfos(to_string(unix_uid)); - } - catch(std::string err) - { - std::cerr << err << std::endl; - } - Notify("Sent crash info"); - return retval; + crashInfos = m_pObserver->GetCrashInfos(to_string(unix_uid)); + return crashInfos; } map_crash_report_t CCommLayerServerDBus::CreateReport(const std::string &pUUID,const std::string &pDBusSender) { unsigned long unix_uid = m_pConn->sender_unix_uid(pDBusSender.c_str()); - //std::cerr << pUUID << ":" << unix_uid << std::endl; map_crash_report_t crashReport; - std::cerr << "Creating report" << std::endl; - try - { - m_pMW->CreateCrashReport(pUUID,to_string(unix_uid), crashReport); - //send out the message about completed analyze - CDBusServer_adaptor::AnalyzeComplete(crashReport); - } - catch(std::string err) - { - CDBusServer_adaptor::Error(err); - std::cerr << err << std::endl; - } + crashReport = m_pObserver->CreateReport(pUUID, to_string(unix_uid)); return crashReport; } bool CCommLayerServerDBus::Report(map_crash_report_t pReport) { - //#define FIELD(X) crashReport.m_s##X = pReport[#X]; - //crashReport.m_sUUID = pReport["UUID"]; - //ALL_CRASH_REPORT_FIELDS; - //#undef FIELD - //for (dbus_map_report_info_t::iterator it = pReport.begin(); it!=pReport.end(); ++it) { - // std::cerr << it->second << std::endl; - //} - try - { - m_pMW->Report(pReport); - } - catch(std::string err) - { - std::cerr << err << std::endl; - return false; - } + m_pObserver->Report(pReport); return true; } bool CCommLayerServerDBus::DeleteDebugDump(const std::string& pUUID, const std::string& pDBusSender) { unsigned long unix_uid = m_pConn->sender_unix_uid(pDBusSender.c_str()); - try - { - //std::cerr << "DeleteDebugDump(" << pUUID << "," << unix_uid << ")" << std::endl; - m_pMW->DeleteCrashInfo(pUUID,to_string(unix_uid), true); - } - catch(std::string err) - { - std::cerr << err << std::endl; - return false; - } + m_pObserver->DeleteDebugDump(pUUID,to_string(unix_uid)); return true; } diff --git a/lib/CommLayer/CommLayerServerDBus.h b/lib/CommLayer/CommLayerServerDBus.h index 01314af2..b5d3180f 100644 --- a/lib/CommLayer/CommLayerServerDBus.h +++ b/lib/CommLayer/CommLayerServerDBus.h @@ -16,14 +16,14 @@ class CCommLayerServerDBus DBus::Glib::BusDispatcher *m_pDispatcher; static DBus::Connection *init_dbus(CCommLayerServerDBus *self); public: - CCommLayerServerDBus(CMiddleWare *m_pMW); + CCommLayerServerDBus(); virtual ~CCommLayerServerDBus(); - + virtual vector_crash_infos_t GetCrashInfos(const std::string &pDBusSender); virtual map_crash_report_t CreateReport(const std::string &pUUID,const std::string &pDBusSender); virtual bool Report(map_crash_report_t pReport); virtual bool DeleteDebugDump(const std::string& pUUID, const std::string& pDBusSender); - + void Crash(const std::string& arg1); void AnalyzeComplete(map_crash_report_t arg1); void Error(const std::string& arg1); diff --git a/lib/CommLayer/CommLayerServerSocket.cpp b/lib/CommLayer/CommLayerServerSocket.cpp index c172c86c..b1ae4341 100644 --- a/lib/CommLayer/CommLayerServerSocket.cpp +++ b/lib/CommLayer/CommLayerServerSocket.cpp @@ -2,8 +2,8 @@ #include <iostream> -CCommLayerServerSocket::CCommLayerServerSocket(CMiddleWare *pMW) -: CCommLayerServer(pMW) +CCommLayerServerSocket::CCommLayerServerSocket() +: CCommLayerServer() { std::cout << "CCommLayerServerSocket init" << std::endl; } diff --git a/lib/CommLayer/CommLayerServerSocket.h b/lib/CommLayer/CommLayerServerSocket.h index 75d5852f..d5604f19 100644 --- a/lib/CommLayer/CommLayerServerSocket.h +++ b/lib/CommLayer/CommLayerServerSocket.h @@ -5,6 +5,6 @@ class CCommLayerServerSocket { private: public: - CCommLayerServerSocket(CMiddleWare *pMW); + CCommLayerServerSocket(); ~CCommLayerServerSocket(); }; diff --git a/lib/CommLayer/Makefile.am b/lib/CommLayer/Makefile.am index 2c9d23e6..d17cdc8b 100644 --- a/lib/CommLayer/Makefile.am +++ b/lib/CommLayer/Makefile.am @@ -2,7 +2,8 @@ lib_LTLIBRARIES = libABRTCommLayer.la libABRTCommLayer_la_SOURCES = CommLayerServer.h CommLayerServer.cpp \ CommLayerServerSocket.h CommLayerServerSocket.cpp \ CommLayerServerDBus.h CommLayerServerDBus.cpp \ - DBusServerProxy.h Observer.h DBusCommon.h + DBusServerProxy.h Observer.h DBusCommon.h \ + CommLayerInner.h CommLayerInner.cpp libABRTCommLayer_la_LIBADD = ../../lib/MiddleWare/libABRTMiddleWare.la $(DL_LIBS) $(DBUSCPP_LIBS) libABRTCommLayer_la_LDFLAGS = -version-info 0:1:0 diff --git a/lib/CommLayer/Observer.h b/lib/CommLayer/Observer.h index 94cccc01..6f276d79 100644 --- a/lib/CommLayer/Observer.h +++ b/lib/CommLayer/Observer.h @@ -1,6 +1,20 @@ +#ifndef OBSERVER_H_ +#define OBSERVER_H_ + +#include "CrashTypes.h" + class CObserver { public: //CObserver(); virtual ~CObserver() {} - virtual void Update(const std::string& pMessage) = 0; + virtual void StatusUpdate(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 */ + virtual vector_crash_infos_t GetCrashInfos(const std::string &pDBusSender) = 0; + virtual map_crash_report_t CreateReport(const std::string &pUUID,const std::string &pDBusSender) = 0; + virtual bool Report(map_crash_report_t pReport) = 0; + virtual bool DeleteDebugDump(const std::string& pUUID, const std::string& pDBusSender) = 0; }; + +#endif /* OBSERVER_H_ */ |