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"
34 * SECTION:gdbusnameowning
35 * @title: Owning Bus Names
36 * @short_description: Simple API for owning bus names
39 * Convenience API for owning bus names.
41 * <example id="gdbus-owning-names"><title>Simple application owning a name</title><programlisting><xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../../../gio/tests/gdbus-example-own-name.c"><xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback></xi:include></programlisting></example>
44 G_LOCK_DEFINE_STATIC (lock);
46 /* ---------------------------------------------------------------------------------------------------- */
50 PREVIOUS_CALL_NONE = 0,
51 PREVIOUS_CALL_ACQUIRED,
57 volatile gint ref_count;
59 GBusNameOwnerFlags flags;
61 GBusAcquiredCallback bus_acquired_handler;
62 GBusNameAcquiredCallback name_acquired_handler;
63 GBusNameLostCallback name_lost_handler;
65 GDestroyNotify user_data_free_func;
66 GMainContext *main_context;
68 PreviousCall previous_call;
70 GDBusConnection *connection;
71 gulong disconnected_signal_handler_id;
72 guint name_acquired_subscription_id;
73 guint name_lost_subscription_id;
75 volatile gboolean cancelled; /* must hold lock when reading or modifying */
77 gboolean needs_release;
80 static guint next_global_id = 1;
81 static GHashTable *map_id_to_client = NULL;
85 client_ref (Client *client)
87 g_atomic_int_inc (&client->ref_count);
92 client_unref (Client *client)
94 if (g_atomic_int_dec_and_test (&client->ref_count))
96 if (client->connection != NULL)
98 if (client->disconnected_signal_handler_id > 0)
99 g_signal_handler_disconnect (client->connection, client->disconnected_signal_handler_id);
100 if (client->name_acquired_subscription_id > 0)
101 g_dbus_connection_signal_unsubscribe (client->connection, client->name_acquired_subscription_id);
102 if (client->name_lost_subscription_id > 0)
103 g_dbus_connection_signal_unsubscribe (client->connection, client->name_lost_subscription_id);
104 g_object_unref (client->connection);
106 g_main_context_unref (client->main_context);
107 g_free (client->name);
108 if (client->user_data_free_func != NULL)
109 client->user_data_free_func (client->user_data);
114 /* ---------------------------------------------------------------------------------------------------- */
119 CALL_TYPE_NAME_ACQUIRED,
127 /* keep this separate because client->connection may
128 * be set to NULL after scheduling the call
130 GDBusConnection *connection;
132 /* set to TRUE to call acquired */
137 call_handler_data_free (CallHandlerData *data)
139 if (data->connection != NULL)
140 g_object_unref (data->connection);
141 client_unref (data->client);
146 actually_do_call (Client *client, GDBusConnection *connection, CallType call_type)
150 case CALL_TYPE_NAME_ACQUIRED:
151 if (client->name_acquired_handler != NULL)
153 client->name_acquired_handler (connection,
159 case CALL_TYPE_NAME_LOST:
160 if (client->name_lost_handler != NULL)
162 client->name_lost_handler (connection,
169 g_assert_not_reached ();
175 call_in_idle_cb (gpointer _data)
177 CallHandlerData *data = _data;
178 actually_do_call (data->client, data->connection, data->call_type);
183 schedule_call_in_idle (Client *client, CallType call_type)
185 CallHandlerData *data;
186 GSource *idle_source;
188 data = g_new0 (CallHandlerData, 1);
189 data->client = client_ref (client);
190 data->connection = client->connection != NULL ? g_object_ref (client->connection) : NULL;
191 data->call_type = call_type;
193 idle_source = g_idle_source_new ();
194 g_source_set_priority (idle_source, G_PRIORITY_HIGH);
195 g_source_set_callback (idle_source,
198 (GDestroyNotify) call_handler_data_free);
199 g_source_attach (idle_source, client->main_context);
200 g_source_unref (idle_source);
204 do_call (Client *client, CallType call_type)
206 GMainContext *current_context;
208 /* only schedule in idle if we're not in the right thread */
209 current_context = g_main_context_ref_thread_default ();
210 if (current_context != client->main_context)
211 schedule_call_in_idle (client, call_type);
213 actually_do_call (client, client->connection, call_type);
214 g_main_context_unref (current_context);
218 call_acquired_handler (Client *client)
221 if (client->previous_call != PREVIOUS_CALL_ACQUIRED)
223 client->previous_call = PREVIOUS_CALL_ACQUIRED;
224 if (!client->cancelled)
227 do_call (client, CALL_TYPE_NAME_ACQUIRED);
237 call_lost_handler (Client *client)
240 if (client->previous_call != PREVIOUS_CALL_LOST)
242 client->previous_call = PREVIOUS_CALL_LOST;
243 if (!client->cancelled)
246 do_call (client, CALL_TYPE_NAME_LOST);
255 /* ---------------------------------------------------------------------------------------------------- */
258 on_name_lost_or_acquired (GDBusConnection *connection,
259 const gchar *sender_name,
260 const gchar *object_path,
261 const gchar *interface_name,
262 const gchar *signal_name,
263 GVariant *parameters,
266 Client *client = user_data;
269 if (g_strcmp0 (object_path, "/org/freedesktop/DBus") != 0 ||
270 g_strcmp0 (interface_name, "org.freedesktop.DBus") != 0 ||
271 g_strcmp0 (sender_name, "org.freedesktop.DBus") != 0)
274 if (g_strcmp0 (signal_name, "NameLost") == 0)
276 g_variant_get (parameters, "(&s)", &name);
277 if (g_strcmp0 (name, client->name) == 0)
279 call_lost_handler (client);
282 else if (g_strcmp0 (signal_name, "NameAcquired") == 0)
284 g_variant_get (parameters, "(&s)", &name);
285 if (g_strcmp0 (name, client->name) == 0)
287 call_acquired_handler (client);
294 /* ---------------------------------------------------------------------------------------------------- */
297 request_name_cb (GObject *source_object,
301 Client *client = user_data;
303 guint32 request_name_reply;
306 request_name_reply = 0;
309 /* don't use client->connection - it may be NULL already */
310 result = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object),
315 g_variant_get (result, "(u)", &request_name_reply);
316 g_variant_unref (result);
321 switch (request_name_reply)
323 case 1: /* DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER */
324 /* We got the name - now listen for NameLost and NameAcquired */
325 call_acquired_handler (client);
327 client->needs_release = TRUE;
330 case 2: /* DBUS_REQUEST_NAME_REPLY_IN_QUEUE */
331 /* Waiting in line - listen for NameLost and NameAcquired */
332 call_lost_handler (client);
334 client->needs_release = TRUE;
338 /* assume we couldn't get the name - explicit fallthrough */
339 case 3: /* DBUS_REQUEST_NAME_REPLY_EXISTS */
340 case 4: /* DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER */
341 /* Some other part of the process is already owning the name */
342 call_lost_handler (client);
349 GDBusConnection *connection = NULL;
351 /* if cancelled, there is no point in subscribing to signals - if not, make sure
352 * we use a known good Connection object since it may be set to NULL at any point
353 * after being cancelled
356 if (!client->cancelled)
357 connection = g_object_ref (client->connection);
360 /* start listening to NameLost and NameAcquired messages */
361 if (connection != NULL)
363 client->name_lost_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 client->name_acquired_subscription_id =
375 g_dbus_connection_signal_subscribe (connection,
376 "org.freedesktop.DBus",
377 "org.freedesktop.DBus",
379 "/org/freedesktop/DBus",
381 G_DBUS_SIGNAL_FLAGS_NONE,
382 on_name_lost_or_acquired,
385 g_object_unref (connection);
389 client_unref (client);
392 /* ---------------------------------------------------------------------------------------------------- */
395 on_connection_disconnected (GDBusConnection *connection,
396 gboolean remote_peer_vanished,
400 Client *client = user_data;
402 if (client->disconnected_signal_handler_id > 0)
403 g_signal_handler_disconnect (client->connection, client->disconnected_signal_handler_id);
404 if (client->name_acquired_subscription_id > 0)
405 g_dbus_connection_signal_unsubscribe (client->connection, client->name_acquired_subscription_id);
406 if (client->name_lost_subscription_id > 0)
407 g_dbus_connection_signal_unsubscribe (client->connection, client->name_lost_subscription_id);
408 g_object_unref (client->connection);
409 client->disconnected_signal_handler_id = 0;
410 client->name_acquired_subscription_id = 0;
411 client->name_lost_subscription_id = 0;
412 client->connection = NULL;
414 call_lost_handler (client);
417 /* ---------------------------------------------------------------------------------------------------- */
420 has_connection (Client *client)
422 /* listen for disconnection */
423 client->disconnected_signal_handler_id = g_signal_connect (client->connection,
425 G_CALLBACK (on_connection_disconnected),
428 /* attempt to acquire the name */
429 g_dbus_connection_call (client->connection,
430 "org.freedesktop.DBus", /* bus name */
431 "/org/freedesktop/DBus", /* object path */
432 "org.freedesktop.DBus", /* interface name */
433 "RequestName", /* method name */
434 g_variant_new ("(su)",
437 G_VARIANT_TYPE ("(u)"),
438 G_DBUS_CALL_FLAGS_NONE,
441 (GAsyncReadyCallback) request_name_cb,
442 client_ref (client));
447 connection_get_cb (GObject *source_object,
451 Client *client = user_data;
453 /* must not do anything if already cancelled */
455 if (client->cancelled)
462 client->connection = g_bus_get_finish (res, NULL);
463 if (client->connection == NULL)
465 call_lost_handler (client);
469 /* No need to schedule this in idle as we're already in the thread
470 * that the user called g_bus_own_name() from. This is because
471 * g_bus_get() guarantees that.
473 * Also, we need to ensure that the handler is invoked *before*
474 * we call RequestName(). Otherwise there is a race.
476 if (client->bus_acquired_handler != NULL)
478 client->bus_acquired_handler (client->connection,
483 has_connection (client);
486 client_unref (client);
489 /* ---------------------------------------------------------------------------------------------------- */
492 * g_bus_own_name_on_connection:
493 * @connection: A #GDBusConnection.
494 * @name: The well-known name to own.
495 * @flags: A set of flags from the #GBusNameOwnerFlags enumeration.
496 * @name_acquired_handler: (allow-none): Handler to invoke when @name is acquired or %NULL.
497 * @name_lost_handler: (allow-none): Handler to invoke when @name is lost or %NULL.
498 * @user_data: User data to pass to handlers.
499 * @user_data_free_func: (allow-none): Function for freeing @user_data or %NULL.
501 * Like g_bus_own_name() but takes a #GDBusConnection instead of a
504 * Returns: An identifier (never 0) that an be used with
505 * g_bus_unown_name() to stop owning the name.
510 g_bus_own_name_on_connection (GDBusConnection *connection,
512 GBusNameOwnerFlags flags,
513 GBusNameAcquiredCallback name_acquired_handler,
514 GBusNameLostCallback name_lost_handler,
516 GDestroyNotify user_data_free_func)
520 g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), 0);
521 g_return_val_if_fail (g_dbus_is_name (name) && !g_dbus_is_unique_name (name), 0);
525 client = g_new0 (Client, 1);
526 client->ref_count = 1;
527 client->id = next_global_id++; /* TODO: uh oh, handle overflow */
528 client->name = g_strdup (name);
529 client->flags = flags;
530 client->name_acquired_handler = name_acquired_handler;
531 client->name_lost_handler = name_lost_handler;
532 client->user_data = user_data;
533 client->user_data_free_func = user_data_free_func;
534 client->main_context = g_main_context_ref_thread_default ();
536 client->connection = g_object_ref (connection);
538 if (map_id_to_client == NULL)
540 map_id_to_client = g_hash_table_new (g_direct_hash, g_direct_equal);
542 g_hash_table_insert (map_id_to_client,
543 GUINT_TO_POINTER (client->id),
548 has_connection (client);
555 * @bus_type: The type of bus to own a name on.
556 * @name: The well-known name to own.
557 * @flags: A set of flags from the #GBusNameOwnerFlags enumeration.
558 * @bus_acquired_handler: (allow-none): Handler to invoke when connected to the bus of type @bus_type or %NULL.
559 * @name_acquired_handler: (allow-none): Handler to invoke when @name is acquired or %NULL.
560 * @name_lost_handler: (allow-none): Handler to invoke when @name is lost or %NULL.
561 * @user_data: User data to pass to handlers.
562 * @user_data_free_func: (allow-none): Function for freeing @user_data or %NULL.
564 * Starts acquiring @name on the bus specified by @bus_type and calls
565 * @name_acquired_handler and @name_lost_handler when the name is
566 * acquired respectively lost. Callbacks will be invoked in the <link
567 * linkend="g-main-context-push-thread-default">thread-default main
568 * loop</link> of the thread you are calling this function from.
570 * You are guaranteed that one of the @name_acquired_handler and @name_lost_handler
571 * callbacks will be invoked after calling this function - there are three
575 * @name_lost_handler with a %NULL connection (if a connection to the bus can't be made).
578 * @bus_acquired_handler then @name_lost_handler (if the name can't be obtained)
581 * @bus_acquired_handler then @name_acquired_handler (if the name was obtained).
584 * When you are done owning the name, just call g_bus_unown_name()
585 * with the owner id this function returns.
587 * If the name is acquired or lost (for example another application
588 * could acquire the name if you allow replacement or the application
589 * currently owning the name exits), the handlers are also invoked. If the
590 * #GDBusConnection that is used for attempting to own the name
591 * closes, then @name_lost_handler is invoked since it is no
592 * longer possible for other processes to access the process.
594 * You cannot use g_bus_own_name() several times for the same name (unless
595 * interleaved with calls to g_bus_unown_name()) - only the first call
598 * Another guarantee is that invocations of @name_acquired_handler
599 * and @name_lost_handler are guaranteed to alternate; that
600 * is, if @name_acquired_handler is invoked then you are
601 * guaranteed that the next time one of the handlers is invoked, it
602 * will be @name_lost_handler. The reverse is also true.
604 * If you plan on exporting objects (using e.g.
605 * g_dbus_connection_register_object()), note that it is generally too late
606 * to export the objects in @name_acquired_handler. Instead, you can do this
607 * in @bus_acquired_handler since you are guaranteed that this will run
608 * before @name is requested from the bus.
610 * This behavior makes it very simple to write applications that wants
611 * to own names and export objects, see <xref linkend="gdbus-owning-names"/>.
612 * Simply register objects to be exported in @bus_acquired_handler and
613 * unregister the objects (if any) in @name_lost_handler.
615 * Returns: An identifier (never 0) that an be used with
616 * g_bus_unown_name() to stop owning the name.
621 g_bus_own_name (GBusType bus_type,
623 GBusNameOwnerFlags flags,
624 GBusAcquiredCallback bus_acquired_handler,
625 GBusNameAcquiredCallback name_acquired_handler,
626 GBusNameLostCallback name_lost_handler,
628 GDestroyNotify user_data_free_func)
632 g_return_val_if_fail (g_dbus_is_name (name) && !g_dbus_is_unique_name (name), 0);
636 client = g_new0 (Client, 1);
637 client->ref_count = 1;
638 client->id = next_global_id++; /* TODO: uh oh, handle overflow */
639 client->name = g_strdup (name);
640 client->flags = flags;
641 client->bus_acquired_handler = bus_acquired_handler;
642 client->name_acquired_handler = name_acquired_handler;
643 client->name_lost_handler = name_lost_handler;
644 client->user_data = user_data;
645 client->user_data_free_func = user_data_free_func;
646 client->main_context = g_main_context_ref_thread_default ();
648 if (map_id_to_client == NULL)
650 map_id_to_client = g_hash_table_new (g_direct_hash, g_direct_equal);
652 g_hash_table_insert (map_id_to_client,
653 GUINT_TO_POINTER (client->id),
659 client_ref (client));
667 GClosure *bus_acquired_closure;
668 GClosure *name_acquired_closure;
669 GClosure *name_lost_closure;
673 own_name_data_new (GClosure *bus_acquired_closure,
674 GClosure *name_acquired_closure,
675 GClosure *name_lost_closure)
679 data = g_new0 (OwnNameData, 1);
681 if (bus_acquired_closure != NULL)
683 data->bus_acquired_closure = g_closure_ref (bus_acquired_closure);
684 g_closure_sink (bus_acquired_closure);
685 if (G_CLOSURE_NEEDS_MARSHAL (bus_acquired_closure))
686 g_closure_set_marshal (bus_acquired_closure, g_cclosure_marshal_generic);
689 if (name_acquired_closure != NULL)
691 data->name_acquired_closure = g_closure_ref (name_acquired_closure);
692 g_closure_sink (name_acquired_closure);
693 if (G_CLOSURE_NEEDS_MARSHAL (name_acquired_closure))
694 g_closure_set_marshal (name_acquired_closure, g_cclosure_marshal_generic);
697 if (name_lost_closure != NULL)
699 data->name_lost_closure = g_closure_ref (name_lost_closure);
700 g_closure_sink (name_lost_closure);
701 if (G_CLOSURE_NEEDS_MARSHAL (name_lost_closure))
702 g_closure_set_marshal (name_lost_closure, g_cclosure_marshal_generic);
709 own_with_closures_on_bus_acquired (GDBusConnection *connection,
713 OwnNameData *data = user_data;
714 GValue params[2] = { G_VALUE_INIT, G_VALUE_INIT };
716 g_value_init (¶ms[0], G_TYPE_DBUS_CONNECTION);
717 g_value_set_object (¶ms[0], connection);
719 g_value_init (¶ms[1], G_TYPE_STRING);
720 g_value_set_string (¶ms[1], name);
722 g_closure_invoke (data->bus_acquired_closure, NULL, 2, params, NULL);
724 g_value_unset (params + 0);
725 g_value_unset (params + 1);
729 own_with_closures_on_name_acquired (GDBusConnection *connection,
733 OwnNameData *data = user_data;
734 GValue params[2] = { G_VALUE_INIT, G_VALUE_INIT };
736 g_value_init (¶ms[0], G_TYPE_DBUS_CONNECTION);
737 g_value_set_object (¶ms[0], connection);
739 g_value_init (¶ms[1], G_TYPE_STRING);
740 g_value_set_string (¶ms[1], name);
742 g_closure_invoke (data->name_acquired_closure, NULL, 2, params, NULL);
744 g_value_unset (params + 0);
745 g_value_unset (params + 1);
749 own_with_closures_on_name_lost (GDBusConnection *connection,
753 OwnNameData *data = user_data;
754 GValue params[2] = { G_VALUE_INIT, G_VALUE_INIT };
756 g_value_init (¶ms[0], G_TYPE_DBUS_CONNECTION);
757 g_value_set_object (¶ms[0], connection);
759 g_value_init (¶ms[1], G_TYPE_STRING);
760 g_value_set_string (¶ms[1], name);
762 g_closure_invoke (data->name_lost_closure, NULL, 2, params, NULL);
764 g_value_unset (params + 0);
765 g_value_unset (params + 1);
769 bus_own_name_free_func (gpointer user_data)
771 OwnNameData *data = user_data;
773 if (data->bus_acquired_closure != NULL)
774 g_closure_unref (data->bus_acquired_closure);
776 if (data->name_acquired_closure != NULL)
777 g_closure_unref (data->name_acquired_closure);
779 if (data->name_lost_closure != NULL)
780 g_closure_unref (data->name_lost_closure);
786 * g_bus_own_name_with_closures:
787 * @bus_type: The type of bus to own a name on.
788 * @name: The well-known name to own.
789 * @flags: A set of flags from the #GBusNameOwnerFlags enumeration.
790 * @bus_acquired_closure: (allow-none): #GClosure to invoke when connected to
791 * the bus of type @bus_type or %NULL.
792 * @name_acquired_closure: (allow-none): #GClosure to invoke when @name is
794 * @name_lost_closure: (allow-none): #GClosure to invoke when @name is lost or
797 * Version of g_bus_own_name() using closures instead of callbacks for
798 * easier binding in other languages.
800 * Returns: An identifier (never 0) that an be used with
801 * g_bus_unown_name() to stop owning the name.
803 * Rename to: g_bus_own_name
808 g_bus_own_name_with_closures (GBusType bus_type,
810 GBusNameOwnerFlags flags,
811 GClosure *bus_acquired_closure,
812 GClosure *name_acquired_closure,
813 GClosure *name_lost_closure)
815 return g_bus_own_name (bus_type,
818 bus_acquired_closure != NULL ? own_with_closures_on_bus_acquired : NULL,
819 name_acquired_closure != NULL ? own_with_closures_on_name_acquired : NULL,
820 name_lost_closure != NULL ? own_with_closures_on_name_lost : NULL,
821 own_name_data_new (bus_acquired_closure,
822 name_acquired_closure,
824 bus_own_name_free_func);
828 * g_bus_own_name_on_connection_with_closures:
829 * @connection: A #GDBusConnection.
830 * @name: The well-known name to own.
831 * @flags: A set of flags from the #GBusNameOwnerFlags enumeration.
832 * @name_acquired_closure: (allow-none): #GClosure to invoke when @name is
834 * @name_lost_closure: (allow-none): #GClosure to invoke when @name is lost or
837 * Version of g_bus_own_name_on_connection() using closures instead of callbacks for
838 * easier binding in other languages.
840 * Returns: An identifier (never 0) that an be used with
841 * g_bus_unown_name() to stop owning the name.
843 * Rename to: g_bus_own_name_on_connection
848 g_bus_own_name_on_connection_with_closures (GDBusConnection *connection,
850 GBusNameOwnerFlags flags,
851 GClosure *name_acquired_closure,
852 GClosure *name_lost_closure)
854 return g_bus_own_name_on_connection (connection,
857 name_acquired_closure != NULL ? own_with_closures_on_name_acquired : NULL,
858 name_lost_closure != NULL ? own_with_closures_on_name_lost : NULL,
859 own_name_data_new (NULL,
860 name_acquired_closure,
862 bus_own_name_free_func);
867 * @owner_id: An identifier obtained from g_bus_own_name()
869 * Stops owning a name.
874 g_bus_unown_name (guint owner_id)
878 g_return_if_fail (owner_id > 0);
883 if (owner_id == 0 || map_id_to_client == NULL ||
884 (client = g_hash_table_lookup (map_id_to_client, GUINT_TO_POINTER (owner_id))) == NULL)
886 g_warning ("Invalid id %d passed to g_bus_unown_name()", owner_id);
890 client->cancelled = TRUE;
891 g_warn_if_fail (g_hash_table_remove (map_id_to_client, GUINT_TO_POINTER (owner_id)));
896 /* do callback without holding lock */
899 /* Release the name if needed */
900 if (client->needs_release &&
901 client->connection != NULL &&
902 !g_dbus_connection_is_closed (client->connection))
906 guint32 release_name_reply;
908 /* TODO: it kinda sucks having to do a sync call to release the name - but if
909 * we don't, then a subsequent grab of the name will make the bus daemon return
910 * IN_QUEUE which will trigger name_lost().
912 * I believe this is a bug in the bus daemon.
915 result = g_dbus_connection_call_sync (client->connection,
916 "org.freedesktop.DBus", /* bus name */
917 "/org/freedesktop/DBus", /* object path */
918 "org.freedesktop.DBus", /* interface name */
919 "ReleaseName", /* method name */
920 g_variant_new ("(s)", client->name),
921 G_VARIANT_TYPE ("(u)"),
922 G_DBUS_CALL_FLAGS_NONE,
928 g_warning ("Error releasing name %s: %s", client->name, error->message);
929 g_error_free (error);
933 g_variant_get (result, "(u)", &release_name_reply);
934 if (release_name_reply != 1 /* DBUS_RELEASE_NAME_REPLY_RELEASED */)
936 g_warning ("Unexpected reply %d when releasing name %s", release_name_reply, client->name);
938 g_variant_unref (result);
942 if (client->disconnected_signal_handler_id > 0)
943 g_signal_handler_disconnect (client->connection, client->disconnected_signal_handler_id);
944 if (client->name_acquired_subscription_id > 0)
945 g_dbus_connection_signal_unsubscribe (client->connection, client->name_acquired_subscription_id);
946 if (client->name_lost_subscription_id > 0)
947 g_dbus_connection_signal_unsubscribe (client->connection, client->name_lost_subscription_id);
948 client->disconnected_signal_handler_id = 0;
949 client->name_acquired_subscription_id = 0;
950 client->name_lost_subscription_id = 0;
951 if (client->connection != NULL)
953 g_object_unref (client->connection);
954 client->connection = NULL;
957 client_unref (client);