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, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Author: David Zeuthen <davidz@redhat.com>
28 #include "gdbusutils.h"
29 #include "gdbusproxy.h"
30 #include "gioenumtypes.h"
31 #include "gdbusconnection.h"
32 #include "gdbuserror.h"
33 #include "gdbusprivate.h"
34 #include "gio-marshal.h"
35 #include "ginitable.h"
36 #include "gasyncinitable.h"
38 #include "gasyncresult.h"
39 #include "gsimpleasyncresult.h"
40 #include "gcancellable.h"
41 #include "gdbusinterface.h"
47 * @short_description: Client-side D-Bus interface proxy
50 * #GDBusProxy is a base class used for proxies to access a D-Bus
51 * interface on a remote object. A #GDBusProxy can be constructed for
52 * both well-known and unique names.
54 * By default, #GDBusProxy will cache all properties (and listen to
55 * changes) of the remote object, and proxy all signals that gets
56 * emitted. This behaviour can be changed by passing suitable
57 * #GDBusProxyFlags when the proxy is created. If the proxy is for a
58 * well-known name, the property cache is flushed when the name owner
59 * vanishes and reloaded when a name owner appears.
61 * If a #GDBusProxy is used for a well-known name, the owner of the
62 * name is tracked and can be read from
63 * #GDBusProxy:g-name-owner. Connect to the #GObject::notify signal to
64 * get notified of changes. Additionally, only signals and property
65 * changes emitted from the current name owner are considered and
66 * calls are always sent to the current name owner. This avoids a
67 * number of race conditions when the name is lost by one owner and
68 * claimed by another. However, if no name owner currently exists,
69 * then calls will be sent to the well-known name which may result in
70 * the message bus launching an owner (unless
71 * %G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START is set).
73 * The generic #GDBusProxy::g-properties-changed and #GDBusProxy::g-signal
74 * signals are not very convenient to work with. Therefore, the recommended
75 * way of working with proxies is to subclass #GDBusProxy, and have
76 * more natural properties and signals in your derived class.
78 * See <xref linkend="gdbus-example-proxy-subclass"/> for an example.
80 * <example id="gdbus-wellknown-proxy"><title>GDBusProxy for a well-known-name</title><programlisting><xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../../../gio/tests/gdbus-example-watch-proxy.c"><xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback></xi:include></programlisting></example>
83 /* ---------------------------------------------------------------------------------------------------- */
85 G_LOCK_DEFINE_STATIC (signal_subscription_lock);
89 volatile gint ref_count;
91 } SignalSubscriptionData;
93 static SignalSubscriptionData *
94 signal_subscription_ref (SignalSubscriptionData *data)
96 g_atomic_int_inc (&data->ref_count);
101 signal_subscription_unref (SignalSubscriptionData *data)
103 if (g_atomic_int_dec_and_test (&data->ref_count))
105 g_slice_free (SignalSubscriptionData, data);
109 /* ---------------------------------------------------------------------------------------------------- */
111 struct _GDBusProxyPrivate
114 GDBusProxyFlags flags;
115 GDBusConnection *connection;
120 gchar *interface_name;
123 guint name_owner_changed_subscription_id;
125 GCancellable *get_all_cancellable;
127 /* gchar* -> GVariant* */
128 GHashTable *properties;
130 GDBusInterfaceInfo *expected_interface;
132 guint properties_changed_subscription_id;
133 guint signals_subscription_id;
135 gboolean initialized;
139 SignalSubscriptionData *signal_subscription_data;
151 PROP_G_INTERFACE_NAME,
152 PROP_G_DEFAULT_TIMEOUT,
153 PROP_G_INTERFACE_INFO
158 PROPERTIES_CHANGED_SIGNAL,
163 guint signals[LAST_SIGNAL] = {0};
165 static void dbus_interface_iface_init (GDBusInterfaceIface *dbus_interface_iface);
166 static void initable_iface_init (GInitableIface *initable_iface);
167 static void async_initable_iface_init (GAsyncInitableIface *async_initable_iface);
169 G_DEFINE_TYPE_WITH_CODE (GDBusProxy, g_dbus_proxy, G_TYPE_OBJECT,
170 G_IMPLEMENT_INTERFACE (G_TYPE_DBUS_INTERFACE, dbus_interface_iface_init)
171 G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, initable_iface_init)
172 G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, async_initable_iface_init)
176 g_dbus_proxy_dispose (GObject *object)
178 GDBusProxy *proxy = G_DBUS_PROXY (object);
179 G_LOCK (signal_subscription_lock);
180 if (proxy->priv->signal_subscription_data != NULL)
182 proxy->priv->signal_subscription_data->proxy = NULL;
183 signal_subscription_unref (proxy->priv->signal_subscription_data);
184 proxy->priv->signal_subscription_data = NULL;
186 G_UNLOCK (signal_subscription_lock);
188 G_OBJECT_CLASS (g_dbus_proxy_parent_class)->dispose (object);
192 g_dbus_proxy_finalize (GObject *object)
194 GDBusProxy *proxy = G_DBUS_PROXY (object);
196 g_warn_if_fail (proxy->priv->get_all_cancellable == NULL);
198 if (proxy->priv->name_owner_changed_subscription_id > 0)
199 g_dbus_connection_signal_unsubscribe (proxy->priv->connection,
200 proxy->priv->name_owner_changed_subscription_id);
202 if (proxy->priv->properties_changed_subscription_id > 0)
203 g_dbus_connection_signal_unsubscribe (proxy->priv->connection,
204 proxy->priv->properties_changed_subscription_id);
206 if (proxy->priv->signals_subscription_id > 0)
207 g_dbus_connection_signal_unsubscribe (proxy->priv->connection,
208 proxy->priv->signals_subscription_id);
210 if (proxy->priv->connection != NULL)
211 g_object_unref (proxy->priv->connection);
212 g_free (proxy->priv->name);
213 g_free (proxy->priv->name_owner);
214 g_free (proxy->priv->object_path);
215 g_free (proxy->priv->interface_name);
216 if (proxy->priv->properties != NULL)
217 g_hash_table_unref (proxy->priv->properties);
219 if (proxy->priv->expected_interface != NULL)
221 g_dbus_interface_info_cache_release (proxy->priv->expected_interface);
222 g_dbus_interface_info_unref (proxy->priv->expected_interface);
225 if (proxy->priv->object != NULL)
226 g_object_remove_weak_pointer (G_OBJECT (proxy->priv->object), (gpointer *) &proxy->priv->object);
228 G_OBJECT_CLASS (g_dbus_proxy_parent_class)->finalize (object);
232 g_dbus_proxy_get_property (GObject *object,
237 GDBusProxy *proxy = G_DBUS_PROXY (object);
241 case PROP_G_CONNECTION:
242 g_value_set_object (value, proxy->priv->connection);
246 g_value_set_flags (value, proxy->priv->flags);
250 g_value_set_string (value, proxy->priv->name);
253 case PROP_G_NAME_OWNER:
254 g_value_set_string (value, proxy->priv->name_owner);
257 case PROP_G_OBJECT_PATH:
258 g_value_set_string (value, proxy->priv->object_path);
261 case PROP_G_INTERFACE_NAME:
262 g_value_set_string (value, proxy->priv->interface_name);
265 case PROP_G_DEFAULT_TIMEOUT:
266 g_value_set_int (value, proxy->priv->timeout_msec);
269 case PROP_G_INTERFACE_INFO:
270 g_value_set_boxed (value, g_dbus_proxy_get_interface_info (proxy));
274 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
280 g_dbus_proxy_set_property (GObject *object,
285 GDBusProxy *proxy = G_DBUS_PROXY (object);
289 case PROP_G_CONNECTION:
290 proxy->priv->connection = g_value_dup_object (value);
294 proxy->priv->flags = g_value_get_flags (value);
298 proxy->priv->name = g_value_dup_string (value);
301 case PROP_G_OBJECT_PATH:
302 proxy->priv->object_path = g_value_dup_string (value);
305 case PROP_G_INTERFACE_NAME:
306 proxy->priv->interface_name = g_value_dup_string (value);
309 case PROP_G_DEFAULT_TIMEOUT:
310 g_dbus_proxy_set_default_timeout (proxy, g_value_get_int (value));
313 case PROP_G_INTERFACE_INFO:
314 g_dbus_proxy_set_interface_info (proxy, g_value_get_boxed (value));
317 case PROP_G_BUS_TYPE:
318 proxy->priv->bus_type = g_value_get_enum (value);
322 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
328 g_dbus_proxy_class_init (GDBusProxyClass *klass)
330 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
332 gobject_class->dispose = g_dbus_proxy_dispose;
333 gobject_class->finalize = g_dbus_proxy_finalize;
334 gobject_class->set_property = g_dbus_proxy_set_property;
335 gobject_class->get_property = g_dbus_proxy_get_property;
337 /* Note that all property names are prefixed to avoid collisions with D-Bus property names
338 * in derived classes */
341 * GDBusProxy:g-interface-info:
343 * Ensure that interactions with this proxy conform to the given
344 * interface. For example, when completing a method call, if the
345 * type signature of the message isn't what's expected, the given
346 * #GError is set. Signals that have a type signature mismatch are
351 g_object_class_install_property (gobject_class,
352 PROP_G_INTERFACE_INFO,
353 g_param_spec_boxed ("g-interface-info",
354 P_("Interface Information"),
355 P_("Interface Information"),
356 G_TYPE_DBUS_INTERFACE_INFO,
359 G_PARAM_STATIC_NAME |
360 G_PARAM_STATIC_BLURB |
361 G_PARAM_STATIC_NICK));
364 * GDBusProxy:g-connection:
366 * The #GDBusConnection the proxy is for.
370 g_object_class_install_property (gobject_class,
372 g_param_spec_object ("g-connection",
374 P_("The connection the proxy is for"),
375 G_TYPE_DBUS_CONNECTION,
378 G_PARAM_CONSTRUCT_ONLY |
379 G_PARAM_STATIC_NAME |
380 G_PARAM_STATIC_BLURB |
381 G_PARAM_STATIC_NICK));
384 * GDBusProxy:g-bus-type:
386 * If this property is not %G_BUS_TYPE_NONE, then
387 * #GDBusProxy:g-connection must be %NULL and will be set to the
388 * #GDBusConnection obtained by calling g_bus_get() with the value
393 g_object_class_install_property (gobject_class,
395 g_param_spec_enum ("g-bus-type",
397 P_("The bus to connect to, if any"),
401 G_PARAM_CONSTRUCT_ONLY |
402 G_PARAM_STATIC_NAME |
403 G_PARAM_STATIC_BLURB |
404 G_PARAM_STATIC_NICK));
407 * GDBusProxy:g-flags:
409 * Flags from the #GDBusProxyFlags enumeration.
413 g_object_class_install_property (gobject_class,
415 g_param_spec_flags ("g-flags",
417 P_("Flags for the proxy"),
418 G_TYPE_DBUS_PROXY_FLAGS,
419 G_DBUS_PROXY_FLAGS_NONE,
422 G_PARAM_CONSTRUCT_ONLY |
423 G_PARAM_STATIC_NAME |
424 G_PARAM_STATIC_BLURB |
425 G_PARAM_STATIC_NICK));
430 * The well-known or unique name that the proxy is for.
434 g_object_class_install_property (gobject_class,
436 g_param_spec_string ("g-name",
438 P_("The well-known or unique name that the proxy is for"),
442 G_PARAM_CONSTRUCT_ONLY |
443 G_PARAM_STATIC_NAME |
444 G_PARAM_STATIC_BLURB |
445 G_PARAM_STATIC_NICK));
448 * GDBusProxy:g-name-owner:
450 * The unique name that owns #GDBusProxy:name or %NULL if no-one
451 * currently owns that name. You may connect to #GObject::notify signal to
452 * track changes to this property.
456 g_object_class_install_property (gobject_class,
458 g_param_spec_string ("g-name-owner",
460 P_("The unique name for the owner"),
463 G_PARAM_STATIC_NAME |
464 G_PARAM_STATIC_BLURB |
465 G_PARAM_STATIC_NICK));
468 * GDBusProxy:g-object-path:
470 * The object path the proxy is for.
474 g_object_class_install_property (gobject_class,
476 g_param_spec_string ("g-object-path",
478 P_("The object path the proxy is for"),
482 G_PARAM_CONSTRUCT_ONLY |
483 G_PARAM_STATIC_NAME |
484 G_PARAM_STATIC_BLURB |
485 G_PARAM_STATIC_NICK));
488 * GDBusProxy:g-interface-name:
490 * The D-Bus interface name the proxy is for.
494 g_object_class_install_property (gobject_class,
495 PROP_G_INTERFACE_NAME,
496 g_param_spec_string ("g-interface-name",
497 P_("g-interface-name"),
498 P_("The D-Bus interface name the proxy is for"),
502 G_PARAM_CONSTRUCT_ONLY |
503 G_PARAM_STATIC_NAME |
504 G_PARAM_STATIC_BLURB |
505 G_PARAM_STATIC_NICK));
508 * GDBusProxy:g-default-timeout:
510 * The timeout to use if -1 (specifying default timeout) is passed
511 * as @timeout_msec in the g_dbus_proxy_call() and
512 * g_dbus_proxy_call_sync() functions.
514 * This allows applications to set a proxy-wide timeout for all
515 * remote method invocations on the proxy. If this property is -1,
516 * the default timeout (typically 25 seconds) is used. If set to
517 * %G_MAXINT, then no timeout is used.
521 g_object_class_install_property (gobject_class,
522 PROP_G_DEFAULT_TIMEOUT,
523 g_param_spec_int ("g-default-timeout",
524 P_("Default Timeout"),
525 P_("Timeout for remote method invocation"),
532 G_PARAM_STATIC_NAME |
533 G_PARAM_STATIC_BLURB |
534 G_PARAM_STATIC_NICK));
537 * GDBusProxy::g-properties-changed:
538 * @proxy: The #GDBusProxy emitting the signal.
539 * @changed_properties: A #GVariant containing the properties that changed
540 * @invalidated_properties: A %NULL terminated array of properties that was invalidated
542 * Emitted when one or more D-Bus properties on @proxy changes. The
543 * local cache has already been updated when this signal fires. Note
544 * that both @changed_properties and @invalidated_properties are
545 * guaranteed to never be %NULL (either may be empty though).
547 * This signal corresponds to the
548 * <literal>PropertiesChanged</literal> D-Bus signal on the
549 * <literal>org.freedesktop.DBus.Properties</literal> interface.
553 signals[PROPERTIES_CHANGED_SIGNAL] = g_signal_new ("g-properties-changed",
555 G_SIGNAL_RUN_LAST | G_SIGNAL_MUST_COLLECT,
556 G_STRUCT_OFFSET (GDBusProxyClass, g_properties_changed),
559 _gio_marshal_VOID__VARIANT_BOXED,
563 G_TYPE_STRV | G_SIGNAL_TYPE_STATIC_SCOPE);
566 * GDBusProxy::g-signal:
567 * @proxy: The #GDBusProxy emitting the signal.
568 * @sender_name: The sender of the signal or %NULL if the connection is not a bus connection.
569 * @signal_name: The name of the signal.
570 * @parameters: A #GVariant tuple with parameters for the signal.
572 * Emitted when a signal from the remote object and interface that @proxy is for, has been received.
576 signals[SIGNAL_SIGNAL] = g_signal_new ("g-signal",
578 G_SIGNAL_RUN_LAST | G_SIGNAL_MUST_COLLECT,
579 G_STRUCT_OFFSET (GDBusProxyClass, g_signal),
582 _gio_marshal_VOID__STRING_STRING_VARIANT,
590 g_type_class_add_private (klass, sizeof (GDBusProxyPrivate));
594 g_dbus_proxy_init (GDBusProxy *proxy)
596 proxy->priv = G_TYPE_INSTANCE_GET_PRIVATE (proxy, G_TYPE_DBUS_PROXY, GDBusProxyPrivate);
597 proxy->priv->signal_subscription_data = g_slice_new0 (SignalSubscriptionData);
598 proxy->priv->signal_subscription_data->ref_count = 1;
599 proxy->priv->signal_subscription_data->proxy = proxy;
600 proxy->priv->properties = g_hash_table_new_full (g_str_hash,
603 (GDestroyNotify) g_variant_unref);
606 /* ---------------------------------------------------------------------------------------------------- */
609 property_name_sort_func (const gchar **a,
612 return g_strcmp0 (*a, *b);
616 * g_dbus_proxy_get_cached_property_names:
617 * @proxy: A #GDBusProxy.
619 * Gets the names of all cached properties on @proxy.
621 * Returns: A %NULL-terminated array of strings or %NULL if @proxy has
622 * no cached properties. Free the returned array with g_strfreev().
627 g_dbus_proxy_get_cached_property_names (GDBusProxy *proxy)
634 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
637 if (g_hash_table_size (proxy->priv->properties) == 0)
640 p = g_ptr_array_new ();
642 g_hash_table_iter_init (&iter, proxy->priv->properties);
643 while (g_hash_table_iter_next (&iter, (gpointer) &key, NULL))
644 g_ptr_array_add (p, g_strdup (key));
645 g_ptr_array_sort (p, (GCompareFunc) property_name_sort_func);
646 g_ptr_array_add (p, NULL);
648 names = (gchar **) g_ptr_array_free (p, FALSE);
654 static const GDBusPropertyInfo *
655 lookup_property_info_or_warn (GDBusProxy *proxy,
656 const gchar *property_name)
658 const GDBusPropertyInfo *info;
660 if (proxy->priv->expected_interface == NULL)
663 info = g_dbus_interface_info_lookup_property (proxy->priv->expected_interface, property_name);
666 g_warning ("Trying to lookup property %s which isn't in expected interface %s",
668 proxy->priv->expected_interface->name);
675 * g_dbus_proxy_get_cached_property:
676 * @proxy: A #GDBusProxy.
677 * @property_name: Property name.
679 * Looks up the value for a property from the cache. This call does no
682 * If @proxy has an expected interface (see
683 * #GDBusProxy:g-interface-info), then @property_name (for existence)
684 * is checked against it.
686 * Returns: A reference to the #GVariant instance that holds the value
687 * for @property_name or %NULL if the value is not in the cache. The
688 * returned reference must be freed with g_variant_unref().
693 g_dbus_proxy_get_cached_property (GDBusProxy *proxy,
694 const gchar *property_name)
698 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
699 g_return_val_if_fail (property_name != NULL, NULL);
701 value = g_hash_table_lookup (proxy->priv->properties, property_name);
704 lookup_property_info_or_warn (proxy, property_name);
709 g_variant_ref (value);
716 * g_dbus_proxy_set_cached_property:
717 * @proxy: A #GDBusProxy
718 * @property_name: Property name.
719 * @value: (allow-none): Value for the property or %NULL to remove it from the cache.
721 * If @value is not %NULL, sets the cached value for the property with
722 * name @property_name to the value in @value.
724 * If @value is %NULL, then the cached value is removed from the
727 * If @proxy has an expected interface (see
728 * #GDBusProxy:g-interface-info), then @property_name (for existence)
729 * and @value (for the type) is checked against it.
731 * If the @value #GVariant is floating, it is consumed. This allows
732 * convenient 'inline' use of g_variant_new(), e.g.
734 * g_dbus_proxy_set_cached_property (proxy,
736 * g_variant_new ("(si)",
741 * Normally you will not need to use this method since @proxy is
742 * tracking changes using the
743 * <literal>org.freedesktop.DBus.Properties.PropertiesChanged</literal>
744 * D-Bus signal. However, for performance reasons an object may decide
745 * to not use this signal for some properties and instead use a
746 * proprietary out-of-band mechanism to transmit changes.
748 * As a concrete example, consider an object with a property
749 * <literal>ChatroomParticipants</literal> which is an array of
750 * strings. Instead of transmitting the same (long) array every time
751 * the property changes, it is more efficient to only transmit the
752 * delta using e.g. signals <literal>ChatroomParticipantJoined(String
753 * name)</literal> and <literal>ChatroomParticipantParted(String
759 g_dbus_proxy_set_cached_property (GDBusProxy *proxy,
760 const gchar *property_name,
763 const GDBusPropertyInfo *info;
765 g_return_if_fail (G_IS_DBUS_PROXY (proxy));
766 g_return_if_fail (property_name != NULL);
770 info = lookup_property_info_or_warn (proxy, property_name);
773 if (g_strcmp0 (info->signature, g_variant_get_type_string (value)) != 0)
775 g_warning ("Trying to set property %s of type %s but according to the expected "
776 "interface the type is %s",
778 g_variant_get_type_string (value),
783 g_hash_table_insert (proxy->priv->properties,
784 g_strdup (property_name),
785 g_variant_ref_sink (value));
789 g_hash_table_remove (proxy->priv->properties, property_name);
796 /* ---------------------------------------------------------------------------------------------------- */
799 on_signal_received (GDBusConnection *connection,
800 const gchar *sender_name,
801 const gchar *object_path,
802 const gchar *interface_name,
803 const gchar *signal_name,
804 GVariant *parameters,
807 SignalSubscriptionData *data = user_data;
810 G_LOCK (signal_subscription_lock);
814 g_object_ref (proxy);
815 G_UNLOCK (signal_subscription_lock);
817 if (!proxy->priv->initialized)
820 if (proxy->priv->name_owner != NULL && g_strcmp0 (sender_name, proxy->priv->name_owner) != 0)
823 if (proxy->priv->expected_interface != NULL)
825 const GDBusSignalInfo *info;
826 GVariantType *expected_type;
827 info = g_dbus_interface_info_lookup_signal (proxy->priv->expected_interface, signal_name);
830 expected_type = _g_dbus_compute_complete_signature (info->args);
831 if (!g_variant_type_equal (expected_type, g_variant_get_type (parameters)))
833 g_variant_type_free (expected_type);
836 g_variant_type_free (expected_type);
839 g_signal_emit (proxy,
840 signals[SIGNAL_SIGNAL],
847 g_object_unref (proxy);
850 /* ---------------------------------------------------------------------------------------------------- */
853 insert_property_checked (GDBusProxy *proxy,
854 gchar *property_name,
857 if (proxy->priv->expected_interface != NULL)
859 const GDBusPropertyInfo *info;
861 info = g_dbus_interface_info_lookup_property (proxy->priv->expected_interface, property_name);
862 /* Ignore unknown properties */
866 /* Ignore properties with the wrong type */
867 if (g_strcmp0 (info->signature, g_variant_get_type_string (value)) != 0)
871 g_hash_table_insert (proxy->priv->properties,
872 property_name, /* adopts string */
873 value); /* adopts value */
878 g_variant_unref (value);
879 g_free (property_name);
883 on_properties_changed (GDBusConnection *connection,
884 const gchar *sender_name,
885 const gchar *object_path,
886 const gchar *interface_name,
887 const gchar *signal_name,
888 GVariant *parameters,
891 SignalSubscriptionData *data = user_data;
893 const gchar *interface_name_for_signal;
894 GVariant *changed_properties;
895 gchar **invalidated_properties;
901 G_LOCK (signal_subscription_lock);
905 g_object_ref (proxy);
906 G_UNLOCK (signal_subscription_lock);
908 changed_properties = NULL;
909 invalidated_properties = NULL;
911 if (!proxy->priv->initialized)
914 if (proxy->priv->name_owner != NULL && g_strcmp0 (sender_name, proxy->priv->name_owner) != 0)
917 if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(sa{sv}as)")))
919 g_warning ("Value for PropertiesChanged signal with type `%s' does not match `(sa{sv}as)'",
920 g_variant_get_type_string (parameters));
924 g_variant_get (parameters,
926 &interface_name_for_signal,
928 &invalidated_properties);
930 if (g_strcmp0 (interface_name_for_signal, proxy->priv->interface_name) != 0)
933 g_variant_iter_init (&iter, changed_properties);
934 while (g_variant_iter_next (&iter, "{sv}", &key, &value))
936 insert_property_checked (proxy,
937 key, /* adopts string */
938 value); /* adopts value */
941 for (n = 0; invalidated_properties[n] != NULL; n++)
943 g_hash_table_remove (proxy->priv->properties, invalidated_properties[n]);
947 g_signal_emit (proxy, signals[PROPERTIES_CHANGED_SIGNAL],
950 invalidated_properties);
953 if (changed_properties != NULL)
954 g_variant_unref (changed_properties);
955 g_free (invalidated_properties);
957 g_object_unref (proxy);
960 /* ---------------------------------------------------------------------------------------------------- */
963 process_get_all_reply (GDBusProxy *proxy,
970 if (!g_variant_is_of_type (result, G_VARIANT_TYPE ("(a{sv})")))
972 g_warning ("Value for GetAll reply with type `%s' does not match `(a{sv})'",
973 g_variant_get_type_string (result));
977 g_variant_get (result, "(a{sv})", &iter);
978 while (g_variant_iter_next (iter, "{sv}", &key, &value))
980 insert_property_checked (proxy,
981 key, /* adopts string */
982 value); /* adopts value */
984 g_variant_iter_free (iter);
986 /* Synthesize ::g-properties-changed changed */
987 if (g_hash_table_size (proxy->priv->properties) > 0)
989 GVariant *changed_properties;
990 const gchar *invalidated_properties[1] = {NULL};
992 g_variant_get (result,
994 &changed_properties);
995 g_signal_emit (proxy, signals[PROPERTIES_CHANGED_SIGNAL],
998 invalidated_properties);
999 g_variant_unref (changed_properties);
1009 GCancellable *cancellable;
1011 } LoadPropertiesOnNameOwnerChangedData;
1014 on_name_owner_changed_get_all_cb (GDBusConnection *connection,
1018 LoadPropertiesOnNameOwnerChangedData *data = user_data;
1026 result = g_dbus_connection_call_finish (connection,
1031 if (error->domain == G_IO_ERROR && error->code == G_IO_ERROR_CANCELLED)
1033 /* We just ignore if GetAll() is failing. Because this might happen
1034 * if the object has no properties at all. Or if the caller is
1035 * not authorized to see the properties.
1037 * Either way, apps can know about this by using
1038 * get_cached_property_names() or get_cached_property().
1040 * TODO: handle G_DBUS_DEBUG flag 'proxy' and, if enabled, log the
1041 * fact that GetAll() failed
1043 //g_debug ("error: %d %d %s", error->domain, error->code, error->message);
1044 g_error_free (error);
1047 /* and finally we can notify */
1050 g_free (data->proxy->priv->name_owner);
1051 data->proxy->priv->name_owner = data->name_owner;
1052 data->name_owner = NULL; /* to avoid an extra copy, we steal the string */
1054 g_hash_table_remove_all (data->proxy->priv->properties);
1057 process_get_all_reply (data->proxy, result);
1058 g_variant_unref (result);
1061 g_object_notify (G_OBJECT (data->proxy), "g-name-owner");
1064 if (data->cancellable == data->proxy->priv->get_all_cancellable)
1065 data->proxy->priv->get_all_cancellable = NULL;
1067 g_object_unref (data->proxy);
1068 g_object_unref (data->cancellable);
1069 g_free (data->name_owner);
1074 on_name_owner_changed (GDBusConnection *connection,
1075 const gchar *sender_name,
1076 const gchar *object_path,
1077 const gchar *interface_name,
1078 const gchar *signal_name,
1079 GVariant *parameters,
1082 SignalSubscriptionData *data = user_data;
1084 const gchar *old_owner;
1085 const gchar *new_owner;
1087 G_LOCK (signal_subscription_lock);
1088 proxy = data->proxy;
1091 g_object_ref (proxy);
1092 G_UNLOCK (signal_subscription_lock);
1094 /* if we are already trying to load properties, cancel that */
1095 if (proxy->priv->get_all_cancellable != NULL)
1097 g_cancellable_cancel (proxy->priv->get_all_cancellable);
1098 proxy->priv->get_all_cancellable = NULL;
1101 g_variant_get (parameters,
1107 if (strlen (new_owner) == 0)
1109 g_free (proxy->priv->name_owner);
1110 proxy->priv->name_owner = NULL;
1112 /* Synthesize ::g-properties-changed changed */
1113 if (!(proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES) &&
1114 g_hash_table_size (proxy->priv->properties) > 0)
1116 GVariantBuilder builder;
1117 GPtrArray *invalidated_properties;
1118 GHashTableIter iter;
1121 /* Build changed_properties (always empty) and invalidated_properties ... */
1122 g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
1124 invalidated_properties = g_ptr_array_new_with_free_func (g_free);
1125 g_hash_table_iter_init (&iter, proxy->priv->properties);
1126 while (g_hash_table_iter_next (&iter, (gpointer) &key, NULL))
1127 g_ptr_array_add (invalidated_properties, g_strdup (key));
1128 g_ptr_array_add (invalidated_properties, NULL);
1130 /* ... throw out the properties ... */
1131 g_hash_table_remove_all (proxy->priv->properties);
1133 /* ... and finally emit the ::g-properties-changed signal */
1134 g_signal_emit (proxy, signals[PROPERTIES_CHANGED_SIGNAL],
1136 g_variant_builder_end (&builder) /* consumed */,
1137 (const gchar* const *) invalidated_properties->pdata);
1138 g_ptr_array_unref (invalidated_properties);
1140 g_object_notify (G_OBJECT (proxy), "g-name-owner");
1144 /* ignore duplicates - this can happen when activating the service */
1145 if (g_strcmp0 (new_owner, proxy->priv->name_owner) == 0)
1148 if (proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES)
1150 g_free (proxy->priv->name_owner);
1151 proxy->priv->name_owner = g_strdup (new_owner);
1152 g_hash_table_remove_all (proxy->priv->properties);
1153 g_object_notify (G_OBJECT (proxy), "g-name-owner");
1157 LoadPropertiesOnNameOwnerChangedData *data;
1159 /* start loading properties.. only then emit notify::g-name-owner .. we
1160 * need to be able to cancel this in the event another NameOwnerChanged
1161 * signal suddenly happens
1164 g_assert (proxy->priv->get_all_cancellable == NULL);
1165 proxy->priv->get_all_cancellable = g_cancellable_new ();
1166 data = g_new0 (LoadPropertiesOnNameOwnerChangedData, 1);
1167 data->proxy = g_object_ref (proxy);
1168 data->cancellable = proxy->priv->get_all_cancellable;
1169 data->name_owner = g_strdup (new_owner);
1170 g_dbus_connection_call (proxy->priv->connection,
1172 proxy->priv->object_path,
1173 "org.freedesktop.DBus.Properties",
1175 g_variant_new ("(s)", proxy->priv->interface_name),
1176 G_VARIANT_TYPE ("(a{sv})"),
1177 G_DBUS_CALL_FLAGS_NONE,
1179 proxy->priv->get_all_cancellable,
1180 (GAsyncReadyCallback) on_name_owner_changed_get_all_cb,
1187 g_object_unref (proxy);
1190 /* ---------------------------------------------------------------------------------------------------- */
1195 GCancellable *cancellable;
1196 GSimpleAsyncResult *simple;
1200 async_init_data_free (AsyncInitData *data)
1202 g_object_unref (data->proxy);
1203 if (data->cancellable != NULL)
1204 g_object_unref (data->cancellable);
1205 g_object_unref (data->simple);
1210 async_init_get_all_cb (GDBusConnection *connection,
1214 AsyncInitData *data = user_data;
1219 result = g_dbus_connection_call_finish (connection,
1224 /* We just ignore if GetAll() is failing. Because this might happen
1225 * if the object has no properties at all. Or if the caller is
1226 * not authorized to see the properties.
1228 * Either way, apps can know about this by using
1229 * get_cached_property_names() or get_cached_property().
1231 * TODO: handle G_DBUS_DEBUG flag 'proxy' and, if enabled, log the
1232 * fact that GetAll() failed
1234 //g_debug ("error: %d %d %s", error->domain, error->code, error->message);
1235 g_error_free (error);
1239 g_simple_async_result_set_op_res_gpointer (data->simple,
1241 (GDestroyNotify) g_variant_unref);
1244 g_simple_async_result_complete_in_idle (data->simple);
1245 async_init_data_free (data);
1250 async_init_get_name_owner_cb (GDBusConnection *connection,
1254 AsyncInitData *data = user_data;
1262 result = g_dbus_connection_call_finish (connection,
1267 if (error->domain == G_DBUS_ERROR &&
1268 error->code == G_DBUS_ERROR_NAME_HAS_NO_OWNER)
1270 g_error_free (error);
1274 g_simple_async_result_take_error (data->simple, error);
1275 g_simple_async_result_complete_in_idle (data->simple);
1276 async_init_data_free (data);
1282 g_variant_get (result,
1284 &data->proxy->priv->name_owner);
1285 g_variant_unref (result);
1289 if (!(data->proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES))
1291 /* load all properties asynchronously */
1292 g_dbus_connection_call (data->proxy->priv->connection,
1293 data->proxy->priv->name_owner,
1294 data->proxy->priv->object_path,
1295 "org.freedesktop.DBus.Properties",
1297 g_variant_new ("(s)", data->proxy->priv->interface_name),
1298 G_VARIANT_TYPE ("(a{sv})"),
1299 G_DBUS_CALL_FLAGS_NONE,
1302 (GAsyncReadyCallback) async_init_get_all_cb,
1307 g_simple_async_result_complete_in_idle (data->simple);
1308 async_init_data_free (data);
1316 async_init_call_get_name_owner (AsyncInitData *data)
1318 g_dbus_connection_call (data->proxy->priv->connection,
1319 "org.freedesktop.DBus", /* name */
1320 "/org/freedesktop/DBus", /* object path */
1321 "org.freedesktop.DBus", /* interface */
1323 g_variant_new ("(s)",
1324 data->proxy->priv->name),
1325 G_VARIANT_TYPE ("(s)"),
1326 G_DBUS_CALL_FLAGS_NONE,
1329 (GAsyncReadyCallback) async_init_get_name_owner_cb,
1334 async_init_start_service_by_name_cb (GDBusConnection *connection,
1338 AsyncInitData *data = user_data;
1343 result = g_dbus_connection_call_finish (connection,
1348 /* Errors are not unexpected; the bus will reply e.g.
1350 * org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.Epiphany2
1351 * was not provided by any .service files
1353 * This doesn't mean that the name doesn't have an owner, just
1354 * that it's not provided by a .service file. So just proceed to
1355 * invoke GetNameOwner() if dealing with that error.
1357 if (error->domain == G_DBUS_ERROR &&
1358 error->code == G_DBUS_ERROR_SERVICE_UNKNOWN)
1360 g_error_free (error);
1364 g_prefix_error (&error,
1365 _("Error calling StartServiceByName for %s: "),
1366 data->proxy->priv->name);
1372 guint32 start_service_result;
1373 g_variant_get (result,
1375 &start_service_result);
1376 g_variant_unref (result);
1377 if (start_service_result == 1 || /* DBUS_START_REPLY_SUCCESS */
1378 start_service_result == 2) /* DBUS_START_REPLY_ALREADY_RUNNING */
1380 /* continue to invoke GetNameOwner() */
1384 error = g_error_new (G_IO_ERROR,
1386 _("Unexpected reply %d from StartServiceByName(\"%s\") method"),
1387 start_service_result,
1388 data->proxy->priv->name);
1393 async_init_call_get_name_owner (data);
1397 g_warn_if_fail (error != NULL);
1398 g_simple_async_result_take_error (data->simple, error);
1399 g_simple_async_result_complete_in_idle (data->simple);
1400 async_init_data_free (data);
1404 async_init_call_start_service_by_name (AsyncInitData *data)
1406 g_dbus_connection_call (data->proxy->priv->connection,
1407 "org.freedesktop.DBus", /* name */
1408 "/org/freedesktop/DBus", /* object path */
1409 "org.freedesktop.DBus", /* interface */
1410 "StartServiceByName",
1411 g_variant_new ("(su)",
1412 data->proxy->priv->name,
1414 G_VARIANT_TYPE ("(u)"),
1415 G_DBUS_CALL_FLAGS_NONE,
1418 (GAsyncReadyCallback) async_init_start_service_by_name_cb,
1423 async_initable_init_second_async (GAsyncInitable *initable,
1425 GCancellable *cancellable,
1426 GAsyncReadyCallback callback,
1429 GDBusProxy *proxy = G_DBUS_PROXY (initable);
1430 AsyncInitData *data;
1432 data = g_new0 (AsyncInitData, 1);
1433 data->proxy = g_object_ref (proxy);
1434 data->cancellable = cancellable != NULL ? g_object_ref (cancellable) : NULL;
1435 data->simple = g_simple_async_result_new (G_OBJECT (proxy),
1440 /* Check name ownership asynchronously - possibly also start the service */
1441 if (proxy->priv->name == NULL)
1444 async_init_get_name_owner_cb (proxy->priv->connection, NULL, data);
1446 else if (g_dbus_is_unique_name (proxy->priv->name))
1448 proxy->priv->name_owner = g_strdup (proxy->priv->name);
1449 async_init_get_name_owner_cb (proxy->priv->connection, NULL, data);
1453 if (proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START)
1455 async_init_call_get_name_owner (data);
1459 async_init_call_start_service_by_name (data);
1465 async_initable_init_second_finish (GAsyncInitable *initable,
1469 GDBusProxy *proxy = G_DBUS_PROXY (initable);
1470 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
1476 if (g_simple_async_result_propagate_error (simple, error))
1479 result = g_simple_async_result_get_op_res_gpointer (simple);
1482 process_get_all_reply (proxy, result);
1488 proxy->priv->initialized = TRUE;
1492 /* ---------------------------------------------------------------------------------------------------- */
1495 async_initable_init_first (GAsyncInitable *initable)
1497 GDBusProxy *proxy = G_DBUS_PROXY (initable);
1499 if (!(proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES))
1501 /* subscribe to PropertiesChanged() */
1502 proxy->priv->properties_changed_subscription_id =
1503 g_dbus_connection_signal_subscribe (proxy->priv->connection,
1505 "org.freedesktop.DBus.Properties",
1506 "PropertiesChanged",
1507 proxy->priv->object_path,
1508 proxy->priv->interface_name,
1509 G_DBUS_SIGNAL_FLAGS_NONE,
1510 on_properties_changed,
1511 signal_subscription_ref (proxy->priv->signal_subscription_data),
1512 (GDestroyNotify) signal_subscription_unref);
1515 if (!(proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS))
1517 /* subscribe to all signals for the object */
1518 proxy->priv->signals_subscription_id =
1519 g_dbus_connection_signal_subscribe (proxy->priv->connection,
1521 proxy->priv->interface_name,
1523 proxy->priv->object_path,
1525 G_DBUS_SIGNAL_FLAGS_NONE,
1527 signal_subscription_ref (proxy->priv->signal_subscription_data),
1528 (GDestroyNotify) signal_subscription_unref);
1531 if (proxy->priv->name != NULL && !g_dbus_is_unique_name (proxy->priv->name))
1533 proxy->priv->name_owner_changed_subscription_id =
1534 g_dbus_connection_signal_subscribe (proxy->priv->connection,
1535 "org.freedesktop.DBus", /* name */
1536 "org.freedesktop.DBus", /* interface */
1537 "NameOwnerChanged", /* signal name */
1538 "/org/freedesktop/DBus", /* path */
1539 proxy->priv->name, /* arg0 */
1540 G_DBUS_SIGNAL_FLAGS_NONE,
1541 on_name_owner_changed,
1542 signal_subscription_ref (proxy->priv->signal_subscription_data),
1543 (GDestroyNotify) signal_subscription_unref);
1547 /* ---------------------------------------------------------------------------------------------------- */
1549 /* initialization is split into two parts - the first is the
1550 * non-blocing part that requires the callers GMainContext - the
1551 * second is a blocking part async part that doesn't require the
1552 * callers GMainContext.. we do this split so the code can be reused
1553 * in the GInitable implementation below.
1555 * Note that obtaining a GDBusConnection is not shared between the two
1563 GCancellable *cancellable;
1564 GAsyncReadyCallback callback;
1566 } GetConnectionData;
1569 get_connection_cb (GObject *source_object,
1573 GetConnectionData *data = user_data;
1577 data->proxy->priv->connection = g_bus_get_finish (res, &error);
1578 if (data->proxy->priv->connection == NULL)
1580 GSimpleAsyncResult *simple;
1581 simple = g_simple_async_result_new (G_OBJECT (data->proxy),
1585 g_simple_async_result_take_error (simple, error);
1586 g_simple_async_result_complete_in_idle (simple);
1587 g_object_unref (simple);
1591 async_initable_init_first (G_ASYNC_INITABLE (data->proxy));
1592 async_initable_init_second_async (G_ASYNC_INITABLE (data->proxy),
1599 if (data->cancellable != NULL)
1600 g_object_unref (data->cancellable);
1601 if (data->proxy != NULL)
1602 g_object_unref (data->proxy);
1607 async_initable_init_async (GAsyncInitable *initable,
1609 GCancellable *cancellable,
1610 GAsyncReadyCallback callback,
1613 GDBusProxy *proxy = G_DBUS_PROXY (initable);
1615 if (proxy->priv->bus_type != G_BUS_TYPE_NONE)
1617 GetConnectionData *data;
1619 g_assert (proxy->priv->connection == NULL);
1621 data = g_new0 (GetConnectionData, 1);
1622 data->proxy = g_object_ref (proxy);
1623 data->io_priority = io_priority;
1624 data->cancellable = cancellable != NULL ? g_object_ref (cancellable) : NULL;
1625 data->callback = callback;
1626 data->user_data = user_data;
1627 g_bus_get (proxy->priv->bus_type,
1634 async_initable_init_first (initable);
1635 async_initable_init_second_async (initable, io_priority, cancellable, callback, user_data);
1640 async_initable_init_finish (GAsyncInitable *initable,
1644 return async_initable_init_second_finish (initable, res, error);
1648 async_initable_iface_init (GAsyncInitableIface *async_initable_iface)
1650 async_initable_iface->init_async = async_initable_init_async;
1651 async_initable_iface->init_finish = async_initable_init_finish;
1654 /* ---------------------------------------------------------------------------------------------------- */
1658 GMainContext *context;
1661 } InitableAsyncInitableData;
1664 async_initable_init_async_cb (GObject *source_object,
1668 InitableAsyncInitableData *data = user_data;
1669 data->res = g_object_ref (res);
1670 g_main_loop_quit (data->loop);
1673 /* Simply reuse the GAsyncInitable implementation but run the first
1674 * part (that is non-blocking and requires the callers GMainContext)
1675 * with the callers GMainContext.. and the second with a private
1676 * GMainContext (bug 621310 is slightly related).
1678 * Note that obtaining a GDBusConnection is not shared between the two
1682 initable_init (GInitable *initable,
1683 GCancellable *cancellable,
1686 GDBusProxy *proxy = G_DBUS_PROXY (initable);
1687 InitableAsyncInitableData *data;
1692 if (proxy->priv->bus_type != G_BUS_TYPE_NONE)
1694 g_assert (proxy->priv->connection == NULL);
1695 proxy->priv->connection = g_bus_get_sync (proxy->priv->bus_type,
1698 if (proxy->priv->connection == NULL)
1702 async_initable_init_first (G_ASYNC_INITABLE (initable));
1704 data = g_new0 (InitableAsyncInitableData, 1);
1705 data->context = g_main_context_new ();
1706 data->loop = g_main_loop_new (data->context, FALSE);
1708 g_main_context_push_thread_default (data->context);
1710 async_initable_init_second_async (G_ASYNC_INITABLE (initable),
1713 async_initable_init_async_cb,
1716 g_main_loop_run (data->loop);
1718 ret = async_initable_init_second_finish (G_ASYNC_INITABLE (initable),
1722 g_main_context_pop_thread_default (data->context);
1724 g_main_context_unref (data->context);
1725 g_main_loop_unref (data->loop);
1726 g_object_unref (data->res);
1735 initable_iface_init (GInitableIface *initable_iface)
1737 initable_iface->init = initable_init;
1740 /* ---------------------------------------------------------------------------------------------------- */
1744 * @connection: A #GDBusConnection.
1745 * @flags: Flags used when constructing the proxy.
1746 * @info: (allow-none): A #GDBusInterfaceInfo specifying the minimal interface that @proxy conforms to or %NULL.
1747 * @name: (allow-none): A bus name (well-known or unique) or %NULL if @connection is not a message bus connection.
1748 * @object_path: An object path.
1749 * @interface_name: A D-Bus interface name.
1750 * @cancellable: A #GCancellable or %NULL.
1751 * @callback: Callback function to invoke when the proxy is ready.
1752 * @user_data: User data to pass to @callback.
1754 * Creates a proxy for accessing @interface_name on the remote object
1755 * at @object_path owned by @name at @connection and asynchronously
1756 * loads D-Bus properties unless the
1757 * %G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES flag is used. Connect to
1758 * the #GDBusProxy::g-properties-changed signal to get notified about
1761 * If the %G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS flag is not set, also sets up
1762 * match rules for signals. Connect to the #GDBusProxy::g-signal signal
1763 * to handle signals from the remote object.
1765 * If @name is a well-known name and the
1766 * %G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START flag isn't set and no name
1767 * owner currently exists, the message bus will be requested to launch
1768 * a name owner for the name.
1770 * This is a failable asynchronous constructor - when the proxy is
1771 * ready, @callback will be invoked and you can use
1772 * g_dbus_proxy_new_finish() to get the result.
1774 * See g_dbus_proxy_new_sync() and for a synchronous version of this constructor.
1776 * See <xref linkend="gdbus-wellknown-proxy"/> for an example of how #GDBusProxy can be used.
1781 g_dbus_proxy_new (GDBusConnection *connection,
1782 GDBusProxyFlags flags,
1783 GDBusInterfaceInfo *info,
1785 const gchar *object_path,
1786 const gchar *interface_name,
1787 GCancellable *cancellable,
1788 GAsyncReadyCallback callback,
1791 g_return_if_fail (G_IS_DBUS_CONNECTION (connection));
1792 g_return_if_fail ((name == NULL && g_dbus_connection_get_unique_name (connection) == NULL) || g_dbus_is_name (name));
1793 g_return_if_fail (g_variant_is_object_path (object_path));
1794 g_return_if_fail (g_dbus_is_interface_name (interface_name));
1796 g_async_initable_new_async (G_TYPE_DBUS_PROXY,
1802 "g-interface-info", info,
1804 "g-connection", connection,
1805 "g-object-path", object_path,
1806 "g-interface-name", interface_name,
1811 * g_dbus_proxy_new_finish:
1812 * @res: A #GAsyncResult obtained from the #GAsyncReadyCallback function passed to g_dbus_proxy_new().
1813 * @error: Return location for error or %NULL.
1815 * Finishes creating a #GDBusProxy.
1817 * Returns: A #GDBusProxy or %NULL if @error is set. Free with g_object_unref().
1822 g_dbus_proxy_new_finish (GAsyncResult *res,
1826 GObject *source_object;
1828 source_object = g_async_result_get_source_object (res);
1829 g_assert (source_object != NULL);
1831 object = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object),
1834 g_object_unref (source_object);
1837 return G_DBUS_PROXY (object);
1843 * g_dbus_proxy_new_sync:
1844 * @connection: A #GDBusConnection.
1845 * @flags: Flags used when constructing the proxy.
1846 * @info: (allow-none): A #GDBusInterfaceInfo specifying the minimal interface that @proxy conforms to or %NULL.
1847 * @name: (allow-none): A bus name (well-known or unique) or %NULL if @connection is not a message bus connection.
1848 * @object_path: An object path.
1849 * @interface_name: A D-Bus interface name.
1850 * @cancellable: (allow-none): A #GCancellable or %NULL.
1851 * @error: (allow-none): Return location for error or %NULL.
1853 * Creates a proxy for accessing @interface_name on the remote object
1854 * at @object_path owned by @name at @connection and synchronously
1855 * loads D-Bus properties unless the
1856 * %G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES flag is used.
1858 * If the %G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS flag is not set, also sets up
1859 * match rules for signals. Connect to the #GDBusProxy::g-signal signal
1860 * to handle signals from the remote object.
1862 * If @name is a well-known name and the
1863 * %G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START flag isn't set and no name
1864 * owner currently exists, the message bus will be requested to launch
1865 * a name owner for the name.
1867 * This is a synchronous failable constructor. See g_dbus_proxy_new()
1868 * and g_dbus_proxy_new_finish() for the asynchronous version.
1870 * See <xref linkend="gdbus-wellknown-proxy"/> for an example of how #GDBusProxy can be used.
1872 * Returns: A #GDBusProxy or %NULL if error is set. Free with g_object_unref().
1877 g_dbus_proxy_new_sync (GDBusConnection *connection,
1878 GDBusProxyFlags flags,
1879 GDBusInterfaceInfo *info,
1881 const gchar *object_path,
1882 const gchar *interface_name,
1883 GCancellable *cancellable,
1886 GInitable *initable;
1888 g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);
1889 g_return_val_if_fail ((name == NULL && g_dbus_connection_get_unique_name (connection) == NULL) ||
1890 g_dbus_is_name (name), NULL);
1891 g_return_val_if_fail (g_variant_is_object_path (object_path), NULL);
1892 g_return_val_if_fail (g_dbus_is_interface_name (interface_name), NULL);
1894 initable = g_initable_new (G_TYPE_DBUS_PROXY,
1898 "g-interface-info", info,
1900 "g-connection", connection,
1901 "g-object-path", object_path,
1902 "g-interface-name", interface_name,
1904 if (initable != NULL)
1905 return G_DBUS_PROXY (initable);
1910 /* ---------------------------------------------------------------------------------------------------- */
1913 * g_dbus_proxy_new_for_bus:
1914 * @bus_type: A #GBusType.
1915 * @flags: Flags used when constructing the proxy.
1916 * @info: (allow-none): A #GDBusInterfaceInfo specifying the minimal interface that @proxy conforms to or %NULL.
1917 * @name: A bus name (well-known or unique).
1918 * @object_path: An object path.
1919 * @interface_name: A D-Bus interface name.
1920 * @cancellable: A #GCancellable or %NULL.
1921 * @callback: Callback function to invoke when the proxy is ready.
1922 * @user_data: User data to pass to @callback.
1924 * Like g_dbus_proxy_new() but takes a #GBusType instead of a #GDBusConnection.
1926 * See <xref linkend="gdbus-wellknown-proxy"/> for an example of how #GDBusProxy can be used.
1931 g_dbus_proxy_new_for_bus (GBusType bus_type,
1932 GDBusProxyFlags flags,
1933 GDBusInterfaceInfo *info,
1935 const gchar *object_path,
1936 const gchar *interface_name,
1937 GCancellable *cancellable,
1938 GAsyncReadyCallback callback,
1941 g_return_if_fail (g_dbus_is_name (name));
1942 g_return_if_fail (g_variant_is_object_path (object_path));
1943 g_return_if_fail (g_dbus_is_interface_name (interface_name));
1945 g_async_initable_new_async (G_TYPE_DBUS_PROXY,
1951 "g-interface-info", info,
1953 "g-bus-type", bus_type,
1954 "g-object-path", object_path,
1955 "g-interface-name", interface_name,
1960 * g_dbus_proxy_new_for_bus_finish:
1961 * @res: A #GAsyncResult obtained from the #GAsyncReadyCallback function passed to g_dbus_proxy_new_for_bus().
1962 * @error: Return location for error or %NULL.
1964 * Finishes creating a #GDBusProxy.
1966 * Returns: A #GDBusProxy or %NULL if @error is set. Free with g_object_unref().
1971 g_dbus_proxy_new_for_bus_finish (GAsyncResult *res,
1974 return g_dbus_proxy_new_finish (res, error);
1978 * g_dbus_proxy_new_for_bus_sync:
1979 * @bus_type: A #GBusType.
1980 * @flags: Flags used when constructing the proxy.
1981 * @info: (allow-none): A #GDBusInterfaceInfo specifying the minimal interface
1982 * that @proxy conforms to or %NULL.
1983 * @name: A bus name (well-known or unique).
1984 * @object_path: An object path.
1985 * @interface_name: A D-Bus interface name.
1986 * @cancellable: A #GCancellable or %NULL.
1987 * @error: Return location for error or %NULL.
1989 * Like g_dbus_proxy_new_sync() but takes a #GBusType instead of a #GDBusConnection.
1991 * See <xref linkend="gdbus-wellknown-proxy"/> for an example of how #GDBusProxy can be used.
1993 * Returns: A #GDBusProxy or %NULL if error is set. Free with g_object_unref().
1998 g_dbus_proxy_new_for_bus_sync (GBusType bus_type,
1999 GDBusProxyFlags flags,
2000 GDBusInterfaceInfo *info,
2002 const gchar *object_path,
2003 const gchar *interface_name,
2004 GCancellable *cancellable,
2007 GInitable *initable;
2009 g_return_val_if_fail (g_dbus_is_name (name), NULL);
2010 g_return_val_if_fail (g_variant_is_object_path (object_path), NULL);
2011 g_return_val_if_fail (g_dbus_is_interface_name (interface_name), NULL);
2013 initable = g_initable_new (G_TYPE_DBUS_PROXY,
2017 "g-interface-info", info,
2019 "g-bus-type", bus_type,
2020 "g-object-path", object_path,
2021 "g-interface-name", interface_name,
2023 if (initable != NULL)
2024 return G_DBUS_PROXY (initable);
2029 /* ---------------------------------------------------------------------------------------------------- */
2032 * g_dbus_proxy_get_connection:
2033 * @proxy: A #GDBusProxy.
2035 * Gets the connection @proxy is for.
2037 * Returns: (transfer none): A #GDBusConnection owned by @proxy. Do not free.
2042 g_dbus_proxy_get_connection (GDBusProxy *proxy)
2044 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
2045 return proxy->priv->connection;
2049 * g_dbus_proxy_get_flags:
2050 * @proxy: A #GDBusProxy.
2052 * Gets the flags that @proxy was constructed with.
2054 * Returns: Flags from the #GDBusProxyFlags enumeration.
2059 g_dbus_proxy_get_flags (GDBusProxy *proxy)
2061 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), 0);
2062 return proxy->priv->flags;
2066 * g_dbus_proxy_get_name:
2067 * @proxy: A #GDBusProxy.
2069 * Gets the name that @proxy was constructed for.
2071 * Returns: A string owned by @proxy. Do not free.
2076 g_dbus_proxy_get_name (GDBusProxy *proxy)
2078 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
2079 return proxy->priv->name;
2083 * g_dbus_proxy_get_name_owner:
2084 * @proxy: A #GDBusProxy.
2086 * The unique name that owns the name that @proxy is for or %NULL if
2087 * no-one currently owns that name. You may connect to the
2088 * #GObject::notify signal to track changes to the
2089 * #GDBusProxy:g-name-owner property.
2091 * Returns: The name owner or %NULL if no name owner exists. Free with g_free().
2096 g_dbus_proxy_get_name_owner (GDBusProxy *proxy)
2098 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
2099 return g_strdup (proxy->priv->name_owner);
2103 * g_dbus_proxy_get_object_path:
2104 * @proxy: A #GDBusProxy.
2106 * Gets the object path @proxy is for.
2108 * Returns: A string owned by @proxy. Do not free.
2113 g_dbus_proxy_get_object_path (GDBusProxy *proxy)
2115 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
2116 return proxy->priv->object_path;
2120 * g_dbus_proxy_get_interface_name:
2121 * @proxy: A #GDBusProxy.
2123 * Gets the D-Bus interface name @proxy is for.
2125 * Returns: A string owned by @proxy. Do not free.
2130 g_dbus_proxy_get_interface_name (GDBusProxy *proxy)
2132 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
2133 return proxy->priv->interface_name;
2137 * g_dbus_proxy_get_default_timeout:
2138 * @proxy: A #GDBusProxy.
2140 * Gets the timeout to use if -1 (specifying default timeout) is
2141 * passed as @timeout_msec in the g_dbus_proxy_call() and
2142 * g_dbus_proxy_call_sync() functions.
2144 * See the #GDBusProxy:g-default-timeout property for more details.
2146 * Returns: Timeout to use for @proxy.
2151 g_dbus_proxy_get_default_timeout (GDBusProxy *proxy)
2153 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), -1);
2154 return proxy->priv->timeout_msec;
2158 * g_dbus_proxy_set_default_timeout:
2159 * @proxy: A #GDBusProxy.
2160 * @timeout_msec: Timeout in milliseconds.
2162 * Sets the timeout to use if -1 (specifying default timeout) is
2163 * passed as @timeout_msec in the g_dbus_proxy_call() and
2164 * g_dbus_proxy_call_sync() functions.
2166 * See the #GDBusProxy:g-default-timeout property for more details.
2171 g_dbus_proxy_set_default_timeout (GDBusProxy *proxy,
2174 g_return_if_fail (G_IS_DBUS_PROXY (proxy));
2175 g_return_if_fail (timeout_msec == -1 || timeout_msec >= 0);
2177 /* TODO: locking? */
2178 if (proxy->priv->timeout_msec != timeout_msec)
2180 proxy->priv->timeout_msec = timeout_msec;
2181 g_object_notify (G_OBJECT (proxy), "g-default-timeout");
2186 * g_dbus_proxy_get_interface_info:
2187 * @proxy: A #GDBusProxy
2189 * Returns the #GDBusInterfaceInfo, if any, specifying the minimal
2190 * interface that @proxy conforms to.
2192 * See the #GDBusProxy:g-interface-info property for more details.
2194 * Returns: A #GDBusInterfaceInfo or %NULL. Do not unref the returned
2195 * object, it is owned by @proxy.
2199 GDBusInterfaceInfo *
2200 g_dbus_proxy_get_interface_info (GDBusProxy *proxy)
2202 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
2203 return proxy->priv->expected_interface;
2207 * g_dbus_proxy_set_interface_info:
2208 * @proxy: A #GDBusProxy
2209 * @info: (allow-none): Minimum interface this proxy conforms to or %NULL to unset.
2211 * Ensure that interactions with @proxy conform to the given
2212 * interface. For example, when completing a method call, if the type
2213 * signature of the message isn't what's expected, the given #GError
2214 * is set. Signals that have a type signature mismatch are simply
2217 * See the #GDBusProxy:g-interface-info property for more details.
2222 g_dbus_proxy_set_interface_info (GDBusProxy *proxy,
2223 GDBusInterfaceInfo *info)
2225 g_return_if_fail (G_IS_DBUS_PROXY (proxy));
2226 if (proxy->priv->expected_interface != NULL)
2228 g_dbus_interface_info_cache_release (proxy->priv->expected_interface);
2229 g_dbus_interface_info_unref (proxy->priv->expected_interface);
2231 proxy->priv->expected_interface = info != NULL ? g_dbus_interface_info_ref (info) : NULL;
2232 if (proxy->priv->expected_interface != NULL)
2233 g_dbus_interface_info_cache_build (proxy->priv->expected_interface);
2236 /* ---------------------------------------------------------------------------------------------------- */
2239 maybe_split_method_name (const gchar *method_name,
2240 gchar **out_interface_name,
2241 const gchar **out_method_name)
2246 g_assert (out_interface_name != NULL);
2247 g_assert (out_method_name != NULL);
2248 *out_interface_name = NULL;
2249 *out_method_name = NULL;
2251 if (strchr (method_name, '.') != NULL)
2256 p = g_strdup (method_name);
2257 last_dot = strrchr (p, '.');
2260 *out_interface_name = p;
2261 *out_method_name = last_dot + 1;
2271 reply_cb (GDBusConnection *connection,
2275 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data);
2280 value = g_dbus_connection_call_finish (connection,
2285 g_simple_async_result_take_error (simple, error);
2289 g_simple_async_result_set_op_res_gpointer (simple,
2291 (GDestroyNotify) g_variant_unref);
2294 /* no need to complete in idle since the method GDBusConnection already does */
2295 g_simple_async_result_complete (simple);
2296 g_object_unref (simple);
2299 static const GDBusMethodInfo *
2300 lookup_method_info_or_warn (GDBusProxy *proxy,
2301 const gchar *method_name)
2303 const GDBusMethodInfo *info;
2305 if (proxy->priv->expected_interface == NULL)
2308 info = g_dbus_interface_info_lookup_method (proxy->priv->expected_interface, method_name);
2311 g_warning ("Trying to invoke method %s which isn't in expected interface %s",
2312 method_name, proxy->priv->expected_interface->name);
2318 static const gchar *
2319 get_destination_for_call (GDBusProxy *proxy)
2325 /* If proxy->priv->name is a unique name, then proxy->priv->name_owner
2326 * is never NULL and always the same as proxy->priv->name. We use this
2327 * knowledge to avoid checking if proxy->priv->name is a unique or
2330 ret = proxy->priv->name_owner;
2334 if (proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START)
2337 ret = proxy->priv->name;
2344 * g_dbus_proxy_call:
2345 * @proxy: A #GDBusProxy.
2346 * @method_name: Name of method to invoke.
2347 * @parameters: (allow-none): A #GVariant tuple with parameters for the signal or %NULL if not passing parameters.
2348 * @flags: Flags from the #GDBusCallFlags enumeration.
2349 * @timeout_msec: The timeout in milliseconds (with %G_MAXINT meaning
2350 * "infinite") or -1 to use the proxy default timeout.
2351 * @cancellable: A #GCancellable or %NULL.
2352 * @callback: A #GAsyncReadyCallback to call when the request is satisfied or %NULL if you don't
2353 * care about the result of the method invocation.
2354 * @user_data: The data to pass to @callback.
2356 * Asynchronously invokes the @method_name method on @proxy.
2358 * If @method_name contains any dots, then @name is split into interface and
2359 * method name parts. This allows using @proxy for invoking methods on
2362 * If the #GDBusConnection associated with @proxy is closed then
2363 * the operation will fail with %G_IO_ERROR_CLOSED. If
2364 * @cancellable is canceled, the operation will fail with
2365 * %G_IO_ERROR_CANCELLED. If @parameters contains a value not
2366 * compatible with the D-Bus protocol, the operation fails with
2367 * %G_IO_ERROR_INVALID_ARGUMENT.
2369 * If the @parameters #GVariant is floating, it is consumed. This allows
2370 * convenient 'inline' use of g_variant_new(), e.g.:
2372 * g_dbus_proxy_call (proxy,
2374 * g_variant_new ("(ss)",
2377 * G_DBUS_CALL_FLAGS_NONE,
2380 * (GAsyncReadyCallback) two_strings_done,
2384 * This is an asynchronous method. When the operation is finished,
2385 * @callback will be invoked in the
2386 * <link linkend="g-main-context-push-thread-default">thread-default
2387 * main loop</link> of the thread you are calling this method from.
2388 * You can then call g_dbus_proxy_call_finish() to get the result of
2389 * the operation. See g_dbus_proxy_call_sync() for the synchronous
2390 * version of this method.
2395 g_dbus_proxy_call (GDBusProxy *proxy,
2396 const gchar *method_name,
2397 GVariant *parameters,
2398 GDBusCallFlags flags,
2400 GCancellable *cancellable,
2401 GAsyncReadyCallback callback,
2404 GSimpleAsyncResult *simple;
2406 gchar *split_interface_name;
2407 const gchar *split_method_name;
2408 const gchar *target_method_name;
2409 const gchar *target_interface_name;
2410 const gchar *destination;
2411 GVariantType *reply_type;
2413 g_return_if_fail (G_IS_DBUS_PROXY (proxy));
2414 g_return_if_fail (g_dbus_is_member_name (method_name) || g_dbus_is_interface_name (method_name));
2415 g_return_if_fail (parameters == NULL || g_variant_is_of_type (parameters, G_VARIANT_TYPE_TUPLE));
2416 g_return_if_fail (timeout_msec == -1 || timeout_msec >= 0);
2419 split_interface_name = NULL;
2421 simple = g_simple_async_result_new (G_OBJECT (proxy),
2426 was_split = maybe_split_method_name (method_name, &split_interface_name, &split_method_name);
2427 target_method_name = was_split ? split_method_name : method_name;
2428 target_interface_name = was_split ? split_interface_name : proxy->priv->interface_name;
2430 /* Warn if method is unexpected (cf. :g-interface-info) */
2433 const GDBusMethodInfo *expected_method_info;
2434 expected_method_info = lookup_method_info_or_warn (proxy, target_method_name);
2435 if (expected_method_info != NULL)
2436 reply_type = _g_dbus_compute_complete_signature (expected_method_info->out_args);
2440 if (proxy->priv->name != NULL)
2442 destination = get_destination_for_call (proxy);
2443 if (destination == NULL)
2445 g_simple_async_result_set_error (simple,
2448 _("Cannot invoke method; proxy is for a well-known name without an owner and proxy was constructed with the G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START flag"));
2453 g_dbus_connection_call (proxy->priv->connection,
2455 proxy->priv->object_path,
2456 target_interface_name,
2461 timeout_msec == -1 ? proxy->priv->timeout_msec : timeout_msec,
2463 (GAsyncReadyCallback) reply_cb,
2467 if (reply_type != NULL)
2468 g_variant_type_free (reply_type);
2470 g_free (split_interface_name);
2474 * g_dbus_proxy_call_finish:
2475 * @proxy: A #GDBusProxy.
2476 * @res: A #GAsyncResult obtained from the #GAsyncReadyCallback passed to g_dbus_proxy_call().
2477 * @error: Return location for error or %NULL.
2479 * Finishes an operation started with g_dbus_proxy_call().
2481 * Returns: %NULL if @error is set. Otherwise a #GVariant tuple with
2482 * return values. Free with g_variant_unref().
2487 g_dbus_proxy_call_finish (GDBusProxy *proxy,
2491 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
2494 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
2495 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
2496 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
2498 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_dbus_proxy_call);
2502 if (g_simple_async_result_propagate_error (simple, error))
2505 value = g_variant_ref (g_simple_async_result_get_op_res_gpointer (simple));
2512 * g_dbus_proxy_call_sync:
2513 * @proxy: A #GDBusProxy.
2514 * @method_name: Name of method to invoke.
2515 * @parameters: (allow-none): A #GVariant tuple with parameters for the signal
2516 * or %NULL if not passing parameters.
2517 * @flags: Flags from the #GDBusCallFlags enumeration.
2518 * @timeout_msec: The timeout in milliseconds (with %G_MAXINT meaning
2519 * "infinite") or -1 to use the proxy default timeout.
2520 * @cancellable: A #GCancellable or %NULL.
2521 * @error: Return location for error or %NULL.
2523 * Synchronously invokes the @method_name method on @proxy.
2525 * If @method_name contains any dots, then @name is split into interface and
2526 * method name parts. This allows using @proxy for invoking methods on
2529 * If the #GDBusConnection associated with @proxy is disconnected then
2530 * the operation will fail with %G_IO_ERROR_CLOSED. If
2531 * @cancellable is canceled, the operation will fail with
2532 * %G_IO_ERROR_CANCELLED. If @parameters contains a value not
2533 * compatible with the D-Bus protocol, the operation fails with
2534 * %G_IO_ERROR_INVALID_ARGUMENT.
2536 * If the @parameters #GVariant is floating, it is consumed. This allows
2537 * convenient 'inline' use of g_variant_new(), e.g.:
2539 * g_dbus_proxy_call_sync (proxy,
2541 * g_variant_new ("(ss)",
2544 * G_DBUS_CALL_FLAGS_NONE,
2550 * The calling thread is blocked until a reply is received. See
2551 * g_dbus_proxy_call() for the asynchronous version of this
2554 * Returns: %NULL if @error is set. Otherwise a #GVariant tuple with
2555 * return values. Free with g_variant_unref().
2560 g_dbus_proxy_call_sync (GDBusProxy *proxy,
2561 const gchar *method_name,
2562 GVariant *parameters,
2563 GDBusCallFlags flags,
2565 GCancellable *cancellable,
2570 gchar *split_interface_name;
2571 const gchar *split_method_name;
2572 const gchar *target_method_name;
2573 const gchar *target_interface_name;
2574 const gchar *destination;
2575 GVariantType *reply_type;
2577 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
2578 g_return_val_if_fail (g_dbus_is_member_name (method_name) || g_dbus_is_interface_name (method_name), NULL);
2579 g_return_val_if_fail (parameters == NULL || g_variant_is_of_type (parameters, G_VARIANT_TYPE_TUPLE), NULL);
2580 g_return_val_if_fail (timeout_msec == -1 || timeout_msec >= 0, NULL);
2581 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
2585 was_split = maybe_split_method_name (method_name, &split_interface_name, &split_method_name);
2586 target_method_name = was_split ? split_method_name : method_name;
2587 target_interface_name = was_split ? split_interface_name : proxy->priv->interface_name;
2589 /* Warn if method is unexpected (cf. :g-interface-info) */
2592 const GDBusMethodInfo *expected_method_info;
2593 expected_method_info = lookup_method_info_or_warn (proxy, target_method_name);
2594 if (expected_method_info != NULL)
2595 reply_type = _g_dbus_compute_complete_signature (expected_method_info->out_args);
2599 if (proxy->priv->name != NULL)
2601 destination = get_destination_for_call (proxy);
2602 if (destination == NULL)
2604 g_set_error_literal (error,
2607 _("Cannot invoke method; proxy is for a well-known name without an owner and proxy was constructed with the G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START flag"));
2613 ret = g_dbus_connection_call_sync (proxy->priv->connection,
2615 proxy->priv->object_path,
2616 target_interface_name,
2621 timeout_msec == -1 ? proxy->priv->timeout_msec : timeout_msec,
2626 if (reply_type != NULL)
2627 g_variant_type_free (reply_type);
2629 g_free (split_interface_name);
2634 /* ---------------------------------------------------------------------------------------------------- */
2636 static GDBusInterfaceInfo *
2637 _g_dbus_proxy_get_info (GDBusInterface *interface)
2639 GDBusProxy *proxy = G_DBUS_PROXY (interface);
2640 return g_dbus_proxy_get_interface_info (proxy);
2643 static GDBusObject *
2644 _g_dbus_proxy_get_object (GDBusInterface *interface)
2646 GDBusProxy *proxy = G_DBUS_PROXY (interface);
2647 return proxy->priv->object;
2651 _g_dbus_proxy_set_object (GDBusInterface *interface,
2652 GDBusObject *object)
2654 GDBusProxy *proxy = G_DBUS_PROXY (interface);
2655 if (proxy->priv->object != NULL)
2656 g_object_remove_weak_pointer (G_OBJECT (proxy->priv->object), (gpointer *) &proxy->priv->object);
2657 proxy->priv->object = object;
2658 if (proxy->priv->object != NULL)
2659 g_object_add_weak_pointer (G_OBJECT (proxy->priv->object), (gpointer *) &proxy->priv->object);
2663 dbus_interface_iface_init (GDBusInterfaceIface *dbus_interface_iface)
2665 dbus_interface_iface->get_info = _g_dbus_proxy_get_info;
2666 dbus_interface_iface->get_object = _g_dbus_proxy_get_object;
2667 dbus_interface_iface->set_object = _g_dbus_proxy_set_object;
2670 /* ---------------------------------------------------------------------------------------------------- */