summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorZdenek Prikryl <zprikryl@redhat.com>2009-02-12 16:31:10 +0100
committerZdenek Prikryl <zprikryl@redhat.com>2009-02-12 16:31:10 +0100
commit418f70ffb976bbae37e5772f92a7bb983f303d1c (patch)
treed78a875e0d2bc7c4011d6d4ed0cc5cbe2b5d9961 /lib
parent3541999cd3338818cd86583383dbca87606d49fa (diff)
parent164c692385ddf3b17fbc9417b748f198ff19b096 (diff)
downloadabrt-418f70ffb976bbae37e5772f92a7bb983f303d1c.tar.gz
abrt-418f70ffb976bbae37e5772f92a7bb983f303d1c.tar.xz
abrt-418f70ffb976bbae37e5772f92a7bb983f303d1c.zip
Merge branch 'master' of git://git.fedorahosted.org/crash-catcher
Diffstat (limited to 'lib')
-rw-r--r--lib/DBus/DBusClient.cpp51
-rw-r--r--lib/DBus/DBusClient.h38
-rw-r--r--lib/DBus/DBusClientProxy.h85
-rw-r--r--lib/DBus/DBusCommon.h28
-rw-r--r--lib/DBus/DBusManager.cpp179
-rw-r--r--lib/DBus/DBusManager.h26
-rw-r--r--lib/DBus/DBusServer.cpp47
-rw-r--r--lib/DBus/DBusServer.h34
-rw-r--r--lib/DBus/DBusServerProxy.h114
-rw-r--r--lib/DBus/DbusClient.h15
-rw-r--r--lib/DBus/Makefile.am23
-rw-r--r--lib/DBus/test.cpp28
-rw-r--r--lib/DBus/test_client.cpp61
-rw-r--r--lib/DBus/test_server.cpp45
14 files changed, 584 insertions, 190 deletions
diff --git a/lib/DBus/DBusClient.cpp b/lib/DBus/DBusClient.cpp
new file mode 100644
index 00000000..cb9c3a0e
--- /dev/null
+++ b/lib/DBus/DBusClient.cpp
@@ -0,0 +1,51 @@
+/*
+ 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 "DBusClient.h"
+#include <iostream>
+
+CDBusClient::CDBusClient(DBus::Connection &connection, const char *path, const char *name)
+: DBus::ObjectProxy(connection, path, name)
+{
+ m_pCrashHandler = NULL;
+ std::cerr << "Client created" << std::endl;
+}
+
+CDBusClient::~CDBusClient()
+{
+ //clean
+}
+
+void CDBusClient::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 CDBusClient::ConnectCrashHandler(void (*pCrashHandler)(const char *progname))
+{
+ m_pCrashHandler = pCrashHandler;
+}
diff --git a/lib/DBus/DBusClient.h b/lib/DBus/DBusClient.h
new file mode 100644
index 00000000..5460141c
--- /dev/null
+++ b/lib/DBus/DBusClient.h
@@ -0,0 +1,38 @@
+/*
+ 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 "DBusClientProxy.h"
+
+class CDBusClient
+: public CDBusClient_proxy,
+ public DBus::IntrospectableProxy,
+ public DBus::ObjectProxy
+{
+private:
+ /* the real signal handler called to handle the signal */
+ void (*m_pCrashHandler)(const char *progname);
+public:
+
+ CDBusClient(DBus::Connection &connection, const char *path, const char *name);
+ ~CDBusClient();
+ void ConnectCrashHandler(void (*pCrashHandler)(const char *progname));
+ void Crash(std::string &value);
+};
+
diff --git a/lib/DBus/DBusClientProxy.h b/lib/DBus/DBusClientProxy.h
new file mode 100644
index 00000000..f0b8a001
--- /dev/null
+++ b/lib/DBus/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/DBus/DBusCommon.h b/lib/DBus/DBusCommon.h
new file mode 100644
index 00000000..8b36d82d
--- /dev/null
+++ b/lib/DBus/DBusCommon.h
@@ -0,0 +1,28 @@
+/*
+ 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.
+ */
+
+/* we need this to know the data structures */
+#include "MiddleWare.h"
+
+#define CC_DBUS_NAME "com.redhat.CrashCatcher"
+#define CC_DBUS_PATH "/com/redhat/CrashCatcher"
+#define CC_DBUS_IFACE "com.redhat.CrashCatcher"
+
+//typedef std::vector<crash_info_t> vector_crash_infos_t;
+typedef std::vector< std::vector<std::string> > dbus_vector_crash_infos_t;
diff --git a/lib/DBus/DBusManager.cpp b/lib/DBus/DBusManager.cpp
index 0b2cb97f..456c1786 100644
--- a/lib/DBus/DBusManager.cpp
+++ b/lib/DBus/DBusManager.cpp
@@ -19,185 +19,48 @@
#include "DBusManager.h"
#include <iostream>
-#include <marshal.h>
-
-// only for testing - used by LoopSend()
-static gboolean send_message(DBusGConnection *con)
-{
- DBusMessage *message;
- /* Create a new signal "Crash" on the "com.redhat.CrashCatcher" interface,
- * from the object "/com/redhat/CrashCatcher". */
- message = dbus_message_new_signal("/com/redhat/CrashCatcher/Crash",
- "com.redhat.CrashCatcher", "Crash");
- if(!message){
- fprintf(stderr,"Message creating error");
- }
- char *progname = "Foo";
- /* Append some info to the signal */
- dbus_message_append_args(message,DBUS_TYPE_STRING, &progname, DBUS_TYPE_INVALID);
- /* get the DBusConnection */
- DBusConnection *dbus_con = dbus_g_connection_get_connection(con);
- /* Send the signal via low level dbus function coz glib doesn't seem to work */
- if(!dbus_connection_send(dbus_con, message, NULL)){
- printf("Error while sending message\n");
- }
- printf("flushing bus %p\n", dbus_con);
- dbus_connection_flush(dbus_con);
- /* Free the signal */
- dbus_message_unref(message);
- /* Tell the user we send a signal */
- g_print("Message sent!\n");
- /* Return TRUE to tell the event loop we want to be called again */
- return TRUE;
-}
-
+#include "marshal.h"
CDBusManager::CDBusManager()
{
- GError *error = NULL;
- g_type_init();
- /* first we need to connect to dbus */
- m_nBus = dbus_g_bus_get(DBUS_BUS, &error);
- if(!m_nBus)
- throw std::string("Couldn't connect to dbus") + error->message;
+ DBus::default_dispatcher = new DBus::Glib::BusDispatcher();
+ m_pConn = new DBus::Connection(DBus::Connection::SessionBus());
+
}
CDBusManager::~CDBusManager()
{
+ //delete DBus::default_dispatcher
+ // delete m_pConn
}
/* register name com.redhat.CrashCatcher on dbus */
void CDBusManager::RegisterService()
{
- GError *error = NULL;
- guint request_name_result;
- g_type_init();
- // then we need a proxy to talk to dbus
- m_nBus_proxy = dbus_g_proxy_new_for_name(m_nBus, DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS,
- DBUS_INTERFACE_DBUS);
- if(!m_nBus_proxy){
- std::cerr << "Error while creating dbus proxy!" << error->message << std::endl;
- }
- /* and register our name */
- if (!dbus_g_proxy_call(m_nBus_proxy, "RequestName", &error,
- G_TYPE_STRING, CC_DBUS_NAME,
- G_TYPE_UINT, 0,
- G_TYPE_INVALID,
- G_TYPE_UINT, &request_name_result,
- G_TYPE_INVALID))
+ /* this can lead to race condition - rewrite with better check */
+ if(m_pConn->has_name(CC_DBUS_NAME))
{
- throw std::string("Failed to acquire com.redhat.CrashCatcher:") + error->message ;
+ /* shouldn't happen, but ... */
+ throw std::string("Name already taken: ") + CC_DBUS_NAME;
}
+ /* register our name */
+ m_pConn->request_name(CC_DBUS_NAME,DBUS_NAME_FLAG_DO_NOT_QUEUE);
#ifdef DEBUG
std::cout << "Service running" << std::endl;
#endif
}
-void CDBusManager::ConnectToDaemon()
-{
- GError *error = NULL;
- guint request_name_result;
- g_type_init();
- /* create a proxy object to talk and listen to CC daemon */
- m_nCCBus_proxy = dbus_g_proxy_new_for_name_owner(m_nBus, CC_DBUS_NAME,
- CC_DBUS_PATH_NOTIFIER,
- CC_DBUS_IFACE, &error);
- if(!m_nCCBus_proxy){
-#ifdef DEBUG
- std::cerr << "Couldn't connect to daemon via dbus: " << error->message << std::endl;
-#endif
- throw std::string(error->message);
- }
-#ifdef DEBUG
- std::cout << "Connected! Waiting for signals\n" << std::endl;
-#endif
-}
-
-void CDBusManager::RegisterToMessage(const std::string& pMessage, GCallback handler, void * data, GClosureNotify free_data_func)
-{
-#ifdef DEBUG
- std::cout << "Trying to register" << std::endl;
-#endif /*DEBUG*/
- /* Register dbus signal marshaller */
- dbus_g_object_register_marshaller(marshal_VOID__STRING,
- G_TYPE_NONE, G_TYPE_STRING,
- G_TYPE_INVALID);
- dbus_g_proxy_add_signal(m_nCCBus_proxy,"Crash",G_TYPE_STRING, G_TYPE_INVALID);
- dbus_g_proxy_connect_signal(m_nCCBus_proxy,"Crash",handler,NULL, NULL);
-#ifdef DEBUG
- std::cout << "Register done" << std::endl;
-#endif /*DEBUG*/
-}
-
-bool CDBusManager::GSendMessage(const std::string& pMessage, const std::string& pMessParam)
-{
- DBusMessage *message;
- /* Create a new signal "Crash" on the "com.redhat.CrashCatcher" interface,
- * from the object "/com/redhat/CrashCatcher/Crash". */
- message = dbus_message_new_signal ("/com/redhat/CrashCatcher/Crash",
- "com.redhat.CrashCatcher", pMessage.c_str());
- if(!message){
- std::cerr << "Message creating error" << std::endl;
- }
-#ifdef DEBUG
- std::cerr << message << std::endl;
-#endif
- const char *progname = pMessParam.c_str();
- /* Append some info to the signal */
- dbus_message_append_args(message,DBUS_TYPE_STRING, &progname, DBUS_TYPE_INVALID);
- /* Send the signal */
- dbus_g_proxy_send(m_nCCBus_proxy, message, NULL);
- /* Free the signal */
- dbus_message_unref(message);
-#ifdef DEBUG
- g_print("Message sent!\n");
-#endif
- /* Return TRUE to tell the event loop we want to be called again */
- return TRUE;
-}
-
bool CDBusManager::SendMessage(const std::string& pMessage, const std::string& pMessParam)
{
- DBusMessage *message;
const char *progname = pMessParam.c_str();
- /* Create a new signal "Crash" on the "com.redhat.CrashCatcher" interface,
- * from the object "/com/redhat/CrashCatcher/Crash". */
- message = dbus_message_new_signal ("/com/redhat/CrashCatcher/Crash",
- "com.redhat.CrashCatcher", pMessage.c_str());
- if(!message){
- std::cerr << "Message creating error" << std::endl;
- }
-#ifdef DEBUG
- std::cerr << message << std::endl;
-#endif
- /* Add program name as the message argument */
- dbus_message_append_args(message,DBUS_TYPE_STRING, &progname, DBUS_TYPE_INVALID);
- /* Send the signal */
- DBusConnection *dbus_con = dbus_g_connection_get_connection(m_nBus);
- /* Send the signal via low level dbus functio coz glib sucks */
- if(!dbus_connection_send(dbus_con, message, NULL)){
- throw "Error while sending message";
- }
- /* flush the connection, otherwise, it won't show on dbus? */
- dbus_connection_flush(dbus_con);
- /* Free the signal */
- dbus_message_unref(message);
-#ifdef DEBUG
- g_print("Message sent!\n");
-#endif
- /* Return TRUE to tell the event loop we want to be called again */
+ DBus::SignalMessage mess(CC_DBUS_PATH, CC_DBUS_NAME, pMessage.c_str());
+ /* append some info to the signal */
+ mess.append(DBUS_TYPE_STRING,&progname,DBUS_TYPE_INVALID);
+ /* send the message */
+ m_pConn->send(mess);
+ /* flush - to make sure it's not stuck in queue */
+ // probably not needed
+ //m_pConn->flush();
+ std::cerr << "Message sent!" << std::endl;
return TRUE;
}
-
-
-// just for testing purposes
-void CDBusManager::LoopSend()
-{
- g_timeout_add(1000, (GSourceFunc)send_message, m_nBus);
-}
-
-void CDBusManager::Unregister()
-{
- std::cerr << "Unregister" << std::endl;
-}
diff --git a/lib/DBus/DBusManager.h b/lib/DBus/DBusManager.h
index f29d5d47..34181698 100644
--- a/lib/DBus/DBusManager.h
+++ b/lib/DBus/DBusManager.h
@@ -20,11 +20,11 @@
#ifndef DBUS_H_
#define DBUS_H_
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-lowlevel.h>
-#include <dbus/dbus.h>
-#include <glib.h>
#include <string>
+#include <dbus/dbus.h>
+//#include <glibmm.h>
+#include <dbus-c++/glib-integration.h>
+#include <dbus-c++/dbus.h>
#define CC_DBUS_NAME "com.redhat.CrashCatcher"
#define CC_DBUS_PATH "/com/redhat/CrashCatcher"
@@ -32,25 +32,19 @@
#define DBUS_BUS DBUS_BUS_SYSTEM
#define CC_DBUS_PATH_NOTIFIER "/com/redhat/CrashCatcher/Crash"
+
+
class CDBusManager
{
private:
- DBusGConnection *m_nBus;
- DBusGProxy *m_nBus_proxy;
- DBusGProxy *m_nCCBus_proxy;
-
+ DBus::Glib::BusDispatcher *m_pDispatcher;
+ DBus::Connection *m_pConn;
public:
CDBusManager();
~CDBusManager();
- bool SendMessage(const std::string& pMessage, const std::string& pMessParam);
- bool GSendMessage(const std::string& pMessage, const std::string& pMessParam);
void RegisterService();
- void ConnectToService();
- void ConnectToDaemon();
- void LoopSend();
- void Unregister();
- void RegisterToMessage(const std::string& pMessage, GCallback handler, void * data, GClosureNotify free_data_func);
- /** TODO
+ bool SendMessage(const std::string& pMessage, const std::string& pMessParam);
+ /** TODO
//tries to reconnect after daemon failure
void Reconnect();
*/
diff --git a/lib/DBus/DBusServer.cpp b/lib/DBus/DBusServer.cpp
new file mode 100644
index 00000000..2f92c966
--- /dev/null
+++ b/lib/DBus/DBusServer.cpp
@@ -0,0 +1,47 @@
+/*
+ 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 "DBusServer.h"
+
+CDBusServer::CDBusServer(DBus::Connection &connection, const std::string& pServerPath)
+: DBus::ObjectAdaptor(connection, pServerPath)
+{
+}
+
+dbus_vector_crash_infos_t CDBusServer::GetCrashInfos(const std::string &pUID)
+{
+ dbus_vector_crash_infos_t info;
+ //CMiddleWare mw;
+ //mw.GetCrashInfos();
+ std::vector<std::string> v;
+ v.push_back("vector1_prvek1");
+ v.push_back("vector1_prvek_1");
+ info.push_back(v);
+ v.clear();
+ v.push_back("vector2_prvek1");
+ v.push_back("vector2_prvek_1");
+ v.push_back(pUID);
+ info.push_back(v);
+ return info;
+}
+
+CDBusServer::~CDBusServer()
+{
+ //clean
+}
diff --git a/lib/DBus/DBusServer.h b/lib/DBus/DBusServer.h
new file mode 100644
index 00000000..17f93939
--- /dev/null
+++ b/lib/DBus/DBusServer.h
@@ -0,0 +1,34 @@
+/*
+ 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 "DBusServerProxy.h"
+
+class CDBusServer
+: public CDBusServer_adaptor,
+ public DBus::IntrospectableAdaptor,
+ public DBus::ObjectAdaptor
+{
+public:
+ CDBusServer(DBus::Connection& connection, const std::string& pServerPath);
+ ~CDBusServer();
+ int32_t Sum(const std::vector<int32_t> & ints);
+ dbus_vector_crash_infos_t GetCrashInfos(const std::string &pUID);
+};
+
diff --git a/lib/DBus/DBusServerProxy.h b/lib/DBus/DBusServerProxy.h
new file mode 100644
index 00000000..a32bbc3d
--- /dev/null
+++ b/lib/DBus/DBusServerProxy.h
@@ -0,0 +1,114 @@
+/*
+ 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 CDBusServer_adaptor
+: public DBus::InterfaceAdaptor
+{
+public:
+
+ CDBusServer_adaptor()
+ : DBus::InterfaceAdaptor(CC_DBUS_IFACE)
+ {
+ register_method(CDBusServer_adaptor, GetCrashInfos, _GetCrashInfos_stub);
+ }
+
+ DBus::IntrospectedInterface *const introspect() const
+ {
+ static DBus::IntrospectedArgument GetCrashInfos_args[] =
+ {
+ { "uid", "i", true},
+ { "info", "aas", false },
+ { 0, 0, 0 }
+ };
+ static DBus::IntrospectedArgument Crash_args[] =
+ {
+ { "value", "v", false },
+ { 0, 0, 0 }
+ };
+ static DBus::IntrospectedMethod CDBusServer_adaptor_methods[] =
+ {
+ { "GetDumps", GetCrashInfos_args },
+ { 0, 0 }
+ };
+ static DBus::IntrospectedMethod CDBusServer_adaptor_signals[] =
+ {
+ { "Echoed", Crash_args },
+ { 0, 0 }
+ };
+ static DBus::IntrospectedProperty CDBusServer_adaptor_properties[] =
+ {
+ { 0, 0, 0, 0 }
+ };
+ static DBus::IntrospectedInterface CDBusServer_adaptor_interface =
+ {
+ "com.redhat.CrashCatcher",
+ 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;
+
+public:
+
+ /* signal emitters for this interface
+ */
+ void Crash(const std::string& arg1)
+ {
+ ::DBus::SignalMessage sig("Crash");
+ ::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;
+ }
+};
+
diff --git a/lib/DBus/DbusClient.h b/lib/DBus/DbusClient.h
new file mode 100644
index 00000000..e278c50d
--- /dev/null
+++ b/lib/DBus/DbusClient.h
@@ -0,0 +1,15 @@
+#include <dbus-c++/dbus.h>
+#include "DBusClientProxy.h"
+
+class CDBusClient
+: public org::freedesktop::DBus::CDBusClient_proxy,
+ public DBus::IntrospectableProxy,
+ public DBus::ObjectProxy
+{
+public:
+
+ CDBusClient(DBus::Connection &connection, const char *path, const char *name);
+ ~CDBusClient();
+ void Crash(const DBus::Variant &value);
+};
+
diff --git a/lib/DBus/Makefile.am b/lib/DBus/Makefile.am
index 0d4d9f6e..1f709e77 100644
--- a/lib/DBus/Makefile.am
+++ b/lib/DBus/Makefile.am
@@ -1,11 +1,20 @@
lib_LTLIBRARIES = libDBus.la
-libDBus_la_SOURCES = DBusManager.cpp DBusManager.h marshal.c marshal.h
+libDBus_la_SOURCES = DBusManager.cpp DBusManager.h DBusClient.h DBusClient.cpp \
+ DBusClientProxy.h DBusServer.cpp DBusServer.h DBusServerProxy.h
libDBus_la_LDFLAGS = -version-info 0:1:0
-libDBus_la_LIBADD = $(DBUS_GLIB_LIBS)
-libDBus_la_CPPFLAGS = $(DBUS_GLIB_CFLAGS)
+libDBus_la_LIBADD = $(DBUS_GLIB_LIBS) $(GLIBMM_LIBS) $(DBUSCPP_LIBS)
+libDBus_la_CPPFLAGS = $(DBUS_GLIB_CFLAGS) $(GLIBMM_CFLAGS) $(DBUSCPP_CFLAGS) \
+ -I../../lib/MiddleWare
+#BUILT_SOURCES = crashcatcher-glue.h
-check_PROGRAMS = test
-test_SOURCES = test.cpp
-test_LDADD = libDBus.la $(DL_LIBS)
-test_CPPFLAGS = $(DBUS_GLIB_CFLAGS)
+#crashcatcher-glue.h: crashcatcher.xml
+# $(LIBTOOL) --mode=execute dbus-binding-tool --prefix=Crash --mode=glib-server --output=crashcatcher-glue.h $(srcdir)/crashcatcher.xml
+
+check_PROGRAMS = test_server test_client
+test_server_SOURCES = test_server.cpp
+test_server_LDADD = libDBus.la $(DL_LIBS)
+test_server_CPPFLAGS = $(DBUS_GLIB_CFLAGS) $(DBUSCPP_CFLAGS) -g -I../../lib/MiddleWare
+test_client_SOURCES = test_client.cpp
+test_client_LDADD = libDBus.la $(DL_LIBS)
+test_client_CPPFLAGS = $(DBUS_GLIB_CFLAGS) $(DBUSCPP_CFLAGS) -g -I../../lib/MiddleWare
diff --git a/lib/DBus/test.cpp b/lib/DBus/test.cpp
index 8f1d66cf..ad414b6a 100644
--- a/lib/DBus/test.cpp
+++ b/lib/DBus/test.cpp
@@ -22,19 +22,28 @@
#include <iostream>
#include <climits>
#include <stdlib.h>
-
-static void
-print_cb(DBusGProxy *proxy, char* progname, gpointer user_data)
-{
- DBusError error;
- dbus_error_init (&error);
- std::cerr << "Application " << progname << " has crashed!" << std::endl;
-}
+#include <unistd.h>
int main(int argc, char** argv){
GMainLoop *mainloop;
mainloop = g_main_loop_new(NULL, FALSE);
-
+ CDBusManager dm;
+ try
+ {
+ dm.RegisterService();
+ }
+ catch(std::string err)
+ {
+ std::cerr << err << std::endl;
+ return -1;
+ }
+ while(1)
+ {
+ dm.SendMessage("Crash","Svete");
+ sleep(1);
+ }
+ g_main_loop_run(mainloop);
+ /*
//no sanity check, it's just a testing program!
if (argc < 2){
std::cout << "Usage: " << argv[0] << " {s|c}" << std::endl;
@@ -72,5 +81,6 @@ int main(int argc, char** argv){
dm.RegisterToMessage("Crash",G_CALLBACK(print_cb),NULL,NULL);
g_main_loop_run(mainloop);
}
+ */
return 0;
}
diff --git a/lib/DBus/test_client.cpp b/lib/DBus/test_client.cpp
new file mode 100644
index 00000000..ccdae45c
--- /dev/null
+++ b/lib/DBus/test_client.cpp
@@ -0,0 +1,61 @@
+/*
+ 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 "DBusClient.h"
+#include <iostream>
+#include <signal.h>
+
+DBus::BusDispatcher dispatcher;
+
+void niam(int sig)
+{
+ dispatcher.leave();
+}
+
+int main()
+{
+ signal(SIGTERM, niam);
+ signal(SIGINT, niam);
+
+ DBus::default_dispatcher = &dispatcher;
+
+ DBus::Connection conn = DBus::Connection::SessionBus();
+
+ CDBusClient client(conn, CC_DBUS_PATH, CC_DBUS_NAME);
+ /*
+ typedef std::vector< std::vector<std::string> > type_t;
+ type_t vec = client.GetCrashInfos("client");
+ for (type_t::iterator it = vec.begin(); it!=vec.end(); ++it) {
+ for (std::vector<std::string>::iterator itt = it->begin(); itt!=it->end(); ++itt) {
+ std::cout << *itt << std::endl;
+ }
+ }
+ */
+ dbus_vector_crash_infos_t v = client.GetCrashInfos("client");
+ for (dbus_vector_crash_infos_t::iterator it = v.begin(); it!=v.end(); ++it) {
+ for (dbus_vector_crash_infos_t::value_type::iterator itt = it->begin(); itt!=it->end(); ++itt) {
+ std::cout << *itt << std::endl;
+ }
+ }
+ dispatcher.enter();
+
+ std::cout << "terminating" << std::endl;
+
+ return 0;
+}
diff --git a/lib/DBus/test_server.cpp b/lib/DBus/test_server.cpp
new file mode 100644
index 00000000..ba4d47a2
--- /dev/null
+++ b/lib/DBus/test_server.cpp
@@ -0,0 +1,45 @@
+/*
+ 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 "DBusServer.h"
+#include <iostream>
+#include <signal.h>
+
+DBus::BusDispatcher dispatcher;
+
+void niam(int sig)
+{
+ dispatcher.leave();
+}
+
+int main()
+{
+ signal(SIGTERM, niam);
+ signal(SIGINT, niam);
+
+ DBus::default_dispatcher = &dispatcher;
+
+ DBus::Connection conn = DBus::Connection::SessionBus();
+
+ CDBusServer server(conn, CC_DBUS_PATH);
+ conn.request_name(CC_DBUS_NAME);
+ dispatcher.enter();
+
+ return 0;
+}