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 "ginitable.h"
35 #include "gasyncinitable.h"
37 #include "gasyncresult.h"
38 #include "gsimpleasyncresult.h"
39 #include "gcancellable.h"
40 #include "gdbusinterface.h"
46 * @short_description: Client-side D-Bus interface proxy
49 * #GDBusProxy is a base class used for proxies to access a D-Bus
50 * interface on a remote object. A #GDBusProxy can be constructed for
51 * both well-known and unique names.
53 * By default, #GDBusProxy will cache all properties (and listen to
54 * changes) of the remote object, and proxy all signals that gets
55 * emitted. This behaviour can be changed by passing suitable
56 * #GDBusProxyFlags when the proxy is created. If the proxy is for a
57 * well-known name, the property cache is flushed when the name owner
58 * vanishes and reloaded when a name owner appears.
60 * If a #GDBusProxy is used for a well-known name, the owner of the
61 * name is tracked and can be read from
62 * #GDBusProxy:g-name-owner. Connect to the #GObject::notify signal to
63 * get notified of changes. Additionally, only signals and property
64 * changes emitted from the current name owner are considered and
65 * calls are always sent to the current name owner. This avoids a
66 * number of race conditions when the name is lost by one owner and
67 * claimed by another. However, if no name owner currently exists,
68 * then calls will be sent to the well-known name which may result in
69 * the message bus launching an owner (unless
70 * %G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START is set).
72 * The generic #GDBusProxy::g-properties-changed and
73 * #GDBusProxy::g-signal signals are not very convenient to work
74 * with. Therefore, the recommended way of working with proxies is to
75 * subclass #GDBusProxy, and have more natural properties and signals
76 * in your derived class. See <xref linkend="gdbus-example-gdbus-codegen"/>
77 * for how this can easily be done using the
78 * <command><link linkend="gdbus-codegen">gdbus-codegen</link></command>
81 * A #GDBusProxy instance can be used from multiple threads but note
82 * that all signals (e.g. #GDBusProxy::g-signal, #GDBusProxy::g-properties-changed
83 * and #GObject::notify) are emitted in the
84 * <link linkend="g-main-context-push-thread-default">thread-default main loop</link>
85 * of the thread where the instance was constructed.
87 * <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>
90 /* lock protecting the properties GHashTable */
91 G_LOCK_DEFINE_STATIC (properties_lock);
93 /* ---------------------------------------------------------------------------------------------------- */
95 G_LOCK_DEFINE_STATIC (signal_subscription_lock);
99 volatile gint ref_count;
101 } SignalSubscriptionData;
103 static SignalSubscriptionData *
104 signal_subscription_ref (SignalSubscriptionData *data)
106 g_atomic_int_inc (&data->ref_count);
111 signal_subscription_unref (SignalSubscriptionData *data)
113 if (g_atomic_int_dec_and_test (&data->ref_count))
115 g_slice_free (SignalSubscriptionData, data);
119 /* ---------------------------------------------------------------------------------------------------- */
121 struct _GDBusProxyPrivate
124 GDBusProxyFlags flags;
125 GDBusConnection *connection;
130 gchar *interface_name;
133 guint name_owner_changed_subscription_id;
135 GCancellable *get_all_cancellable;
137 /* gchar* -> GVariant* */
138 GHashTable *properties;
140 GDBusInterfaceInfo *expected_interface;
142 guint properties_changed_subscription_id;
143 guint signals_subscription_id;
145 gboolean initialized;
149 SignalSubscriptionData *signal_subscription_data;
161 PROP_G_INTERFACE_NAME,
162 PROP_G_DEFAULT_TIMEOUT,
163 PROP_G_INTERFACE_INFO
168 PROPERTIES_CHANGED_SIGNAL,
173 guint signals[LAST_SIGNAL] = {0};
175 static void dbus_interface_iface_init (GDBusInterfaceIface *dbus_interface_iface);
176 static void initable_iface_init (GInitableIface *initable_iface);
177 static void async_initable_iface_init (GAsyncInitableIface *async_initable_iface);
179 G_DEFINE_TYPE_WITH_CODE (GDBusProxy, g_dbus_proxy, G_TYPE_OBJECT,
180 G_IMPLEMENT_INTERFACE (G_TYPE_DBUS_INTERFACE, dbus_interface_iface_init)
181 G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, initable_iface_init)
182 G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, async_initable_iface_init)
186 g_dbus_proxy_dispose (GObject *object)
188 GDBusProxy *proxy = G_DBUS_PROXY (object);
189 G_LOCK (signal_subscription_lock);
190 if (proxy->priv->signal_subscription_data != NULL)
192 proxy->priv->signal_subscription_data->proxy = NULL;
193 signal_subscription_unref (proxy->priv->signal_subscription_data);
194 proxy->priv->signal_subscription_data = NULL;
196 G_UNLOCK (signal_subscription_lock);
198 G_OBJECT_CLASS (g_dbus_proxy_parent_class)->dispose (object);
202 g_dbus_proxy_finalize (GObject *object)
204 GDBusProxy *proxy = G_DBUS_PROXY (object);
206 g_warn_if_fail (proxy->priv->get_all_cancellable == NULL);
208 if (proxy->priv->name_owner_changed_subscription_id > 0)
209 g_dbus_connection_signal_unsubscribe (proxy->priv->connection,
210 proxy->priv->name_owner_changed_subscription_id);
212 if (proxy->priv->properties_changed_subscription_id > 0)
213 g_dbus_connection_signal_unsubscribe (proxy->priv->connection,
214 proxy->priv->properties_changed_subscription_id);
216 if (proxy->priv->signals_subscription_id > 0)
217 g_dbus_connection_signal_unsubscribe (proxy->priv->connection,
218 proxy->priv->signals_subscription_id);
220 if (proxy->priv->connection != NULL)
221 g_object_unref (proxy->priv->connection);
222 g_free (proxy->priv->name);
223 g_free (proxy->priv->name_owner);
224 g_free (proxy->priv->object_path);
225 g_free (proxy->priv->interface_name);
226 if (proxy->priv->properties != NULL)
227 g_hash_table_unref (proxy->priv->properties);
229 if (proxy->priv->expected_interface != NULL)
231 g_dbus_interface_info_cache_release (proxy->priv->expected_interface);
232 g_dbus_interface_info_unref (proxy->priv->expected_interface);
235 if (proxy->priv->object != NULL)
236 g_object_remove_weak_pointer (G_OBJECT (proxy->priv->object), (gpointer *) &proxy->priv->object);
238 G_OBJECT_CLASS (g_dbus_proxy_parent_class)->finalize (object);
242 g_dbus_proxy_get_property (GObject *object,
247 GDBusProxy *proxy = G_DBUS_PROXY (object);
251 case PROP_G_CONNECTION:
252 g_value_set_object (value, proxy->priv->connection);
256 g_value_set_flags (value, proxy->priv->flags);
260 g_value_set_string (value, proxy->priv->name);
263 case PROP_G_NAME_OWNER:
264 g_value_set_string (value, proxy->priv->name_owner);
267 case PROP_G_OBJECT_PATH:
268 g_value_set_string (value, proxy->priv->object_path);
271 case PROP_G_INTERFACE_NAME:
272 g_value_set_string (value, proxy->priv->interface_name);
275 case PROP_G_DEFAULT_TIMEOUT:
276 g_value_set_int (value, proxy->priv->timeout_msec);
279 case PROP_G_INTERFACE_INFO:
280 g_value_set_boxed (value, g_dbus_proxy_get_interface_info (proxy));
284 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
290 g_dbus_proxy_set_property (GObject *object,
295 GDBusProxy *proxy = G_DBUS_PROXY (object);
299 case PROP_G_CONNECTION:
300 proxy->priv->connection = g_value_dup_object (value);
304 proxy->priv->flags = g_value_get_flags (value);
308 proxy->priv->name = g_value_dup_string (value);
311 case PROP_G_OBJECT_PATH:
312 proxy->priv->object_path = g_value_dup_string (value);
315 case PROP_G_INTERFACE_NAME:
316 proxy->priv->interface_name = g_value_dup_string (value);
319 case PROP_G_DEFAULT_TIMEOUT:
320 g_dbus_proxy_set_default_timeout (proxy, g_value_get_int (value));
323 case PROP_G_INTERFACE_INFO:
324 g_dbus_proxy_set_interface_info (proxy, g_value_get_boxed (value));
327 case PROP_G_BUS_TYPE:
328 proxy->priv->bus_type = g_value_get_enum (value);
332 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
338 g_dbus_proxy_class_init (GDBusProxyClass *klass)
340 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
342 gobject_class->dispose = g_dbus_proxy_dispose;
343 gobject_class->finalize = g_dbus_proxy_finalize;
344 gobject_class->set_property = g_dbus_proxy_set_property;
345 gobject_class->get_property = g_dbus_proxy_get_property;
347 /* Note that all property names are prefixed to avoid collisions with D-Bus property names
348 * in derived classes */
351 * GDBusProxy:g-interface-info:
353 * Ensure that interactions with this proxy conform to the given
354 * interface. For example, when completing a method call, if the
355 * type signature of the message isn't what's expected, the given
356 * #GError is set. Signals that have a type signature mismatch are
361 g_object_class_install_property (gobject_class,
362 PROP_G_INTERFACE_INFO,
363 g_param_spec_boxed ("g-interface-info",
364 P_("Interface Information"),
365 P_("Interface Information"),
366 G_TYPE_DBUS_INTERFACE_INFO,
369 G_PARAM_STATIC_NAME |
370 G_PARAM_STATIC_BLURB |
371 G_PARAM_STATIC_NICK));
374 * GDBusProxy:g-connection:
376 * The #GDBusConnection the proxy is for.
380 g_object_class_install_property (gobject_class,
382 g_param_spec_object ("g-connection",
384 P_("The connection the proxy is for"),
385 G_TYPE_DBUS_CONNECTION,
388 G_PARAM_CONSTRUCT_ONLY |
389 G_PARAM_STATIC_NAME |
390 G_PARAM_STATIC_BLURB |
391 G_PARAM_STATIC_NICK));
394 * GDBusProxy:g-bus-type:
396 * If this property is not %G_BUS_TYPE_NONE, then
397 * #GDBusProxy:g-connection must be %NULL and will be set to the
398 * #GDBusConnection obtained by calling g_bus_get() with the value
403 g_object_class_install_property (gobject_class,
405 g_param_spec_enum ("g-bus-type",
407 P_("The bus to connect to, if any"),
411 G_PARAM_CONSTRUCT_ONLY |
412 G_PARAM_STATIC_NAME |
413 G_PARAM_STATIC_BLURB |
414 G_PARAM_STATIC_NICK));
417 * GDBusProxy:g-flags:
419 * Flags from the #GDBusProxyFlags enumeration.
423 g_object_class_install_property (gobject_class,
425 g_param_spec_flags ("g-flags",
427 P_("Flags for the proxy"),
428 G_TYPE_DBUS_PROXY_FLAGS,
429 G_DBUS_PROXY_FLAGS_NONE,
432 G_PARAM_CONSTRUCT_ONLY |
433 G_PARAM_STATIC_NAME |
434 G_PARAM_STATIC_BLURB |
435 G_PARAM_STATIC_NICK));
440 * The well-known or unique name that the proxy is for.
444 g_object_class_install_property (gobject_class,
446 g_param_spec_string ("g-name",
448 P_("The well-known or unique name that the proxy is for"),
452 G_PARAM_CONSTRUCT_ONLY |
453 G_PARAM_STATIC_NAME |
454 G_PARAM_STATIC_BLURB |
455 G_PARAM_STATIC_NICK));
458 * GDBusProxy:g-name-owner:
460 * The unique name that owns #GDBusProxy:name or %NULL if no-one
461 * currently owns that name. You may connect to #GObject::notify signal to
462 * track changes to this property.
466 g_object_class_install_property (gobject_class,
468 g_param_spec_string ("g-name-owner",
470 P_("The unique name for the owner"),
473 G_PARAM_STATIC_NAME |
474 G_PARAM_STATIC_BLURB |
475 G_PARAM_STATIC_NICK));
478 * GDBusProxy:g-object-path:
480 * The object path the proxy is for.
484 g_object_class_install_property (gobject_class,
486 g_param_spec_string ("g-object-path",
488 P_("The object path the proxy is for"),
492 G_PARAM_CONSTRUCT_ONLY |
493 G_PARAM_STATIC_NAME |
494 G_PARAM_STATIC_BLURB |
495 G_PARAM_STATIC_NICK));
498 * GDBusProxy:g-interface-name:
500 * The D-Bus interface name the proxy is for.
504 g_object_class_install_property (gobject_class,
505 PROP_G_INTERFACE_NAME,
506 g_param_spec_string ("g-interface-name",
507 P_("g-interface-name"),
508 P_("The D-Bus interface name the proxy is for"),
512 G_PARAM_CONSTRUCT_ONLY |
513 G_PARAM_STATIC_NAME |
514 G_PARAM_STATIC_BLURB |
515 G_PARAM_STATIC_NICK));
518 * GDBusProxy:g-default-timeout:
520 * The timeout to use if -1 (specifying default timeout) is passed
521 * as @timeout_msec in the g_dbus_proxy_call() and
522 * g_dbus_proxy_call_sync() functions.
524 * This allows applications to set a proxy-wide timeout for all
525 * remote method invocations on the proxy. If this property is -1,
526 * the default timeout (typically 25 seconds) is used. If set to
527 * %G_MAXINT, then no timeout is used.
531 g_object_class_install_property (gobject_class,
532 PROP_G_DEFAULT_TIMEOUT,
533 g_param_spec_int ("g-default-timeout",
534 P_("Default Timeout"),
535 P_("Timeout for remote method invocation"),
542 G_PARAM_STATIC_NAME |
543 G_PARAM_STATIC_BLURB |
544 G_PARAM_STATIC_NICK));
547 * GDBusProxy::g-properties-changed:
548 * @proxy: The #GDBusProxy emitting the signal.
549 * @changed_properties: A #GVariant containing the properties that changed
550 * @invalidated_properties: A %NULL terminated array of properties that was invalidated
552 * Emitted when one or more D-Bus properties on @proxy changes. The
553 * local cache has already been updated when this signal fires. Note
554 * that both @changed_properties and @invalidated_properties are
555 * guaranteed to never be %NULL (either may be empty though).
557 * This signal corresponds to the
558 * <literal>PropertiesChanged</literal> D-Bus signal on the
559 * <literal>org.freedesktop.DBus.Properties</literal> interface.
563 signals[PROPERTIES_CHANGED_SIGNAL] = g_signal_new ("g-properties-changed",
565 G_SIGNAL_RUN_LAST | G_SIGNAL_MUST_COLLECT,
566 G_STRUCT_OFFSET (GDBusProxyClass, g_properties_changed),
573 G_TYPE_STRV | G_SIGNAL_TYPE_STATIC_SCOPE);
576 * GDBusProxy::g-signal:
577 * @proxy: The #GDBusProxy emitting the signal.
578 * @sender_name: The sender of the signal or %NULL if the connection is not a bus connection.
579 * @signal_name: The name of the signal.
580 * @parameters: A #GVariant tuple with parameters for the signal.
582 * Emitted when a signal from the remote object and interface that @proxy is for, has been received.
586 signals[SIGNAL_SIGNAL] = g_signal_new ("g-signal",
588 G_SIGNAL_RUN_LAST | G_SIGNAL_MUST_COLLECT,
589 G_STRUCT_OFFSET (GDBusProxyClass, g_signal),
600 g_type_class_add_private (klass, sizeof (GDBusProxyPrivate));
604 g_dbus_proxy_init (GDBusProxy *proxy)
606 proxy->priv = G_TYPE_INSTANCE_GET_PRIVATE (proxy, G_TYPE_DBUS_PROXY, GDBusProxyPrivate);
607 proxy->priv->signal_subscription_data = g_slice_new0 (SignalSubscriptionData);
608 proxy->priv->signal_subscription_data->ref_count = 1;
609 proxy->priv->signal_subscription_data->proxy = proxy;
610 proxy->priv->properties = g_hash_table_new_full (g_str_hash,
613 (GDestroyNotify) g_variant_unref);
616 /* ---------------------------------------------------------------------------------------------------- */
619 property_name_sort_func (const gchar **a,
622 return g_strcmp0 (*a, *b);
626 * g_dbus_proxy_get_cached_property_names:
627 * @proxy: A #GDBusProxy.
629 * Gets the names of all cached properties on @proxy.
631 * Returns: A %NULL-terminated array of strings or %NULL if @proxy has
632 * no cached properties. Free the returned array with g_strfreev().
637 g_dbus_proxy_get_cached_property_names (GDBusProxy *proxy)
644 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
646 G_LOCK (properties_lock);
649 if (g_hash_table_size (proxy->priv->properties) == 0)
652 p = g_ptr_array_new ();
654 g_hash_table_iter_init (&iter, proxy->priv->properties);
655 while (g_hash_table_iter_next (&iter, (gpointer) &key, NULL))
656 g_ptr_array_add (p, g_strdup (key));
657 g_ptr_array_sort (p, (GCompareFunc) property_name_sort_func);
658 g_ptr_array_add (p, NULL);
660 names = (gchar **) g_ptr_array_free (p, FALSE);
663 G_UNLOCK (properties_lock);
667 static const GDBusPropertyInfo *
668 lookup_property_info_or_warn (GDBusProxy *proxy,
669 const gchar *property_name)
671 const GDBusPropertyInfo *info;
673 if (proxy->priv->expected_interface == NULL)
676 info = g_dbus_interface_info_lookup_property (proxy->priv->expected_interface, property_name);
679 g_warning ("Trying to lookup property %s which isn't in expected interface %s",
681 proxy->priv->expected_interface->name);
688 * g_dbus_proxy_get_cached_property:
689 * @proxy: A #GDBusProxy.
690 * @property_name: Property name.
692 * Looks up the value for a property from the cache. This call does no
695 * If @proxy has an expected interface (see
696 * #GDBusProxy:g-interface-info), then @property_name (for existence)
697 * is checked against it.
699 * Returns: A reference to the #GVariant instance that holds the value
700 * for @property_name or %NULL if the value is not in the cache. The
701 * returned reference must be freed with g_variant_unref().
706 g_dbus_proxy_get_cached_property (GDBusProxy *proxy,
707 const gchar *property_name)
711 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
712 g_return_val_if_fail (property_name != NULL, NULL);
714 G_LOCK (properties_lock);
716 value = g_hash_table_lookup (proxy->priv->properties, property_name);
719 lookup_property_info_or_warn (proxy, property_name);
724 g_variant_ref (value);
727 G_UNLOCK (properties_lock);
732 * g_dbus_proxy_set_cached_property:
733 * @proxy: A #GDBusProxy
734 * @property_name: Property name.
735 * @value: (allow-none): Value for the property or %NULL to remove it from the cache.
737 * If @value is not %NULL, sets the cached value for the property with
738 * name @property_name to the value in @value.
740 * If @value is %NULL, then the cached value is removed from the
743 * If @proxy has an expected interface (see
744 * #GDBusProxy:g-interface-info), then @property_name (for existence)
745 * and @value (for the type) is checked against it.
747 * If the @value #GVariant is floating, it is consumed. This allows
748 * convenient 'inline' use of g_variant_new(), e.g.
750 * g_dbus_proxy_set_cached_property (proxy,
752 * g_variant_new ("(si)",
757 * Normally you will not need to use this method since @proxy is
758 * tracking changes using the
759 * <literal>org.freedesktop.DBus.Properties.PropertiesChanged</literal>
760 * D-Bus signal. However, for performance reasons an object may decide
761 * to not use this signal for some properties and instead use a
762 * proprietary out-of-band mechanism to transmit changes.
764 * As a concrete example, consider an object with a property
765 * <literal>ChatroomParticipants</literal> which is an array of
766 * strings. Instead of transmitting the same (long) array every time
767 * the property changes, it is more efficient to only transmit the
768 * delta using e.g. signals <literal>ChatroomParticipantJoined(String
769 * name)</literal> and <literal>ChatroomParticipantParted(String
775 g_dbus_proxy_set_cached_property (GDBusProxy *proxy,
776 const gchar *property_name,
779 const GDBusPropertyInfo *info;
781 g_return_if_fail (G_IS_DBUS_PROXY (proxy));
782 g_return_if_fail (property_name != NULL);
784 G_LOCK (properties_lock);
788 info = lookup_property_info_or_warn (proxy, property_name);
791 if (g_strcmp0 (info->signature, g_variant_get_type_string (value)) != 0)
793 g_warning ("Trying to set property %s of type %s but according to the expected "
794 "interface the type is %s",
796 g_variant_get_type_string (value),
801 g_hash_table_insert (proxy->priv->properties,
802 g_strdup (property_name),
803 g_variant_ref_sink (value));
807 g_hash_table_remove (proxy->priv->properties, property_name);
811 G_UNLOCK (properties_lock);
814 /* ---------------------------------------------------------------------------------------------------- */
817 on_signal_received (GDBusConnection *connection,
818 const gchar *sender_name,
819 const gchar *object_path,
820 const gchar *interface_name,
821 const gchar *signal_name,
822 GVariant *parameters,
825 SignalSubscriptionData *data = user_data;
828 G_LOCK (signal_subscription_lock);
832 G_UNLOCK (signal_subscription_lock);
837 g_object_ref (proxy);
838 G_UNLOCK (signal_subscription_lock);
841 if (!proxy->priv->initialized)
844 if (proxy->priv->name_owner != NULL && g_strcmp0 (sender_name, proxy->priv->name_owner) != 0)
847 if (proxy->priv->expected_interface != NULL)
849 const GDBusSignalInfo *info;
850 GVariantType *expected_type;
851 info = g_dbus_interface_info_lookup_signal (proxy->priv->expected_interface, signal_name);
854 expected_type = _g_dbus_compute_complete_signature (info->args);
855 if (!g_variant_type_equal (expected_type, g_variant_get_type (parameters)))
857 g_variant_type_free (expected_type);
860 g_variant_type_free (expected_type);
863 g_signal_emit (proxy,
864 signals[SIGNAL_SIGNAL],
871 g_object_unref (proxy);
874 /* ---------------------------------------------------------------------------------------------------- */
876 /* must hold properties_lock */
878 insert_property_checked (GDBusProxy *proxy,
879 gchar *property_name,
882 if (proxy->priv->expected_interface != NULL)
884 const GDBusPropertyInfo *info;
886 info = g_dbus_interface_info_lookup_property (proxy->priv->expected_interface, property_name);
887 /* Ignore unknown properties */
891 /* Ignore properties with the wrong type */
892 if (g_strcmp0 (info->signature, g_variant_get_type_string (value)) != 0)
896 g_hash_table_insert (proxy->priv->properties,
897 property_name, /* adopts string */
898 value); /* adopts value */
903 g_variant_unref (value);
904 g_free (property_name);
908 on_properties_changed (GDBusConnection *connection,
909 const gchar *sender_name,
910 const gchar *object_path,
911 const gchar *interface_name,
912 const gchar *signal_name,
913 GVariant *parameters,
916 SignalSubscriptionData *data = user_data;
918 const gchar *interface_name_for_signal;
919 GVariant *changed_properties;
920 gchar **invalidated_properties;
926 G_LOCK (signal_subscription_lock);
930 G_UNLOCK (signal_subscription_lock);
935 g_object_ref (proxy);
936 G_UNLOCK (signal_subscription_lock);
939 changed_properties = NULL;
940 invalidated_properties = NULL;
942 if (!proxy->priv->initialized)
945 if (proxy->priv->name_owner != NULL && g_strcmp0 (sender_name, proxy->priv->name_owner) != 0)
948 if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(sa{sv}as)")))
950 g_warning ("Value for PropertiesChanged signal with type `%s' does not match `(sa{sv}as)'",
951 g_variant_get_type_string (parameters));
955 g_variant_get (parameters,
957 &interface_name_for_signal,
959 &invalidated_properties);
961 if (g_strcmp0 (interface_name_for_signal, proxy->priv->interface_name) != 0)
964 G_LOCK (properties_lock);
966 g_variant_iter_init (&iter, changed_properties);
967 while (g_variant_iter_next (&iter, "{sv}", &key, &value))
969 insert_property_checked (proxy,
970 key, /* adopts string */
971 value); /* adopts value */
974 for (n = 0; invalidated_properties[n] != NULL; n++)
976 g_hash_table_remove (proxy->priv->properties, invalidated_properties[n]);
979 G_UNLOCK (properties_lock);
982 g_signal_emit (proxy, signals[PROPERTIES_CHANGED_SIGNAL],
985 invalidated_properties);
988 if (changed_properties != NULL)
989 g_variant_unref (changed_properties);
990 g_free (invalidated_properties);
992 g_object_unref (proxy);
995 /* ---------------------------------------------------------------------------------------------------- */
998 process_get_all_reply (GDBusProxy *proxy,
1004 guint num_properties;
1006 if (!g_variant_is_of_type (result, G_VARIANT_TYPE ("(a{sv})")))
1008 g_warning ("Value for GetAll reply with type `%s' does not match `(a{sv})'",
1009 g_variant_get_type_string (result));
1013 G_LOCK (properties_lock);
1015 g_variant_get (result, "(a{sv})", &iter);
1016 while (g_variant_iter_next (iter, "{sv}", &key, &value))
1018 insert_property_checked (proxy,
1019 key, /* adopts string */
1020 value); /* adopts value */
1022 g_variant_iter_free (iter);
1024 num_properties = g_hash_table_size (proxy->priv->properties);
1025 G_UNLOCK (properties_lock);
1027 /* Synthesize ::g-properties-changed changed */
1028 if (num_properties > 0)
1030 GVariant *changed_properties;
1031 const gchar *invalidated_properties[1] = {NULL};
1033 g_variant_get (result,
1035 &changed_properties);
1036 g_signal_emit (proxy, signals[PROPERTIES_CHANGED_SIGNAL],
1039 invalidated_properties);
1040 g_variant_unref (changed_properties);
1050 GCancellable *cancellable;
1052 } LoadPropertiesOnNameOwnerChangedData;
1055 on_name_owner_changed_get_all_cb (GDBusConnection *connection,
1059 LoadPropertiesOnNameOwnerChangedData *data = user_data;
1067 result = g_dbus_connection_call_finish (connection,
1072 if (error->domain == G_IO_ERROR && error->code == G_IO_ERROR_CANCELLED)
1074 /* We just ignore if GetAll() is failing. Because this might happen
1075 * if the object has no properties at all. Or if the caller is
1076 * not authorized to see the properties.
1078 * Either way, apps can know about this by using
1079 * get_cached_property_names() or get_cached_property().
1081 * TODO: handle G_DBUS_DEBUG flag 'proxy' and, if enabled, log the
1082 * fact that GetAll() failed
1084 //g_debug ("error: %d %d %s", error->domain, error->code, error->message);
1085 g_error_free (error);
1088 /* and finally we can notify */
1091 g_free (data->proxy->priv->name_owner);
1092 data->proxy->priv->name_owner = data->name_owner;
1093 data->name_owner = NULL; /* to avoid an extra copy, we steal the string */
1095 G_LOCK (properties_lock);
1096 g_hash_table_remove_all (data->proxy->priv->properties);
1097 G_UNLOCK (properties_lock);
1100 process_get_all_reply (data->proxy, result);
1101 g_variant_unref (result);
1104 g_object_notify (G_OBJECT (data->proxy), "g-name-owner");
1107 if (data->cancellable == data->proxy->priv->get_all_cancellable)
1108 data->proxy->priv->get_all_cancellable = NULL;
1110 g_object_unref (data->proxy);
1111 g_object_unref (data->cancellable);
1112 g_free (data->name_owner);
1117 on_name_owner_changed (GDBusConnection *connection,
1118 const gchar *sender_name,
1119 const gchar *object_path,
1120 const gchar *interface_name,
1121 const gchar *signal_name,
1122 GVariant *parameters,
1125 SignalSubscriptionData *data = user_data;
1127 const gchar *old_owner;
1128 const gchar *new_owner;
1130 G_LOCK (signal_subscription_lock);
1131 proxy = data->proxy;
1134 G_UNLOCK (signal_subscription_lock);
1139 g_object_ref (proxy);
1140 G_UNLOCK (signal_subscription_lock);
1143 /* if we are already trying to load properties, cancel that */
1144 if (proxy->priv->get_all_cancellable != NULL)
1146 g_cancellable_cancel (proxy->priv->get_all_cancellable);
1147 proxy->priv->get_all_cancellable = NULL;
1150 g_variant_get (parameters,
1156 if (strlen (new_owner) == 0)
1158 g_free (proxy->priv->name_owner);
1159 proxy->priv->name_owner = NULL;
1161 G_LOCK (properties_lock);
1163 /* Synthesize ::g-properties-changed changed */
1164 if (!(proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES) &&
1165 g_hash_table_size (proxy->priv->properties) > 0)
1167 GVariantBuilder builder;
1168 GPtrArray *invalidated_properties;
1169 GHashTableIter iter;
1172 /* Build changed_properties (always empty) and invalidated_properties ... */
1173 g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
1175 invalidated_properties = g_ptr_array_new_with_free_func (g_free);
1176 g_hash_table_iter_init (&iter, proxy->priv->properties);
1177 while (g_hash_table_iter_next (&iter, (gpointer) &key, NULL))
1178 g_ptr_array_add (invalidated_properties, g_strdup (key));
1179 g_ptr_array_add (invalidated_properties, NULL);
1181 /* ... throw out the properties ... */
1182 g_hash_table_remove_all (proxy->priv->properties);
1184 G_UNLOCK (properties_lock);
1186 /* ... and finally emit the ::g-properties-changed signal */
1187 g_signal_emit (proxy, signals[PROPERTIES_CHANGED_SIGNAL],
1189 g_variant_builder_end (&builder) /* consumed */,
1190 (const gchar* const *) invalidated_properties->pdata);
1191 g_ptr_array_unref (invalidated_properties);
1195 G_UNLOCK (properties_lock);
1197 g_object_notify (G_OBJECT (proxy), "g-name-owner");
1201 /* ignore duplicates - this can happen when activating the service */
1202 if (g_strcmp0 (new_owner, proxy->priv->name_owner) == 0)
1205 if (proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES)
1207 g_free (proxy->priv->name_owner);
1208 proxy->priv->name_owner = g_strdup (new_owner);
1209 G_LOCK (properties_lock);
1210 g_hash_table_remove_all (proxy->priv->properties);
1211 G_UNLOCK (properties_lock);
1212 g_object_notify (G_OBJECT (proxy), "g-name-owner");
1216 LoadPropertiesOnNameOwnerChangedData *data;
1218 /* start loading properties.. only then emit notify::g-name-owner .. we
1219 * need to be able to cancel this in the event another NameOwnerChanged
1220 * signal suddenly happens
1223 g_assert (proxy->priv->get_all_cancellable == NULL);
1224 proxy->priv->get_all_cancellable = g_cancellable_new ();
1225 data = g_new0 (LoadPropertiesOnNameOwnerChangedData, 1);
1226 data->proxy = g_object_ref (proxy);
1227 data->cancellable = proxy->priv->get_all_cancellable;
1228 data->name_owner = g_strdup (new_owner);
1229 g_dbus_connection_call (proxy->priv->connection,
1231 proxy->priv->object_path,
1232 "org.freedesktop.DBus.Properties",
1234 g_variant_new ("(s)", proxy->priv->interface_name),
1235 G_VARIANT_TYPE ("(a{sv})"),
1236 G_DBUS_CALL_FLAGS_NONE,
1238 proxy->priv->get_all_cancellable,
1239 (GAsyncReadyCallback) on_name_owner_changed_get_all_cb,
1246 g_object_unref (proxy);
1249 /* ---------------------------------------------------------------------------------------------------- */
1254 GCancellable *cancellable;
1255 GSimpleAsyncResult *simple;
1259 async_init_data_free (AsyncInitData *data)
1261 g_object_unref (data->proxy);
1262 if (data->cancellable != NULL)
1263 g_object_unref (data->cancellable);
1264 g_object_unref (data->simple);
1269 async_init_get_all_cb (GDBusConnection *connection,
1273 AsyncInitData *data = user_data;
1278 result = g_dbus_connection_call_finish (connection,
1283 /* We just ignore if GetAll() is failing. Because this might happen
1284 * if the object has no properties at all. Or if the caller is
1285 * not authorized to see the properties.
1287 * Either way, apps can know about this by using
1288 * get_cached_property_names() or get_cached_property().
1290 * TODO: handle G_DBUS_DEBUG flag 'proxy' and, if enabled, log the
1291 * fact that GetAll() failed
1293 //g_debug ("error: %d %d %s", error->domain, error->code, error->message);
1294 g_error_free (error);
1298 g_simple_async_result_set_op_res_gpointer (data->simple,
1300 (GDestroyNotify) g_variant_unref);
1303 g_simple_async_result_complete_in_idle (data->simple);
1304 async_init_data_free (data);
1309 async_init_get_name_owner_cb (GDBusConnection *connection,
1313 AsyncInitData *data = user_data;
1321 result = g_dbus_connection_call_finish (connection,
1326 if (error->domain == G_DBUS_ERROR &&
1327 error->code == G_DBUS_ERROR_NAME_HAS_NO_OWNER)
1329 g_error_free (error);
1333 g_simple_async_result_take_error (data->simple, error);
1334 g_simple_async_result_complete_in_idle (data->simple);
1335 async_init_data_free (data);
1341 g_variant_get (result,
1343 &data->proxy->priv->name_owner);
1344 g_variant_unref (result);
1348 if (!(data->proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES))
1350 /* load all properties asynchronously */
1351 g_dbus_connection_call (data->proxy->priv->connection,
1352 data->proxy->priv->name_owner,
1353 data->proxy->priv->object_path,
1354 "org.freedesktop.DBus.Properties",
1356 g_variant_new ("(s)", data->proxy->priv->interface_name),
1357 G_VARIANT_TYPE ("(a{sv})"),
1358 G_DBUS_CALL_FLAGS_NONE,
1361 (GAsyncReadyCallback) async_init_get_all_cb,
1366 g_simple_async_result_complete_in_idle (data->simple);
1367 async_init_data_free (data);
1375 async_init_call_get_name_owner (AsyncInitData *data)
1377 g_dbus_connection_call (data->proxy->priv->connection,
1378 "org.freedesktop.DBus", /* name */
1379 "/org/freedesktop/DBus", /* object path */
1380 "org.freedesktop.DBus", /* interface */
1382 g_variant_new ("(s)",
1383 data->proxy->priv->name),
1384 G_VARIANT_TYPE ("(s)"),
1385 G_DBUS_CALL_FLAGS_NONE,
1388 (GAsyncReadyCallback) async_init_get_name_owner_cb,
1393 async_init_start_service_by_name_cb (GDBusConnection *connection,
1397 AsyncInitData *data = user_data;
1402 result = g_dbus_connection_call_finish (connection,
1407 /* Errors are not unexpected; the bus will reply e.g.
1409 * org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.Epiphany2
1410 * was not provided by any .service files
1412 * This doesn't mean that the name doesn't have an owner, just
1413 * that it's not provided by a .service file. So just proceed to
1414 * invoke GetNameOwner() if dealing with that error.
1416 if (error->domain == G_DBUS_ERROR &&
1417 error->code == G_DBUS_ERROR_SERVICE_UNKNOWN)
1419 g_error_free (error);
1423 g_prefix_error (&error,
1424 _("Error calling StartServiceByName for %s: "),
1425 data->proxy->priv->name);
1431 guint32 start_service_result;
1432 g_variant_get (result,
1434 &start_service_result);
1435 g_variant_unref (result);
1436 if (start_service_result == 1 || /* DBUS_START_REPLY_SUCCESS */
1437 start_service_result == 2) /* DBUS_START_REPLY_ALREADY_RUNNING */
1439 /* continue to invoke GetNameOwner() */
1443 error = g_error_new (G_IO_ERROR,
1445 _("Unexpected reply %d from StartServiceByName(\"%s\") method"),
1446 start_service_result,
1447 data->proxy->priv->name);
1452 async_init_call_get_name_owner (data);
1456 g_warn_if_fail (error != NULL);
1457 g_simple_async_result_take_error (data->simple, error);
1458 g_simple_async_result_complete_in_idle (data->simple);
1459 async_init_data_free (data);
1463 async_init_call_start_service_by_name (AsyncInitData *data)
1465 g_dbus_connection_call (data->proxy->priv->connection,
1466 "org.freedesktop.DBus", /* name */
1467 "/org/freedesktop/DBus", /* object path */
1468 "org.freedesktop.DBus", /* interface */
1469 "StartServiceByName",
1470 g_variant_new ("(su)",
1471 data->proxy->priv->name,
1473 G_VARIANT_TYPE ("(u)"),
1474 G_DBUS_CALL_FLAGS_NONE,
1477 (GAsyncReadyCallback) async_init_start_service_by_name_cb,
1482 async_initable_init_second_async (GAsyncInitable *initable,
1484 GCancellable *cancellable,
1485 GAsyncReadyCallback callback,
1488 GDBusProxy *proxy = G_DBUS_PROXY (initable);
1489 AsyncInitData *data;
1491 data = g_new0 (AsyncInitData, 1);
1492 data->proxy = g_object_ref (proxy);
1493 data->cancellable = cancellable != NULL ? g_object_ref (cancellable) : NULL;
1494 data->simple = g_simple_async_result_new (G_OBJECT (proxy),
1499 /* Check name ownership asynchronously - possibly also start the service */
1500 if (proxy->priv->name == NULL)
1503 async_init_get_name_owner_cb (proxy->priv->connection, NULL, data);
1505 else if (g_dbus_is_unique_name (proxy->priv->name))
1507 proxy->priv->name_owner = g_strdup (proxy->priv->name);
1508 async_init_get_name_owner_cb (proxy->priv->connection, NULL, data);
1512 if (proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START)
1514 async_init_call_get_name_owner (data);
1518 async_init_call_start_service_by_name (data);
1524 async_initable_init_second_finish (GAsyncInitable *initable,
1528 GDBusProxy *proxy = G_DBUS_PROXY (initable);
1529 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
1535 if (g_simple_async_result_propagate_error (simple, error))
1538 result = g_simple_async_result_get_op_res_gpointer (simple);
1541 process_get_all_reply (proxy, result);
1547 proxy->priv->initialized = TRUE;
1551 /* ---------------------------------------------------------------------------------------------------- */
1554 async_initable_init_first (GAsyncInitable *initable)
1556 GDBusProxy *proxy = G_DBUS_PROXY (initable);
1558 if (!(proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES))
1560 /* subscribe to PropertiesChanged() */
1561 proxy->priv->properties_changed_subscription_id =
1562 g_dbus_connection_signal_subscribe (proxy->priv->connection,
1564 "org.freedesktop.DBus.Properties",
1565 "PropertiesChanged",
1566 proxy->priv->object_path,
1567 proxy->priv->interface_name,
1568 G_DBUS_SIGNAL_FLAGS_NONE,
1569 on_properties_changed,
1570 signal_subscription_ref (proxy->priv->signal_subscription_data),
1571 (GDestroyNotify) signal_subscription_unref);
1574 if (!(proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS))
1576 /* subscribe to all signals for the object */
1577 proxy->priv->signals_subscription_id =
1578 g_dbus_connection_signal_subscribe (proxy->priv->connection,
1580 proxy->priv->interface_name,
1582 proxy->priv->object_path,
1584 G_DBUS_SIGNAL_FLAGS_NONE,
1586 signal_subscription_ref (proxy->priv->signal_subscription_data),
1587 (GDestroyNotify) signal_subscription_unref);
1590 if (proxy->priv->name != NULL && !g_dbus_is_unique_name (proxy->priv->name))
1592 proxy->priv->name_owner_changed_subscription_id =
1593 g_dbus_connection_signal_subscribe (proxy->priv->connection,
1594 "org.freedesktop.DBus", /* name */
1595 "org.freedesktop.DBus", /* interface */
1596 "NameOwnerChanged", /* signal name */
1597 "/org/freedesktop/DBus", /* path */
1598 proxy->priv->name, /* arg0 */
1599 G_DBUS_SIGNAL_FLAGS_NONE,
1600 on_name_owner_changed,
1601 signal_subscription_ref (proxy->priv->signal_subscription_data),
1602 (GDestroyNotify) signal_subscription_unref);
1606 /* ---------------------------------------------------------------------------------------------------- */
1608 /* initialization is split into two parts - the first is the
1609 * non-blocing part that requires the callers GMainContext - the
1610 * second is a blocking part async part that doesn't require the
1611 * callers GMainContext.. we do this split so the code can be reused
1612 * in the GInitable implementation below.
1614 * Note that obtaining a GDBusConnection is not shared between the two
1622 GCancellable *cancellable;
1623 GAsyncReadyCallback callback;
1625 } GetConnectionData;
1628 get_connection_cb (GObject *source_object,
1632 GetConnectionData *data = user_data;
1636 data->proxy->priv->connection = g_bus_get_finish (res, &error);
1637 if (data->proxy->priv->connection == NULL)
1639 GSimpleAsyncResult *simple;
1640 simple = g_simple_async_result_new (G_OBJECT (data->proxy),
1644 g_simple_async_result_take_error (simple, error);
1645 g_simple_async_result_complete_in_idle (simple);
1646 g_object_unref (simple);
1650 async_initable_init_first (G_ASYNC_INITABLE (data->proxy));
1651 async_initable_init_second_async (G_ASYNC_INITABLE (data->proxy),
1658 if (data->cancellable != NULL)
1659 g_object_unref (data->cancellable);
1661 g_object_unref (data->proxy);
1666 async_initable_init_async (GAsyncInitable *initable,
1668 GCancellable *cancellable,
1669 GAsyncReadyCallback callback,
1672 GDBusProxy *proxy = G_DBUS_PROXY (initable);
1674 if (proxy->priv->bus_type != G_BUS_TYPE_NONE)
1676 GetConnectionData *data;
1678 g_assert (proxy->priv->connection == NULL);
1680 data = g_new0 (GetConnectionData, 1);
1681 data->proxy = g_object_ref (proxy);
1682 data->io_priority = io_priority;
1683 data->cancellable = cancellable != NULL ? g_object_ref (cancellable) : NULL;
1684 data->callback = callback;
1685 data->user_data = user_data;
1686 g_bus_get (proxy->priv->bus_type,
1693 async_initable_init_first (initable);
1694 async_initable_init_second_async (initable, io_priority, cancellable, callback, user_data);
1699 async_initable_init_finish (GAsyncInitable *initable,
1703 return async_initable_init_second_finish (initable, res, error);
1707 async_initable_iface_init (GAsyncInitableIface *async_initable_iface)
1709 async_initable_iface->init_async = async_initable_init_async;
1710 async_initable_iface->init_finish = async_initable_init_finish;
1713 /* ---------------------------------------------------------------------------------------------------- */
1717 GMainContext *context;
1720 } InitableAsyncInitableData;
1723 async_initable_init_async_cb (GObject *source_object,
1727 InitableAsyncInitableData *data = user_data;
1728 data->res = g_object_ref (res);
1729 g_main_loop_quit (data->loop);
1732 /* Simply reuse the GAsyncInitable implementation but run the first
1733 * part (that is non-blocking and requires the callers GMainContext)
1734 * with the callers GMainContext.. and the second with a private
1735 * GMainContext (bug 621310 is slightly related).
1737 * Note that obtaining a GDBusConnection is not shared between the two
1741 initable_init (GInitable *initable,
1742 GCancellable *cancellable,
1745 GDBusProxy *proxy = G_DBUS_PROXY (initable);
1746 InitableAsyncInitableData *data;
1751 if (proxy->priv->bus_type != G_BUS_TYPE_NONE)
1753 g_assert (proxy->priv->connection == NULL);
1754 proxy->priv->connection = g_bus_get_sync (proxy->priv->bus_type,
1757 if (proxy->priv->connection == NULL)
1761 async_initable_init_first (G_ASYNC_INITABLE (initable));
1763 data = g_new0 (InitableAsyncInitableData, 1);
1764 data->context = g_main_context_new ();
1765 data->loop = g_main_loop_new (data->context, FALSE);
1767 g_main_context_push_thread_default (data->context);
1769 async_initable_init_second_async (G_ASYNC_INITABLE (initable),
1772 async_initable_init_async_cb,
1775 g_main_loop_run (data->loop);
1777 ret = async_initable_init_second_finish (G_ASYNC_INITABLE (initable),
1781 g_main_context_pop_thread_default (data->context);
1783 g_main_context_unref (data->context);
1784 g_main_loop_unref (data->loop);
1785 g_object_unref (data->res);
1794 initable_iface_init (GInitableIface *initable_iface)
1796 initable_iface->init = initable_init;
1799 /* ---------------------------------------------------------------------------------------------------- */
1803 * @connection: A #GDBusConnection.
1804 * @flags: Flags used when constructing the proxy.
1805 * @info: (allow-none): A #GDBusInterfaceInfo specifying the minimal interface that @proxy conforms to or %NULL.
1806 * @name: (allow-none): A bus name (well-known or unique) or %NULL if @connection is not a message bus connection.
1807 * @object_path: An object path.
1808 * @interface_name: A D-Bus interface name.
1809 * @cancellable: A #GCancellable or %NULL.
1810 * @callback: Callback function to invoke when the proxy is ready.
1811 * @user_data: User data to pass to @callback.
1813 * Creates a proxy for accessing @interface_name on the remote object
1814 * at @object_path owned by @name at @connection and asynchronously
1815 * loads D-Bus properties unless the
1816 * %G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES flag is used. Connect to
1817 * the #GDBusProxy::g-properties-changed signal to get notified about
1820 * If the %G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS flag is not set, also sets up
1821 * match rules for signals. Connect to the #GDBusProxy::g-signal signal
1822 * to handle signals from the remote object.
1824 * If @name is a well-known name and the
1825 * %G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START flag isn't set and no name
1826 * owner currently exists, the message bus will be requested to launch
1827 * a name owner for the name.
1829 * This is a failable asynchronous constructor - when the proxy is
1830 * ready, @callback will be invoked and you can use
1831 * g_dbus_proxy_new_finish() to get the result.
1833 * See g_dbus_proxy_new_sync() and for a synchronous version of this constructor.
1835 * See <xref linkend="gdbus-wellknown-proxy"/> for an example of how #GDBusProxy can be used.
1840 g_dbus_proxy_new (GDBusConnection *connection,
1841 GDBusProxyFlags flags,
1842 GDBusInterfaceInfo *info,
1844 const gchar *object_path,
1845 const gchar *interface_name,
1846 GCancellable *cancellable,
1847 GAsyncReadyCallback callback,
1850 g_return_if_fail (G_IS_DBUS_CONNECTION (connection));
1851 g_return_if_fail ((name == NULL && g_dbus_connection_get_unique_name (connection) == NULL) || g_dbus_is_name (name));
1852 g_return_if_fail (g_variant_is_object_path (object_path));
1853 g_return_if_fail (g_dbus_is_interface_name (interface_name));
1855 g_async_initable_new_async (G_TYPE_DBUS_PROXY,
1861 "g-interface-info", info,
1863 "g-connection", connection,
1864 "g-object-path", object_path,
1865 "g-interface-name", interface_name,
1870 * g_dbus_proxy_new_finish:
1871 * @res: A #GAsyncResult obtained from the #GAsyncReadyCallback function passed to g_dbus_proxy_new().
1872 * @error: Return location for error or %NULL.
1874 * Finishes creating a #GDBusProxy.
1876 * Returns: A #GDBusProxy or %NULL if @error is set. Free with g_object_unref().
1881 g_dbus_proxy_new_finish (GAsyncResult *res,
1885 GObject *source_object;
1887 source_object = g_async_result_get_source_object (res);
1888 g_assert (source_object != NULL);
1890 object = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object),
1893 g_object_unref (source_object);
1896 return G_DBUS_PROXY (object);
1902 * g_dbus_proxy_new_sync:
1903 * @connection: A #GDBusConnection.
1904 * @flags: Flags used when constructing the proxy.
1905 * @info: (allow-none): A #GDBusInterfaceInfo specifying the minimal interface that @proxy conforms to or %NULL.
1906 * @name: (allow-none): A bus name (well-known or unique) or %NULL if @connection is not a message bus connection.
1907 * @object_path: An object path.
1908 * @interface_name: A D-Bus interface name.
1909 * @cancellable: (allow-none): A #GCancellable or %NULL.
1910 * @error: (allow-none): Return location for error or %NULL.
1912 * Creates a proxy for accessing @interface_name on the remote object
1913 * at @object_path owned by @name at @connection and synchronously
1914 * loads D-Bus properties unless the
1915 * %G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES flag is used.
1917 * If the %G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS flag is not set, also sets up
1918 * match rules for signals. Connect to the #GDBusProxy::g-signal signal
1919 * to handle signals from the remote object.
1921 * If @name is a well-known name and the
1922 * %G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START flag isn't set and no name
1923 * owner currently exists, the message bus will be requested to launch
1924 * a name owner for the name.
1926 * This is a synchronous failable constructor. See g_dbus_proxy_new()
1927 * and g_dbus_proxy_new_finish() for the asynchronous version.
1929 * See <xref linkend="gdbus-wellknown-proxy"/> for an example of how #GDBusProxy can be used.
1931 * Returns: A #GDBusProxy or %NULL if error is set. Free with g_object_unref().
1936 g_dbus_proxy_new_sync (GDBusConnection *connection,
1937 GDBusProxyFlags flags,
1938 GDBusInterfaceInfo *info,
1940 const gchar *object_path,
1941 const gchar *interface_name,
1942 GCancellable *cancellable,
1945 GInitable *initable;
1947 g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);
1948 g_return_val_if_fail ((name == NULL && g_dbus_connection_get_unique_name (connection) == NULL) ||
1949 g_dbus_is_name (name), NULL);
1950 g_return_val_if_fail (g_variant_is_object_path (object_path), NULL);
1951 g_return_val_if_fail (g_dbus_is_interface_name (interface_name), NULL);
1953 initable = g_initable_new (G_TYPE_DBUS_PROXY,
1957 "g-interface-info", info,
1959 "g-connection", connection,
1960 "g-object-path", object_path,
1961 "g-interface-name", interface_name,
1963 if (initable != NULL)
1964 return G_DBUS_PROXY (initable);
1969 /* ---------------------------------------------------------------------------------------------------- */
1972 * g_dbus_proxy_new_for_bus:
1973 * @bus_type: A #GBusType.
1974 * @flags: Flags used when constructing the proxy.
1975 * @info: (allow-none): A #GDBusInterfaceInfo specifying the minimal interface that @proxy conforms to or %NULL.
1976 * @name: A bus name (well-known or unique).
1977 * @object_path: An object path.
1978 * @interface_name: A D-Bus interface name.
1979 * @cancellable: A #GCancellable or %NULL.
1980 * @callback: Callback function to invoke when the proxy is ready.
1981 * @user_data: User data to pass to @callback.
1983 * Like g_dbus_proxy_new() but takes a #GBusType instead of a #GDBusConnection.
1985 * See <xref linkend="gdbus-wellknown-proxy"/> for an example of how #GDBusProxy can be used.
1990 g_dbus_proxy_new_for_bus (GBusType bus_type,
1991 GDBusProxyFlags flags,
1992 GDBusInterfaceInfo *info,
1994 const gchar *object_path,
1995 const gchar *interface_name,
1996 GCancellable *cancellable,
1997 GAsyncReadyCallback callback,
2000 g_return_if_fail (g_dbus_is_name (name));
2001 g_return_if_fail (g_variant_is_object_path (object_path));
2002 g_return_if_fail (g_dbus_is_interface_name (interface_name));
2004 g_async_initable_new_async (G_TYPE_DBUS_PROXY,
2010 "g-interface-info", info,
2012 "g-bus-type", bus_type,
2013 "g-object-path", object_path,
2014 "g-interface-name", interface_name,
2019 * g_dbus_proxy_new_for_bus_finish:
2020 * @res: A #GAsyncResult obtained from the #GAsyncReadyCallback function passed to g_dbus_proxy_new_for_bus().
2021 * @error: Return location for error or %NULL.
2023 * Finishes creating a #GDBusProxy.
2025 * Returns: A #GDBusProxy or %NULL if @error is set. Free with g_object_unref().
2030 g_dbus_proxy_new_for_bus_finish (GAsyncResult *res,
2033 return g_dbus_proxy_new_finish (res, error);
2037 * g_dbus_proxy_new_for_bus_sync:
2038 * @bus_type: A #GBusType.
2039 * @flags: Flags used when constructing the proxy.
2040 * @info: (allow-none): A #GDBusInterfaceInfo specifying the minimal interface
2041 * that @proxy conforms to or %NULL.
2042 * @name: A bus name (well-known or unique).
2043 * @object_path: An object path.
2044 * @interface_name: A D-Bus interface name.
2045 * @cancellable: A #GCancellable or %NULL.
2046 * @error: Return location for error or %NULL.
2048 * Like g_dbus_proxy_new_sync() but takes a #GBusType instead of a #GDBusConnection.
2050 * See <xref linkend="gdbus-wellknown-proxy"/> for an example of how #GDBusProxy can be used.
2052 * Returns: A #GDBusProxy or %NULL if error is set. Free with g_object_unref().
2057 g_dbus_proxy_new_for_bus_sync (GBusType bus_type,
2058 GDBusProxyFlags flags,
2059 GDBusInterfaceInfo *info,
2061 const gchar *object_path,
2062 const gchar *interface_name,
2063 GCancellable *cancellable,
2066 GInitable *initable;
2068 g_return_val_if_fail (g_dbus_is_name (name), NULL);
2069 g_return_val_if_fail (g_variant_is_object_path (object_path), NULL);
2070 g_return_val_if_fail (g_dbus_is_interface_name (interface_name), NULL);
2072 initable = g_initable_new (G_TYPE_DBUS_PROXY,
2076 "g-interface-info", info,
2078 "g-bus-type", bus_type,
2079 "g-object-path", object_path,
2080 "g-interface-name", interface_name,
2082 if (initable != NULL)
2083 return G_DBUS_PROXY (initable);
2088 /* ---------------------------------------------------------------------------------------------------- */
2091 * g_dbus_proxy_get_connection:
2092 * @proxy: A #GDBusProxy.
2094 * Gets the connection @proxy is for.
2096 * Returns: (transfer none): A #GDBusConnection owned by @proxy. Do not free.
2101 g_dbus_proxy_get_connection (GDBusProxy *proxy)
2103 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
2104 return proxy->priv->connection;
2108 * g_dbus_proxy_get_flags:
2109 * @proxy: A #GDBusProxy.
2111 * Gets the flags that @proxy was constructed with.
2113 * Returns: Flags from the #GDBusProxyFlags enumeration.
2118 g_dbus_proxy_get_flags (GDBusProxy *proxy)
2120 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), 0);
2121 return proxy->priv->flags;
2125 * g_dbus_proxy_get_name:
2126 * @proxy: A #GDBusProxy.
2128 * Gets the name that @proxy was constructed for.
2130 * Returns: A string owned by @proxy. Do not free.
2135 g_dbus_proxy_get_name (GDBusProxy *proxy)
2137 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
2138 return proxy->priv->name;
2142 * g_dbus_proxy_get_name_owner:
2143 * @proxy: A #GDBusProxy.
2145 * The unique name that owns the name that @proxy is for or %NULL if
2146 * no-one currently owns that name. You may connect to the
2147 * #GObject::notify signal to track changes to the
2148 * #GDBusProxy:g-name-owner property.
2150 * Returns: The name owner or %NULL if no name owner exists. Free with g_free().
2155 g_dbus_proxy_get_name_owner (GDBusProxy *proxy)
2157 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
2158 return g_strdup (proxy->priv->name_owner);
2162 * g_dbus_proxy_get_object_path:
2163 * @proxy: A #GDBusProxy.
2165 * Gets the object path @proxy is for.
2167 * Returns: A string owned by @proxy. Do not free.
2172 g_dbus_proxy_get_object_path (GDBusProxy *proxy)
2174 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
2175 return proxy->priv->object_path;
2179 * g_dbus_proxy_get_interface_name:
2180 * @proxy: A #GDBusProxy.
2182 * Gets the D-Bus interface name @proxy is for.
2184 * Returns: A string owned by @proxy. Do not free.
2189 g_dbus_proxy_get_interface_name (GDBusProxy *proxy)
2191 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
2192 return proxy->priv->interface_name;
2196 * g_dbus_proxy_get_default_timeout:
2197 * @proxy: A #GDBusProxy.
2199 * Gets the timeout to use if -1 (specifying default timeout) is
2200 * passed as @timeout_msec in the g_dbus_proxy_call() and
2201 * g_dbus_proxy_call_sync() functions.
2203 * See the #GDBusProxy:g-default-timeout property for more details.
2205 * Returns: Timeout to use for @proxy.
2210 g_dbus_proxy_get_default_timeout (GDBusProxy *proxy)
2212 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), -1);
2213 return proxy->priv->timeout_msec;
2217 * g_dbus_proxy_set_default_timeout:
2218 * @proxy: A #GDBusProxy.
2219 * @timeout_msec: Timeout in milliseconds.
2221 * Sets the timeout to use if -1 (specifying default timeout) is
2222 * passed as @timeout_msec in the g_dbus_proxy_call() and
2223 * g_dbus_proxy_call_sync() functions.
2225 * See the #GDBusProxy:g-default-timeout property for more details.
2230 g_dbus_proxy_set_default_timeout (GDBusProxy *proxy,
2233 g_return_if_fail (G_IS_DBUS_PROXY (proxy));
2234 g_return_if_fail (timeout_msec == -1 || timeout_msec >= 0);
2236 /* TODO: locking? */
2237 if (proxy->priv->timeout_msec != timeout_msec)
2239 proxy->priv->timeout_msec = timeout_msec;
2240 g_object_notify (G_OBJECT (proxy), "g-default-timeout");
2245 * g_dbus_proxy_get_interface_info:
2246 * @proxy: A #GDBusProxy
2248 * Returns the #GDBusInterfaceInfo, if any, specifying the minimal
2249 * interface that @proxy conforms to.
2251 * See the #GDBusProxy:g-interface-info property for more details.
2253 * Returns: A #GDBusInterfaceInfo or %NULL. Do not unref the returned
2254 * object, it is owned by @proxy.
2258 GDBusInterfaceInfo *
2259 g_dbus_proxy_get_interface_info (GDBusProxy *proxy)
2261 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
2262 return proxy->priv->expected_interface;
2266 * g_dbus_proxy_set_interface_info:
2267 * @proxy: A #GDBusProxy
2268 * @info: (allow-none): Minimum interface this proxy conforms to or %NULL to unset.
2270 * Ensure that interactions with @proxy conform to the given
2271 * interface. For example, when completing a method call, if the type
2272 * signature of the message isn't what's expected, the given #GError
2273 * is set. Signals that have a type signature mismatch are simply
2276 * See the #GDBusProxy:g-interface-info property for more details.
2281 g_dbus_proxy_set_interface_info (GDBusProxy *proxy,
2282 GDBusInterfaceInfo *info)
2284 g_return_if_fail (G_IS_DBUS_PROXY (proxy));
2285 if (proxy->priv->expected_interface != NULL)
2287 g_dbus_interface_info_cache_release (proxy->priv->expected_interface);
2288 g_dbus_interface_info_unref (proxy->priv->expected_interface);
2290 proxy->priv->expected_interface = info != NULL ? g_dbus_interface_info_ref (info) : NULL;
2291 if (proxy->priv->expected_interface != NULL)
2292 g_dbus_interface_info_cache_build (proxy->priv->expected_interface);
2295 /* ---------------------------------------------------------------------------------------------------- */
2298 maybe_split_method_name (const gchar *method_name,
2299 gchar **out_interface_name,
2300 const gchar **out_method_name)
2305 g_assert (out_interface_name != NULL);
2306 g_assert (out_method_name != NULL);
2307 *out_interface_name = NULL;
2308 *out_method_name = NULL;
2310 if (strchr (method_name, '.') != NULL)
2315 p = g_strdup (method_name);
2316 last_dot = strrchr (p, '.');
2319 *out_interface_name = p;
2320 *out_method_name = last_dot + 1;
2330 reply_cb (GDBusConnection *connection,
2334 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data);
2339 value = g_dbus_connection_call_finish (connection,
2344 g_simple_async_result_take_error (simple, error);
2348 g_simple_async_result_set_op_res_gpointer (simple,
2350 (GDestroyNotify) g_variant_unref);
2353 /* no need to complete in idle since the method GDBusConnection already does */
2354 g_simple_async_result_complete (simple);
2355 g_object_unref (simple);
2358 static const GDBusMethodInfo *
2359 lookup_method_info_or_warn (GDBusProxy *proxy,
2360 const gchar *method_name)
2362 const GDBusMethodInfo *info;
2364 if (proxy->priv->expected_interface == NULL)
2367 info = g_dbus_interface_info_lookup_method (proxy->priv->expected_interface, method_name);
2370 g_warning ("Trying to invoke method %s which isn't in expected interface %s",
2371 method_name, proxy->priv->expected_interface->name);
2377 static const gchar *
2378 get_destination_for_call (GDBusProxy *proxy)
2384 /* If proxy->priv->name is a unique name, then proxy->priv->name_owner
2385 * is never NULL and always the same as proxy->priv->name. We use this
2386 * knowledge to avoid checking if proxy->priv->name is a unique or
2389 ret = proxy->priv->name_owner;
2393 if (proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START)
2396 ret = proxy->priv->name;
2403 * g_dbus_proxy_call:
2404 * @proxy: A #GDBusProxy.
2405 * @method_name: Name of method to invoke.
2406 * @parameters: (allow-none): A #GVariant tuple with parameters for the signal or %NULL if not passing parameters.
2407 * @flags: Flags from the #GDBusCallFlags enumeration.
2408 * @timeout_msec: The timeout in milliseconds (with %G_MAXINT meaning
2409 * "infinite") or -1 to use the proxy default timeout.
2410 * @cancellable: A #GCancellable or %NULL.
2411 * @callback: A #GAsyncReadyCallback to call when the request is satisfied or %NULL if you don't
2412 * care about the result of the method invocation.
2413 * @user_data: The data to pass to @callback.
2415 * Asynchronously invokes the @method_name method on @proxy.
2417 * If @method_name contains any dots, then @name is split into interface and
2418 * method name parts. This allows using @proxy for invoking methods on
2421 * If the #GDBusConnection associated with @proxy is closed then
2422 * the operation will fail with %G_IO_ERROR_CLOSED. If
2423 * @cancellable is canceled, the operation will fail with
2424 * %G_IO_ERROR_CANCELLED. If @parameters contains a value not
2425 * compatible with the D-Bus protocol, the operation fails with
2426 * %G_IO_ERROR_INVALID_ARGUMENT.
2428 * If the @parameters #GVariant is floating, it is consumed. This allows
2429 * convenient 'inline' use of g_variant_new(), e.g.:
2431 * g_dbus_proxy_call (proxy,
2433 * g_variant_new ("(ss)",
2436 * G_DBUS_CALL_FLAGS_NONE,
2439 * (GAsyncReadyCallback) two_strings_done,
2443 * This is an asynchronous method. When the operation is finished,
2444 * @callback will be invoked in the
2445 * <link linkend="g-main-context-push-thread-default">thread-default main loop</link>
2446 * of the thread you are calling this method from.
2447 * You can then call g_dbus_proxy_call_finish() to get the result of
2448 * the operation. See g_dbus_proxy_call_sync() for the synchronous
2449 * version of this method.
2454 g_dbus_proxy_call (GDBusProxy *proxy,
2455 const gchar *method_name,
2456 GVariant *parameters,
2457 GDBusCallFlags flags,
2459 GCancellable *cancellable,
2460 GAsyncReadyCallback callback,
2463 GSimpleAsyncResult *simple;
2465 gchar *split_interface_name;
2466 const gchar *split_method_name;
2467 const gchar *target_method_name;
2468 const gchar *target_interface_name;
2469 const gchar *destination;
2470 GVariantType *reply_type;
2472 g_return_if_fail (G_IS_DBUS_PROXY (proxy));
2473 g_return_if_fail (g_dbus_is_member_name (method_name) || g_dbus_is_interface_name (method_name));
2474 g_return_if_fail (parameters == NULL || g_variant_is_of_type (parameters, G_VARIANT_TYPE_TUPLE));
2475 g_return_if_fail (timeout_msec == -1 || timeout_msec >= 0);
2478 split_interface_name = NULL;
2480 simple = g_simple_async_result_new (G_OBJECT (proxy),
2485 was_split = maybe_split_method_name (method_name, &split_interface_name, &split_method_name);
2486 target_method_name = was_split ? split_method_name : method_name;
2487 target_interface_name = was_split ? split_interface_name : proxy->priv->interface_name;
2489 /* Warn if method is unexpected (cf. :g-interface-info) */
2492 const GDBusMethodInfo *expected_method_info;
2493 expected_method_info = lookup_method_info_or_warn (proxy, target_method_name);
2494 if (expected_method_info != NULL)
2495 reply_type = _g_dbus_compute_complete_signature (expected_method_info->out_args);
2499 if (proxy->priv->name != NULL)
2501 destination = get_destination_for_call (proxy);
2502 if (destination == NULL)
2504 g_simple_async_result_set_error (simple,
2507 _("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"));
2512 g_dbus_connection_call (proxy->priv->connection,
2514 proxy->priv->object_path,
2515 target_interface_name,
2520 timeout_msec == -1 ? proxy->priv->timeout_msec : timeout_msec,
2522 (GAsyncReadyCallback) reply_cb,
2526 if (reply_type != NULL)
2527 g_variant_type_free (reply_type);
2529 g_free (split_interface_name);
2533 * g_dbus_proxy_call_finish:
2534 * @proxy: A #GDBusProxy.
2535 * @res: A #GAsyncResult obtained from the #GAsyncReadyCallback passed to g_dbus_proxy_call().
2536 * @error: Return location for error or %NULL.
2538 * Finishes an operation started with g_dbus_proxy_call().
2540 * Returns: %NULL if @error is set. Otherwise a #GVariant tuple with
2541 * return values. Free with g_variant_unref().
2546 g_dbus_proxy_call_finish (GDBusProxy *proxy,
2550 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
2553 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
2554 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
2555 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
2557 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_dbus_proxy_call);
2561 if (g_simple_async_result_propagate_error (simple, error))
2564 value = g_variant_ref (g_simple_async_result_get_op_res_gpointer (simple));
2571 * g_dbus_proxy_call_sync:
2572 * @proxy: A #GDBusProxy.
2573 * @method_name: Name of method to invoke.
2574 * @parameters: (allow-none): A #GVariant tuple with parameters for the signal
2575 * or %NULL if not passing parameters.
2576 * @flags: Flags from the #GDBusCallFlags enumeration.
2577 * @timeout_msec: The timeout in milliseconds (with %G_MAXINT meaning
2578 * "infinite") or -1 to use the proxy default timeout.
2579 * @cancellable: A #GCancellable or %NULL.
2580 * @error: Return location for error or %NULL.
2582 * Synchronously invokes the @method_name method on @proxy.
2584 * If @method_name contains any dots, then @name is split into interface and
2585 * method name parts. This allows using @proxy for invoking methods on
2588 * If the #GDBusConnection associated with @proxy is disconnected then
2589 * the operation will fail with %G_IO_ERROR_CLOSED. If
2590 * @cancellable is canceled, the operation will fail with
2591 * %G_IO_ERROR_CANCELLED. If @parameters contains a value not
2592 * compatible with the D-Bus protocol, the operation fails with
2593 * %G_IO_ERROR_INVALID_ARGUMENT.
2595 * If the @parameters #GVariant is floating, it is consumed. This allows
2596 * convenient 'inline' use of g_variant_new(), e.g.:
2598 * g_dbus_proxy_call_sync (proxy,
2600 * g_variant_new ("(ss)",
2603 * G_DBUS_CALL_FLAGS_NONE,
2609 * The calling thread is blocked until a reply is received. See
2610 * g_dbus_proxy_call() for the asynchronous version of this
2613 * Returns: %NULL if @error is set. Otherwise a #GVariant tuple with
2614 * return values. Free with g_variant_unref().
2619 g_dbus_proxy_call_sync (GDBusProxy *proxy,
2620 const gchar *method_name,
2621 GVariant *parameters,
2622 GDBusCallFlags flags,
2624 GCancellable *cancellable,
2629 gchar *split_interface_name;
2630 const gchar *split_method_name;
2631 const gchar *target_method_name;
2632 const gchar *target_interface_name;
2633 const gchar *destination;
2634 GVariantType *reply_type;
2636 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
2637 g_return_val_if_fail (g_dbus_is_member_name (method_name) || g_dbus_is_interface_name (method_name), NULL);
2638 g_return_val_if_fail (parameters == NULL || g_variant_is_of_type (parameters, G_VARIANT_TYPE_TUPLE), NULL);
2639 g_return_val_if_fail (timeout_msec == -1 || timeout_msec >= 0, NULL);
2640 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
2644 was_split = maybe_split_method_name (method_name, &split_interface_name, &split_method_name);
2645 target_method_name = was_split ? split_method_name : method_name;
2646 target_interface_name = was_split ? split_interface_name : proxy->priv->interface_name;
2648 /* Warn if method is unexpected (cf. :g-interface-info) */
2651 const GDBusMethodInfo *expected_method_info;
2652 expected_method_info = lookup_method_info_or_warn (proxy, target_method_name);
2653 if (expected_method_info != NULL)
2654 reply_type = _g_dbus_compute_complete_signature (expected_method_info->out_args);
2658 if (proxy->priv->name != NULL)
2660 destination = get_destination_for_call (proxy);
2661 if (destination == NULL)
2663 g_set_error_literal (error,
2666 _("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"));
2672 ret = g_dbus_connection_call_sync (proxy->priv->connection,
2674 proxy->priv->object_path,
2675 target_interface_name,
2680 timeout_msec == -1 ? proxy->priv->timeout_msec : timeout_msec,
2685 if (reply_type != NULL)
2686 g_variant_type_free (reply_type);
2688 g_free (split_interface_name);
2693 /* ---------------------------------------------------------------------------------------------------- */
2695 static GDBusInterfaceInfo *
2696 _g_dbus_proxy_get_info (GDBusInterface *interface)
2698 GDBusProxy *proxy = G_DBUS_PROXY (interface);
2699 return g_dbus_proxy_get_interface_info (proxy);
2702 static GDBusObject *
2703 _g_dbus_proxy_get_object (GDBusInterface *interface)
2705 GDBusProxy *proxy = G_DBUS_PROXY (interface);
2706 return proxy->priv->object;
2710 _g_dbus_proxy_set_object (GDBusInterface *interface,
2711 GDBusObject *object)
2713 GDBusProxy *proxy = G_DBUS_PROXY (interface);
2714 if (proxy->priv->object != NULL)
2715 g_object_remove_weak_pointer (G_OBJECT (proxy->priv->object), (gpointer *) &proxy->priv->object);
2716 proxy->priv->object = object;
2717 if (proxy->priv->object != NULL)
2718 g_object_add_weak_pointer (G_OBJECT (proxy->priv->object), (gpointer *) &proxy->priv->object);
2722 dbus_interface_iface_init (GDBusInterfaceIface *dbus_interface_iface)
2724 dbus_interface_iface->get_info = _g_dbus_proxy_get_info;
2725 dbus_interface_iface->get_object = _g_dbus_proxy_get_object;
2726 dbus_interface_iface->set_object = _g_dbus_proxy_set_object;
2729 /* ---------------------------------------------------------------------------------------------------- */