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 * A #GDBusProxy instance can be used from multiple threads but note
79 * that all signals (e.g. #GDBusProxy::g-signal, #GDBusProxy::g-properties
80 * and #GObject::notify) are emitted in the
81 * <link linkend="g-main-context-push-thread-default">thread-default main loop</link>
82 * of the thread where the instance was constructed.
84 * See <xref linkend="gdbus-example-proxy-subclass"/> for an example.
86 * <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>
89 /* lock protecting the properties GHashTable */
90 G_LOCK_DEFINE_STATIC (properties_lock);
92 /* ---------------------------------------------------------------------------------------------------- */
94 G_LOCK_DEFINE_STATIC (signal_subscription_lock);
98 volatile gint ref_count;
100 } SignalSubscriptionData;
102 static SignalSubscriptionData *
103 signal_subscription_ref (SignalSubscriptionData *data)
105 g_atomic_int_inc (&data->ref_count);
110 signal_subscription_unref (SignalSubscriptionData *data)
112 if (g_atomic_int_dec_and_test (&data->ref_count))
114 g_slice_free (SignalSubscriptionData, data);
118 /* ---------------------------------------------------------------------------------------------------- */
120 struct _GDBusProxyPrivate
123 GDBusProxyFlags flags;
124 GDBusConnection *connection;
129 gchar *interface_name;
132 guint name_owner_changed_subscription_id;
134 GCancellable *get_all_cancellable;
136 /* gchar* -> GVariant* */
137 GHashTable *properties;
139 GDBusInterfaceInfo *expected_interface;
141 guint properties_changed_subscription_id;
142 guint signals_subscription_id;
144 gboolean initialized;
148 SignalSubscriptionData *signal_subscription_data;
160 PROP_G_INTERFACE_NAME,
161 PROP_G_DEFAULT_TIMEOUT,
162 PROP_G_INTERFACE_INFO
167 PROPERTIES_CHANGED_SIGNAL,
172 guint signals[LAST_SIGNAL] = {0};
174 static void dbus_interface_iface_init (GDBusInterfaceIface *dbus_interface_iface);
175 static void initable_iface_init (GInitableIface *initable_iface);
176 static void async_initable_iface_init (GAsyncInitableIface *async_initable_iface);
178 G_DEFINE_TYPE_WITH_CODE (GDBusProxy, g_dbus_proxy, G_TYPE_OBJECT,
179 G_IMPLEMENT_INTERFACE (G_TYPE_DBUS_INTERFACE, dbus_interface_iface_init)
180 G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, initable_iface_init)
181 G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, async_initable_iface_init)
185 g_dbus_proxy_dispose (GObject *object)
187 GDBusProxy *proxy = G_DBUS_PROXY (object);
188 G_LOCK (signal_subscription_lock);
189 if (proxy->priv->signal_subscription_data != NULL)
191 proxy->priv->signal_subscription_data->proxy = NULL;
192 signal_subscription_unref (proxy->priv->signal_subscription_data);
193 proxy->priv->signal_subscription_data = NULL;
195 G_UNLOCK (signal_subscription_lock);
197 G_OBJECT_CLASS (g_dbus_proxy_parent_class)->dispose (object);
201 g_dbus_proxy_finalize (GObject *object)
203 GDBusProxy *proxy = G_DBUS_PROXY (object);
205 g_warn_if_fail (proxy->priv->get_all_cancellable == NULL);
207 if (proxy->priv->name_owner_changed_subscription_id > 0)
208 g_dbus_connection_signal_unsubscribe (proxy->priv->connection,
209 proxy->priv->name_owner_changed_subscription_id);
211 if (proxy->priv->properties_changed_subscription_id > 0)
212 g_dbus_connection_signal_unsubscribe (proxy->priv->connection,
213 proxy->priv->properties_changed_subscription_id);
215 if (proxy->priv->signals_subscription_id > 0)
216 g_dbus_connection_signal_unsubscribe (proxy->priv->connection,
217 proxy->priv->signals_subscription_id);
219 if (proxy->priv->connection != NULL)
220 g_object_unref (proxy->priv->connection);
221 g_free (proxy->priv->name);
222 g_free (proxy->priv->name_owner);
223 g_free (proxy->priv->object_path);
224 g_free (proxy->priv->interface_name);
225 if (proxy->priv->properties != NULL)
226 g_hash_table_unref (proxy->priv->properties);
228 if (proxy->priv->expected_interface != NULL)
230 g_dbus_interface_info_cache_release (proxy->priv->expected_interface);
231 g_dbus_interface_info_unref (proxy->priv->expected_interface);
234 if (proxy->priv->object != NULL)
235 g_object_remove_weak_pointer (G_OBJECT (proxy->priv->object), (gpointer *) &proxy->priv->object);
237 G_OBJECT_CLASS (g_dbus_proxy_parent_class)->finalize (object);
241 g_dbus_proxy_get_property (GObject *object,
246 GDBusProxy *proxy = G_DBUS_PROXY (object);
250 case PROP_G_CONNECTION:
251 g_value_set_object (value, proxy->priv->connection);
255 g_value_set_flags (value, proxy->priv->flags);
259 g_value_set_string (value, proxy->priv->name);
262 case PROP_G_NAME_OWNER:
263 g_value_set_string (value, proxy->priv->name_owner);
266 case PROP_G_OBJECT_PATH:
267 g_value_set_string (value, proxy->priv->object_path);
270 case PROP_G_INTERFACE_NAME:
271 g_value_set_string (value, proxy->priv->interface_name);
274 case PROP_G_DEFAULT_TIMEOUT:
275 g_value_set_int (value, proxy->priv->timeout_msec);
278 case PROP_G_INTERFACE_INFO:
279 g_value_set_boxed (value, g_dbus_proxy_get_interface_info (proxy));
283 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
289 g_dbus_proxy_set_property (GObject *object,
294 GDBusProxy *proxy = G_DBUS_PROXY (object);
298 case PROP_G_CONNECTION:
299 proxy->priv->connection = g_value_dup_object (value);
303 proxy->priv->flags = g_value_get_flags (value);
307 proxy->priv->name = g_value_dup_string (value);
310 case PROP_G_OBJECT_PATH:
311 proxy->priv->object_path = g_value_dup_string (value);
314 case PROP_G_INTERFACE_NAME:
315 proxy->priv->interface_name = g_value_dup_string (value);
318 case PROP_G_DEFAULT_TIMEOUT:
319 g_dbus_proxy_set_default_timeout (proxy, g_value_get_int (value));
322 case PROP_G_INTERFACE_INFO:
323 g_dbus_proxy_set_interface_info (proxy, g_value_get_boxed (value));
326 case PROP_G_BUS_TYPE:
327 proxy->priv->bus_type = g_value_get_enum (value);
331 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
337 g_dbus_proxy_class_init (GDBusProxyClass *klass)
339 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
341 gobject_class->dispose = g_dbus_proxy_dispose;
342 gobject_class->finalize = g_dbus_proxy_finalize;
343 gobject_class->set_property = g_dbus_proxy_set_property;
344 gobject_class->get_property = g_dbus_proxy_get_property;
346 /* Note that all property names are prefixed to avoid collisions with D-Bus property names
347 * in derived classes */
350 * GDBusProxy:g-interface-info:
352 * Ensure that interactions with this proxy conform to the given
353 * interface. For example, when completing a method call, if the
354 * type signature of the message isn't what's expected, the given
355 * #GError is set. Signals that have a type signature mismatch are
360 g_object_class_install_property (gobject_class,
361 PROP_G_INTERFACE_INFO,
362 g_param_spec_boxed ("g-interface-info",
363 P_("Interface Information"),
364 P_("Interface Information"),
365 G_TYPE_DBUS_INTERFACE_INFO,
368 G_PARAM_STATIC_NAME |
369 G_PARAM_STATIC_BLURB |
370 G_PARAM_STATIC_NICK));
373 * GDBusProxy:g-connection:
375 * The #GDBusConnection the proxy is for.
379 g_object_class_install_property (gobject_class,
381 g_param_spec_object ("g-connection",
383 P_("The connection the proxy is for"),
384 G_TYPE_DBUS_CONNECTION,
387 G_PARAM_CONSTRUCT_ONLY |
388 G_PARAM_STATIC_NAME |
389 G_PARAM_STATIC_BLURB |
390 G_PARAM_STATIC_NICK));
393 * GDBusProxy:g-bus-type:
395 * If this property is not %G_BUS_TYPE_NONE, then
396 * #GDBusProxy:g-connection must be %NULL and will be set to the
397 * #GDBusConnection obtained by calling g_bus_get() with the value
402 g_object_class_install_property (gobject_class,
404 g_param_spec_enum ("g-bus-type",
406 P_("The bus to connect to, if any"),
410 G_PARAM_CONSTRUCT_ONLY |
411 G_PARAM_STATIC_NAME |
412 G_PARAM_STATIC_BLURB |
413 G_PARAM_STATIC_NICK));
416 * GDBusProxy:g-flags:
418 * Flags from the #GDBusProxyFlags enumeration.
422 g_object_class_install_property (gobject_class,
424 g_param_spec_flags ("g-flags",
426 P_("Flags for the proxy"),
427 G_TYPE_DBUS_PROXY_FLAGS,
428 G_DBUS_PROXY_FLAGS_NONE,
431 G_PARAM_CONSTRUCT_ONLY |
432 G_PARAM_STATIC_NAME |
433 G_PARAM_STATIC_BLURB |
434 G_PARAM_STATIC_NICK));
439 * The well-known or unique name that the proxy is for.
443 g_object_class_install_property (gobject_class,
445 g_param_spec_string ("g-name",
447 P_("The well-known or unique name that the proxy is for"),
451 G_PARAM_CONSTRUCT_ONLY |
452 G_PARAM_STATIC_NAME |
453 G_PARAM_STATIC_BLURB |
454 G_PARAM_STATIC_NICK));
457 * GDBusProxy:g-name-owner:
459 * The unique name that owns #GDBusProxy:name or %NULL if no-one
460 * currently owns that name. You may connect to #GObject::notify signal to
461 * track changes to this property.
465 g_object_class_install_property (gobject_class,
467 g_param_spec_string ("g-name-owner",
469 P_("The unique name for the owner"),
472 G_PARAM_STATIC_NAME |
473 G_PARAM_STATIC_BLURB |
474 G_PARAM_STATIC_NICK));
477 * GDBusProxy:g-object-path:
479 * The object path the proxy is for.
483 g_object_class_install_property (gobject_class,
485 g_param_spec_string ("g-object-path",
487 P_("The object path the proxy is for"),
491 G_PARAM_CONSTRUCT_ONLY |
492 G_PARAM_STATIC_NAME |
493 G_PARAM_STATIC_BLURB |
494 G_PARAM_STATIC_NICK));
497 * GDBusProxy:g-interface-name:
499 * The D-Bus interface name the proxy is for.
503 g_object_class_install_property (gobject_class,
504 PROP_G_INTERFACE_NAME,
505 g_param_spec_string ("g-interface-name",
506 P_("g-interface-name"),
507 P_("The D-Bus interface name the proxy is for"),
511 G_PARAM_CONSTRUCT_ONLY |
512 G_PARAM_STATIC_NAME |
513 G_PARAM_STATIC_BLURB |
514 G_PARAM_STATIC_NICK));
517 * GDBusProxy:g-default-timeout:
519 * The timeout to use if -1 (specifying default timeout) is passed
520 * as @timeout_msec in the g_dbus_proxy_call() and
521 * g_dbus_proxy_call_sync() functions.
523 * This allows applications to set a proxy-wide timeout for all
524 * remote method invocations on the proxy. If this property is -1,
525 * the default timeout (typically 25 seconds) is used. If set to
526 * %G_MAXINT, then no timeout is used.
530 g_object_class_install_property (gobject_class,
531 PROP_G_DEFAULT_TIMEOUT,
532 g_param_spec_int ("g-default-timeout",
533 P_("Default Timeout"),
534 P_("Timeout for remote method invocation"),
541 G_PARAM_STATIC_NAME |
542 G_PARAM_STATIC_BLURB |
543 G_PARAM_STATIC_NICK));
546 * GDBusProxy::g-properties-changed:
547 * @proxy: The #GDBusProxy emitting the signal.
548 * @changed_properties: A #GVariant containing the properties that changed
549 * @invalidated_properties: A %NULL terminated array of properties that was invalidated
551 * Emitted when one or more D-Bus properties on @proxy changes. The
552 * local cache has already been updated when this signal fires. Note
553 * that both @changed_properties and @invalidated_properties are
554 * guaranteed to never be %NULL (either may be empty though).
556 * This signal corresponds to the
557 * <literal>PropertiesChanged</literal> D-Bus signal on the
558 * <literal>org.freedesktop.DBus.Properties</literal> interface.
562 signals[PROPERTIES_CHANGED_SIGNAL] = g_signal_new ("g-properties-changed",
564 G_SIGNAL_RUN_LAST | G_SIGNAL_MUST_COLLECT,
565 G_STRUCT_OFFSET (GDBusProxyClass, g_properties_changed),
568 _gio_marshal_VOID__VARIANT_BOXED,
572 G_TYPE_STRV | G_SIGNAL_TYPE_STATIC_SCOPE);
575 * GDBusProxy::g-signal:
576 * @proxy: The #GDBusProxy emitting the signal.
577 * @sender_name: The sender of the signal or %NULL if the connection is not a bus connection.
578 * @signal_name: The name of the signal.
579 * @parameters: A #GVariant tuple with parameters for the signal.
581 * Emitted when a signal from the remote object and interface that @proxy is for, has been received.
585 signals[SIGNAL_SIGNAL] = g_signal_new ("g-signal",
587 G_SIGNAL_RUN_LAST | G_SIGNAL_MUST_COLLECT,
588 G_STRUCT_OFFSET (GDBusProxyClass, g_signal),
591 _gio_marshal_VOID__STRING_STRING_VARIANT,
599 g_type_class_add_private (klass, sizeof (GDBusProxyPrivate));
603 g_dbus_proxy_init (GDBusProxy *proxy)
605 proxy->priv = G_TYPE_INSTANCE_GET_PRIVATE (proxy, G_TYPE_DBUS_PROXY, GDBusProxyPrivate);
606 proxy->priv->signal_subscription_data = g_slice_new0 (SignalSubscriptionData);
607 proxy->priv->signal_subscription_data->ref_count = 1;
608 proxy->priv->signal_subscription_data->proxy = proxy;
609 proxy->priv->properties = g_hash_table_new_full (g_str_hash,
612 (GDestroyNotify) g_variant_unref);
615 /* ---------------------------------------------------------------------------------------------------- */
618 property_name_sort_func (const gchar **a,
621 return g_strcmp0 (*a, *b);
625 * g_dbus_proxy_get_cached_property_names:
626 * @proxy: A #GDBusProxy.
628 * Gets the names of all cached properties on @proxy.
630 * Returns: A %NULL-terminated array of strings or %NULL if @proxy has
631 * no cached properties. Free the returned array with g_strfreev().
636 g_dbus_proxy_get_cached_property_names (GDBusProxy *proxy)
643 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
645 G_LOCK (properties_lock);
648 if (g_hash_table_size (proxy->priv->properties) == 0)
651 p = g_ptr_array_new ();
653 g_hash_table_iter_init (&iter, proxy->priv->properties);
654 while (g_hash_table_iter_next (&iter, (gpointer) &key, NULL))
655 g_ptr_array_add (p, g_strdup (key));
656 g_ptr_array_sort (p, (GCompareFunc) property_name_sort_func);
657 g_ptr_array_add (p, NULL);
659 names = (gchar **) g_ptr_array_free (p, FALSE);
662 G_UNLOCK (properties_lock);
666 static const GDBusPropertyInfo *
667 lookup_property_info_or_warn (GDBusProxy *proxy,
668 const gchar *property_name)
670 const GDBusPropertyInfo *info;
672 if (proxy->priv->expected_interface == NULL)
675 info = g_dbus_interface_info_lookup_property (proxy->priv->expected_interface, property_name);
678 g_warning ("Trying to lookup property %s which isn't in expected interface %s",
680 proxy->priv->expected_interface->name);
687 * g_dbus_proxy_get_cached_property:
688 * @proxy: A #GDBusProxy.
689 * @property_name: Property name.
691 * Looks up the value for a property from the cache. This call does no
694 * If @proxy has an expected interface (see
695 * #GDBusProxy:g-interface-info), then @property_name (for existence)
696 * is checked against it.
698 * Returns: A reference to the #GVariant instance that holds the value
699 * for @property_name or %NULL if the value is not in the cache. The
700 * returned reference must be freed with g_variant_unref().
705 g_dbus_proxy_get_cached_property (GDBusProxy *proxy,
706 const gchar *property_name)
710 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
711 g_return_val_if_fail (property_name != NULL, NULL);
713 G_LOCK (properties_lock);
715 value = g_hash_table_lookup (proxy->priv->properties, property_name);
718 lookup_property_info_or_warn (proxy, property_name);
723 g_variant_ref (value);
726 G_UNLOCK (properties_lock);
731 * g_dbus_proxy_set_cached_property:
732 * @proxy: A #GDBusProxy
733 * @property_name: Property name.
734 * @value: (allow-none): Value for the property or %NULL to remove it from the cache.
736 * If @value is not %NULL, sets the cached value for the property with
737 * name @property_name to the value in @value.
739 * If @value is %NULL, then the cached value is removed from the
742 * If @proxy has an expected interface (see
743 * #GDBusProxy:g-interface-info), then @property_name (for existence)
744 * and @value (for the type) is checked against it.
746 * If the @value #GVariant is floating, it is consumed. This allows
747 * convenient 'inline' use of g_variant_new(), e.g.
749 * g_dbus_proxy_set_cached_property (proxy,
751 * g_variant_new ("(si)",
756 * Normally you will not need to use this method since @proxy is
757 * tracking changes using the
758 * <literal>org.freedesktop.DBus.Properties.PropertiesChanged</literal>
759 * D-Bus signal. However, for performance reasons an object may decide
760 * to not use this signal for some properties and instead use a
761 * proprietary out-of-band mechanism to transmit changes.
763 * As a concrete example, consider an object with a property
764 * <literal>ChatroomParticipants</literal> which is an array of
765 * strings. Instead of transmitting the same (long) array every time
766 * the property changes, it is more efficient to only transmit the
767 * delta using e.g. signals <literal>ChatroomParticipantJoined(String
768 * name)</literal> and <literal>ChatroomParticipantParted(String
774 g_dbus_proxy_set_cached_property (GDBusProxy *proxy,
775 const gchar *property_name,
778 const GDBusPropertyInfo *info;
780 g_return_if_fail (G_IS_DBUS_PROXY (proxy));
781 g_return_if_fail (property_name != NULL);
783 G_LOCK (properties_lock);
787 info = lookup_property_info_or_warn (proxy, property_name);
790 if (g_strcmp0 (info->signature, g_variant_get_type_string (value)) != 0)
792 g_warning ("Trying to set property %s of type %s but according to the expected "
793 "interface the type is %s",
795 g_variant_get_type_string (value),
800 g_hash_table_insert (proxy->priv->properties,
801 g_strdup (property_name),
802 g_variant_ref_sink (value));
806 g_hash_table_remove (proxy->priv->properties, property_name);
810 G_UNLOCK (properties_lock);
813 /* ---------------------------------------------------------------------------------------------------- */
816 on_signal_received (GDBusConnection *connection,
817 const gchar *sender_name,
818 const gchar *object_path,
819 const gchar *interface_name,
820 const gchar *signal_name,
821 GVariant *parameters,
824 SignalSubscriptionData *data = user_data;
827 G_LOCK (signal_subscription_lock);
831 G_UNLOCK (signal_subscription_lock);
836 g_object_ref (proxy);
837 G_UNLOCK (signal_subscription_lock);
840 if (!proxy->priv->initialized)
843 if (proxy->priv->name_owner != NULL && g_strcmp0 (sender_name, proxy->priv->name_owner) != 0)
846 if (proxy->priv->expected_interface != NULL)
848 const GDBusSignalInfo *info;
849 GVariantType *expected_type;
850 info = g_dbus_interface_info_lookup_signal (proxy->priv->expected_interface, signal_name);
853 expected_type = _g_dbus_compute_complete_signature (info->args);
854 if (!g_variant_type_equal (expected_type, g_variant_get_type (parameters)))
856 g_variant_type_free (expected_type);
859 g_variant_type_free (expected_type);
862 g_signal_emit (proxy,
863 signals[SIGNAL_SIGNAL],
870 g_object_unref (proxy);
873 /* ---------------------------------------------------------------------------------------------------- */
875 /* must hold properties_lock */
877 insert_property_checked (GDBusProxy *proxy,
878 gchar *property_name,
881 if (proxy->priv->expected_interface != NULL)
883 const GDBusPropertyInfo *info;
885 info = g_dbus_interface_info_lookup_property (proxy->priv->expected_interface, property_name);
886 /* Ignore unknown properties */
890 /* Ignore properties with the wrong type */
891 if (g_strcmp0 (info->signature, g_variant_get_type_string (value)) != 0)
895 g_hash_table_insert (proxy->priv->properties,
896 property_name, /* adopts string */
897 value); /* adopts value */
902 g_variant_unref (value);
903 g_free (property_name);
907 on_properties_changed (GDBusConnection *connection,
908 const gchar *sender_name,
909 const gchar *object_path,
910 const gchar *interface_name,
911 const gchar *signal_name,
912 GVariant *parameters,
915 SignalSubscriptionData *data = user_data;
917 const gchar *interface_name_for_signal;
918 GVariant *changed_properties;
919 gchar **invalidated_properties;
925 G_LOCK (signal_subscription_lock);
929 G_UNLOCK (signal_subscription_lock);
934 g_object_ref (proxy);
935 G_UNLOCK (signal_subscription_lock);
938 changed_properties = NULL;
939 invalidated_properties = NULL;
941 if (!proxy->priv->initialized)
944 if (proxy->priv->name_owner != NULL && g_strcmp0 (sender_name, proxy->priv->name_owner) != 0)
947 if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(sa{sv}as)")))
949 g_warning ("Value for PropertiesChanged signal with type `%s' does not match `(sa{sv}as)'",
950 g_variant_get_type_string (parameters));
954 g_variant_get (parameters,
956 &interface_name_for_signal,
958 &invalidated_properties);
960 if (g_strcmp0 (interface_name_for_signal, proxy->priv->interface_name) != 0)
963 G_LOCK (properties_lock);
965 g_variant_iter_init (&iter, changed_properties);
966 while (g_variant_iter_next (&iter, "{sv}", &key, &value))
968 insert_property_checked (proxy,
969 key, /* adopts string */
970 value); /* adopts value */
973 for (n = 0; invalidated_properties[n] != NULL; n++)
975 g_hash_table_remove (proxy->priv->properties, invalidated_properties[n]);
978 G_UNLOCK (properties_lock);
981 g_signal_emit (proxy, signals[PROPERTIES_CHANGED_SIGNAL],
984 invalidated_properties);
987 if (changed_properties != NULL)
988 g_variant_unref (changed_properties);
989 g_free (invalidated_properties);
991 g_object_unref (proxy);
994 /* ---------------------------------------------------------------------------------------------------- */
997 process_get_all_reply (GDBusProxy *proxy,
1003 guint num_properties;
1005 if (!g_variant_is_of_type (result, G_VARIANT_TYPE ("(a{sv})")))
1007 g_warning ("Value for GetAll reply with type `%s' does not match `(a{sv})'",
1008 g_variant_get_type_string (result));
1012 G_LOCK (properties_lock);
1014 g_variant_get (result, "(a{sv})", &iter);
1015 while (g_variant_iter_next (iter, "{sv}", &key, &value))
1017 insert_property_checked (proxy,
1018 key, /* adopts string */
1019 value); /* adopts value */
1021 g_variant_iter_free (iter);
1023 num_properties = g_hash_table_size (proxy->priv->properties);
1024 G_UNLOCK (properties_lock);
1026 /* Synthesize ::g-properties-changed changed */
1027 if (num_properties > 0)
1029 GVariant *changed_properties;
1030 const gchar *invalidated_properties[1] = {NULL};
1032 g_variant_get (result,
1034 &changed_properties);
1035 g_signal_emit (proxy, signals[PROPERTIES_CHANGED_SIGNAL],
1038 invalidated_properties);
1039 g_variant_unref (changed_properties);
1049 GCancellable *cancellable;
1051 } LoadPropertiesOnNameOwnerChangedData;
1054 on_name_owner_changed_get_all_cb (GDBusConnection *connection,
1058 LoadPropertiesOnNameOwnerChangedData *data = user_data;
1066 result = g_dbus_connection_call_finish (connection,
1071 if (error->domain == G_IO_ERROR && error->code == G_IO_ERROR_CANCELLED)
1073 /* We just ignore if GetAll() is failing. Because this might happen
1074 * if the object has no properties at all. Or if the caller is
1075 * not authorized to see the properties.
1077 * Either way, apps can know about this by using
1078 * get_cached_property_names() or get_cached_property().
1080 * TODO: handle G_DBUS_DEBUG flag 'proxy' and, if enabled, log the
1081 * fact that GetAll() failed
1083 //g_debug ("error: %d %d %s", error->domain, error->code, error->message);
1084 g_error_free (error);
1087 /* and finally we can notify */
1090 g_free (data->proxy->priv->name_owner);
1091 data->proxy->priv->name_owner = data->name_owner;
1092 data->name_owner = NULL; /* to avoid an extra copy, we steal the string */
1094 G_LOCK (properties_lock);
1095 g_hash_table_remove_all (data->proxy->priv->properties);
1096 G_UNLOCK (properties_lock);
1099 process_get_all_reply (data->proxy, result);
1100 g_variant_unref (result);
1103 g_object_notify (G_OBJECT (data->proxy), "g-name-owner");
1106 if (data->cancellable == data->proxy->priv->get_all_cancellable)
1107 data->proxy->priv->get_all_cancellable = NULL;
1109 g_object_unref (data->proxy);
1110 g_object_unref (data->cancellable);
1111 g_free (data->name_owner);
1116 on_name_owner_changed (GDBusConnection *connection,
1117 const gchar *sender_name,
1118 const gchar *object_path,
1119 const gchar *interface_name,
1120 const gchar *signal_name,
1121 GVariant *parameters,
1124 SignalSubscriptionData *data = user_data;
1126 const gchar *old_owner;
1127 const gchar *new_owner;
1129 G_LOCK (signal_subscription_lock);
1130 proxy = data->proxy;
1133 G_UNLOCK (signal_subscription_lock);
1138 g_object_ref (proxy);
1139 G_UNLOCK (signal_subscription_lock);
1142 /* if we are already trying to load properties, cancel that */
1143 if (proxy->priv->get_all_cancellable != NULL)
1145 g_cancellable_cancel (proxy->priv->get_all_cancellable);
1146 proxy->priv->get_all_cancellable = NULL;
1149 g_variant_get (parameters,
1155 if (strlen (new_owner) == 0)
1157 g_free (proxy->priv->name_owner);
1158 proxy->priv->name_owner = NULL;
1160 G_LOCK (properties_lock);
1162 /* Synthesize ::g-properties-changed changed */
1163 if (!(proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES) &&
1164 g_hash_table_size (proxy->priv->properties) > 0)
1166 GVariantBuilder builder;
1167 GPtrArray *invalidated_properties;
1168 GHashTableIter iter;
1171 /* Build changed_properties (always empty) and invalidated_properties ... */
1172 g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
1174 invalidated_properties = g_ptr_array_new_with_free_func (g_free);
1175 g_hash_table_iter_init (&iter, proxy->priv->properties);
1176 while (g_hash_table_iter_next (&iter, (gpointer) &key, NULL))
1177 g_ptr_array_add (invalidated_properties, g_strdup (key));
1178 g_ptr_array_add (invalidated_properties, NULL);
1180 /* ... throw out the properties ... */
1181 g_hash_table_remove_all (proxy->priv->properties);
1183 G_UNLOCK (properties_lock);
1185 /* ... and finally emit the ::g-properties-changed signal */
1186 g_signal_emit (proxy, signals[PROPERTIES_CHANGED_SIGNAL],
1188 g_variant_builder_end (&builder) /* consumed */,
1189 (const gchar* const *) invalidated_properties->pdata);
1190 g_ptr_array_unref (invalidated_properties);
1194 G_UNLOCK (properties_lock);
1196 g_object_notify (G_OBJECT (proxy), "g-name-owner");
1200 /* ignore duplicates - this can happen when activating the service */
1201 if (g_strcmp0 (new_owner, proxy->priv->name_owner) == 0)
1204 if (proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES)
1206 g_free (proxy->priv->name_owner);
1207 proxy->priv->name_owner = g_strdup (new_owner);
1208 G_LOCK (properties_lock);
1209 g_hash_table_remove_all (proxy->priv->properties);
1210 G_UNLOCK (properties_lock);
1211 g_object_notify (G_OBJECT (proxy), "g-name-owner");
1215 LoadPropertiesOnNameOwnerChangedData *data;
1217 /* start loading properties.. only then emit notify::g-name-owner .. we
1218 * need to be able to cancel this in the event another NameOwnerChanged
1219 * signal suddenly happens
1222 g_assert (proxy->priv->get_all_cancellable == NULL);
1223 proxy->priv->get_all_cancellable = g_cancellable_new ();
1224 data = g_new0 (LoadPropertiesOnNameOwnerChangedData, 1);
1225 data->proxy = g_object_ref (proxy);
1226 data->cancellable = proxy->priv->get_all_cancellable;
1227 data->name_owner = g_strdup (new_owner);
1228 g_dbus_connection_call (proxy->priv->connection,
1230 proxy->priv->object_path,
1231 "org.freedesktop.DBus.Properties",
1233 g_variant_new ("(s)", proxy->priv->interface_name),
1234 G_VARIANT_TYPE ("(a{sv})"),
1235 G_DBUS_CALL_FLAGS_NONE,
1237 proxy->priv->get_all_cancellable,
1238 (GAsyncReadyCallback) on_name_owner_changed_get_all_cb,
1245 g_object_unref (proxy);
1248 /* ---------------------------------------------------------------------------------------------------- */
1253 GCancellable *cancellable;
1254 GSimpleAsyncResult *simple;
1258 async_init_data_free (AsyncInitData *data)
1260 g_object_unref (data->proxy);
1261 if (data->cancellable != NULL)
1262 g_object_unref (data->cancellable);
1263 g_object_unref (data->simple);
1268 async_init_get_all_cb (GDBusConnection *connection,
1272 AsyncInitData *data = user_data;
1277 result = g_dbus_connection_call_finish (connection,
1282 /* We just ignore if GetAll() is failing. Because this might happen
1283 * if the object has no properties at all. Or if the caller is
1284 * not authorized to see the properties.
1286 * Either way, apps can know about this by using
1287 * get_cached_property_names() or get_cached_property().
1289 * TODO: handle G_DBUS_DEBUG flag 'proxy' and, if enabled, log the
1290 * fact that GetAll() failed
1292 //g_debug ("error: %d %d %s", error->domain, error->code, error->message);
1293 g_error_free (error);
1297 g_simple_async_result_set_op_res_gpointer (data->simple,
1299 (GDestroyNotify) g_variant_unref);
1302 g_simple_async_result_complete_in_idle (data->simple);
1303 async_init_data_free (data);
1308 async_init_get_name_owner_cb (GDBusConnection *connection,
1312 AsyncInitData *data = user_data;
1320 result = g_dbus_connection_call_finish (connection,
1325 if (error->domain == G_DBUS_ERROR &&
1326 error->code == G_DBUS_ERROR_NAME_HAS_NO_OWNER)
1328 g_error_free (error);
1332 g_simple_async_result_take_error (data->simple, error);
1333 g_simple_async_result_complete_in_idle (data->simple);
1334 async_init_data_free (data);
1340 g_variant_get (result,
1342 &data->proxy->priv->name_owner);
1343 g_variant_unref (result);
1347 if (!(data->proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES))
1349 /* load all properties asynchronously */
1350 g_dbus_connection_call (data->proxy->priv->connection,
1351 data->proxy->priv->name_owner,
1352 data->proxy->priv->object_path,
1353 "org.freedesktop.DBus.Properties",
1355 g_variant_new ("(s)", data->proxy->priv->interface_name),
1356 G_VARIANT_TYPE ("(a{sv})"),
1357 G_DBUS_CALL_FLAGS_NONE,
1360 (GAsyncReadyCallback) async_init_get_all_cb,
1365 g_simple_async_result_complete_in_idle (data->simple);
1366 async_init_data_free (data);
1374 async_init_call_get_name_owner (AsyncInitData *data)
1376 g_dbus_connection_call (data->proxy->priv->connection,
1377 "org.freedesktop.DBus", /* name */
1378 "/org/freedesktop/DBus", /* object path */
1379 "org.freedesktop.DBus", /* interface */
1381 g_variant_new ("(s)",
1382 data->proxy->priv->name),
1383 G_VARIANT_TYPE ("(s)"),
1384 G_DBUS_CALL_FLAGS_NONE,
1387 (GAsyncReadyCallback) async_init_get_name_owner_cb,
1392 async_init_start_service_by_name_cb (GDBusConnection *connection,
1396 AsyncInitData *data = user_data;
1401 result = g_dbus_connection_call_finish (connection,
1406 /* Errors are not unexpected; the bus will reply e.g.
1408 * org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.Epiphany2
1409 * was not provided by any .service files
1411 * This doesn't mean that the name doesn't have an owner, just
1412 * that it's not provided by a .service file. So just proceed to
1413 * invoke GetNameOwner() if dealing with that error.
1415 if (error->domain == G_DBUS_ERROR &&
1416 error->code == G_DBUS_ERROR_SERVICE_UNKNOWN)
1418 g_error_free (error);
1422 g_prefix_error (&error,
1423 _("Error calling StartServiceByName for %s: "),
1424 data->proxy->priv->name);
1430 guint32 start_service_result;
1431 g_variant_get (result,
1433 &start_service_result);
1434 g_variant_unref (result);
1435 if (start_service_result == 1 || /* DBUS_START_REPLY_SUCCESS */
1436 start_service_result == 2) /* DBUS_START_REPLY_ALREADY_RUNNING */
1438 /* continue to invoke GetNameOwner() */
1442 error = g_error_new (G_IO_ERROR,
1444 _("Unexpected reply %d from StartServiceByName(\"%s\") method"),
1445 start_service_result,
1446 data->proxy->priv->name);
1451 async_init_call_get_name_owner (data);
1455 g_warn_if_fail (error != NULL);
1456 g_simple_async_result_take_error (data->simple, error);
1457 g_simple_async_result_complete_in_idle (data->simple);
1458 async_init_data_free (data);
1462 async_init_call_start_service_by_name (AsyncInitData *data)
1464 g_dbus_connection_call (data->proxy->priv->connection,
1465 "org.freedesktop.DBus", /* name */
1466 "/org/freedesktop/DBus", /* object path */
1467 "org.freedesktop.DBus", /* interface */
1468 "StartServiceByName",
1469 g_variant_new ("(su)",
1470 data->proxy->priv->name,
1472 G_VARIANT_TYPE ("(u)"),
1473 G_DBUS_CALL_FLAGS_NONE,
1476 (GAsyncReadyCallback) async_init_start_service_by_name_cb,
1481 async_initable_init_second_async (GAsyncInitable *initable,
1483 GCancellable *cancellable,
1484 GAsyncReadyCallback callback,
1487 GDBusProxy *proxy = G_DBUS_PROXY (initable);
1488 AsyncInitData *data;
1490 data = g_new0 (AsyncInitData, 1);
1491 data->proxy = g_object_ref (proxy);
1492 data->cancellable = cancellable != NULL ? g_object_ref (cancellable) : NULL;
1493 data->simple = g_simple_async_result_new (G_OBJECT (proxy),
1498 /* Check name ownership asynchronously - possibly also start the service */
1499 if (proxy->priv->name == NULL)
1502 async_init_get_name_owner_cb (proxy->priv->connection, NULL, data);
1504 else if (g_dbus_is_unique_name (proxy->priv->name))
1506 proxy->priv->name_owner = g_strdup (proxy->priv->name);
1507 async_init_get_name_owner_cb (proxy->priv->connection, NULL, data);
1511 if (proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START)
1513 async_init_call_get_name_owner (data);
1517 async_init_call_start_service_by_name (data);
1523 async_initable_init_second_finish (GAsyncInitable *initable,
1527 GDBusProxy *proxy = G_DBUS_PROXY (initable);
1528 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
1534 if (g_simple_async_result_propagate_error (simple, error))
1537 result = g_simple_async_result_get_op_res_gpointer (simple);
1540 process_get_all_reply (proxy, result);
1546 proxy->priv->initialized = TRUE;
1550 /* ---------------------------------------------------------------------------------------------------- */
1553 async_initable_init_first (GAsyncInitable *initable)
1555 GDBusProxy *proxy = G_DBUS_PROXY (initable);
1557 if (!(proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES))
1559 /* subscribe to PropertiesChanged() */
1560 proxy->priv->properties_changed_subscription_id =
1561 g_dbus_connection_signal_subscribe (proxy->priv->connection,
1563 "org.freedesktop.DBus.Properties",
1564 "PropertiesChanged",
1565 proxy->priv->object_path,
1566 proxy->priv->interface_name,
1567 G_DBUS_SIGNAL_FLAGS_NONE,
1568 on_properties_changed,
1569 signal_subscription_ref (proxy->priv->signal_subscription_data),
1570 (GDestroyNotify) signal_subscription_unref);
1573 if (!(proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS))
1575 /* subscribe to all signals for the object */
1576 proxy->priv->signals_subscription_id =
1577 g_dbus_connection_signal_subscribe (proxy->priv->connection,
1579 proxy->priv->interface_name,
1581 proxy->priv->object_path,
1583 G_DBUS_SIGNAL_FLAGS_NONE,
1585 signal_subscription_ref (proxy->priv->signal_subscription_data),
1586 (GDestroyNotify) signal_subscription_unref);
1589 if (proxy->priv->name != NULL && !g_dbus_is_unique_name (proxy->priv->name))
1591 proxy->priv->name_owner_changed_subscription_id =
1592 g_dbus_connection_signal_subscribe (proxy->priv->connection,
1593 "org.freedesktop.DBus", /* name */
1594 "org.freedesktop.DBus", /* interface */
1595 "NameOwnerChanged", /* signal name */
1596 "/org/freedesktop/DBus", /* path */
1597 proxy->priv->name, /* arg0 */
1598 G_DBUS_SIGNAL_FLAGS_NONE,
1599 on_name_owner_changed,
1600 signal_subscription_ref (proxy->priv->signal_subscription_data),
1601 (GDestroyNotify) signal_subscription_unref);
1605 /* ---------------------------------------------------------------------------------------------------- */
1607 /* initialization is split into two parts - the first is the
1608 * non-blocing part that requires the callers GMainContext - the
1609 * second is a blocking part async part that doesn't require the
1610 * callers GMainContext.. we do this split so the code can be reused
1611 * in the GInitable implementation below.
1613 * Note that obtaining a GDBusConnection is not shared between the two
1621 GCancellable *cancellable;
1622 GAsyncReadyCallback callback;
1624 } GetConnectionData;
1627 get_connection_cb (GObject *source_object,
1631 GetConnectionData *data = user_data;
1635 data->proxy->priv->connection = g_bus_get_finish (res, &error);
1636 if (data->proxy->priv->connection == NULL)
1638 GSimpleAsyncResult *simple;
1639 simple = g_simple_async_result_new (G_OBJECT (data->proxy),
1643 g_simple_async_result_take_error (simple, error);
1644 g_simple_async_result_complete_in_idle (simple);
1645 g_object_unref (simple);
1649 async_initable_init_first (G_ASYNC_INITABLE (data->proxy));
1650 async_initable_init_second_async (G_ASYNC_INITABLE (data->proxy),
1657 if (data->cancellable != NULL)
1658 g_object_unref (data->cancellable);
1659 if (data->proxy != NULL)
1660 g_object_unref (data->proxy);
1665 async_initable_init_async (GAsyncInitable *initable,
1667 GCancellable *cancellable,
1668 GAsyncReadyCallback callback,
1671 GDBusProxy *proxy = G_DBUS_PROXY (initable);
1673 if (proxy->priv->bus_type != G_BUS_TYPE_NONE)
1675 GetConnectionData *data;
1677 g_assert (proxy->priv->connection == NULL);
1679 data = g_new0 (GetConnectionData, 1);
1680 data->proxy = g_object_ref (proxy);
1681 data->io_priority = io_priority;
1682 data->cancellable = cancellable != NULL ? g_object_ref (cancellable) : NULL;
1683 data->callback = callback;
1684 data->user_data = user_data;
1685 g_bus_get (proxy->priv->bus_type,
1692 async_initable_init_first (initable);
1693 async_initable_init_second_async (initable, io_priority, cancellable, callback, user_data);
1698 async_initable_init_finish (GAsyncInitable *initable,
1702 return async_initable_init_second_finish (initable, res, error);
1706 async_initable_iface_init (GAsyncInitableIface *async_initable_iface)
1708 async_initable_iface->init_async = async_initable_init_async;
1709 async_initable_iface->init_finish = async_initable_init_finish;
1712 /* ---------------------------------------------------------------------------------------------------- */
1716 GMainContext *context;
1719 } InitableAsyncInitableData;
1722 async_initable_init_async_cb (GObject *source_object,
1726 InitableAsyncInitableData *data = user_data;
1727 data->res = g_object_ref (res);
1728 g_main_loop_quit (data->loop);
1731 /* Simply reuse the GAsyncInitable implementation but run the first
1732 * part (that is non-blocking and requires the callers GMainContext)
1733 * with the callers GMainContext.. and the second with a private
1734 * GMainContext (bug 621310 is slightly related).
1736 * Note that obtaining a GDBusConnection is not shared between the two
1740 initable_init (GInitable *initable,
1741 GCancellable *cancellable,
1744 GDBusProxy *proxy = G_DBUS_PROXY (initable);
1745 InitableAsyncInitableData *data;
1750 if (proxy->priv->bus_type != G_BUS_TYPE_NONE)
1752 g_assert (proxy->priv->connection == NULL);
1753 proxy->priv->connection = g_bus_get_sync (proxy->priv->bus_type,
1756 if (proxy->priv->connection == NULL)
1760 async_initable_init_first (G_ASYNC_INITABLE (initable));
1762 data = g_new0 (InitableAsyncInitableData, 1);
1763 data->context = g_main_context_new ();
1764 data->loop = g_main_loop_new (data->context, FALSE);
1766 g_main_context_push_thread_default (data->context);
1768 async_initable_init_second_async (G_ASYNC_INITABLE (initable),
1771 async_initable_init_async_cb,
1774 g_main_loop_run (data->loop);
1776 ret = async_initable_init_second_finish (G_ASYNC_INITABLE (initable),
1780 g_main_context_pop_thread_default (data->context);
1782 g_main_context_unref (data->context);
1783 g_main_loop_unref (data->loop);
1784 g_object_unref (data->res);
1793 initable_iface_init (GInitableIface *initable_iface)
1795 initable_iface->init = initable_init;
1798 /* ---------------------------------------------------------------------------------------------------- */
1802 * @connection: A #GDBusConnection.
1803 * @flags: Flags used when constructing the proxy.
1804 * @info: (allow-none): A #GDBusInterfaceInfo specifying the minimal interface that @proxy conforms to or %NULL.
1805 * @name: (allow-none): A bus name (well-known or unique) or %NULL if @connection is not a message bus connection.
1806 * @object_path: An object path.
1807 * @interface_name: A D-Bus interface name.
1808 * @cancellable: A #GCancellable or %NULL.
1809 * @callback: Callback function to invoke when the proxy is ready.
1810 * @user_data: User data to pass to @callback.
1812 * Creates a proxy for accessing @interface_name on the remote object
1813 * at @object_path owned by @name at @connection and asynchronously
1814 * loads D-Bus properties unless the
1815 * %G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES flag is used. Connect to
1816 * the #GDBusProxy::g-properties-changed signal to get notified about
1819 * If the %G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS flag is not set, also sets up
1820 * match rules for signals. Connect to the #GDBusProxy::g-signal signal
1821 * to handle signals from the remote object.
1823 * If @name is a well-known name and the
1824 * %G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START flag isn't set and no name
1825 * owner currently exists, the message bus will be requested to launch
1826 * a name owner for the name.
1828 * This is a failable asynchronous constructor - when the proxy is
1829 * ready, @callback will be invoked and you can use
1830 * g_dbus_proxy_new_finish() to get the result.
1832 * See g_dbus_proxy_new_sync() and for a synchronous version of this constructor.
1834 * See <xref linkend="gdbus-wellknown-proxy"/> for an example of how #GDBusProxy can be used.
1839 g_dbus_proxy_new (GDBusConnection *connection,
1840 GDBusProxyFlags flags,
1841 GDBusInterfaceInfo *info,
1843 const gchar *object_path,
1844 const gchar *interface_name,
1845 GCancellable *cancellable,
1846 GAsyncReadyCallback callback,
1849 g_return_if_fail (G_IS_DBUS_CONNECTION (connection));
1850 g_return_if_fail ((name == NULL && g_dbus_connection_get_unique_name (connection) == NULL) || g_dbus_is_name (name));
1851 g_return_if_fail (g_variant_is_object_path (object_path));
1852 g_return_if_fail (g_dbus_is_interface_name (interface_name));
1854 g_async_initable_new_async (G_TYPE_DBUS_PROXY,
1860 "g-interface-info", info,
1862 "g-connection", connection,
1863 "g-object-path", object_path,
1864 "g-interface-name", interface_name,
1869 * g_dbus_proxy_new_finish:
1870 * @res: A #GAsyncResult obtained from the #GAsyncReadyCallback function passed to g_dbus_proxy_new().
1871 * @error: Return location for error or %NULL.
1873 * Finishes creating a #GDBusProxy.
1875 * Returns: A #GDBusProxy or %NULL if @error is set. Free with g_object_unref().
1880 g_dbus_proxy_new_finish (GAsyncResult *res,
1884 GObject *source_object;
1886 source_object = g_async_result_get_source_object (res);
1887 g_assert (source_object != NULL);
1889 object = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object),
1892 g_object_unref (source_object);
1895 return G_DBUS_PROXY (object);
1901 * g_dbus_proxy_new_sync:
1902 * @connection: A #GDBusConnection.
1903 * @flags: Flags used when constructing the proxy.
1904 * @info: (allow-none): A #GDBusInterfaceInfo specifying the minimal interface that @proxy conforms to or %NULL.
1905 * @name: (allow-none): A bus name (well-known or unique) or %NULL if @connection is not a message bus connection.
1906 * @object_path: An object path.
1907 * @interface_name: A D-Bus interface name.
1908 * @cancellable: (allow-none): A #GCancellable or %NULL.
1909 * @error: (allow-none): Return location for error or %NULL.
1911 * Creates a proxy for accessing @interface_name on the remote object
1912 * at @object_path owned by @name at @connection and synchronously
1913 * loads D-Bus properties unless the
1914 * %G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES flag is used.
1916 * If the %G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS flag is not set, also sets up
1917 * match rules for signals. Connect to the #GDBusProxy::g-signal signal
1918 * to handle signals from the remote object.
1920 * If @name is a well-known name and the
1921 * %G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START flag isn't set and no name
1922 * owner currently exists, the message bus will be requested to launch
1923 * a name owner for the name.
1925 * This is a synchronous failable constructor. See g_dbus_proxy_new()
1926 * and g_dbus_proxy_new_finish() for the asynchronous version.
1928 * See <xref linkend="gdbus-wellknown-proxy"/> for an example of how #GDBusProxy can be used.
1930 * Returns: A #GDBusProxy or %NULL if error is set. Free with g_object_unref().
1935 g_dbus_proxy_new_sync (GDBusConnection *connection,
1936 GDBusProxyFlags flags,
1937 GDBusInterfaceInfo *info,
1939 const gchar *object_path,
1940 const gchar *interface_name,
1941 GCancellable *cancellable,
1944 GInitable *initable;
1946 g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);
1947 g_return_val_if_fail ((name == NULL && g_dbus_connection_get_unique_name (connection) == NULL) ||
1948 g_dbus_is_name (name), NULL);
1949 g_return_val_if_fail (g_variant_is_object_path (object_path), NULL);
1950 g_return_val_if_fail (g_dbus_is_interface_name (interface_name), NULL);
1952 initable = g_initable_new (G_TYPE_DBUS_PROXY,
1956 "g-interface-info", info,
1958 "g-connection", connection,
1959 "g-object-path", object_path,
1960 "g-interface-name", interface_name,
1962 if (initable != NULL)
1963 return G_DBUS_PROXY (initable);
1968 /* ---------------------------------------------------------------------------------------------------- */
1971 * g_dbus_proxy_new_for_bus:
1972 * @bus_type: A #GBusType.
1973 * @flags: Flags used when constructing the proxy.
1974 * @info: (allow-none): A #GDBusInterfaceInfo specifying the minimal interface that @proxy conforms to or %NULL.
1975 * @name: A bus name (well-known or unique).
1976 * @object_path: An object path.
1977 * @interface_name: A D-Bus interface name.
1978 * @cancellable: A #GCancellable or %NULL.
1979 * @callback: Callback function to invoke when the proxy is ready.
1980 * @user_data: User data to pass to @callback.
1982 * Like g_dbus_proxy_new() but takes a #GBusType instead of a #GDBusConnection.
1984 * See <xref linkend="gdbus-wellknown-proxy"/> for an example of how #GDBusProxy can be used.
1989 g_dbus_proxy_new_for_bus (GBusType bus_type,
1990 GDBusProxyFlags flags,
1991 GDBusInterfaceInfo *info,
1993 const gchar *object_path,
1994 const gchar *interface_name,
1995 GCancellable *cancellable,
1996 GAsyncReadyCallback callback,
1999 g_return_if_fail (g_dbus_is_name (name));
2000 g_return_if_fail (g_variant_is_object_path (object_path));
2001 g_return_if_fail (g_dbus_is_interface_name (interface_name));
2003 g_async_initable_new_async (G_TYPE_DBUS_PROXY,
2009 "g-interface-info", info,
2011 "g-bus-type", bus_type,
2012 "g-object-path", object_path,
2013 "g-interface-name", interface_name,
2018 * g_dbus_proxy_new_for_bus_finish:
2019 * @res: A #GAsyncResult obtained from the #GAsyncReadyCallback function passed to g_dbus_proxy_new_for_bus().
2020 * @error: Return location for error or %NULL.
2022 * Finishes creating a #GDBusProxy.
2024 * Returns: A #GDBusProxy or %NULL if @error is set. Free with g_object_unref().
2029 g_dbus_proxy_new_for_bus_finish (GAsyncResult *res,
2032 return g_dbus_proxy_new_finish (res, error);
2036 * g_dbus_proxy_new_for_bus_sync:
2037 * @bus_type: A #GBusType.
2038 * @flags: Flags used when constructing the proxy.
2039 * @info: (allow-none): A #GDBusInterfaceInfo specifying the minimal interface
2040 * that @proxy conforms to or %NULL.
2041 * @name: A bus name (well-known or unique).
2042 * @object_path: An object path.
2043 * @interface_name: A D-Bus interface name.
2044 * @cancellable: A #GCancellable or %NULL.
2045 * @error: Return location for error or %NULL.
2047 * Like g_dbus_proxy_new_sync() but takes a #GBusType instead of a #GDBusConnection.
2049 * See <xref linkend="gdbus-wellknown-proxy"/> for an example of how #GDBusProxy can be used.
2051 * Returns: A #GDBusProxy or %NULL if error is set. Free with g_object_unref().
2056 g_dbus_proxy_new_for_bus_sync (GBusType bus_type,
2057 GDBusProxyFlags flags,
2058 GDBusInterfaceInfo *info,
2060 const gchar *object_path,
2061 const gchar *interface_name,
2062 GCancellable *cancellable,
2065 GInitable *initable;
2067 g_return_val_if_fail (g_dbus_is_name (name), NULL);
2068 g_return_val_if_fail (g_variant_is_object_path (object_path), NULL);
2069 g_return_val_if_fail (g_dbus_is_interface_name (interface_name), NULL);
2071 initable = g_initable_new (G_TYPE_DBUS_PROXY,
2075 "g-interface-info", info,
2077 "g-bus-type", bus_type,
2078 "g-object-path", object_path,
2079 "g-interface-name", interface_name,
2081 if (initable != NULL)
2082 return G_DBUS_PROXY (initable);
2087 /* ---------------------------------------------------------------------------------------------------- */
2090 * g_dbus_proxy_get_connection:
2091 * @proxy: A #GDBusProxy.
2093 * Gets the connection @proxy is for.
2095 * Returns: (transfer none): A #GDBusConnection owned by @proxy. Do not free.
2100 g_dbus_proxy_get_connection (GDBusProxy *proxy)
2102 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
2103 return proxy->priv->connection;
2107 * g_dbus_proxy_get_flags:
2108 * @proxy: A #GDBusProxy.
2110 * Gets the flags that @proxy was constructed with.
2112 * Returns: Flags from the #GDBusProxyFlags enumeration.
2117 g_dbus_proxy_get_flags (GDBusProxy *proxy)
2119 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), 0);
2120 return proxy->priv->flags;
2124 * g_dbus_proxy_get_name:
2125 * @proxy: A #GDBusProxy.
2127 * Gets the name that @proxy was constructed for.
2129 * Returns: A string owned by @proxy. Do not free.
2134 g_dbus_proxy_get_name (GDBusProxy *proxy)
2136 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
2137 return proxy->priv->name;
2141 * g_dbus_proxy_get_name_owner:
2142 * @proxy: A #GDBusProxy.
2144 * The unique name that owns the name that @proxy is for or %NULL if
2145 * no-one currently owns that name. You may connect to the
2146 * #GObject::notify signal to track changes to the
2147 * #GDBusProxy:g-name-owner property.
2149 * Returns: The name owner or %NULL if no name owner exists. Free with g_free().
2154 g_dbus_proxy_get_name_owner (GDBusProxy *proxy)
2156 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
2157 return g_strdup (proxy->priv->name_owner);
2161 * g_dbus_proxy_get_object_path:
2162 * @proxy: A #GDBusProxy.
2164 * Gets the object path @proxy is for.
2166 * Returns: A string owned by @proxy. Do not free.
2171 g_dbus_proxy_get_object_path (GDBusProxy *proxy)
2173 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
2174 return proxy->priv->object_path;
2178 * g_dbus_proxy_get_interface_name:
2179 * @proxy: A #GDBusProxy.
2181 * Gets the D-Bus interface name @proxy is for.
2183 * Returns: A string owned by @proxy. Do not free.
2188 g_dbus_proxy_get_interface_name (GDBusProxy *proxy)
2190 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
2191 return proxy->priv->interface_name;
2195 * g_dbus_proxy_get_default_timeout:
2196 * @proxy: A #GDBusProxy.
2198 * Gets the timeout to use if -1 (specifying default timeout) is
2199 * passed as @timeout_msec in the g_dbus_proxy_call() and
2200 * g_dbus_proxy_call_sync() functions.
2202 * See the #GDBusProxy:g-default-timeout property for more details.
2204 * Returns: Timeout to use for @proxy.
2209 g_dbus_proxy_get_default_timeout (GDBusProxy *proxy)
2211 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), -1);
2212 return proxy->priv->timeout_msec;
2216 * g_dbus_proxy_set_default_timeout:
2217 * @proxy: A #GDBusProxy.
2218 * @timeout_msec: Timeout in milliseconds.
2220 * Sets the timeout to use if -1 (specifying default timeout) is
2221 * passed as @timeout_msec in the g_dbus_proxy_call() and
2222 * g_dbus_proxy_call_sync() functions.
2224 * See the #GDBusProxy:g-default-timeout property for more details.
2229 g_dbus_proxy_set_default_timeout (GDBusProxy *proxy,
2232 g_return_if_fail (G_IS_DBUS_PROXY (proxy));
2233 g_return_if_fail (timeout_msec == -1 || timeout_msec >= 0);
2235 /* TODO: locking? */
2236 if (proxy->priv->timeout_msec != timeout_msec)
2238 proxy->priv->timeout_msec = timeout_msec;
2239 g_object_notify (G_OBJECT (proxy), "g-default-timeout");
2244 * g_dbus_proxy_get_interface_info:
2245 * @proxy: A #GDBusProxy
2247 * Returns the #GDBusInterfaceInfo, if any, specifying the minimal
2248 * interface that @proxy conforms to.
2250 * See the #GDBusProxy:g-interface-info property for more details.
2252 * Returns: A #GDBusInterfaceInfo or %NULL. Do not unref the returned
2253 * object, it is owned by @proxy.
2257 GDBusInterfaceInfo *
2258 g_dbus_proxy_get_interface_info (GDBusProxy *proxy)
2260 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
2261 return proxy->priv->expected_interface;
2265 * g_dbus_proxy_set_interface_info:
2266 * @proxy: A #GDBusProxy
2267 * @info: (allow-none): Minimum interface this proxy conforms to or %NULL to unset.
2269 * Ensure that interactions with @proxy conform to the given
2270 * interface. For example, when completing a method call, if the type
2271 * signature of the message isn't what's expected, the given #GError
2272 * is set. Signals that have a type signature mismatch are simply
2275 * See the #GDBusProxy:g-interface-info property for more details.
2280 g_dbus_proxy_set_interface_info (GDBusProxy *proxy,
2281 GDBusInterfaceInfo *info)
2283 g_return_if_fail (G_IS_DBUS_PROXY (proxy));
2284 if (proxy->priv->expected_interface != NULL)
2286 g_dbus_interface_info_cache_release (proxy->priv->expected_interface);
2287 g_dbus_interface_info_unref (proxy->priv->expected_interface);
2289 proxy->priv->expected_interface = info != NULL ? g_dbus_interface_info_ref (info) : NULL;
2290 if (proxy->priv->expected_interface != NULL)
2291 g_dbus_interface_info_cache_build (proxy->priv->expected_interface);
2294 /* ---------------------------------------------------------------------------------------------------- */
2297 maybe_split_method_name (const gchar *method_name,
2298 gchar **out_interface_name,
2299 const gchar **out_method_name)
2304 g_assert (out_interface_name != NULL);
2305 g_assert (out_method_name != NULL);
2306 *out_interface_name = NULL;
2307 *out_method_name = NULL;
2309 if (strchr (method_name, '.') != NULL)
2314 p = g_strdup (method_name);
2315 last_dot = strrchr (p, '.');
2318 *out_interface_name = p;
2319 *out_method_name = last_dot + 1;
2329 reply_cb (GDBusConnection *connection,
2333 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data);
2338 value = g_dbus_connection_call_finish (connection,
2343 g_simple_async_result_take_error (simple, error);
2347 g_simple_async_result_set_op_res_gpointer (simple,
2349 (GDestroyNotify) g_variant_unref);
2352 /* no need to complete in idle since the method GDBusConnection already does */
2353 g_simple_async_result_complete (simple);
2354 g_object_unref (simple);
2357 static const GDBusMethodInfo *
2358 lookup_method_info_or_warn (GDBusProxy *proxy,
2359 const gchar *method_name)
2361 const GDBusMethodInfo *info;
2363 if (proxy->priv->expected_interface == NULL)
2366 info = g_dbus_interface_info_lookup_method (proxy->priv->expected_interface, method_name);
2369 g_warning ("Trying to invoke method %s which isn't in expected interface %s",
2370 method_name, proxy->priv->expected_interface->name);
2376 static const gchar *
2377 get_destination_for_call (GDBusProxy *proxy)
2383 /* If proxy->priv->name is a unique name, then proxy->priv->name_owner
2384 * is never NULL and always the same as proxy->priv->name. We use this
2385 * knowledge to avoid checking if proxy->priv->name is a unique or
2388 ret = proxy->priv->name_owner;
2392 if (proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START)
2395 ret = proxy->priv->name;
2402 * g_dbus_proxy_call:
2403 * @proxy: A #GDBusProxy.
2404 * @method_name: Name of method to invoke.
2405 * @parameters: (allow-none): A #GVariant tuple with parameters for the signal or %NULL if not passing parameters.
2406 * @flags: Flags from the #GDBusCallFlags enumeration.
2407 * @timeout_msec: The timeout in milliseconds (with %G_MAXINT meaning
2408 * "infinite") or -1 to use the proxy default timeout.
2409 * @cancellable: A #GCancellable or %NULL.
2410 * @callback: A #GAsyncReadyCallback to call when the request is satisfied or %NULL if you don't
2411 * care about the result of the method invocation.
2412 * @user_data: The data to pass to @callback.
2414 * Asynchronously invokes the @method_name method on @proxy.
2416 * If @method_name contains any dots, then @name is split into interface and
2417 * method name parts. This allows using @proxy for invoking methods on
2420 * If the #GDBusConnection associated with @proxy is closed then
2421 * the operation will fail with %G_IO_ERROR_CLOSED. If
2422 * @cancellable is canceled, the operation will fail with
2423 * %G_IO_ERROR_CANCELLED. If @parameters contains a value not
2424 * compatible with the D-Bus protocol, the operation fails with
2425 * %G_IO_ERROR_INVALID_ARGUMENT.
2427 * If the @parameters #GVariant is floating, it is consumed. This allows
2428 * convenient 'inline' use of g_variant_new(), e.g.:
2430 * g_dbus_proxy_call (proxy,
2432 * g_variant_new ("(ss)",
2435 * G_DBUS_CALL_FLAGS_NONE,
2438 * (GAsyncReadyCallback) two_strings_done,
2442 * This is an asynchronous method. When the operation is finished,
2443 * @callback will be invoked in the
2444 * <link linkend="g-main-context-push-thread-default">thread-default main loop</link>
2445 * of the thread you are calling this method from.
2446 * You can then call g_dbus_proxy_call_finish() to get the result of
2447 * the operation. See g_dbus_proxy_call_sync() for the synchronous
2448 * version of this method.
2453 g_dbus_proxy_call (GDBusProxy *proxy,
2454 const gchar *method_name,
2455 GVariant *parameters,
2456 GDBusCallFlags flags,
2458 GCancellable *cancellable,
2459 GAsyncReadyCallback callback,
2462 GSimpleAsyncResult *simple;
2464 gchar *split_interface_name;
2465 const gchar *split_method_name;
2466 const gchar *target_method_name;
2467 const gchar *target_interface_name;
2468 const gchar *destination;
2469 GVariantType *reply_type;
2471 g_return_if_fail (G_IS_DBUS_PROXY (proxy));
2472 g_return_if_fail (g_dbus_is_member_name (method_name) || g_dbus_is_interface_name (method_name));
2473 g_return_if_fail (parameters == NULL || g_variant_is_of_type (parameters, G_VARIANT_TYPE_TUPLE));
2474 g_return_if_fail (timeout_msec == -1 || timeout_msec >= 0);
2477 split_interface_name = NULL;
2479 simple = g_simple_async_result_new (G_OBJECT (proxy),
2484 was_split = maybe_split_method_name (method_name, &split_interface_name, &split_method_name);
2485 target_method_name = was_split ? split_method_name : method_name;
2486 target_interface_name = was_split ? split_interface_name : proxy->priv->interface_name;
2488 /* Warn if method is unexpected (cf. :g-interface-info) */
2491 const GDBusMethodInfo *expected_method_info;
2492 expected_method_info = lookup_method_info_or_warn (proxy, target_method_name);
2493 if (expected_method_info != NULL)
2494 reply_type = _g_dbus_compute_complete_signature (expected_method_info->out_args);
2498 if (proxy->priv->name != NULL)
2500 destination = get_destination_for_call (proxy);
2501 if (destination == NULL)
2503 g_simple_async_result_set_error (simple,
2506 _("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"));
2511 g_dbus_connection_call (proxy->priv->connection,
2513 proxy->priv->object_path,
2514 target_interface_name,
2519 timeout_msec == -1 ? proxy->priv->timeout_msec : timeout_msec,
2521 (GAsyncReadyCallback) reply_cb,
2525 if (reply_type != NULL)
2526 g_variant_type_free (reply_type);
2528 g_free (split_interface_name);
2532 * g_dbus_proxy_call_finish:
2533 * @proxy: A #GDBusProxy.
2534 * @res: A #GAsyncResult obtained from the #GAsyncReadyCallback passed to g_dbus_proxy_call().
2535 * @error: Return location for error or %NULL.
2537 * Finishes an operation started with g_dbus_proxy_call().
2539 * Returns: %NULL if @error is set. Otherwise a #GVariant tuple with
2540 * return values. Free with g_variant_unref().
2545 g_dbus_proxy_call_finish (GDBusProxy *proxy,
2549 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
2552 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
2553 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
2554 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
2556 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_dbus_proxy_call);
2560 if (g_simple_async_result_propagate_error (simple, error))
2563 value = g_variant_ref (g_simple_async_result_get_op_res_gpointer (simple));
2570 * g_dbus_proxy_call_sync:
2571 * @proxy: A #GDBusProxy.
2572 * @method_name: Name of method to invoke.
2573 * @parameters: (allow-none): A #GVariant tuple with parameters for the signal
2574 * or %NULL if not passing parameters.
2575 * @flags: Flags from the #GDBusCallFlags enumeration.
2576 * @timeout_msec: The timeout in milliseconds (with %G_MAXINT meaning
2577 * "infinite") or -1 to use the proxy default timeout.
2578 * @cancellable: A #GCancellable or %NULL.
2579 * @error: Return location for error or %NULL.
2581 * Synchronously invokes the @method_name method on @proxy.
2583 * If @method_name contains any dots, then @name is split into interface and
2584 * method name parts. This allows using @proxy for invoking methods on
2587 * If the #GDBusConnection associated with @proxy is disconnected then
2588 * the operation will fail with %G_IO_ERROR_CLOSED. If
2589 * @cancellable is canceled, the operation will fail with
2590 * %G_IO_ERROR_CANCELLED. If @parameters contains a value not
2591 * compatible with the D-Bus protocol, the operation fails with
2592 * %G_IO_ERROR_INVALID_ARGUMENT.
2594 * If the @parameters #GVariant is floating, it is consumed. This allows
2595 * convenient 'inline' use of g_variant_new(), e.g.:
2597 * g_dbus_proxy_call_sync (proxy,
2599 * g_variant_new ("(ss)",
2602 * G_DBUS_CALL_FLAGS_NONE,
2608 * The calling thread is blocked until a reply is received. See
2609 * g_dbus_proxy_call() for the asynchronous version of this
2612 * Returns: %NULL if @error is set. Otherwise a #GVariant tuple with
2613 * return values. Free with g_variant_unref().
2618 g_dbus_proxy_call_sync (GDBusProxy *proxy,
2619 const gchar *method_name,
2620 GVariant *parameters,
2621 GDBusCallFlags flags,
2623 GCancellable *cancellable,
2628 gchar *split_interface_name;
2629 const gchar *split_method_name;
2630 const gchar *target_method_name;
2631 const gchar *target_interface_name;
2632 const gchar *destination;
2633 GVariantType *reply_type;
2635 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
2636 g_return_val_if_fail (g_dbus_is_member_name (method_name) || g_dbus_is_interface_name (method_name), NULL);
2637 g_return_val_if_fail (parameters == NULL || g_variant_is_of_type (parameters, G_VARIANT_TYPE_TUPLE), NULL);
2638 g_return_val_if_fail (timeout_msec == -1 || timeout_msec >= 0, NULL);
2639 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
2643 was_split = maybe_split_method_name (method_name, &split_interface_name, &split_method_name);
2644 target_method_name = was_split ? split_method_name : method_name;
2645 target_interface_name = was_split ? split_interface_name : proxy->priv->interface_name;
2647 /* Warn if method is unexpected (cf. :g-interface-info) */
2650 const GDBusMethodInfo *expected_method_info;
2651 expected_method_info = lookup_method_info_or_warn (proxy, target_method_name);
2652 if (expected_method_info != NULL)
2653 reply_type = _g_dbus_compute_complete_signature (expected_method_info->out_args);
2657 if (proxy->priv->name != NULL)
2659 destination = get_destination_for_call (proxy);
2660 if (destination == NULL)
2662 g_set_error_literal (error,
2665 _("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"));
2671 ret = g_dbus_connection_call_sync (proxy->priv->connection,
2673 proxy->priv->object_path,
2674 target_interface_name,
2679 timeout_msec == -1 ? proxy->priv->timeout_msec : timeout_msec,
2684 if (reply_type != NULL)
2685 g_variant_type_free (reply_type);
2687 g_free (split_interface_name);
2692 /* ---------------------------------------------------------------------------------------------------- */
2694 static GDBusInterfaceInfo *
2695 _g_dbus_proxy_get_info (GDBusInterface *interface)
2697 GDBusProxy *proxy = G_DBUS_PROXY (interface);
2698 return g_dbus_proxy_get_interface_info (proxy);
2701 static GDBusObject *
2702 _g_dbus_proxy_get_object (GDBusInterface *interface)
2704 GDBusProxy *proxy = G_DBUS_PROXY (interface);
2705 return proxy->priv->object;
2709 _g_dbus_proxy_set_object (GDBusInterface *interface,
2710 GDBusObject *object)
2712 GDBusProxy *proxy = G_DBUS_PROXY (interface);
2713 if (proxy->priv->object != NULL)
2714 g_object_remove_weak_pointer (G_OBJECT (proxy->priv->object), (gpointer *) &proxy->priv->object);
2715 proxy->priv->object = object;
2716 if (proxy->priv->object != NULL)
2717 g_object_add_weak_pointer (G_OBJECT (proxy->priv->object), (gpointer *) &proxy->priv->object);
2721 dbus_interface_iface_init (GDBusInterfaceIface *dbus_interface_iface)
2723 dbus_interface_iface->get_info = _g_dbus_proxy_get_info;
2724 dbus_interface_iface->get_object = _g_dbus_proxy_get_object;
2725 dbus_interface_iface->set_object = _g_dbus_proxy_set_object;
2728 /* ---------------------------------------------------------------------------------------------------- */