diff options
Diffstat (limited to 'lib/CommLayer')
-rw-r--r-- | lib/CommLayer/CommLayerServer.cpp | 30 | ||||
-rw-r--r-- | lib/CommLayer/CommLayerServer.h | 49 | ||||
-rw-r--r-- | lib/CommLayer/CommLayerServerDBus.cpp | 120 | ||||
-rw-r--r-- | lib/CommLayer/CommLayerServerDBus.h | 27 | ||||
-rw-r--r-- | lib/CommLayer/CommLayerServerSocket.cpp | 14 | ||||
-rw-r--r-- | lib/CommLayer/CommLayerServerSocket.h | 10 | ||||
-rw-r--r-- | lib/CommLayer/DBusClientProxy.h | 85 | ||||
-rw-r--r-- | lib/CommLayer/DBusCommon.h | 27 | ||||
-rw-r--r-- | lib/CommLayer/DBusServerProxy.h | 189 | ||||
-rw-r--r-- | lib/CommLayer/Makefile.am | 23 | ||||
-rw-r--r-- | lib/CommLayer/Observer.h | 6 |
11 files changed, 580 insertions, 0 deletions
diff --git a/lib/CommLayer/CommLayerServer.cpp b/lib/CommLayer/CommLayerServer.cpp new file mode 100644 index 00000000..1ebae6d3 --- /dev/null +++ b/lib/CommLayer/CommLayerServer.cpp @@ -0,0 +1,30 @@ +#include "CommLayerServer.h" +#include <iostream> + +CCommLayerServer::CCommLayerServer(CMiddleWare *pMW) +{ + 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); +} diff --git a/lib/CommLayer/CommLayerServer.h b/lib/CommLayer/CommLayerServer.h new file mode 100644 index 00000000..bc4082fa --- /dev/null +++ b/lib/CommLayer/CommLayerServer.h @@ -0,0 +1,49 @@ +#include <vector> +#include <map> +#include <string> +#include <sstream> +#include "MiddleWare.h" +#include "Observer.h" + + +//typedef std::vector<crash_info_t> vector_crash_infos_t; +typedef std::vector< std::vector<std::string> > dbus_vector_crash_infos_t; +typedef std::vector< std::map<std::string, std::string> > dbus_vector_map_crash_infos_t; +typedef std::map<std::string, std::string> dbus_map_report_info_t; + +/* just a helper function */ +template< class T > +std::string +to_string( T x ) +{ + std::ostringstream o; + o << x; + return o.str(); +} + +class CCommLayerServer{ + private: + /* FIXME more observers? */ + //std::vector<Observer *obs>; + CObserver *m_pObserver; + public: + CMiddleWare *m_pMW; + CCommLayerServer(CMiddleWare *pMW); + ~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; + */ + public: + /* just stubs to be called when not implemented in specific comm layer */ + void Crash(const std::string& arg1) {} + void AnalyzeComplete(dbus_map_report_info_t arg1) {} + void Error(const std::string& arg1) {} +}; diff --git a/lib/CommLayer/CommLayerServerDBus.cpp b/lib/CommLayer/CommLayerServerDBus.cpp new file mode 100644 index 00000000..81afd090 --- /dev/null +++ b/lib/CommLayer/CommLayerServerDBus.cpp @@ -0,0 +1,120 @@ +#include "CommLayerServerDBus.h" +#include <iostream> + +DBus::Connection *CCommLayerServerDBus::init_dbus(CCommLayerServerDBus *self) +{ + CCommLayerServerDBus *server = (CCommLayerServerDBus*) self; + server->dispatcher = new DBus::Glib::BusDispatcher(); + server->dispatcher->attach(NULL); + DBus::default_dispatcher = self->dispatcher; + server->m_pConn = new DBus::Connection(DBus::Connection::SystemBus()); + return server->m_pConn; +} + +CCommLayerServerDBus::CCommLayerServerDBus(CMiddleWare *pMW) +: CCommLayerServer(pMW), + DBus::ObjectAdaptor(*init_dbus(this), CC_DBUS_PATH) +{ + std::cerr << "CCommLayerDBus init.." << std::endl; + m_pConn->request_name(CC_DBUS_NAME); + +} + +CCommLayerServerDBus::~CCommLayerServerDBus() +{ + std::cout << "Cleaning up dbus" << std::endl; + delete dispatcher; +} + +dbus_vector_crash_infos_t CCommLayerServerDBus::GetCrashInfos(const std::string &pUID) +{ + dbus_vector_crash_infos_t retval; + vector_crash_infos_t crash_info; + m_pMW->GetCrashInfos("501"); + for (vector_crash_infos_t::iterator it = crash_info.begin(); it!=crash_info.end(); ++it) { + std::cerr << it->m_sExecutable << std::endl; + } + return retval; +} + +dbus_vector_map_crash_infos_t CCommLayerServerDBus::GetCrashInfosMap(const std::string &pDBusSender) +{ + dbus_vector_map_crash_infos_t retval; + vector_crash_infos_t crash_info; + unsigned long unix_uid = m_pConn->sender_unix_uid(pDBusSender.c_str()); + try + { + crash_info = m_pMW->GetCrashInfos(to_string(unix_uid)); + } + catch(std::string err) + { + std::cerr << err << std::endl; + } + for (vector_crash_infos_t::iterator it = crash_info.begin(); it!=crash_info.end(); ++it) { + std::cerr << it->m_sExecutable << std::endl; + retval.push_back(it->GetMap()); + } + Notify("Sent crash info"); + return retval; +} + +dbus_map_report_info_t CCommLayerServerDBus::CreateReport(const std::string &pUUID,const std::string &pDBusSender) +{ + dbus_map_report_info_t retval; + unsigned long unix_uid = m_pConn->sender_unix_uid(pDBusSender.c_str()); + //std::cerr << pUUID << ":" << unix_uid << std::endl; + crash_report_t crashReport; + std::cerr << "Creating report" << std::endl; + try + { + m_pMW->CreateReport(pUUID,to_string(unix_uid), crashReport); + retval = crashReport.GetMap(); + //send out the message about completed analyze + CDBusServer_adaptor::AnalyzeComplete(retval); + } + catch(std::string err) + { + CDBusServer_adaptor::Error(err); + std::cerr << err << std::endl; + } + return retval; +} + +bool CCommLayerServerDBus::Report(dbus_map_report_info_t pReport) +{ + crash_report_t crashReport; + //#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; + //} + crashReport.SetFromMap(pReport); + try + { + m_pMW->Report(crashReport); + } + catch(std::string err) + { + std::cerr << err << std::endl; + return false; + } + 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; + } + return true; +} diff --git a/lib/CommLayer/CommLayerServerDBus.h b/lib/CommLayer/CommLayerServerDBus.h new file mode 100644 index 00000000..05ca0a47 --- /dev/null +++ b/lib/CommLayer/CommLayerServerDBus.h @@ -0,0 +1,27 @@ +#include "CommLayerServer.h" + +#include <dbus-c++/dbus.h> +#include <dbus-c++/glib-integration.h> +#include "DBusServerProxy.h" + +class CCommLayerServerDBus +: public CCommLayerServer, + public CDBusServer_adaptor, + public DBus::IntrospectableAdaptor, + public DBus::ObjectAdaptor +{ + private: + DBus::Connection *m_pConn; + DBus::Glib::BusDispatcher *dispatcher; + static DBus::Connection *init_dbus(CCommLayerServerDBus *self); + public: + CCommLayerServerDBus(CMiddleWare *m_pMW); + ~CCommLayerServerDBus(); + + virtual dbus_vector_crash_infos_t GetCrashInfos(const std::string &pUID); + virtual dbus_vector_map_crash_infos_t GetCrashInfosMap(const std::string &pDBusSender); + virtual dbus_map_report_info_t CreateReport(const std::string &pUUID,const std::string &pDBusSender); + virtual bool Report(dbus_map_report_info_t pReport); + virtual bool DeleteDebugDump(const std::string& pUUID, const std::string& pDBusSender); +}; + diff --git a/lib/CommLayer/CommLayerServerSocket.cpp b/lib/CommLayer/CommLayerServerSocket.cpp new file mode 100644 index 00000000..c172c86c --- /dev/null +++ b/lib/CommLayer/CommLayerServerSocket.cpp @@ -0,0 +1,14 @@ +#include "CommLayerServerSocket.h" +#include <iostream> + + +CCommLayerServerSocket::CCommLayerServerSocket(CMiddleWare *pMW) +: CCommLayerServer(pMW) +{ + std::cout << "CCommLayerServerSocket init" << std::endl; +} + +CCommLayerServerSocket::~CCommLayerServerSocket() +{ + std::cout << "Cleaning up Socket" << std::endl; +} diff --git a/lib/CommLayer/CommLayerServerSocket.h b/lib/CommLayer/CommLayerServerSocket.h new file mode 100644 index 00000000..75d5852f --- /dev/null +++ b/lib/CommLayer/CommLayerServerSocket.h @@ -0,0 +1,10 @@ +#include "CommLayerServer.h" + +class CCommLayerServerSocket +: public CCommLayerServer +{ + private: + public: + CCommLayerServerSocket(CMiddleWare *pMW); + ~CCommLayerServerSocket(); +}; diff --git a/lib/CommLayer/DBusClientProxy.h b/lib/CommLayer/DBusClientProxy.h new file mode 100644 index 00000000..f0b8a001 --- /dev/null +++ b/lib/CommLayer/DBusClientProxy.h @@ -0,0 +1,85 @@ +/* + Copyright (C) 2009 Jiri Moskovcak (jmoskovc@redhat.com) + Copyright (C) 2009 RedHat inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include <dbus-c++/dbus.h> +#include <dbus-c++/glib-integration.h> +#include "DBusCommon.h" + +class CDBusClient_proxy + : public DBus::InterfaceProxy +{ +public: + + CDBusClient_proxy() + : DBus::InterfaceProxy(CC_DBUS_IFACE) + { + //# define connect_signal(interface, signal, callback) + connect_signal(CDBusClient_proxy, Crash, _Crash_stub); + } + +public: + + /* properties exported by this interface */ +public: + + /* methods exported by this interface, + * this functions will invoke the corresponding methods on the remote objects + */ + /* + + < + <m_sUUID;m_sUID;m_sCount;m_sExecutable;m_sPackage> + <m_sUUID;m_sUID;m_sCount;m_sExecutable;m_sPackage> + <m_sUUID;m_sUID;m_sCount;m_sExecutable;m_sPackage> + ... + > + */ + dbus_vector_crash_infos_t GetCrashInfos(const std::string &pUID) + { + DBus::CallMessage call; + + DBus::MessageIter wi = call.writer(); + + wi << pUID; + call.member("GetCrashInfos"); + DBus::Message ret = invoke_method(call); + DBus::MessageIter ri = ret.reader(); + + dbus_vector_crash_infos_t argout; + ri >> argout; + return argout; + } +public: + + /* signal handlers for this interface + */ + virtual void Crash(std::string& value) = 0; + +private: + + /* unmarshalers (to unpack the DBus message before calling the actual signal handler) + */ + void _Crash_stub(const ::DBus::SignalMessage &sig) + { + DBus::MessageIter ri = sig.reader(); + + std::string value; ri >> value; + Crash(value); + } +}; diff --git a/lib/CommLayer/DBusCommon.h b/lib/CommLayer/DBusCommon.h new file mode 100644 index 00000000..7582541c --- /dev/null +++ b/lib/CommLayer/DBusCommon.h @@ -0,0 +1,27 @@ +/* + Copyright (C) 2009 Jiri Moskovcak (jmoskovc@redhat.com) + Copyright (C) 2009 RedHat inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#define CC_DBUS_NAME "com.redhat.abrt" +#define CC_DBUS_PATH "/com/redhat/abrt" +#define CC_DBUS_IFACE "com.redhat.abrt" + +//typedef std::vector<crash_info_t> vector_crash_infos_t; +typedef std::vector< std::vector<std::string> > dbus_vector_crash_infos_t; +typedef std::vector< std::map<std::string, std::string> > dbus_vector_map_crash_infos_t; +typedef std::map<std::string, std::string> dbus_map_report_info_t; diff --git a/lib/CommLayer/DBusServerProxy.h b/lib/CommLayer/DBusServerProxy.h new file mode 100644 index 00000000..da6af721 --- /dev/null +++ b/lib/CommLayer/DBusServerProxy.h @@ -0,0 +1,189 @@ +/* + Copyright (C) 2009 Jiri Moskovcak (jmoskovc@redhat.com) + Copyright (C) 2009 RedHat inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +#include <dbus-c++/dbus.h> +#include <dbus-c++/glib-integration.h> +#include "DBusCommon.h" +#include <map> +#include <map> + +class CDBusServer_adaptor +: public DBus::InterfaceAdaptor +{ +public: + + CDBusServer_adaptor() + : DBus::InterfaceAdaptor(CC_DBUS_IFACE) + { + register_method(CDBusServer_adaptor, GetCrashInfos, _GetCrashInfos_stub); + register_method(CDBusServer_adaptor, GetCrashInfosMap, _GetCrashInfosMap_stub); + register_method(CDBusServer_adaptor, CreateReport, _CreateReport_stub); + register_method(CDBusServer_adaptor, Report, _Report_stub); + register_method(CDBusServer_adaptor, DeleteDebugDump, _DeleteDebugDump_stub); + } +/* reveal Interface introspection when we stabilize the API */ +/* + DBus::IntrospectedInterface *const introspect() const + { + static DBus::IntrospectedArgument GetCrashInfos_args[] = + { + //{ "uid", "i", true}, + { "info", "a{ss}", false }, + { 0, 0, 0 } + }; + static DBus::IntrospectedArgument Crash_args[] = + { + { "package", "s", false }, + { 0, 0, 0 } + }; + static DBus::IntrospectedMethod CDBusServer_adaptor_methods[] = + { + { "GetCrashInfos", GetCrashInfos_args }, + { 0, 0 }, + { "GetCrashInfosMap", GetCrashInfos_args }, + { 0, 0 } + }; + static DBus::IntrospectedMethod CDBusServer_adaptor_signals[] = + { + { "Crash", Crash_args }, + { 0, 0 } + }; + static DBus::IntrospectedProperty CDBusServer_adaptor_properties[] = + { + { 0, 0, 0, 0 } + }; + static DBus::IntrospectedInterface CDBusServer_adaptor_interface = + { + "com.redhat.abrt", + CDBusServer_adaptor_methods, + CDBusServer_adaptor_signals, + CDBusServer_adaptor_properties + }; + return &CDBusServer_adaptor_interface; + } +*/ +public: + + /* properties exposed by this interface, use + * property() and property(value) to get and set a particular property + */ + +public: + + /* methods exported by this interface, + * you will have to implement them in your ObjectAdaptor + */ + 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; + +public: + /* signal emitters for this interface + */ + /* Notify the clients (UI) about a new crash */ + void Crash(const std::string& arg1) + { + ::DBus::SignalMessage sig("Crash"); + ::DBus::MessageIter wi = sig.writer(); + wi << arg1; + emit_signal(sig); + } + /* Notify the clients that creating a report has finished */ + void AnalyzeComplete(dbus_map_report_info_t arg1) + { + ::DBus::SignalMessage sig("AnalyzeComplete"); + ::DBus::MessageIter wi = sig.writer(); + wi << arg1; + emit_signal(sig); + } + + void Error(const std::string& arg1) + { + ::DBus::SignalMessage sig("Error"); + ::DBus::MessageIter wi = sig.writer(); + wi << arg1; + emit_signal(sig); + } + +private: + + /* unmarshalers (to unpack the DBus message before calling the actual interface method) + */ + DBus::Message _GetCrashInfos_stub(const DBus::CallMessage &call) + { + DBus::MessageIter ri = call.reader(); + + std::string argin1; ri >> argin1; + dbus_vector_crash_infos_t argout1 = GetCrashInfos(argin1); + DBus::ReturnMessage reply(call); + DBus::MessageIter wi = reply.writer(); + wi << argout1; + return reply; + } + + DBus::Message _CreateReport_stub(const DBus::CallMessage &call) + { + DBus::MessageIter ri = call.reader(); + + std::string argin1; ri >> argin1; + dbus_map_report_info_t argout1 = CreateReport(argin1,call.sender()); + DBus::ReturnMessage reply(call); + DBus::MessageIter wi = reply.writer(); + wi << argout1; + return reply; + } + + DBus::Message _GetCrashInfosMap_stub(const DBus::CallMessage &call) + { + DBus::MessageIter ri = call.reader(); + + std::string argin1; ri >> argin1; + dbus_vector_map_crash_infos_t argout1 = GetCrashInfosMap(call.sender()); + DBus::ReturnMessage reply(call); + DBus::MessageIter wi = reply.writer(); + wi << argout1; + return reply; + } + + DBus::Message _Report_stub(const DBus::CallMessage &call) + { + DBus::MessageIter ri = call.reader(); + + dbus_map_report_info_t argin1; ri >> argin1; + bool argout1 = Report(argin1); + DBus::ReturnMessage reply(call); + DBus::MessageIter wi = reply.writer(); + wi << argout1; + return reply; + } + + DBus::Message _DeleteDebugDump_stub(const DBus::CallMessage &call) + { + DBus::MessageIter ri = call.reader(); + + std::string argin1; ri >> argin1; + bool argout1 = DeleteDebugDump(argin1,call.sender()); + DBus::ReturnMessage reply(call); + DBus::MessageIter wi = reply.writer(); + wi << argout1; + return reply; + } +}; + diff --git a/lib/CommLayer/Makefile.am b/lib/CommLayer/Makefile.am new file mode 100644 index 00000000..f9635b5d --- /dev/null +++ b/lib/CommLayer/Makefile.am @@ -0,0 +1,23 @@ +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 + +libABRTCommLayer_la_LIBADD = ../../lib/MiddleWare/libMiddleWare.la $(DL_LIBS) $(DBUSCPP_LIBS) +libABRTCommLayer_la_LDFLAGS = -version-info 0:1:0 +libABRTCommLayer_la_CPPFLAGS = -Wall -Werror -I../../lib/MiddleWare\ + -I../../lib/DBus \ + -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" $(GLIB_CFLAGS) $(DBUSCPP_CFLAGS) \ + -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" \ + -DPLUGINS_CONF_DIR=\"$(PLUGINS_CONF_DIR)\" \ + -DCONF_DIR=\"$(CONF_DIR)\" + +#check_PROGRAMS = test +#test_SOURCES = test.cpp +#test_LDADD = ../Utils/libUtils.la libABRTCommLayer.la $(DL_LIBS) $(RPM_LIBS) +#test_CPPFLAGS = -I$(srcdir)/../Utils \ +# -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" \ +# -DPLUGINS_CONF_DIR=\"$(PLUGINS_CONF_DIR)\" \ +# -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \ +# -DCONF_DIR=\"$(CONF_DIR)\" diff --git a/lib/CommLayer/Observer.h b/lib/CommLayer/Observer.h new file mode 100644 index 00000000..94cccc01 --- /dev/null +++ b/lib/CommLayer/Observer.h @@ -0,0 +1,6 @@ +class CObserver { + public: + //CObserver(); + virtual ~CObserver() {} + virtual void Update(const std::string& pMessage) = 0; +}; |