/* ---------------------------------------------------------------------------------------------------- */
static void
-process_request_name_reply (Client *client,
- GBusRequestNameReplyFlags request_name_reply)
+request_name_cb (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
{
+ 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)
{
- case G_BUS_REQUEST_NAME_FLAGS_PRIMARY_OWNER:
+ case 1: /* DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER */
/* We got the name - now listen for NameLost and NameAcquired */
call_acquired_handler (client);
subscribe = TRUE;
client->needs_release = TRUE;
break;
- case G_BUS_REQUEST_NAME_FLAGS_IN_QUEUE:
+ case 2: /* DBUS_REQUEST_NAME_REPLY_IN_QUEUE */
/* Waiting in line - listen for NameLost and NameAcquired */
call_lost_handler (client);
subscribe = TRUE;
default:
/* assume we couldn't get the name - explicit fallthrough */
- case G_BUS_REQUEST_NAME_FLAGS_EXISTS:
- case G_BUS_REQUEST_NAME_FLAGS_ALREADY_OWNER:
+ case 3: /* DBUS_REQUEST_NAME_REPLY_EXISTS */
+ case 4: /* DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER */
/* Some other part of the process is already owning the name */
call_lost_handler (client);
break;
g_object_unref (connection);
}
}
+
+ client_unref (client);
}
/* ---------------------------------------------------------------------------------------------------- */
static void
has_connection (Client *client)
{
- GError *error = NULL;
- GBusRequestNameReplyFlags request_name_reply;
-
- request_name_reply = G_BUS_REQUEST_NAME_FLAGS_ERROR;
-
/* listen for disconnection */
client->disconnected_signal_handler_id = g_signal_connect (client->connection,
"closed",
G_CALLBACK (on_connection_disconnected),
client);
- /* attempt to acquire the name */
- request_name_reply = g_dbus_request_name (client->connection, client->name, client->flags, &error);
- if (request_name_reply == G_BUS_REQUEST_NAME_FLAGS_ERROR)
- {
- g_warning ("Error requesting name %s: %s", client->name, error->message);
- g_error_free (error);
- }
- process_request_name_reply (client, request_name_reply);
+ /* 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));
}
client->connection != NULL &&
!g_dbus_connection_is_closed (client->connection))
{
- GBusReleaseNameReplyFlags release_name_reply;
+ GVariant *result;
GError *error;
-
- error = NULL;
+ guint32 release_name_reply;
/* TODO: it kinda sucks having to do a sync call to release the name - but if
* we don't, then a subsequent grab of the name will make the bus daemon return
*
* I believe this is a bug in the bus daemon.
*/
-
- release_name_reply = g_dbus_release_name (client->connection, client->name, &error);
- if (release_name_reply == G_BUS_RELEASE_NAME_FLAGS_ERROR)
+ 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 (result == NULL)
{
g_warning ("Error releasing name %s: %s", client->name, error->message);
g_error_free (error);
}
else
- if (release_name_reply != G_BUS_RELEASE_NAME_FLAGS_RELEASED)
- g_warning ("Unexpected reply %d when releasing name %s", release_name_reply, client->name);
+ {
+ g_variant_get (result, "(u)", &release_name_reply);
+ if (release_name_reply != 1 /* DBUS_RELEASE_NAME_REPLY_RELEASED */)
+ {
+ g_warning ("Unexpected reply %d when releasing name %s", release_name_reply, client->name);
+ }
+ g_variant_unref (result);
+ }
}
if (client->disconnected_signal_handler_id > 0)
/* ---------------------------------------------------------------------------------------------------- */
static void
-process_get_name_owner (Client *client,
- const char *name_owner)
-{
- if (name_owner != NULL)
- {
- g_warn_if_fail (client->name_owner == NULL);
- client->name_owner = g_strdup (name_owner);
- call_appeared_handler (client);
- }
- else
- call_vanished_handler (client, FALSE);
-
- client->initialized = TRUE;
-}
-
-static void
get_name_owner_cb (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
g_variant_get (result, "(&s)", &name_owner);
}
- process_get_name_owner (client, name_owner);
+ if (name_owner != NULL)
+ {
+ g_warn_if_fail (client->name_owner == NULL);
+ client->name_owner = g_strdup (name_owner);
+ call_appeared_handler (client);
+ }
+ else
+ {
+ call_vanished_handler (client, FALSE);
+ }
+
+ client->initialized = TRUE;
if (result != NULL)
g_variant_unref (result);
static void
invoke_get_name_owner (Client *client)
{
- if (_g_dbus_connection_is_kdbus (client->connection))
- {
- char *name_owner;
-
- name_owner = g_dbus_get_name_owner (client->connection,
- client->name,
- NULL);
- process_get_name_owner (client, name_owner);
- if (name_owner != NULL)
- g_free (name_owner);
- }
- else
- {
- g_dbus_connection_call (client->connection,
- "org.freedesktop.DBus", /* bus name */
- "/org/freedesktop/DBus", /* object path */
- "org.freedesktop.DBus", /* interface name */
- "GetNameOwner", /* method name */
- g_variant_new ("(s)", client->name),
- G_VARIANT_TYPE ("(s)"),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- (GAsyncReadyCallback) get_name_owner_cb,
- client_ref (client));
- }
+ g_dbus_connection_call (client->connection,
+ "org.freedesktop.DBus", /* bus name */
+ "/org/freedesktop/DBus", /* object path */
+ "org.freedesktop.DBus", /* interface name */
+ "GetNameOwner", /* method name */
+ g_variant_new ("(s)", client->name),
+ G_VARIANT_TYPE ("(s)"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ (GAsyncReadyCallback) get_name_owner_cb,
+ client_ref (client));
}
/* ---------------------------------------------------------------------------------------------------- */
static void
-process_start_service_by_name (Client *client,
- GBusStartServiceReplyFlags result)
-{
- if (result == G_BUS_START_SERVICE_REPLY_SUCCESS)
- invoke_get_name_owner (client);
- else if (result == G_BUS_START_SERVICE_REPLY_ALREADY_RUNNING)
- invoke_get_name_owner (client);
- else
- {
- g_warning ("Unexpected reply %d from StartServiceByName() method", result);
- call_vanished_handler (client, FALSE);
- client->initialized = TRUE;
- }
-}
-
-static void
start_service_by_name_cb (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
guint32 start_service_result;
g_variant_get (result, "(u)", &start_service_result);
- process_start_service_by_name (client, (GBusStartServiceReplyFlags) start_service_result);
+ if (start_service_result == 1) /* DBUS_START_REPLY_SUCCESS */
+ {
+ invoke_get_name_owner (client);
+ }
+ else if (start_service_result == 2) /* DBUS_START_REPLY_ALREADY_RUNNING */
+ {
+ invoke_get_name_owner (client);
+ }
+ else
+ {
+ g_warning ("Unexpected reply %d from StartServiceByName() method", start_service_result);
+ call_vanished_handler (client, FALSE);
+ client->initialized = TRUE;
+ }
}
else
{
if (client->flags & G_BUS_NAME_WATCHER_FLAGS_AUTO_START)
{
- if (_g_dbus_connection_is_kdbus (client->connection))
- {
- GBusStartServiceReplyFlags result;
-
- result = g_dbus_start_service_by_name (client->connection, client->name, 0, NULL);
- process_start_service_by_name (client, result);
- }
- else
- g_dbus_connection_call (client->connection,
- "org.freedesktop.DBus", /* bus name */
- "/org/freedesktop/DBus", /* object path */
- "org.freedesktop.DBus", /* interface name */
- "StartServiceByName", /* method name */
- g_variant_new ("(su)", client->name, 0),
- G_VARIANT_TYPE ("(u)"),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- (GAsyncReadyCallback) start_service_by_name_cb,
- client_ref (client));
+ g_dbus_connection_call (client->connection,
+ "org.freedesktop.DBus", /* bus name */
+ "/org/freedesktop/DBus", /* object path */
+ "org.freedesktop.DBus", /* interface name */
+ "StartServiceByName", /* method name */
+ g_variant_new ("(su)", client->name, 0),
+ G_VARIANT_TYPE ("(u)"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ (GAsyncReadyCallback) start_service_by_name_cb,
+ client_ref (client));
}
else
{