From 9b05e0bc3e88f9e54710aabb2ad29908739e6345 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 11 May 2010 21:30:53 -0400 Subject: [PATCH] Complete the name owning section of the migration guide --- docs/reference/gio/migrating-gdbus.xml | 136 ++++++++++++++++++--------------- 1 file changed, 76 insertions(+), 60 deletions(-) diff --git a/docs/reference/gio/migrating-gdbus.xml b/docs/reference/gio/migrating-gdbus.xml index 1f33e02..8217426 100644 --- a/docs/reference/gio/migrating-gdbus.xml +++ b/docs/reference/gio/migrating-gdbus.xml @@ -74,75 +74,91 @@ Using dbus-glib, you typically call RequestName manually to own a name, like in the following excerpt: message); - g_error_free (error); - } - else { - g_warning ("Failed to acquire %s", NAME_TO_CLAIM); - } - goto out; + error = NULL; + res = dbus_g_proxy_call (system_bus_proxy, + "RequestName", + &error, + G_TYPE_STRING, NAME_TO_CLAIM, + G_TYPE_UINT, DBUS_NAME_FLAG_ALLOW_REPLACEMENT, + G_TYPE_INVALID, + G_TYPE_UINT, &result, + G_TYPE_INVALID); + if (!res) + { + if (error != NULL) + { + g_warning ("Failed to acquire %s: %s", + NAME_TO_CLAIM, error->message); + g_error_free (error); } + else + { + g_warning ("Failed to acquire %s", NAME_TO_CLAIM); + } + goto out; + } - if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { - if (error != NULL) { - g_warning ("Failed to acquire %s: %s", - NAME_TO_CLAIM, error->message); - g_error_free (error); - } - else { - g_warning ("Failed to acquire %s", NAME_TO_CLAIM); - } - goto out; + if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) + { + if (error != NULL) + { + g_warning ("Failed to acquire %s: %s", + NAME_TO_CLAIM, error->message); + g_error_free (error); + } + else + { + g_warning ("Failed to acquire %s", NAME_TO_CLAIM); } + exit (1); + } - dbus_g_proxy_add_signal (system_bus_proxy, "NameLost", - G_TYPE_STRING, G_TYPE_INVALID); - dbus_g_proxy_connect_signal (system_bus_proxy, "NameLost", - G_CALLBACK (name_lost), NULL, NULL); - ret = TRUE; -out: - return ret; -} + dbus_g_proxy_add_signal (system_bus_proxy, "NameLost", + G_TYPE_STRING, G_TYPE_INVALID); + dbus_g_proxy_connect_signal (system_bus_proxy, "NameLost", + G_CALLBACK (on_name_lost), NULL, NULL); + + /* further setup ... */ ]]> - While you can do things this way with GDBus too, it is much nicer - to use the high-level API for this: - - ...insert example here... + While you can do things this way with GDBus too, using + g_dbus_proxy_call_sync(), it is much nicer to use the high-level API + for this: + + Note that g_bus_own_name() works asynchronously and requires + you to enter your mainloop to await the on_name_aquired() + callback. Also note that in order to avoid race conditions (e.g. + when your service is activated by a method call), you have to export + your manager object before acquiring the + name. The on_bus_acquired() callback is the right place to do + such preparations. +
-- 2.7.4