summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJiri Moskovcak <jmoskovc@redhat.com>2009-02-19 14:52:09 +0100
committerJiri Moskovcak <jmoskovc@redhat.com>2009-02-19 14:52:09 +0100
commit71d3637ffe75f9dd910d418e9b9d5242ec9ac423 (patch)
tree46938b59068d0f8a0d5ba61db6305cd2dee10a75 /src
parente5fdb1cbef199fd48ed7615cc83383bc55a345fa (diff)
downloadabrt-71d3637ffe75f9dd910d418e9b9d5242ec9ac423.tar.gz
abrt-71d3637ffe75f9dd910d418e9b9d5242ec9ac423.tar.xz
abrt-71d3637ffe75f9dd910d418e9b9d5242ec9ac423.zip
Moved dbus backend from lib to applet - better OO model.
Diffstat (limited to 'src')
-rw-r--r--src/Applet/Applet.cpp7
-rw-r--r--src/Applet/CCApplet.cpp21
-rw-r--r--src/Applet/CCApplet.h11
-rw-r--r--src/Applet/DBusClientProxy.h85
-rw-r--r--src/Applet/Makefile.am6
5 files changed, 121 insertions, 9 deletions
diff --git a/src/Applet/Applet.cpp b/src/Applet/Applet.cpp
index b33cc9f..8984e0e 100644
--- a/src/Applet/Applet.cpp
+++ b/src/Applet/Applet.cpp
@@ -18,7 +18,6 @@
*/
#include "CCApplet.h"
-#include "DBusClient.h"
#include <iostream>
//@@global applet object
@@ -43,7 +42,6 @@ int main(int argc, char **argv)
gdk_threads_init();
gdk_threads_enter();
gtk_init(&argc,&argv);
- applet = new CApplet();
/* move to the DBusClient::connect */
DBus::Glib::BusDispatcher dispatcher;
/* this should bind the dispatcher with mainloop */
@@ -51,8 +49,9 @@ int main(int argc, char **argv)
DBus::default_dispatcher = &dispatcher;
DBus::Connection conn = DBus::Connection::SystemBus();
- CDBusClient client(conn, CC_DBUS_PATH, CC_DBUS_NAME);
- client.ConnectCrashHandler(crash_notify_cb);
+ //CDBusClient client(conn, CC_DBUS_PATH, CC_DBUS_NAME);
+ applet = new CApplet(conn, CC_DBUS_PATH, CC_DBUS_NAME);
+ applet->ConnectCrashHandler(crash_notify_cb);
gtk_main();
gdk_threads_leave();
return 0;
diff --git a/src/Applet/CCApplet.cpp b/src/Applet/CCApplet.cpp
index 45062dc..de42f91 100644
--- a/src/Applet/CCApplet.cpp
+++ b/src/Applet/CCApplet.cpp
@@ -22,7 +22,8 @@
#include <cstdarg>
#include <sstream>
-CApplet::CApplet()
+CApplet::CApplet(DBus::Connection &connection, const char *path, const char *name)
+: DBus::ObjectProxy(connection, path, name)
{
m_pStatusIcon = gtk_status_icon_new_from_stock(GTK_STOCK_DIALOG_WARNING);
gtk_status_icon_set_visible(m_pStatusIcon,FALSE);
@@ -37,7 +38,25 @@ CApplet::CApplet()
CApplet::~CApplet()
{
}
+/* dbus related */
+void CApplet::Crash(std::string &value)
+{
+ if(m_pCrashHandler)
+ {
+ m_pCrashHandler(value.c_str());
+ }
+ else
+ {
+ std::cout << "This is default handler, you should register your own with ConnectCrashHandler" << std::endl;
+ std::cout.flush();
+ }
+}
+void CApplet::ConnectCrashHandler(void (*pCrashHandler)(const char *progname))
+{
+ m_pCrashHandler = pCrashHandler;
+}
+/* --- */
void CApplet::SetIconTooltip(const char *format, ...)
{
va_list args;
diff --git a/src/Applet/CCApplet.h b/src/Applet/CCApplet.h
index 09aee38..b1c62a4 100644
--- a/src/Applet/CCApplet.h
+++ b/src/Applet/CCApplet.h
@@ -23,15 +23,19 @@
#include <gtk/gtk.h>
#include <map>
#include <string>
+#include <DBusClientProxy.h>
class CApplet
+: public CDBusClient_proxy,
+ public DBus::IntrospectableProxy,
+ public DBus::ObjectProxy
{
private:
//Glib::RefPtr<Gtk::StatusIcon> m_nStatusIcon;
GtkStatusIcon* m_pStatusIcon;
std::map<int, std::string > m_mapEvents;
public:
- CApplet();
+ CApplet(DBus::Connection &connection, const char *path, const char *name);
~CApplet();
void ShowIcon();
void HideIcon();
@@ -44,6 +48,8 @@ class CApplet
// map::
int AddEvent(int pUUID, const std::string& pProgname);
int RemoveEvent(int pUUID);
+ void ConnectCrashHandler(void (*pCrashHandler)(const char *progname));
+ void Crash(std::string &value);
protected:
//@@TODO applet menus
void OnAppletActivate_CB();
@@ -52,6 +58,9 @@ class CApplet
//Glib::RefPtr<Gtk::UIManager> m_refUIManager;
//Glib::RefPtr<Gtk::ActionGroup> m_refActionGroup;
//Gtk::Menu* m_pMenuPopup;
+ private:
+ /* the real signal handler called to handle the signal */
+ void (*m_pCrashHandler)(const char *progname);
};
#endif /*CC_APPLET_H_*/
diff --git a/src/Applet/DBusClientProxy.h b/src/Applet/DBusClientProxy.h
new file mode 100644
index 0000000..f0b8a00
--- /dev/null
+++ b/src/Applet/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/src/Applet/Makefile.am b/src/Applet/Makefile.am
index 36410ee..e9cfbd7 100644
--- a/src/Applet/Makefile.am
+++ b/src/Applet/Makefile.am
@@ -1,8 +1,8 @@
bin_PROGRAMS = applet
-applet_SOURCES = Applet.cpp CCApplet.cpp CCApplet.h
-applet_CPPFLAGS = -I../../lib/DBus \
+applet_SOURCES = Applet.cpp CCApplet.cpp CCApplet.h DBusClientProxy.h
+applet_CPPFLAGS = -I../Daemon/ \
-DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \
$(DBUS_GLIB_CFLAGS) $(GTK_CFLAGS) $(DBUSCPP_CFLAGS) \
-I../../lib/MiddleWare -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include
-applet_LDADD = ../../lib/DBus/libDBus.la $(DL_LIBS) $(GTK_LIBS) -lglib-2.0 -lgthread-2.0
+applet_LDADD = $(DL_LIBS) $(GTK_LIBS) -lglib-2.0 -lgthread-2.0 $(DBUSCPP_LIBS)