summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiri Moskovcak <jmoskovc@redhat.com>2009-07-28 15:20:23 +0200
committerJiri Moskovcak <jmoskovc@redhat.com>2009-07-28 15:20:23 +0200
commit4e7ebc3c2bc770f0aac4f857954755fe8a3d074a (patch)
tree7ba405f41aef7777a60019be583b5c13d587b9ca
parent8a163407875f2c73258e7f968b8f1e2d7f50a72c (diff)
downloadabrt-4e7ebc3c2bc770f0aac4f857954755fe8a3d074a.tar.gz
abrt-4e7ebc3c2bc770f0aac4f857954755fe8a3d074a.tar.xz
abrt-4e7ebc3c2bc770f0aac4f857954755fe8a3d074a.zip
CommLayer: Added DaemonWatcher to watch if daemon is running
-rw-r--r--lib/CommLayer/DBusClientProxy.h88
1 files changed, 88 insertions, 0 deletions
diff --git a/lib/CommLayer/DBusClientProxy.h b/lib/CommLayer/DBusClientProxy.h
index 8895a11c..4065307b 100644
--- a/lib/CommLayer/DBusClientProxy.h
+++ b/lib/CommLayer/DBusClientProxy.h
@@ -20,6 +20,94 @@
#include <dbus-c++/dbus.h>
#include <dbus-c++/glib-integration.h>
#include "DBusCommon.h"
+#include <iostream>
+#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()
+ : ::DBus::InterfaceProxy("org.freedesktop.DBus")
+ {
+ m_pStateChangeHandler_cb_data = NULL;
+ m_pStateChangeHandler = NULL;
+ connect_signal(DaemonWatcher_proxy, NameOwnerChanged , _DaemonStateChanged);
+ }
+
+ void 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 _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;
+ }
+ }
+ }
+ }
+};
+
+} } }
+
+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)
+ : ::DBus::ObjectProxy(connection, path, name)
+ {
+ }
+ ~DaemonWatcher()
+ {
+ std::cout << "~DaemonWatcher" << std::endl;
+ }
+};
+
class CDBusClient_proxy
: public DBus::InterfaceProxy