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
74 * #GDBusProxy::g-signal signals are not very convenient to work
75 * with. Therefore, the recommended way of working with proxies is to
76 * subclass #GDBusProxy, and have more natural properties and signals
77 * in your derived class. See <xref linkend="gdbus-example-gdbus-codegen"/>
78 * for how this can easily be done using the
79 * <command><link linkend="gdbus-codegen">gdbus-codegen</link></command>
82 * A #GDBusProxy instance can be used from multiple threads but note
83 * that all signals (e.g. #GDBusProxy::g-signal, #GDBusProxy::g-properties-changed
84 * and #GObject::notify) are emitted in the
85 * <link linkend="g-main-context-push-thread-default">thread-default main loop</link>
86 * of the thread where the instance was constructed.
88 * <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>
91 /* lock protecting the properties GHashTable */
92 G_LOCK_DEFINE_STATIC (properties_lock);
94 /* ---------------------------------------------------------------------------------------------------- */
96 G_LOCK_DEFINE_STATIC (signal_subscription_lock);
100 volatile gint ref_count;
102 } SignalSubscriptionData;
104 static SignalSubscriptionData *
105 signal_subscription_ref (SignalSubscriptionData *data)
107 g_atomic_int_inc (&data->ref_count);
112 signal_subscription_unref (SignalSubscriptionData *data)
114 if (g_atomic_int_dec_and_test (&data->ref_count))
116 g_slice_free (SignalSubscriptionData, data);
120 /* ---------------------------------------------------------------------------------------------------- */
122 struct _GDBusProxyPrivate
125 GDBusProxyFlags flags;
126 GDBusConnection *connection;
131 gchar *interface_name;
134 guint name_owner_changed_subscription_id;
136 GCancellable *get_all_cancellable;
138 /* gchar* -> GVariant* */
139 GHashTable *properties;
141 GDBusInterfaceInfo *expected_interface;
143 guint properties_changed_subscription_id;
144 guint signals_subscription_id;
146 gboolean initialized;
150 SignalSubscriptionData *signal_subscription_data;
162 PROP_G_INTERFACE_NAME,
163 PROP_G_DEFAULT_TIMEOUT,
164 PROP_G_INTERFACE_INFO
169 PROPERTIES_CHANGED_SIGNAL,
174 guint signals[LAST_SIGNAL] = {0};
176 static void dbus_interface_iface_init (GDBusInterfaceIface *dbus_interface_iface);
177 static void initable_iface_init (GInitableIface *initable_iface);
178 static void async_initable_iface_init (GAsyncInitableIface *async_initable_iface);
180 G_DEFINE_TYPE_WITH_CODE (GDBusProxy, g_dbus_proxy, G_TYPE_OBJECT,
181 G_IMPLEMENT_INTERFACE (G_TYPE_DBUS_INTERFACE, dbus_interface_iface_init)
182 G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, initable_iface_init)
183 G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, async_initable_iface_init)
187 g_dbus_proxy_dispose (GObject *object)
189 GDBusProxy *proxy = G_DBUS_PROXY (object);
190 G_LOCK (signal_subscription_lock);
191 if (proxy->priv->signal_subscription_data != NULL)
193 proxy->priv->signal_subscription_data->proxy = NULL;
194 signal_subscription_unref (proxy->priv->signal_subscription_data);
195 proxy->priv->signal_subscription_data = NULL;
197 G_UNLOCK (signal_subscription_lock);
199 G_OBJECT_CLASS (g_dbus_proxy_parent_class)->dispose (object);
203 g_dbus_proxy_finalize (GObject *object)
205 GDBusProxy *proxy = G_DBUS_PROXY (object);
207 g_warn_if_fail (proxy->priv->get_all_cancellable == NULL);
209 if (proxy->priv->name_owner_changed_subscription_id > 0)
210 g_dbus_connection_signal_unsubscribe (proxy->priv->connection,
211 proxy->priv->name_owner_changed_subscription_id);
213 if (proxy->priv->properties_changed_subscription_id > 0)
214 g_dbus_connection_signal_unsubscribe (proxy->priv->connection,
215 proxy->priv->properties_changed_subscription_id);
217 if (proxy->priv->signals_subscription_id > 0)
218 g_dbus_connection_signal_unsubscribe (proxy->priv->connection,
219 proxy->priv->signals_subscription_id);
221 if (proxy->priv->connection != NULL)
222 g_object_unref (proxy->priv->connection);
223 g_free (proxy->priv->name);
224 g_free (proxy->priv->name_owner);
225 g_free (proxy->priv->object_path);
226 g_free (proxy->priv->interface_name);
227 if (proxy->priv->properties != NULL)
228 g_hash_table_unref (proxy->priv->properties);
230 if (proxy->priv->expected_interface != NULL)
232 g_dbus_interface_info_cache_release (proxy->priv->expected_interface);
233 g_dbus_interface_info_unref (proxy->priv->expected_interface);
236 if (proxy->priv->object != NULL)
237 g_object_remove_weak_pointer (G_OBJECT (proxy->priv->object), (gpointer *) &proxy->priv->object);
239 G_OBJECT_CLASS (g_dbus_proxy_parent_class)->finalize (object);
243 g_dbus_proxy_get_property (GObject *object,
248 GDBusProxy *proxy = G_DBUS_PROXY (object);
252 case PROP_G_CONNECTION:
253 g_value_set_object (value, proxy->priv->connection);
257 g_value_set_flags (value, proxy->priv->flags);
261 g_value_set_string (value, proxy->priv->name);
264 case PROP_G_NAME_OWNER:
265 g_value_set_string (value, proxy->priv->name_owner);
268 case PROP_G_OBJECT_PATH:
269 g_value_set_string (value, proxy->priv->object_path);
272 case PROP_G_INTERFACE_NAME:
273 g_value_set_string (value, proxy->priv->interface_name);
276 case PROP_G_DEFAULT_TIMEOUT:
277 g_value_set_int (value, proxy->priv->timeout_msec);
280 case PROP_G_INTERFACE_INFO:
281 g_value_set_boxed (value, g_dbus_proxy_get_interface_info (proxy));
285 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
291 g_dbus_proxy_set_property (GObject *object,
296 GDBusProxy *proxy = G_DBUS_PROXY (object);
300 case PROP_G_CONNECTION:
301 proxy->priv->connection = g_value_dup_object (value);
305 proxy->priv->flags = g_value_get_flags (value);
309 proxy->priv->name = g_value_dup_string (value);
312 case PROP_G_OBJECT_PATH:
313 proxy->priv->object_path = g_value_dup_string (value);
316 case PROP_G_INTERFACE_NAME:
317 proxy->priv->interface_name = g_value_dup_string (value);
320 case PROP_G_DEFAULT_TIMEOUT:
321 g_dbus_proxy_set_default_timeout (proxy, g_value_get_int (value));
324 case PROP_G_INTERFACE_INFO:
325 g_dbus_proxy_set_interface_info (proxy, g_value_get_boxed (value));
328 case PROP_G_BUS_TYPE:
329 proxy->priv->bus_type = g_value_get_enum (value);
333 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
339 g_dbus_proxy_class_init (GDBusProxyClass *klass)
341 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
343 gobject_class->dispose = g_dbus_proxy_dispose;
344 gobject_class->finalize = g_dbus_proxy_finalize;
345 gobject_class->set_property = g_dbus_proxy_set_property;
346 gobject_class->get_property = g_dbus_proxy_get_property;
348 /* Note that all property names are prefixed to avoid collisions with D-Bus property names
349 * in derived classes */
352 * GDBusProxy:g-interface-info:
354 * Ensure that interactions with this proxy conform to the given
355 * interface. For example, when completing a method call, if the
356 * type signature of the message isn't what's expected, the given
357 * #GError is set. Signals that have a type signature mismatch are
362 g_object_class_install_property (gobject_class,
363 PROP_G_INTERFACE_INFO,
364 g_param_spec_boxed ("g-interface-info",
365 P_("Interface Information"),
366 P_("Interface Information"),
367 G_TYPE_DBUS_INTERFACE_INFO,
370 G_PARAM_STATIC_NAME |
371 G_PARAM_STATIC_BLURB |
372 G_PARAM_STATIC_NICK));
375 * GDBusProxy:g-connection:
377 * The #GDBusConnection the proxy is for.
381 g_object_class_install_property (gobject_class,
383 g_param_spec_object ("g-connection",
385 P_("The connection the proxy is for"),
386 G_TYPE_DBUS_CONNECTION,
389 G_PARAM_CONSTRUCT_ONLY |
390 G_PARAM_STATIC_NAME |
391 G_PARAM_STATIC_BLURB |
392 G_PARAM_STATIC_NICK));
395 * GDBusProxy:g-bus-type:
397 * If this property is not %G_BUS_TYPE_NONE, then
398 * #GDBusProxy:g-connection must be %NULL and will be set to the
399 * #GDBusConnection obtained by calling g_bus_get() with the value
404 g_object_class_install_property (gobject_class,
406 g_param_spec_enum ("g-bus-type",
408 P_("The bus to connect to, if any"),
412 G_PARAM_CONSTRUCT_ONLY |
413 G_PARAM_STATIC_NAME |
414 G_PARAM_STATIC_BLURB |
415 G_PARAM_STATIC_NICK));
418 * GDBusProxy:g-flags:
420 * Flags from the #GDBusProxyFlags enumeration.
424 g_object_class_install_property (gobject_class,
426 g_param_spec_flags ("g-flags",
428 P_("Flags for the proxy"),
429 G_TYPE_DBUS_PROXY_FLAGS,
430 G_DBUS_PROXY_FLAGS_NONE,
433 G_PARAM_CONSTRUCT_ONLY |
434 G_PARAM_STATIC_NAME |
435 G_PARAM_STATIC_BLURB |
436 G_PARAM_STATIC_NICK));
441 * The well-known or unique name that the proxy is for.
445 g_object_class_install_property (gobject_class,
447 g_param_spec_string ("g-name",
449 P_("The well-known or unique name that the proxy is for"),
453 G_PARAM_CONSTRUCT_ONLY |
454 G_PARAM_STATIC_NAME |
455 G_PARAM_STATIC_BLURB |
456 G_PARAM_STATIC_NICK));
459 * GDBusProxy:g-name-owner:
461 * The unique name that owns #GDBusProxy:name or %NULL if no-one
462 * currently owns that name. You may connect to #GObject::notify signal to
463 * track changes to this property.
467 g_object_class_install_property (gobject_class,
469 g_param_spec_string ("g-name-owner",
471 P_("The unique name for the owner"),
474 G_PARAM_STATIC_NAME |
475 G_PARAM_STATIC_BLURB |
476 G_PARAM_STATIC_NICK));
479 * GDBusProxy:g-object-path:
481 * The object path the proxy is for.
485 g_object_class_install_property (gobject_class,
487 g_param_spec_string ("g-object-path",
489 P_("The object path the proxy is for"),
493 G_PARAM_CONSTRUCT_ONLY |
494 G_PARAM_STATIC_NAME |
495 G_PARAM_STATIC_BLURB |
496 G_PARAM_STATIC_NICK));
499 * GDBusProxy:g-interface-name:
501 * The D-Bus interface name the proxy is for.
505 g_object_class_install_property (gobject_class,
506 PROP_G_INTERFACE_NAME,
507 g_param_spec_string ("g-interface-name",
508 P_("g-interface-name"),
509 P_("The D-Bus interface name the proxy is for"),
513 G_PARAM_CONSTRUCT_ONLY |
514 G_PARAM_STATIC_NAME |
515 G_PARAM_STATIC_BLURB |
516 G_PARAM_STATIC_NICK));
519 * GDBusProxy:g-default-timeout:
521 * The timeout to use if -1 (specifying default timeout) is passed
522 * as @timeout_msec in the g_dbus_proxy_call() and
523 * g_dbus_proxy_call_sync() functions.
525 * This allows applications to set a proxy-wide timeout for all
526 * remote method invocations on the proxy. If this property is -1,
527 * the default timeout (typically 25 seconds) is used. If set to
528 * %G_MAXINT, then no timeout is used.
532 g_object_class_install_property (gobject_class,
533 PROP_G_DEFAULT_TIMEOUT,
534 g_param_spec_int ("g-default-timeout",
535 P_("Default Timeout"),
536 P_("Timeout for remote method invocation"),
543 G_PARAM_STATIC_NAME |
544 G_PARAM_STATIC_BLURB |
545 G_PARAM_STATIC_NICK));
548 * GDBusProxy::g-properties-changed:
549 * @proxy: The #GDBusProxy emitting the signal.
550 * @changed_properties: A #GVariant containing the properties that changed
551 * @invalidated_properties: A %NULL terminated array of properties that was invalidated
553 * Emitted when one or more D-Bus properties on @proxy changes. The
554 * local cache has already been updated when this signal fires. Note
555 * that both @changed_properties and @invalidated_properties are
556 * guaranteed to never be %NULL (either may be empty though).
558 * This signal corresponds to the
559 * <literal>PropertiesChanged</literal> D-Bus signal on the
560 * <literal>org.freedesktop.DBus.Properties</literal> interface.
564 signals[PROPERTIES_CHANGED_SIGNAL] = g_signal_new ("g-properties-changed",
566 G_SIGNAL_RUN_LAST | G_SIGNAL_MUST_COLLECT,
567 G_STRUCT_OFFSET (GDBusProxyClass, g_properties_changed),
570 _gio_marshal_VOID__VARIANT_BOXED,
574 G_TYPE_STRV | G_SIGNAL_TYPE_STATIC_SCOPE);
577 * GDBusProxy::g-signal:
578 * @proxy: The #GDBusProxy emitting the signal.
579 * @sender_name: The sender of the signal or %NULL if the connection is not a bus connection.
580 * @signal_name: The name of the signal.
581 * @parameters: A #GVariant tuple with parameters for the signal.
583 * Emitted when a signal from the remote object and interface that @proxy is for, has been received.
587 signals[SIGNAL_SIGNAL] = g_signal_new ("g-signal",
589 G_SIGNAL_RUN_LAST | G_SIGNAL_MUST_COLLECT,
590 G_STRUCT_OFFSET (GDBusProxyClass, g_signal),
593 _gio_marshal_VOID__STRING_STRING_VARIANT,
601 g_type_class_add_private (klass, sizeof (GDBusProxyPrivate));
605 g_dbus_proxy_init (GDBusProxy *proxy)
607 proxy->priv = G_TYPE_INSTANCE_GET_PRIVATE (proxy, G_TYPE_DBUS_PROXY, GDBusProxyPrivate);
608 proxy->priv->signal_subscription_data = g_slice_new0 (SignalSubscriptionData);
609 proxy->priv->signal_subscription_data->ref_count = 1;
610 proxy->priv->signal_subscription_data->proxy = proxy;
611 proxy->priv->properties = g_hash_table_new_full (g_str_hash,
614 (GDestroyNotify) g_variant_unref);
617 /* ---------------------------------------------------------------------------------------------------- */
620 property_name_sort_func (const gchar **a,
623 return g_strcmp0 (*a, *b);
627 * g_dbus_proxy_get_cached_property_names:
628 * @proxy: A #GDBusProxy.
630 * Gets the names of all cached properties on @proxy.
632 * Returns: A %NULL-terminated array of strings or %NULL if @proxy has
633 * no cached properties. Free the returned array with g_strfreev().
638 g_dbus_proxy_get_cached_property_names (GDBusProxy *proxy)
645 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
647 G_LOCK (properties_lock);
650 if (g_hash_table_size (proxy->priv->properties) == 0)
653 p = g_ptr_array_new ();
655 g_hash_table_iter_init (&iter, proxy->priv->properties);
656 while (g_hash_table_iter_next (&iter, (gpointer) &key, NULL))
657 g_ptr_array_add (p, g_strdup (key));
658 g_ptr_array_sort (p, (GCompareFunc) property_name_sort_func);
659 g_ptr_array_add (p, NULL);
661 names = (gchar **) g_ptr_array_free (p, FALSE);
664 G_UNLOCK (properties_lock);
668 static const GDBusPropertyInfo *
669 lookup_property_info_or_warn (GDBusProxy *proxy,
670 const gchar *property_name)
672 const GDBusPropertyInfo *info;
674 if (proxy->priv->expected_interface == NULL)
677 info = g_dbus_interface_info_lookup_property (proxy->priv->expected_interface, property_name);
680 g_warning ("Trying to lookup property %s which isn't in expected interface %s",
682 proxy->priv->expected_interface->name);
689 * g_dbus_proxy_get_cached_property:
690 * @proxy: A #GDBusProxy.
691 * @property_name: Property name.
693 * Looks up the value for a property from the cache. This call does no
696 * If @proxy has an expected interface (see
697 * #GDBusProxy:g-interface-info), then @property_name (for existence)
698 * is checked against it.
700 * Returns: A reference to the #GVariant instance that holds the value
701 * for @property_name or %NULL if the value is not in the cache. The
702 * returned reference must be freed with g_variant_unref().
707 g_dbus_proxy_get_cached_property (GDBusProxy *proxy,
708 const gchar *property_name)
712 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
713 g_return_val_if_fail (property_name != NULL, NULL);
715 G_LOCK (properties_lock);
717 value = g_hash_table_lookup (proxy->priv->properties, property_name);
720 lookup_property_info_or_warn (proxy, property_name);
725 g_variant_ref (value);
728 G_UNLOCK (properties_lock);
733 * g_dbus_proxy_set_cached_property:
734 * @proxy: A #GDBusProxy
735 * @property_name: Property name.
736 * @value: (allow-none): Value for the property or %NULL to remove it from the cache.
738 * If @value is not %NULL, sets the cached value for the property with
739 * name @property_name to the value in @value.
741 * If @value is %NULL, then the cached value is removed from the
744 * If @proxy has an expected interface (see
745 * #GDBusProxy:g-interface-info), then @property_name (for existence)
746 * and @value (for the type) is checked against it.
748 * If the @value #GVariant is floating, it is consumed. This allows
749 * convenient 'inline' use of g_variant_new(), e.g.
751 * g_dbus_proxy_set_cached_property (proxy,
753 * g_variant_new ("(si)",
758 * Normally you will not need to use this method since @proxy is
759 * tracking changes using the
760 * <literal>org.freedesktop.DBus.Properties.PropertiesChanged</literal>
761 * D-Bus signal. However, for performance reasons an object may decide
762 * to not use this signal for some properties and instead use a
763 * proprietary out-of-band mechanism to transmit changes.
765 * As a concrete example, consider an object with a property
766 * <literal>ChatroomParticipants</literal> which is an array of
767 * strings. Instead of transmitting the same (long) array every time
768 * the property changes, it is more efficient to only transmit the
769 * delta using e.g. signals <literal>ChatroomParticipantJoined(String
770 * name)</literal> and <literal>ChatroomParticipantParted(String
776 g_dbus_proxy_set_cached_property (GDBusProxy *proxy,
777 const gchar *property_name,
780 const GDBusPropertyInfo *info;
782 g_return_if_fail (G_IS_DBUS_PROXY (proxy));
783 g_return_if_fail (property_name != NULL);
785 G_LOCK (properties_lock);
789 info = lookup_property_info_or_warn (proxy, property_name);
792 if (g_strcmp0 (info->signature, g_variant_get_type_string (value)) != 0)
794 g_warning ("Trying to set property %s of type %s but according to the expected "
795 "interface the type is %s",
797 g_variant_get_type_string (value),
802 g_hash_table_insert (proxy->priv->properties,
803 g_strdup (property_name),
804 g_variant_ref_sink (value));
808 g_hash_table_remove (proxy->priv->properties, property_name);
812 G_UNLOCK (properties_lock);
815 /* ---------------------------------------------------------------------------------------------------- */
818 on_signal_received (GDBusConnection *connection,
819 const gchar *sender_name,
820 const gchar *object_path,
821 const gchar *interface_name,
822 const gchar *signal_name,
823 GVariant *parameters,
826 SignalSubscriptionData *data = user_data;
829 G_LOCK (signal_subscription_lock);
833 G_UNLOCK (signal_subscription_lock);
838 g_object_ref (proxy);
839 G_UNLOCK (signal_subscription_lock);
842 if (!proxy->priv->initialized)
845 if (proxy->priv->name_owner != NULL && g_strcmp0 (sender_name, proxy->priv->name_owner) != 0)
848 if (proxy->priv->expected_interface != NULL)
850 const GDBusSignalInfo *info;
851 GVariantType *expected_type;
852 info = g_dbus_interface_info_lookup_signal (proxy->priv->expected_interface, signal_name);
855 expected_type = _g_dbus_compute_complete_signature (info->args);
856 if (!g_variant_type_equal (expected_type, g_variant_get_type (parameters)))
858 g_variant_type_free (expected_type);
861 g_variant_type_free (expected_type);
864 g_signal_emit (proxy,
865 signals[SIGNAL_SIGNAL],
872 g_object_unref (proxy);
875 /* ---------------------------------------------------------------------------------------------------- */
877 /* must hold properties_lock */
879 insert_property_checked (GDBusProxy *proxy,
880 gchar *property_name,
883 if (proxy->priv->expected_interface != NULL)
885 const GDBusPropertyInfo *info;
887 info = g_dbus_interface_info_lookup_property (proxy->priv->expected_interface, property_name);
888 /* Ignore unknown properties */
892 /* Ignore properties with the wrong type */
893 if (g_strcmp0 (info->signature, g_variant_get_type_string (value)) != 0)
897 g_hash_table_insert (proxy->priv->properties,
898 property_name, /* adopts string */
899 value); /* adopts value */
904 g_variant_unref (value);
905 g_free (property_name);
909 on_properties_changed (GDBusConnection *connection,
910 const gchar *sender_name,
911 const gchar *object_path,
912 const gchar *interface_name,
913 const gchar *signal_name,
914 GVariant *parameters,
917 SignalSubscriptionData *data = user_data;
919 const gchar *interface_name_for_signal;
920 GVariant *changed_properties;
921 gchar **invalidated_properties;
927 G_LOCK (signal_subscription_lock);
931 G_UNLOCK (signal_subscription_lock);
936 g_object_ref (proxy);
937 G_UNLOCK (signal_subscription_lock);
940 changed_properties = NULL;
941 invalidated_properties = NULL;
943 if (!proxy->priv->initialized)
946 if (proxy->priv->name_owner != NULL && g_strcmp0 (sender_name, proxy->priv->name_owner) != 0)
949 if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(sa{sv}as)")))
951 g_warning ("Value for PropertiesChanged signal with type `%s' does not match `(sa{sv}as)'",
952 g_variant_get_type_string (parameters));
956 g_variant_get (parameters,
958 &interface_name_for_signal,
960 &invalidated_properties);
962 if (g_strcmp0 (interface_name_for_signal, proxy->priv->interface_name) != 0)
965 G_LOCK (properties_lock);
967 g_variant_iter_init (&iter, changed_properties);
968 while (g_variant_iter_next (&iter, "{sv}", &key, &value))
970 insert_property_checked (proxy,
971 key, /* adopts string */
972 value); /* adopts value */
975 for (n = 0; invalidated_properties[n] != NULL; n++)
977 g_hash_table_remove (proxy->priv->properties, invalidated_properties[n]);
980 G_UNLOCK (properties_lock);
983 g_signal_emit (proxy, signals[PROPERTIES_CHANGED_SIGNAL],
986 invalidated_properties);
989 if (changed_properties != NULL)
990 g_variant_unref (changed_properties);
991 g_free (invalidated_properties);
993 g_object_unref (proxy);
996 /* ---------------------------------------------------------------------------------------------------- */
999 process_get_all_reply (GDBusProxy *proxy,
1005 guint num_properties;
1007 if (!g_variant_is_of_type (result, G_VARIANT_TYPE ("(a{sv})")))
1009 g_warning ("Value for GetAll reply with type `%s' does not match `(a{sv})'",
1010 g_variant_get_type_string (result));
1014 G_LOCK (properties_lock);
1016 g_variant_get (result, "(a{sv})", &iter);
1017 while (g_variant_iter_next (iter, "{sv}", &key, &value))
1019 insert_property_checked (proxy,
1020 key, /* adopts string */
1021 value); /* adopts value */
1023 g_variant_iter_free (iter);
1025 num_properties = g_hash_table_size (proxy->priv->properties);
1026 G_UNLOCK (properties_lock);
1028 /* Synthesize ::g-properties-changed changed */
1029 if (num_properties > 0)
1031 GVariant *changed_properties;
1032 const gchar *invalidated_properties[1] = {NULL};
1034 g_variant_get (result,
1036 &changed_properties);
1037 g_signal_emit (proxy, signals[PROPERTIES_CHANGED_SIGNAL],
1040 invalidated_properties);
1041 g_variant_unref (changed_properties);
1051 GCancellable *cancellable;
1053 } LoadPropertiesOnNameOwnerChangedData;
1056 on_name_owner_changed_get_all_cb (GDBusConnection *connection,
1060 LoadPropertiesOnNameOwnerChangedData *data = user_data;
1068 result = g_dbus_connection_call_finish (connection,
1073 if (error->domain == G_IO_ERROR && error->code == G_IO_ERROR_CANCELLED)
1075 /* We just ignore if GetAll() is failing. Because this might happen
1076 * if the object has no properties at all. Or if the caller is
1077 * not authorized to see the properties.
1079 * Either way, apps can know about this by using
1080 * get_cached_property_names() or get_cached_property().
1082 * TODO: handle G_DBUS_DEBUG flag 'proxy' and, if enabled, log the
1083 * fact that GetAll() failed
1085 //g_debug ("error: %d %d %s", error->domain, error->code, error->message);
1086 g_error_free (error);
1089 /* and finally we can notify */
1092 g_free (data->proxy->priv->name_owner);
1093 data->proxy->priv->name_owner = data->name_owner;
1094 data->name_owner = NULL; /* to avoid an extra copy, we steal the string */
1096 G_LOCK (properties_lock);
1097 g_hash_table_remove_all (data->proxy->priv->properties);
1098 G_UNLOCK (properties_lock);
1101 process_get_all_reply (data->proxy, result);
1102 g_variant_unref (result);
1105 g_object_notify (G_OBJECT (data->proxy), "g-name-owner");
1108 if (data->cancellable == data->proxy->priv->get_all_cancellable)
1109 data->proxy->priv->get_all_cancellable = NULL;
1111 g_object_unref (data->proxy);
1112 g_object_unref (data->cancellable);
1113 g_free (data->name_owner);
1118 on_name_owner_changed (GDBusConnection *connection,
1119 const gchar *sender_name,
1120 const gchar *object_path,
1121 const gchar *interface_name,
1122 const gchar *signal_name,
1123 GVariant *parameters,
1126 SignalSubscriptionData *data = user_data;
1128 const gchar *old_owner;
1129 const gchar *new_owner;
1131 G_LOCK (signal_subscription_lock);
1132 proxy = data->proxy;
1135 G_UNLOCK (signal_subscription_lock);
1140 g_object_ref (proxy);
1141 G_UNLOCK (signal_subscription_lock);
1144 /* if we are already trying to load properties, cancel that */
1145 if (proxy->priv->get_all_cancellable != NULL)
1147 g_cancellable_cancel (proxy->priv->get_all_cancellable);
1148 proxy->priv->get_all_cancellable = NULL;
1151 g_variant_get (parameters,
1157 if (strlen (new_owner) == 0)
1159 g_free (proxy->priv->name_owner);
1160 proxy->priv->name_owner = NULL;
1162 G_LOCK (properties_lock);
1164 /* Synthesize ::g-properties-changed changed */
1165 if (!(proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES) &&
1166 g_hash_table_size (proxy->priv->properties) > 0)
1168 GVariantBuilder builder;
1169 GPtrArray *invalidated_properties;
1170 GHashTableIter iter;
1173 /* Build changed_properties (always empty) and invalidated_properties ... */
1174 g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
1176 invalidated_properties = g_ptr_array_new_with_free_func (g_free);
1177 g_hash_table_iter_init (&iter, proxy->priv->properties);
1178 while (g_hash_table_iter_next (&iter, (gpointer) &key, NULL))
1179 g_ptr_array_add (invalidated_properties, g_strdup (key));
1180 g_ptr_array_add (invalidated_properties, NULL);
1182 /* ... throw out the properties ... */
1183 g_hash_table_remove_all (proxy->priv->properties);
1185 G_UNLOCK (properties_lock);
1187 /* ... and finally emit the ::g-properties-changed signal */
1188 g_signal_emit (proxy, signals[PROPERTIES_CHANGED_SIGNAL],
1190 g_variant_builder_end (&builder) /* consumed */,
1191 (const gchar* const *) invalidated_properties->pdata);
1192 g_ptr_array_unref (invalidated_properties);
1196 G_UNLOCK (properties_lock);
1198 g_object_notify (G_OBJECT (proxy), "g-name-owner");
1202 /* ignore duplicates - this can happen when activating the service */
1203 if (g_strcmp0 (new_owner, proxy->priv->name_owner) == 0)
1206 if (proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES)
1208 g_free (proxy->priv->name_owner);
1209 proxy->priv->name_owner = g_strdup (new_owner);
1210 G_LOCK (properties_lock);
1211 g_hash_table_remove_all (proxy->priv->properties);
1212 G_UNLOCK (properties_lock);
1213 g_object_notify (G_OBJECT (proxy), "g-name-owner");
1217 LoadPropertiesOnNameOwnerChangedData *data;
1219 /* start loading properties.. only then emit notify::g-name-owner .. we
1220 * need to be able to cancel this in the event another NameOwnerChanged
1221 * signal suddenly happens
1224 g_assert (proxy->priv->get_all_cancellable == NULL);
1225 proxy->priv->get_all_cancellable = g_cancellable_new ();
1226 data = g_new0 (LoadPropertiesOnNameOwnerChangedData, 1);
1227 data->proxy = g_object_ref (proxy);
1228 data->cancellable = proxy->priv->get_all_cancellable;
1229 data->name_owner = g_strdup (new_owner);
1230 g_dbus_connection_call (proxy->priv->connection,
1232 proxy->priv->object_path,
1233 "org.freedesktop.DBus.Properties",
1235 g_variant_new ("(s)", proxy->priv->interface_name),
1236 G_VARIANT_TYPE ("(a{sv})"),
1237 G_DBUS_CALL_FLAGS_NONE,
1239 proxy->priv->get_all_cancellable,
1240 (GAsyncReadyCallback) on_name_owner_changed_get_all_cb,
1247 g_object_unref (proxy);
1250 /* ---------------------------------------------------------------------------------------------------- */
1255 GCancellable *cancellable;
1256 GSimpleAsyncResult *simple;
1260 async_init_data_free (AsyncInitData *data)
1262 g_object_unref (data->proxy);
1263 if (data->cancellable != NULL)
1264 g_object_unref (data->cancellable);
1265 g_object_unref (data->simple);
1270 async_init_get_all_cb (GDBusConnection *connection,
1274 AsyncInitData *data = user_data;
1279 result = g_dbus_connection_call_finish (connection,
1284 /* We just ignore if GetAll() is failing. Because this might happen
1285 * if the object has no properties at all. Or if the caller is
1286 * not authorized to see the properties.
1288 * Either way, apps can know about this by using
1289 * get_cached_property_names() or get_cached_property().
1291 * TODO: handle G_DBUS_DEBUG flag 'proxy' and, if enabled, log the
1292 * fact that GetAll() failed
1294 //g_debug ("error: %d %d %s", error->domain, error->code, error->message);
1295 g_error_free (error);
1299 g_simple_async_result_set_op_res_gpointer (data->simple,
1301 (GDestroyNotify) g_variant_unref);
1304 g_simple_async_result_complete_in_idle (data->simple);
1305 async_init_data_free (data);
1310 async_init_get_name_owner_cb (GDBusConnection *connection,
1314 AsyncInitData *data = user_data;
1322 result = g_dbus_connection_call_finish (connection,
1327 if (error->domain == G_DBUS_ERROR &&
1328 error->code == G_DBUS_ERROR_NAME_HAS_NO_OWNER)
1330 g_error_free (error);
1334 g_simple_async_result_take_error (data->simple, error);
1335 g_simple_async_result_complete_in_idle (data->simple);
1336 async_init_data_free (data);
1342 g_variant_get (result,
1344 &data->proxy->priv->name_owner);
1345 g_variant_unref (result);
1349 if (!(data->proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES))
1351 /* load all properties asynchronously */
1352 g_dbus_connection_call (data->proxy->priv->connection,
1353 data->proxy->priv->name_owner,
1354 data->proxy->priv->object_path,
1355 "org.freedesktop.DBus.Properties",
1357 g_variant_new ("(s)", data->proxy->priv->interface_name),
1358 G_VARIANT_TYPE ("(a{sv})"),
1359 G_DBUS_CALL_FLAGS_NONE,
1362 (GAsyncReadyCallback) async_init_get_all_cb,
1367 g_simple_async_result_complete_in_idle (data->simple);
1368 async_init_data_free (data);
1376 async_init_call_get_name_owner (AsyncInitData *data)
1378 g_dbus_connection_call (data->proxy->priv->connection,
1379 "org.freedesktop.DBus", /* name */
1380 "/org/freedesktop/DBus", /* object path */
1381 "org.freedesktop.DBus", /* interface */
1383 g_variant_new ("(s)",
1384 data->proxy->priv->name),
1385 G_VARIANT_TYPE ("(s)"),
1386 G_DBUS_CALL_FLAGS_NONE,
1389 (GAsyncReadyCallback) async_init_get_name_owner_cb,
1394 async_init_start_service_by_name_cb (GDBusConnection *connection,
1398 AsyncInitData *data = user_data;
1403 result = g_dbus_connection_call_finish (connection,
1408 /* Errors are not unexpected; the bus will reply e.g.
1410 * org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.Epiphany2
1411 * was not provided by any .service files
1413 * This doesn't mean that the name doesn't have an owner, just
1414 * that it's not provided by a .service file. So just proceed to
1415 * invoke GetNameOwner() if dealing with that error.
1417 if (error->domain == G_DBUS_ERROR &&
1418 error->code == G_DBUS_ERROR_SERVICE_UNKNOWN)
1420 g_error_free (error);
1424 g_prefix_error (&error,
1425 _("Error calling StartServiceByName for %s: "),
1426 data->proxy->priv->name);
1432 guint32 start_service_result;
1433 g_variant_get (result,
1435 &start_service_result);
1436 g_variant_unref (result);
1437 if (start_service_result == 1 || /* DBUS_START_REPLY_SUCCESS */
1438 start_service_result == 2) /* DBUS_START_REPLY_ALREADY_RUNNING */
1440 /* continue to invoke GetNameOwner() */
1444 error = g_error_new (G_IO_ERROR,
1446 _("Unexpected reply %d from StartServiceByName(\"%s\") method"),
1447 start_service_result,
1448 data->proxy->priv->name);
1453 async_init_call_get_name_owner (data);
1457 g_warn_if_fail (error != NULL);
1458 g_simple_async_result_take_error (data->simple, error);
1459 g_simple_async_result_complete_in_idle (data->simple);
1460 async_init_data_free (data);
1464 async_init_call_start_service_by_name (AsyncInitData *data)
1466 g_dbus_connection_call (data->proxy->priv->connection,
1467 "org.freedesktop.DBus", /* name */
1468 "/org/freedesktop/DBus", /* object path */
1469 "org.freedesktop.DBus", /* interface */
1470 "StartServiceByName",
1471 g_variant_new ("(su)",
1472 data->proxy->priv->name,
1474 G_VARIANT_TYPE ("(u)"),
1475 G_DBUS_CALL_FLAGS_NONE,
1478 (GAsyncReadyCallback) async_init_start_service_by_name_cb,
1483 async_initable_init_second_async (GAsyncInitable *initable,
1485 GCancellable *cancellable,
1486 GAsyncReadyCallback callback,
1489 GDBusProxy *proxy = G_DBUS_PROXY (initable);
1490 AsyncInitData *data;
1492 data = g_new0 (AsyncInitData, 1);
1493 data->proxy = g_object_ref (proxy);
1494 data->cancellable = cancellable != NULL ? g_object_ref (cancellable) : NULL;
1495 data->simple = g_simple_async_result_new (G_OBJECT (proxy),
1500 /* Check name ownership asynchronously - possibly also start the service */
1501 if (proxy->priv->name == NULL)
1504 async_init_get_name_owner_cb (proxy->priv->connection, NULL, data);
1506 else if (g_dbus_is_unique_name (proxy->priv->name))
1508 proxy->priv->name_owner = g_strdup (proxy->priv->name);
1509 async_init_get_name_owner_cb (proxy->priv->connection, NULL, data);
1513 if (proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START)
1515 async_init_call_get_name_owner (data);
1519 async_init_call_start_service_by_name (data);
1525 async_initable_init_second_finish (GAsyncInitable *initable,
1529 GDBusProxy *proxy = G_DBUS_PROXY (initable);
1530 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
1536 if (g_simple_async_result_propagate_error (simple, error))
1539 result = g_simple_async_result_get_op_res_gpointer (simple);
1542 process_get_all_reply (proxy, result);
1548 proxy->priv->initialized = TRUE;
1552 /* ---------------------------------------------------------------------------------------------------- */
1555 async_initable_init_first (GAsyncInitable *initable)
1557 GDBusProxy *proxy = G_DBUS_PROXY (initable);
1559 if (!(proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES))
1561 /* subscribe to PropertiesChanged() */
1562 proxy->priv->properties_changed_subscription_id =
1563 g_dbus_connection_signal_subscribe (proxy->priv->connection,
1565 "org.freedesktop.DBus.Properties",
1566 "PropertiesChanged",
1567 proxy->priv->object_path,
1568 proxy->priv->interface_name,
1569 G_DBUS_SIGNAL_FLAGS_NONE,
1570 on_properties_changed,
1571 signal_subscription_ref (proxy->priv->signal_subscription_data),
1572 (GDestroyNotify) signal_subscription_unref);
1575 if (!(proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS))
1577 /* subscribe to all signals for the object */
1578 proxy->priv->signals_subscription_id =
1579 g_dbus_connection_signal_subscribe (proxy->priv->connection,
1581 proxy->priv->interface_name,
1583 proxy->priv->object_path,
1585 G_DBUS_SIGNAL_FLAGS_NONE,
1587 signal_subscription_ref (proxy->priv->signal_subscription_data),
1588 (GDestroyNotify) signal_subscription_unref);
1591 if (proxy->priv->name != NULL && !g_dbus_is_unique_name (proxy->priv->name))
1593 proxy->priv->name_owner_changed_subscription_id =
1594 g_dbus_connection_signal_subscribe (proxy->priv->connection,
1595 "org.freedesktop.DBus", /* name */
1596 "org.freedesktop.DBus", /* interface */
1597 "NameOwnerChanged", /* signal name */
1598 "/org/freedesktop/DBus", /* path */
1599 proxy->priv->name, /* arg0 */
1600 G_DBUS_SIGNAL_FLAGS_NONE,
1601 on_name_owner_changed,
1602 signal_subscription_ref (proxy->priv->signal_subscription_data),
1603 (GDestroyNotify) signal_subscription_unref);
1607 /* ---------------------------------------------------------------------------------------------------- */
1609 /* initialization is split into two parts - the first is the
1610 * non-blocing part that requires the callers GMainContext - the
1611 * second is a blocking part async part that doesn't require the
1612 * callers GMainContext.. we do this split so the code can be reused
1613 * in the GInitable implementation below.
1615 * Note that obtaining a GDBusConnection is not shared between the two
1623 GCancellable *cancellable;
1624 GAsyncReadyCallback callback;
1626 } GetConnectionData;
1629 get_connection_cb (GObject *source_object,
1633 GetConnectionData *data = user_data;
1637 data->proxy->priv->connection = g_bus_get_finish (res, &error);
1638 if (data->proxy->priv->connection == NULL)
1640 GSimpleAsyncResult *simple;
1641 simple = g_simple_async_result_new (G_OBJECT (data->proxy),
1645 g_simple_async_result_take_error (simple, error);
1646 g_simple_async_result_complete_in_idle (simple);
1647 g_object_unref (simple);
1651 async_initable_init_first (G_ASYNC_INITABLE (data->proxy));
1652 async_initable_init_second_async (G_ASYNC_INITABLE (data->proxy),
1659 if (data->cancellable != NULL)
1660 g_object_unref (data->cancellable);
1662 g_object_unref (data->proxy);
1667 async_initable_init_async (GAsyncInitable *initable,
1669 GCancellable *cancellable,
1670 GAsyncReadyCallback callback,
1673 GDBusProxy *proxy = G_DBUS_PROXY (initable);
1675 if (proxy->priv->bus_type != G_BUS_TYPE_NONE)
1677 GetConnectionData *data;
1679 g_assert (proxy->priv->connection == NULL);
1681 data = g_new0 (GetConnectionData, 1);
1682 data->proxy = g_object_ref (proxy);
1683 data->io_priority = io_priority;
1684 data->cancellable = cancellable != NULL ? g_object_ref (cancellable) : NULL;
1685 data->callback = callback;
1686 data->user_data = user_data;
1687 g_bus_get (proxy->priv->bus_type,
1694 async_initable_init_first (initable);
1695 async_initable_init_second_async (initable, io_priority, cancellable, callback, user_data);
1700 async_initable_init_finish (GAsyncInitable *initable,
1704 return async_initable_init_second_finish (initable, res, error);
1708 async_initable_iface_init (GAsyncInitableIface *async_initable_iface)
1710 async_initable_iface->init_async = async_initable_init_async;
1711 async_initable_iface->init_finish = async_initable_init_finish;
1714 /* ---------------------------------------------------------------------------------------------------- */
1718 GMainContext *context;
1721 } InitableAsyncInitableData;
1724 async_initable_init_async_cb (GObject *source_object,
1728 InitableAsyncInitableData *data = user_data;
1729 data->res = g_object_ref (res);
1730 g_main_loop_quit (data->loop);
1733 /* Simply reuse the GAsyncInitable implementation but run the first
1734 * part (that is non-blocking and requires the callers GMainContext)
1735 * with the callers GMainContext.. and the second with a private
1736 * GMainContext (bug 621310 is slightly related).
1738 * Note that obtaining a GDBusConnection is not shared between the two
1742 initable_init (GInitable *initable,
1743 GCancellable *cancellable,
1746 GDBusProxy *proxy = G_DBUS_PROXY (initable);
1747 InitableAsyncInitableData *data;
1752 if (proxy->priv->bus_type != G_BUS_TYPE_NONE)
1754 g_assert (proxy->priv->connection == NULL);
1755 proxy->priv->connection = g_bus_get_sync (proxy->priv->bus_type,
1758 if (proxy->priv->connection == NULL)
1762 async_initable_init_first (G_ASYNC_INITABLE (initable));
1764 data = g_new0 (InitableAsyncInitableData, 1);
1765 data->context = g_main_context_new ();
1766 data->loop = g_main_loop_new (data->context, FALSE);
1768 g_main_context_push_thread_default (data->context);
1770 async_initable_init_second_async (G_ASYNC_INITABLE (initable),
1773 async_initable_init_async_cb,
1776 g_main_loop_run (data->loop);
1778 ret = async_initable_init_second_finish (G_ASYNC_INITABLE (initable),
1782 g_main_context_pop_thread_default (data->context);
1784 g_main_context_unref (data->context);
1785 g_main_loop_unref (data->loop);
1786 g_object_unref (data->res);
1795 initable_iface_init (GInitableIface *initable_iface)
1797 initable_iface->init = initable_init;
1800 /* ---------------------------------------------------------------------------------------------------- */
1804 * @connection: A #GDBusConnection.
1805 * @flags: Flags used when constructing the proxy.
1806 * @info: (allow-none): A #GDBusInterfaceInfo specifying the minimal interface that @proxy conforms to or %NULL.
1807 * @name: (allow-none): A bus name (well-known or unique) or %NULL if @connection is not a message bus connection.
1808 * @object_path: An object path.
1809 * @interface_name: A D-Bus interface name.
1810 * @cancellable: A #GCancellable or %NULL.
1811 * @callback: Callback function to invoke when the proxy is ready.
1812 * @user_data: User data to pass to @callback.
1814 * Creates a proxy for accessing @interface_name on the remote object
1815 * at @object_path owned by @name at @connection and asynchronously
1816 * loads D-Bus properties unless the
1817 * %G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES flag is used. Connect to
1818 * the #GDBusProxy::g-properties-changed signal to get notified about
1821 * If the %G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS flag is not set, also sets up
1822 * match rules for signals. Connect to the #GDBusProxy::g-signal signal
1823 * to handle signals from the remote object.
1825 * If @name is a well-known name and the
1826 * %G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START flag isn't set and no name
1827 * owner currently exists, the message bus will be requested to launch
1828 * a name owner for the name.
1830 * This is a failable asynchronous constructor - when the proxy is
1831 * ready, @callback will be invoked and you can use
1832 * g_dbus_proxy_new_finish() to get the result.
1834 * See g_dbus_proxy_new_sync() and for a synchronous version of this constructor.
1836 * See <xref linkend="gdbus-wellknown-proxy"/> for an example of how #GDBusProxy can be used.
1841 g_dbus_proxy_new (GDBusConnection *connection,
1842 GDBusProxyFlags flags,
1843 GDBusInterfaceInfo *info,
1845 const gchar *object_path,
1846 const gchar *interface_name,
1847 GCancellable *cancellable,
1848 GAsyncReadyCallback callback,
1851 g_return_if_fail (G_IS_DBUS_CONNECTION (connection));
1852 g_return_if_fail ((name == NULL && g_dbus_connection_get_unique_name (connection) == NULL) || g_dbus_is_name (name));
1853 g_return_if_fail (g_variant_is_object_path (object_path));
1854 g_return_if_fail (g_dbus_is_interface_name (interface_name));
1856 g_async_initable_new_async (G_TYPE_DBUS_PROXY,
1862 "g-interface-info", info,
1864 "g-connection", connection,
1865 "g-object-path", object_path,
1866 "g-interface-name", interface_name,
1871 * g_dbus_proxy_new_finish:
1872 * @res: A #GAsyncResult obtained from the #GAsyncReadyCallback function passed to g_dbus_proxy_new().
1873 * @error: Return location for error or %NULL.
1875 * Finishes creating a #GDBusProxy.
1877 * Returns: A #GDBusProxy or %NULL if @error is set. Free with g_object_unref().
1882 g_dbus_proxy_new_finish (GAsyncResult *res,
1886 GObject *source_object;
1888 source_object = g_async_result_get_source_object (res);
1889 g_assert (source_object != NULL);
1891 object = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object),
1894 g_object_unref (source_object);
1897 return G_DBUS_PROXY (object);
1903 * g_dbus_proxy_new_sync:
1904 * @connection: A #GDBusConnection.
1905 * @flags: Flags used when constructing the proxy.
1906 * @info: (allow-none): A #GDBusInterfaceInfo specifying the minimal interface that @proxy conforms to or %NULL.
1907 * @name: (allow-none): A bus name (well-known or unique) or %NULL if @connection is not a message bus connection.
1908 * @object_path: An object path.
1909 * @interface_name: A D-Bus interface name.
1910 * @cancellable: (allow-none): A #GCancellable or %NULL.
1911 * @error: (allow-none): Return location for error or %NULL.
1913 * Creates a proxy for accessing @interface_name on the remote object
1914 * at @object_path owned by @name at @connection and synchronously
1915 * loads D-Bus properties unless the
1916 * %G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES flag is used.
1918 * If the %G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS flag is not set, also sets up
1919 * match rules for signals. Connect to the #GDBusProxy::g-signal signal
1920 * to handle signals from the remote object.
1922 * If @name is a well-known name and the
1923 * %G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START flag isn't set and no name
1924 * owner currently exists, the message bus will be requested to launch
1925 * a name owner for the name.
1927 * This is a synchronous failable constructor. See g_dbus_proxy_new()
1928 * and g_dbus_proxy_new_finish() for the asynchronous version.
1930 * See <xref linkend="gdbus-wellknown-proxy"/> for an example of how #GDBusProxy can be used.
1932 * Returns: A #GDBusProxy or %NULL if error is set. Free with g_object_unref().
1937 g_dbus_proxy_new_sync (GDBusConnection *connection,
1938 GDBusProxyFlags flags,
1939 GDBusInterfaceInfo *info,
1941 const gchar *object_path,
1942 const gchar *interface_name,
1943 GCancellable *cancellable,
1946 GInitable *initable;
1948 g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);
1949 g_return_val_if_fail ((name == NULL && g_dbus_connection_get_unique_name (connection) == NULL) ||
1950 g_dbus_is_name (name), NULL);
1951 g_return_val_if_fail (g_variant_is_object_path (object_path), NULL);
1952 g_return_val_if_fail (g_dbus_is_interface_name (interface_name), NULL);
1954 initable = g_initable_new (G_TYPE_DBUS_PROXY,
1958 "g-interface-info", info,
1960 "g-connection", connection,
1961 "g-object-path", object_path,
1962 "g-interface-name", interface_name,
1964 if (initable != NULL)
1965 return G_DBUS_PROXY (initable);
1970 /* ---------------------------------------------------------------------------------------------------- */
1973 * g_dbus_proxy_new_for_bus:
1974 * @bus_type: A #GBusType.
1975 * @flags: Flags used when constructing the proxy.
1976 * @info: (allow-none): A #GDBusInterfaceInfo specifying the minimal interface that @proxy conforms to or %NULL.
1977 * @name: A bus name (well-known or unique).
1978 * @object_path: An object path.
1979 * @interface_name: A D-Bus interface name.
1980 * @cancellable: A #GCancellable or %NULL.
1981 * @callback: Callback function to invoke when the proxy is ready.
1982 * @user_data: User data to pass to @callback.
1984 * Like g_dbus_proxy_new() but takes a #GBusType instead of a #GDBusConnection.
1986 * See <xref linkend="gdbus-wellknown-proxy"/> for an example of how #GDBusProxy can be used.
1991 g_dbus_proxy_new_for_bus (GBusType bus_type,
1992 GDBusProxyFlags flags,
1993 GDBusInterfaceInfo *info,
1995 const gchar *object_path,
1996 const gchar *interface_name,
1997 GCancellable *cancellable,
1998 GAsyncReadyCallback callback,
2001 g_return_if_fail (g_dbus_is_name (name));
2002 g_return_if_fail (g_variant_is_object_path (object_path));
2003 g_return_if_fail (g_dbus_is_interface_name (interface_name));
2005 g_async_initable_new_async (G_TYPE_DBUS_PROXY,
2011 "g-interface-info", info,
2013 "g-bus-type", bus_type,
2014 "g-object-path", object_path,
2015 "g-interface-name", interface_name,
2020 * g_dbus_proxy_new_for_bus_finish:
2021 * @res: A #GAsyncResult obtained from the #GAsyncReadyCallback function passed to g_dbus_proxy_new_for_bus().
2022 * @error: Return location for error or %NULL.
2024 * Finishes creating a #GDBusProxy.
2026 * Returns: A #GDBusProxy or %NULL if @error is set. Free with g_object_unref().
2031 g_dbus_proxy_new_for_bus_finish (GAsyncResult *res,
2034 return g_dbus_proxy_new_finish (res, error);
2038 * g_dbus_proxy_new_for_bus_sync:
2039 * @bus_type: A #GBusType.
2040 * @flags: Flags used when constructing the proxy.
2041 * @info: (allow-none): A #GDBusInterfaceInfo specifying the minimal interface
2042 * that @proxy conforms to or %NULL.
2043 * @name: A bus name (well-known or unique).
2044 * @object_path: An object path.
2045 * @interface_name: A D-Bus interface name.
2046 * @cancellable: A #GCancellable or %NULL.
2047 * @error: Return location for error or %NULL.
2049 * Like g_dbus_proxy_new_sync() but takes a #GBusType instead of a #GDBusConnection.
2051 * See <xref linkend="gdbus-wellknown-proxy"/> for an example of how #GDBusProxy can be used.
2053 * Returns: A #GDBusProxy or %NULL if error is set. Free with g_object_unref().
2058 g_dbus_proxy_new_for_bus_sync (GBusType bus_type,
2059 GDBusProxyFlags flags,
2060 GDBusInterfaceInfo *info,
2062 const gchar *object_path,
2063 const gchar *interface_name,
2064 GCancellable *cancellable,
2067 GInitable *initable;
2069 g_return_val_if_fail (g_dbus_is_name (name), NULL);
2070 g_return_val_if_fail (g_variant_is_object_path (object_path), NULL);
2071 g_return_val_if_fail (g_dbus_is_interface_name (interface_name), NULL);
2073 initable = g_initable_new (G_TYPE_DBUS_PROXY,
2077 "g-interface-info", info,
2079 "g-bus-type", bus_type,
2080 "g-object-path", object_path,
2081 "g-interface-name", interface_name,
2083 if (initable != NULL)
2084 return G_DBUS_PROXY (initable);
2089 /* ---------------------------------------------------------------------------------------------------- */
2092 * g_dbus_proxy_get_connection:
2093 * @proxy: A #GDBusProxy.
2095 * Gets the connection @proxy is for.
2097 * Returns: (transfer none): A #GDBusConnection owned by @proxy. Do not free.
2102 g_dbus_proxy_get_connection (GDBusProxy *proxy)
2104 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
2105 return proxy->priv->connection;
2109 * g_dbus_proxy_get_flags:
2110 * @proxy: A #GDBusProxy.
2112 * Gets the flags that @proxy was constructed with.
2114 * Returns: Flags from the #GDBusProxyFlags enumeration.
2119 g_dbus_proxy_get_flags (GDBusProxy *proxy)
2121 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), 0);
2122 return proxy->priv->flags;
2126 * g_dbus_proxy_get_name:
2127 * @proxy: A #GDBusProxy.
2129 * Gets the name that @proxy was constructed for.
2131 * Returns: A string owned by @proxy. Do not free.
2136 g_dbus_proxy_get_name (GDBusProxy *proxy)
2138 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
2139 return proxy->priv->name;
2143 * g_dbus_proxy_get_name_owner:
2144 * @proxy: A #GDBusProxy.
2146 * The unique name that owns the name that @proxy is for or %NULL if
2147 * no-one currently owns that name. You may connect to the
2148 * #GObject::notify signal to track changes to the
2149 * #GDBusProxy:g-name-owner property.
2151 * Returns: The name owner or %NULL if no name owner exists. Free with g_free().
2156 g_dbus_proxy_get_name_owner (GDBusProxy *proxy)
2158 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
2159 return g_strdup (proxy->priv->name_owner);
2163 * g_dbus_proxy_get_object_path:
2164 * @proxy: A #GDBusProxy.
2166 * Gets the object path @proxy is for.
2168 * Returns: A string owned by @proxy. Do not free.
2173 g_dbus_proxy_get_object_path (GDBusProxy *proxy)
2175 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
2176 return proxy->priv->object_path;
2180 * g_dbus_proxy_get_interface_name:
2181 * @proxy: A #GDBusProxy.
2183 * Gets the D-Bus interface name @proxy is for.
2185 * Returns: A string owned by @proxy. Do not free.
2190 g_dbus_proxy_get_interface_name (GDBusProxy *proxy)
2192 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
2193 return proxy->priv->interface_name;
2197 * g_dbus_proxy_get_default_timeout:
2198 * @proxy: A #GDBusProxy.
2200 * Gets the timeout to use if -1 (specifying default timeout) is
2201 * passed as @timeout_msec in the g_dbus_proxy_call() and
2202 * g_dbus_proxy_call_sync() functions.
2204 * See the #GDBusProxy:g-default-timeout property for more details.
2206 * Returns: Timeout to use for @proxy.
2211 g_dbus_proxy_get_default_timeout (GDBusProxy *proxy)
2213 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), -1);
2214 return proxy->priv->timeout_msec;
2218 * g_dbus_proxy_set_default_timeout:
2219 * @proxy: A #GDBusProxy.
2220 * @timeout_msec: Timeout in milliseconds.
2222 * Sets the timeout to use if -1 (specifying default timeout) is
2223 * passed as @timeout_msec in the g_dbus_proxy_call() and
2224 * g_dbus_proxy_call_sync() functions.
2226 * See the #GDBusProxy:g-default-timeout property for more details.
2231 g_dbus_proxy_set_default_timeout (GDBusProxy *proxy,
2234 g_return_if_fail (G_IS_DBUS_PROXY (proxy));
2235 g_return_if_fail (timeout_msec == -1 || timeout_msec >= 0);
2237 /* TODO: locking? */
2238 if (proxy->priv->timeout_msec != timeout_msec)
2240 proxy->priv->timeout_msec = timeout_msec;
2241 g_object_notify (G_OBJECT (proxy), "g-default-timeout");
2246 * g_dbus_proxy_get_interface_info:
2247 * @proxy: A #GDBusProxy
2249 * Returns the #GDBusInterfaceInfo, if any, specifying the minimal
2250 * interface that @proxy conforms to.
2252 * See the #GDBusProxy:g-interface-info property for more details.
2254 * Returns: A #GDBusInterfaceInfo or %NULL. Do not unref the returned
2255 * object, it is owned by @proxy.
2259 GDBusInterfaceInfo *
2260 g_dbus_proxy_get_interface_info (GDBusProxy *proxy)
2262 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
2263 return proxy->priv->expected_interface;
2267 * g_dbus_proxy_set_interface_info:
2268 * @proxy: A #GDBusProxy
2269 * @info: (allow-none): Minimum interface this proxy conforms to or %NULL to unset.
2271 * Ensure that interactions with @proxy conform to the given
2272 * interface. For example, when completing a method call, if the type
2273 * signature of the message isn't what's expected, the given #GError
2274 * is set. Signals that have a type signature mismatch are simply
2277 * See the #GDBusProxy:g-interface-info property for more details.
2282 g_dbus_proxy_set_interface_info (GDBusProxy *proxy,
2283 GDBusInterfaceInfo *info)
2285 g_return_if_fail (G_IS_DBUS_PROXY (proxy));
2286 if (proxy->priv->expected_interface != NULL)
2288 g_dbus_interface_info_cache_release (proxy->priv->expected_interface);
2289 g_dbus_interface_info_unref (proxy->priv->expected_interface);
2291 proxy->priv->expected_interface = info != NULL ? g_dbus_interface_info_ref (info) : NULL;
2292 if (proxy->priv->expected_interface != NULL)
2293 g_dbus_interface_info_cache_build (proxy->priv->expected_interface);
2296 /* ---------------------------------------------------------------------------------------------------- */
2299 maybe_split_method_name (const gchar *method_name,
2300 gchar **out_interface_name,
2301 const gchar **out_method_name)
2306 g_assert (out_interface_name != NULL);
2307 g_assert (out_method_name != NULL);
2308 *out_interface_name = NULL;
2309 *out_method_name = NULL;
2311 if (strchr (method_name, '.') != NULL)
2316 p = g_strdup (method_name);
2317 last_dot = strrchr (p, '.');
2320 *out_interface_name = p;
2321 *out_method_name = last_dot + 1;
2331 reply_cb (GDBusConnection *connection,
2335 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data);
2340 value = g_dbus_connection_call_finish (connection,
2345 g_simple_async_result_take_error (simple, error);
2349 g_simple_async_result_set_op_res_gpointer (simple,
2351 (GDestroyNotify) g_variant_unref);
2354 /* no need to complete in idle since the method GDBusConnection already does */
2355 g_simple_async_result_complete (simple);
2356 g_object_unref (simple);
2359 static const GDBusMethodInfo *
2360 lookup_method_info_or_warn (GDBusProxy *proxy,
2361 const gchar *method_name)
2363 const GDBusMethodInfo *info;
2365 if (proxy->priv->expected_interface == NULL)
2368 info = g_dbus_interface_info_lookup_method (proxy->priv->expected_interface, method_name);
2371 g_warning ("Trying to invoke method %s which isn't in expected interface %s",
2372 method_name, proxy->priv->expected_interface->name);
2378 static const gchar *
2379 get_destination_for_call (GDBusProxy *proxy)
2385 /* If proxy->priv->name is a unique name, then proxy->priv->name_owner
2386 * is never NULL and always the same as proxy->priv->name. We use this
2387 * knowledge to avoid checking if proxy->priv->name is a unique or
2390 ret = proxy->priv->name_owner;
2394 if (proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START)
2397 ret = proxy->priv->name;
2404 * g_dbus_proxy_call:
2405 * @proxy: A #GDBusProxy.
2406 * @method_name: Name of method to invoke.
2407 * @parameters: (allow-none): A #GVariant tuple with parameters for the signal or %NULL if not passing parameters.
2408 * @flags: Flags from the #GDBusCallFlags enumeration.
2409 * @timeout_msec: The timeout in milliseconds (with %G_MAXINT meaning
2410 * "infinite") or -1 to use the proxy default timeout.
2411 * @cancellable: A #GCancellable or %NULL.
2412 * @callback: A #GAsyncReadyCallback to call when the request is satisfied or %NULL if you don't
2413 * care about the result of the method invocation.
2414 * @user_data: The data to pass to @callback.
2416 * Asynchronously invokes the @method_name method on @proxy.
2418 * If @method_name contains any dots, then @name is split into interface and
2419 * method name parts. This allows using @proxy for invoking methods on
2422 * If the #GDBusConnection associated with @proxy is closed then
2423 * the operation will fail with %G_IO_ERROR_CLOSED. If
2424 * @cancellable is canceled, the operation will fail with
2425 * %G_IO_ERROR_CANCELLED. If @parameters contains a value not
2426 * compatible with the D-Bus protocol, the operation fails with
2427 * %G_IO_ERROR_INVALID_ARGUMENT.
2429 * If the @parameters #GVariant is floating, it is consumed. This allows
2430 * convenient 'inline' use of g_variant_new(), e.g.:
2432 * g_dbus_proxy_call (proxy,
2434 * g_variant_new ("(ss)",
2437 * G_DBUS_CALL_FLAGS_NONE,
2440 * (GAsyncReadyCallback) two_strings_done,
2444 * This is an asynchronous method. When the operation is finished,
2445 * @callback will be invoked in the
2446 * <link linkend="g-main-context-push-thread-default">thread-default main loop</link>
2447 * of the thread you are calling this method from.
2448 * You can then call g_dbus_proxy_call_finish() to get the result of
2449 * the operation. See g_dbus_proxy_call_sync() for the synchronous
2450 * version of this method.
2455 g_dbus_proxy_call (GDBusProxy *proxy,
2456 const gchar *method_name,
2457 GVariant *parameters,
2458 GDBusCallFlags flags,
2460 GCancellable *cancellable,
2461 GAsyncReadyCallback callback,
2464 GSimpleAsyncResult *simple;
2466 gchar *split_interface_name;
2467 const gchar *split_method_name;
2468 const gchar *target_method_name;
2469 const gchar *target_interface_name;
2470 const gchar *destination;
2471 GVariantType *reply_type;
2473 g_return_if_fail (G_IS_DBUS_PROXY (proxy));
2474 g_return_if_fail (g_dbus_is_member_name (method_name) || g_dbus_is_interface_name (method_name));
2475 g_return_if_fail (parameters == NULL || g_variant_is_of_type (parameters, G_VARIANT_TYPE_TUPLE));
2476 g_return_if_fail (timeout_msec == -1 || timeout_msec >= 0);
2479 split_interface_name = NULL;
2481 simple = g_simple_async_result_new (G_OBJECT (proxy),
2486 was_split = maybe_split_method_name (method_name, &split_interface_name, &split_method_name);
2487 target_method_name = was_split ? split_method_name : method_name;
2488 target_interface_name = was_split ? split_interface_name : proxy->priv->interface_name;
2490 /* Warn if method is unexpected (cf. :g-interface-info) */
2493 const GDBusMethodInfo *expected_method_info;
2494 expected_method_info = lookup_method_info_or_warn (proxy, target_method_name);
2495 if (expected_method_info != NULL)
2496 reply_type = _g_dbus_compute_complete_signature (expected_method_info->out_args);
2500 if (proxy->priv->name != NULL)
2502 destination = get_destination_for_call (proxy);
2503 if (destination == NULL)
2505 g_simple_async_result_set_error (simple,
2508 _("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"));
2513 g_dbus_connection_call (proxy->priv->connection,
2515 proxy->priv->object_path,
2516 target_interface_name,
2521 timeout_msec == -1 ? proxy->priv->timeout_msec : timeout_msec,
2523 (GAsyncReadyCallback) reply_cb,
2527 if (reply_type != NULL)
2528 g_variant_type_free (reply_type);
2530 g_free (split_interface_name);
2534 * g_dbus_proxy_call_finish:
2535 * @proxy: A #GDBusProxy.
2536 * @res: A #GAsyncResult obtained from the #GAsyncReadyCallback passed to g_dbus_proxy_call().
2537 * @error: Return location for error or %NULL.
2539 * Finishes an operation started with g_dbus_proxy_call().
2541 * Returns: %NULL if @error is set. Otherwise a #GVariant tuple with
2542 * return values. Free with g_variant_unref().
2547 g_dbus_proxy_call_finish (GDBusProxy *proxy,
2551 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
2554 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
2555 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
2556 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
2558 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_dbus_proxy_call);
2562 if (g_simple_async_result_propagate_error (simple, error))
2565 value = g_variant_ref (g_simple_async_result_get_op_res_gpointer (simple));
2572 * g_dbus_proxy_call_sync:
2573 * @proxy: A #GDBusProxy.
2574 * @method_name: Name of method to invoke.
2575 * @parameters: (allow-none): A #GVariant tuple with parameters for the signal
2576 * or %NULL if not passing parameters.
2577 * @flags: Flags from the #GDBusCallFlags enumeration.
2578 * @timeout_msec: The timeout in milliseconds (with %G_MAXINT meaning
2579 * "infinite") or -1 to use the proxy default timeout.
2580 * @cancellable: A #GCancellable or %NULL.
2581 * @error: Return location for error or %NULL.
2583 * Synchronously invokes the @method_name method on @proxy.
2585 * If @method_name contains any dots, then @name is split into interface and
2586 * method name parts. This allows using @proxy for invoking methods on
2589 * If the #GDBusConnection associated with @proxy is disconnected then
2590 * the operation will fail with %G_IO_ERROR_CLOSED. If
2591 * @cancellable is canceled, the operation will fail with
2592 * %G_IO_ERROR_CANCELLED. If @parameters contains a value not
2593 * compatible with the D-Bus protocol, the operation fails with
2594 * %G_IO_ERROR_INVALID_ARGUMENT.
2596 * If the @parameters #GVariant is floating, it is consumed. This allows
2597 * convenient 'inline' use of g_variant_new(), e.g.:
2599 * g_dbus_proxy_call_sync (proxy,
2601 * g_variant_new ("(ss)",
2604 * G_DBUS_CALL_FLAGS_NONE,
2610 * The calling thread is blocked until a reply is received. See
2611 * g_dbus_proxy_call() for the asynchronous version of this
2614 * Returns: %NULL if @error is set. Otherwise a #GVariant tuple with
2615 * return values. Free with g_variant_unref().
2620 g_dbus_proxy_call_sync (GDBusProxy *proxy,
2621 const gchar *method_name,
2622 GVariant *parameters,
2623 GDBusCallFlags flags,
2625 GCancellable *cancellable,
2630 gchar *split_interface_name;
2631 const gchar *split_method_name;
2632 const gchar *target_method_name;
2633 const gchar *target_interface_name;
2634 const gchar *destination;
2635 GVariantType *reply_type;
2637 g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
2638 g_return_val_if_fail (g_dbus_is_member_name (method_name) || g_dbus_is_interface_name (method_name), NULL);
2639 g_return_val_if_fail (parameters == NULL || g_variant_is_of_type (parameters, G_VARIANT_TYPE_TUPLE), NULL);
2640 g_return_val_if_fail (timeout_msec == -1 || timeout_msec >= 0, NULL);
2641 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
2645 was_split = maybe_split_method_name (method_name, &split_interface_name, &split_method_name);
2646 target_method_name = was_split ? split_method_name : method_name;
2647 target_interface_name = was_split ? split_interface_name : proxy->priv->interface_name;
2649 /* Warn if method is unexpected (cf. :g-interface-info) */
2652 const GDBusMethodInfo *expected_method_info;
2653 expected_method_info = lookup_method_info_or_warn (proxy, target_method_name);
2654 if (expected_method_info != NULL)
2655 reply_type = _g_dbus_compute_complete_signature (expected_method_info->out_args);
2659 if (proxy->priv->name != NULL)
2661 destination = get_destination_for_call (proxy);
2662 if (destination == NULL)
2664 g_set_error_literal (error,
2667 _("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"));
2673 ret = g_dbus_connection_call_sync (proxy->priv->connection,
2675 proxy->priv->object_path,
2676 target_interface_name,
2681 timeout_msec == -1 ? proxy->priv->timeout_msec : timeout_msec,
2686 if (reply_type != NULL)
2687 g_variant_type_free (reply_type);
2689 g_free (split_interface_name);
2694 /* ---------------------------------------------------------------------------------------------------- */
2696 static GDBusInterfaceInfo *
2697 _g_dbus_proxy_get_info (GDBusInterface *interface)
2699 GDBusProxy *proxy = G_DBUS_PROXY (interface);
2700 return g_dbus_proxy_get_interface_info (proxy);
2703 static GDBusObject *
2704 _g_dbus_proxy_get_object (GDBusInterface *interface)
2706 GDBusProxy *proxy = G_DBUS_PROXY (interface);
2707 return proxy->priv->object;
2711 _g_dbus_proxy_set_object (GDBusInterface *interface,
2712 GDBusObject *object)
2714 GDBusProxy *proxy = G_DBUS_PROXY (interface);
2715 if (proxy->priv->object != NULL)
2716 g_object_remove_weak_pointer (G_OBJECT (proxy->priv->object), (gpointer *) &proxy->priv->object);
2717 proxy->priv->object = object;
2718 if (proxy->priv->object != NULL)
2719 g_object_add_weak_pointer (G_OBJECT (proxy->priv->object), (gpointer *) &proxy->priv->object);
2723 dbus_interface_iface_init (GDBusInterfaceIface *dbus_interface_iface)
2725 dbus_interface_iface->get_info = _g_dbus_proxy_get_info;
2726 dbus_interface_iface->get_object = _g_dbus_proxy_get_object;
2727 dbus_interface_iface->set_object = _g_dbus_proxy_set_object;
2730 /* ---------------------------------------------------------------------------------------------------- */