diff options
| author | Jiri Moskovcak <jmoskovc@redhat.com> | 2009-04-01 09:36:46 +0200 |
|---|---|---|
| committer | Jiri Moskovcak <jmoskovc@redhat.com> | 2009-04-01 09:36:46 +0200 |
| commit | 42657326fdf8db194013094537d9386830fe5876 (patch) | |
| tree | a81cde5aa03cc72950987c4eaa29d0461696a3d4 | |
| parent | d879ebf08c48bbe8ed9bd344fceee9163fe464da (diff) | |
| download | abrt-42657326fdf8db194013094537d9386830fe5876.tar.gz abrt-42657326fdf8db194013094537d9386830fe5876.tar.xz abrt-42657326fdf8db194013094537d9386830fe5876.zip | |
Added commlayer to make dbus optional
| -rw-r--r-- | configure.ac | 1 | ||||
| -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 | ||||
| -rw-r--r-- | lib/Makefile.am | 2 | ||||
| -rw-r--r-- | src/Daemon/CrashWatcher.cpp | 39 | ||||
| -rw-r--r-- | src/Daemon/CrashWatcher.h | 28 | ||||
| -rw-r--r-- | src/Daemon/Daemon.cpp | 8 | ||||
| -rw-r--r-- | src/Daemon/Makefile.am | 4 |
17 files changed, 644 insertions, 18 deletions
diff --git a/configure.ac b/configure.ac index d6d13af..e3562c3 100644 --- a/configure.ac +++ b/configure.ac @@ -46,6 +46,7 @@ AC_CONFIG_FILES([ lib/Makefile lib/Utils/Makefile lib/MiddleWare/Makefile + lib/CommLayer/Makefile lib/Plugins/Makefile src/Makefile src/Daemon/Makefile diff --git a/lib/CommLayer/CommLayerServer.cpp b/lib/CommLayer/CommLayerServer.cpp new file mode 100644 index 0000000..1ebae6d --- /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 0000000..bc4082f --- /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 0000000..81afd09 --- /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 0000000..05ca0a4 --- /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 0000000..c172c86 --- /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 0000000..75d5852 --- /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 0000000..f0b8a00 --- /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 0000000..7582541 --- /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 0000000..da6af72 --- /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 0000000..f9635b5 --- /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 0000000..94cccc0 --- /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; +}; diff --git a/lib/Makefile.am b/lib/Makefile.am index b1aad5c..fede186 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1 +1 @@ -SUBDIRS = Utils MiddleWare Plugins
\ No newline at end of file +SUBDIRS = Utils MiddleWare Plugins CommLayer
\ No newline at end of file diff --git a/src/Daemon/CrashWatcher.cpp b/src/Daemon/CrashWatcher.cpp index ad4dac9..3426e92 100644 --- a/src/Daemon/CrashWatcher.cpp +++ b/src/Daemon/CrashWatcher.cpp @@ -31,7 +31,7 @@ #include <dirent.h> #include <cstring> -/* just a helper function */ +/* just a helper function template< class T > std::string to_string( T x ) @@ -40,6 +40,7 @@ to_string( T x ) o << x; return o.str(); } +*/ gboolean CCrashWatcher::handle_event_cb(GIOChannel *gio, GIOCondition condition, gpointer daemon){ GIOError err; @@ -76,7 +77,7 @@ gboolean CCrashWatcher::handle_event_cb(GIOChannel *gio, GIOCondition condition, if(cc->m_pMW->SaveDebugDump(std::string(DEBUG_DUMPS_DIR) + "/" + name, crashinfo)) { /* send message to dbus */ - cc->Crash(crashinfo.m_sPackage); + cc->m_pCommLayer->Crash(crashinfo.m_sPackage); } } catch(std::string err) @@ -94,7 +95,7 @@ gboolean CCrashWatcher::handle_event_cb(GIOChannel *gio, GIOCondition condition, delete[] buf; return TRUE; } - +/* CCrashWatcher::CCrashWatcher(const std::string& pPath,DBus::Connection &connection) : DBus::ObjectAdaptor(connection, CC_DBUS_PATH) { @@ -117,11 +118,39 @@ CCrashWatcher::CCrashWatcher(const std::string& pPath,DBus::Connection &connecti } m_pGio = g_io_channel_unix_new(m_nFd); } +*/ +CCrashWatcher::CCrashWatcher(const std::string& pPath) +{ + int watch = 0; + m_sTarget = pPath; + // middleware object + m_pMW = new CMiddleWare(PLUGINS_CONF_DIR,PLUGINS_LIB_DIR, std::string(CONF_DIR) + "/abrt.conf"); + FindNewDumps(pPath); + m_pMainloop = g_main_loop_new(NULL,FALSE); +#ifdef HAVE_DBUS + m_pCommLayer = new CCommLayerServerDBus(m_pMW); +#elif HAVE_SOCKET + m_pCommLayer = new CCommLayerServerSocket(m_pMW); +#endif + m_pCommLayer = new CCommLayerServerDBus(m_pMW); + m_pCommLayer->Attach(this); + + if((m_nFd = inotify_init()) == -1){ + throw std::string("Init Failed"); + //std::cerr << "Init Failed" << std::endl; + exit(-1); + } + if((watch = inotify_add_watch(m_nFd, pPath.c_str(), IN_CREATE)) == -1){ + + throw std::string("Add watch failed:") + pPath.c_str(); + } + m_pGio = g_io_channel_unix_new(m_nFd); +} CCrashWatcher::~CCrashWatcher() { //delete dispatcher, connection, etc.. - m_pConn->disconnect(); + //m_pConn->disconnect(); delete m_pMW; g_io_channel_unref(m_pGio); g_main_loop_unref(m_pMainloop); @@ -170,6 +199,7 @@ void CCrashWatcher::FindNewDumps(const std::string& pPath) } } } +/* dbus_vector_crash_infos_t CCrashWatcher::GetCrashInfos(const std::string &pUID) { dbus_vector_crash_infos_t retval; @@ -260,6 +290,7 @@ bool CCrashWatcher::DeleteDebugDump(const std::string& pUUID, const std::string& } return true; } +*/ void CCrashWatcher::Lock() { int lfp = open("abrt.lock",O_RDWR|O_CREAT,0640); diff --git a/src/Daemon/CrashWatcher.h b/src/Daemon/CrashWatcher.h index f18a16d..667e521 100644 --- a/src/Daemon/CrashWatcher.h +++ b/src/Daemon/CrashWatcher.h @@ -25,17 +25,25 @@ #include <sys/inotify.h> #include <glib.h> //#include "DBusManager.h" -#include "DBusServerProxy.h" +//#include "DBusServerProxy.h" #include "MiddleWare.h" +#include "CommLayerServerDBus.h" +#ifdef HAVE_DBUS + #include "CommLayerServerDBus.h" +#elif HAVE_SOCKET + #include "CommLayerServerSocket.h" +#endif + // 1024 simultaneous actions #define INOTIFY_BUFF_SIZE ((sizeof(struct inotify_event)+FILENAME_MAX)*1024) class CCrashWatcher -: public CDBusServer_adaptor, - public DBus::IntrospectableAdaptor, - public DBus::ObjectAdaptor +//: public CDBusServer_adaptor, +// public DBus::IntrospectableAdaptor, +// public DBus::ObjectAdaptor, +: public CObserver { private: static gboolean handle_event_cb(GIOChannel *gio, GIOCondition condition, gpointer data); @@ -50,9 +58,13 @@ class CCrashWatcher GMainLoop *m_pMainloop; std::string m_sTarget; CMiddleWare *m_pMW; - DBus::Connection *m_pConn; + CCommLayerServer *m_pCommLayer; + /*FIXME not needed */ + //DBus::Connection *m_pConn; + public: - CCrashWatcher(const std::string& pPath,DBus::Connection &connection); + //CCrashWatcher(const std::string& pPath,DBus::Connection &connection); + CCrashWatcher(const std::string& pPath); ~CCrashWatcher(); //run as daemon void Daemonize(); @@ -66,7 +78,9 @@ class CCrashWatcher dbus_map_report_info_t CreateReport(const std::string &pUUID,const std::string &pDBusSender); bool Report(dbus_map_report_info_t pReport); bool DeleteDebugDump(const std::string& pUUID, const std::string& pDBusSender); - + public: + /* Observer methods */ + void Update(const std::string&) {} }; #endif /*CRASHWATCHER_H_*/ diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp index b5d6cbe..1eca300 100644 --- a/src/Daemon/Daemon.cpp +++ b/src/Daemon/Daemon.cpp @@ -28,7 +28,7 @@ void terminate(int signal) { fprintf(stderr, "Got SIGINT/SIGTERM, cleaning up..\n"); delete ccdaemon; - delete dispatcher; + //delete dispatcher; exit(0); } @@ -37,15 +37,15 @@ int main(int argc, char** argv){ /*signal handlers */ signal(SIGTERM, terminate); signal(SIGINT, terminate); - /* connect to dbus */ + /* connect to dbus //DBus::Glib::BusDispatcher *dispatcher; dispatcher = new DBus::Glib::BusDispatcher(); dispatcher->attach(NULL); DBus::default_dispatcher = dispatcher; DBus::Connection conn = DBus::Connection::SystemBus(); - + */ try{ - ccdaemon = new CCrashWatcher(DEBUG_DUMPS_DIR, conn); + ccdaemon = new CCrashWatcher(DEBUG_DUMPS_DIR); if (argc > 1){ if (strcmp(argv[1], "-d") == 0){ daemonize = 0; diff --git a/src/Daemon/Makefile.am b/src/Daemon/Makefile.am index 70934b4..3eb2292 100644 --- a/src/Daemon/Makefile.am +++ b/src/Daemon/Makefile.am @@ -1,13 +1,13 @@ sbin_PROGRAMS = abrt abrt_SOURCES = CrashWatcher.cpp CrashWatcher.h Daemon.cpp DBusServerProxy.h \ DBusCommon.h -abrt_CPPFLAGS = -Wall -Werror -I../../lib/MiddleWare\ +abrt_CPPFLAGS = -Wall -Werror -I../../lib/MiddleWare -I../../lib/CommLayer\ -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)\" -abrt_LDADD = ../../lib/MiddleWare/libMiddleWare.la $(DL_LIBS) $(DBUSCPP_LIBS) $(RPM_LIBS) +abrt_LDADD = ../../lib/MiddleWare/libMiddleWare.la ../../lib/CommLayer/libABRTCommLayer.la $(DL_LIBS) $(DBUSCPP_LIBS) $(RPM_LIBS) dbusabrtconfdir = ${sysconfdir}/dbus-1/system.d/ dist_dbusabrtconf_DATA = dbus-abrt.conf |
