1 /* GDBus - GLib D-Bus Library
3 * Copyright (C) 2008-2010 Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 * Author: David Zeuthen <davidz@redhat.com>
25 #include "gdbusutils.h"
26 #include "gdbusnameowning.h"
27 #include "gdbuserror.h"
28 #include "gdbusprivate.h"
29 #include "gdbusconnection.h"
32 #include "gkdbusconnection.h"
38 * SECTION:gdbusnameowning
39 * @title: Owning Bus Names
40 * @short_description: Simple API for owning bus names
43 * Convenience API for owning bus names.
45 * A simple example for owning a name can be found in
46 * [gdbus-example-own-name.c](https://git.gnome.org/browse/glib/tree/gio/tests/gdbus-example-own-name.c)
49 G_LOCK_DEFINE_STATIC (lock);
51 /* ---------------------------------------------------------------------------------------------------- */
55 PREVIOUS_CALL_NONE = 0,
56 PREVIOUS_CALL_ACQUIRED,
62 volatile gint ref_count;
64 GBusNameOwnerFlags flags;
66 GBusAcquiredCallback bus_acquired_handler;
67 GBusNameAcquiredCallback name_acquired_handler;
68 GBusNameLostCallback name_lost_handler;
70 GDestroyNotify user_data_free_func;
71 GMainContext *main_context;
73 PreviousCall previous_call;
75 GDBusConnection *connection;
76 gulong disconnected_signal_handler_id;
77 guint name_acquired_subscription_id;
78 guint name_lost_subscription_id;
80 volatile gboolean cancelled; /* must hold lock when reading or modifying */
82 gboolean needs_release;
85 static guint next_global_id = 1;
86 static GHashTable *map_id_to_client = NULL;
90 client_ref (Client *client)
92 g_atomic_int_inc (&client->ref_count);
97 client_unref (Client *client)
99 if (g_atomic_int_dec_and_test (&client->ref_count))
101 if (client->connection != NULL)
103 if (client->disconnected_signal_handler_id > 0)
104 g_signal_handler_disconnect (client->connection, client->disconnected_signal_handler_id);
105 if (client->name_acquired_subscription_id > 0)
106 g_dbus_connection_signal_unsubscribe (client->connection, client->name_acquired_subscription_id);
107 if (client->name_lost_subscription_id > 0)
108 g_dbus_connection_signal_unsubscribe (client->connection, client->name_lost_subscription_id);
109 g_object_unref (client->connection);
111 g_main_context_unref (client->main_context);
112 g_free (client->name);
113 if (client->user_data_free_func != NULL)
114 client->user_data_free_func (client->user_data);
119 /* ---------------------------------------------------------------------------------------------------- */
124 CALL_TYPE_NAME_ACQUIRED,
132 /* keep this separate because client->connection may
133 * be set to NULL after scheduling the call
135 GDBusConnection *connection;
137 /* set to TRUE to call acquired */
142 call_handler_data_free (CallHandlerData *data)
144 if (data->connection != NULL)
145 g_object_unref (data->connection);
146 client_unref (data->client);
151 actually_do_call (Client *client, GDBusConnection *connection, CallType call_type)
155 case CALL_TYPE_NAME_ACQUIRED:
156 if (client->name_acquired_handler != NULL)
158 client->name_acquired_handler (connection,
164 case CALL_TYPE_NAME_LOST:
165 if (client->name_lost_handler != NULL)
167 client->name_lost_handler (connection,
174 g_assert_not_reached ();
180 call_in_idle_cb (gpointer _data)
182 CallHandlerData *data = _data;
183 actually_do_call (data->client, data->connection, data->call_type);
188 schedule_call_in_idle (Client *client, CallType call_type)
190 CallHandlerData *data;
191 GSource *idle_source;
193 data = g_new0 (CallHandlerData, 1);
194 data->client = client_ref (client);
195 data->connection = client->connection != NULL ? g_object_ref (client->connection) : NULL;
196 data->call_type = call_type;
198 idle_source = g_idle_source_new ();
199 g_source_set_priority (idle_source, G_PRIORITY_HIGH);
200 g_source_set_callback (idle_source,
203 (GDestroyNotify) call_handler_data_free);
204 g_source_set_name (idle_source, "[gio] call_in_idle_cb");
205 g_source_attach (idle_source, client->main_context);
206 g_source_unref (idle_source);
210 do_call (Client *client, CallType call_type)
212 GMainContext *current_context;
214 /* only schedule in idle if we're not in the right thread */
215 current_context = g_main_context_ref_thread_default ();
216 if (current_context != client->main_context)
217 schedule_call_in_idle (client, call_type);
219 actually_do_call (client, client->connection, call_type);
220 g_main_context_unref (current_context);
224 call_acquired_handler (Client *client)
227 if (client->previous_call != PREVIOUS_CALL_ACQUIRED)
229 client->previous_call = PREVIOUS_CALL_ACQUIRED;
230 if (!client->cancelled)
233 do_call (client, CALL_TYPE_NAME_ACQUIRED);
243 call_lost_handler (Client *client)
246 if (client->previous_call != PREVIOUS_CALL_LOST)
248 client->previous_call = PREVIOUS_CALL_LOST;
249 if (!client->cancelled)
252 do_call (client, CALL_TYPE_NAME_LOST);
261 /* ---------------------------------------------------------------------------------------------------- */
264 on_name_lost_or_acquired (GDBusConnection *connection,
265 const gchar *sender_name,
266 const gchar *object_path,
267 const gchar *interface_name,
268 const gchar *signal_name,
269 GVariant *parameters,
272 Client *client = user_data;
275 if (g_strcmp0 (object_path, "/org/freedesktop/DBus") != 0 ||
276 g_strcmp0 (interface_name, "org.freedesktop.DBus") != 0 ||
277 g_strcmp0 (sender_name, "org.freedesktop.DBus") != 0)
280 if (g_strcmp0 (signal_name, "NameLost") == 0)
282 g_variant_get (parameters, "(&s)", &name);
283 if (g_strcmp0 (name, client->name) == 0)
285 call_lost_handler (client);
288 else if (g_strcmp0 (signal_name, "NameAcquired") == 0)
290 g_variant_get (parameters, "(&s)", &name);
291 if (g_strcmp0 (name, client->name) == 0)
293 call_acquired_handler (client);
300 /* ---------------------------------------------------------------------------------------------------- */
303 process_request_name_reply (Client *client,
304 guint32 request_name_reply)
310 switch (request_name_reply)
312 case 1: /* DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER */
313 /* We got the name - now listen for NameLost and NameAcquired */
314 call_acquired_handler (client);
316 client->needs_release = TRUE;
319 case 2: /* DBUS_REQUEST_NAME_REPLY_IN_QUEUE */
320 /* Waiting in line - listen for NameLost and NameAcquired */
321 call_lost_handler (client);
323 client->needs_release = TRUE;
327 /* assume we couldn't get the name - explicit fallthrough */
328 case 3: /* DBUS_REQUEST_NAME_REPLY_EXISTS */
329 case 4: /* DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER */
330 /* Some other part of the process is already owning the name */
331 call_lost_handler (client);
338 GDBusConnection *connection = NULL;
340 /* if cancelled, there is no point in subscribing to signals - if not, make sure
341 * we use a known good Connection object since it may be set to NULL at any point
342 * after being cancelled
345 if (!client->cancelled)
346 connection = g_object_ref (client->connection);
349 /* start listening to NameLost and NameAcquired messages */
350 if (connection != NULL)
352 client->name_lost_subscription_id =
353 g_dbus_connection_signal_subscribe (connection,
354 "org.freedesktop.DBus",
355 "org.freedesktop.DBus",
357 "/org/freedesktop/DBus",
359 G_DBUS_SIGNAL_FLAGS_NONE,
360 on_name_lost_or_acquired,
363 client->name_acquired_subscription_id =
364 g_dbus_connection_signal_subscribe (connection,
365 "org.freedesktop.DBus",
366 "org.freedesktop.DBus",
368 "/org/freedesktop/DBus",
370 G_DBUS_SIGNAL_FLAGS_NONE,
371 on_name_lost_or_acquired,
374 g_object_unref (connection);
379 /* ---------------------------------------------------------------------------------------------------- */
382 request_name_cb (GObject *source_object,
386 Client *client = user_data;
388 guint32 request_name_reply;
390 request_name_reply = 0;
393 /* don't use client->connection - it may be NULL already */
394 result = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object),
399 g_variant_get (result, "(u)", &request_name_reply);
400 g_variant_unref (result);
403 process_request_name_reply (client, request_name_reply);
405 client_unref (client);
408 /* ---------------------------------------------------------------------------------------------------- */
411 on_connection_disconnected (GDBusConnection *connection,
412 gboolean remote_peer_vanished,
416 Client *client = user_data;
418 if (client->disconnected_signal_handler_id > 0)
419 g_signal_handler_disconnect (client->connection, client->disconnected_signal_handler_id);
420 if (client->name_acquired_subscription_id > 0)
421 g_dbus_connection_signal_unsubscribe (client->connection, client->name_acquired_subscription_id);
422 if (client->name_lost_subscription_id > 0)
423 g_dbus_connection_signal_unsubscribe (client->connection, client->name_lost_subscription_id);
424 g_object_unref (client->connection);
425 client->disconnected_signal_handler_id = 0;
426 client->name_acquired_subscription_id = 0;
427 client->name_lost_subscription_id = 0;
428 client->connection = NULL;
430 call_lost_handler (client);
433 /* ---------------------------------------------------------------------------------------------------- */
436 has_connection (Client *client)
438 /* listen for disconnection */
439 client->disconnected_signal_handler_id = g_signal_connect (client->connection,
441 G_CALLBACK (on_connection_disconnected),
444 /* attempt to acquire the name */
445 if (G_IS_KDBUS_CONNECTION (g_dbus_connection_get_stream (client->connection)))
448 guint32 request_name_reply;
450 request_name_reply = 0;
453 result = _g_kdbus_RequestName (client->connection, client->name, client->flags, NULL);
457 g_variant_get (result, "(u)", &request_name_reply);
458 g_variant_unref (result);
461 process_request_name_reply (client, request_name_reply);
465 g_dbus_connection_call (client->connection,
466 "org.freedesktop.DBus", /* bus name */
467 "/org/freedesktop/DBus", /* object path */
468 "org.freedesktop.DBus", /* interface name */
469 "RequestName", /* method name */
470 g_variant_new ("(su)",
473 G_VARIANT_TYPE ("(u)"),
474 G_DBUS_CALL_FLAGS_NONE,
477 (GAsyncReadyCallback) request_name_cb,
478 client_ref (client));
484 connection_get_cb (GObject *source_object,
488 Client *client = user_data;
490 /* must not do anything if already cancelled */
492 if (client->cancelled)
499 client->connection = g_bus_get_finish (res, NULL);
500 if (client->connection == NULL)
502 call_lost_handler (client);
506 /* No need to schedule this in idle as we're already in the thread
507 * that the user called g_bus_own_name() from. This is because
508 * g_bus_get() guarantees that.
510 * Also, we need to ensure that the handler is invoked *before*
511 * we call RequestName(). Otherwise there is a race.
513 if (client->bus_acquired_handler != NULL)
515 client->bus_acquired_handler (client->connection,
520 has_connection (client);
523 client_unref (client);
526 /* ---------------------------------------------------------------------------------------------------- */
529 * g_bus_own_name_on_connection:
530 * @connection: a #GDBusConnection
531 * @name: the well-known name to own
532 * @flags: a set of flags from the #GBusNameOwnerFlags enumeration
533 * @name_acquired_handler: (allow-none): handler to invoke when @name is acquired or %NULL
534 * @name_lost_handler: (allow-none): handler to invoke when @name is lost or %NULL
535 * @user_data: user data to pass to handlers
536 * @user_data_free_func: (allow-none): function for freeing @user_data or %NULL
538 * Like g_bus_own_name() but takes a #GDBusConnection instead of a
541 * Returns: an identifier (never 0) that an be used with
542 * g_bus_unown_name() to stop owning the name
547 g_bus_own_name_on_connection (GDBusConnection *connection,
549 GBusNameOwnerFlags flags,
550 GBusNameAcquiredCallback name_acquired_handler,
551 GBusNameLostCallback name_lost_handler,
553 GDestroyNotify user_data_free_func)
557 g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), 0);
558 g_return_val_if_fail (g_dbus_is_name (name) && !g_dbus_is_unique_name (name), 0);
562 client = g_new0 (Client, 1);
563 client->ref_count = 1;
564 client->id = next_global_id++; /* TODO: uh oh, handle overflow */
565 client->name = g_strdup (name);
566 client->flags = flags;
567 client->name_acquired_handler = name_acquired_handler;
568 client->name_lost_handler = name_lost_handler;
569 client->user_data = user_data;
570 client->user_data_free_func = user_data_free_func;
571 client->main_context = g_main_context_ref_thread_default ();
573 client->connection = g_object_ref (connection);
575 if (map_id_to_client == NULL)
577 map_id_to_client = g_hash_table_new (g_direct_hash, g_direct_equal);
579 g_hash_table_insert (map_id_to_client,
580 GUINT_TO_POINTER (client->id),
585 has_connection (client);
592 * @bus_type: the type of bus to own a name on
593 * @name: the well-known name to own
594 * @flags: a set of flags from the #GBusNameOwnerFlags enumeration
595 * @bus_acquired_handler: (allow-none): handler to invoke when connected to the bus of type @bus_type or %NULL
596 * @name_acquired_handler: (allow-none): handler to invoke when @name is acquired or %NULL
597 * @name_lost_handler: (allow-none): handler to invoke when @name is lost or %NULL
598 * @user_data: user data to pass to handlers
599 * @user_data_free_func: (allow-none): function for freeing @user_data or %NULL
601 * Starts acquiring @name on the bus specified by @bus_type and calls
602 * @name_acquired_handler and @name_lost_handler when the name is
603 * acquired respectively lost. Callbacks will be invoked in the
604 * [thread-default main context][g-main-context-push-thread-default]
605 * of the thread you are calling this function from.
607 * You are guaranteed that one of the @name_acquired_handler and @name_lost_handler
608 * callbacks will be invoked after calling this function - there are three
611 * - @name_lost_handler with a %NULL connection (if a connection to the bus
614 * - @bus_acquired_handler then @name_lost_handler (if the name can't be
617 * - @bus_acquired_handler then @name_acquired_handler (if the name was
620 * When you are done owning the name, just call g_bus_unown_name()
621 * with the owner id this function returns.
623 * If the name is acquired or lost (for example another application
624 * could acquire the name if you allow replacement or the application
625 * currently owning the name exits), the handlers are also invoked.
626 * If the #GDBusConnection that is used for attempting to own the name
627 * closes, then @name_lost_handler is invoked since it is no longer
628 * possible for other processes to access the process.
630 * You cannot use g_bus_own_name() several times for the same name (unless
631 * interleaved with calls to g_bus_unown_name()) - only the first call
634 * Another guarantee is that invocations of @name_acquired_handler
635 * and @name_lost_handler are guaranteed to alternate; that
636 * is, if @name_acquired_handler is invoked then you are
637 * guaranteed that the next time one of the handlers is invoked, it
638 * will be @name_lost_handler. The reverse is also true.
640 * If you plan on exporting objects (using e.g.
641 * g_dbus_connection_register_object()), note that it is generally too late
642 * to export the objects in @name_acquired_handler. Instead, you can do this
643 * in @bus_acquired_handler since you are guaranteed that this will run
644 * before @name is requested from the bus.
646 * This behavior makes it very simple to write applications that wants
647 * to [own names][gdbus-owning-names] and export objects.
648 * Simply register objects to be exported in @bus_acquired_handler and
649 * unregister the objects (if any) in @name_lost_handler.
651 * Returns: an identifier (never 0) that an be used with
652 * g_bus_unown_name() to stop owning the name.
657 g_bus_own_name (GBusType bus_type,
659 GBusNameOwnerFlags flags,
660 GBusAcquiredCallback bus_acquired_handler,
661 GBusNameAcquiredCallback name_acquired_handler,
662 GBusNameLostCallback name_lost_handler,
664 GDestroyNotify user_data_free_func)
668 g_return_val_if_fail (g_dbus_is_name (name) && !g_dbus_is_unique_name (name), 0);
672 client = g_new0 (Client, 1);
673 client->ref_count = 1;
674 client->id = next_global_id++; /* TODO: uh oh, handle overflow */
675 client->name = g_strdup (name);
676 client->flags = flags;
677 client->bus_acquired_handler = bus_acquired_handler;
678 client->name_acquired_handler = name_acquired_handler;
679 client->name_lost_handler = name_lost_handler;
680 client->user_data = user_data;
681 client->user_data_free_func = user_data_free_func;
682 client->main_context = g_main_context_ref_thread_default ();
684 if (map_id_to_client == NULL)
686 map_id_to_client = g_hash_table_new (g_direct_hash, g_direct_equal);
688 g_hash_table_insert (map_id_to_client,
689 GUINT_TO_POINTER (client->id),
695 client_ref (client));
703 GClosure *bus_acquired_closure;
704 GClosure *name_acquired_closure;
705 GClosure *name_lost_closure;
709 own_name_data_new (GClosure *bus_acquired_closure,
710 GClosure *name_acquired_closure,
711 GClosure *name_lost_closure)
715 data = g_new0 (OwnNameData, 1);
717 if (bus_acquired_closure != NULL)
719 data->bus_acquired_closure = g_closure_ref (bus_acquired_closure);
720 g_closure_sink (bus_acquired_closure);
721 if (G_CLOSURE_NEEDS_MARSHAL (bus_acquired_closure))
722 g_closure_set_marshal (bus_acquired_closure, g_cclosure_marshal_generic);
725 if (name_acquired_closure != NULL)
727 data->name_acquired_closure = g_closure_ref (name_acquired_closure);
728 g_closure_sink (name_acquired_closure);
729 if (G_CLOSURE_NEEDS_MARSHAL (name_acquired_closure))
730 g_closure_set_marshal (name_acquired_closure, g_cclosure_marshal_generic);
733 if (name_lost_closure != NULL)
735 data->name_lost_closure = g_closure_ref (name_lost_closure);
736 g_closure_sink (name_lost_closure);
737 if (G_CLOSURE_NEEDS_MARSHAL (name_lost_closure))
738 g_closure_set_marshal (name_lost_closure, g_cclosure_marshal_generic);
745 own_with_closures_on_bus_acquired (GDBusConnection *connection,
749 OwnNameData *data = user_data;
750 GValue params[2] = { G_VALUE_INIT, G_VALUE_INIT };
752 g_value_init (¶ms[0], G_TYPE_DBUS_CONNECTION);
753 g_value_set_object (¶ms[0], connection);
755 g_value_init (¶ms[1], G_TYPE_STRING);
756 g_value_set_string (¶ms[1], name);
758 g_closure_invoke (data->bus_acquired_closure, NULL, 2, params, NULL);
760 g_value_unset (params + 0);
761 g_value_unset (params + 1);
765 own_with_closures_on_name_acquired (GDBusConnection *connection,
769 OwnNameData *data = user_data;
770 GValue params[2] = { G_VALUE_INIT, G_VALUE_INIT };
772 g_value_init (¶ms[0], G_TYPE_DBUS_CONNECTION);
773 g_value_set_object (¶ms[0], connection);
775 g_value_init (¶ms[1], G_TYPE_STRING);
776 g_value_set_string (¶ms[1], name);
778 g_closure_invoke (data->name_acquired_closure, NULL, 2, params, NULL);
780 g_value_unset (params + 0);
781 g_value_unset (params + 1);
785 own_with_closures_on_name_lost (GDBusConnection *connection,
789 OwnNameData *data = user_data;
790 GValue params[2] = { G_VALUE_INIT, G_VALUE_INIT };
792 g_value_init (¶ms[0], G_TYPE_DBUS_CONNECTION);
793 g_value_set_object (¶ms[0], connection);
795 g_value_init (¶ms[1], G_TYPE_STRING);
796 g_value_set_string (¶ms[1], name);
798 g_closure_invoke (data->name_lost_closure, NULL, 2, params, NULL);
800 g_value_unset (params + 0);
801 g_value_unset (params + 1);
805 bus_own_name_free_func (gpointer user_data)
807 OwnNameData *data = user_data;
809 if (data->bus_acquired_closure != NULL)
810 g_closure_unref (data->bus_acquired_closure);
812 if (data->name_acquired_closure != NULL)
813 g_closure_unref (data->name_acquired_closure);
815 if (data->name_lost_closure != NULL)
816 g_closure_unref (data->name_lost_closure);
822 * g_bus_own_name_with_closures:
823 * @bus_type: the type of bus to own a name on
824 * @name: the well-known name to own
825 * @flags: a set of flags from the #GBusNameOwnerFlags enumeration
826 * @bus_acquired_closure: (allow-none): #GClosure to invoke when connected to
827 * the bus of type @bus_type or %NULL
828 * @name_acquired_closure: (allow-none): #GClosure to invoke when @name is
830 * @name_lost_closure: (allow-none): #GClosure to invoke when @name is lost or
833 * Version of g_bus_own_name() using closures instead of callbacks for
834 * easier binding in other languages.
836 * Returns: an identifier (never 0) that an be used with
837 * g_bus_unown_name() to stop owning the name.
839 * Rename to: g_bus_own_name
844 g_bus_own_name_with_closures (GBusType bus_type,
846 GBusNameOwnerFlags flags,
847 GClosure *bus_acquired_closure,
848 GClosure *name_acquired_closure,
849 GClosure *name_lost_closure)
851 return g_bus_own_name (bus_type,
854 bus_acquired_closure != NULL ? own_with_closures_on_bus_acquired : NULL,
855 name_acquired_closure != NULL ? own_with_closures_on_name_acquired : NULL,
856 name_lost_closure != NULL ? own_with_closures_on_name_lost : NULL,
857 own_name_data_new (bus_acquired_closure,
858 name_acquired_closure,
860 bus_own_name_free_func);
864 * g_bus_own_name_on_connection_with_closures:
865 * @connection: a #GDBusConnection
866 * @name: the well-known name to own
867 * @flags: a set of flags from the #GBusNameOwnerFlags enumeration
868 * @name_acquired_closure: (allow-none): #GClosure to invoke when @name is
870 * @name_lost_closure: (allow-none): #GClosure to invoke when @name is lost
873 * Version of g_bus_own_name_on_connection() using closures instead of
874 * callbacks for easier binding in other languages.
876 * Returns: an identifier (never 0) that an be used with
877 * g_bus_unown_name() to stop owning the name.
879 * Rename to: g_bus_own_name_on_connection
884 g_bus_own_name_on_connection_with_closures (GDBusConnection *connection,
886 GBusNameOwnerFlags flags,
887 GClosure *name_acquired_closure,
888 GClosure *name_lost_closure)
890 return g_bus_own_name_on_connection (connection,
893 name_acquired_closure != NULL ? own_with_closures_on_name_acquired : NULL,
894 name_lost_closure != NULL ? own_with_closures_on_name_lost : NULL,
895 own_name_data_new (NULL,
896 name_acquired_closure,
898 bus_own_name_free_func);
903 * @owner_id: an identifier obtained from g_bus_own_name()
905 * Stops owning a name.
910 g_bus_unown_name (guint owner_id)
914 g_return_if_fail (owner_id > 0);
919 if (owner_id == 0 || map_id_to_client == NULL ||
920 (client = g_hash_table_lookup (map_id_to_client, GUINT_TO_POINTER (owner_id))) == NULL)
922 g_warning ("Invalid id %d passed to g_bus_unown_name()", owner_id);
926 client->cancelled = TRUE;
927 g_warn_if_fail (g_hash_table_remove (map_id_to_client, GUINT_TO_POINTER (owner_id)));
932 /* do callback without holding lock */
935 /* Release the name if needed */
936 if (client->needs_release &&
937 client->connection != NULL &&
938 !g_dbus_connection_is_closed (client->connection))
942 guint32 release_name_reply;
944 /* TODO: it kinda sucks having to do a sync call to release the name - but if
945 * we don't, then a subsequent grab of the name will make the bus daemon return
946 * IN_QUEUE which will trigger name_lost().
948 * I believe this is a bug in the bus daemon.
951 if (G_IS_KDBUS_CONNECTION (g_dbus_connection_get_stream (client->connection)))
952 result = _g_kdbus_ReleaseName (client->connection, client->name, &error);
954 result = g_dbus_connection_call_sync (client->connection,
955 "org.freedesktop.DBus", /* bus name */
956 "/org/freedesktop/DBus", /* object path */
957 "org.freedesktop.DBus", /* interface name */
958 "ReleaseName", /* method name */
959 g_variant_new ("(s)", client->name),
960 G_VARIANT_TYPE ("(u)"),
961 G_DBUS_CALL_FLAGS_NONE,
967 g_warning ("Error releasing name %s: %s", client->name, error->message);
968 g_error_free (error);
972 g_variant_get (result, "(u)", &release_name_reply);
973 if (release_name_reply != 1 /* DBUS_RELEASE_NAME_REPLY_RELEASED */)
975 g_warning ("Unexpected reply %d when releasing name %s", release_name_reply, client->name);
977 g_variant_unref (result);
981 if (client->disconnected_signal_handler_id > 0)
982 g_signal_handler_disconnect (client->connection, client->disconnected_signal_handler_id);
983 if (client->name_acquired_subscription_id > 0)
984 g_dbus_connection_signal_unsubscribe (client->connection, client->name_acquired_subscription_id);
985 if (client->name_lost_subscription_id > 0)
986 g_dbus_connection_signal_unsubscribe (client->connection, client->name_lost_subscription_id);
987 client->disconnected_signal_handler_id = 0;
988 client->name_acquired_subscription_id = 0;
989 client->name_lost_subscription_id = 0;
990 if (client->connection != NULL)
992 g_object_unref (client->connection);
993 client->connection = NULL;
996 client_unref (client);