diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-09-15 12:43:01 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-09-15 12:43:01 +0200 |
| commit | 0f91e9a06aa0f68a2cbe3c9fc4a858c0a5e6744a (patch) | |
| tree | 13f92f2fc02d346d8474ef03fd0596e3e0447eda /lib/CommLayer | |
| parent | 5f4a56f97f36e9cb844fcf3e4399cea67000a6bb (diff) | |
| download | abrt-0f91e9a06aa0f68a2cbe3c9fc4a858c0a5e6744a.tar.gz abrt-0f91e9a06aa0f68a2cbe3c9fc4a858c0a5e6744a.tar.xz abrt-0f91e9a06aa0f68a2cbe3c9fc4a858c0a5e6744a.zip | |
unify CommLayer, MiddleWare and Utils into Utils
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'lib/CommLayer')
| -rw-r--r-- | lib/CommLayer/CommLayerInner.cpp | 69 | ||||
| -rw-r--r-- | lib/CommLayer/CommLayerInner.h | 23 | ||||
| -rw-r--r-- | lib/CommLayer/DBusClientProxy.cpp | 239 | ||||
| -rw-r--r-- | lib/CommLayer/DBusClientProxy.h | 108 | ||||
| -rw-r--r-- | lib/CommLayer/DBusCommon.h | 29 | ||||
| -rw-r--r-- | lib/CommLayer/Makefile.am | 32 | ||||
| -rw-r--r-- | lib/CommLayer/Observer.h | 16 |
7 files changed, 0 insertions, 516 deletions
diff --git a/lib/CommLayer/CommLayerInner.cpp b/lib/CommLayer/CommLayerInner.cpp deleted file mode 100644 index b5b8db7..0000000 --- a/lib/CommLayer/CommLayerInner.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include <pthread.h> -#include <map> -#include "abrtlib.h" -#include "CommLayerInner.h" - -static CObserver *s_pObs; - -typedef std::map<uint64_t, std::string> map_uint_str_t; -static map_uint_str_t s_mapClientID; -static pthread_mutex_t s_map_mutex; -static bool s_map_mutex_inited; - -void init_daemon_logging(CObserver *pObs) -{ - s_pObs = pObs; - if (!s_map_mutex_inited) - { - pthread_mutex_init(&s_map_mutex, NULL); - s_map_mutex_inited = true; - } -} - -void set_client_name(const char* name) -{ - uint64_t key = uint64_t(pthread_self()); - - pthread_mutex_lock(&s_map_mutex); - if (!name) - s_mapClientID.erase(key); - else - s_mapClientID[key] = name; - pthread_mutex_unlock(&s_map_mutex); -} - -void warn_client(const std::string& pMessage) -{ - if (!s_pObs) - return; - - uint64_t key = uint64_t(pthread_self()); - - pthread_mutex_lock(&s_map_mutex); - map_uint_str_t::const_iterator ki = s_mapClientID.find(key); - const char* peer = (ki != s_mapClientID.end() ? ki->second.c_str() : NULL); - pthread_mutex_unlock(&s_map_mutex); - - if (peer) - s_pObs->Warning(pMessage, peer, key); - else /* Bug: someone tries to warn_client() without set_client_name()!? */ - log("Hmm, stray %s: '%s'", __func__, pMessage.c_str()); -} - -void update_client(const std::string& pMessage) -{ - if (!s_pObs) - return; - - uint64_t key = uint64_t(pthread_self()); - - pthread_mutex_lock(&s_map_mutex); - map_uint_str_t::const_iterator ki = s_mapClientID.find(key); - const char* peer = (ki != s_mapClientID.end() ? ki->second.c_str() : NULL); - pthread_mutex_unlock(&s_map_mutex); - - if (peer) - s_pObs->Status(pMessage, peer, key); - else - log("Hmm, stray %s: '%s'", __func__, pMessage.c_str()); -} diff --git a/lib/CommLayer/CommLayerInner.h b/lib/CommLayer/CommLayerInner.h deleted file mode 100644 index d161cfc..0000000 --- a/lib/CommLayer/CommLayerInner.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef COMMLAYERINNER_H_ -#define COMMLAYERINNER_H_ - -#include "Observer.h" - -void init_daemon_logging(CObserver *pObs); - -/* - * Set client's name (dbus ID). NULL unsets it. - */ -void set_client_name(const char* name); -/* Ask a client to warn the user about a non-fatal, but unexpected condition. - * In GUI, it will usually be presented as a popup message. - */ -void warn_client(const std::string& pMessage); -/* Logs a message to a client. - * In UI, it will usually appear as a new status line message in GUI, - * or as a new message line in CLI. - */ -void update_client(const std::string& pMessage); - -#endif /* COMMLAYERINNER_H_ */ - diff --git a/lib/CommLayer/DBusClientProxy.cpp b/lib/CommLayer/DBusClientProxy.cpp deleted file mode 100644 index ccb48d5..0000000 --- a/lib/CommLayer/DBusClientProxy.cpp +++ /dev/null @@ -1,239 +0,0 @@ -/* - 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 "DBusClientProxy.h" -#include <iostream> - -namespace org { -namespace freedesktop { -namespace DBus { - -/* class DaemonWatcher_proxy */ - -/* public: */ - -DaemonWatcher_proxy::DaemonWatcher_proxy() -: ::DBus::InterfaceProxy("org.freedesktop.DBus") -{ - m_pStateChangeHandler_cb_data = NULL; - m_pStateChangeHandler = NULL; - connect_signal(DaemonWatcher_proxy, NameOwnerChanged, _DaemonStateChanged); -} - -void DaemonWatcher_proxy::ConnectStateChangeHandler(void (*pStateChangeHandler)(bool running, void* data), void *cb_data) -{ - m_pStateChangeHandler_cb_data = cb_data; - m_pStateChangeHandler = pStateChangeHandler; -} - -/* private: */ - -/* unmarshalers (to unpack the DBus message before calling the actual signal handler) - */ -void DaemonWatcher_proxy::_DaemonStateChanged(const ::DBus::SignalMessage &sig) -{ - ::DBus::MessageIter ri = sig.reader(); - std::string name; - std::string old_owner; - std::string new_owner; - ri >> name; - ri >> old_owner; - ri >> new_owner; - if(name.compare("com.redhat.abrt") == 0) - { - if(new_owner.length() > 0) - { - if(m_pStateChangeHandler) - { - m_pStateChangeHandler(true,m_pStateChangeHandler_cb_data); - } - else - { - std::cout << "Daemon appeared!" << std::endl; - } - } - if(new_owner.length() == 0) - { - if(m_pStateChangeHandler) - { - m_pStateChangeHandler(false, m_pStateChangeHandler_cb_data); - } - else - { - std::cout << "Daemon dissapeared!" << std::endl; - } - } - } -} - -} } } /* closing namespaces */ - - -/* class DaemonWatcher */ - -/* public: */ - -DaemonWatcher::DaemonWatcher(DBus::Connection &connection, const char *path, const char *name) -: ::DBus::ObjectProxy(connection, path, name) -{ -} -DaemonWatcher::~DaemonWatcher() -{ - std::cout << "~DaemonWatcher" << std::endl; -} - - -/* class CDBusClient_proxy */ - -/* public: */ - -CDBusClient_proxy::CDBusClient_proxy() -: DBus::InterfaceProxy(CC_DBUS_IFACE) -{ - connect_signal(CDBusClient_proxy, Crash, _Crash_stub); - connect_signal(CDBusClient_proxy, JobDone, _JobDone_stub); - m_sConnName = ""; -} - -CDBusClient_proxy::CDBusClient_proxy(::DBus::Connection &pConnection) -: DBus::InterfaceProxy(CC_DBUS_IFACE) -{ - gloop = g_main_loop_new(NULL, false); - //# define connect_signal(interface, signal, callback) - connect_signal(CDBusClient_proxy, Crash, _Crash_stub); - connect_signal(CDBusClient_proxy, JobDone, _JobDone_stub); - m_sConnName = pConnection.unique_name(); -} - -/* 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> - ... - > - */ -vector_crash_infos_t CDBusClient_proxy::GetCrashInfos() -{ - DBus::CallMessage call; - DBus::MessageIter wi = call.writer(); - - call.member("GetCrashInfos"); - DBus::Message ret = invoke_method(call); - DBus::MessageIter ri = ret.reader(); - - vector_crash_infos_t argout; - ri >> argout; - return argout; -} - -bool CDBusClient_proxy::DeleteDebugDump(const std::string& pUUID) -{ - DBus::CallMessage call; - - DBus::MessageIter wi = call.writer(); - - wi << pUUID; - call.member("DeleteDebugDump"); - DBus::Message ret = invoke_method(call); - DBus::MessageIter ri = ret.reader(); - - bool argout; - ri >> argout; - return argout; -} - -map_crash_report_t CDBusClient_proxy::CreateReport(const std::string& pUUID) -{ - m_bJobDone = false; - DBus::CallMessage call; - - DBus::MessageIter wi = call.writer(); - - wi << pUUID; - call.member("CreateReport"); - DBus::Message ret = invoke_method(call); - DBus::MessageIter ri = ret.reader(); - ri >> m_iPendingJobID; - //FIXME: what if the report is created before we start the loop? (we miss the signal and get stuck in the loop) - g_main_loop_run(gloop); - return GetJobResult(m_iPendingJobID); -}; - -void CDBusClient_proxy::Report(const map_crash_report_t& pReport) -{ - DBus::CallMessage call; - - DBus::MessageIter wi = call.writer(); - - wi << pReport; - call.member("Report"); - DBus::Message ret = invoke_method(call); - DBus::MessageIter ri = ret.reader(); -} - -map_crash_report_t CDBusClient_proxy::GetJobResult(uint64_t pJobID) -{ - DBus::CallMessage call; - - DBus::MessageIter wi = call.writer(); - - wi << pJobID; - call.member("GetJobResult"); - DBus::Message ret = invoke_method(call); - DBus::MessageIter ri = ret.reader(); - map_crash_report_t argout; - ri >> argout; - return argout; -} - -/* signal handlers for this interface - */ -void CDBusClient_proxy::Crash(const std::string& progname, const std::string& uid) -{ -} - -/* private: */ - -/* unmarshalers (to unpack the DBus message before calling the actual signal handler) - */ -void CDBusClient_proxy::_Crash_stub(const ::DBus::SignalMessage &sig) -{ - DBus::MessageIter ri = sig.reader(); - - std::string progname; ri >> progname; - std::string uid; ri >> uid; - Crash(progname, uid); -} - -void CDBusClient_proxy::_JobDone_stub(const ::DBus::SignalMessage &sig) -{ - DBus::MessageIter ri = sig.reader(); - std::string dest; - ri >> dest; - if(m_sConnName == dest) - { - ri >> m_iPendingJobID; - g_main_loop_quit(gloop); - } -} diff --git a/lib/CommLayer/DBusClientProxy.h b/lib/CommLayer/DBusClientProxy.h deleted file mode 100644 index e43805b..0000000 --- a/lib/CommLayer/DBusClientProxy.h +++ /dev/null @@ -1,108 +0,0 @@ -/* - 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. - */ -#ifndef DBUSCLIENTPROXY_H_ -#define DBUSCLIENTPROXY_H_ - -#include <dbus-c++/dbus.h> -#include <dbus-c++/glib-integration.h> -#include "DBusCommon.h" - -#define ABRT_NOT_RUNNING 0 -#define ABRT_RUNNING 1 - -namespace org { -namespace freedesktop { -namespace DBus { - -class DaemonWatcher_proxy -: public ::DBus::InterfaceProxy -{ -private: - void *m_pStateChangeHandler_cb_data; - void (*m_pStateChangeHandler)(bool running, void* data); - -public: - DaemonWatcher_proxy(); - void ConnectStateChangeHandler(void (*pStateChangeHandler)(bool running, void* data), void *cb_data); - -private: - /* unmarshalers (to unpack the DBus message before calling the actual signal handler) - */ - void _DaemonStateChanged(const ::DBus::SignalMessage &sig); -}; - -} } } - - -class DaemonWatcher -: public org::freedesktop::DBus::DaemonWatcher_proxy, - public DBus::IntrospectableProxy, - public DBus::ObjectProxy -{ -public: - - DaemonWatcher(DBus::Connection &connection, const char *path, const char *name); - ~DaemonWatcher(); -}; - - -class CDBusClient_proxy -: public DBus::InterfaceProxy -{ -private: - bool m_bJobDone; - uint64_t m_iPendingJobID; - GMainLoop *gloop; - std::string m_sConnName; - -public: - CDBusClient_proxy(); - CDBusClient_proxy(::DBus::Connection &pConnection); - -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> - ... - > - */ - vector_crash_infos_t GetCrashInfos(); - bool DeleteDebugDump(const std::string& pUUID); - map_crash_report_t CreateReport(const std::string& pUUID); - void Report(const map_crash_report_t& pReport); - map_crash_report_t GetJobResult(uint64_t pJobID); - -public: - /* signal handlers for this interface - */ - virtual void Crash(const std::string& progname, const std::string& uid); - -private: - /* unmarshalers (to unpack the DBus message before calling the actual signal handler) - */ - void _Crash_stub(const ::DBus::SignalMessage &sig); - void _JobDone_stub(const ::DBus::SignalMessage &sig); -}; - -#endif diff --git a/lib/CommLayer/DBusCommon.h b/lib/CommLayer/DBusCommon.h deleted file mode 100644 index b3e3af2..0000000 --- a/lib/CommLayer/DBusCommon.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - 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. - */ - -#ifndef DBUSCOMMON_H_ -#define DBUSCOMMON_H_ - -#include "CrashTypes.h" - -#define CC_DBUS_NAME "com.redhat.abrt" -#define CC_DBUS_PATH "/com/redhat/abrt" -#define CC_DBUS_IFACE "com.redhat.abrt" - -#endif diff --git a/lib/CommLayer/Makefile.am b/lib/CommLayer/Makefile.am deleted file mode 100644 index be0c52b..0000000 --- a/lib/CommLayer/Makefile.am +++ /dev/null @@ -1,32 +0,0 @@ -lib_LTLIBRARIES = libABRTCommLayer.la - -libABRTCommLayer_la_SOURCES = \ - DBusClientProxy.h DBusClientProxy.cpp \ - CommLayerInner.h CommLayerInner.cpp \ - Observer.h \ - DBusCommon.h -libABRTCommLayer_la_LIBADD = \ - ../../lib/MiddleWare/libABRTMiddleWare.la \ - $(DL_LIBS) $(DBUSCPP_LIBS) -libABRTCommLayer_la_LDFLAGS = -version-info 0:1:0 -libABRTCommLayer_la_CPPFLAGS = \ - -Wall -Werror \ - -I$(srcdir)/../../inc \ - -I$(srcdir)/../../lib/MiddleWare \ - -I$(srcdir)/../../lib/DBus \ - -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \ - -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" \ - -DPLUGINS_CONF_DIR=\"$(PLUGINS_CONF_DIR)\" \ - -DCONF_DIR=\"$(CONF_DIR)\" \ - -DVAR_RUN=\"$(VAR_RUN)\" \ - $(GLIB_CFLAGS) $(DBUSCPP_CFLAGS) \ - -D_GNU_SOURCE - -#check_PROGRAMS = test -#test_SOURCES = test.cpp -#test_LDADD = ../Utils/libABRTUtils.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 deleted file mode 100644 index 421dc0c..0000000 --- a/lib/CommLayer/Observer.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef OBSERVER_H_ -#define OBSERVER_H_ - -#include <string> -#include <iostream> -#include <stdint.h> -#include "DBusCommon.h" - -class CObserver { - public: - virtual ~CObserver() {} - virtual void Status(const std::string& pMessage, const char* peer, uint64_t pDest) = 0; - virtual void Warning(const std::string& pMessage, const char* peer, uint64_t pDest) = 0; -}; - -#endif |
