summaryrefslogtreecommitdiffstats
path: root/gdbus
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2008-05-08 19:39:12 +0000
committerMarcel Holtmann <marcel@holtmann.org>2008-05-08 19:39:12 +0000
commitaa215d6fa551a3edbd129d4a163210e98357bdd1 (patch)
treed117772b0b444240eac624427393e9dff4d92703 /gdbus
parent33191e6275ab82aa4161cdf75b45597e4d1568ec (diff)
Emulate libgdbus API for mainloop integration
Diffstat (limited to 'gdbus')
-rw-r--r--gdbus/gdbus.h10
-rw-r--r--gdbus/mainloop.c71
2 files changed, 40 insertions, 41 deletions
diff --git a/gdbus/gdbus.h b/gdbus/gdbus.h
index d749d5e2..a9f2aa51 100644
--- a/gdbus/gdbus.h
+++ b/gdbus/gdbus.h
@@ -31,10 +31,14 @@ extern "C" {
#include <dbus/dbus.h>
#include <glib.h>
-void setup_dbus_with_main_loop(DBusConnection *conn);
+typedef void (* GDBusDisconnectFunction) (void *user_data);
-DBusConnection *dbus_bus_system_setup_with_main_loop(const char *name,
- void (*disconnect_cb)(void *), void *user_data);
+DBusConnection *g_dbus_setup_bus(DBusBusType type, const char *name,
+ DBusError *error);
+
+gboolean g_dbus_set_disconnect_function(DBusConnection *connection,
+ GDBusDisconnectFunction function,
+ void *user_data, DBusFreeFunction destroy);
#ifdef __cplusplus
}
diff --git a/gdbus/mainloop.c b/gdbus/mainloop.c
index e8e7e0af..a9b8237c 100644
--- a/gdbus/mainloop.c
+++ b/gdbus/mainloop.c
@@ -235,7 +235,7 @@ static void dispatch_status_cb(DBusConnection *conn,
}
#endif
-void setup_dbus_with_main_loop(DBusConnection *conn)
+static void setup_dbus_with_main_loop(DBusConnection *conn)
{
#ifdef HAVE_DBUS_GLIB
debug("Using D-Bus GLib connection setup");
@@ -253,66 +253,61 @@ void setup_dbus_with_main_loop(DBusConnection *conn)
#endif
}
-static DBusConnection *init_dbus(const char *name,
- void (*disconnect_cb)(void *), void *user_data)
+DBusConnection *g_dbus_setup_bus(DBusBusType type, const char *name,
+ DBusError *error)
{
- struct disconnect_data *dc_data;
DBusConnection *conn;
- DBusError err;
-
- dbus_error_init(&err);
- conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
+ conn = dbus_bus_get(type, error);
- if (dbus_error_is_set(&err)) {
- error("Can't connect to system message bus: %s", err.message);
- dbus_error_free(&err);
- return NULL;
+ if (error != NULL) {
+ if (dbus_error_is_set(error) == TRUE)
+ return NULL;
}
- setup_dbus_with_main_loop(conn);
-
- if (name) {
- dbus_error_init(&err);
+ if (conn == NULL)
+ return NULL;
- if (dbus_bus_request_name(conn, name, 0, &err) !=
+ if (name != NULL) {
+ if (dbus_bus_request_name(conn, name,
+ DBUS_NAME_FLAG_DO_NOT_QUEUE, error) !=
DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER ) {
- error("Could not become the primary owner of %s", name);
dbus_connection_unref(conn);
return NULL;
}
- if (dbus_error_is_set(&err)) {
- error("Can't get bus name %s: %s", name, err.message);
- dbus_error_free(&err);
- dbus_connection_unref(conn);
- return NULL;
+ if (error != NULL) {
+ if (dbus_error_is_set(error) == TRUE) {
+ dbus_connection_unref(conn);
+ return NULL;
+ }
}
}
- if (!disconnect_cb)
- return conn;
+ setup_dbus_with_main_loop(conn);
+
+ return conn;
+}
+
+gboolean g_dbus_set_disconnect_function(DBusConnection *connection,
+ GDBusDisconnectFunction function,
+ void *user_data, DBusFreeFunction destroy)
+{
+ struct disconnect_data *dc_data;
dc_data = g_new(struct disconnect_data, 1);
- dc_data->disconnect_cb = disconnect_cb;
+ dc_data->disconnect_cb = function;
dc_data->user_data = user_data;
- dbus_connection_set_exit_on_disconnect(conn, FALSE);
+ dbus_connection_set_exit_on_disconnect(connection, FALSE);
- if (!dbus_connection_add_filter(conn, disconnect_filter,
- dc_data, g_free)) {
+ if (dbus_connection_add_filter(connection, disconnect_filter,
+ dc_data, g_free) == FALSE) {
error("Can't add D-Bus disconnect filter");
g_free(dc_data);
- dbus_connection_unref(conn);
- return NULL;
+ return FALSE;
}
- return conn;
-}
-
-DBusConnection *dbus_bus_system_setup_with_main_loop(const char *name,
- void (*disconnect_cb)(void *), void *user_data)
-{
- return init_dbus(name, disconnect_cb, user_data);
+ return TRUE;
}