summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Kühl <chrisk@openismus.com>2011-10-01 07:24:57 +0200
committerChris Kühl <chrisk@openismus.com>2011-11-16 11:06:45 +0100
commitb7c7577b7041407c30153273e2086b1aee4230c3 (patch)
treebdc61d040f8c272d3d2d15e30f499b33c859ac91
parentf53ae35a365067627e53f6dbf6e0ceb8250373bd (diff)
dbus: Introduce dbus wrapper around GIO GDBus d-bus implementationfor-master-v1/gio-gdbus
Background: Prior to this patch a C++ wrapper around Bluez gdbus, a convienience wrapper around the low-level libdbus, was used by syncevo-dbus-server. This patch introduces a second C++ wrapper around the GIO GDBus implementation. The reason for introducing this second wrapper is to move away from using the in-tree copy of Bluez gdbus and towards a more well-maintained d-bus implementation. Also, libdbus was not designed to be thread-safe whereas GIO GDBus was. The GIO GDBus wrapper retains the same public api as the first one. This means the consumers of this wrapper (syncevo-dbus-server, for example) have remained almost completely untouched. The only exceptions are in the few case where libdbus objects where used directly by the consuming class. The choice of which wrapper is determined at configure time. The option can be explicitly set using the --with-gio-gdbus and --without-gio-gdbus flags or, if no flag is given, an adequate version of GIO is search for. If found, the GIO GDBus wrapper is chosen.
-rw-r--r--configure.ac4
-rw-r--r--src/dbus/server/bluez-manager.cpp7
-rw-r--r--src/dbus/server/bluez-manager.h6
-rw-r--r--src/dbus/server/connman-client.cpp2
-rw-r--r--src/dbus/server/connman-client.h2
-rw-r--r--src/dbus/server/exceptions.cpp10
-rw-r--r--src/dbus/server/exceptions.h15
-rw-r--r--src/dbus/server/main.cpp10
-rw-r--r--src/dbus/server/network-manager-client.cpp2
-rw-r--r--src/dbus/server/network-manager-client.h4
-rw-r--r--src/dbus/server/server.am2
-rw-r--r--src/gdbus/gdbus-cxx-bridge.cpp23
-rw-r--r--src/gdbus/gdbus-cxx-bridge.h27
-rw-r--r--src/gdbus/test/example.cpp8
-rw-r--r--src/gdbusxx/gdbus-cxx-bridge.cpp68
-rw-r--r--src/gdbusxx/gdbus-cxx-bridge.h3242
-rw-r--r--src/gdbusxx/gdbusxx.am9
-rw-r--r--src/gdbusxx/test/example.cpp19
-rw-r--r--src/syncevolution.cpp6
-rwxr-xr-xtest/test-dbus.py13
20 files changed, 1822 insertions, 1657 deletions
diff --git a/configure.ac b/configure.ac
index f80d895c..1e9668a1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -448,7 +448,9 @@ AC_ARG_WITH(gio-gdbus,
[with_gio_gdbus="yes"],
[with_gio_gdbus="no"]))
AM_CONDITIONAL([COND_GIO_GDBUS], [test "x$with_gio_gdbus" = "xyes"])
-AS_IF([test "x$with_gio_gdbus" = "xyes"], [need_glib=yes])
+AS_IF([test "x$with_gio_gdbus" = "xyes"], [need_glib=yes
+ PKG_CHECK_MODULES([GIO_GDBUS], [gio-2.0 >= 2.26])
+ AC_DEFINE([WITH_GIO_GDBUS],[],[Set if using GIO GDBus])])
PKG_CHECK_MODULES(KEYRING, [gnome-keyring-1], HAVE_KEYRING=yes, HAVE_KEYRING=no)
AC_ARG_ENABLE(gnome-keyring,
diff --git a/src/dbus/server/bluez-manager.cpp b/src/dbus/server/bluez-manager.cpp
index 13854d4b..4ffb5ea0 100644
--- a/src/dbus/server/bluez-manager.cpp
+++ b/src/dbus/server/bluez-manager.cpp
@@ -36,11 +36,12 @@ BluezManager::BluezManager(Server &server) :
m_server(server),
m_adapterChanged(*this, "DefaultAdapterChanged")
{
+ m_lookupTable.bt_key_file = NULL;
+ m_lookupTable.isLoaded = false;
const char *bluetoothTest = getenv ("DBUS_TEST_BLUETOOTH");
m_bluezConn = (bluetoothTest && !strcmp(bluetoothTest, "none")) ? NULL :
- b_dbus_setup_bus((bluetoothTest && !strcmp(bluetoothTest, "session")) ?
- DBUS_BUS_SESSION : DBUS_BUS_SYSTEM,
- NULL, true, NULL);
+ dbus_get_bus_connection((bluetoothTest && !strcmp(bluetoothTest, "session")) ?
+ "SESSION" : "SYSTEM", NULL, true, NULL);
if(m_bluezConn) {
m_done = false;
DBusClientCall1<DBusObject_t> getAdapter(*this, "DefaultAdapter");
diff --git a/src/dbus/server/bluez-manager.h b/src/dbus/server/bluez-manager.h
index cdde2e67..34f5d76f 100644
--- a/src/dbus/server/bluez-manager.h
+++ b/src/dbus/server/bluez-manager.h
@@ -56,7 +56,7 @@ public:
virtual const char *getDestination() const {return "org.bluez";}
virtual const char *getPath() const {return "/";}
virtual const char *getInterface() const {return "org.bluez.Manager";}
- virtual DBusConnection *getConnection() const {return m_bluezConn.get();}
+ virtual DBUS_CONNECTION_TYPE *getConnection() const {return m_bluezConn.get();}
bool isDone() { return m_done; }
private:
@@ -75,7 +75,7 @@ private:
virtual const char *getDestination() const {return "org.bluez";}
virtual const char *getPath() const {return m_path.c_str();}
virtual const char *getInterface() const {return "org.bluez.Adapter";}
- virtual DBusConnection *getConnection() const {return m_manager.getConnection();}
+ virtual DBUS_CONNECTION_TYPE *getConnection() const {return m_manager.getConnection();}
void checkDone(bool forceDone = false)
{
if(forceDone || m_devReplies >= m_devNo) {
@@ -133,7 +133,7 @@ private:
virtual const char *getDestination() const {return "org.bluez";}
virtual const char *getPath() const {return m_path.c_str();}
virtual const char *getInterface() const {return "org.bluez.Device";}
- virtual DBusConnection *getConnection() const {return m_adapter.m_manager.getConnection();}
+ virtual DBUS_CONNECTION_TYPE *getConnection() const {return m_adapter.m_manager.getConnection();}
std::string getMac() { return m_mac; }
/**
diff --git a/src/dbus/server/connman-client.cpp b/src/dbus/server/connman-client.cpp
index 38d22984..f153c94d 100644
--- a/src/dbus/server/connman-client.cpp
+++ b/src/dbus/server/connman-client.cpp
@@ -27,7 +27,7 @@ ConnmanClient::ConnmanClient(Server &server):
m_propertyChanged(*this, "PropertyChanged")
{
const char *connmanTest = getenv ("DBUS_TEST_CONNMAN");
- m_connmanConn = b_dbus_setup_bus (connmanTest ? DBUS_BUS_SESSION: DBUS_BUS_SYSTEM, NULL, true, NULL);
+ m_connmanConn = GDBusCXX::dbus_get_bus_connection(connmanTest ? "SESSION": "SYSTEM", NULL, true, NULL);
if (m_connmanConn){
typedef std::map <std::string, boost::variant <std::vector <std::string> > > PropDict;
GDBusCXX::DBusClientCall1<PropDict> getProp(*this,"GetProperties");
diff --git a/src/dbus/server/connman-client.h b/src/dbus/server/connman-client.h
index 8b8205d0..7d9f4230 100644
--- a/src/dbus/server/connman-client.h
+++ b/src/dbus/server/connman-client.h
@@ -41,7 +41,7 @@ public:
virtual const char *getDestination() const {return "net.connman";}
virtual const char *getPath() const {return "/";}
virtual const char *getInterface() const {return "net.connman.Manager";}
- virtual DBusConnection *getConnection() const {return m_connmanConn.get();}
+ virtual DBUS_CONNECTION_TYPE *getConnection() const {return m_connmanConn.get();}
void propertyChanged(const std::string &name,
const boost::variant<std::vector<std::string>, std::string> &prop);
diff --git a/src/dbus/server/exceptions.cpp b/src/dbus/server/exceptions.cpp
index ceb082c1..90bd3d32 100644
--- a/src/dbus/server/exceptions.cpp
+++ b/src/dbus/server/exceptions.cpp
@@ -25,20 +25,20 @@ SE_BEGIN_CXX
* implement syncevolution exception handler
* to cover its default implementation
*/
-DBusMessage* SyncEvoHandleException(DBusMessage *msg)
+DBUS_MESSAGE_TYPE* SyncEvoHandleException(DBUS_MESSAGE_TYPE *msg)
{
/** give an opportunity to let syncevolution handle exception */
Exception::handle();
try {
throw;
} catch (const GDBusCXX::dbus_error &ex) {
- return b_dbus_create_error(msg, ex.dbusName().c_str(), "%s", ex.what());
+ return DBUS_NEW_ERROR_MSG(msg, ex.dbusName().c_str(), "%s", ex.what());
} catch (const GDBusCXX::DBusCXXException &ex) {
- return b_dbus_create_error(msg, ex.getName().c_str(), "%s", ex.getMessage());
+ return DBUS_NEW_ERROR_MSG(msg, ex.getName().c_str(), "%s", ex.getMessage());
} catch (const std::runtime_error &ex) {
- return b_dbus_create_error(msg, "org.syncevolution.Exception", "%s", ex.what());
+ return DBUS_NEW_ERROR_MSG(msg, "org.syncevolution.Exception", "%s", ex.what());
} catch (...) {
- return b_dbus_create_error(msg, "org.syncevolution.Exception", "unknown");
+ return DBUS_NEW_ERROR_MSG(msg, "org.syncevolution.Exception", "unknown");
}
}
diff --git a/src/dbus/server/exceptions.h b/src/dbus/server/exceptions.h
index 756fb97b..7156575a 100644
--- a/src/dbus/server/exceptions.h
+++ b/src/dbus/server/exceptions.h
@@ -21,10 +21,23 @@
#define SYNCEVO_EXCEPTIONS_H
#include <syncevo/util.h>
+#include "config.h"
+// Can't use the DBUS_MESSAGE_TYPE define here because it's not
+// defined till we include gdbus-cxx-bridge.h below.
+#ifdef WITH_GIO_GDBUS
+// Forward decleration can't be used here due to later typedef _GDBusMessage GDBusMessage.
+#include <gio/gio.h>
+#else
struct DBusMessage;
+#endif
+
SE_BEGIN_CXX
-DBusMessage *SyncEvoHandleException(DBusMessage *msg);
+#ifdef WITH_GIO_GDBUS
+GDBusMessage *SyncEvoHandleException(GDBusMessage *msg);
+#else
+DBusMessage *SyncEvoHandleException(DBusMessage *msg);
+#endif
SE_END_CXX
// This needs to be defined before including gdbus-cxx-bridge.h!
#define DBUS_CXX_EXCEPTION_HANDLER SyncEvo::SyncEvoHandleException
diff --git a/src/dbus/server/main.cpp b/src/dbus/server/main.cpp
index 480863e5..8a5de48f 100644
--- a/src/dbus/server/main.cpp
+++ b/src/dbus/server/main.cpp
@@ -102,12 +102,12 @@ int main(int argc, char **argv, char **envp)
LoggerBase::INFO);
DBusErrorCXX err;
- DBusConnectionPtr conn = b_dbus_setup_bus(DBUS_BUS_SESSION,
- "org.syncevolution",
- true,
- &err);
+ DBusConnectionPtr conn = dbus_get_bus_connection("SESSION",
+ "org.syncevolution",
+ false,
+ &err);
if (!conn) {
- err.throwFailure("b_dbus_setup_bus()", " failed - server already running?");
+ err.throwFailure("dbus_get_bus_connection()", " failed - server already running?");
}
SyncEvo::Server server(loop, shutdownRequested, restart, conn, duration);
diff --git a/src/dbus/server/network-manager-client.cpp b/src/dbus/server/network-manager-client.cpp
index 9287024e..f9056d9b 100644
--- a/src/dbus/server/network-manager-client.cpp
+++ b/src/dbus/server/network-manager-client.cpp
@@ -28,7 +28,7 @@ NetworkManagerClient::NetworkManagerClient(Server &server) :
m_stateChanged(*this, "StateChanged"),
m_properties(*this)
{
- m_networkManagerConn = b_dbus_setup_bus(DBUS_BUS_SYSTEM, NULL, true, NULL);
+ m_networkManagerConn = GDBusCXX::dbus_get_bus_connection("SYSTEM", NULL, true, NULL);
if(m_networkManagerConn) {
m_properties.get();
m_stateChanged.activate(boost::bind(
diff --git a/src/dbus/server/network-manager-client.h b/src/dbus/server/network-manager-client.h
index 21a1f167..c37b930d 100644
--- a/src/dbus/server/network-manager-client.h
+++ b/src/dbus/server/network-manager-client.h
@@ -69,7 +69,7 @@ public:
virtual const char *getInterface() const {
return "org.freedesktop.NetworkManager";
}
- virtual DBusConnection *getConnection() const {
+ virtual DBUS_CONNECTION_TYPE *getConnection() const {
return m_networkManagerConn.get();
}
@@ -94,7 +94,7 @@ private:
virtual const char *getInterface() const {
return "org.freedesktop.DBus.Properties";
}
- virtual DBusConnection* getConnection() const {
+ virtual DBUS_CONNECTION_TYPE* getConnection() const {
return m_manager.getConnection();
}
void get();
diff --git a/src/dbus/server/server.am b/src/dbus/server/server.am
index 2070085e..02a31ee2 100644
--- a/src/dbus/server/server.am
+++ b/src/dbus/server/server.am
@@ -53,7 +53,7 @@ gdbus_dir = $(top_srcdir)/src/gdbus
endif
src_dbus_server_libsyncevodbusserver_la_LIBADD = $(KEYRING_LIBS) $(LIBNOTIFY_LIBS) $(MLITE_LIBS) $(KDE_KWALLET_LIBS) $(DBUS_LIBS) $(LIBSOUP_LIBS)
-src_dbus_server_libsyncevodbusserver_la_CPPFLAGS = -DHAVE_CONFIG_H -DSYNCEVOLUTION_LOCALEDIR=\"${SYNCEVOLUTION_LOCALEDIR}\" -I$(top_srcdir)/src -I$(top_srcdir)/test -I$(top_srcdir) -I$(gdbus_dir) $(BACKEND_CPPFLAGS)
+src_dbus_server_libsyncevodbusserver_la_CPPFLAGS = -DHAVE_CONFIG_H -DSYNCEVOLUTION_LOCALEDIR=\"${SYNCEVOLUTION_LOCALEDIR}\" -I$(top_srcdir)/src -I$(top_srcdir)/test -I$(top_srcdir) -I$(gdbus_dir) $(BACKEND_CPPFLAGS)
src_dbus_server_libsyncevodbusserver_la_CXXFLAGS = $(SYNCEVOLUTION_CXXFLAGS) $(CORE_CXXFLAGS) $(SYNTHESIS_CFLAGS) $(GLIB_CFLAGS) $(DBUS_CFLAGS) $(LIBSOUP_CFLAGS) $(KEYRING_CFLAGS) $(LIBNOTIFY_CFLAGS) $(MLITE_CFLAGS) $(KDE_KWALLET_CFLAGS) $(SYNCEVO_WFLAGS)
# Deal with .service, .desktop and startup script files.
diff --git a/src/gdbus/gdbus-cxx-bridge.cpp b/src/gdbus/gdbus-cxx-bridge.cpp
index 8f39d7bc..2689b780 100644
--- a/src/gdbus/gdbus-cxx-bridge.cpp
+++ b/src/gdbus/gdbus-cxx-bridge.cpp
@@ -18,4 +18,27 @@
*/
#include "gdbus-cxx-bridge.h"
+#include <boost/algorithm/string/predicate.hpp>
+namespace boost
+{
+ void intrusive_ptr_add_ref(DBusConnection *con) { dbus_connection_ref(con); }
+ void intrusive_ptr_release(DBusConnection *con) { dbus_connection_unref(con); }
+ void intrusive_ptr_add_ref(DBusMessage *msg) { dbus_message_ref(msg); }
+ void intrusive_ptr_release(DBusMessage *msg) { dbus_message_unref(msg); }
+ void intrusive_ptr_add_ref(DBusPendingCall *call) { dbus_pending_call_ref (call); }
+ void intrusive_ptr_release(DBusPendingCall *call) { dbus_pending_call_unref (call); }
+}
+
+namespace GDBusCXX {
+
+DBusConnection *dbus_get_bus_connection(const char *busType,
+ const char *interface,
+ bool unshared,
+ DBusErrorCXX *err)
+{
+ return b_dbus_setup_bus(boost::iequals(busType, "SYSTEM") ? DBUS_BUS_SYSTEM : DBUS_BUS_SESSION,
+ interface, unshared, err);;
+}
+
+}
diff --git a/src/gdbus/gdbus-cxx-bridge.h b/src/gdbus/gdbus-cxx-bridge.h
index 84cf00b8..87c51192 100644
--- a/src/gdbus/gdbus-cxx-bridge.h
+++ b/src/gdbus/gdbus-cxx-bridge.h
@@ -63,12 +63,14 @@
#include <map>
#include <vector>
-static inline void intrusive_ptr_add_ref(DBusConnection *con) { dbus_connection_ref(con); }
-static inline void intrusive_ptr_release(DBusConnection *con) { dbus_connection_unref(con); }
-static inline void intrusive_ptr_add_ref(DBusMessage *msg) { dbus_message_ref(msg); }
-static inline void intrusive_ptr_release(DBusMessage *msg) { dbus_message_unref(msg); }
-static inline void intrusive_ptr_add_ref(DBusPendingCall *call) { dbus_pending_call_ref (call); }
-static inline void intrusive_ptr_release(DBusPendingCall *call) { dbus_pending_call_unref (call); }
+namespace boost {
+ void intrusive_ptr_add_ref(DBusConnection *con);
+ void intrusive_ptr_release(DBusConnection *con);
+ void intrusive_ptr_add_ref(DBusMessage *msg);
+ void intrusive_ptr_release(DBusMessage *msg);
+ void intrusive_ptr_add_ref(DBusPendingCall *call);
+ void intrusive_ptr_release(DBusPendingCall *call);
+}
#include <boost/bind.hpp>
#include <boost/intrusive_ptr.hpp>
@@ -76,6 +78,14 @@ static inline void intrusive_ptr_release(DBusPendingCall *call) { dbus_pending_c
#include <boost/variant.hpp>
#include <boost/variant/get.hpp>
+/* The connection is the only client-exposed type from the C API. To
+ * keep changes to a minimum while supporting both dbus
+ * implementations, this is made to be a define. The intention is to
+ * remove the define once the in-tree gdbus is dropped. */
+#define DBUS_CONNECTION_TYPE DBusConnection
+#define DBUS_MESSAGE_TYPE DBusMessage
+#define DBUS_NEW_ERROR_MSG b_dbus_create_error
+
namespace GDBusCXX {
class DBusConnectionPtr : public boost::intrusive_ptr<DBusConnection>
@@ -153,6 +163,11 @@ class DBusErrorCXX : public DBusError
}
};
+DBusConnection *dbus_get_bus_connection(const char *busType,
+ const char *interface,
+ bool unshared,
+ DBusErrorCXX *err);
+
/**
* Special type for object paths. A string in practice.
*/
diff --git a/src/gdbus/test/example.cpp b/src/gdbus/test/example.cpp
index 8d11cb27..366b429e 100644
--- a/src/gdbus/test/example.cpp
+++ b/src/gdbus/test/example.cpp
@@ -245,7 +245,7 @@ using namespace GDBusCXX;
int main(int argc, char *argv[])
{
DBusConnection *conn;
- DBusError err;
+ DBusErrorCXX err;
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
@@ -259,9 +259,7 @@ int main(int argc, char *argv[])
main_loop = g_main_loop_new(NULL, FALSE);
- dbus_error_init(&err);
-
- conn = b_dbus_setup_bus(DBUS_BUS_SESSION, "org.example", false, &err);
+ conn = dbus_get_bus_connection("SESSION", "org.example", false, &err);
if (conn == NULL) {
if (dbus_error_is_set(&err) == TRUE) {
fprintf(stderr, "%s\n", err.message);
@@ -282,8 +280,6 @@ int main(int argc, char *argv[])
test.reset();
- b_dbus_cleanup_connection(conn);
-
g_main_loop_unref(main_loop);
return 0;
diff --git a/src/gdbusxx/gdbus-cxx-bridge.cpp b/src/gdbusxx/gdbus-cxx-bridge.cpp
index 866d18ab..f7558683 100644
--- a/src/gdbusxx/gdbus-cxx-bridge.cpp
+++ b/src/gdbusxx/gdbus-cxx-bridge.cpp
@@ -21,10 +21,66 @@
namespace boost
{
- void intrusive_ptr_add_ref(GDBusConnection *con) { g_object_ref(con); }
- void intrusive_ptr_release(GDBusConnection *con) { g_object_unref(con); }
- void intrusive_ptr_add_ref(GDBusMessage *msg) { g_object_ref(msg); }
- void intrusive_ptr_release(GDBusMessage *msg) { g_object_unref(msg); }
- void intrusive_ptr_add_ref(GDBusPendingCall *call) { g_object_ref(call); }
- void intrusive_ptr_release(GDBusPendingCall *call) { g_object_unref(call); }
+ void intrusive_ptr_add_ref(GDBusConnection *con) { g_object_ref(con); }
+ void intrusive_ptr_release(GDBusConnection *con) { g_object_unref(con); }
+ void intrusive_ptr_add_ref(GDBusMessage *msg) { g_object_ref(msg); }
+ void intrusive_ptr_release(GDBusMessage *msg) { g_object_unref(msg); }
+}
+
+namespace GDBusCXX {
+
+MethodHandler::MethodMap MethodHandler::m_methodMap;
+boost::function<void (void)> MethodHandler::m_callback;
+
+GDBusConnection *dbus_get_bus_connection(const char *busType,
+ const char *name,
+ bool unshared,
+ DBusErrorCXX *err /* Ignored */)
+{
+ GDBusConnection *conn;
+ GError* error = NULL;
+
+ if(unshared) {
+ char *address = g_dbus_address_get_for_bus_sync(boost::iequals(busType, "SESSION") ?
+ G_BUS_TYPE_SESSION : G_BUS_TYPE_SYSTEM,
+ NULL, &error);
+ if(address == NULL) {
+ err->set(error);
+ return NULL;
+ }
+ // Here we set up a private client connection using the chosen bus' address.
+ conn = g_dbus_connection_new_for_address_sync(address,
+ (GDBusConnectionFlags)
+ (G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT |
+ G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION),
+ NULL, NULL, &error);
+ g_free(address);
+
+ if(error != NULL) {
+ err->set(error);
+ return NULL;
+ }
+ } else {
+ // This returns a singleton, shared connection object.
+ conn = g_bus_get_sync(boost::iequals(busType, "SESSION") ? G_BUS_TYPE_SESSION : G_BUS_TYPE_SYSTEM,
+ NULL, &error);
+ if(error != NULL) {
+ err->set(error);
+ return NULL;
+ }
+ g_bus_own_name_on_connection(conn, name, G_BUS_NAME_OWNER_FLAGS_NONE,
+ NULL, NULL, NULL, NULL);
+ }
+
+ if(!conn) {
+ return NULL;
+ }
+
+ if(name) {
+ g_dbus_connection_set_exit_on_close(conn, TRUE);
+ }
+
+ return conn;
+}
+
}
diff --git a/src/gdbusxx/gdbus-cxx-bridge.h b/src/gdbusxx/gdbus-cxx-bridge.h
index 65144e1b..5d0b3ac7 100644
--- a/src/gdbusxx/gdbus-cxx-bridge.h
+++ b/src/gdbusxx/gdbus-cxx-bridge.h
@@ -56,27 +56,34 @@
#ifndef INCL_GDBUS_CXX_BRIDGE
#define INCL_GDBUS_CXX_BRIDGE
+#include "gdbus-cxx.h"
#include <gio/gio.h>
-#include "gdbus-cxx.h"
#include <map>
#include <vector>
-namespace boost {
- void intrusive_ptr_add_ref(GDBusConnection *con);
- void intrusive_ptr_release(GDBusConnection *con);
- void intrusive_ptr_add_ref(GDBusMessage *msg);
- void intrusive_ptr_release(GDBusMessage *msg);
- void intrusive_ptr_add_ref(GDBusPendingCall *call);
- void intrusive_ptr_release(GDBusPendingCall *call);
-}
-
#include <boost/bind.hpp>
#include <boost/intrusive_ptr.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/variant.hpp>
#include <boost/variant/get.hpp>
+#include <boost/algorithm/string/predicate.hpp>
+
+/* The connection and message are the only client-exposed types from
+ * the C API. To keep changes to a minimum while supporting both dbus
+ * implementations, this is made to be a define. The intention is to
+ * remove the define once the in-tree gdbus is dropped. */
+#define DBUS_CONNECTION_TYPE GDBusConnection
+#define DBUS_MESSAGE_TYPE GDBusMessage
+#define DBUS_NEW_ERROR_MSG g_dbus_message_new_method_error
+
+namespace boost {
+ void intrusive_ptr_add_ref(GDBusConnection *con);
+ void intrusive_ptr_release(GDBusConnection *con);
+ void intrusive_ptr_add_ref(GDBusMessage *msg);
+ void intrusive_ptr_release(GDBusMessage *msg);
+}
namespace GDBusCXX {
@@ -85,76 +92,102 @@ class DBusConnectionPtr : public boost::intrusive_ptr<GDBusConnection>
public:
DBusConnectionPtr() {}
// connections are typically created once, so increment the ref counter by default
- DBusConnectionPtr(DBusConnection *conn, bool add_ref = true) :
- boost::intrusive_ptr<DBusConnection>(conn, add_ref)
- {}
+ DBusConnectionPtr(GDBusConnection *conn, bool add_ref = true) :
+ boost::intrusive_ptr<GDBusConnection>(conn, add_ref)
+ {}
- DBusConnection *reference(void) throw()
+ GDBusConnection *reference(void) throw()
{
- DBusConnection *conn = get();
- dbus_connection_ref(conn);
+ GDBusConnection *conn = get();
+ g_object_ref(conn);
return conn;
}
};
-class DBusMessagePtr : public boost::intrusive_ptr<GDBusMessage>
+class GDBusMessagePtr : public boost::intrusive_ptr<GDBusMessage>
{
public:
- DBusMessagePtr() {}
+ GDBusMessagePtr() {}
// expected to be used for messages created anew,
// so use the reference already incremented for us
// and don't increment by default
- DBusMessagePtr(DBusMessage *msg, bool add_ref = false) :
- boost::intrusive_ptr<DBusMessage>(msg, add_ref)
+ GDBusMessagePtr(GDBusMessage *msg, bool add_ref = false) :
+ boost::intrusive_ptr<GDBusMessage>(msg, add_ref)
{}
- DBusMessage *reference(void) throw()
+ GDBusMessage *reference(void) throw()
{
- DBusMessage *msg = get();
- dbus_message_ref(msg);
+ GDBusMessage *msg = get();
+ g_object_ref(msg);
return msg;
}
};
-class DBusPendingCallPtr : public boost::intrusive_ptr<DBusPendingCall>
-{
-public:
- DBusPendingCallPtr(DBusPendingCall *call, bool add_ref = false) :
- boost::intrusive_ptr<DBusPendingCall>(call, add_ref)
- {}
-
- DBusPendingCall *reference(void) throw()
- {
- DBusPendingCall *call = get();
- dbus_pending_call_ref(call);
- return call;
- }
-};
-
/**
- * wrapper around DBusError which initializes
+ * wrapper around GError which initializes
* the struct automatically, then can be used to
* throw an exception
*/
-class DBusErrorCXX : public DBusError
+class DBusErrorCXX
{
+ GError *m_error;
public:
- DBusErrorCXX() { dbus_error_init(this); }
- void throwFailure(const std::string &operation, const std::string &explanation = " failed")
+ char *message;
+ DBusErrorCXX(GError *error = NULL)
+ : m_error(error)
{
- if (dbus_error_is_set(this)) {
- throw std::runtime_error(operation + ": " + message);
- } else {
- throw std::runtime_error(operation + explanation);
+ if (m_error) {
+ message = m_error->message;
+ }
+ }
+ DBusErrorCXX(const DBusErrorCXX &dbus_error)
+ : m_error(NULL)
+ {
+ if (dbus_error.m_error) {
+ m_error = g_error_copy (dbus_error.m_error);
+ message = m_error->message;
+ }
+ }
+
+ DBusErrorCXX operator=(const DBusErrorCXX &dbus_error)
+ {
+ DBusErrorCXX temp_error(dbus_error);
+ GError* temp_c_error = temp_error.m_error;
+
+ temp_error.m_error = m_error;
+ m_error = temp_c_error;
+ message = m_error->message;
+ return *this;
+ }
+
+ void set(GError *error) {
+ if (m_error) {
+ g_error_free (m_error);
+ }
+ m_error = error;
+ if (m_error) {
+ message = m_error->message;
+ }
+ }
+
+ ~DBusErrorCXX() {
+ if (m_error) {
+ g_error_free (m_error);
}
}
- operator bool ()
+ void throwFailure(const std::string &operation, const std::string &explanation = " failed")
{
- return dbus_error_is_set(this);
+ std::string error_message(m_error ? (std::string(": ") + m_error->message) : "");
+ throw std::runtime_error(operation + explanation + error_message);
}
};
+GDBusConnection *dbus_get_bus_connection(const char *busType,
+ const char *interface,
+ bool unshared,
+ DBusErrorCXX *err);
+
/**
* Special type for object paths. A string in practice.
*/
@@ -192,15 +225,22 @@ struct dbus_traits_base
* method calls.
*/
class AppendRetvals {
- DBusMessageIter m_iter;
+ GDBusMessage *m_msg;
+ GVariantBuilder m_builder;
public:
- AppendRetvals(DBusMessagePtr &msg) {
- dbus_message_iter_init_append(msg.get(), &m_iter);
+ AppendRetvals(GDBusMessage *msg) {
+ m_msg = msg;
+ g_variant_builder_init(&m_builder, G_VARIANT_TYPE_TUPLE);
+ }
+
+ ~AppendRetvals()
+ {
+ g_dbus_message_set_body(m_msg, g_variant_builder_end(&m_builder));
}
template<class A> AppendRetvals & operator << (const A &a) {
- dbus_traits<A>::append(m_iter, a);
+ dbus_traits<A>::append(m_builder, a);
return *this;
}
};
@@ -210,10 +250,16 @@ class AppendRetvals {
* message, using AppendArgs(msg) << Set<A1>(res1) << Set<A2>(res2) << ...;
*/
struct AppendArgs {
- DBusMessageIter m_iter;
+ GDBusMessage *m_msg;
+ GVariantBuilder m_builder;
+
+ AppendArgs(GDBusMessage *msg) {
+ m_msg = msg;
+ g_variant_builder_init(&m_builder, G_VARIANT_TYPE_TUPLE);
+ }
- AppendArgs(DBusMessage *msg) {
- dbus_message_iter_init_append(msg, &m_iter);
+ ~AppendArgs() {
+ g_dbus_message_set_body(m_msg, g_variant_builder_end(&m_builder));
}
/** syntactic sugar: redirect << into Set instance */
@@ -227,7 +273,7 @@ struct AppendArgs {
* skipped.
*/
template<class A> AppendArgs & operator + (const A &a) {
- dbus_traits<A>::append(m_iter, a);
+ dbus_traits<A>::append(m_builder, a);
return *this;
}
};
@@ -256,7 +302,7 @@ template<class A> struct Set <A &>
A &m_a;
Set(A &a) : m_a(a) {}
AppendArgs &set(AppendArgs &context) const {
- dbus_traits<A>::append(context.m_iter, m_a);
+ dbus_traits<A>::append(context.m_builder, m_a);
return context;
}
};
@@ -270,15 +316,19 @@ template<class A> struct Set <A &>
* ultimately on the prototype of the method.
*/
struct ExtractArgs {
- DBusConnection *m_conn;
- DBusMessage *m_msg;
- DBusMessageIter m_iter;
+ GDBusConnection *m_conn;
+ GDBusMessage *m_msg;
+ GVariantIter m_iter;
public:
- ExtractArgs(DBusConnection *conn, DBusMessage *msg) {
+ ExtractArgs(GDBusConnection *conn, GDBusMessage *msg) {
m_conn = conn;
m_msg = msg;
- dbus_message_iter_init(msg, &m_iter);
+
+ GVariant * msgBody = g_dbus_message_get_body(m_msg);
+ if (msgBody != NULL) {
+ g_variant_iter_init(&m_iter, msgBody);
+ }
}
/** syntactic sugar: redirect >> into Get instance */
@@ -326,7 +376,7 @@ class DBusObject
public:
virtual ~DBusObject() {}
- virtual DBusConnection *getConnection() const = 0;
+ virtual GDBusConnection *getConnection() const = 0;
virtual const char *getPath() const = 0;
virtual const char *getInterface() const = 0;
};
@@ -345,29 +395,58 @@ class EmitSignal0
void operator () ()
{
- DBusMessagePtr msg(dbus_message_new_signal(m_object.getPath(),
- m_object.getInterface(),
- m_signal.c_str()));
+ GDBusMessagePtr msg(g_dbus_message_new_signal(m_object.getPath(),
+ m_object.getInterface(),
+ m_signal.c_str()));
if (!msg) {
- throw std::runtime_error("dbus_message_new_signal() failed");
+ throw std::runtime_error("g_dbus_message_new_signal() failed");
}
- if (!dbus_connection_send(m_object.getConnection(), msg.get(), NULL)) {
- throw std::runtime_error("dbus_connection_send failed");
+ if (!g_dbus_connection_send_message(m_object.getConnection(), msg.get(),
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL)) {
+ throw std::runtime_error("g_dbus_connection_send_message failed");
}
}
- BDBusSignalTable makeSignalEntry(BDBusSignalFlags flags = G_DBUS_SIGNAL_FLAG_NONE) const
+ GDBusSignalInfo *makeSignalEntry() const
{
- BDBusSignalTable entry;
- entry.name = m_signal.c_str();
- std::string buffer;
- entry.signature = strdup(buffer.c_str());
- entry.flags = flags;
+ GDBusSignalInfo *entry = g_new0(GDBusSignalInfo, 1);
+
+ entry->name = g_strdup(m_signal.c_str());
+
+ entry->ref_count = 1;
return entry;
}
};
+template <typename Arg>
+void appendNewArg(GPtrArray *pa)
+{
+ // Only append argument if there is a signature.
+ if (dbus_traits<Arg>::getSignature().empty()) {
+ return;
+ }
+
+ GDBusArgInfo *argInfo = g_new0(GDBusArgInfo, 1);
+ argInfo->signature = g_strdup(dbus_traits<Arg>::getSignature().c_str());
+ argInfo->ref_count = 1;
+ g_ptr_array_add(pa, argInfo);
+}
+
+template <typename Arg>
+void appendNewArgForReply(GPtrArray *pa)
+{
+ // Only append argument if there is a reply signature.
+ if (dbus_traits<Arg>::getReply().empty()) {
+ return;
+ }
+
+ GDBusArgInfo *argInfo = g_new0(GDBusArgInfo, 1);
+ argInfo->signature = g_strdup(dbus_traits<Arg>::getReply().c_str());
+ argInfo->ref_count = 1;
+ g_ptr_array_add(pa, argInfo);
+}
+
template <typename A1>
class EmitSignal1
{
@@ -383,27 +462,33 @@ class EmitSignal1
void operator () (A1 a1)
{
- DBusMessagePtr msg(dbus_message_new_signal(m_object.getPath(),
- m_object.getInterface(),
- m_signal.c_str()));
+ GDBusMessagePtr msg(g_dbus_message_new_signal(m_object.getPath(),
+ m_object.getInterface(),
+ m_signal.c_str()));
if (!msg) {
- throw std::runtime_error("dbus_message_new_signal() failed");
+ throw std::runtime_error("g_dbus_message_new_signal() failed");
}
- AppendRetvals(msg) << a1;
- if (!dbus_connection_send(m_object.getConnection(), msg.get(), NULL)) {
- throw std::runtime_error("dbus_connection_send failed");
+ AppendRetvals(msg.get()) << a1;
+
+ if (!g_dbus_connection_send_message(m_object.getConnection(), msg.get(),
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL)) {
+ throw std::runtime_error("g_dbus_connection_send_message failed");
}
}
- BDBusSignalTable makeSignalEntry(BDBusSignalFlags flags = G_DBUS_SIGNAL_FLAG_NONE) const
+ GDBusSignalInfo *makeSignalEntry() const
{
- BDBusSignalTable entry;
- entry.name = m_signal.c_str();
- std::string buffer;
- buffer += dbus_traits<A1>::getSignature();
- entry.signature = strdup(buffer.c_str());
- entry.flags = flags;
+ GDBusSignalInfo *entry = g_new0(GDBusSignalInfo, 1);
+
+ GPtrArray *args = g_ptr_array_new();
+ appendNewArg<A1>(args);
+ g_ptr_array_add(args, NULL);
+
+ entry->name = g_strdup(m_signal.c_str());
+ entry->args = (GDBusArgInfo **)g_ptr_array_free (args, FALSE);
+
+ entry->ref_count = 1;
return entry;
}
};
@@ -423,28 +508,33 @@ class EmitSignal2
void operator () (A1 a1, A2 a2)
{
- DBusMessagePtr msg(dbus_message_new_signal(m_object.getPath(),
- m_object.getInterface(),
- m_signal.c_str()));
+ GDBusMessagePtr msg(g_dbus_message_new_signal(m_object.getPath(),
+ m_object.getInterface(),
+ m_signal.c_str()));
if (!msg) {
- throw std::runtime_error("dbus_message_new_signal() failed");
+ throw std::runtime_error("g_dbus_message_new_signal() failed");
}
- AppendRetvals(msg) << a1 << a2;
+ AppendRetvals(msg.get()) << a1 << a2;
- if (!dbus_connection_send(m_object.getConnection(), msg.get(), NULL)) {
- throw std::runtime_error("dbus_connection_send failed");
+ if (!g_dbus_connection_send_message(m_object.getConnection(), msg.get(),
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL)) {
+ throw std::runtime_error("g_dbus_connection_send_message failed");
}
}
- BDBusSignalTable makeSignalEntry(BDBusSignalFlags flags = G_DBUS_SIGNAL_FLAG_NONE) const
+ GDBusSignalInfo *makeSignalEntry() const
{
- BDBusSignalTable entry;
- entry.name = m_signal.c_str();
- std::string buffer;
- buffer += dbus_traits<A1>::getSignature();
- buffer += dbus_traits<A2>::getSignature();
- entry.signature = strdup(buffer.c_str());
- entry.flags = flags;
+ GDBusSignalInfo *entry = g_new0(GDBusSignalInfo, 1);
+
+ GPtrArray *args = g_ptr_array_new();
+ appendNewArg<A1>(args);
+ appendNewArg<A2>(args);
+ g_ptr_array_add(args, NULL);
+
+ entry->name = g_strdup(m_signal.c_str());
+ entry->args = (GDBusArgInfo **)g_ptr_array_free (args, FALSE);
+
+ entry->ref_count = 1;
return entry;
}
};
@@ -464,28 +554,33 @@ class EmitSignal3
void operator () (A1 a1, A2 a2, A3 a3)
{
- DBusMessagePtr msg(dbus_message_new_signal(m_object.getPath(),
- m_object.getInterface(),
- m_signal.c_str()));
+ GDBusMessagePtr msg(g_dbus_message_new_signal(m_object.getPath(),
+ m_object.getInterface(),
+ m_signal.c_str()));
if (!msg) {
- throw std::runtime_error("dbus_message_new_signal() failed");
+ throw std::runtime_error("g_dbus_message_new_signal() failed");
}
- AppendRetvals(msg) << a1 << a2 << a3;
- if (!dbus_connection_send(m_object.getConnection(), msg.get(), NULL)) {
- throw std::runtime_error("dbus_connection_send failed");
+ AppendRetvals(msg.get()) << a1 << a2 << a3;
+ if (!g_dbus_connection_send_message(m_object.getConnection(), msg.get(),
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL)) {
+ throw std::runtime_error("g_dbus_connection_send_message failed");
}
}
- BDBusSignalTable makeSignalEntry(BDBusSignalFlags flags = G_DBUS_SIGNAL_FLAG_NONE) const
+ GDBusSignalInfo *makeSignalEntry() const
{
- BDBusSignalTable entry;
- entry.name = m_signal.c_str();
- std::string buffer;
- buffer += dbus_traits<A1>::getSignature();
- buffer += dbus_traits<A2>::getSignature();
- buffer += dbus_traits<A3>::getSignature();
- entry.signature = strdup(buffer.c_str());
- entry.flags = flags;
+ GDBusSignalInfo *entry = g_new0(GDBusSignalInfo, 1);
+
+ GPtrArray *args = g_ptr_array_new();
+ appendNewArg<A1>(args);
+ appendNewArg<A2>(args);
+ appendNewArg<A3>(args);
+ g_ptr_array_add(args, NULL);
+
+ entry->name = g_strdup(m_signal.c_str());
+ entry->args = (GDBusArgInfo **)g_ptr_array_free (args, FALSE);
+
+ entry->ref_count = 1;
return entry;
}
};
@@ -505,29 +600,34 @@ class EmitSignal4
void operator () (A1 a1, A2 a2, A3 a3, A4 a4)
{
- DBusMessagePtr msg(dbus_message_new_signal(m_object.getPath(),
- m_object.getInterface(),
- m_signal.c_str()));
+ GDBusMessagePtr msg(g_dbus_message_new_signal(m_object.getPath(),
+ m_object.getInterface(),
+ m_signal.c_str()));
if (!msg) {
- throw std::runtime_error("dbus_message_new_signal() failed");
+ throw std::runtime_error("g_dbus_message_new_signal() failed");
}
- AppendRetvals(msg) << a1 << a2 << a3 << a4;
- if (!dbus_connection_send(m_object.getConnection(), msg.get(), NULL)) {
- throw std::runtime_error("dbus_connection_send failed");
+ AppendRetvals(msg.get()) << a1 << a2 << a3 << a4;
+ if (!g_dbus_connection_send_message(m_object.getConnection(), msg.get(),
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL)) {
+ throw std::runtime_error("g_dbus_connection_send_message failed");
}
}
- BDBusSignalTable makeSignalEntry(BDBusSignalFlags flags = G_DBUS_SIGNAL_FLAG_NONE) const
+ GDBusSignalInfo *makeSignalEntry() const
{
- BDBusSignalTable entry;
- entry.name = m_signal.c_str();
- std::string buffer;
- buffer += dbus_traits<A1>::getSignature();
- buffer += dbus_traits<A2>::getSignature();
- buffer += dbus_traits<A3>::getSignature();
- buffer += dbus_traits<A4>::getSignature();
- entry.signature = strdup(buffer.c_str());
- entry.flags = flags;
+ GDBusSignalInfo *entry = g_new0(GDBusSignalInfo, 1);
+
+ GPtrArray *args = g_ptr_array_new();
+ appendNewArg<A1>(args);
+ appendNewArg<A2>(args);
+ appendNewArg<A3>(args);
+ appendNewArg<A4>(args);
+ g_ptr_array_add(args, NULL);
+
+ entry->name = g_strdup(m_signal.c_str());
+ entry->args = (GDBusArgInfo **)g_ptr_array_free (args, FALSE);
+
+ entry->ref_count = 1;
return entry;
}
};
@@ -547,30 +647,35 @@ class EmitSignal5
void operator () (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5)
{
- DBusMessagePtr msg(dbus_message_new_signal(m_object.getPath(),
- m_object.getInterface(),
- m_signal.c_str()));
+ GDBusMessagePtr msg(g_dbus_message_new_signal(m_object.getPath(),
+ m_object.getInterface(),
+ m_signal.c_str()));
if (!msg) {
- throw std::runtime_error("dbus_message_new_signal() failed");
+ throw std::runtime_error("g_dbus_message_new_signal() failed");
}
- AppendRetvals(msg) << a1 << a2 << a3 << a4 << a5;
- if (!dbus_connection_send(m_object.getConnection(), msg.get(), NULL)) {
- throw std::runtime_error("dbus_connection_send failed");
+ AppendRetvals(msg.get()) << a1 << a2 << a3 << a4 << a5;
+ if (!g_dbus_connection_send_message(m_object.getConnection(), msg.get(),
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL)) {
+ throw std::runtime_error("g_dbus_connection_send_message");
}
}
- BDBusSignalTable makeSignalEntry(BDBusSignalFlags flags = G_DBUS_SIGNAL_FLAG_NONE) const
+ GDBusSignalInfo *makeSignalEntry() const
{
- BDBusSignalTable entry;
- entry.name = m_signal.c_str();
- std::string buffer;
- buffer += dbus_traits<A1>::getSignature();
- buffer += dbus_traits<A2>::getSignature();
- buffer += dbus_traits<A3>::getSignature();
- buffer += dbus_traits<A4>::getSignature();
- buffer += dbus_traits<A5>::getSignature();
- entry.signature = strdup(buffer.c_str());
- entry.flags = flags;
+ GDBusSignalInfo *entry = g_new0(GDBusSignalInfo, 1);
+
+ GPtrArray *args = g_ptr_array_new();
+ appendNewArg<A1>(args);
+ appendNewArg<A2>(args);
+ appendNewArg<A3>(args);
+ appendNewArg<A4>(args);
+ appendNewArg<A5>(args);
+ g_ptr_array_add(args, NULL);
+
+ entry->name = g_strdup(m_signal.c_str());
+ entry->args = (GDBusArgInfo **)g_ptr_array_free (args, FALSE);
+
+ entry->ref_count = 1;
return entry;
}
};
@@ -590,131 +695,190 @@ class EmitSignal6
void operator () (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6)
{
- DBusMessagePtr msg(dbus_message_new_signal(m_object.getPath(),
- m_object.getInterface(),
- m_signal.c_str()));
+ GDBusMessagePtr msg(g_dbus_message_new_signal(m_object.getPath(),
+ m_object.getInterface(),
+ m_signal.c_str()));
if (!msg) {
- throw std::runtime_error("dbus_message_new_signal() failed");
+ throw std::runtime_error("g_dbus_message_new_signal() failed");
}
- AppendRetvals(msg) << a1 << a2 << a3 << a4 << a5 << a6;
- if (!dbus_connection_send(m_object.getConnection(), msg.get(), NULL)) {
- throw std::runtime_error("dbus_connection_send failed");
+ AppendRetvals(msg.get()) << a1 << a2 << a3 << a4 << a5 << a6;
+ if (!g_dbus_connection_send_message(m_object.getConnection(), msg.get(),
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL)) {
+ throw std::runtime_error("g_dbus_connection_send_message failed");
}
}
- BDBusSignalTable makeSignalEntry(BDBusSignalFlags flags = G_DBUS_SIGNAL_FLAG_NONE) const
+ GDBusSignalInfo *makeSignalEntry() const
{
- BDBusSignalTable entry;
- entry.name = m_signal.c_str();
- std::string buffer;
- buffer += dbus_traits<A1>::getSignature();
- buffer += dbus_traits<A2>::getSignature();
- buffer += dbus_traits<A3>::getSignature();
- buffer += dbus_traits<A4>::getSignature();
- buffer += dbus_traits<A5>::getSignature();
- buffer += dbus_traits<A6>::getSignature();
- entry.signature = strdup(buffer.c_str());
- entry.flags = flags;
+ GDBusSignalInfo *entry = g_new0(GDBusSignalInfo, 1);
+
+ GPtrArray *args = g_ptr_array_sized_new(7);
+ appendNewArg<A1>(args);
+ appendNewArg<A2>(args);
+ appendNewArg<A3>(args);
+ appendNewArg<A4>(args);
+ appendNewArg<A5>(args);
+ appendNewArg<A6>(args);
+ g_ptr_array_add(args, NULL);
+
+ entry->name = g_strdup(m_signal.c_str());
+ entry->args = (GDBusArgInfo **)g_ptr_array_free (args, FALSE);
+
+ entry->ref_count = 1;
return entry;
}
};
-template <class M>
-struct MakeMethodEntry
-{
- // There is no generic implementation of this method.
- // If you get an error about it missing, then write
- // a specialization for your type M (the method pointer).
- //
- // static BDBusMethodTable make(const char *name,
- // BDBusMethodFlags flags)
+struct FunctionWrapperBase {
+ void* m_func_ptr;
+ FunctionWrapperBase(void* func_ptr)
+ : m_func_ptr(func_ptr)
+ {}
+
+ virtual ~FunctionWrapperBase() {}
};
-/**
- * Storage for method/signal/property arrays.
- * Always contains at least one empty element
- * at the end or is NULL.
- */
-template <class T> class DBusVector {
- size_t m_entries;
- size_t m_size;
- T *m_elements;
-
- static void destroy(BDBusMethodTable &entry) {
- free(const_cast<char *>(entry.name));
- free(const_cast<char *>(entry.signature));
- free(const_cast<char *>(entry.reply));
- if (entry.destroy) {
- entry.destroy(&entry);
- }
- }
+template<typename M>
+struct FunctionWrapper : public FunctionWrapperBase {
+ FunctionWrapper(boost::function<M>* func_ptr)
+ : FunctionWrapperBase(reinterpret_cast<void*>(func_ptr))
+ {}
- static void destroy(BDBusSignalTable &entry) {
- free(const_cast<char *>(entry.signature));
- // if (entry.destroy) {
- // entry.destroy(&entry);
- // }
+ virtual ~FunctionWrapper() {
+ delete reinterpret_cast<boost::function<M>*>(m_func_ptr);
}
+};
- public:
- DBusVector() : m_entries(0), m_size(0), m_elements(NULL) {}
- ~DBusVector() {
- if (m_elements) {
- for (size_t i = 0; i < m_entries; i++) {
- destroy(m_elements[i]);
- }
- free(m_elements);
+struct MethodHandler
+{
+ typedef GDBusMessage *(*MethodFunction)(GDBusConnection *conn, GDBusMessage *msg, void *data);
+ typedef boost::shared_ptr<FunctionWrapperBase> FuncWrapper;
+ typedef std::pair<MethodFunction, FuncWrapper > CallbackPair;
+ typedef std::map<const std::string, CallbackPair > MethodMap;
+ static MethodMap m_methodMap;
+ static boost::function<void (void)> m_callback;
+
+ static std::string make_prefix(const char *object_path) {
+ return std::string(object_path) + "~";
+ }
+
+ static std::string make_method_key(const char *object_path,
+ const char *method_name) {
+ return make_prefix(object_path) + method_name;
+ }
+
+ static void handler(GDBusConnection *connection,
+ const gchar *sender,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *method_name,
+ GVariant *parameters,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
+ {
+ MethodMap::iterator it;
+ it = m_methodMap.find(make_method_key(object_path, method_name));
+ if (it == m_methodMap.end()) {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.SyncEvolution.NoMatchingMethodName",
+ "No methods registered with this name");
+ return;
}
- }
- T *get() { return m_elements; }
- void push_back(const T &element) {
- if (m_entries + 1 >= m_size) {
- size_t newSize = m_size ? m_size * 2 : 16;
- m_elements = static_cast<T *>(realloc(m_elements, newSize * sizeof(T)));
- if (!m_elements) {
- throw std::bad_alloc();
- }
- m_size = newSize;
+ // We are calling callback because we want to keep server alive as long
+ // as possible. This callback is in fact delaying server's autotermination.
+ if (!m_callback.empty()) {
+ m_callback();
+ }
+
+ MethodFunction methodFunc = it->second.first;
+ void *methodData = reinterpret_cast<void*>(it->second.second->m_func_ptr);
+ GDBusMessage *reply;
+ reply = (methodFunc)(g_dbus_method_invocation_get_connection(invocation),
+ g_dbus_method_invocation_get_message(invocation),
+ methodData);
+
+ GError *error = NULL;
+ g_dbus_connection_send_message(g_dbus_method_invocation_get_connection(invocation),
+ reply,
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE,
+ NULL,
+ &error);
+ g_object_unref(reply);
+ // TODO: throw an exception?
+ if (error != NULL) {
+ g_error_free (error);
}
- m_elements[m_entries] = element;
- m_entries++;
- memset(m_elements + m_entries, 0, sizeof(T));
}
};
+template <class M>
+struct MakeMethodEntry
+{
+ // There is no generic implementation of this method.
+ // If you get an error about it missing, then write
+ // a specialization for your type M (the method pointer).
+ //
+ // static GDBusMethodEntry make(const char *name)
+};
+
/**
* utility class for registering an interface
*/
class DBusObjectHelper : public DBusObject
{
DBusConnectionPtr m_conn;
+ guint m_connId;
std::string m_path;
std::string m_interface;
- boost::function<void (void)> m_callback;
bool m_activated;
- DBusVector<BDBusMethodTable> m_methods;
- DBusVector<BDBusSignalTable> m_signals;
+ GPtrArray *m_methods;
+ GPtrArray *m_signals;
public:
- DBusObjectHelper(DBusConnection *conn,
+ DBusObjectHelper(GDBusConnection *conn,
const std::string &path,
const std::string &interface,
const boost::function<void (void)> &callback = boost::function<void (void)>()) :
m_conn(conn),
m_path(path),
m_interface(interface),
- m_callback(callback),
- m_activated(false)
+ m_activated(false),
+ m_methods(g_ptr_array_new()),
+ m_signals(g_ptr_array_new())
{
+ if (!MethodHandler::m_callback) {
+ MethodHandler::m_callback = callback;
+ }
}
~DBusObjectHelper()
{
deactivate();
+
+ MethodHandler::MethodMap::iterator iter(MethodHandler::m_methodMap.begin());
+ MethodHandler::MethodMap::iterator iter_end(MethodHandler::m_methodMap.end());
+ MethodHandler::MethodMap::iterator first_to_erase(iter_end);
+ MethodHandler::MethodMap::iterator last_to_erase(iter_end);
+ const std::string prefix(MethodHandler::make_prefix(m_path.c_str()));
+
+ while (iter != iter_end) {
+ const bool prefix_equal(!iter->first.compare(0, prefix.size(), prefix));
+
+ if (prefix_equal && (first_to_erase == iter_end)) {
+ first_to_erase = iter;
+ } else if (!prefix_equal && (first_to_erase != iter_end)) {
+ last_to_erase = iter;
+ break;
+ }
+ ++iter;
+ }
+ if (first_to_erase != iter_end) {
+ MethodHandler::m_methodMap.erase(first_to_erase, last_to_erase);
+ }
}
- virtual DBusConnection *getConnection() const { return m_conn.get(); }
+ virtual GDBusConnection *getConnection() const { return m_conn.get(); }
virtual const char *getPath() const { return m_path.c_str(); }
virtual const char *getInterface() const { return m_interface.c_str(); }
@@ -722,45 +886,118 @@ class DBusObjectHelper : public DBusObject
* binds a member to the this pointer of its instance
* and invokes it when the specified method is called
*/
- template <class A1, class C, class M> void add(A1 instance, M C::*method,
- const char *name, BDBusMethodFlags flags = G_DBUS_METHOD_FLAG_NONE) {
+ template <class A1, class C, class M> void add(A1 instance, M C::*method, const char *name)
+ {
+ if (!m_methods) {
+ throw std::logic_error("You can't add new methods after registration!");
+ }
+
typedef MakeMethodEntry< boost::function<M> > entry_type;
- m_methods.push_back(entry_type::make(name, flags, entry_type::boostptr(method, instance)));
- }
+ g_ptr_array_add(m_methods, entry_type::make(name));
+
+ boost::function<M> *func = new boost::function<M>(entry_type::boostptr(method, instance));
+ MethodHandler::FuncWrapper wrapper(new FunctionWrapper<M>(func));
+ MethodHandler::CallbackPair methodAndData = std::make_pair(entry_type::methodFunction, wrapper);
+ const std::string key(MethodHandler::make_method_key(m_path.c_str(), name));
+ MethodHandler::m_methodMap.insert(std::make_pair(key, methodAndData));
+ }
/**
* binds a plain function pointer with no additional arguments and
* invokes it when the specified method is called
*/
- template <class M> void add(M *function,
- const char *name, BDBusMethodFlags flags = G_DBUS_METHOD_FLAG_NONE) {
- m_methods.push_back(MakeMethodEntry< boost::function<M> >::make(name, flags, function));
+ template <class M> void add(M *function, const char *name)
+ {
+ if (!m_methods) {
+ throw std::logic_error("You can't add new functions after registration!");
+ }
+
+ typedef MakeMethodEntry< boost::function<M> > entry_type;
+ g_ptr_array_add(m_methods, entry_type::make(name));
+
+ boost::function<M> *func = new boost::function<M>(function);
+ MethodHandler::FuncWrapper wrapper(new FunctionWrapper<M>(func));
+ MethodHandler::CallbackPair methodAndData = std::make_pair(entry_type::methodFunction,
+ wrapper);
+ const std::string key(MethodHandler::make_method_key(m_path.c_str(), name));
+
+ MethodHandler::m_methodMap.insert(std::make_pair(key, methodAndData));
}
/**
* add an existing signal entry
*/
- template <class S> void add(const S &s) {
- m_signals.push_back(s.makeSignalEntry());
- }
+ template <class S> void add(const S &s)
+ {
+ if (!m_signals) {
+ throw std::logic_error("You can't add new signals after registration!");
+ }
- void activate(BDBusMethodTable *methods,
- BDBusSignalTable *signals,
- BDBusPropertyTable *properties,
- const boost::function<void (void)> &callback) {
- if (!b_dbus_register_interface_with_callback(getConnection(), getPath(), getInterface(),
- methods, signals, properties, this, NULL, interfaceCallback)) {
- throw std::runtime_error(std::string("b_dbus_register_interface() failed for ") + getPath() + " " + getInterface());
+ g_ptr_array_add(m_signals, s.makeSignalEntry());
+ }
+
+ void activate(GDBusMethodInfo **methods,
+ GDBusSignalInfo **signals,
+ GDBusPropertyInfo **properties,
+ const boost::function<void (void)> &callback)
+ {
+ GDBusInterfaceInfo *ifInfo = g_new0(GDBusInterfaceInfo, 1);
+ ifInfo->name = g_strdup(m_interface.c_str());
+ ifInfo->methods = methods;
+ ifInfo->signals = signals;
+ ifInfo->properties = properties;
+
+ GDBusInterfaceVTable ifVTable;
+ ifVTable.method_call = MethodHandler::handler;
+ ifVTable.get_property = NULL;
+ ifVTable.set_property = NULL;
+
+ if ((m_connId = g_dbus_connection_register_object(getConnection(),
+ getPath(),
+ ifInfo,
+ &ifVTable,
+ this,
+ NULL,
+ NULL)) == 0) {
+ throw std::runtime_error(std::string("g_dbus_connection_register_object() failed for ") +
+ getPath() + " " + getInterface());
}
- m_callback = callback;
m_activated = true;
}
void activate() {
- if (!b_dbus_register_interface_with_callback(getConnection(), getPath(), getInterface(),
- m_methods.get(), m_signals.get(), NULL, this, NULL, interfaceCallback)) {
- throw std::runtime_error(std::string("b_dbus_register_interface() failed for ") + getPath() + " " + getInterface());
+ // method and signal array must be NULL-terminated.
+ if (!m_methods || !m_signals) {
+ throw std::logic_error("This object was already activated.");
+ }
+ if (m_methods->pdata[m_methods->len - 1] != NULL) {
+ g_ptr_array_add(m_methods, NULL);
+ }
+ if (m_signals->pdata[m_signals->len - 1] != NULL) {
+ g_ptr_array_add(m_signals, NULL);
+ }
+ GDBusInterfaceInfo *ifInfo = g_new0(GDBusInterfaceInfo, 1);
+ ifInfo->name = g_strdup(m_interface.c_str());
+ ifInfo->methods = (GDBusMethodInfo **)g_ptr_array_free(m_methods, FALSE);
+ ifInfo->signals = (GDBusSignalInfo **)g_ptr_array_free(m_signals, FALSE);
+ m_signals = NULL;
+ m_methods = NULL;
+
+ GDBusInterfaceVTable ifVTable;
+ ifVTable.method_call = MethodHandler::handler;
+ ifVTable.get_property = NULL;
+ ifVTable.set_property = NULL;
+
+ if ((m_connId = g_dbus_connection_register_object(getConnection(),
+ getPath(),
+ ifInfo,
+ &ifVTable,
+ this,
+ NULL,
+ NULL)) == 0) {
+ throw std::runtime_error(std::string("g_dbus_connection_register_object() failed for ") +
+ getPath() + " " + getInterface());
}
m_activated = true;
}
@@ -768,61 +1005,65 @@ class DBusObjectHelper : public DBusObject
void deactivate()
{
if (m_activated) {
- if (!b_dbus_unregister_interface(getConnection(),
- getPath(),
- getInterface())) {
- throw std::runtime_error(std::string("b_dbus_unregister_interface() failed for ") + getPath() + " " + getInterface());
+ if (!g_dbus_connection_unregister_object(getConnection(), m_connId)) {
+ throw std::runtime_error(std::string("g_dbus_connection_unregister_object() failed for ") +
+ getPath() + " " + getInterface());
}
m_activated = false;
}
}
- static void interfaceCallback(void *userData) {
- DBusObjectHelper* helper = static_cast<DBusObjectHelper*>(userData);
- if(!helper->m_callback.empty()) {
- helper->m_callback();
- }
- }
};
/**
* to be used for plain parameters like int32_t:
* treat as arguments which have to be extracted
- * from the D-Bus message and can be skipped when
+ * from the GVariants and can be skipped when
* encoding the reply
*/
-template<class host, int dbus> struct basic_marshal : public dbus_traits_base
+
+struct VariantTypeBoolean { static const GVariantType* getVariantType() { return G_VARIANT_TYPE_BOOLEAN; } };
+struct VariantTypeByte { static const GVariantType* getVariantType() { return G_VARIANT_TYPE_BYTE; } };
+struct VariantTypeInt16 { static const GVariantType* getVariantType() { return G_VARIANT_TYPE_INT16; } };
+struct VariantTypeUInt16 { static const GVariantType* getVariantType() { return G_VARIANT_TYPE_UINT16; } };
+struct VariantTypeInt32 { static const GVariantType* getVariantType() { return G_VARIANT_TYPE_INT32; } };
+struct VariantTypeUInt32 { static const GVariantType* getVariantType() { return G_VARIANT_TYPE_UINT32; } };
+struct VariantTypeInt64 { static const GVariantType* getVariantType() { return G_VARIANT_TYPE_INT64; } };
+struct VariantTypeUInt64 { static const GVariantType* getVariantType() { return G_VARIANT_TYPE_UINT64; } };
+struct VariantTypeDouble { static const GVariantType* getVariantType() { return G_VARIANT_TYPE_DOUBLE; } };
+
+template<class host, class VariantTraits> struct basic_marshal : public dbus_traits_base
{
typedef host host_type;
typedef host arg_type;
- static const int dbus_type = dbus;
/**
- * copy value from D-Bus iterator into variable
+ * copy value from GVariant iterator into variable
*/
- static void get(DBusConnection *conn, DBusMessage *msg,
- DBusMessageIter &iter, host &value)
+ static void get(GDBusConnection *conn, GDBusMessage *msg,
+ GVariantIter &iter, host &value)
{
- if (dbus_message_iter_get_arg_type(&iter) != dbus) {
+ GVariant *var = g_variant_iter_next_value(&iter);
+ if (var == NULL || !g_variant_type_equal(g_variant_get_type(var), VariantTraits::getVariantType())) {
throw std::runtime_error("invalid argument");
}
- dbus_message_iter_get_basic(&iter, &value);
- dbus_message_iter_next(&iter);
+ g_variant_get(var, g_variant_get_type_string(var), &value);
+ g_variant_unref(var);
}
/**
* copy value into D-Bus iterator
*/
- static void append(DBusMessageIter &iter, arg_type value)
+ static void append(GVariantBuilder &builder, arg_type value)
{
- if (!dbus_message_iter_append_basic(&iter, dbus, &value)) {
- throw std::runtime_error("out of memory");
- }
+ const gchar *typeStr = g_variant_type_dup_string(VariantTraits::getVariantType());
+ g_variant_builder_add(&builder, typeStr, value);
+ g_free((gpointer)typeStr);
}
};
template<> struct dbus_traits<uint8_t> :
- public basic_marshal< uint8_t, DBUS_TYPE_BYTE >
+public basic_marshal< uint8_t, VariantTypeByte >
{
/**
* plain type, regardless of whether used as
@@ -848,71 +1089,48 @@ template<> struct dbus_traits<int8_t> : dbus_traits<uint8_t>
typedef int8_t host_type;
typedef int8_t arg_type;
- static void get(DBusConnection *conn, DBusMessage *msg,
- DBusMessageIter &iter, host_type &value)
+ static void get(GDBusConnection *conn, GDBusMessage *msg,
+ GVariantIter &iter, host_type &value)
{
dbus_traits<uint8_t>::get(conn, msg, iter, reinterpret_cast<uint8_t &>(value));
}
};
template<> struct dbus_traits<int16_t> :
- public basic_marshal< int16_t, DBUS_TYPE_INT16 >
+ public basic_marshal< int16_t, VariantTypeInt16 >
{
static std::string getType() { return "n"; }
static std::string getSignature() {return getType(); }
static std::string getReply() { return ""; }
};
template<> struct dbus_traits<uint16_t> :
- public basic_marshal< uint16_t, DBUS_TYPE_UINT16 >
+ public basic_marshal< uint16_t, VariantTypeUInt16 >
{
static std::string getType() { return "q"; }
static std::string getSignature() {return getType(); }
static std::string getReply() { return ""; }
};
template<> struct dbus_traits<int32_t> :
- public basic_marshal< int32_t, DBUS_TYPE_INT32 >
+ public basic_marshal< int32_t, VariantTypeInt32 >
{
static std::string getType() { return "i"; }
static std::string getSignature() {return getType(); }
static std::string getReply() { return ""; }
};
template<> struct dbus_traits<uint32_t> :
- public basic_marshal< uint32_t, DBUS_TYPE_UINT32 >
+ public basic_marshal< uint32_t, VariantTypeUInt32 >
{
static std::string getType() { return "u"; }
static std::string getSignature() {return getType(); }
static std::string getReply() { return ""; }
};
-template<> struct dbus_traits<bool> : public dbus_traits_base
+template<> struct dbus_traits<bool> :
+ public basic_marshal< bool, VariantTypeBoolean >
{
static std::string getType() { return "b"; }
static std::string getSignature() {return getType(); }
static std::string getReply() { return ""; }
- static const int dbus = DBUS_TYPE_BOOLEAN;
-
- static void get(DBusConnection *conn, DBusMessage *msg,
- DBusMessageIter &iter, bool &value)
- {
- if (dbus_message_iter_get_arg_type(&iter) != dbus) {
- throw std::runtime_error("invalid argument");
- }
- dbus_bool_t dbus_value;
- dbus_message_iter_get_basic(&iter, &dbus_value);
- dbus_message_iter_next(&iter);
- value = dbus_value;
- }
-
- static void append(DBusMessageIter &iter, bool value)
- {
- dbus_bool_t dbus_value = value;
- if (!dbus_message_iter_append_basic(&iter, dbus, &dbus_value)) {
- throw std::runtime_error("out of memory");
- }
- }
-
- typedef bool host_type;
- typedef bool arg_type;
};
template<> struct dbus_traits<std::string> : public dbus_traits_base
@@ -920,26 +1138,23 @@ template<> struct dbus_traits<std::string> : public dbus_traits_base
static std::string getType() { return "s"; }
static std::string getSignature() {return getType(); }
static std::string getReply() { return ""; }
- static const int dbus = DBUS_TYPE_STRING;
- static void get(DBusConnection *conn, DBusMessage *msg,
- DBusMessageIter &iter, std::string &value)
+ static void get(GDBusConnection *conn, GDBusMessage *msg,
+ GVariantIter &iter, std::string &value)
{
- if (dbus_message_iter_get_arg_type(&iter) != dbus) {
+ GVariant *var = g_variant_iter_next_value(&iter);
+ if (var == NULL || !g_variant_type_equal(g_variant_get_type(var), G_VARIANT_TYPE_STRING)) {
throw std::runtime_error("invalid argument");
}
- const char *str;
- dbus_message_iter_get_basic(&iter, &str);
- dbus_message_iter_next(&iter);
+ const char *str = g_variant_get_string(var, NULL);
value = str;
+
+ g_variant_unref(var);
}
- static void append(DBusMessageIter &iter, const std::string &value)
+ static void append(GVariantBuilder &builder, const std::string &value)
{
- const char *str = value.c_str();
- if (!dbus_message_iter_append_basic(&iter, dbus, &str)) {
- throw std::runtime_error("out of memory");
- }
+ g_variant_builder_add_value(&builder, g_variant_new_string(value.c_str()));
}
typedef std::string host_type;
@@ -951,26 +1166,25 @@ template <> struct dbus_traits<DBusObject_t> : public dbus_traits_base
static std::string getType() { return "o"; }
static std::string getSignature() {return getType(); }
static std::string getReply() { return ""; }
- static const int dbus = DBUS_TYPE_OBJECT_PATH;
- static void get(DBusConnection *conn, DBusMessage *msg,
- DBusMessageIter &iter, DBusObject_t &value)
+ static void get(GDBusConnection *conn, GDBusMessage *msg,
+ GVariantIter &iter, DBusObject_t &value)
{
- if (dbus_message_iter_get_arg_type(&iter) != dbus) {
+ GVariant *var = g_variant_iter_next_value(&iter);
+ if (var == NULL || !g_variant_type_equal(g_variant_get_type(var), G_VARIANT_TYPE_OBJECT_PATH)) {
throw std::runtime_error("invalid argument");
}
- const char *str;
- dbus_message_iter_get_basic(&iter, &str);
- dbus_message_iter_next(&iter);
- value = str;
+ const char *objPath = g_variant_get_string(var, NULL);
+ value = objPath;
+ g_variant_unref(var);
}
- static void append(DBusMessageIter &iter, const DBusObject_t &value)
+ static void append(GVariantBuilder &builder, const DBusObject_t &value)
{
- const char *str = value.c_str();
- if (!dbus_message_iter_append_basic(&iter, dbus, &str)) {
- throw std::runtime_error("out of memory");
+ if (!g_variant_is_object_path(value.c_str())) {
+ throw std::runtime_error("invalid argument");
}
+ g_variant_builder_add_value(&builder, g_variant_new_object_path(value.c_str()));
}
typedef DBusObject_t host_type;
@@ -987,10 +1201,10 @@ template <> struct dbus_traits<Caller_t> : public dbus_traits_base
static std::string getSignature() { return ""; }
static std::string getReply() { return ""; }
- static void get(DBusConnection *conn, DBusMessage *msg,
- DBusMessageIter &iter, Caller_t &value)
+ static void get(GDBusConnection *conn, GDBusMessage *msg,
+ GVariantIter &iter, Caller_t &value)
{
- const char *peer = dbus_message_get_sender(msg);
+ const char *peer = g_dbus_message_get_sender(msg);
if (!peer) {
throw std::runtime_error("D-Bus method call without sender?!");
}
@@ -1024,34 +1238,31 @@ template<class V> struct dbus_traits< std::pair<size_t, const V *> > : public db
typedef std::pair<size_t, const V *> host_type;
typedef const host_type &arg_type;
- static void get(DBusConnection *conn, DBusMessage *msg,
- DBusMessageIter &iter, host_type &array)
+ static void get(GDBusConnection *conn, GDBusMessage *msg,
+ GVariantIter &iter, host_type &array)
{
- if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY) {
- throw std::runtime_error("invalid argument");
- }
- DBusMessageIter sub;
- dbus_message_iter_recurse(&iter, &sub);
- int type = dbus_message_iter_get_arg_type(&sub);
- if (type != dbus_traits<V>::dbus_type) {
+ GVariant *var = g_variant_iter_next_value(&iter);
+ if (var == NULL || !g_variant_type_is_subtype_of(g_variant_get_type(var), G_VARIANT_TYPE_ARRAY)) {
throw std::runtime_error("invalid argument");
}
- int nelements;
- typename dbus_traits<V>::host_type *data;
- dbus_message_iter_get_fixed_array(&sub, &data, &nelements);
+ typedef typename dbus_traits<V>::host_type V_host_type;
+ gsize nelements;
+ V_host_type *data;
+ data = (V_host_type *) g_variant_get_fixed_array(var,
+ &nelements,
+ static_cast<gsize>(sizeof(V_host_type)));
array.first = nelements;
array.second = data;
- dbus_message_iter_next(&iter);
+ g_variant_unref(var);
}
- static void append(DBusMessageIter &iter, arg_type array)
+ static void append(GVariantBuilder &builder, arg_type array)
{
- DBusMessageIter sub;
- if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, getContainedType().c_str(), &sub) ||
- !dbus_message_iter_append_fixed_array(&sub, dbus_traits<V>::dbus_type, &array.second, array.first) ||
- !dbus_message_iter_close_container(&iter, &sub)) {
- throw std::runtime_error("out of memory");
+ g_variant_builder_open(&builder, G_VARIANT_TYPE(getType().c_str()));
+ for(uint i = 0; i < array.first; ++i) {
+ g_variant_builder_add(&builder, getContainedType().c_str(), array.second[i]);
}
+ g_variant_builder_close(&builder);
}
};
@@ -1077,54 +1288,44 @@ template<class K, class V> struct dbus_traits< std::map<K, V> > : public dbus_tr
typedef std::map<K, V> host_type;
typedef const std::map<K, V> &arg_type;
- static void get(DBusConnection *conn, DBusMessage *msg,
- DBusMessageIter &iter, host_type &dict)
+ static void get(GDBusConnection *conn, GDBusMessage *msg,
+ GVariantIter &iter, host_type &dict)
{
- if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY) {
+ GVariant *var = g_variant_iter_next_value(&iter);
+ if (var == NULL || !g_variant_type_is_subtype_of(g_variant_get_type(var), G_VARIANT_TYPE_ARRAY)) {
throw std::runtime_error("invalid argument");
}
- DBusMessageIter sub;
- dbus_message_iter_recurse(&iter, &sub);
- int type;
- while ((type = dbus_message_iter_get_arg_type(&sub)) != DBUS_TYPE_INVALID) {
- if (type != DBUS_TYPE_DICT_ENTRY) {
- throw std::runtime_error("invalid argument");
- }
- DBusMessageIter entry;
- dbus_message_iter_recurse(&sub, &entry);
+
+ GVariantIter contIter;
+ GVariant *child;
+ g_variant_iter_init(&contIter, var);
+ while((child = g_variant_iter_next_value(&contIter)) != NULL) {
K key;
V value;
- dbus_traits<K>::get(conn, msg, entry, key);
- dbus_traits<V>::get(conn, msg, entry, value);
+ GVariantIter childIter;
+ g_variant_iter_init(&childIter, child);
+ dbus_traits<K>::get(conn, msg, childIter, key);
+ dbus_traits<V>::get(conn, msg, childIter, value);
dict.insert(std::make_pair(key, value));
- dbus_message_iter_next(&sub);
+ g_variant_unref(child);
}
- dbus_message_iter_next(&iter);
+ g_variant_unref(var);
}
- static void append(DBusMessageIter &iter, arg_type dict)
+ static void append(GVariantBuilder &builder, arg_type dict)
{
- DBusMessageIter sub;
- if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, getContainedType().c_str(), &sub)) {
- throw std::runtime_error("out of memory");
- }
+ g_variant_builder_open(&builder, G_VARIANT_TYPE(getType().c_str()));
for(typename host_type::const_iterator it = dict.begin();
it != dict.end();
++it) {
- DBusMessageIter entry;
- if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_DICT_ENTRY, NULL, &entry)) {
- throw std::runtime_error("out of memory");
- }
- dbus_traits<K>::append(entry, it->first);
- dbus_traits<V>::append(entry, it->second);
- if (!dbus_message_iter_close_container(&sub, &entry)) {
- throw std::runtime_error("out of memory");
- }
- }
- if (!dbus_message_iter_close_container(&iter, &sub)) {
- throw std::runtime_error("out of memory");
+ g_variant_builder_open(&builder, G_VARIANT_TYPE(getContainedType().c_str()));
+ dbus_traits<K>::append(builder, it->first);
+ dbus_traits<V>::append(builder, it->second);
+ g_variant_builder_close(&builder);
}
+
+ g_variant_builder_close(&builder);
}
};
@@ -1148,37 +1349,36 @@ template<class V> struct dbus_traits< std::vector<V> > : public dbus_traits_base
typedef std::vector<V> host_type;
typedef const std::vector<V> &arg_type;
- static void get(DBusConnection *conn, DBusMessage *msg,
- DBusMessageIter &iter, host_type &array)
+ static void get(GDBusConnection *conn, GDBusMessage *msg,
+ GVariantIter &iter, host_type &array)
{
- if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY) {
+ GVariant *var = g_variant_iter_next_value(&iter);
+ if (var == NULL || !g_variant_type_is_subtype_of(g_variant_get_type(var), G_VARIANT_TYPE_ARRAY)) {
throw std::runtime_error("invalid argument");
}
- DBusMessageIter sub;
- dbus_message_iter_recurse(&iter, &sub);
- while (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) {
+
+ int nelements = g_variant_n_children(var);
+ GVariantIter childIter;
+ g_variant_iter_init(&childIter, var);
+ for(int i = 0; i < nelements; ++i) {
V value;
- dbus_traits<V>::get(conn, msg, sub, value);
+ dbus_traits<V>::get(conn, msg, childIter, value);
array.push_back(value);
}
- dbus_message_iter_next(&iter);
+ g_variant_unref(var);
}
- static void append(DBusMessageIter &iter, arg_type array)
+ static void append(GVariantBuilder &builder, arg_type array)
{
- DBusMessageIter sub;
- if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, getContainedType().c_str(), &sub)) {
- throw std::runtime_error("out of memory");
- }
+ g_variant_builder_open(&builder, G_VARIANT_TYPE(getType().c_str()));
for(typename host_type::const_iterator it = array.begin();
it != array.end();
++it) {
- dbus_traits<V>::append(sub, *it);
- }
- if (!dbus_message_iter_close_container(&iter, &sub)) {
- throw std::runtime_error("out of memory");
+ dbus_traits<V>::append(builder, *it);
}
+
+ g_variant_builder_close(&builder);
}
};
@@ -1193,24 +1393,32 @@ template <class V> struct dbus_traits <boost::variant <V> > : public dbus_traits
static std::string getType() { return "v"; }
static std::string getSignature() { return getType(); }
static std::string getReply() { return ""; }
- static const int dbus = DBUS_TYPE_VARIANT;
- static void get(DBusConnection *conn, DBusMessage *msg,
- DBusMessageIter &iter, boost::variant <V> &value)
+ static void get(GDBusConnection *conn, GDBusMessage *msg,
+ GVariantIter &iter, boost::variant <V> &value)
{
- if (dbus_message_iter_get_arg_type(&iter) != dbus) {
+ GVariant *var = g_variant_iter_next_value(&iter);
+ if (var == NULL || !g_variant_type_equal(g_variant_get_type(var), G_VARIANT_TYPE_VARIANT)) {
throw std::runtime_error("invalid argument");
- return;
}
- DBusMessageIter sub;
- dbus_message_iter_recurse(&iter, &sub);
- if (dbus_message_iter_get_signature(&sub) != dbus_traits<V>::getSignature()){
+
+ GVariant *varVar;
+ GVariantIter varIter;
+ g_variant_iter_init(&varIter, var);
+ varVar = g_variant_iter_next_value(&varIter);
+ if (!boost::iequals(g_variant_get_type_string(varVar), dbus_traits<V>::getSignature())) {
//ignore unrecognized sub type in variant
return;
}
+
V val;
- dbus_traits<V>::get (conn, msg, sub, val);
+ // Note: Reset the iterator so that the call to dbus_traits<V>::get() will get the right variant;
+ g_variant_iter_init(&varIter, var);
+ dbus_traits<V>::get(conn, msg, varIter, val);
value = val;
+
+ g_variant_unref(var);
+ g_variant_unref(varVar);
}
typedef boost::variant<V> host_type;
@@ -1228,30 +1436,39 @@ template <class V1, class V2> struct dbus_traits <boost::variant <V1, V2> > : pu
static std::string getType() { return "v"; }
static std::string getSignature() { return getType(); }
static std::string getReply() { return ""; }
- static const int dbus = DBUS_TYPE_VARIANT;
- static void get(DBusConnection *conn, DBusMessage *msg,
- DBusMessageIter &iter, boost::variant <V1, V2> &value)
+ static void get(GDBusConnection *conn, GDBusMessage *msg,
+ GVariantIter &iter, boost::variant <V1, V2> &value)
{
- if (dbus_message_iter_get_arg_type(&iter) != dbus) {
+ GVariant *var = g_variant_iter_next_value(&iter);
+ if (var == NULL || !g_variant_type_equal(g_variant_get_type(var), G_VARIANT_TYPE_VARIANT)) {
throw std::runtime_error("invalid argument");
- return;
}
- DBusMessageIter sub;
- dbus_message_iter_recurse(&iter, &sub);
- if (dbus_message_iter_get_signature(&sub) != dbus_traits<V1>::getSignature()
- && dbus_message_iter_get_signature(&sub) != dbus_traits<V2>::getSignature()){
- //ignore unrecognized sub type in variant
+
+ GVariant *varVar;
+ GVariantIter varIter;
+ g_variant_iter_init(&varIter, var);
+ varVar = g_variant_iter_next_value(&varIter);
+ if ((!boost::iequals(g_variant_get_type_string(varVar), dbus_traits<V2>::getSignature())) &&
+ (!boost::iequals(g_variant_get_type_string(varVar), dbus_traits<V1>::getSignature()))) {
+ // ignore unrecognized sub type in variant
return;
- } else if (dbus_message_iter_get_signature(&sub) == dbus_traits<V1>::getSignature()) {
+ }
+ else if (boost::iequals(g_variant_get_type_string(varVar), dbus_traits<V1>::getSignature())) {
V1 val;
- dbus_traits<V1>::get (conn, msg, sub, val);
+ // Note: Reset the iterator so that the call to dbus_traits<V>::get() will get the right variant;
+ g_variant_iter_init(&varIter, var);
+ dbus_traits<V1>::get(conn, msg, varIter, val);
value = val;
} else {
V2 val;
- dbus_traits<V2>::get (conn, msg, sub, val);
+ // Note: Reset the iterator so that the call to dbus_traits<V>::get() will get the right variant;
+ g_variant_iter_init(&varIter, var);
+ dbus_traits<V2>::get(conn, msg, varIter, val);
value = val;
}
+ g_variant_unref(var);
+ g_variant_unref(varVar);
}
typedef boost::variant<V1, V2> host_type;
@@ -1269,15 +1486,15 @@ template<class K, class V, V K::*m> struct dbus_member_single
}
typedef V host_type;
- static void get(DBusConnection *conn, DBusMessage *msg,
- DBusMessageIter &iter, K &val)
+ static void get(GDBusConnection *conn, GDBusMessage *msg,
+ GVariantIter &iter, K &val)
{
dbus_traits<V>::get(conn, msg, iter, val.*m);
}
- static void append(DBusMessageIter &iter, const K &val)
+ static void append(GVariantBuilder &builder, const K &val)
{
- dbus_traits<V>::append(iter, val.*m);
+ dbus_traits<V>::append(builder, val.*m);
}
};
@@ -1293,17 +1510,17 @@ template<class K, class V, V K::*m, class M> struct dbus_member
}
typedef V host_type;
- static void get(DBusConnection *conn, DBusMessage *msg,
- DBusMessageIter &iter, K &val)
+ static void get(GDBusConnection *conn, GDBusMessage *msg,
+ GVariantIter &iter, K &val)
{
dbus_traits<V>::get(conn, msg, iter, val.*m);
M::get(conn, msg, iter, val);
}
- static void append(DBusMessageIter &iter, const K &val)
+ static void append(GVariantBuilder &builder, const K &val)
{
- dbus_traits<V>::append(iter, val.*m);
- M::append(iter, val);
+ dbus_traits<V>::append(builder, val.*m);
+ M::append(builder, val);
}
};
@@ -1332,29 +1549,26 @@ template<class K, class M> struct dbus_struct_traits : public dbus_traits_base
typedef K host_type;
typedef const K &arg_type;
- static void get(DBusConnection *conn, DBusMessage *msg,
- DBusMessageIter &iter, host_type &val)
+ static void get(GDBusConnection *conn, GDBusMessage *msg,
+ GVariantIter &iter, host_type &val)
{
-
- if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRUCT) {
+ GVariant *var = g_variant_iter_next_value(&iter);
+ if (var == NULL || !g_variant_type_is_subtype_of(g_variant_get_type(var), G_VARIANT_TYPE_TUPLE)) {
throw std::runtime_error("invalid argument");
}
- DBusMessageIter sub;
- dbus_message_iter_recurse(&iter, &sub);
- M::get(conn, msg, sub, val);
- dbus_message_iter_next(&iter);
+
+ GVariantIter tupIter;
+ g_variant_iter_init(&tupIter, var);
+ M::get(conn, msg, tupIter, val);
+
+ g_variant_unref(var);
}
- static void append(DBusMessageIter &iter, arg_type val)
+ static void append(GVariantBuilder &builder, arg_type val)
{
- DBusMessageIter sub;
- if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_STRUCT, NULL, &sub)) {
- throw std::runtime_error("out of memory");
- }
- M::append(sub, val);
- if (!dbus_message_iter_close_container(&iter, &sub)) {
- throw std::runtime_error("out of memory");
- }
+ g_variant_builder_open(&builder, G_VARIANT_TYPE(getType().c_str()));
+ M::append(builder, val);
+ g_variant_builder_close(&builder);
}
};
@@ -1398,7 +1612,7 @@ class DBusCXXException
virtual const char* getMessage() const { return "unknown"; }
};
-static DBusMessage *handleException(DBusMessage *msg)
+static GDBusMessage *handleException(GDBusMessage *msg)
{
try {
#ifdef DBUS_CXX_EXCEPTION_HANDLER
@@ -1407,13 +1621,13 @@ static DBusMessage *handleException(DBusMessage *msg)
throw;
#endif
} catch (const dbus_error &ex) {
- return b_dbus_create_error(msg, ex.dbusName().c_str(), "%s", ex.what());
+ return g_dbus_message_new_method_error(msg, ex.dbusName().c_str(), "%s", ex.what());
} catch (const DBusCXXException &ex) {
- return b_dbus_create_error(msg, ex.getName().c_str(), "%s", ex.getMessage());
+ return g_dbus_message_new_method_error(msg, ex.getName().c_str(), "%s", ex.getMessage());
} catch (const std::runtime_error &ex) {
- return b_dbus_create_error(msg, "org.syncevolution.gdbus-cxx.Exception", "%s", ex.what());
+ return g_dbus_message_new_method_error(msg, "org.syncevolution.gdbus-cxx.Exception", "%s", ex.what());
} catch (...) {
- return b_dbus_create_error(msg, "org.syncevolution.gdbus-cxx.Exception", "unknown");
+ return g_dbus_message_new_method_error(msg, "org.syncevolution.gdbus-cxx.Exception", "unknown");
}
}
@@ -1427,8 +1641,13 @@ class DBusWatch : public Watch
bool m_called;
guint m_watchID;
- static void disconnect(DBusConnection *connection,
- void *user_data)
+ static void disconnect(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
{
DBusWatch *watch = static_cast<DBusWatch *>(user_data);
if (!watch->m_called) {
@@ -1464,13 +1683,18 @@ class DBusWatch : public Watch
}
// Install watch first ...
- m_watchID = b_dbus_add_disconnect_watch(m_conn.get(),
- peer,
- disconnect,
- this,
- NULL);
+ m_watchID = g_dbus_connection_signal_subscribe(m_conn.get(),
+ peer,
+ "org.freedesktop.DBus",
+ "NameLost",
+ "/org/freesktop/DBus",
+ NULL,
+ G_DBUS_SIGNAL_FLAGS_NONE,
+ disconnect,
+ this,
+ NULL);
if (!m_watchID) {
- throw std::runtime_error("b_dbus_add_disconnect_watch() failed");
+ throw std::runtime_error("g_dbus_connection_signal_subscribe(): NameLost failed");
}
// ... then check that the peer really exists,
@@ -1478,24 +1702,39 @@ class DBusWatch : public Watch
// If it disconnects while we are doing this,
// then disconnect() will be called twice,
// but it handles that.
- DBusErrorCXX error;
- if (!dbus_bus_name_has_owner(m_conn.get(),
- peer,
- &error)) {
- if (error) {
- error.throwFailure("dbus_bus_name_has_owner()");
+ GError *error = NULL;
+
+ GVariant *result = g_dbus_connection_call_sync(m_conn.get(),
+ "org.freedesktop.DBus",
+ "/org/freedesktop/DBus",
+ "org.freedesktop.DBus",
+ "NameHasOwner",
+ g_variant_new("(s)", peer),
+ G_VARIANT_TYPE("(b)"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+
+ if (result != NULL) {
+ bool actual_result = false;
+
+ g_variant_get(result, "(b)", &actual_result);
+ if (!actual_result) {
+ disconnect(m_conn.get(), NULL, NULL, NULL, NULL, NULL, this);
}
- disconnect(m_conn.get(), this);
+ } else {
+ std::string error_message(error->message);
+ g_error_free(error);
+ std::string err_msg("g_dbus_connection_call_sync(): NameHasOwner - ");
+ throw std::runtime_error(err_msg + error_message);
}
}
~DBusWatch()
{
if (m_watchID) {
- if (!b_dbus_remove_watch(m_conn.get(), m_watchID)) {
- // this may happen because the watch is
- // removed automatically when it was triggered
- }
+ g_dbus_connection_signal_unsubscribe(m_conn.get(), m_watchID);
m_watchID = 0;
}
}
@@ -1511,15 +1750,15 @@ template <> struct dbus_traits< boost::shared_ptr<Watch> > : public dbus_traits
static std::string getSignature() { return ""; }
static std::string getReply() { return ""; }
- static void get(DBusConnection *conn, DBusMessage *msg,
- DBusMessageIter &iter, boost::shared_ptr<Watch> &value)
+ static void get(GDBusConnection *conn, GDBusMessage *msg,
+ GVariantIter &iter, boost::shared_ptr<Watch> &value)
{
boost::shared_ptr<DBusWatch> watch(new DBusWatch(conn));
- watch->activate(dbus_message_get_sender(msg));
+ watch->activate(g_dbus_message_get_sender(msg));
value = watch;
}
- static void append(DBusMessageIter &iter, const boost::shared_ptr<Watch> &value) {}
+ static void append(GVariantBuilder &builder, const boost::shared_ptr<Watch> &value) {}
typedef boost::shared_ptr<Watch> host_type;
typedef const boost::shared_ptr<Watch> &arg_type;
@@ -1534,28 +1773,30 @@ class DBusResult : virtual public Result
{
protected:
DBusConnectionPtr m_conn; /**< connection via which the message was received */
- DBusMessagePtr m_msg; /**< the method invocation message */
+ GDBusMessagePtr m_msg; /**< the method invocation message */
public:
- DBusResult(DBusConnection *conn,
- DBusMessage *msg) :
+ DBusResult(GDBusConnection *conn,
+ GDBusMessage *msg) :
m_conn(conn, true),
m_msg(msg, true)
{}
virtual void failed(const dbus_error &error)
{
- if (!b_dbus_send_error(m_conn.get(), m_msg.get(),
- error.dbusName().c_str(),
- "%s", error.what())) {
- throw std::runtime_error("b_dbus_send_error() failed");
+ GDBusMessage *errMsg;
+ errMsg = g_dbus_message_new_method_error(m_msg.get(), error.dbusName().c_str(),
+ "%s", error.what());
+ if (!g_dbus_connection_send_message(m_conn.get(), m_msg.get(),
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL)) {
+ throw std::runtime_error(" g_dbus_connection_send_message failed");
}
}
virtual Watch *createWatch(const boost::function<void (void)> &callback)
{
std::auto_ptr<DBusWatch> watch(new DBusWatch(m_conn, callback));
- watch->activate(dbus_message_get_sender(m_msg.get()));
+ watch->activate(g_dbus_message_get_sender(m_msg.get()));
return watch.release();
}
};
@@ -1565,19 +1806,20 @@ class DBusResult0 :
public DBusResult
{
public:
- DBusResult0(DBusConnection *conn,
- DBusMessage *msg) :
+ DBusResult0(GDBusConnection *conn,
+ GDBusMessage *msg) :
DBusResult(conn, msg)
{}
virtual void done()
{
- DBusMessagePtr reply(b_dbus_create_reply(m_msg.get(), DBUS_TYPE_INVALID));
+ GDBusMessagePtr reply(g_dbus_message_new_method_reply(m_msg.get()));
if (!reply) {
- throw std::runtime_error("no DBusMessage");
+ throw std::runtime_error("no GDBusMessage");
}
- if (!dbus_connection_send(m_conn.get(), reply.get(), NULL)) {
- throw std::runtime_error("dbus_connection_send failed");
+ if (!g_dbus_connection_send_message(m_conn.get(), reply.get(),
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL)) {
+ throw std::runtime_error("g_dbus_connection_send_message");
}
}
@@ -1590,27 +1832,26 @@ class DBusResult1 :
public DBusResult
{
public:
- DBusResult1(DBusConnection *conn,
- DBusMessage *msg) :
+ DBusResult1(GDBusConnection *conn,
+ GDBusMessage *msg) :
DBusResult(conn, msg)
{}
virtual void done(A1 a1)
{
- DBusMessagePtr reply(b_dbus_create_reply(m_msg.get(), DBUS_TYPE_INVALID));
+ GDBusMessagePtr reply(g_dbus_message_new_method_reply(m_msg.get()));
if (!reply) {
- throw std::runtime_error("no DBusMessage");
+ throw std::runtime_error("no GDBusMessage");
}
- AppendRetvals(reply) << a1;
- if (!dbus_connection_send(m_conn.get(), reply.get(), NULL)) {
- throw std::runtime_error("dbus_connection_send failed");
+ AppendRetvals(reply.get()) << a1;
+ if (!g_dbus_connection_send_message(m_conn.get(), reply.get(),
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL)) {
}
}
static std::string getSignature() { return dbus_traits<A1>::getSignature(); }
- static const bool asynchronous =
- dbus_traits<A1>::asynchronous;
+ static const bool asynchronous = dbus_traits<A1>::asynchronous;
};
template <typename A1, typename A2>
@@ -1619,20 +1860,20 @@ class DBusResult2 :
public DBusResult
{
public:
- DBusResult2(DBusConnection *conn,
- DBusMessage *msg) :
+ DBusResult2(GDBusConnection *conn,
+ GDBusMessage *msg) :
DBusResult(conn, msg)
{}
virtual void done(A1 a1, A2 a2)
{
- DBusMessagePtr reply(b_dbus_create_reply(m_msg.get(), DBUS_TYPE_INVALID));
+ GDBusMessagePtr reply(g_dbus_message_new_method_reply(m_msg.get()));
if (!reply) {
- throw std::runtime_error("no DBusMessage");
+ throw std::runtime_error("no GDBusMessage");
}
- AppendRetvals(reply) << a1 << a2;
- if (!dbus_connection_send(m_conn.get(), reply.get(), NULL)) {
- throw std::runtime_error("dbus_connection_send failed");
+ AppendRetvals(reply.get()) << a1 << a2;
+ if (!g_dbus_connection_send_message(m_conn.get(), reply.get(),
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL)) {
}
}
@@ -1652,20 +1893,20 @@ class DBusResult3 :
public DBusResult
{
public:
- DBusResult3(DBusConnection *conn,
- DBusMessage *msg) :
+ DBusResult3(GDBusConnection *conn,
+ GDBusMessage *msg) :
DBusResult(conn, msg)
{}
virtual void done(A1 a1, A2 a2, A3 a3)
{
- DBusMessagePtr reply(b_dbus_create_reply(m_msg.get(), DBUS_TYPE_INVALID));
+ GDBusMessagePtr reply(g_dbus_message_new_method_reply(m_msg.get()));
if (!reply) {
- throw std::runtime_error("no DBusMessage");
+ throw std::runtime_error("no GDBusMessage");
}
- AppendRetvals(reply) << a1 << a2 << a3;
- if (!dbus_connection_send(m_conn.get(), reply.get(), NULL)) {
- throw std::runtime_error("dbus_connection_send failed");
+ AppendRetvals(reply.get()) << a1 << a2 << a3;
+ if (!g_dbus_connection_send_message(m_conn.get(), reply.get(),
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL)) {
}
}
@@ -1685,23 +1926,22 @@ class DBusResult4 :
public DBusResult
{
public:
- DBusResult4(DBusConnection *conn,
- DBusMessage *msg) :
+ DBusResult4(GDBusConnection *conn,
+ GDBusMessage *msg) :
DBusResult(conn, msg)
{}
virtual void done(A1 a1, A2 a2, A3 a3, A4 a4)
{
- DBusMessagePtr reply(b_dbus_create_reply(m_msg.get(), DBUS_TYPE_INVALID));
+ GDBusMessagePtr reply(g_dbus_message_new_method_reply(m_msg.get()));
if (!reply) {
- throw std::runtime_error("no DBusMessage");
+ throw std::runtime_error("no GDBusMessage");
}
- AppendRetvals(reply) << a1 << a2 << a3 << a4;
- if (!dbus_connection_send(m_conn.get(), reply.get(), NULL)) {
- throw std::runtime_error("dbus_connection_send failed");
+ AppendRetvals(reply.get()) << a1 << a2 << a3 << a4;
+ if (!g_dbus_connection_send_message(m_conn.get(), reply.get(),
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL)) {
}
}
-
static std::string getSignature() {
return dbus_traits<A1>::getSignature() +
DBusResult3<A2, A3, A4>::getSignature();
@@ -1718,20 +1958,20 @@ class DBusResult5 :
public DBusResult
{
public:
- DBusResult5(DBusConnection *conn,
- DBusMessage *msg) :
+ DBusResult5(GDBusConnection *conn,
+ GDBusMessage *msg) :
DBusResult(conn, msg)
{}
virtual void done(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5)
{
- DBusMessagePtr reply(b_dbus_create_reply(m_msg.get(), DBUS_TYPE_INVALID));
+ GDBusMessagePtr reply(g_dbus_message_new_method_reply(m_msg.get()));
if (!reply) {
- throw std::runtime_error("no DBusMessage");
+ throw std::runtime_error("no GDBusMessage");
}
- AppendRetvals(reply) << a1 << a2 << a3 << a4 << a5;
- if (!dbus_connection_send(m_conn.get(), reply.get(), NULL)) {
- throw std::runtime_error("dbus_connection_send failed");
+ AppendRetvals(reply.get()) << a1 << a2 << a3 << a4 << a5;
+ if (!g_dbus_connection_send_message(m_conn.get(), reply.get(),
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL)) {
}
}
@@ -1752,20 +1992,20 @@ class DBusResult6 :
public DBusResult
{
public:
- DBusResult6(DBusConnection *conn,
- DBusMessage *msg) :
+ DBusResult6(GDBusConnection *conn,
+ GDBusMessage *msg) :
DBusResult(conn, msg)
{}
virtual void done(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6)
{
- DBusMessagePtr reply(b_dbus_create_reply(m_msg.get(), DBUS_TYPE_INVALID));
+ GDBusMessagePtr reply(g_dbus_message_new_method_reply(m_msg.get()));
if (!reply) {
- throw std::runtime_error("no DBusMessage");
+ throw std::runtime_error("no GDBusMessage");
}
- AppendRetvals(reply) << a1 << a2 << a3 << a4 << a5 << a6;
- if (!dbus_connection_send(m_conn.get(), reply.get(), NULL)) {
- throw std::runtime_error("dbus_connection_send failed");
+ AppendRetvals(reply.get()) << a1 << a2 << a3 << a4 << a5 << a6;
+ if (!g_dbus_connection_send_message(m_conn.get(), reply.get(),
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL)) {
}
}
@@ -1786,20 +2026,20 @@ class DBusResult7 :
public DBusResult
{
public:
- DBusResult7(DBusConnection *conn,
- DBusMessage *msg) :
+ DBusResult7(GDBusConnection *conn,
+ GDBusMessage *msg) :
DBusResult(conn, msg)
{}
virtual void done(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7)
{
- DBusMessagePtr reply(b_dbus_create_reply(m_msg.get(), DBUS_TYPE_INVALID));
+ GDBusMessagePtr reply(g_dbus_message_new_method_reply(m_msg.get()));
if (!reply) {
- throw std::runtime_error("no DBusMessage");
+ throw std::runtime_error("no GDBusMessage");
}
- AppendRetvals(reply) << a1 << a2 << a3 << a4 << a5 << a6 << a7;
- if (!dbus_connection_send(m_conn.get(), reply.get(), NULL)) {
- throw std::runtime_error("dbus_connection_send failed");
+ AppendRetvals(reply.get()) << a1 << a2 << a3 << a4 << a5 << a6 << a7;
+ if (!g_dbus_connection_send_message(m_conn.get(), reply.get(),
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL)) {
}
}
@@ -1820,20 +2060,20 @@ class DBusResult8 :
public DBusResult
{
public:
- DBusResult8(DBusConnection *conn,
- DBusMessage *msg) :
+ DBusResult8(GDBusConnection *conn,
+ GDBusMessage *msg) :
DBusResult(conn, msg)
{}
virtual void done(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8)
{
- DBusMessagePtr reply(b_dbus_create_reply(m_msg.get(), DBUS_TYPE_INVALID));
+ GDBusMessagePtr reply(g_dbus_message_new_method_reply(m_msg.get()));
if (!reply) {
- throw std::runtime_error("no DBusMessage");
+ throw std::runtime_error("no GDBusMessage");
}
- AppendRetvals(reply) << a1 << a2 << a3 << a4 << a5 << a6 << a7 << a8;
- if (!dbus_connection_send(m_conn.get(), reply.get(), NULL)) {
- throw std::runtime_error("dbus_connection_send failed");
+ AppendRetvals(reply.get()) << a1 << a2 << a3 << a4 << a5 << a6 << a7 << a8;
+ if (!g_dbus_connection_send_message(m_conn.get(), reply.get(),
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL)) {
}
}
@@ -1854,20 +2094,20 @@ class DBusResult9 :
public DBusResult
{
public:
- DBusResult9(DBusConnection *conn,
- DBusMessage *msg) :
+ DBusResult9(GDBusConnection *conn,
+ GDBusMessage *msg) :
DBusResult(conn, msg)
{}
virtual void done(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9)
{
- DBusMessagePtr reply(b_dbus_create_reply(m_msg.get(), DBUS_TYPE_INVALID));
+ GDBusMessagePtr reply(g_dbus_message_new_method_reply(m_msg.get()));
if (!reply) {
- throw std::runtime_error("no DBusMessage");
+ throw std::runtime_error("no GDBusMessage");
}
- AppendRetvals(reply) << a1 << a2 << a3 << a4 << a5 << a6 << a7 << a8 << a9;
- if (!dbus_connection_send(m_conn.get(), reply.get(), NULL)) {
- throw std::runtime_error("dbus_connection_send failed");
+ AppendRetvals(reply.get()) << a1 << a2 << a3 << a4 << a5 << a6 << a7 << a8 << a9;
+ if (!g_dbus_connection_send_message(m_conn.get(), reply.get(),
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL)) {
}
}
@@ -1888,20 +2128,20 @@ class DBusResult10 :
public DBusResult
{
public:
- DBusResult10(DBusConnection *conn,
- DBusMessage *msg) :
+ DBusResult10(GDBusConnection *conn,
+ GDBusMessage *msg) :
DBusResult(conn, msg)
{}
virtual void done(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10)
{
- DBusMessagePtr reply(b_dbus_create_reply(m_msg.get(), DBUS_TYPE_INVALID));
+ GDBusMessagePtr reply(g_dbus_message_new_method_reply(m_msg.get()));
if (!reply) {
- throw std::runtime_error("no DBusMessage");
+ throw std::runtime_error("no GDBusMessage");
}
- AppendRetvals(reply) << a1 << a2 << a3 << a4 << a5 << a6 << a7 << a8 << a9 << a10;
- if (!dbus_connection_send(m_conn.get(), reply.get(), NULL)) {
- throw std::runtime_error("dbus_connection_send failed");
+ AppendRetvals(reply.get()) << a1 << a2 << a3 << a4 << a5 << a6 << a7 << a8 << a9 << a10;
+ if (!g_dbus_connection_send_message(m_conn.get(), reply.get(),
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL)) {
}
}
@@ -1931,10 +2171,10 @@ template <class R, class DBusR> struct dbus_traits_result
typedef boost::shared_ptr<R> host_type;
typedef boost::shared_ptr<R> &arg_type;
- static const bool asynchronous = true;
+ static const bool asynchronous = false;
- static void get(DBusConnection *conn, DBusMessage *msg,
- DBusMessageIter &iter, host_type &value)
+ static void get(GDBusConnection *conn, GDBusMessage *msg,
+ GVariantIter &iter, host_type &value)
{
value.reset(new DBusR(conn, msg));
}
@@ -1985,128 +2225,6 @@ template <class A1, class A2, class A3, class A4, class A5, class A6, class A7,
public dbus_traits_result< Result10<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10>, DBusResult10<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10> >
{};
-
-#if 0
-/**
- * Call with two parameters and one return code. All other calls are
- * variations of this, so this one is fully documented to explain all
- * tricks used in these templates. The actual code without comments is
- * below.
- */
-template <class R, class A1, class A2>
-struct MakeMethodEntry< boost::function<R (A1, A2)> >
-{
- typedef boost::function<R (A1, A2)> M;
-
- // Any type a Result parameter? This can be computed at compile time.
- static const bool asynchronous = dbus_traits< DBusResult2<A1, A2> >::asynchronous;
-
- static DBusMessage *methodFunction(DBusConnection *conn,
- DBusMessage *msg, void *data)
- {
- // all exceptions must be caught and translated into
- // a suitable D-Bus reply
- try {
- // Argument types might may be references or pointers.
- // To instantiate a variable we need the underlying
- // datatype, which is provided by the dbus_traits.
- // "typename" is necessary to tell the compiler
- // that host_type really is a type.
- typename dbus_traits<R>::host_type r;
- typename dbus_traits<A1>::host_type a1;
- typename dbus_traits<A2>::host_type a2;
-
- // Extract all parameters. Because we don't now
- // whether a parameter is an argument or a return
- // value, we call get() for each of them and let
- // the corresponding dbus_traits decide that. Traits
- // for types which are plain types or const references
- // have a non-empty get(), whereas references are treated
- // as return values and have an empty get().
- DBusMessageIter iter;
- dbus_message_iter_init(msg, &iter);
- dbus_traits<A1>::get(conn, msg, iter, a1);
- dbus_traits<A2>::get(conn, msg, iter, a2);
-
- // The data pointer is a pointer to a boost function,
- // as set up for us by make(). The compiler knows the
- // exact method prototype and thus can handle
- // call-by-value and call-by-reference correctly.
- r = (*static_cast<M *>(data))(a1, a2);
-
- // No reply necessary? If any of the types is asking for
- // a Result handle, then the reply will be sent later.
- if (asynchronous) {
- return NULL;
- }
-
- // Now prepare the reply. As with extracting parameters,
- // append() is empty for those parameters where nothing
- // has to be done.
- DBusMessage *reply = dbus_message_new_method_return(msg);
- if (!reply)
- return NULL;
- dbus_message_iter_init_append(reply, &iter);
- // We know that the return value has to be appended,
- // even though the trait would not normally do that
- // because it is a plain type => call utility function
- // directly.
- dbus_traits<R>::append(iter, r);
- dbus_traits<A1>::append(iter, a1);
- dbus_traits<A2>::append(iter, a2);
- return reply;
- } catch (...) {
- // let handleException rethrow the exception
- // to determine its type
- return handleException(msg);
- }
- }
-
- /**
- * The boost function doesn't have a virtual destructor.
- * Therefore we have to cast down to the right type M
- * before deleting it. The rest of the allocated data
- * is freed by BDBusVector.
- */
- static void destroyFunction(void *user_data)
- {
- BDBusMethodTable *entry = static_cast<BDBusMethodTable *>(user_data);
- delete static_cast<M *>(entry->method_data);
- }
-
- /**
- * Creates a BDBusMethodTable entry.
- * The strings inside the entry are allocated
- * with strdup(), to be freed by BDBusVector::destroy().
- */
- BDBusMethodTable make(const char *name, BDBusMethodFlags flags, const M &m)
- {
- BDBusMethodTable entry;
- entry.name = strdup(name);
- // same trick as before: only argument types
- // are added to the signature
- std::string buffer;
- buffer += dbus_traits<A1>::getSignature();
- buffer += dbus_traits<A2>::getSignature();
- entry.signature = strdup(buffer.c_str());
- // now the same for reply types
- buffer.clear();
- buffer += dbus_traits<R>::getReply();
- buffer += dbus_traits<A1>::getReply();
- buffer += dbus_traits<A2>::getReply();
- entry.reply = strdup(buffer.c_str());
- // these are the function templates above
- entry.function = methodFunction;
- entry.destroy = destroyFunction;
- // make sure that methodFunction has access to the boost function
- entry.flags = BDBusMethodFlags(flags | G_DBUS_METHOD_FLAG_METHOD_DATA |
- (asynchronous ? G_DBUS_METHOD_FLAG_ASYNC : 0));
- entry.method_data = new M(m);
- return entry;
- }
-};
-#endif // 0
-
/** ===> 10 parameters */
template <class A1, class A2, class A3, class A4, class A5,
class A6, class A7, class A8, class A9, class A10>
@@ -2123,8 +2241,8 @@ struct MakeMethodEntry< boost::function<void (A1, A2, A3, A4, A5, A6, A7, A8, A9
static const bool asynchronous = dbus_traits< DBusResult10<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10> >::asynchronous;
- static DBusMessage *methodFunction(DBusConnection *conn,
- DBusMessage *msg, void *data)
+ static GDBusMessage *methodFunction(GDBusConnection *conn,
+ GDBusMessage *msg, void *data)
{
try {
typename dbus_traits<A1>::host_type a1;
@@ -2138,7 +2256,8 @@ struct MakeMethodEntry< boost::function<void (A1, A2, A3, A4, A5, A6, A7, A8, A9
typename dbus_traits<A9>::host_type a9;
typename dbus_traits<A10>::host_type a10;
- ExtractArgs(conn, msg) >> Get<A1>(a1) >> Get<A2>(a2) >> Get<A3>(a3) >> Get<A4>(a4) >> Get<A5>(a5) >> Get<A6>(a6) >> Get<A7>(a7) >> Get<A8>(a8) >> Get<A9>(a9) >> Get<A10>(a10);
+ ExtractArgs(conn, msg) >> Get<A1>(a1) >> Get<A2>(a2) >> Get<A3>(a3) >> Get<A4>(a4) >> Get<A5>(a5)
+ >> Get<A6>(a6) >> Get<A7>(a7) >> Get<A8>(a8) >> Get<A9>(a9) >> Get<A10>(a10);
(*static_cast<M *>(data))(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
@@ -2146,11 +2265,12 @@ struct MakeMethodEntry< boost::function<void (A1, A2, A3, A4, A5, A6, A7, A8, A9
return NULL;
}
- DBusMessage *reply = dbus_message_new_method_return(msg);
+ GDBusMessage *reply = g_dbus_message_new_method_reply(msg);
if (!reply)
return NULL;
- AppendArgs(reply) << Set<A1>(a1) << Set<A2>(a2) << Set<A3>(a3) << Set<A4>(a4) << Set<A5>(a5) << Set<A6>(a6) << Set<A7>(a7) << Set<A8>(a8) << Set<A9>(a9) << Set<A10>(a10);
+ AppendArgs(reply) << Set<A1>(a1) << Set<A2>(a2) << Set<A3>(a3) << Set<A4>(a4) << Set<A5>(a5)
+ << Set<A6>(a6) << Set<A7>(a7) << Set<A8>(a8) << Set<A9>(a9) << Set<A10>(a10);
return reply;
} catch (...) {
@@ -2158,45 +2278,41 @@ struct MakeMethodEntry< boost::function<void (A1, A2, A3, A4, A5, A6, A7, A8, A9
}
}
- static void destroyFunction(void *user_data)
- {
- BDBusMethodTable *entry = static_cast<BDBusMethodTable *>(user_data);
- delete static_cast<M *>(entry->method_data);
- }
-
- static BDBusMethodTable make(const char *name, BDBusMethodFlags flags, const M &m)
- {
- BDBusMethodTable entry;
- entry.name = strdup(name);
- std::string buffer;
- buffer += dbus_traits<A1>::getSignature();
- buffer += dbus_traits<A2>::getSignature();
- buffer += dbus_traits<A3>::getSignature();
- buffer += dbus_traits<A4>::getSignature();
- buffer += dbus_traits<A5>::getSignature();
- buffer += dbus_traits<A6>::getSignature();
- buffer += dbus_traits<A7>::getSignature();
- buffer += dbus_traits<A8>::getSignature();
- buffer += dbus_traits<A9>::getSignature();
- buffer += dbus_traits<A10>::getSignature();
- entry.signature = strdup(buffer.c_str());
- buffer.clear();
- buffer += dbus_traits<A1>::getReply();
- buffer += dbus_traits<A2>::getReply();
- buffer += dbus_traits<A3>::getReply();
- buffer += dbus_traits<A4>::getReply();
- buffer += dbus_traits<A5>::getReply();
- buffer += dbus_traits<A6>::getReply();
- buffer += dbus_traits<A7>::getReply();
- buffer += dbus_traits<A8>::getReply();
- buffer += dbus_traits<A9>::getReply();
- buffer += dbus_traits<A10>::getReply();
- entry.reply = strdup(buffer.c_str());
- entry.function = methodFunction;
- entry.destroy = destroyFunction;
- entry.flags = BDBusMethodFlags(flags | G_DBUS_METHOD_FLAG_METHOD_DATA |
- (asynchronous ? G_DBUS_METHOD_FLAG_ASYNC : 0));
- entry.method_data = new M(m);
+ static GDBusMethodInfo *make(const char *name)
+ {
+ GDBusMethodInfo *entry = g_new0(GDBusMethodInfo, 1);
+
+ GPtrArray *inArgs = g_ptr_array_new();
+ appendNewArg<A1>(inArgs);
+ appendNewArg<A2>(inArgs);
+ appendNewArg<A3>(inArgs);
+ appendNewArg<A4>(inArgs);
+ appendNewArg<A5>(inArgs);
+ appendNewArg<A6>(inArgs);
+ appendNewArg<A7>(inArgs);
+ appendNewArg<A8>(inArgs);
+ appendNewArg<A9>(inArgs);
+ appendNewArg<A10>(inArgs);
+ g_ptr_array_add(inArgs, NULL);
+
+ GPtrArray *outArgs = g_ptr_array_new();
+ appendNewArgForReply<A1>(outArgs);
+ appendNewArgForReply<A2>(outArgs);
+ appendNewArgForReply<A3>(outArgs);
+ appendNewArgForReply<A4>(outArgs);
+ appendNewArgForReply<A5>(outArgs);
+ appendNewArgForReply<A6>(outArgs);
+ appendNewArgForReply<A7>(outArgs);
+ appendNewArgForReply<A8>(outArgs);
+ appendNewArgForReply<A9>(outArgs);
+ appendNewArgForReply<A10>(outArgs);
+ g_ptr_array_add(outArgs, NULL);
+
+ entry->name = g_strdup(name);
+ entry->in_args = (GDBusArgInfo **)g_ptr_array_free(inArgs, FALSE);
+ entry->out_args = (GDBusArgInfo **)g_ptr_array_free(outArgs, FALSE);
+
+ entry->ref_count = 1;
return entry;
}
};
@@ -2218,8 +2334,8 @@ struct MakeMethodEntry< boost::function<R (A1, A2, A3, A4, A5, A6, A7, A8, A9)>
static const bool asynchronous = DBusResult9<A1, A2, A3, A4, A5, A6, A7, A8, A9>::asynchronous;
- static DBusMessage *methodFunction(DBusConnection *conn,
- DBusMessage *msg, void *data)
+ static GDBusMessage *methodFunction(GDBusConnection *conn,
+ GDBusMessage *msg, void *data)
{
try {
typename dbus_traits<R>::host_type r;
@@ -2233,7 +2349,8 @@ struct MakeMethodEntry< boost::function<R (A1, A2, A3, A4, A5, A6, A7, A8, A9)>
typename dbus_traits<A8>::host_type a8;
typename dbus_traits<A9>::host_type a9;
- ExtractArgs(conn, msg) >> Get<A1>(a1) >> Get<A2>(a2) >> Get<A3>(a3) >> Get<A4>(a4) >> Get<A5>(a5) >> Get<A6>(a6) >> Get<A7>(a7) >> Get<A8>(a8) >> Get<A9>(a9);
+ ExtractArgs(conn, msg) >> Get<A1>(a1) >> Get<A2>(a2) >> Get<A3>(a3) >> Get<A4>(a4) >> Get<A5>(a5)
+ >> Get<A6>(a6) >> Get<A7>(a7) >> Get<A8>(a8) >> Get<A9>(a9);
r = (*static_cast<M *>(data))(a1, a2, a3, a4, a5, a6, a7, a8, a9);
@@ -2241,11 +2358,12 @@ struct MakeMethodEntry< boost::function<R (A1, A2, A3, A4, A5, A6, A7, A8, A9)>
return NULL;
}
- DBusMessage *reply = dbus_message_new_method_return(msg);
+ GDBusMessage *reply = g_dbus_message_new_method_reply(msg);
if (!reply)
return NULL;
- AppendArgs(reply) + r << Set<A1>(a1) << Set<A2>(a2) << Set<A3>(a3) << Set<A4>(a4) << Set<A5>(a5) << Set<A6>(a6) << Set<A7>(a7) << Set<A8>(a8) << Set<A9>(a9);
+ AppendArgs(reply) + r << Set<A1>(a1) << Set<A2>(a2) << Set<A3>(a3) << Set<A4>(a4) << Set<A5>(a5)
+ << Set<A6>(a6) << Set<A7>(a7) << Set<A8>(a8) << Set<A9>(a9);
return reply;
} catch (...) {
@@ -2253,44 +2371,39 @@ struct MakeMethodEntry< boost::function<R (A1, A2, A3, A4, A5, A6, A7, A8, A9)>
}
}
- static void destroyFunction(void *user_data)
- {
- BDBusMethodTable *entry = static_cast<BDBusMethodTable *>(user_data);
- delete static_cast<M *>(entry->method_data);
- }
-
- static BDBusMethodTable make(const char *name, BDBusMethodFlags flags, const M &m)
- {
- BDBusMethodTable entry;
- entry.name = strdup(name);
- std::string buffer;
- buffer += dbus_traits<A1>::getSignature();
- buffer += dbus_traits<A2>::getSignature();
- buffer += dbus_traits<A3>::getSignature();
- buffer += dbus_traits<A4>::getSignature();
- buffer += dbus_traits<A5>::getSignature();
- buffer += dbus_traits<A6>::getSignature();
- buffer += dbus_traits<A7>::getSignature();
- buffer += dbus_traits<A8>::getSignature();
- buffer += dbus_traits<A9>::getSignature();
- entry.signature = strdup(buffer.c_str());
- buffer.clear();
- buffer += dbus_traits<R>::getReply();
- buffer += dbus_traits<A1>::getReply();
- buffer += dbus_traits<A2>::getReply();
- buffer += dbus_traits<A3>::getReply();
- buffer += dbus_traits<A4>::getReply();
- buffer += dbus_traits<A5>::getReply();
- buffer += dbus_traits<A6>::getReply();
- buffer += dbus_traits<A7>::getReply();
- buffer += dbus_traits<A8>::getReply();
- buffer += dbus_traits<A9>::getReply();
- entry.reply = strdup(buffer.c_str());
- entry.function = methodFunction;
- entry.destroy = destroyFunction;
- entry.flags = BDBusMethodFlags(flags | G_DBUS_METHOD_FLAG_METHOD_DATA |
- (asynchronous ? G_DBUS_METHOD_FLAG_ASYNC : 0));
- entry.method_data = new M(m);
+ static GDBusMethodInfo *make(const char *name)
+ {
+ GDBusMethodInfo *entry = g_new0(GDBusMethodInfo, 1);
+
+ GPtrArray *inArgs = g_ptr_array_new();
+ appendNewArg<A1>(inArgs);
+ appendNewArg<A2>(inArgs);
+ appendNewArg<A3>(inArgs);
+ appendNewArg<A4>(inArgs);
+ appendNewArg<A5>(inArgs);
+ appendNewArg<A6>(inArgs);
+ appendNewArg<A7>(inArgs);
+ appendNewArg<A8>(inArgs);
+ appendNewArg<A9>(inArgs);
+ g_ptr_array_add(inArgs, NULL);
+
+ GPtrArray *outArgs = g_ptr_array_new();
+ appendNewArgForReply<A1>(outArgs);
+ appendNewArgForReply<A2>(outArgs);
+ appendNewArgForReply<A3>(outArgs);
+ appendNewArgForReply<A4>(outArgs);
+ appendNewArgForReply<A5>(outArgs);
+ appendNewArgForReply<A6>(outArgs);
+ appendNewArgForReply<A7>(outArgs);
+ appendNewArgForReply<A8>(outArgs);
+ appendNewArgForReply<A9>(outArgs);
+ g_ptr_array_add(outArgs, NULL);
+
+ entry->name = g_strdup(name);
+ entry->in_args = (GDBusArgInfo **)g_ptr_array_free(inArgs, FALSE);
+ entry->out_args = (GDBusArgInfo **)g_ptr_array_free(outArgs, FALSE);
+
+ entry->ref_count = 1;
return entry;
}
};
@@ -2309,8 +2422,8 @@ struct MakeMethodEntry< boost::function<void (A1, A2, A3, A4, A5, A6, A7, A8, A9
static const bool asynchronous = DBusResult9<A1, A2, A3, A4, A5, A6, A7, A8, A9>::asynchronous;
- static DBusMessage *methodFunction(DBusConnection *conn,
- DBusMessage *msg, void *data)
+ static GDBusMessage *methodFunction(GDBusConnection *conn,
+ GDBusMessage *msg, void *data)
{
try {
typename dbus_traits<A1>::host_type a1;
@@ -2323,7 +2436,8 @@ struct MakeMethodEntry< boost::function<void (A1, A2, A3, A4, A5, A6, A7, A8, A9
typename dbus_traits<A8>::host_type a8;
typename dbus_traits<A9>::host_type a9;
- ExtractArgs(conn, msg) >> Get<A1>(a1) >> Get<A2>(a2) >> Get<A3>(a3) >> Get<A4>(a4) >> Get<A5>(a5) >> Get<A6>(a6) >> Get<A7>(a7) >> Get<A8>(a8) >> Get<A9>(a9);
+ ExtractArgs(conn, msg) >> Get<A1>(a1) >> Get<A2>(a2) >> Get<A3>(a3) >> Get<A4>(a4) >> Get<A5>(a5)
+ >> Get<A6>(a6) >> Get<A7>(a7) >> Get<A8>(a8) >> Get<A9>(a9);
(*static_cast<M *>(data))(a1, a2, a3, a4, a5, a6, a7, a8, a9);
@@ -2331,11 +2445,12 @@ struct MakeMethodEntry< boost::function<void (A1, A2, A3, A4, A5, A6, A7, A8, A9
return NULL;
}
- DBusMessage *reply = dbus_message_new_method_return(msg);
+ GDBusMessage *reply = g_dbus_message_new_method_reply(msg);
if (!reply)
return NULL;
- AppendArgs(reply) << Set<A1>(a1) << Set<A2>(a2) << Set<A3>(a3) << Set<A4>(a4) << Set<A5>(a5) << Set<A6>(a6) << Set<A7>(a7) << Set<A8>(a8) << Set<A9>(a9);
+ AppendArgs(reply) << Set<A1>(a1) << Set<A2>(a2) << Set<A3>(a3) << Set<A4>(a4) << Set<A5>(a5)
+ << Set<A6>(a6) << Set<A7>(a7) << Set<A8>(a8) << Set<A9>(a9);
return reply;
} catch (...) {
@@ -2343,43 +2458,39 @@ struct MakeMethodEntry< boost::function<void (A1, A2, A3, A4, A5, A6, A7, A8, A9
}
}
- static void destroyFunction(void *user_data)
- {
- BDBusMethodTable *entry = static_cast<BDBusMethodTable *>(user_data);
- delete static_cast<M *>(entry->method_data);
- }
-
- static BDBusMethodTable make(const char *name, BDBusMethodFlags flags, const M &m)
- {
- BDBusMethodTable entry;
- entry.name = strdup(name);
- std::string buffer;
- buffer += dbus_traits<A1>::getSignature();
- buffer += dbus_traits<A2>::getSignature();
- buffer += dbus_traits<A3>::getSignature();
- buffer += dbus_traits<A4>::getSignature();
- buffer += dbus_traits<A5>::getSignature();
- buffer += dbus_traits<A6>::getSignature();
- buffer += dbus_traits<A7>::getSignature();
- buffer += dbus_traits<A8>::getSignature();
- buffer += dbus_traits<A9>::getSignature();
- entry.signature = strdup(buffer.c_str());
- buffer.clear();
- buffer += dbus_traits<A1>::getReply();
- buffer += dbus_traits<A2>::getReply();
- buffer += dbus_traits<A3>::getReply();
- buffer += dbus_traits<A4>::getReply();
- buffer += dbus_traits<A5>::getReply();
- buffer += dbus_traits<A6>::getReply();
- buffer += dbus_traits<A7>::getReply();
- buffer += dbus_traits<A8>::getReply();
- buffer += dbus_traits<A9>::getReply();
- entry.reply = strdup(buffer.c_str());
- entry.function = methodFunction;
- entry.destroy = destroyFunction;
- entry.flags = BDBusMethodFlags(flags | G_DBUS_METHOD_FLAG_METHOD_DATA |
- (asynchronous ? G_DBUS_METHOD_FLAG_ASYNC : 0));
- entry.method_data = new M(m);
+ static GDBusMethodInfo *make(const char *name)
+ {
+ GDBusMethodInfo *entry = g_new0(GDBusMethodInfo, 1);
+
+ GPtrArray *inArgs = g_ptr_array_new();
+ appendNewArg<A1>(inArgs);
+ appendNewArg<A2>(inArgs);
+ appendNewArg<A3>(inArgs);
+ appendNewArg<A4>(inArgs);
+ appendNewArg<A5>(inArgs);
+ appendNewArg<A6>(inArgs);
+ appendNewArg<A7>(inArgs);
+ appendNewArg<A8>(inArgs);
+ appendNewArg<A9>(inArgs);
+ g_ptr_array_add(inArgs, NULL);
+
+ GPtrArray *outArgs = g_ptr_array_new();
+ appendNewArgForReply<A1>(outArgs);
+ appendNewArgForReply<A2>(outArgs);
+ appendNewArgForReply<A3>(outArgs);
+ appendNewArgForReply<A4>(outArgs);
+ appendNewArgForReply<A5>(outArgs);
+ appendNewArgForReply<A6>(outArgs);
+ appendNewArgForReply<A7>(outArgs);
+ appendNewArgForReply<A8>(outArgs);
+ appendNewArgForReply<A9>(outArgs);
+ g_ptr_array_add(outArgs, NULL);
+
+ entry->name = g_strdup(name);
+ entry->in_args = (GDBusArgInfo **)g_ptr_array_free(inArgs, FALSE);
+ entry->out_args = (GDBusArgInfo **)g_ptr_array_free(outArgs, FALSE);
+
+ entry->ref_count = 1;
return entry;
}
};
@@ -2399,8 +2510,8 @@ struct MakeMethodEntry< boost::function<R (A1, A2, A3, A4, A5, A6, A7, A8)> >
static const bool asynchronous = DBusResult8<A1, A2, A3, A4, A5, A6, A7, A8>::asynchronous;
- static DBusMessage *methodFunction(DBusConnection *conn,
- DBusMessage *msg, void *data)
+ static GDBusMessage *methodFunction(GDBusConnection *conn,
+ GDBusMessage *msg, void *data)
{
try {
typename dbus_traits<R>::host_type r;
@@ -2413,7 +2524,8 @@ struct MakeMethodEntry< boost::function<R (A1, A2, A3, A4, A5, A6, A7, A8)> >
typename dbus_traits<A7>::host_type a7;
typename dbus_traits<A8>::host_type a8;
- ExtractArgs(conn, msg) >> Get<A1>(a1) >> Get<A2>(a2) >> Get<A3>(a3) >> Get<A4>(a4) >> Get<A5>(a5) >> Get<A6>(a6) >> Get<A7>(a7) >> Get<A8>(a8);
+ ExtractArgs(conn, msg) >> Get<A1>(a1) >> Get<A2>(a2) >> Get<A3>(a3) >> Get<A4>(a4) >>
+ Get<A5>(a5) >> Get<A6>(a6) >> Get<A7>(a7) >> Get<A8>(a8);
r = (*static_cast<M *>(data))(a1, a2, a3, a4, a5, a6, a7, a8);
@@ -2421,11 +2533,12 @@ struct MakeMethodEntry< boost::function<R (A1, A2, A3, A4, A5, A6, A7, A8)> >
return NULL;
}
- DBusMessage *reply = dbus_message_new_method_return(msg);
+ GDBusMessage *reply = g_dbus_message_new_method_reply(msg);
if (!reply)
return NULL;
- AppendArgs(reply) + r << Set<A1>(a1) << Set<A2>(a2) << Set<A3>(a3) << Set<A4>(a4) << Set<A5>(a5) << Set<A6>(a6) << Set<A7>(a7) << Set<A8>(a8);
+ AppendArgs(reply) + r << Set<A1>(a1) << Set<A2>(a2) << Set<A3>(a3) << Set<A4>(a4)
+ << Set<A5>(a5) << Set<A6>(a6) << Set<A7>(a7) << Set<A8>(a8);
return reply;
} catch (...) {
@@ -2433,42 +2546,37 @@ struct MakeMethodEntry< boost::function<R (A1, A2, A3, A4, A5, A6, A7, A8)> >
}
}
- static void destroyFunction(void *user_data)
- {
- BDBusMethodTable *entry = static_cast<BDBusMethodTable *>(user_data);
- delete static_cast<M *>(entry->method_data);
- }
-
- static BDBusMethodTable make(const char *name, BDBusMethodFlags flags, const M &m)
- {
- BDBusMethodTable entry;
- entry.name = strdup(name);
- std::string buffer;
- buffer += dbus_traits<A1>::getSignature();
- buffer += dbus_traits<A2>::getSignature();
- buffer += dbus_traits<A3>::getSignature();
- buffer += dbus_traits<A4>::getSignature();
- buffer += dbus_traits<A5>::getSignature();
- buffer += dbus_traits<A6>::getSignature();
- buffer += dbus_traits<A7>::getSignature();
- buffer += dbus_traits<A8>::getSignature();
- entry.signature = strdup(buffer.c_str());
- buffer.clear();
- buffer += dbus_traits<R>::getReply();
- buffer += dbus_traits<A1>::getReply();
- buffer += dbus_traits<A2>::getReply();
- buffer += dbus_traits<A3>::getReply();
- buffer += dbus_traits<A4>::getReply();
- buffer += dbus_traits<A5>::getReply();
- buffer += dbus_traits<A6>::getReply();
- buffer += dbus_traits<A7>::getReply();
- buffer += dbus_traits<A8>::getReply();
- entry.reply = strdup(buffer.c_str());
- entry.function = methodFunction;
- entry.destroy = destroyFunction;
- entry.flags = BDBusMethodFlags(flags | G_DBUS_METHOD_FLAG_METHOD_DATA |
- (asynchronous ? G_DBUS_METHOD_FLAG_ASYNC : 0));
- entry.method_data = new M(m);
+ static GDBusMethodInfo *make(const char *name)
+ {
+ GDBusMethodInfo *entry = g_new0(GDBusMethodInfo, 1);
+
+ GPtrArray *inArgs = g_ptr_array_new();
+ appendNewArg<A1>(inArgs);
+ appendNewArg<A2>(inArgs);
+ appendNewArg<A3>(inArgs);
+ appendNewArg<A4>(inArgs);
+ appendNewArg<A5>(inArgs);
+ appendNewArg<A6>(inArgs);
+ appendNewArg<A7>(inArgs);
+ appendNewArg<A8>(inArgs);
+ g_ptr_array_add(inArgs, NULL);
+
+ GPtrArray *outArgs = g_ptr_array_new();
+ appendNewArgForReply<A1>(outArgs);
+ appendNewArgForReply<A2>(outArgs);
+ appendNewArgForReply<A3>(outArgs);
+ appendNewArgForReply<A4>(outArgs);
+ appendNewArgForReply<A5>(outArgs);
+ appendNewArgForReply<A6>(outArgs);
+ appendNewArgForReply<A7>(outArgs);
+ appendNewArgForReply<A8>(outArgs);
+ g_ptr_array_add(outArgs, NULL);
+
+ entry->name = g_strdup(name);
+ entry->in_args = (GDBusArgInfo **)g_ptr_array_free(inArgs, FALSE);
+ entry->out_args = (GDBusArgInfo **)g_ptr_array_free(outArgs, FALSE);
+
+ entry->ref_count = 1;
return entry;
}
};
@@ -2487,8 +2595,8 @@ struct MakeMethodEntry< boost::function<void (A1, A2, A3, A4, A5, A6, A7, A8)> >
static const bool asynchronous = DBusResult8<A1, A2, A3, A4, A5, A6, A7, A8>::asynchronous;
- static DBusMessage *methodFunction(DBusConnection *conn,
- DBusMessage *msg, void *data)
+ static GDBusMessage *methodFunction(GDBusConnection *conn,
+ GDBusMessage *msg, void *data)
{
try {
typename dbus_traits<A1>::host_type a1;
@@ -2500,7 +2608,8 @@ struct MakeMethodEntry< boost::function<void (A1, A2, A3, A4, A5, A6, A7, A8)> >
typename dbus_traits<A7>::host_type a7;
typename dbus_traits<A8>::host_type a8;
- ExtractArgs(conn, msg) >> Get<A1>(a1) >> Get<A2>(a2) >> Get<A3>(a3) >> Get<A4>(a4) >> Get<A5>(a5) >> Get<A6>(a6) >> Get<A7>(a7) >> Get<A8>(a8);
+ ExtractArgs(conn, msg) >> Get<A1>(a1) >> Get<A2>(a2) >> Get<A3>(a3) >> Get<A4>(a4)
+ >> Get<A5>(a5) >> Get<A6>(a6) >> Get<A7>(a7) >> Get<A8>(a8);
(*static_cast<M *>(data))(a1, a2, a3, a4, a5, a6, a7, a8);
@@ -2508,11 +2617,12 @@ struct MakeMethodEntry< boost::function<void (A1, A2, A3, A4, A5, A6, A7, A8)> >
return NULL;
}
- DBusMessage *reply = dbus_message_new_method_return(msg);
+ GDBusMessage *reply = g_dbus_message_new_method_reply(msg);
if (!reply)
return NULL;
- AppendArgs(reply) << Set<A1>(a1) << Set<A2>(a2) << Set<A3>(a3) << Set<A4>(a4) << Set<A5>(a5) << Set<A6>(a6) << Set<A7>(a7) << Set<A8>(a8);
+ AppendArgs(reply) << Set<A1>(a1) << Set<A2>(a2) << Set<A3>(a3) << Set<A4>(a4)
+ << Set<A5>(a5) << Set<A6>(a6) << Set<A7>(a7) << Set<A8>(a8);
return reply;
} catch (...) {
@@ -2520,41 +2630,37 @@ struct MakeMethodEntry< boost::function<void (A1, A2, A3, A4, A5, A6, A7, A8)> >
}
}
- static void destroyFunction(void *user_data)
- {
- BDBusMethodTable *entry = static_cast<BDBusMethodTable *>(user_data);
- delete static_cast<M *>(entry->method_data);
- }
-
- static BDBusMethodTable make(const char *name, BDBusMethodFlags flags, const M &m)
- {
- BDBusMethodTable entry;
- entry.name = strdup(name);
- std::string buffer;
- buffer += dbus_traits<A1>::getSignature();
- buffer += dbus_traits<A2>::getSignature();
- buffer += dbus_traits<A3>::getSignature();
- buffer += dbus_traits<A4>::getSignature();
- buffer += dbus_traits<A5>::getSignature();
- buffer += dbus_traits<A6>::getSignature();
- buffer += dbus_traits<A7>::getSignature();
- buffer += dbus_traits<A8>::getSignature();
- entry.signature = strdup(buffer.c_str());
- buffer.clear();
- buffer += dbus_traits<A1>::getReply();
- buffer += dbus_traits<A2>::getReply();
- buffer += dbus_traits<A3>::getReply();
- buffer += dbus_traits<A4>::getReply();
- buffer += dbus_traits<A5>::getReply();
- buffer += dbus_traits<A6>::getReply();
- buffer += dbus_traits<A7>::getReply();
- buffer += dbus_traits<A8>::getReply();
- entry.reply = strdup(buffer.c_str());
- entry.function = methodFunction;
- entry.destroy = destroyFunction;
- entry.flags = BDBusMethodFlags(flags | G_DBUS_METHOD_FLAG_METHOD_DATA |
- (asynchronous ? G_DBUS_METHOD_FLAG_ASYNC : 0));
- entry.method_data = new M(m);
+ static GDBusMethodInfo *make(const char *name)
+ {
+ GDBusMethodInfo *entry = g_new0(GDBusMethodInfo, 1);
+
+ GPtrArray *inArgs = g_ptr_array_new();
+ appendNewArg<A1>(inArgs);
+ appendNewArg<A2>(inArgs);
+ appendNewArg<A3>(inArgs);
+ appendNewArg<A4>(inArgs);
+ appendNewArg<A5>(inArgs);
+ appendNewArg<A6>(inArgs);
+ appendNewArg<A7>(inArgs);
+ appendNewArg<A8>(inArgs);
+ g_ptr_array_add(inArgs, NULL);
+
+ GPtrArray *outArgs = g_ptr_array_new();
+ appendNewArgForReply<A1>(outArgs);
+ appendNewArgForReply<A2>(outArgs);
+ appendNewArgForReply<A3>(outArgs);
+ appendNewArgForReply<A4>(outArgs);
+ appendNewArgForReply<A5>(outArgs);
+ appendNewArgForReply<A6>(outArgs);
+ appendNewArgForReply<A7>(outArgs);
+ appendNewArgForReply<A8>(outArgs);
+ g_ptr_array_add(outArgs, NULL);
+
+ entry->name = g_strdup(name);
+ entry->in_args = (GDBusArgInfo **)g_ptr_array_free(inArgs, FALSE);
+ entry->out_args = (GDBusArgInfo **)g_ptr_array_free(outArgs, FALSE);
+
+ entry->ref_count = 1;
return entry;
}
};
@@ -2574,8 +2680,8 @@ struct MakeMethodEntry< boost::function<R (A1, A2, A3, A4, A5, A6, A7)> >
static const bool asynchronous = DBusResult7<A1, A2, A3, A4, A5, A6, A7>::asynchronous;
- static DBusMessage *methodFunction(DBusConnection *conn,
- DBusMessage *msg, void *data)
+ static GDBusMessage *methodFunction(GDBusConnection *conn,
+ GDBusMessage *msg, void *data)
{
try {
typename dbus_traits<R>::host_type r;
@@ -2587,7 +2693,8 @@ struct MakeMethodEntry< boost::function<R (A1, A2, A3, A4, A5, A6, A7)> >
typename dbus_traits<A6>::host_type a6;
typename dbus_traits<A7>::host_type a7;
- ExtractArgs(conn, msg) >> Get<A1>(a1) >> Get<A2>(a2) >> Get<A3>(a3) >> Get<A4>(a4) >> Get<A5>(a5) >> Get<A6>(a6) >> Get<A7>(a7);
+ ExtractArgs(conn, msg) >> Get<A1>(a1) >> Get<A2>(a2) >> Get<A3>(a3) >> Get<A4>(a4)
+ >> Get<A5>(a5) >> Get<A6>(a6) >> Get<A7>(a7);
r = (*static_cast<M *>(data))(a1, a2, a3, a4, a5, a6, a7);
@@ -2595,11 +2702,12 @@ struct MakeMethodEntry< boost::function<R (A1, A2, A3, A4, A5, A6, A7)> >
return NULL;
}
- DBusMessage *reply = dbus_message_new_method_return(msg);
+ GDBusMessage *reply = g_dbus_message_new_method_reply(msg);
if (!reply)
return NULL;
- AppendArgs(reply) + r << Set<A1>(a1) << Set<A2>(a2) << Set<A3>(a3) << Set<A4>(a4) << Set<A5>(a5) << Set<A6>(a6) << Set<A7>(a7);
+ AppendArgs(reply) + r << Set<A1>(a1) << Set<A2>(a2) << Set<A3>(a3) << Set<A4>(a4)
+ << Set<A5>(a5) << Set<A6>(a6) << Set<A7>(a7);
return reply;
} catch (...) {
@@ -2607,40 +2715,35 @@ struct MakeMethodEntry< boost::function<R (A1, A2, A3, A4, A5, A6, A7)> >
}
}
- static void destroyFunction(void *user_data)
- {
- BDBusMethodTable *entry = static_cast<BDBusMethodTable *>(user_data);
- delete static_cast<M *>(entry->method_data);
- }
-
- static BDBusMethodTable make(const char *name, BDBusMethodFlags flags, const M &m)
- {
- BDBusMethodTable entry;
- entry.name = strdup(name);
- std::string buffer;
- buffer += dbus_traits<A1>::getSignature();
- buffer += dbus_traits<A2>::getSignature();
- buffer += dbus_traits<A3>::getSignature();
- buffer += dbus_traits<A4>::getSignature();
- buffer += dbus_traits<A5>::getSignature();
- buffer += dbus_traits<A6>::getSignature();
- buffer += dbus_traits<A7>::getSignature();
- entry.signature = strdup(buffer.c_str());
- buffer.clear();
- buffer += dbus_traits<R>::getReply();
- buffer += dbus_traits<A1>::getReply();
- buffer += dbus_traits<A2>::getReply();
- buffer += dbus_traits<A3>::getReply();
- buffer += dbus_traits<A4>::getReply();
- buffer += dbus_traits<A5>::getReply();
- buffer += dbus_traits<A6>::getReply();
- buffer += dbus_traits<A7>::getReply();
- entry.reply = strdup(buffer.c_str());
- entry.function = methodFunction;
- entry.destroy = destroyFunction;
- entry.flags = BDBusMethodFlags(flags | G_DBUS_METHOD_FLAG_METHOD_DATA |
- (asynchronous ? G_DBUS_METHOD_FLAG_ASYNC : 0));
- entry.method_data = new M(m);
+ static GDBusMethodInfo *make(const char *name)
+ {
+ GDBusMethodInfo *entry = g_new0(GDBusMethodInfo, 1);
+
+ GPtrArray *inArgs = g_ptr_array_new();
+ appendNewArg<A1>(inArgs);
+ appendNewArg<A2>(inArgs);
+ appendNewArg<A3>(inArgs);
+ appendNewArg<A4>(inArgs);
+ appendNewArg<A5>(inArgs);
+ appendNewArg<A6>(inArgs);
+ appendNewArg<A7>(inArgs);
+ g_ptr_array_add(inArgs, NULL);
+
+ GPtrArray *outArgs = g_ptr_array_new();
+ appendNewArgForReply<A1>(outArgs);
+ appendNewArgForReply<A2>(outArgs);
+ appendNewArgForReply<A3>(outArgs);
+ appendNewArgForReply<A4>(outArgs);
+ appendNewArgForReply<A5>(outArgs);
+ appendNewArgForReply<A6>(outArgs);
+ appendNewArgForReply<A7>(outArgs);
+ g_ptr_array_add(outArgs, NULL);
+
+ entry->name = g_strdup(name);
+ entry->in_args = (GDBusArgInfo **)g_ptr_array_free(inArgs, FALSE);
+ entry->out_args = (GDBusArgInfo **)g_ptr_array_free(outArgs, FALSE);
+
+ entry->ref_count = 1;
return entry;
}
};
@@ -2659,8 +2762,8 @@ struct MakeMethodEntry< boost::function<void (A1, A2, A3, A4, A5, A6, A7)> >
static const bool asynchronous = DBusResult7<A1, A2, A3, A4, A5, A6, A7>::asynchronous;
- static DBusMessage *methodFunction(DBusConnection *conn,
- DBusMessage *msg, void *data)
+ static GDBusMessage *methodFunction(GDBusConnection *conn,
+ GDBusMessage *msg, void *data)
{
try {
typename dbus_traits<A1>::host_type a1;
@@ -2671,7 +2774,8 @@ struct MakeMethodEntry< boost::function<void (A1, A2, A3, A4, A5, A6, A7)> >
typename dbus_traits<A6>::host_type a6;
typename dbus_traits<A7>::host_type a7;
- ExtractArgs(conn, msg) >> Get<A1>(a1) >> Get<A2>(a2) >> Get<A3>(a3) >> Get<A4>(a4) >> Get<A5>(a5) >> Get<A6>(a6) >> Get<A7>(a7);
+ ExtractArgs(conn, msg) >> Get<A1>(a1) >> Get<A2>(a2) >> Get<A3>(a3) >> Get<A4>(a4)
+ >> Get<A5>(a5) >> Get<A6>(a6) >> Get<A7>(a7);
(*static_cast<M *>(data))(a1, a2, a3, a4, a5, a6, a7);
@@ -2679,11 +2783,12 @@ struct MakeMethodEntry< boost::function<void (A1, A2, A3, A4, A5, A6, A7)> >
return NULL;
}
- DBusMessage *reply = dbus_message_new_method_return(msg);
+ GDBusMessage *reply = g_dbus_message_new_method_reply(msg);
if (!reply)
return NULL;
- AppendArgs(reply) << Set<A1>(a1) << Set<A2>(a2) << Set<A3>(a3) << Set<A4>(a4) << Set<A5>(a5) << Set<A6>(a6) << Set<A7>(a7);
+ AppendArgs(reply) << Set<A1>(a1) << Set<A2>(a2) << Set<A3>(a3) << Set<A4>(a4)
+ << Set<A5>(a5) << Set<A6>(a6) << Set<A7>(a7);
return reply;
} catch (...) {
@@ -2691,39 +2796,35 @@ struct MakeMethodEntry< boost::function<void (A1, A2, A3, A4, A5, A6, A7)> >
}
}
- static void destroyFunction(void *user_data)
- {
- BDBusMethodTable *entry = static_cast<BDBusMethodTable *>(user_data);
- delete static_cast<M *>(entry->method_data);
- }
-
- static BDBusMethodTable make(const char *name, BDBusMethodFlags flags, const M &m)
- {
- BDBusMethodTable entry;
- entry.name = strdup(name);
- std::string buffer;
- buffer += dbus_traits<A1>::getSignature();
- buffer += dbus_traits<A2>::getSignature();
- buffer += dbus_traits<A3>::getSignature();
- buffer += dbus_traits<A4>::getSignature();
- buffer += dbus_traits<A5>::getSignature();
- buffer += dbus_traits<A6>::getSignature();
- buffer += dbus_traits<A7>::getSignature();
- entry.signature = strdup(buffer.c_str());
- buffer.clear();
- buffer += dbus_traits<A1>::getReply();
- buffer += dbus_traits<A2>::getReply();
- buffer += dbus_traits<A3>::getReply();
- buffer += dbus_traits<A4>::getReply();
- buffer += dbus_traits<A5>::getReply();
- buffer += dbus_traits<A6>::getReply();
- buffer += dbus_traits<A7>::getReply();
- entry.reply = strdup(buffer.c_str());
- entry.function = methodFunction;
- entry.destroy = destroyFunction;
- entry.flags = BDBusMethodFlags(flags | G_DBUS_METHOD_FLAG_METHOD_DATA |
- (asynchronous ? G_DBUS_METHOD_FLAG_ASYNC : 0));
- entry.method_data = new M(m);
+ static GDBusMethodInfo *make(const char *name)
+ {
+ GDBusMethodInfo *entry = g_new0(GDBusMethodInfo, 1);
+
+ GPtrArray *inArgs = g_ptr_array_new();
+ appendNewArg<A1>(inArgs);
+ appendNewArg<A2>(inArgs);
+ appendNewArg<A3>(inArgs);
+ appendNewArg<A4>(inArgs);
+ appendNewArg<A5>(inArgs);
+ appendNewArg<A6>(inArgs);
+ appendNewArg<A7>(inArgs);
+ g_ptr_array_add(inArgs, NULL);
+
+ GPtrArray *outArgs = g_ptr_array_new();
+ appendNewArgForReply<A1>(outArgs);
+ appendNewArgForReply<A2>(outArgs);
+ appendNewArgForReply<A3>(outArgs);
+ appendNewArgForReply<A4>(outArgs);
+ appendNewArgForReply<A5>(outArgs);
+ appendNewArgForReply<A6>(outArgs);
+ appendNewArgForReply<A7>(outArgs);
+ g_ptr_array_add(outArgs, NULL);
+
+ entry->name = g_strdup(name);
+ entry->in_args = (GDBusArgInfo **)g_ptr_array_free(inArgs, FALSE);
+ entry->out_args = (GDBusArgInfo **)g_ptr_array_free(outArgs, FALSE);
+
+ entry->ref_count = 1;
return entry;
}
};
@@ -2743,8 +2844,8 @@ struct MakeMethodEntry< boost::function<R (A1, A2, A3, A4, A5, A6)> >
static const bool asynchronous = DBusResult6<A1, A2, A3, A4, A5, A6>::asynchronous;
- static DBusMessage *methodFunction(DBusConnection *conn,
- DBusMessage *msg, void *data)
+ static GDBusMessage *methodFunction(GDBusConnection *conn,
+ GDBusMessage *msg, void *data)
{
try {
typename dbus_traits<R>::host_type r;
@@ -2755,7 +2856,8 @@ struct MakeMethodEntry< boost::function<R (A1, A2, A3, A4, A5, A6)> >
typename dbus_traits<A5>::host_type a5;
typename dbus_traits<A6>::host_type a6;
- ExtractArgs(conn, msg) >> Get<A1>(a1) >> Get<A2>(a2) >> Get<A3>(a3) >> Get<A4>(a4) >> Get<A5>(a5) >> Get<A6>(a6);
+ ExtractArgs(conn, msg) >> Get<A1>(a1) >> Get<A2>(a2) >> Get<A3>(a3)
+ >> Get<A4>(a4) >> Get<A5>(a5) >> Get<A6>(a6);
r = (*static_cast<M *>(data))(a1, a2, a3, a4, a5, a6);
@@ -2763,11 +2865,12 @@ struct MakeMethodEntry< boost::function<R (A1, A2, A3, A4, A5, A6)> >
return NULL;
}
- DBusMessage *reply = dbus_message_new_method_return(msg);
+ GDBusMessage *reply = g_dbus_message_new_method_reply(msg);
if (!reply)
return NULL;
- AppendArgs(reply) + r << Set<A1>(a1) << Set<A2>(a2) << Set<A3>(a3) << Set<A4>(a4) << Set<A5>(a5) << Set<A6>(a6);
+ AppendArgs(reply) + r << Set<A1>(a1) << Set<A2>(a2) << Set<A3>(a3)
+ << Set<A4>(a4) << Set<A5>(a5) << Set<A6>(a6);
return reply;
} catch (...) {
@@ -2775,38 +2878,33 @@ struct MakeMethodEntry< boost::function<R (A1, A2, A3, A4, A5, A6)> >
}
}
- static void destroyFunction(void *user_data)
- {
- BDBusMethodTable *entry = static_cast<BDBusMethodTable *>(user_data);
- delete static_cast<M *>(entry->method_data);
- }
-
- static BDBusMethodTable make(const char *name, BDBusMethodFlags flags, const M &m)
- {
- BDBusMethodTable entry;
- entry.name = strdup(name);
- std::string buffer;
- buffer += dbus_traits<A1>::getSignature();
- buffer += dbus_traits<A2>::getSignature();
- buffer += dbus_traits<A3>::getSignature();
- buffer += dbus_traits<A4>::getSignature();
- buffer += dbus_traits<A5>::getSignature();
- buffer += dbus_traits<A6>::getSignature();
- entry.signature = strdup(buffer.c_str());
- buffer.clear();
- buffer += dbus_traits<R>::getReply();
- buffer += dbus_traits<A1>::getReply();
- buffer += dbus_traits<A2>::getReply();
- buffer += dbus_traits<A3>::getReply();
- buffer += dbus_traits<A4>::getReply();
- buffer += dbus_traits<A5>::getReply();
- buffer += dbus_traits<A6>::getReply();
- entry.reply = strdup(buffer.c_str());
- entry.function = methodFunction;
- entry.destroy = destroyFunction;
- entry.flags = BDBusMethodFlags(flags | G_DBUS_METHOD_FLAG_METHOD_DATA |
- (asynchronous ? G_DBUS_METHOD_FLAG_ASYNC : 0));
- entry.method_data = new M(m);
+ static GDBusMethodInfo *make(const char *name)
+ {
+ GDBusMethodInfo *entry = g_new0(GDBusMethodInfo, 1);
+
+ GPtrArray *inArgs = g_ptr_array_new();
+ appendNewArg<A1>(inArgs);
+ appendNewArg<A2>(inArgs);
+ appendNewArg<A3>(inArgs);
+ appendNewArg<A4>(inArgs);
+ appendNewArg<A5>(inArgs);
+ appendNewArg<A6>(inArgs);
+ g_ptr_array_add(inArgs, NULL);
+
+ GPtrArray *outArgs = g_ptr_array_new();
+ appendNewArgForReply<A1>(outArgs);
+ appendNewArgForReply<A2>(outArgs);
+ appendNewArgForReply<A3>(outArgs);
+ appendNewArgForReply<A4>(outArgs);
+ appendNewArgForReply<A5>(outArgs);
+ appendNewArgForReply<A6>(outArgs);
+ g_ptr_array_add(outArgs, NULL);
+
+ entry->name = g_strdup(name);
+ entry->in_args = (GDBusArgInfo **)g_ptr_array_free(inArgs, FALSE);
+ entry->out_args = (GDBusArgInfo **)g_ptr_array_free(outArgs, FALSE);
+
+ entry->ref_count = 1;
return entry;
}
};
@@ -2825,8 +2923,8 @@ struct MakeMethodEntry< boost::function<void (A1, A2, A3, A4, A5, A6)> >
static const bool asynchronous = DBusResult6<A1, A2, A3, A4, A5, A6>::asynchronous;
- static DBusMessage *methodFunction(DBusConnection *conn,
- DBusMessage *msg, void *data)
+ static GDBusMessage *methodFunction(GDBusConnection *conn,
+ GDBusMessage *msg, void *data)
{
try {
typename dbus_traits<A1>::host_type a1;
@@ -2836,7 +2934,8 @@ struct MakeMethodEntry< boost::function<void (A1, A2, A3, A4, A5, A6)> >
typename dbus_traits<A5>::host_type a5;
typename dbus_traits<A6>::host_type a6;
- ExtractArgs(conn, msg) >> Get<A1>(a1) >> Get<A2>(a2) >> Get<A3>(a3) >> Get<A4>(a4) >> Get<A5>(a5) >> Get<A6>(a6);
+ ExtractArgs(conn, msg) >> Get<A1>(a1) >> Get<A2>(a2) >> Get<A3>(a3)
+ >> Get<A4>(a4) >> Get<A5>(a5) >> Get<A6>(a6);
(*static_cast<M *>(data))(a1, a2, a3, a4, a5, a6);
@@ -2844,48 +2943,46 @@ struct MakeMethodEntry< boost::function<void (A1, A2, A3, A4, A5, A6)> >
return NULL;
}
- DBusMessage *reply = dbus_message_new_method_return(msg);
+ GDBusMessage *reply = g_dbus_message_new_method_reply(msg);
if (!reply)
return NULL;
- AppendArgs(reply) << Set<A1>(a1) << Set<A2>(a2) << Set<A3>(a3) << Set<A4>(a4) << Set<A5>(a5) << Set<A6>(a6);
+ AppendArgs(reply) << Set<A1>(a1) << Set<A2>(a2) << Set<A3>(a3)
+ << Set<A4>(a4) << Set<A5>(a5) << Set<A6>(a6);
return reply;
} catch (...) {
return handleException(msg);
}
}
- static void destroyFunction(void *user_data)
- {
- BDBusMethodTable *entry = static_cast<BDBusMethodTable *>(user_data);
- delete static_cast<M *>(entry->method_data);
- }
-
- static BDBusMethodTable make(const char *name, BDBusMethodFlags flags, const M &m)
- {
- BDBusMethodTable entry;
- entry.name = strdup(name);
- std::string buffer;
- buffer += dbus_traits<A1>::getSignature();
- buffer += dbus_traits<A2>::getSignature();
- buffer += dbus_traits<A3>::getSignature();
- buffer += dbus_traits<A4>::getSignature();
- buffer += dbus_traits<A5>::getSignature();
- buffer += dbus_traits<A6>::getSignature();
- entry.signature = strdup(buffer.c_str());
- buffer.clear();
- buffer += dbus_traits<A1>::getReply();
- buffer += dbus_traits<A2>::getReply();
- buffer += dbus_traits<A3>::getReply();
- buffer += dbus_traits<A4>::getReply();
- buffer += dbus_traits<A5>::getReply();
- buffer += dbus_traits<A6>::getReply();
- entry.reply = strdup(buffer.c_str());
- entry.function = methodFunction;
- entry.destroy = destroyFunction;
- entry.flags = BDBusMethodFlags(flags | G_DBUS_METHOD_FLAG_METHOD_DATA |
- (asynchronous ? G_DBUS_METHOD_FLAG_ASYNC : 0));
- entry.method_data = new M(m);
+
+ static GDBusMethodInfo *make(const char *name)
+ {
+ GDBusMethodInfo *entry = g_new0(GDBusMethodInfo, 1);
+
+ GPtrArray *inArgs = g_ptr_array_new();
+ appendNewArg<A1>(inArgs);
+ appendNewArg<A2>(inArgs);
+ appendNewArg<A3>(inArgs);
+ appendNewArg<A4>(inArgs);
+ appendNewArg<A5>(inArgs);
+ appendNewArg<A6>(inArgs);
+ g_ptr_array_add(inArgs, NULL);
+
+ GPtrArray *outArgs = g_ptr_array_new();
+ appendNewArgForReply<A1>(outArgs);
+ appendNewArgForReply<A2>(outArgs);
+ appendNewArgForReply<A3>(outArgs);
+ appendNewArgForReply<A4>(outArgs);
+ appendNewArgForReply<A5>(outArgs);
+ appendNewArgForReply<A6>(outArgs);
+ g_ptr_array_add(outArgs, NULL);
+
+ entry->name = g_strdup(name);
+ entry->in_args = (GDBusArgInfo **)g_ptr_array_free(inArgs, FALSE);
+ entry->out_args = (GDBusArgInfo **)g_ptr_array_free(outArgs, FALSE);
+
+ entry->ref_count = 1;
return entry;
}
};
@@ -2904,8 +3001,8 @@ struct MakeMethodEntry< boost::function<R (A1, A2, A3, A4, A5)> >
static const bool asynchronous = DBusResult5<A1, A2, A3, A4, A5>::asynchronous;
- static DBusMessage *methodFunction(DBusConnection *conn,
- DBusMessage *msg, void *data)
+ static GDBusMessage *methodFunction(GDBusConnection *conn,
+ GDBusMessage *msg, void *data)
{
try {
typename dbus_traits<R>::host_type r;
@@ -2915,7 +3012,8 @@ struct MakeMethodEntry< boost::function<R (A1, A2, A3, A4, A5)> >
typename dbus_traits<A4>::host_type a4;
typename dbus_traits<A5>::host_type a5;
- ExtractArgs(conn, msg) >> Get<A1>(a1) >> Get<A2>(a2) >> Get<A3>(a3) >> Get<A4>(a4) >> Get<A5>(a5);
+ ExtractArgs(conn, msg) >> Get<A1>(a1) >> Get<A2>(a2) >> Get<A3>(a3)
+ >> Get<A4>(a4) >> Get<A5>(a5);
r = (*static_cast<M *>(data))(a1, a2, a3, a4, a5);
@@ -2923,11 +3021,12 @@ struct MakeMethodEntry< boost::function<R (A1, A2, A3, A4, A5)> >
return NULL;
}
- DBusMessage *reply = dbus_message_new_method_return(msg);
+ GDBusMessage *reply = g_dbus_message_new_method_reply(msg);
if (!reply)
return NULL;
- AppendArgs(reply) + r << Set<A1>(a1) << Set<A2>(a2) << Set<A3>(a3) << Set<A4>(a4) << Set<A5>(a5);
+ AppendArgs(reply) + r << Set<A1>(a1) << Set<A2>(a2) << Set<A3>(a3)
+ << Set<A4>(a4) << Set<A5>(a5);
return reply;
} catch (...) {
@@ -2935,36 +3034,31 @@ struct MakeMethodEntry< boost::function<R (A1, A2, A3, A4, A5)> >
}
}
- static void destroyFunction(void *user_data)
- {
- BDBusMethodTable *entry = static_cast<BDBusMethodTable *>(user_data);
- delete static_cast<M *>(entry->method_data);
- }
-
- static BDBusMethodTable make(const char *name, BDBusMethodFlags flags, const M &m)
- {
- BDBusMethodTable entry;
- entry.name = strdup(name);
- std::string buffer;
- buffer += dbus_traits<A1>::getSignature();
- buffer += dbus_traits<A2>::getSignature();
- buffer += dbus_traits<A3>::getSignature();
- buffer += dbus_traits<A4>::getSignature();
- buffer += dbus_traits<A5>::getSignature();
- entry.signature = strdup(buffer.c_str());
- buffer.clear();
- buffer += dbus_traits<R>::getReply();
- buffer += dbus_traits<A1>::getReply();
- buffer += dbus_traits<A2>::getReply();
- buffer += dbus_traits<A3>::getReply();
- buffer += dbus_traits<A4>::getReply();
- buffer += dbus_traits<A5>::getReply();
- entry.reply = strdup(buffer.c_str());
- entry.function = methodFunction;
- entry.destroy = destroyFunction;
- entry.flags = BDBusMethodFlags(flags | G_DBUS_METHOD_FLAG_METHOD_DATA |
- (asynchronous ? G_DBUS_METHOD_FLAG_ASYNC : 0));
- entry.method_data = new M(m);
+ static GDBusMethodInfo *make(const char *name)
+ {
+ GDBusMethodInfo *entry = g_new0(GDBusMethodInfo, 1);
+
+ GPtrArray *inArgs = g_ptr_array_new();
+ appendNewArg<A1>(inArgs);
+ appendNewArg<A2>(inArgs);
+ appendNewArg<A3>(inArgs);
+ appendNewArg<A4>(inArgs);
+ appendNewArg<A5>(inArgs);
+ g_ptr_array_add(inArgs, NULL);
+
+ GPtrArray *outArgs = g_ptr_array_new();
+ appendNewArgForReply<A1>(outArgs);
+ appendNewArgForReply<A2>(outArgs);
+ appendNewArgForReply<A3>(outArgs);
+ appendNewArgForReply<A4>(outArgs);
+ appendNewArgForReply<A5>(outArgs);
+ g_ptr_array_add(outArgs, NULL);
+
+ entry->name = g_strdup(name);
+ entry->in_args = (GDBusArgInfo **)g_ptr_array_free(inArgs, FALSE);
+ entry->out_args = (GDBusArgInfo **)g_ptr_array_free(outArgs, FALSE);
+
+ entry->ref_count = 1;
return entry;
}
};
@@ -2982,8 +3076,8 @@ struct MakeMethodEntry< boost::function<void (A1, A2, A3, A4, A5)> >
static const bool asynchronous = DBusResult5<A1, A2, A3, A4, A5>::asynchronous;
- static DBusMessage *methodFunction(DBusConnection *conn,
- DBusMessage *msg, void *data)
+ static GDBusMessage *methodFunction(GDBusConnection *conn,
+ GDBusMessage *msg, void *data)
{
try {
typename dbus_traits<A1>::host_type a1;
@@ -2992,7 +3086,8 @@ struct MakeMethodEntry< boost::function<void (A1, A2, A3, A4, A5)> >
typename dbus_traits<A4>::host_type a4;
typename dbus_traits<A5>::host_type a5;
- ExtractArgs(conn, msg) >> Get<A1>(a1) >> Get<A2>(a2) >> Get<A3>(a3) >> Get<A4>(a4) >> Get<A5>(a5);
+ ExtractArgs(conn, msg) >> Get<A1>(a1) >> Get<A2>(a2) >> Get<A3>(a3)
+ >> Get<A4>(a4) >> Get<A5>(a5);
(*static_cast<M *>(data))(a1, a2, a3, a4, a5);
@@ -3000,11 +3095,12 @@ struct MakeMethodEntry< boost::function<void (A1, A2, A3, A4, A5)> >
return NULL;
}
- DBusMessage *reply = dbus_message_new_method_return(msg);
+ GDBusMessage *reply = g_dbus_message_new_method_reply(msg);
if (!reply)
return NULL;
- AppendArgs(reply) << Set<A1>(a1) << Set<A2>(a2) << Set<A3>(a3) << Set<A4>(a4) << Set<A5>(a5);
+ AppendArgs(reply) << Set<A1>(a1) << Set<A2>(a2) << Set<A3>(a3)
+ << Set<A4>(a4) << Set<A5>(a5);
return reply;
} catch (...) {
@@ -3012,35 +3108,31 @@ struct MakeMethodEntry< boost::function<void (A1, A2, A3, A4, A5)> >
}
}
- static void destroyFunction(void *user_data)
- {
- BDBusMethodTable *entry = static_cast<BDBusMethodTable *>(user_data);
- delete static_cast<M *>(entry->method_data);
- }
-
- static BDBusMethodTable make(const char *name, BDBusMethodFlags flags, const M &m)
- {
- BDBusMethodTable entry;
- entry.name = strdup(name);
- std::string buffer;
- buffer += dbus_traits<A1>::getSignature();
- buffer += dbus_traits<A2>::getSignature();
- buffer += dbus_traits<A3>::getSignature();
- buffer += dbus_traits<A4>::getSignature();
- buffer += dbus_traits<A5>::getSignature();
- entry.signature = strdup(buffer.c_str());
- buffer.clear();
- buffer += dbus_traits<A1>::getReply();
- buffer += dbus_traits<A2>::getReply();
- buffer += dbus_traits<A3>::getReply();
- buffer += dbus_traits<A4>::getReply();
- buffer += dbus_traits<A5>::getReply();
- entry.reply = strdup(buffer.c_str());
- entry.function = methodFunction;
- entry.destroy = destroyFunction;
- entry.flags = BDBusMethodFlags(flags | G_DBUS_METHOD_FLAG_METHOD_DATA |
- (asynchronous ? G_DBUS_METHOD_FLAG_ASYNC : 0));
- entry.method_data = new M(m);
+ static GDBusMethodInfo *make(const char *name)
+ {
+ GDBusMethodInfo *entry = g_new0(GDBusMethodInfo, 1);
+
+ GPtrArray *inArgs = g_ptr_array_new();
+ appendNewArg<A1>(inArgs);
+ appendNewArg<A2>(inArgs);
+ appendNewArg<A3>(inArgs);
+ appendNewArg<A4>(inArgs);
+ appendNewArg<A5>(inArgs);
+ g_ptr_array_add(inArgs, NULL);
+
+ GPtrArray *outArgs = g_ptr_array_new();
+ appendNewArgForReply<A1>(outArgs);
+ appendNewArgForReply<A2>(outArgs);
+ appendNewArgForReply<A3>(outArgs);
+ appendNewArgForReply<A4>(outArgs);
+ appendNewArgForReply<A5>(outArgs);
+ g_ptr_array_add(outArgs, NULL);
+
+ entry->name = g_strdup(name);
+ entry->in_args = (GDBusArgInfo **)g_ptr_array_free(inArgs, FALSE);
+ entry->out_args = (GDBusArgInfo **)g_ptr_array_free(outArgs, FALSE);
+
+ entry->ref_count = 1;
return entry;
}
};
@@ -3059,8 +3151,8 @@ struct MakeMethodEntry< boost::function<R (A1, A2, A3, A4)> >
static const bool asynchronous = DBusResult4<A1, A2, A3, A4>::asynchronous;
- static DBusMessage *methodFunction(DBusConnection *conn,
- DBusMessage *msg, void *data)
+ static GDBusMessage *methodFunction(GDBusConnection *conn,
+ GDBusMessage *msg, void *data)
{
try {
typename dbus_traits<R>::host_type r;
@@ -3077,7 +3169,7 @@ struct MakeMethodEntry< boost::function<R (A1, A2, A3, A4)> >
return NULL;
}
- DBusMessage *reply = dbus_message_new_method_return(msg);
+ GDBusMessage *reply = g_dbus_message_new_method_reply(msg);
if (!reply)
return NULL;
@@ -3089,34 +3181,29 @@ struct MakeMethodEntry< boost::function<R (A1, A2, A3, A4)> >
}
}
- static void destroyFunction(void *user_data)
- {
- BDBusMethodTable *entry = static_cast<BDBusMethodTable *>(user_data);
- delete static_cast<M *>(entry->method_data);
- }
-
- static BDBusMethodTable make(const char *name, BDBusMethodFlags flags, const M &m)
- {
- BDBusMethodTable entry;
- entry.name = strdup(name);
- std::string buffer;
- buffer += dbus_traits<A1>::getSignature();
- buffer += dbus_traits<A2>::getSignature();
- buffer += dbus_traits<A3>::getSignature();
- buffer += dbus_traits<A4>::getSignature();
- entry.signature = strdup(buffer.c_str());
- buffer.clear();
- buffer += dbus_traits<R>::getReply();
- buffer += dbus_traits<A1>::getReply();
- buffer += dbus_traits<A2>::getReply();
- buffer += dbus_traits<A3>::getReply();
- buffer += dbus_traits<A4>::getReply();
- entry.reply = strdup(buffer.c_str());
- entry.function = methodFunction;
- entry.destroy = destroyFunction;
- entry.flags = BDBusMethodFlags(flags | G_DBUS_METHOD_FLAG_METHOD_DATA |
- (asynchronous ? G_DBUS_METHOD_FLAG_ASYNC : 0));
- entry.method_data = new M(m);
+ static GDBusMethodInfo *make(const char *name)
+ {
+ GDBusMethodInfo *entry = g_new0(GDBusMethodInfo, 1);
+
+ GPtrArray *inArgs = g_ptr_array_new();
+ appendNewArg<A1>(inArgs);
+ appendNewArg<A2>(inArgs);
+ appendNewArg<A3>(inArgs);
+ appendNewArg<A4>(inArgs);
+ g_ptr_array_add(inArgs, NULL);
+
+ GPtrArray *outArgs = g_ptr_array_new();
+ appendNewArgForReply<A1>(outArgs);
+ appendNewArgForReply<A2>(outArgs);
+ appendNewArgForReply<A3>(outArgs);
+ appendNewArgForReply<A4>(outArgs);
+ g_ptr_array_add(outArgs, NULL);
+
+ entry->name = g_strdup(name);
+ entry->in_args = (GDBusArgInfo **)g_ptr_array_free(inArgs, FALSE);
+ entry->out_args = (GDBusArgInfo **)g_ptr_array_free(outArgs, FALSE);
+
+ entry->ref_count = 1;
return entry;
}
};
@@ -3134,8 +3221,8 @@ struct MakeMethodEntry< boost::function<void (A1, A2, A3, A4)> >
static const bool asynchronous = DBusResult4<A1, A2, A3, A4>::asynchronous;
- static DBusMessage *methodFunction(DBusConnection *conn,
- DBusMessage *msg, void *data)
+ static GDBusMessage *methodFunction(GDBusConnection *conn,
+ GDBusMessage *msg, void *data)
{
try {
typename dbus_traits<A1>::host_type a1;
@@ -3151,7 +3238,7 @@ struct MakeMethodEntry< boost::function<void (A1, A2, A3, A4)> >
return NULL;
}
- DBusMessage *reply = dbus_message_new_method_return(msg);
+ GDBusMessage *reply = g_dbus_message_new_method_reply(msg);
if (!reply)
return NULL;
@@ -3163,33 +3250,29 @@ struct MakeMethodEntry< boost::function<void (A1, A2, A3, A4)> >
}
}
- static void destroyFunction(void *user_data)
- {
- BDBusMethodTable *entry = static_cast<BDBusMethodTable *>(user_data);
- delete static_cast<M *>(entry->method_data);
- }
-
- static BDBusMethodTable make(const char *name, BDBusMethodFlags flags, const M &m)
- {
- BDBusMethodTable entry;
- entry.name = strdup(name);
- std::string buffer;
- buffer += dbus_traits<A1>::getSignature();
- buffer += dbus_traits<A2>::getSignature();
- buffer += dbus_traits<A3>::getSignature();
- buffer += dbus_traits<A4>::getSignature();
- entry.signature = strdup(buffer.c_str());
- buffer.clear();
- buffer += dbus_traits<A1>::getReply();
- buffer += dbus_traits<A2>::getReply();
- buffer += dbus_traits<A3>::getReply();
- buffer += dbus_traits<A4>::getReply();
- entry.reply = strdup(buffer.c_str());
- entry.function = methodFunction;
- entry.destroy = destroyFunction;
- entry.flags = BDBusMethodFlags(flags | G_DBUS_METHOD_FLAG_METHOD_DATA |
- (asynchronous ? G_DBUS_METHOD_FLAG_ASYNC : 0));
- entry.method_data = new M(m);
+ static GDBusMethodInfo *make(const char *name)
+ {
+ GDBusMethodInfo *entry = g_new0(GDBusMethodInfo, 1);
+
+ GPtrArray *inArgs = g_ptr_array_new();
+ appendNewArg<A1>(inArgs);
+ appendNewArg<A2>(inArgs);
+ appendNewArg<A3>(inArgs);
+ appendNewArg<A4>(inArgs);
+ g_ptr_array_add(inArgs, NULL);
+
+ GPtrArray *outArgs = g_ptr_array_new();
+ appendNewArgForReply<A1>(outArgs);
+ appendNewArgForReply<A2>(outArgs);
+ appendNewArgForReply<A3>(outArgs);
+ appendNewArgForReply<A4>(outArgs);
+ g_ptr_array_add(outArgs, NULL);
+
+ entry->name = g_strdup(name);
+ entry->in_args = (GDBusArgInfo **)g_ptr_array_free(inArgs, FALSE);
+ entry->out_args = (GDBusArgInfo **)g_ptr_array_free(outArgs, FALSE);
+
+ entry->ref_count = 1;
return entry;
}
};
@@ -3208,8 +3291,8 @@ struct MakeMethodEntry< boost::function<R (A1, A2, A3)> >
static const bool asynchronous = DBusResult3<A1, A2, A3>::asynchronous;
- static DBusMessage *methodFunction(DBusConnection *conn,
- DBusMessage *msg, void *data)
+ static GDBusMessage *methodFunction(GDBusConnection *conn,
+ GDBusMessage *msg, void *data)
{
try {
typename dbus_traits<R>::host_type r;
@@ -3225,7 +3308,7 @@ struct MakeMethodEntry< boost::function<R (A1, A2, A3)> >
return NULL;
}
- DBusMessage *reply = dbus_message_new_method_return(msg);
+ GDBusMessage *reply = g_dbus_message_new_method_reply(msg);
if (!reply)
return NULL;
@@ -3237,32 +3320,27 @@ struct MakeMethodEntry< boost::function<R (A1, A2, A3)> >
}
}
- static void destroyFunction(void *user_data)
- {
- BDBusMethodTable *entry = static_cast<BDBusMethodTable *>(user_data);
- delete static_cast<M *>(entry->method_data);
- }
-
- static BDBusMethodTable make(const char *name, BDBusMethodFlags flags, const M &m)
- {
- BDBusMethodTable entry;
- entry.name = strdup(name);
- std::string buffer;
- buffer += dbus_traits<A1>::getSignature();
- buffer += dbus_traits<A2>::getSignature();
- buffer += dbus_traits<A3>::getSignature();
- entry.signature = strdup(buffer.c_str());
- buffer.clear();
- buffer += dbus_traits<R>::getReply();
- buffer += dbus_traits<A1>::getReply();
- buffer += dbus_traits<A2>::getReply();
- buffer += dbus_traits<A3>::getReply();
- entry.reply = strdup(buffer.c_str());
- entry.function = methodFunction;
- entry.destroy = destroyFunction;
- entry.flags = BDBusMethodFlags(flags | G_DBUS_METHOD_FLAG_METHOD_DATA |
- (asynchronous ? G_DBUS_METHOD_FLAG_ASYNC : 0));
- entry.method_data = new M(m);
+ static GDBusMethodInfo *make(const char *name)
+ {
+ GDBusMethodInfo *entry = g_new0(GDBusMethodInfo, 1);
+
+ GPtrArray *inArgs = g_ptr_array_new();
+ appendNewArg<A1>(inArgs);
+ appendNewArg<A2>(inArgs);
+ appendNewArg<A3>(inArgs);
+ g_ptr_array_add(inArgs, NULL);
+
+ GPtrArray *outArgs = g_ptr_array_new();
+ appendNewArgForReply<A1>(outArgs);
+ appendNewArgForReply<A2>(outArgs);
+ appendNewArgForReply<A3>(outArgs);
+ g_ptr_array_add(outArgs, NULL);
+
+ entry->name = g_strdup(name);
+ entry->in_args = (GDBusArgInfo **)g_ptr_array_free(inArgs, FALSE);
+ entry->out_args = (GDBusArgInfo **)g_ptr_array_free(outArgs, FALSE);
+
+ entry->ref_count = 1;
return entry;
}
};
@@ -3280,8 +3358,8 @@ struct MakeMethodEntry< boost::function<void (A1, A2, A3)> >
static const bool asynchronous = DBusResult3<A1, A2, A3>::asynchronous;
- static DBusMessage *methodFunction(DBusConnection *conn,
- DBusMessage *msg, void *data)
+ static GDBusMessage *methodFunction(GDBusConnection *conn,
+ GDBusMessage *msg, void *data)
{
try {
typename dbus_traits<A1>::host_type a1;
@@ -3296,7 +3374,7 @@ struct MakeMethodEntry< boost::function<void (A1, A2, A3)> >
return NULL;
}
- DBusMessage *reply = dbus_message_new_method_return(msg);
+ GDBusMessage *reply = g_dbus_message_new_method_reply(msg);
if (!reply)
return NULL;
@@ -3308,31 +3386,27 @@ struct MakeMethodEntry< boost::function<void (A1, A2, A3)> >
}
}
- static void destroyFunction(void *user_data)
+ static GDBusMethodInfo *make(const char *name)
{
- BDBusMethodTable *entry = static_cast<BDBusMethodTable *>(user_data);
- delete static_cast<M *>(entry->method_data);
- }
+ GDBusMethodInfo *entry = g_new0(GDBusMethodInfo, 1);
- static BDBusMethodTable make(const char *name, BDBusMethodFlags flags, const M &m)
- {
- BDBusMethodTable entry;
- entry.name = strdup(name);
- std::string buffer;
- buffer += dbus_traits<A1>::getSignature();
- buffer += dbus_traits<A2>::getSignature();
- buffer += dbus_traits<A3>::getSignature();
- entry.signature = strdup(buffer.c_str());
- buffer.clear();
- buffer += dbus_traits<A1>::getReply();
- buffer += dbus_traits<A2>::getReply();
- buffer += dbus_traits<A3>::getReply();
- entry.reply = strdup(buffer.c_str());
- entry.function = methodFunction;
- entry.destroy = destroyFunction;
- entry.flags = BDBusMethodFlags(flags | G_DBUS_METHOD_FLAG_METHOD_DATA |
- (asynchronous ? G_DBUS_METHOD_FLAG_ASYNC : 0));
- entry.method_data = new M(m);
+ GPtrArray *inArgs = g_ptr_array_new();
+ appendNewArg<A1>(inArgs);
+ appendNewArg<A2>(inArgs);
+ appendNewArg<A3>(inArgs);
+ g_ptr_array_add(inArgs, NULL);
+
+ GPtrArray *outArgs = g_ptr_array_new();
+ appendNewArgForReply<A1>(outArgs);
+ appendNewArgForReply<A2>(outArgs);
+ appendNewArgForReply<A3>(outArgs);
+ g_ptr_array_add(outArgs, NULL);
+
+ entry->name = g_strdup(name);
+ entry->in_args = (GDBusArgInfo **)g_ptr_array_free(inArgs, FALSE);
+ entry->out_args = (GDBusArgInfo **)g_ptr_array_free(outArgs, FALSE);
+
+ entry->ref_count = 1;
return entry;
}
};
@@ -3351,8 +3425,8 @@ struct MakeMethodEntry< boost::function<R (A1, A2)> >
static const bool asynchronous = DBusResult2<A1, A2>::asynchronous;
- static DBusMessage *methodFunction(DBusConnection *conn,
- DBusMessage *msg, void *data)
+ static GDBusMessage *methodFunction(GDBusConnection *conn,
+ GDBusMessage *msg, void *data)
{
try {
typename dbus_traits<R>::host_type r;
@@ -3367,7 +3441,7 @@ struct MakeMethodEntry< boost::function<R (A1, A2)> >
return NULL;
}
- DBusMessage *reply = dbus_message_new_method_return(msg);
+ GDBusMessage *reply = g_dbus_message_new_method_reply(msg);
if (!reply)
return NULL;
@@ -3379,30 +3453,25 @@ struct MakeMethodEntry< boost::function<R (A1, A2)> >
}
}
- static void destroyFunction(void *user_data)
+ static GDBusMethodInfo *make(const char *name)
{
- BDBusMethodTable *entry = static_cast<BDBusMethodTable *>(user_data);
- delete static_cast<M *>(entry->method_data);
- }
+ GDBusMethodInfo *entry = g_new0(GDBusMethodInfo, 1);
- static BDBusMethodTable make(const char *name, BDBusMethodFlags flags, const M &m)
- {
- BDBusMethodTable entry;
- entry.name = strdup(name);
- std::string buffer;
- buffer += dbus_traits<A1>::getSignature();
- buffer += dbus_traits<A2>::getSignature();
- entry.signature = strdup(buffer.c_str());
- buffer.clear();
- buffer += dbus_traits<R>::getReply();
- buffer += dbus_traits<A1>::getReply();
- buffer += dbus_traits<A2>::getReply();
- entry.reply = strdup(buffer.c_str());
- entry.function = methodFunction;
- entry.destroy = destroyFunction;
- entry.flags = BDBusMethodFlags(flags | G_DBUS_METHOD_FLAG_METHOD_DATA |
- (asynchronous ? G_DBUS_METHOD_FLAG_ASYNC : 0));
- entry.method_data = new M(m);
+ GPtrArray *inArgs = g_ptr_array_new();
+ appendNewArg<A1>(inArgs);
+ appendNewArg<A2>(inArgs);
+ g_ptr_array_add(inArgs, NULL);
+
+ GPtrArray *outArgs = g_ptr_array_new();
+ appendNewArgForReply<A1>(outArgs);
+ appendNewArgForReply<A2>(outArgs);
+ g_ptr_array_add(outArgs, NULL);
+
+ entry->name = g_strdup(name);
+ entry->in_args = (GDBusArgInfo **)g_ptr_array_free(inArgs, FALSE);
+ entry->out_args = (GDBusArgInfo **)g_ptr_array_free(outArgs, FALSE);
+
+ entry->ref_count = 1;
return entry;
}
};
@@ -3420,8 +3489,8 @@ struct MakeMethodEntry< boost::function<void (A1, A2)> >
static const bool asynchronous = DBusResult2<A1, A2>::asynchronous;
- static DBusMessage *methodFunction(DBusConnection *conn,
- DBusMessage *msg, void *data)
+ static GDBusMessage *methodFunction(GDBusConnection *conn,
+ GDBusMessage *msg, void *data)
{
try {
typename dbus_traits<A1>::host_type a1;
@@ -3435,7 +3504,7 @@ struct MakeMethodEntry< boost::function<void (A1, A2)> >
return NULL;
}
- DBusMessage *reply = dbus_message_new_method_return(msg);
+ GDBusMessage *reply = g_dbus_message_new_method_reply(msg);
if (!reply)
return NULL;
@@ -3447,29 +3516,25 @@ struct MakeMethodEntry< boost::function<void (A1, A2)> >
}
}
- static void destroyFunction(void *user_data)
+ static GDBusMethodInfo *make(const char *name)
{
- BDBusMethodTable *entry = static_cast<BDBusMethodTable *>(user_data);
- delete static_cast<M *>(entry->method_data);
- }
+ GDBusMethodInfo *entry = g_new0(GDBusMethodInfo, 1);
- static BDBusMethodTable make(const char *name, BDBusMethodFlags flags, const M &m)
- {
- BDBusMethodTable entry;
- entry.name = strdup(name);
- std::string buffer;
- buffer += dbus_traits<A1>::getSignature();
- buffer += dbus_traits<A2>::getSignature();
- entry.signature = strdup(buffer.c_str());
- buffer.clear();
- buffer += dbus_traits<A1>::getReply();
- buffer += dbus_traits<A2>::getReply();
- entry.reply = strdup(buffer.c_str());
- entry.function = methodFunction;
- entry.destroy = destroyFunction;
- entry.flags = BDBusMethodFlags(flags | G_DBUS_METHOD_FLAG_METHOD_DATA |
- (asynchronous ? G_DBUS_METHOD_FLAG_ASYNC : 0));
- entry.method_data = new M(m);
+ GPtrArray *inArgs = g_ptr_array_new();
+ appendNewArg<A1>(inArgs);
+ appendNewArg<A2>(inArgs);
+ g_ptr_array_add(inArgs, NULL);
+
+ GPtrArray *outArgs = g_ptr_array_new();
+ appendNewArgForReply<A1>(outArgs);
+ appendNewArgForReply<A2>(outArgs);
+ g_ptr_array_add(outArgs, NULL);
+
+ entry->name = g_strdup(name);
+ entry->in_args = (GDBusArgInfo **)g_ptr_array_free(inArgs, FALSE);
+ entry->out_args = (GDBusArgInfo **)g_ptr_array_free(outArgs, FALSE);
+
+ entry->ref_count = 1;
return entry;
}
};
@@ -3488,8 +3553,8 @@ struct MakeMethodEntry< boost::function<R (A1)> >
static const bool asynchronous = DBusResult1<A1>::asynchronous;
- static DBusMessage *methodFunction(DBusConnection *conn,
- DBusMessage *msg, void *data)
+ static GDBusMessage *methodFunction(GDBusConnection *conn,
+ GDBusMessage *msg, void *data)
{
try {
typename dbus_traits<R>::host_type r;
@@ -3503,7 +3568,7 @@ struct MakeMethodEntry< boost::function<R (A1)> >
return NULL;
}
- DBusMessage *reply = dbus_message_new_method_return(msg);
+ GDBusMessage *reply = g_dbus_message_new_method_reply(msg);
if (!reply)
return NULL;
@@ -3515,28 +3580,23 @@ struct MakeMethodEntry< boost::function<R (A1)> >
}
}
- static void destroyFunction(void *user_data)
+ static GDBusMethodInfo *make(const char *name)
{
- BDBusMethodTable *entry = static_cast<BDBusMethodTable *>(user_data);
- delete static_cast<M *>(entry->method_data);
- }
+ GDBusMethodInfo *entry = g_new0(GDBusMethodInfo, 1);
- static BDBusMethodTable make(const char *name, BDBusMethodFlags flags, const M &m)
- {
- BDBusMethodTable entry;
- entry.name = strdup(name);
- std::string buffer;
- buffer += dbus_traits<A1>::getSignature();
- entry.signature = strdup(buffer.c_str());
- buffer.clear();
- buffer += dbus_traits<R>::getReply();
- buffer += dbus_traits<A1>::getReply();
- entry.reply = strdup(buffer.c_str());
- entry.function = methodFunction;
- entry.destroy = destroyFunction;
- entry.flags = BDBusMethodFlags(flags | G_DBUS_METHOD_FLAG_METHOD_DATA |
- (asynchronous ? G_DBUS_METHOD_FLAG_ASYNC : 0));
- entry.method_data = new M(m);
+ GPtrArray *inArgs = g_ptr_array_new();
+ appendNewArg<A1>(inArgs);
+ g_ptr_array_add(inArgs, NULL);
+
+ GPtrArray *outArgs = g_ptr_array_new();
+ appendNewArgForReply<A1>(outArgs);
+ g_ptr_array_add(outArgs, NULL);
+
+ entry->name = g_strdup(name);
+ entry->in_args = (GDBusArgInfo **)g_ptr_array_free(inArgs, FALSE);
+ entry->out_args = (GDBusArgInfo **)g_ptr_array_free(outArgs, FALSE);
+
+ entry->ref_count = 1;
return entry;
}
};
@@ -3554,8 +3614,8 @@ struct MakeMethodEntry< boost::function<void (A1)> >
static const bool asynchronous = DBusResult1<A1>::asynchronous;
- static DBusMessage *methodFunction(DBusConnection *conn,
- DBusMessage *msg, void *data)
+ static GDBusMessage *methodFunction(GDBusConnection *conn,
+ GDBusMessage *msg, void *data)
{
try {
typename dbus_traits<A1>::host_type a1;
@@ -3568,7 +3628,7 @@ struct MakeMethodEntry< boost::function<void (A1)> >
return NULL;
}
- DBusMessage *reply = dbus_message_new_method_return(msg);
+ GDBusMessage *reply = g_dbus_message_new_method_reply(msg);
if (!reply)
return NULL;
@@ -3580,27 +3640,23 @@ struct MakeMethodEntry< boost::function<void (A1)> >
}
}
- static void destroyFunction(void *user_data)
+ static GDBusMethodInfo *make(const char *name)
{
- BDBusMethodTable *entry = static_cast<BDBusMethodTable *>(user_data);
- delete static_cast<M *>(entry->method_data);
- }
+ GDBusMethodInfo *entry = g_new0(GDBusMethodInfo, 1);
- static BDBusMethodTable make(const char *name, BDBusMethodFlags flags, const M &m)
- {
- BDBusMethodTable entry;
- entry.name = strdup(name);
- std::string buffer;
- buffer += dbus_traits<A1>::getSignature();
- entry.signature = strdup(buffer.c_str());
- buffer.clear();
- buffer += dbus_traits<A1>::getReply();
- entry.reply = strdup(buffer.c_str());
- entry.function = methodFunction;
- entry.destroy = destroyFunction;
- entry.flags = BDBusMethodFlags(flags | G_DBUS_METHOD_FLAG_METHOD_DATA |
- (asynchronous ? G_DBUS_METHOD_FLAG_ASYNC : 0));
- entry.method_data = new M(m);
+ GPtrArray *inArgs = g_ptr_array_new();
+ appendNewArg<A1>(inArgs);
+ g_ptr_array_add(inArgs, NULL);
+
+ GPtrArray *outArgs = g_ptr_array_new();
+ appendNewArgForReply<A1>(outArgs);
+ g_ptr_array_add(outArgs, NULL);
+
+ entry->name = g_strdup(name);
+ entry->in_args = (GDBusArgInfo **)g_ptr_array_free(inArgs, FALSE);
+ entry->out_args = (GDBusArgInfo **)g_ptr_array_free(outArgs, FALSE);
+
+ entry->ref_count = 1;
return entry;
}
};
@@ -3616,15 +3672,15 @@ struct MakeMethodEntry< boost::function<R ()> >
return boost::bind(method, instance);
}
- static DBusMessage *methodFunction(DBusConnection *conn,
- DBusMessage *msg, void *data)
+ static GDBusMessage *methodFunction(GDBusConnection *conn,
+ GDBusMessage *msg, void *data)
{
try {
typename dbus_traits<R>::host_type r;
r = (*static_cast<M *>(data))();
- DBusMessage *reply = dbus_message_new_method_return(msg);
+ GDBusMessage *reply = g_dbus_message_new_method_reply(msg);
if (!reply)
return NULL;
@@ -3635,25 +3691,16 @@ struct MakeMethodEntry< boost::function<R ()> >
return handleException(msg);
}
}
- static void destroyFunction(void *user_data)
- {
- BDBusMethodTable *entry = static_cast<BDBusMethodTable *>(user_data);
- delete static_cast<M *>(entry->method_data);
- }
- static BDBusMethodTable make(const char *name, BDBusMethodFlags flags, const M &m)
+ static GDBusMethodInfo *make(const char *name)
{
- BDBusMethodTable entry;
- entry.name = strdup(name);
- std::string buffer;
- entry.signature = strdup(buffer.c_str());
- buffer.clear();
- buffer += dbus_traits<R>::getReply();
- entry.reply = strdup(buffer.c_str());
- entry.function = methodFunction;
- entry.destroy = destroyFunction;
- entry.flags = BDBusMethodFlags(flags | G_DBUS_METHOD_FLAG_METHOD_DATA);
- entry.method_data = new M(m);
+ GDBusMethodInfo *entry = g_new0(GDBusMethodInfo, 1);
+
+ entry->name = g_strdup(name);
+ entry->in_args = NULL;
+ entry->out_args = NULL;
+
+ entry->ref_count = 1;
return entry;
}
};
@@ -3669,13 +3716,13 @@ struct MakeMethodEntry< boost::function<void ()> >
return boost::bind(method, instance);
}
- static DBusMessage *methodFunction(DBusConnection *conn,
- DBusMessage *msg, void *data)
+ static GDBusMessage *methodFunction(GDBusConnection *conn,
+ GDBusMessage *msg, void *data)
{
try {
(*static_cast<M *>(data))();
- DBusMessage *reply = dbus_message_new_method_return(msg);
+ GDBusMessage *reply = g_dbus_message_new_method_reply(msg);
if (!reply)
return NULL;
return reply;
@@ -3684,24 +3731,15 @@ struct MakeMethodEntry< boost::function<void ()> >
}
}
- static void destroyFunction(void *user_data)
+ static GDBusMethodInfo *make(const char *name)
{
- BDBusMethodTable *entry = static_cast<BDBusMethodTable *>(user_data);
- delete static_cast<M *>(entry->method_data);
- }
+ GDBusMethodInfo *entry = g_new0(GDBusMethodInfo, 1);
- static BDBusMethodTable make(const char *name, BDBusMethodFlags flags, const M &m)
- {
- BDBusMethodTable entry;
- entry.name = strdup(name);
- std::string buffer;
- entry.signature = strdup(buffer.c_str());
- buffer.clear();
- entry.reply = strdup(buffer.c_str());
- entry.function = methodFunction;
- entry.destroy = destroyFunction;
- entry.flags = BDBusMethodFlags(flags | G_DBUS_METHOD_FLAG_METHOD_DATA);
- entry.method_data = new M(m);
+ entry->name = g_strdup(name);
+ entry->in_args = NULL;
+ entry->out_args = NULL;
+
+ entry->ref_count = 1;
return entry;
}
};
@@ -3736,11 +3774,11 @@ protected:
const std::string m_method;
const DBusConnectionPtr m_conn;
- typedef DBusPendingCallNotifyFunction DBusCallback;
+ typedef GAsyncReadyCallback DBusCallback;
DBusCallback m_dbusCallback;
- /**
- * called by libdbus to free the user_data pointer set in
+ /**
+ * called by GDBus to free the user_data pointer set in
* dbus_pending_call_set_notify()
*/
static void callDataUnref(void *user_data) {
@@ -3781,112 +3819,80 @@ public:
{
}
- DBusConnection *getConnection() { return m_conn.get(); }
+ GDBusConnection *getConnection() { return m_conn.get(); }
void operator () (const Callback_t &callback)
{
- DBusPendingCall *call;
- DBusMessagePtr msg(dbus_message_new_method_call(
- m_destination.c_str(),
- m_path.c_str(),
- m_interface.c_str(),
- m_method.c_str()));
+ GDBusMessagePtr msg(g_dbus_message_new_method_call(m_destination.c_str(),
+ m_path.c_str(),
+ m_interface.c_str(),
+ m_method.c_str()));
if (!msg) {
- throw std::runtime_error("dbus_message_new_method_call() failed");
- }
-
- //parameter marshaling (none)
- if (!dbus_connection_send_with_reply(m_conn.get(), msg.get(), &call, -1)) {
- throw std::runtime_error("dbus_connection_send failed");
+ throw std::runtime_error("g_dbus_message_new_method_call() failed");
}
- DBusPendingCallPtr mCall (call);
CallbackData *data = new CallbackData(m_conn, callback);
- dbus_pending_call_set_notify(mCall.get(),
- m_dbusCallback,
- data,
- callDataUnref);
+
+ //parameter marshaling (none)
+ g_dbus_connection_send_message_with_reply(m_conn.get(), msg.get(), G_DBUS_SEND_MESSAGE_FLAGS_NONE,
+ -1, NULL, NULL, m_dbusCallback, data);
}
template <class A1>
void operator () (const A1 &a1, const Callback_t &callback)
{
- DBusPendingCall *call;
- DBusMessagePtr msg(dbus_message_new_method_call(
- m_destination.c_str(),
- m_path.c_str(),
- m_interface.c_str(),
- m_method.c_str()));
+ GDBusMessagePtr msg(g_dbus_message_new_method_call(m_destination.c_str(),
+ m_path.c_str(),
+ m_interface.c_str(),
+ m_method.c_str()));
if (!msg) {
- throw std::runtime_error("dbus_message_new_method_call() failed");
+ throw std::runtime_error("g_dbus_message_new_method_call() failed");
}
- AppendRetvals(msg) << a1;
+ AppendRetvals(msg.get()) << a1;
- //parameter marshaling (none)
- if (!dbus_connection_send_with_reply(m_conn.get(), msg.get(), &call, -1)) {
- throw std::runtime_error("dbus_connection_send failed");
- }
-
- DBusPendingCallPtr mCall (call);
CallbackData *data = new CallbackData(m_conn, callback);
- dbus_pending_call_set_notify(mCall.get(),
- m_dbusCallback,
- data,
- callDataUnref);
+
+ //parameter marshaling (none)
+ g_dbus_connection_send_message_with_reply(m_conn.get(), msg.get(), G_DBUS_SEND_MESSAGE_FLAGS_NONE,
+ -1, NULL, NULL, m_dbusCallback, data);
}
template <class A1, class A2>
void operator () (const A1 &a1, const A2 &a2, const Callback_t &callback)
{
- DBusPendingCall *call;
- DBusMessagePtr msg(dbus_message_new_method_call(
- m_destination.c_str(),
- m_path.c_str(),
- m_interface.c_str(),
- m_method.c_str()));
+ GDBusMessagePtr msg(g_dbus_message_new_method_call(m_destination.c_str(),
+ m_path.c_str(),
+ m_interface.c_str(),
+ m_method.c_str()));
if (!msg) {
- throw std::runtime_error("dbus_message_new_method_call() failed");
- }
- AppendRetvals(msg) << a1 << a2;
-
- //parameter marshaling (none)
- if (!dbus_connection_send_with_reply(m_conn.get(), msg.get(), &call, -1)) {
- throw std::runtime_error("dbus_connection_send failed");
+ throw std::runtime_error("g_dbus_message_new_method_call() failed");
}
+ AppendRetvals(msg.get()) << a1 << a2;
- DBusPendingCallPtr mCall (call);
CallbackData *data = new CallbackData(m_conn, callback);
- dbus_pending_call_set_notify(mCall.get(),
- m_dbusCallback,
- data,
- callDataUnref);
+
+ //parameter marshaling (none)
+ g_dbus_connection_send_message_with_reply(m_conn.get(), msg.get(), G_DBUS_SEND_MESSAGE_FLAGS_NONE,
+ -1, NULL, NULL, m_dbusCallback, data);
}
template <class A1, class A2, class A3>
void operator () (const A1 &a1, const A2 &a2, const A3 &a3, const Callback_t &callback)
{
- DBusPendingCall *call;
- DBusMessagePtr msg(dbus_message_new_method_call(
- m_destination.c_str(),
- m_path.c_str(),
- m_interface.c_str(),
- m_method.c_str()));
+ GDBusMessagePtr msg(g_dbus_message_new_method_call(m_destination.c_str(),
+ m_path.c_str(),
+ m_interface.c_str(),
+ m_method.c_str()));
if (!msg) {
- throw std::runtime_error("dbus_message_new_method_call() failed");
- }
- AppendRetvals(msg) << a1 << a2 << a3;
-
- //parameter marshaling (none)
- if (!dbus_connection_send_with_reply(m_conn.get(), msg.get(), &call, -1)) {
- throw std::runtime_error("dbus_connection_send failed");
+ throw std::runtime_error("g_dbus_message_new_method_call() failed");
}
+ AppendRetvals(msg.get()) << a1 << a2 << a3;
- DBusPendingCallPtr mCall (call);
CallbackData *data = new CallbackData(m_conn, callback);
- dbus_pending_call_set_notify(mCall.get(),
- m_dbusCallback,
- data,
- callDataUnref);
+
+ //parameter marshaling (none)
+ g_dbus_connection_send_message_with_reply(m_conn.get(), msg.get(), G_DBUS_SEND_MESSAGE_FLAGS_NONE,
+ -1, NULL, NULL, m_dbusCallback, data);
}
};
@@ -3901,18 +3907,20 @@ class DBusClientCall0 : public DBusClientCall<boost::function<void (const std::s
*/
typedef boost::function<void (const std::string &)> Callback_t;
- /** called by libdbus on error or completion of call */
- static void dbusCallback (DBusPendingCall *call, void *user_data)
+ /** called by gdbus on error or completion of call */
+ static void dbusCallback (GObject *src_obj, GAsyncResult *res, void *user_data)
{
+ typedef typename DBusClientCall<Callback_t>::CallbackData CallbackData;
CallbackData *data = static_cast<CallbackData *>(user_data);
- DBusMessagePtr reply = dbus_pending_call_steal_reply (call);
- const char* errname = dbus_message_get_error_name (reply.get());
- std::string error;
- if (errname) {
- error = errname;
- }
+
+ GError *err = NULL;
+ GDBusMessagePtr reply(g_dbus_connection_send_message_with_reply_finish(data->m_conn.get(), res, &err));
//unmarshal the return results and call user callback
- (data->m_callback)(error);
+ (data->m_callback)(err ? err->message : "");
+ delete data;
+ if (err != NULL) {
+ g_error_free (err);
+ }
}
public:
@@ -3936,23 +3944,26 @@ class DBusClientCall1 : public DBusClientCall<boost::function<void (const R1 &,
*/
typedef boost::function<void (const R1 &, const std::string &)> Callback_t;
- /** called by libdbus on error or completion of call */
- static void dbusCallback (DBusPendingCall *call, void *user_data)
+ /** called by gdbus on error or completion of call */
+ static void dbusCallback (GObject *src_obj, GAsyncResult *res, void *user_data)
{
typedef typename DBusClientCall<Callback_t>::CallbackData CallbackData;
CallbackData *data = static_cast<CallbackData *>(user_data);
- DBusMessagePtr reply = dbus_pending_call_steal_reply (call);
- const char* errname = dbus_message_get_error_name (reply.get());
- std::string error;
+
+ GError *err = NULL;
+ GDBusMessagePtr reply(g_dbus_connection_send_message_with_reply_finish(data->m_conn.get(), res, &err));
typename dbus_traits<R1>::host_type r;
- if (!errname) {
+ if (err == NULL && !g_dbus_message_to_gerror(reply.get(), &err)) {
ExtractArgs(data->m_conn.get(), reply.get()) >> Get<R1>(r);
- } else {
- error = errname;
}
+
//unmarshal the return results and call user callback
- //(*static_cast <Callback_t *>(user_data))(r, error);
- (data->m_callback)(r, error);
+ //(*static_cast <Callback_t *>(user_data))(r, err->message);
+ (data->m_callback)(r, err ? err->message : "");
+ delete data;
+ if (err != NULL) {
+ g_error_free (err);
+ }
}
public:
@@ -3978,23 +3989,25 @@ class DBusClientCall2 : public DBusClientCall<boost::function<
*/
typedef boost::function<void (const R1 &, const R2 &, const std::string &)> Callback_t;
- /** called by libdbus on error or completion of call */
- static void dbusCallback (DBusPendingCall *call, void *user_data)
+ /** called by gdbus on error or completion of call */
+ static void dbusCallback (GObject *src_obj, GAsyncResult *res, void *user_data)
{
typedef typename DBusClientCall<Callback_t>::CallbackData CallbackData;
CallbackData *data = static_cast<CallbackData *>(user_data);
- DBusMessagePtr reply = dbus_pending_call_steal_reply (call);
- const char* errname = dbus_message_get_error_name (reply.get());
- std::string error;
+
+ GError *err = NULL;
+ GDBusMessagePtr reply(g_dbus_connection_send_message_with_reply_finish(data->m_conn.get(), res, &err));
typename dbus_traits<R1>::host_type r1;
typename dbus_traits<R2>::host_type r2;
- if (!errname) {
+ if (err == NULL && !g_dbus_message_to_gerror(reply.get(), &err)) {
ExtractArgs(data->m_conn.get(), reply.get()) >> Get<R1>(r1) >> Get<R2>(r2);
- } else {
- error = errname;
}
//unmarshal the return results and call user callback
- (data->m_callback)(r1, r2, error);
+ (data->m_callback)(r1, r2, err ? err->message : "");
+ delete data;
+ if (err != NULL) {
+ g_error_free (err);
+ }
}
public:
@@ -4020,24 +4033,26 @@ class DBusClientCall3 : public DBusClientCall<boost::function<
*/
typedef boost::function<void (const R1 &, const R2 &, const R3 &, const std::string &)> Callback_t;
- /** called by libdbus on error or completion of call */
- static void dbusCallback (DBusPendingCall *call, void *user_data)
+ /** called by gdbus on error or completion of call */
+ static void dbusCallback (GObject *src_obj, GAsyncResult *res, void *user_data)
{
typedef typename DBusClientCall<Callback_t>::CallbackData CallbackData;
CallbackData *data = static_cast<CallbackData *>(user_data);
- DBusMessagePtr reply = dbus_pending_call_steal_reply (call);
- const char* errname = dbus_message_get_error_name (reply.get());
- std::string error;
+
+ GError *err = NULL;
+ GDBusMessagePtr reply(g_dbus_connection_send_message_with_reply_finish(data->m_conn.get(), res, &err));
typename dbus_traits<R1>::host_type r1;
typename dbus_traits<R2>::host_type r2;
typename dbus_traits<R3>::host_type r3;
- if (!errname) {
+ if (err == NULL && !g_dbus_message_to_gerror(reply.get(), &err)) {
ExtractArgs(data->m_conn.get(), reply.get()) >> Get<R1>(r1) >> Get<R2>(r2) >> Get<R3>(r3);
- } else {
- error = errname;
}
//unmarshal the return results and call user callback
- (data->m_callback)(r1, r2, r3, error);
+ (data->m_callback)(r1, r2, r3, err ? err->message : "");
+ delete data;
+ if (err != NULL) {
+ g_error_free (err);
+ }
}
public:
@@ -4068,7 +4083,7 @@ template <class T> class SignalWatch
~SignalWatch()
{
if (m_tag) {
- b_dbus_remove_watch(m_object.getConnection(), m_tag);
+ g_dbus_connection_signal_unsubscribe(m_object.getConnection(), m_tag);
}
}
@@ -4081,34 +4096,26 @@ template <class T> class SignalWatch
guint m_tag;
T m_callback;
- std::string makeSignalRule() {
- std::string rule;
- rule = "type='signal',path='";
- rule += m_object.getPath();
- rule += "',interface='";
- rule += m_object.getInterface();
- rule += "',member='";
- rule += m_signal;
- rule += "'";
- return rule;
- }
-
- static gboolean isMatched(DBusMessage *msg, void *data) {
+ static gboolean isMatched(GDBusMessage *msg, void *data)
+ {
SignalWatch *watch = static_cast<SignalWatch*>(data);
- return dbus_message_has_path(msg, watch->m_object.getPath()) &&
- dbus_message_is_signal(msg, watch->m_object.getInterface(), watch->m_signal.c_str());
+ return boost::iequals(g_dbus_message_get_path(msg), watch->m_object.getPath()) &&
+ g_dbus_message_get_message_type(msg) == G_DBUS_MESSAGE_TYPE_SIGNAL;
}
- void activateInternal(const Callback_t &callback,
- gboolean (*cb)(DBusConnection *, DBusMessage *, void *))
+ void activateInternal(const Callback_t &callback, GDBusSignalCallback cb)
{
m_callback = callback;
- std::string rule = makeSignalRule();
- m_tag = b_dbus_add_signal_watch(m_object.getConnection(),
- rule.c_str(),
- cb,
- this,
- NULL);
+ m_tag = g_dbus_connection_signal_subscribe(m_object.getConnection(),
+ NULL,
+ m_object.getInterface(),
+ m_signal.c_str(),
+ m_object.getPath(),
+ NULL,
+ G_DBUS_SIGNAL_FLAGS_NONE,
+ cb,
+ this,
+ NULL);
}
};
@@ -4123,18 +4130,22 @@ class SignalWatch0 : public SignalWatch< boost::function<void (void)> >
{
}
- static gboolean internalCallback(DBusConnection *conn, DBusMessage *msg, void *data)
+ static void internalCallback(GDBusConnection *conn,
+ const gchar *sender,
+ const gchar *path,
+ const gchar *interface,
+ const gchar *signal,
+ GVariant *params,
+ gpointer data)
{
- if(isMatched(msg, data) == FALSE) {
- return TRUE;
- }
const Callback_t &cb = static_cast< SignalWatch<Callback_t> *>(data)->getCallback();
cb();
-
- return TRUE;
}
- void activate(const Callback_t &callback) { SignalWatch< boost::function<void (void)> >::activateInternal(callback, internalCallback); }
+ void activate(const Callback_t &callback)
+ {
+ SignalWatch< boost::function<void (void)> >::activateInternal(callback, internalCallback);
+ }
};
template <typename A1>
@@ -4149,24 +4160,28 @@ class SignalWatch1 : public SignalWatch< boost::function<void (const A1 &)> >
{
}
- static gboolean internalCallback(DBusConnection *conn, DBusMessage *msg, void *data)
+ static void internalCallback(GDBusConnection *conn,
+ const gchar *sender,
+ const gchar *path,
+ const gchar *interface,
+ const gchar *signal,
+ GVariant *params,
+ gpointer data)
{
- if (SignalWatch<Callback_t>::isMatched(msg, data) == FALSE) {
- return TRUE;
- }
- const Callback_t &cb =static_cast< SignalWatch<Callback_t> *>(data)->getCallback();
+ const Callback_t &cb = static_cast< SignalWatch<Callback_t> *>(data)->getCallback();
typename dbus_traits<A1>::host_type a1;
- DBusMessageIter iter;
- dbus_message_iter_init(msg, &iter);
- dbus_traits<A1>::get(conn, msg, iter, a1);
+ GVariantIter iter;
+ g_variant_iter_init(&iter, params);
+ dbus_traits<A1>::get(conn, NULL, iter, a1);
cb(a1);
-
- return TRUE;
}
- void activate(const Callback_t &callback) { SignalWatch< boost::function<void (const A1 &)> >::activateInternal(callback, internalCallback); }
+ void activate(const Callback_t &callback)
+ {
+ SignalWatch< boost::function<void (const A1 &)> >::activateInternal(callback, internalCallback);
+ }
};
template <typename A1, typename A2>
@@ -4181,26 +4196,31 @@ class SignalWatch2 : public SignalWatch< boost::function<void (const A1 &, const
{
}
- static gboolean internalCallback(DBusConnection *conn, DBusMessage *msg, void *data)
+ static void internalCallback(GDBusConnection *conn,
+ const gchar *sender,
+ const gchar *path,
+ const gchar *interface,
+ const gchar *signal,
+ GVariant *params,
+ gpointer data)
{
- if (SignalWatch<Callback_t>::isMatched(msg, data) == FALSE) {
- return TRUE;
- }
const Callback_t &cb = static_cast< SignalWatch<Callback_t> *>(data)->getCallback();
typename dbus_traits<A1>::host_type a1;
typename dbus_traits<A2>::host_type a2;
- DBusMessageIter iter;
- dbus_message_iter_init(msg, &iter);
- dbus_traits<A1>::get(conn, msg, iter, a1);
- dbus_traits<A2>::get(conn, msg, iter, a2);
+ GVariantIter iter;
+ g_variant_iter_init(&iter, params);
+ dbus_traits<A1>::get(conn, NULL, iter, a1);
+ dbus_traits<A2>::get(conn, NULL, iter, a2);
cb(a1, a2);
-
- return TRUE;
}
- void activate(const Callback_t &callback) { SignalWatch< boost::function<void (const A1 &, const A2 &)> >::activateInternal(callback, internalCallback); }
+ void activate(const Callback_t &callback)
+ {
+ SignalWatch< boost::function<void (const A1 &, const A2 &)> >::activateInternal(callback,
+ internalCallback);
+ }
};
template <typename A1, typename A2, typename A3>
@@ -4215,32 +4235,43 @@ class SignalWatch3 : public SignalWatch< boost::function<void (const A1 &, const
{
}
- static gboolean internalCallback(DBusConnection *conn, DBusMessage *msg, void *data)
+ static void internalCallback(GDBusConnection *conn,
+ const gchar *sender,
+ const gchar *path,
+ const gchar *interface,
+ const gchar *signal,
+ GVariant *params,
+ gpointer data)
{
- if (SignalWatch<Callback_t>::isMatched(msg, data) == FALSE) {
- return TRUE;
- }
+ /* if (SignalWatch<Callback_t>::isMatched(msg, data) == FALSE) { */
+ /* return TRUE; */
+ /* } */
const Callback_t &cb =static_cast< SignalWatch<Callback_t> *>(data)->getCallback();
typename dbus_traits<A1>::host_type a1;
typename dbus_traits<A2>::host_type a2;
typename dbus_traits<A3>::host_type a3;
- DBusMessageIter iter;
- dbus_message_iter_init(msg, &iter);
- dbus_traits<A1>::get(conn, msg, iter, a1);
- dbus_traits<A2>::get(conn, msg, iter, a2);
- dbus_traits<A3>::get(conn, msg, iter, a3);
+ GVariantIter iter;
+ g_variant_iter_init(&iter, params);
+ dbus_traits<A1>::get(conn, NULL, iter, a1);
+ dbus_traits<A2>::get(conn, NULL, iter, a2);
+ dbus_traits<A3>::get(conn, NULL, iter, a3);
cb(a1, a2, a3);
-
- return TRUE;
}
- void activate(const Callback_t &callback) { SignalWatch< boost::function<void (const A1 &, const A2 &, const A3 &)> >::activateInternal(callback, internalCallback); }
+ void activate(const Callback_t &callback)
+ {
+ SignalWatch< boost::function<void (const A1 &,
+ const A2 &,
+ const A3 &)> >::activateInternal(callback,
+ internalCallback);
+ }
};
template <typename A1, typename A2, typename A3, typename A4>
-class SignalWatch4 : public SignalWatch< boost::function<void (const A1 &, const A2 &, const A3 &, const A4 &)> >
+class SignalWatch4 : public SignalWatch< boost::function<void (const A1 &, const A2 &,
+ const A3 &, const A4 &)> >
{
typedef boost::function<void (const A1 &, const A2 &, const A3 &, const A4 &)> Callback_t;
@@ -4251,30 +4282,37 @@ class SignalWatch4 : public SignalWatch< boost::function<void (const A1 &, const
{
}
- static gboolean internalCallback(DBusConnection *conn, DBusMessage *msg, void *data)
+ static void internalCallback(GDBusConnection *conn,
+ const gchar *sender,
+ const gchar *path,
+ const gchar *interface,
+ const gchar *signal,
+ GVariant *params,
+ gpointer data)
{
- if (SignalWatch<Callback_t>::isMatched(msg, data) == FALSE) {
- return TRUE;
- }
const Callback_t &cb = static_cast< SignalWatch<Callback_t> *>(data)->getCallback();
+
typename dbus_traits<A1>::host_type a1;
typename dbus_traits<A2>::host_type a2;
typename dbus_traits<A3>::host_type a3;
typename dbus_traits<A4>::host_type a4;
- DBusMessageIter iter;
- dbus_message_iter_init(msg, &iter);
- dbus_traits<A1>::get(conn, msg, iter, a1);
- dbus_traits<A2>::get(conn, msg, iter, a2);
- dbus_traits<A3>::get(conn, msg, iter, a3);
- dbus_traits<A4>::get(conn, msg, iter, a4);
+ GVariantIter iter;
+ g_variant_iter_init(&iter, params);
+ dbus_traits<A1>::get(conn, NULL, &iter, a1);
+ dbus_traits<A2>::get(conn, NULL, &iter, a2);
+ dbus_traits<A3>::get(conn, NULL, &iter, a3);
+ dbus_traits<A4>::get(conn, NULL, &iter, a4);
cb(a1, a2, a3, a4);
-
- return TRUE;
}
- void activate(const Callback_t &callback) { SignalWatch< boost::function<void (const A1 &, const A2 &, const A3 &, const A4 &)> >::activateInternal(callback, internalCallback); }
+ void activate(const Callback_t &callback)
+ {
+ SignalWatch< boost::function<void (const A1 &, const A2 &,
+ const A3 &, const A4 &)> >::activateInternal(callback,
+ internalCallback);
+ }
};
template <typename A1, typename A2, typename A3, typename A4, typename A5>
@@ -4289,38 +4327,47 @@ class SignalWatch5 : public SignalWatch< boost::function<void (const A1 &, const
{
}
- static gboolean internalCallback(DBusConnection *conn, DBusMessage *msg, void *data)
+ static void internalCallback(GDBusConnection *conn,
+ const gchar *sender,
+ const gchar *path,
+ const gchar *interface,
+ const gchar *signal,
+ GVariant *params,
+ gpointer data)
{
- if (SignalWatch<Callback_t>::isMatched(msg, data) == FALSE) {
- return TRUE;
- }
const Callback_t &cb = static_cast< SignalWatch<Callback_t> *>(data)->getCallback();
+
typename dbus_traits<A1>::host_type a1;
typename dbus_traits<A2>::host_type a2;
typename dbus_traits<A3>::host_type a3;
typename dbus_traits<A4>::host_type a4;
typename dbus_traits<A5>::host_type a5;
- DBusMessageIter iter;
- dbus_message_iter_init(msg, &iter);
- dbus_traits<A1>::get(conn, msg, iter, a1);
- dbus_traits<A2>::get(conn, msg, iter, a2);
- dbus_traits<A3>::get(conn, msg, iter, a3);
- dbus_traits<A4>::get(conn, msg, iter, a4);
- dbus_traits<A5>::get(conn, msg, iter, a5);
+ GVariantIter iter;
+ g_variant_iter_init(&iter, params);
+ dbus_traits<A1>::get(conn, NULL, iter, a1);
+ dbus_traits<A2>::get(conn, NULL, iter, a2);
+ dbus_traits<A3>::get(conn, NULL, iter, a3);
+ dbus_traits<A4>::get(conn, NULL, iter, a4);
+ dbus_traits<A5>::get(conn, NULL, iter, a5);
cb(a1, a2, a3, a4, a5);
-
- return TRUE;
}
- void activate(const Callback_t &callback) { SignalWatch< boost::function<void (const A1 &, const A2 &, const A3 &, const A4 &, const A5 &)> >::activateInternal(callback, internalCallback); }
+ void activate(const Callback_t &callback)
+ {
+ SignalWatch< boost::function<void (const A1 &, const A2 &,
+ const A3 &, const A4 &,
+ const A5 &)> >::activateInternal(callback, internalCallback);
+ }
};
template <typename A1, typename A2, typename A3, typename A4, typename A5, typename A6>
-class SignalWatch6 : public SignalWatch< boost::function<void (const A1 &, const A2 &, const A3 &, const A4 &, const A5 &, const A6 &)> >
+class SignalWatch6 : public SignalWatch< boost::function<void (const A1 &, const A2 &, const A3 &,
+ const A4 &, const A5 &, const A6 &)> >
{
- typedef boost::function<void (const A1 &, const A2 &, const A3 &, const A4 &, const A5 &, const A6 &)> Callback_t;
+ typedef boost::function<void (const A1 &, const A2 &, const A3 &,
+ const A4 &, const A5 &, const A6 &)> Callback_t;
public:
@@ -4330,11 +4377,14 @@ class SignalWatch6 : public SignalWatch< boost::function<void (const A1 &, const
{
}
- static gboolean internalCallback(DBusConnection *conn, DBusMessage *msg, void *data)
+ static void internalCallback(GDBusConnection *conn,
+ const gchar *sender,
+ const gchar *path,
+ const gchar *interface,
+ const gchar *signal,
+ GVariant *params,
+ gpointer data)
{
- if (SignalWatch<Callback_t>::isMatched(msg, data) == FALSE) {
- return TRUE;
- }
const Callback_t &cb = static_cast< SignalWatch<Callback_t> *>(data)->getCallback();
typename dbus_traits<A1>::host_type a1;
@@ -4344,20 +4394,24 @@ class SignalWatch6 : public SignalWatch< boost::function<void (const A1 &, const
typename dbus_traits<A5>::host_type a5;
typename dbus_traits<A6>::host_type a6;
- DBusMessageIter iter;
- dbus_message_iter_init(msg, &iter);
- dbus_traits<A1>::get(conn, msg, iter, a1);
- dbus_traits<A2>::get(conn, msg, iter, a2);
- dbus_traits<A3>::get(conn, msg, iter, a3);
- dbus_traits<A4>::get(conn, msg, iter, a4);
- dbus_traits<A5>::get(conn, msg, iter, a5);
- dbus_traits<A6>::get(conn, msg, iter, a6);
+ GVariantIter iter;
+ g_variant_iter_init(&iter, params);
+ dbus_traits<A1>::get(conn, NULL, iter, a1);
+ dbus_traits<A2>::get(conn, NULL, iter, a2);
+ dbus_traits<A3>::get(conn, NULL, iter, a3);
+ dbus_traits<A4>::get(conn, NULL, iter, a4);
+ dbus_traits<A5>::get(conn, NULL, iter, a5);
+ dbus_traits<A6>::get(conn, NULL, iter, a6);
cb(a1, a2, a3, a4, a5, a6);
-
- return TRUE;
}
- void activate(const Callback_t &callback) { SignalWatch< boost::function<void (const A1 &, const A2 &, const A3 &, const A4 &, const A5 &, const A6 &)> >::activateInternal(callback, internalCallback); }
+ void activate(const Callback_t &callback)
+ {
+ SignalWatch< boost::function<void (const A1 &, const A2 &,
+ const A3 &, const A4 &,
+ const A5 &, const A6 &)> >::activateInternal(callback,
+ internalCallback);
+ }
};
} // namespace GDBusCXX
diff --git a/src/gdbusxx/gdbusxx.am b/src/gdbusxx/gdbusxx.am
index 5133fa86..fb2a9b24 100644
--- a/src/gdbusxx/gdbusxx.am
+++ b/src/gdbusxx/gdbusxx.am
@@ -11,12 +11,13 @@ src_gdbusxx_libgdbussyncevo_la_SOURCES = \
src/gdbusxx/gdbus-cxx.h
src_gdbusxx_libgdbussyncevo_la_LDFLAGS = $(src_gdbus_version_info)
-src_gdbusxx_libgdbussyncevo_la_LIBADD = @GLIB_LIBS@
-src_gdbusxx_libgdbussyncevo_la_CXXFLAGS = @GLIB_CFLAGS@
+src_gdbusxx_libgdbussyncevo_la_LIBADD = @GLIB_LIBS@ @GIO_GDBUS_LIBS@
+src_gdbusxx_libgdbussyncevo_la_CXXFLAGS = @GLIB_CFLAGS@ @GIO_GDBUS_CFLAGS@
MAINTAINERCLEANFILES += Makefile.in
noinst_PROGRAMS += src/gdbusxx/example
src_gdbusxx_example_SOURCES = src/gdbusxx/test/example.cpp
-src_gdbusxx_example_CXXFLAGS = @GLIB_CFLAGS@
-src_gdbusxx_example_LDADD = src/gdbusxx/libgdbussyncevo.la @GLIB_LIBS@
+src_gdbusxx_example_CPPFLAGS = -I$(top_srcdir)/src/gdbusxx/
+src_gdbusxx_example_CXXFLAGS = @GLIB_CFLAGS@ @GIO_GDBUS_CFLAGS@
+src_gdbusxx_example_LDADD = src/gdbusxx/libgdbussyncevo.la @GLIB_LIBS@ @GIO_GDBUS_LIBS@
diff --git a/src/gdbusxx/test/example.cpp b/src/gdbusxx/test/example.cpp
index 250201a2..70d52516 100644
--- a/src/gdbusxx/test/example.cpp
+++ b/src/gdbusxx/test/example.cpp
@@ -176,7 +176,7 @@ class DBusTest : public Test, private Test2
DBusObjectHelper m_secondary;
public:
- DBusTest(DBusConnection *conn) :
+ DBusTest(GDBusConnection *conn) :
m_object(conn, "/test", "org.example.Test"),
// same path!
m_secondary(conn, m_object.getPath(), "org.example.Secondary"),
@@ -244,8 +244,8 @@ using namespace GDBusCXX;
int main(int argc, char *argv[])
{
- DBusConnection *conn;
- DBusError err;
+ GDBusConnection *conn;
+ DBusErrorCXX err;
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
@@ -259,13 +259,10 @@ int main(int argc, char *argv[])
main_loop = g_main_loop_new(NULL, FALSE);
- dbus_error_init(&err);
-
- conn = b_dbus_setup_bus(DBUS_BUS_SESSION, "org.example", false, &err);
+ conn = dbus_get_bus_connection("SESSION", "org.example", false, &err);
if (conn == NULL) {
- if (dbus_error_is_set(&err) == TRUE) {
+ if (err.message) {
fprintf(stderr, "%s\n", err.message);
- dbus_error_free(&err);
} else
fprintf(stderr, "Can't register with session bus\n");
exit(1);
@@ -282,8 +279,10 @@ int main(int argc, char *argv[])
test.reset();
- b_dbus_cleanup_connection(conn);
-
+ if(!g_dbus_connection_close_sync(conn, NULL, NULL)) {
+ fprintf(stderr, "Problem closing connection.\n");
+ }
+
g_main_loop_unref(main_loop);
return 0;
diff --git a/src/syncevolution.cpp b/src/syncevolution.cpp
index 0d0df61a..a441c768 100644
--- a/src/syncevolution.cpp
+++ b/src/syncevolution.cpp
@@ -125,7 +125,7 @@ public:
virtual const char *getDestination() const {return "org.syncevolution";}
virtual const char *getPath() const {return "/org/syncevolution/Server";}
virtual const char *getInterface() const {return "org.syncevolution.Server";}
- virtual DBusConnection *getConnection() const {return m_conn.get();}
+ virtual DBUS_CONNECTION_TYPE *getConnection() const {return m_conn.get();}
GMainLoop *getLoop() { return m_loop; }
/**
@@ -288,7 +288,7 @@ public:
virtual const char *getDestination() const {return "org.syncevolution";}
virtual const char *getPath() const {return m_path.c_str();}
virtual const char *getInterface() const {return "org.syncevolution.Session";}
- virtual DBusConnection *getConnection() const {return m_server.getConnection();}
+ virtual DBUS_CONNECTION_TYPE *getConnection() const {return m_server.getConnection();}
RemoteDBusServer &getServer() { return m_server; }
/**
@@ -599,7 +599,7 @@ RemoteDBusServer::RemoteDBusServer()
m_infoReq(*this, "InfoRequest")
{
m_loop = g_main_loop_new (NULL, FALSE);
- m_conn = b_dbus_setup_bus(DBUS_BUS_SESSION, NULL, true, NULL);
+ m_conn = dbus_get_bus_connection("SESSION", NULL, true, NULL);
if(m_conn) {
//check whether we can attach to the daemon
diff --git a/test/test-dbus.py b/test/test-dbus.py
index fdf2005f..a52ce398 100755
--- a/test/test-dbus.py
+++ b/test/test-dbus.py
@@ -1053,10 +1053,12 @@ class TestDBusServerPresence(unittest.TestCase, DBusUtil):
"http://http-only-1"}})
self.session.Detach()
def cb_http_presence(server, status, transport):
- self.assertEqual (status, "")
- self.assertEqual (server, "foo")
- self.assertEqual (transport, "http://http-only-1")
- loop.quit()
+ try:
+ self.assertEqual (status, "")
+ self.assertEqual (server, "foo")
+ self.assertEqual (transport, "http://http-only-1")
+ finally:
+ loop.quit()
match = bus.add_signal_receiver(cb_http_presence,
'Presence',
@@ -1065,6 +1067,9 @@ class TestDBusServerPresence(unittest.TestCase, DBusUtil):
None,
byte_arrays=True,
utf8_strings=True)
+ # this loop is quit by connman GetProperties
+ loop.run()
+ # this loop is quit by cb_http_presence
loop.run()
time.sleep(1)
self.setUpSession("foo")