From 5d3a66f0b6cc2e9fd6a5dc5815d65d6708050ccc Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 21 Jan 2011 17:34:29 +0100 Subject: remove CCommLayerServer[DBus] classes Signed-off-by: Denys Vlasenko --- src/daemon/CommLayerServer.cpp | 28 ------------------------ src/daemon/CommLayerServer.h | 44 -------------------------------------- src/daemon/CommLayerServerDBus.cpp | 22 ++++++++++++------- src/daemon/CommLayerServerDBus.h | 30 +++++++++++++------------- src/daemon/Daemon.cpp | 13 ++++------- src/daemon/Daemon.h | 29 ------------------------- src/daemon/Makefile.am | 3 +-- src/daemon/MiddleWare.cpp | 5 ++--- src/daemon/comm_layer_inner.cpp | 9 +++----- 9 files changed, 39 insertions(+), 144 deletions(-) delete mode 100644 src/daemon/CommLayerServer.cpp delete mode 100644 src/daemon/CommLayerServer.h delete mode 100644 src/daemon/Daemon.h (limited to 'src/daemon') diff --git a/src/daemon/CommLayerServer.cpp b/src/daemon/CommLayerServer.cpp deleted file mode 100644 index 748611b3..00000000 --- a/src/daemon/CommLayerServer.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/* - Copyright (C) 2010 ABRT team - Copyright (C) 2010 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 "CommLayerServer.h" - -CCommLayerServer::CCommLayerServer() -{ - m_init_error = 0; -} - -CCommLayerServer::~CCommLayerServer() -{ -} diff --git a/src/daemon/CommLayerServer.h b/src/daemon/CommLayerServer.h deleted file mode 100644 index 17ecb44a..00000000 --- a/src/daemon/CommLayerServer.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - Copyright (C) 2010 ABRT team - Copyright (C) 2010 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 COMMLAYERSERVER_H_ -#define COMMLAYERSERVER_H_ - -#include "abrtlib.h" - -class CCommLayerServer { - public: - int m_init_error; - - CCommLayerServer(); - virtual ~CCommLayerServer(); - - /* just stubs to be called when not implemented in specific comm layer */ - virtual void Crash(const char *package_name, - const char *crash_id, - const char *dir, - const char *uid_str - ) {} - virtual void JobDone(const char* peer) = 0; - virtual void QuotaExceeded(const char* str) {} - - virtual void Update(const char* pMessage, const char* peer) {}; - virtual void Warning(const char* pMessage, const char* peer) {}; -}; - -#endif diff --git a/src/daemon/CommLayerServerDBus.cpp b/src/daemon/CommLayerServerDBus.cpp index 654a1ad4..be1f30f3 100644 --- a/src/daemon/CommLayerServerDBus.cpp +++ b/src/daemon/CommLayerServerDBus.cpp @@ -23,7 +23,6 @@ #include "dbus_common.h" #include "MiddleWare.h" #include "Settings.h" -#include "Daemon.h" #include "CommLayerServerDBus.h" // 16kB message limit @@ -47,6 +46,11 @@ static DBusMessage* new_signal_msg(const char* member, const char* peer = NULL) } static void send_flush_and_unref(DBusMessage* msg) { + if (!g_dbus_conn) + { + /* Not logging this, it may recurse */ + return; + } if (!dbus_connection_send(g_dbus_conn, msg, NULL /* &serial */)) error_msg_and_die("Error sending DBus message"); dbus_connection_flush(g_dbus_conn); @@ -55,7 +59,7 @@ static void send_flush_and_unref(DBusMessage* msg) } /* Notify the clients (UI) about a new crash */ -void CCommLayerServerDBus::Crash(const char *package_name, +void send_dbus_sig_Crash(const char *package_name, const char *crash_id, const char *dir, const char *uid_str @@ -83,7 +87,7 @@ void CCommLayerServerDBus::Crash(const char *package_name, send_flush_and_unref(msg); } -void CCommLayerServerDBus::QuotaExceeded(const char* str) +void send_dbus_sig_QuotaExceeded(const char* str) { DBusMessage* msg = new_signal_msg("QuotaExceeded"); dbus_message_append_args(msg, @@ -93,14 +97,14 @@ void CCommLayerServerDBus::QuotaExceeded(const char* str) send_flush_and_unref(msg); } -void CCommLayerServerDBus::JobDone(const char* peer) +void send_dbus_sig_JobDone(const char* peer) { DBusMessage* msg = new_signal_msg("JobDone", peer); VERB2 log("Sending signal JobDone() to peer %s", peer); send_flush_and_unref(msg); } -void CCommLayerServerDBus::Update(const char* pMessage, const char* peer) +void send_dbus_sig_Update(const char* pMessage, const char* peer) { DBusMessage* msg = new_signal_msg("Update", peer); dbus_message_append_args(msg, @@ -109,7 +113,7 @@ void CCommLayerServerDBus::Update(const char* pMessage, const char* peer) send_flush_and_unref(msg); } -void CCommLayerServerDBus::Warning(const char* pMessage, const char* peer) +void send_dbus_sig_Warning(const char* pMessage, const char* peer) { DBusMessage* msg = new_signal_msg("Warning", peer); dbus_message_append_args(msg, @@ -464,7 +468,7 @@ static void handle_dbus_err(bool error_flag, DBusError *err) ABRTD_DBUS_NAME); } -CCommLayerServerDBus::CCommLayerServerDBus() +int init_dbus() { DBusConnection* conn; DBusError err; @@ -514,9 +518,11 @@ CCommLayerServerDBus::CCommLayerServerDBus() int cnt = 10; while (dbus_connection_dispatch(conn) != DBUS_DISPATCH_COMPLETE && --cnt) VERB3 log("processed initial buffered dbus message"); + + return 0; } -CCommLayerServerDBus::~CCommLayerServerDBus() +void deinit_dbus() { dbus_connection_unref(g_dbus_conn); } diff --git a/src/daemon/CommLayerServerDBus.h b/src/daemon/CommLayerServerDBus.h index 4e632fb9..979fef69 100644 --- a/src/daemon/CommLayerServerDBus.h +++ b/src/daemon/CommLayerServerDBus.h @@ -19,26 +19,26 @@ #ifndef COMMLAYERSERVERDBUS_H_ #define COMMLAYERSERVERDBUS_H_ -#include "CommLayerServer.h" +#ifdef __cplusplus +extern "C" { +#endif -class CCommLayerServerDBus -: public CCommLayerServer -{ - public: - CCommLayerServerDBus(); - virtual ~CCommLayerServerDBus(); +int init_dbus(void); +void deinit_dbus(void); - /* DBus signal senders */ - virtual void Crash(const char *package_name, +void send_dbus_sig_Crash(const char *package_name, const char *crash_id, const char *dir, const char *uid_str - ); - virtual void JobDone(const char* peer); - virtual void QuotaExceeded(const char* str); +); +void send_dbus_sig_JobDone(const char* peer); +void send_dbus_sig_QuotaExceeded(const char* str); + +void send_dbus_sig_Update(const char* pMessage, const char* peer); +void send_dbus_sig_Warning(const char* pMessage, const char* peer); - virtual void Update(const char* pMessage, const char* peer); - virtual void Warning(const char* pMessage, const char* peer); -}; +#ifdef __cplusplus +} +#endif #endif diff --git a/src/daemon/Daemon.cpp b/src/daemon/Daemon.cpp index 25b2bbdf..ca9cf0c5 100644 --- a/src/daemon/Daemon.cpp +++ b/src/daemon/Daemon.cpp @@ -30,7 +30,6 @@ #include "Settings.h" #include "CommLayerServerDBus.h" #include "MiddleWare.h" -#include "Daemon.h" #include "parse_options.h" #define PROGNAME "abrtd" @@ -83,8 +82,6 @@ using namespace std; * Both are sent as unicast to last client set by set_client_name(name). * If set_client_name(NULL) was done, they are not sent. */ -CCommLayerServer* g_pCommLayer; - static volatile sig_atomic_t s_sig_caught; static int s_signal_pipe[2]; static int s_signal_pipe_write = -1; @@ -371,7 +368,7 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin && worst_dir ) { log("Size of '%s' >= %u MB, deleting '%s'", DEBUG_DUMPS_DIR, g_settings_nMaxCrashReportsSize, worst_dir); - g_pCommLayer->QuotaExceeded(_("The size of the report exceeded the quota. Please check system's MaxCrashReportsSize value in abrt.conf.")); + send_dbus_sig_QuotaExceeded(_("The size of the report exceeded the quota. Please check system's MaxCrashReportsSize value in abrt.conf.")); /* deletes both directory and DB record */ char *d = concat_path_file(DEBUG_DUMPS_DIR, worst_dir); free(worst_dir); @@ -411,8 +408,7 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin get_crash_item_content_or_NULL(crash_data, FILENAME_UID), get_crash_item_content_or_NULL(crash_data, FILENAME_UUID) ); - /* Send dbus signal */ - g_pCommLayer->Crash(get_crash_item_content_or_NULL(crash_data, FILENAME_PACKAGE), + send_dbus_sig_Crash(get_crash_item_content_or_NULL(crash_data, FILENAME_PACKAGE), crash_id, //TODO: stop passing this param, it is unused fullname, uid_str @@ -688,8 +684,7 @@ int main(int argc, char** argv) * therefore it should be the last thing to initialize. */ VERB1 log("Initializing dbus"); - g_pCommLayer = new CCommLayerServerDBus(); - if (g_pCommLayer->m_init_error) + if (init_dbus() != 0) throw 1; } catch (...) @@ -751,7 +746,7 @@ int main(int argc, char** argv) if (channel_inotify) g_io_channel_unref(channel_inotify); - delete g_pCommLayer; + deinit_dbus(); if (pMainloop) g_main_loop_unref(pMainloop); diff --git a/src/daemon/Daemon.h b/src/daemon/Daemon.h deleted file mode 100644 index d4cf0414..00000000 --- a/src/daemon/Daemon.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - Copyright (C) 2009 Denys Vlasenko (dvlasenk@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 DAEMON_H_ -#define DAEMON_H_ - -#include -#include "abrt_types.h" -#include "CommLayerServer.h" - -/* Used for sending dbus signals */ -extern CCommLayerServer *g_pCommLayer; - -#endif diff --git a/src/daemon/Makefile.am b/src/daemon/Makefile.am index 37b662af..6fe73065 100644 --- a/src/daemon/Makefile.am +++ b/src/daemon/Makefile.am @@ -11,11 +11,10 @@ sbin_PROGRAMS = \ abrtd_SOURCES = \ MiddleWare.h MiddleWare.cpp \ - CommLayerServer.h CommLayerServer.cpp \ CommLayerServerDBus.h CommLayerServerDBus.cpp \ Settings.h Settings.cpp \ comm_layer_inner.h comm_layer_inner.cpp \ - Daemon.h Daemon.cpp + Daemon.cpp abrtd_CPPFLAGS = \ -I$(srcdir)/../include/report -I$(srcdir)/../include \ -I$(srcdir)/../lib \ diff --git a/src/daemon/MiddleWare.cpp b/src/daemon/MiddleWare.cpp index 9a01bf3d..2f15d50d 100644 --- a/src/daemon/MiddleWare.cpp +++ b/src/daemon/MiddleWare.cpp @@ -19,10 +19,9 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "abrtlib.h" -#include "Daemon.h" #include "Settings.h" #include "comm_layer_inner.h" -#include "CommLayerServer.h" +#include "CommLayerServerDBus.h" #include "MiddleWare.h" using namespace std; @@ -703,7 +702,7 @@ static void* create_report(void* arg) log("Creating report..."); crash_data_t *crash_data = NULL; CreateReport(thread_data->crash_id, thread_data->caller_uid, thread_data->force, &crash_data); - g_pCommLayer->JobDone(thread_data->peer); + send_dbus_sig_JobDone(thread_data->peer); set_client_name(NULL); /* free strduped strings */ diff --git a/src/daemon/comm_layer_inner.cpp b/src/daemon/comm_layer_inner.cpp index 59f7c3f3..9d5ddfc2 100644 --- a/src/daemon/comm_layer_inner.cpp +++ b/src/daemon/comm_layer_inner.cpp @@ -19,7 +19,7 @@ #include #include #include "abrtlib.h" -#include "Daemon.h" +#include "CommLayerServerDBus.h" #include "comm_layer_inner.h" typedef std::map map_uint_str_t; @@ -39,9 +39,7 @@ static void warn_client(const char *msg) if (peer) { - VERB1 log("Warning('%s'): %s", peer, msg); - if (g_pCommLayer != NULL) - g_pCommLayer->Warning(msg, peer); + send_dbus_sig_Warning(msg, peer); } } @@ -86,8 +84,7 @@ void update_client(const char *fmt, ...) va_end(p); VERB1 log("Update('%s'): %s", peer, msg); - if (g_pCommLayer != NULL) - g_pCommLayer->Update(msg, peer); + send_dbus_sig_Update(msg, peer); free(msg); } -- cgit