[glib/wip/kdbus-junk: 19/37] [kdbus] Integrate acquiring and releasing names on kdbus with GLib core
- From: Ryan Lortie <desrt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/kdbus-junk: 19/37] [kdbus] Integrate acquiring and releasing names on kdbus with GLib core
- Date: Wed, 10 Dec 2014 15:58:48 +0000 (UTC)
commit 679fdbc5e33db8145ffd1887edf560883a7891bc
Author: Lukasz Skalski <l skalski samsung com>
Date: Thu Oct 23 11:11:08 2014 +0000
[kdbus] Integrate acquiring and releasing names on kdbus with GLib core
Now it's possible to use GLib API for owning bus names, like:
g_bus_own_name() or g_bus_own_name_on_connection(). It is not yet
fully functional until I'll add 'Add Match' method on kdbus, so
g_bus_unown_name() still doesn't invoke proper handler, when 'name'
is lost - work in progress.
gio/gdbusnameowning.c | 126 ++++++++++++++++++++++++++++++++-----------------
gio/gkdbus.c | 18 ++++++-
2 files changed, 98 insertions(+), 46 deletions(-)
---
diff --git a/gio/gdbusnameowning.c b/gio/gdbusnameowning.c
index cb7cb09..d39faea 100644
--- a/gio/gdbusnameowning.c
+++ b/gio/gdbusnameowning.c
@@ -28,6 +28,10 @@
#include "gdbusprivate.h"
#include "gdbusconnection.h"
+#ifdef G_OS_UNIX
+#include "gkdbusconnection.h"
+#endif
+
#include "glibintl.h"
/**
@@ -296,28 +300,11 @@ on_name_lost_or_acquired (GDBusConnection *connection,
/* ---------------------------------------------------------------------------------------------------- */
static void
-request_name_cb (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
+process_request_name_reply (Client *client,
+ guint32 request_name_reply)
{
- Client *client = user_data;
- GVariant *result;
- guint32 request_name_reply;
gboolean subscribe;
- request_name_reply = 0;
- result = NULL;
-
- /* don't use client->connection - it may be NULL already */
- result = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object),
- res,
- NULL);
- if (result != NULL)
- {
- g_variant_get (result, "(u)", &request_name_reply);
- g_variant_unref (result);
- }
-
subscribe = FALSE;
switch (request_name_reply)
@@ -387,6 +374,33 @@ request_name_cb (GObject *source_object,
g_object_unref (connection);
}
}
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static void
+request_name_cb (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ Client *client = user_data;
+ GVariant *result;
+ guint32 request_name_reply;
+
+ request_name_reply = 0;
+ result = NULL;
+
+ /* don't use client->connection - it may be NULL already */
+ result = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object),
+ res,
+ NULL);
+ if (result != NULL)
+ {
+ g_variant_get (result, "(u)", &request_name_reply);
+ g_variant_unref (result);
+ }
+
+ process_request_name_reply (client, request_name_reply);
client_unref (client);
}
@@ -428,20 +442,41 @@ has_connection (Client *client)
client);
/* attempt to acquire the name */
- g_dbus_connection_call (client->connection,
- "org.freedesktop.DBus", /* bus name */
- "/org/freedesktop/DBus", /* object path */
- "org.freedesktop.DBus", /* interface name */
- "RequestName", /* method name */
- g_variant_new ("(su)",
- client->name,
- client->flags),
- G_VARIANT_TYPE ("(u)"),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- (GAsyncReadyCallback) request_name_cb,
- client_ref (client));
+ if (G_IS_KDBUS_CONNECTION (g_dbus_connection_get_stream (client->connection)))
+ {
+ GVariant *result;
+ guint32 request_name_reply;
+
+ request_name_reply = 0;
+ result = NULL;
+
+ result = _g_kdbus_RequestName (client->connection, client->name, client->flags, NULL);
+
+ if (result != NULL)
+ {
+ g_variant_get (result, "(u)", &request_name_reply);
+ g_variant_unref (result);
+ }
+
+ process_request_name_reply (client, request_name_reply);
+ }
+ else
+ {
+ g_dbus_connection_call (client->connection,
+ "org.freedesktop.DBus", /* bus name */
+ "/org/freedesktop/DBus", /* object path */
+ "org.freedesktop.DBus", /* interface name */
+ "RequestName", /* method name */
+ g_variant_new ("(su)",
+ client->name,
+ client->flags),
+ G_VARIANT_TYPE ("(u)"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ (GAsyncReadyCallback) request_name_cb,
+ client_ref (client));
+ }
}
@@ -913,17 +948,20 @@ g_bus_unown_name (guint owner_id)
* I believe this is a bug in the bus daemon.
*/
error = NULL;
- result = g_dbus_connection_call_sync (client->connection,
- "org.freedesktop.DBus", /* bus name */
- "/org/freedesktop/DBus", /* object path */
- "org.freedesktop.DBus", /* interface name */
- "ReleaseName", /* method name */
- g_variant_new ("(s)", client->name),
- G_VARIANT_TYPE ("(u)"),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
+ if (G_IS_KDBUS_CONNECTION (g_dbus_connection_get_stream (client->connection)))
+ result = _g_kdbus_ReleaseName (client->connection, client->name, &error);
+ else
+ result = g_dbus_connection_call_sync (client->connection,
+ "org.freedesktop.DBus", /* bus name */
+ "/org/freedesktop/DBus", /* object path */
+ "org.freedesktop.DBus", /* interface name */
+ "ReleaseName", /* method name */
+ g_variant_new ("(s)", client->name),
+ G_VARIANT_TYPE ("(u)"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
if (result == NULL)
{
g_warning ("Error releasing name %s: %s", client->name, error->message);
diff --git a/gio/gkdbus.c b/gio/gkdbus.c
index 03c2d8e..312b34f 100644
--- a/gio/gkdbus.c
+++ b/gio/gkdbus.c
@@ -677,6 +677,7 @@ _g_kdbus_RequestName (GDBusConnection *connection,
len = strlen(name) + 1;
size = G_STRUCT_OFFSET (struct kdbus_cmd_name, items) + KDBUS_ITEM_SIZE(len);
kdbus_name = g_alloca0 (size);
+ kdbus_name->size = size;
kdbus_name->items[0].size = KDBUS_ITEM_HEADER_SIZE + len;
kdbus_name->items[0].type = KDBUS_ITEM_NAME;
kdbus_name->flags = kdbus_flags;
@@ -690,7 +691,13 @@ _g_kdbus_RequestName (GDBusConnection *connection,
else if (errno == EALREADY)
status = G_BUS_REQUEST_NAME_REPLY_ALREADY_OWNER;
else
- return FALSE;
+ {
+ g_set_error (error, G_IO_ERROR,
+ g_io_error_from_errno (errno),
+ _("Error while acquiring name: %s"),
+ g_strerror (errno));
+ return NULL;
+ }
}
if (kdbus_name->flags & KDBUS_NAME_IN_QUEUE)
@@ -750,6 +757,7 @@ _g_kdbus_ReleaseName (GDBusConnection *connection,
len = strlen(name) + 1;
size = G_STRUCT_OFFSET (struct kdbus_cmd_name, items) + KDBUS_ITEM_SIZE(len);
kdbus_name = g_alloca0 (size);
+ kdbus_name->size = size;
kdbus_name->items[0].size = KDBUS_ITEM_HEADER_SIZE + len;
kdbus_name->items[0].type = KDBUS_ITEM_NAME;
memcpy (kdbus_name->items[0].str, name, len);
@@ -762,7 +770,13 @@ _g_kdbus_ReleaseName (GDBusConnection *connection,
else if (errno == EADDRINUSE)
status = G_BUS_RELEASE_NAME_REPLY_NOT_OWNER;
else
- return FALSE;
+ {
+ g_set_error (error, G_IO_ERROR,
+ g_io_error_from_errno (errno),
+ _("Error while releasing name: %s"),
+ g_strerror (errno));
+ return NULL;
+ }
}
result = g_variant_new ("(u)", status);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]