1 /* GDBus - GLib D-Bus Library
3 * Copyright (C) 2008-2010 Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 * Author: David Zeuthen <davidz@redhat.com>
23 #include "gdbusobjectmanager.h"
24 #include "gdbusobjectmanagerclient.h"
25 #include "gdbusobject.h"
26 #include "gdbusprivate.h"
27 #include "gioenumtypes.h"
28 #include "ginitable.h"
29 #include "gasyncresult.h"
30 #include "gsimpleasyncresult.h"
31 #include "gasyncinitable.h"
32 #include "gdbusconnection.h"
33 #include "gdbusutils.h"
34 #include "gdbusobject.h"
35 #include "gdbusobjectproxy.h"
36 #include "gdbusproxy.h"
37 #include "gdbusinterface.h"
42 * SECTION:gdbusobjectmanagerclient
43 * @short_description: Client-side object manager
46 * #GDBusObjectManagerClient is used to create, monitor and delete object
47 * proxies for remote objects exported by a #GDBusObjectManagerServer (or any
48 * code implementing the
49 * [org.freedesktop.DBus.ObjectManager](http://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-objectmanager)
52 * Once an instance of this type has been created, you can connect to
53 * the #GDBusObjectManager::object-added and
54 * #GDBusObjectManager::object-removed signals and inspect the
55 * #GDBusObjectProxy objects returned by
56 * g_dbus_object_manager_get_objects().
58 * If the name for a #GDBusObjectManagerClient is not owned by anyone at
59 * object construction time, the default behavior is to request the
60 * message bus to launch an owner for the name. This behavior can be
61 * disabled using the %G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_DO_NOT_AUTO_START
62 * flag. It's also worth noting that this only works if the name of
63 * interest is activatable in the first place. E.g. in some cases it
64 * is not possible to launch an owner for the requested name. In this
65 * case, #GDBusObjectManagerClient object construction still succeeds but
66 * there will be no object proxies
67 * (e.g. g_dbus_object_manager_get_objects() returns the empty list) and
68 * the #GDBusObjectManagerClient:name-owner property is %NULL.
70 * The owner of the requested name can come and go (for example
71 * consider a system service being restarted) – #GDBusObjectManagerClient
72 * handles this case too; simply connect to the #GObject::notify
73 * signal to watch for changes on the #GDBusObjectManagerClient:name-owner
74 * property. When the name owner vanishes, the behavior is that
75 * #GDBusObjectManagerClient:name-owner is set to %NULL (this includes
76 * emission of the #GObject::notify signal) and then
77 * #GDBusObjectManager::object-removed signals are synthesized
78 * for all currently existing object proxies. Since
79 * #GDBusObjectManagerClient:name-owner is %NULL when this happens, you can
80 * use this information to disambiguate a synthesized signal from a
81 * genuine signal caused by object removal on the remote
82 * #GDBusObjectManager. Similarly, when a new name owner appears,
83 * #GDBusObjectManager::object-added signals are synthesized
84 * while #GDBusObjectManagerClient:name-owner is still %NULL. Only when all
85 * object proxies have been added, the #GDBusObjectManagerClient:name-owner
86 * is set to the new name owner (this includes emission of the
87 * #GObject::notify signal). Furthermore, you are guaranteed that
88 * #GDBusObjectManagerClient:name-owner will alternate between a name owner
89 * (e.g. `:1.42`) and %NULL even in the case where
90 * the name of interest is atomically replaced
92 * Ultimately, #GDBusObjectManagerClient is used to obtain #GDBusProxy
93 * instances. All signals (including the
94 * org.freedesktop.DBus.Properties::PropertiesChanged signal)
95 * delivered to #GDBusProxy instances are guaranteed to originate
96 * from the name owner. This guarantee along with the behavior
97 * described above, means that certain race conditions including the
98 * "half the proxy is from the old owner and the other half is from
99 * the new owner" problem cannot happen.
101 * To avoid having the application connect to signals on the returned
102 * #GDBusObjectProxy and #GDBusProxy objects, the
103 * #GDBusObject::interface-added,
104 * #GDBusObject::interface-removed,
105 * #GDBusProxy::g-properties-changed and
106 * #GDBusProxy::g-signal signals
107 * are also emitted on the #GDBusObjectManagerClient instance managing these
108 * objects. The signals emitted are
109 * #GDBusObjectManager::interface-added,
110 * #GDBusObjectManager::interface-removed,
111 * #GDBusObjectManagerClient::interface-proxy-properties-changed and
112 * #GDBusObjectManagerClient::interface-proxy-signal.
114 * Note that all callbacks and signals are emitted in the
115 * [thread-default main context][g-main-context-push-thread-default]
116 * that the #GDBusObjectManagerClient object was constructed
117 * in. Additionally, the #GDBusObjectProxy and #GDBusProxy objects
118 * originating from the #GDBusObjectManagerClient object will be created in
119 * the same context and, consequently, will deliver signals in the
123 struct _GDBusObjectManagerClientPrivate
128 GDBusConnection *connection;
132 GDBusObjectManagerClientFlags flags;
134 GDBusProxy *control_proxy;
136 GHashTable *map_object_path_to_object_proxy;
138 guint signal_subscription_id;
141 GDBusProxyTypeFunc get_proxy_type_func;
142 gpointer get_proxy_type_user_data;
143 GDestroyNotify get_proxy_type_destroy_notify;
155 PROP_GET_PROXY_TYPE_FUNC,
156 PROP_GET_PROXY_TYPE_USER_DATA,
157 PROP_GET_PROXY_TYPE_DESTROY_NOTIFY
162 INTERFACE_PROXY_SIGNAL_SIGNAL,
163 INTERFACE_PROXY_PROPERTIES_CHANGED_SIGNAL,
167 static guint signals[LAST_SIGNAL] = { 0 };
169 static void initable_iface_init (GInitableIface *initable_iface);
170 static void async_initable_iface_init (GAsyncInitableIface *async_initable_iface);
171 static void dbus_object_manager_interface_init (GDBusObjectManagerIface *iface);
173 G_DEFINE_TYPE_WITH_CODE (GDBusObjectManagerClient, g_dbus_object_manager_client, G_TYPE_OBJECT,
174 G_ADD_PRIVATE (GDBusObjectManagerClient)
175 G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, initable_iface_init)
176 G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, async_initable_iface_init)
177 G_IMPLEMENT_INTERFACE (G_TYPE_DBUS_OBJECT_MANAGER, dbus_object_manager_interface_init));
179 static void maybe_unsubscribe_signals (GDBusObjectManagerClient *manager);
181 static void on_control_proxy_g_signal (GDBusProxy *proxy,
182 const gchar *sender_name,
183 const gchar *signal_name,
184 GVariant *parameters,
187 static void process_get_all_result (GDBusObjectManagerClient *manager,
189 const gchar *name_owner);
192 g_dbus_object_manager_client_finalize (GObject *object)
194 GDBusObjectManagerClient *manager = G_DBUS_OBJECT_MANAGER_CLIENT (object);
196 maybe_unsubscribe_signals (manager);
198 g_hash_table_unref (manager->priv->map_object_path_to_object_proxy);
200 if (manager->priv->control_proxy != NULL)
202 g_signal_handlers_disconnect_by_func (manager->priv->control_proxy,
203 on_control_proxy_g_signal,
205 g_object_unref (manager->priv->control_proxy);
207 if (manager->priv->connection != NULL)
208 g_object_unref (manager->priv->connection);
209 g_free (manager->priv->object_path);
210 g_free (manager->priv->name);
211 g_free (manager->priv->name_owner);
213 if (manager->priv->get_proxy_type_destroy_notify != NULL)
214 manager->priv->get_proxy_type_destroy_notify (manager->priv->get_proxy_type_user_data);
216 g_mutex_clear (&manager->priv->lock);
218 if (G_OBJECT_CLASS (g_dbus_object_manager_client_parent_class)->finalize != NULL)
219 G_OBJECT_CLASS (g_dbus_object_manager_client_parent_class)->finalize (object);
223 g_dbus_object_manager_client_get_property (GObject *_object,
228 GDBusObjectManagerClient *manager = G_DBUS_OBJECT_MANAGER_CLIENT (_object);
232 case PROP_CONNECTION:
233 g_value_set_object (value, g_dbus_object_manager_client_get_connection (manager));
236 case PROP_OBJECT_PATH:
237 g_value_set_string (value, g_dbus_object_manager_get_object_path (G_DBUS_OBJECT_MANAGER (manager)));
241 g_value_set_string (value, g_dbus_object_manager_client_get_name (manager));
245 g_value_set_flags (value, g_dbus_object_manager_client_get_flags (manager));
248 case PROP_NAME_OWNER:
249 g_value_take_string (value, g_dbus_object_manager_client_get_name_owner (manager));
253 G_OBJECT_WARN_INVALID_PROPERTY_ID (manager, prop_id, pspec);
259 g_dbus_object_manager_client_set_property (GObject *_object,
264 GDBusObjectManagerClient *manager = G_DBUS_OBJECT_MANAGER_CLIENT (_object);
270 manager->priv->bus_type = g_value_get_enum (value);
273 case PROP_CONNECTION:
274 if (g_value_get_object (value) != NULL)
276 g_assert (manager->priv->connection == NULL);
277 g_assert (G_IS_DBUS_CONNECTION (g_value_get_object (value)));
278 manager->priv->connection = g_value_dup_object (value);
282 case PROP_OBJECT_PATH:
283 g_assert (manager->priv->object_path == NULL);
284 g_assert (g_variant_is_object_path (g_value_get_string (value)));
285 manager->priv->object_path = g_value_dup_string (value);
289 g_assert (manager->priv->name == NULL);
290 name = g_value_get_string (value);
291 g_assert (name == NULL || g_dbus_is_name (name));
292 manager->priv->name = g_strdup (name);
296 manager->priv->flags = g_value_get_flags (value);
299 case PROP_GET_PROXY_TYPE_FUNC:
300 manager->priv->get_proxy_type_func = g_value_get_pointer (value);
303 case PROP_GET_PROXY_TYPE_USER_DATA:
304 manager->priv->get_proxy_type_user_data = g_value_get_pointer (value);
307 case PROP_GET_PROXY_TYPE_DESTROY_NOTIFY:
308 manager->priv->get_proxy_type_destroy_notify = g_value_get_pointer (value);
312 G_OBJECT_WARN_INVALID_PROPERTY_ID (manager, prop_id, pspec);
318 g_dbus_object_manager_client_class_init (GDBusObjectManagerClientClass *klass)
320 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
322 gobject_class->finalize = g_dbus_object_manager_client_finalize;
323 gobject_class->set_property = g_dbus_object_manager_client_set_property;
324 gobject_class->get_property = g_dbus_object_manager_client_get_property;
327 * GDBusObjectManagerClient:connection:
329 * The #GDBusConnection to use.
333 g_object_class_install_property (gobject_class,
335 g_param_spec_object ("connection",
337 "The connection to use",
338 G_TYPE_DBUS_CONNECTION,
341 G_PARAM_CONSTRUCT_ONLY |
342 G_PARAM_STATIC_STRINGS));
345 * GDBusObjectManagerClient:bus-type:
347 * If this property is not %G_BUS_TYPE_NONE, then
348 * #GDBusObjectManagerClient:connection must be %NULL and will be set to the
349 * #GDBusConnection obtained by calling g_bus_get() with the value
354 g_object_class_install_property (gobject_class,
356 g_param_spec_enum ("bus-type",
358 "The bus to connect to, if any",
362 G_PARAM_CONSTRUCT_ONLY |
363 G_PARAM_STATIC_NAME |
364 G_PARAM_STATIC_BLURB |
365 G_PARAM_STATIC_NICK));
368 * GDBusObjectManagerClient:flags:
370 * Flags from the #GDBusObjectManagerClientFlags enumeration.
374 g_object_class_install_property (gobject_class,
376 g_param_spec_flags ("flags",
378 "Flags for the proxy manager",
379 G_TYPE_DBUS_OBJECT_MANAGER_CLIENT_FLAGS,
380 G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE,
383 G_PARAM_CONSTRUCT_ONLY |
384 G_PARAM_STATIC_NAME |
385 G_PARAM_STATIC_BLURB |
386 G_PARAM_STATIC_NICK));
389 * GDBusObjectManagerClient:object-path:
391 * The object path the manager is for.
395 g_object_class_install_property (gobject_class,
397 g_param_spec_string ("object-path",
399 "The object path of the control object",
403 G_PARAM_CONSTRUCT_ONLY |
404 G_PARAM_STATIC_STRINGS));
407 * GDBusObjectManagerClient:name:
409 * The well-known name or unique name that the manager is for.
413 g_object_class_install_property (gobject_class,
415 g_param_spec_string ("name",
417 "Name that the manager is for",
421 G_PARAM_CONSTRUCT_ONLY |
422 G_PARAM_STATIC_STRINGS));
425 * GDBusObjectManagerClient:name-owner:
427 * The unique name that owns #GDBusObjectManagerClient:name or %NULL if
428 * no-one is currently owning the name. Connect to the
429 * #GObject::notify signal to track changes to this property.
433 g_object_class_install_property (gobject_class,
435 g_param_spec_string ("name-owner",
437 "The owner of the name we are watching",
440 G_PARAM_STATIC_STRINGS));
443 * GDBusObjectManagerClient:get-proxy-type-func:
445 * The #GDBusProxyTypeFunc to use when determining what #GType to
446 * use for interface proxies or %NULL.
450 g_object_class_install_property (gobject_class,
451 PROP_GET_PROXY_TYPE_FUNC,
452 g_param_spec_pointer ("get-proxy-type-func",
453 "GDBusProxyTypeFunc Function Pointer",
454 "The GDBusProxyTypeFunc pointer to use",
457 G_PARAM_CONSTRUCT_ONLY |
458 G_PARAM_STATIC_STRINGS));
461 * GDBusObjectManagerClient:get-proxy-type-user-data:
463 * The #gpointer user_data to pass to #GDBusObjectManagerClient:get-proxy-type-func.
467 g_object_class_install_property (gobject_class,
468 PROP_GET_PROXY_TYPE_USER_DATA,
469 g_param_spec_pointer ("get-proxy-type-user-data",
470 "GDBusProxyTypeFunc User Data",
471 "The GDBusProxyTypeFunc user_data",
474 G_PARAM_CONSTRUCT_ONLY |
475 G_PARAM_STATIC_STRINGS));
478 * GDBusObjectManagerClient:get-proxy-type-destroy-notify:
480 * A #GDestroyNotify for the #gpointer user_data in #GDBusObjectManagerClient:get-proxy-type-user-data.
484 g_object_class_install_property (gobject_class,
485 PROP_GET_PROXY_TYPE_DESTROY_NOTIFY,
486 g_param_spec_pointer ("get-proxy-type-destroy-notify",
487 "GDBusProxyTypeFunc user data free function",
488 "The GDBusProxyTypeFunc user data free function",
491 G_PARAM_CONSTRUCT_ONLY |
492 G_PARAM_STATIC_STRINGS));
495 * GDBusObjectManagerClient::interface-proxy-signal:
496 * @manager: The #GDBusObjectManagerClient emitting the signal.
497 * @object_proxy: The #GDBusObjectProxy on which an interface is emitting a D-Bus signal.
498 * @interface_proxy: The #GDBusProxy that is emitting a D-Bus signal.
499 * @sender_name: The sender of the signal or NULL if the connection is not a bus connection.
500 * @signal_name: The signal name.
501 * @parameters: A #GVariant tuple with parameters for the signal.
503 * Emitted when a D-Bus signal is received on @interface_proxy.
505 * This signal exists purely as a convenience to avoid having to
506 * connect signals to all interface proxies managed by @manager.
508 * This signal is emitted in the
509 * [thread-default main context][g-main-context-push-thread-default]
510 * that @manager was constructed in.
514 signals[INTERFACE_PROXY_SIGNAL_SIGNAL] =
515 g_signal_new ("interface-proxy-signal",
516 G_TYPE_DBUS_OBJECT_MANAGER_CLIENT,
518 G_STRUCT_OFFSET (GDBusObjectManagerClientClass, interface_proxy_signal),
524 G_TYPE_DBUS_OBJECT_PROXY,
531 * GDBusObjectManagerClient::interface-proxy-properties-changed:
532 * @manager: The #GDBusObjectManagerClient emitting the signal.
533 * @object_proxy: The #GDBusObjectProxy on which an interface has properties that are changing.
534 * @interface_proxy: The #GDBusProxy that has properties that are changing.
535 * @changed_properties: A #GVariant containing the properties that changed.
536 * @invalidated_properties: A %NULL terminated array of properties that was invalidated.
538 * Emitted when one or more D-Bus properties on proxy changes. The
539 * local cache has already been updated when this signal fires. Note
540 * that both @changed_properties and @invalidated_properties are
541 * guaranteed to never be %NULL (either may be empty though).
543 * This signal exists purely as a convenience to avoid having to
544 * connect signals to all interface proxies managed by @manager.
546 * This signal is emitted in the
547 * [thread-default main context][g-main-context-push-thread-default]
548 * that @manager was constructed in.
552 signals[INTERFACE_PROXY_PROPERTIES_CHANGED_SIGNAL] =
553 g_signal_new ("interface-proxy-properties-changed",
554 G_TYPE_DBUS_OBJECT_MANAGER_CLIENT,
556 G_STRUCT_OFFSET (GDBusObjectManagerClientClass, interface_proxy_properties_changed),
562 G_TYPE_DBUS_OBJECT_PROXY,
569 g_dbus_object_manager_client_init (GDBusObjectManagerClient *manager)
571 manager->priv = g_dbus_object_manager_client_get_instance_private (manager);
572 g_mutex_init (&manager->priv->lock);
573 manager->priv->map_object_path_to_object_proxy = g_hash_table_new_full (g_str_hash,
576 (GDestroyNotify) g_object_unref);
579 /* ---------------------------------------------------------------------------------------------------- */
582 * g_dbus_object_manager_client_new_sync:
583 * @connection: A #GDBusConnection.
584 * @flags: Zero or more flags from the #GDBusObjectManagerClientFlags enumeration.
585 * @name: (allow-none): The owner of the control object (unique or well-known name), or %NULL when not using a message bus connection.
586 * @object_path: The object path of the control object.
587 * @get_proxy_type_func: (allow-none): A #GDBusProxyTypeFunc function or %NULL to always construct #GDBusProxy proxies.
588 * @get_proxy_type_user_data: User data to pass to @get_proxy_type_func.
589 * @get_proxy_type_destroy_notify: (allow-none): Free function for @get_proxy_type_user_data or %NULL.
590 * @cancellable: (allow-none): A #GCancellable or %NULL
591 * @error: Return location for error or %NULL.
593 * Creates a new #GDBusObjectManagerClient object.
595 * This is a synchronous failable constructor - the calling thread is
596 * blocked until a reply is received. See g_dbus_object_manager_client_new()
597 * for the asynchronous version.
599 * Returns: (transfer full) (type GDBusObjectManagerClient): A
600 * #GDBusObjectManagerClient object or %NULL if @error is set. Free
601 * with g_object_unref().
606 g_dbus_object_manager_client_new_sync (GDBusConnection *connection,
607 GDBusObjectManagerClientFlags flags,
609 const gchar *object_path,
610 GDBusProxyTypeFunc get_proxy_type_func,
611 gpointer get_proxy_type_user_data,
612 GDestroyNotify get_proxy_type_destroy_notify,
613 GCancellable *cancellable,
618 g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);
619 g_return_val_if_fail ((name == NULL && g_dbus_connection_get_unique_name (connection) == NULL) ||
620 g_dbus_is_name (name), NULL);
621 g_return_val_if_fail (g_variant_is_object_path (object_path), NULL);
622 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
624 initable = g_initable_new (G_TYPE_DBUS_OBJECT_MANAGER_CLIENT,
627 "connection", connection,
630 "object-path", object_path,
631 "get-proxy-type-func", get_proxy_type_func,
632 "get-proxy-type-user-data", get_proxy_type_user_data,
633 "get-proxy-type-destroy-notify", get_proxy_type_destroy_notify,
635 if (initable != NULL)
636 return G_DBUS_OBJECT_MANAGER (initable);
642 * g_dbus_object_manager_client_new:
643 * @connection: A #GDBusConnection.
644 * @flags: Zero or more flags from the #GDBusObjectManagerClientFlags enumeration.
645 * @name: The owner of the control object (unique or well-known name).
646 * @object_path: The object path of the control object.
647 * @get_proxy_type_func: (allow-none): A #GDBusProxyTypeFunc function or %NULL to always construct #GDBusProxy proxies.
648 * @get_proxy_type_user_data: User data to pass to @get_proxy_type_func.
649 * @get_proxy_type_destroy_notify: (allow-none): Free function for @get_proxy_type_user_data or %NULL.
650 * @cancellable: (allow-none): A #GCancellable or %NULL
651 * @callback: A #GAsyncReadyCallback to call when the request is satisfied.
652 * @user_data: The data to pass to @callback.
654 * Asynchronously creates a new #GDBusObjectManagerClient object.
656 * This is an asynchronous failable constructor. When the result is
657 * ready, @callback will be invoked in the
658 * [thread-default main context][g-main-context-push-thread-default]
659 * of the thread you are calling this method from. You can
660 * then call g_dbus_object_manager_client_new_finish() to get the result. See
661 * g_dbus_object_manager_client_new_sync() for the synchronous version.
666 g_dbus_object_manager_client_new (GDBusConnection *connection,
667 GDBusObjectManagerClientFlags flags,
669 const gchar *object_path,
670 GDBusProxyTypeFunc get_proxy_type_func,
671 gpointer get_proxy_type_user_data,
672 GDestroyNotify get_proxy_type_destroy_notify,
673 GCancellable *cancellable,
674 GAsyncReadyCallback callback,
677 g_return_if_fail (G_IS_DBUS_CONNECTION (connection));
678 g_return_if_fail ((name == NULL && g_dbus_connection_get_unique_name (connection) == NULL) ||
679 g_dbus_is_name (name));
680 g_return_if_fail (g_variant_is_object_path (object_path));
682 g_async_initable_new_async (G_TYPE_DBUS_OBJECT_MANAGER_CLIENT,
687 "connection", connection,
690 "object-path", object_path,
691 "get-proxy-type-func", get_proxy_type_func,
692 "get-proxy-type-user-data", get_proxy_type_user_data,
693 "get-proxy-type-destroy-notify", get_proxy_type_destroy_notify,
698 * g_dbus_object_manager_client_new_finish:
699 * @res: A #GAsyncResult obtained from the #GAsyncReadyCallback passed to g_dbus_object_manager_client_new().
700 * @error: Return location for error or %NULL.
702 * Finishes an operation started with g_dbus_object_manager_client_new().
704 * Returns: (transfer full) (type GDBusObjectManagerClient): A
705 * #GDBusObjectManagerClient object or %NULL if @error is set. Free
706 * with g_object_unref().
711 g_dbus_object_manager_client_new_finish (GAsyncResult *res,
715 GObject *source_object;
717 source_object = g_async_result_get_source_object (res);
718 g_assert (source_object != NULL);
720 object = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object),
723 g_object_unref (source_object);
726 return G_DBUS_OBJECT_MANAGER (object);
731 /* ---------------------------------------------------------------------------------------------------- */
734 * g_dbus_object_manager_client_new_for_bus_sync:
735 * @bus_type: A #GBusType.
736 * @flags: Zero or more flags from the #GDBusObjectManagerClientFlags enumeration.
737 * @name: The owner of the control object (unique or well-known name).
738 * @object_path: The object path of the control object.
739 * @get_proxy_type_func: (allow-none): A #GDBusProxyTypeFunc function or %NULL to always construct #GDBusProxy proxies.
740 * @get_proxy_type_user_data: User data to pass to @get_proxy_type_func.
741 * @get_proxy_type_destroy_notify: (allow-none): Free function for @get_proxy_type_user_data or %NULL.
742 * @cancellable: (allow-none): A #GCancellable or %NULL
743 * @error: Return location for error or %NULL.
745 * Like g_dbus_object_manager_client_new_sync() but takes a #GBusType instead
746 * of a #GDBusConnection.
748 * This is a synchronous failable constructor - the calling thread is
749 * blocked until a reply is received. See g_dbus_object_manager_client_new_for_bus()
750 * for the asynchronous version.
752 * Returns: (transfer full) (type GDBusObjectManagerClient): A
753 * #GDBusObjectManagerClient object or %NULL if @error is set. Free
754 * with g_object_unref().
759 g_dbus_object_manager_client_new_for_bus_sync (GBusType bus_type,
760 GDBusObjectManagerClientFlags flags,
762 const gchar *object_path,
763 GDBusProxyTypeFunc get_proxy_type_func,
764 gpointer get_proxy_type_user_data,
765 GDestroyNotify get_proxy_type_destroy_notify,
766 GCancellable *cancellable,
771 g_return_val_if_fail (bus_type != G_BUS_TYPE_NONE, NULL);
772 g_return_val_if_fail (g_dbus_is_name (name), NULL);
773 g_return_val_if_fail (g_variant_is_object_path (object_path), NULL);
774 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
776 initable = g_initable_new (G_TYPE_DBUS_OBJECT_MANAGER_CLIENT,
779 "bus-type", bus_type,
782 "object-path", object_path,
783 "get-proxy-type-func", get_proxy_type_func,
784 "get-proxy-type-user-data", get_proxy_type_user_data,
785 "get-proxy-type-destroy-notify", get_proxy_type_destroy_notify,
787 if (initable != NULL)
788 return G_DBUS_OBJECT_MANAGER (initable);
794 * g_dbus_object_manager_client_new_for_bus:
795 * @bus_type: A #GBusType.
796 * @flags: Zero or more flags from the #GDBusObjectManagerClientFlags enumeration.
797 * @name: The owner of the control object (unique or well-known name).
798 * @object_path: The object path of the control object.
799 * @get_proxy_type_func: (allow-none): A #GDBusProxyTypeFunc function or %NULL to always construct #GDBusProxy proxies.
800 * @get_proxy_type_user_data: User data to pass to @get_proxy_type_func.
801 * @get_proxy_type_destroy_notify: (allow-none): Free function for @get_proxy_type_user_data or %NULL.
802 * @cancellable: (allow-none): A #GCancellable or %NULL
803 * @callback: A #GAsyncReadyCallback to call when the request is satisfied.
804 * @user_data: The data to pass to @callback.
806 * Like g_dbus_object_manager_client_new() but takes a #GBusType instead of a
809 * This is an asynchronous failable constructor. When the result is
810 * ready, @callback will be invoked in the
811 * [thread-default main loop][g-main-context-push-thread-default]
812 * of the thread you are calling this method from. You can
813 * then call g_dbus_object_manager_client_new_for_bus_finish() to get the result. See
814 * g_dbus_object_manager_client_new_for_bus_sync() for the synchronous version.
819 g_dbus_object_manager_client_new_for_bus (GBusType bus_type,
820 GDBusObjectManagerClientFlags flags,
822 const gchar *object_path,
823 GDBusProxyTypeFunc get_proxy_type_func,
824 gpointer get_proxy_type_user_data,
825 GDestroyNotify get_proxy_type_destroy_notify,
826 GCancellable *cancellable,
827 GAsyncReadyCallback callback,
830 g_return_if_fail (bus_type != G_BUS_TYPE_NONE);
831 g_return_if_fail (g_dbus_is_name (name));
832 g_return_if_fail (g_variant_is_object_path (object_path));
834 g_async_initable_new_async (G_TYPE_DBUS_OBJECT_MANAGER_CLIENT,
839 "bus-type", bus_type,
842 "object-path", object_path,
843 "get-proxy-type-func", get_proxy_type_func,
844 "get-proxy-type-user-data", get_proxy_type_user_data,
845 "get-proxy-type-destroy-notify", get_proxy_type_destroy_notify,
850 * g_dbus_object_manager_client_new_for_bus_finish:
851 * @res: A #GAsyncResult obtained from the #GAsyncReadyCallback passed to g_dbus_object_manager_client_new_for_bus().
852 * @error: Return location for error or %NULL.
854 * Finishes an operation started with g_dbus_object_manager_client_new_for_bus().
856 * Returns: (transfer full) (type GDBusObjectManagerClient): A
857 * #GDBusObjectManagerClient object or %NULL if @error is set. Free
858 * with g_object_unref().
863 g_dbus_object_manager_client_new_for_bus_finish (GAsyncResult *res,
867 GObject *source_object;
869 source_object = g_async_result_get_source_object (res);
870 g_assert (source_object != NULL);
872 object = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object),
875 g_object_unref (source_object);
878 return G_DBUS_OBJECT_MANAGER (object);
883 /* ---------------------------------------------------------------------------------------------------- */
886 * g_dbus_object_manager_client_get_connection:
887 * @manager: A #GDBusObjectManagerClient
889 * Gets the #GDBusConnection used by @manager.
891 * Returns: (transfer none): A #GDBusConnection object. Do not free,
892 * the object belongs to @manager.
897 g_dbus_object_manager_client_get_connection (GDBusObjectManagerClient *manager)
899 GDBusConnection *ret;
900 g_return_val_if_fail (G_IS_DBUS_OBJECT_MANAGER_CLIENT (manager), NULL);
901 g_mutex_lock (&manager->priv->lock);
902 ret = manager->priv->connection;
903 g_mutex_unlock (&manager->priv->lock);
908 * g_dbus_object_manager_client_get_name:
909 * @manager: A #GDBusObjectManagerClient
911 * Gets the name that @manager is for, or %NULL if not a message bus
914 * Returns: A unique or well-known name. Do not free, the string
915 * belongs to @manager.
920 g_dbus_object_manager_client_get_name (GDBusObjectManagerClient *manager)
923 g_return_val_if_fail (G_IS_DBUS_OBJECT_MANAGER_CLIENT (manager), NULL);
924 g_mutex_lock (&manager->priv->lock);
925 ret = manager->priv->name;
926 g_mutex_unlock (&manager->priv->lock);
931 * g_dbus_object_manager_client_get_flags:
932 * @manager: A #GDBusObjectManagerClient
934 * Gets the flags that @manager was constructed with.
936 * Returns: Zero of more flags from the #GDBusObjectManagerClientFlags
941 GDBusObjectManagerClientFlags
942 g_dbus_object_manager_client_get_flags (GDBusObjectManagerClient *manager)
944 GDBusObjectManagerClientFlags ret;
945 g_return_val_if_fail (G_IS_DBUS_OBJECT_MANAGER_CLIENT (manager), G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE);
946 g_mutex_lock (&manager->priv->lock);
947 ret = manager->priv->flags;
948 g_mutex_unlock (&manager->priv->lock);
953 * g_dbus_object_manager_client_get_name_owner:
954 * @manager: A #GDBusObjectManagerClient.
956 * The unique name that owns the name that @manager is for or %NULL if
957 * no-one currently owns that name. You can connect to the
958 * #GObject::notify signal to track changes to the
959 * #GDBusObjectManagerClient:name-owner property.
961 * Returns: (nullable): The name owner or %NULL if no name owner
962 * exists. Free with g_free().
967 g_dbus_object_manager_client_get_name_owner (GDBusObjectManagerClient *manager)
970 g_return_val_if_fail (G_IS_DBUS_OBJECT_MANAGER_CLIENT (manager), NULL);
971 g_mutex_lock (&manager->priv->lock);
972 ret = g_strdup (manager->priv->name_owner);
973 g_mutex_unlock (&manager->priv->lock);
977 /* ---------------------------------------------------------------------------------------------------- */
979 /* signal handler for all objects we manage - we dispatch signals
980 * from here to the objects
983 signal_cb (GDBusConnection *connection,
984 const gchar *sender_name,
985 const gchar *object_path,
986 const gchar *interface_name,
987 const gchar *signal_name,
988 GVariant *parameters,
991 GDBusObjectManagerClient *manager = G_DBUS_OBJECT_MANAGER_CLIENT (user_data);
992 GDBusObjectProxy *object_proxy;
993 GDBusInterface *interface;
995 g_mutex_lock (&manager->priv->lock);
996 object_proxy = g_hash_table_lookup (manager->priv->map_object_path_to_object_proxy, object_path);
997 if (object_proxy == NULL)
999 g_mutex_unlock (&manager->priv->lock);
1002 g_object_ref (object_proxy);
1003 g_mutex_unlock (&manager->priv->lock);
1005 //g_debug ("yay, signal_cb %s %s: %s\n", signal_name, object_path, g_variant_print (parameters, TRUE));
1007 g_object_ref (manager);
1008 if (g_strcmp0 (interface_name, "org.freedesktop.DBus.Properties") == 0)
1010 if (g_strcmp0 (signal_name, "PropertiesChanged") == 0)
1012 const gchar *interface_name;
1013 GVariant *changed_properties;
1014 const gchar **invalidated_properties;
1016 g_variant_get (parameters,
1019 &changed_properties,
1020 &invalidated_properties);
1022 interface = g_dbus_object_get_interface (G_DBUS_OBJECT (object_proxy), interface_name);
1023 if (interface != NULL)
1025 GVariantIter property_iter;
1026 const gchar *property_name;
1027 GVariant *property_value;
1030 /* update caches... */
1031 g_variant_iter_init (&property_iter, changed_properties);
1032 while (g_variant_iter_next (&property_iter,
1037 g_dbus_proxy_set_cached_property (G_DBUS_PROXY (interface),
1040 g_variant_unref (property_value);
1043 for (n = 0; invalidated_properties[n] != NULL; n++)
1045 g_dbus_proxy_set_cached_property (G_DBUS_PROXY (interface),
1046 invalidated_properties[n],
1049 /* ... and then synthesize the signal */
1050 g_signal_emit_by_name (interface,
1051 "g-properties-changed",
1053 invalidated_properties);
1054 g_signal_emit (manager,
1055 signals[INTERFACE_PROXY_PROPERTIES_CHANGED_SIGNAL],
1060 invalidated_properties);
1061 g_object_unref (interface);
1063 g_variant_unref (changed_properties);
1064 g_free (invalidated_properties);
1069 /* regular signal - just dispatch it */
1070 interface = g_dbus_object_get_interface (G_DBUS_OBJECT (object_proxy), interface_name);
1071 if (interface != NULL)
1073 g_signal_emit_by_name (interface,
1078 g_signal_emit (manager,
1079 signals[INTERFACE_PROXY_SIGNAL_SIGNAL],
1086 g_object_unref (interface);
1089 g_object_unref (manager);
1092 g_clear_object (&object_proxy);
1096 subscribe_signals (GDBusObjectManagerClient *manager,
1097 const gchar *name_owner)
1099 GError *error = NULL;
1102 g_return_if_fail (G_IS_DBUS_OBJECT_MANAGER_CLIENT (manager));
1103 g_return_if_fail (manager->priv->signal_subscription_id == 0);
1104 g_return_if_fail (name_owner == NULL || g_dbus_is_unique_name (name_owner));
1106 if (name_owner != NULL)
1108 /* Only add path_namespace if it's non-'/'. This removes a no-op key from
1109 * the match rule, and also works around a D-Bus bug where
1110 * path_namespace='/' matches nothing in D-Bus versions < 1.6.18.
1112 * See: https://bugs.freedesktop.org/show_bug.cgi?id=70799 */
1113 if (g_str_equal (manager->priv->object_path, "/"))
1115 manager->priv->match_rule = g_strdup_printf ("type='signal',sender='%s'",
1120 manager->priv->match_rule = g_strdup_printf ("type='signal',sender='%s',path_namespace='%s'",
1121 name_owner, manager->priv->object_path);
1124 /* The bus daemon may not implement path_namespace so gracefully
1125 * handle this by using a fallback triggered if @error is set. */
1126 ret = g_dbus_connection_call_sync (manager->priv->connection,
1127 "org.freedesktop.DBus",
1128 "/org/freedesktop/DBus",
1129 "org.freedesktop.DBus",
1131 g_variant_new ("(s)",
1132 manager->priv->match_rule),
1133 NULL, /* reply_type */
1134 G_DBUS_CALL_FLAGS_NONE,
1135 -1, /* default timeout */
1136 NULL, /* TODO: Cancellable */
1139 /* yay, bus daemon supports path_namespace */
1141 g_variant_unref (ret);
1146 /* still need to ask GDBusConnection for the callbacks */
1147 manager->priv->signal_subscription_id =
1148 g_dbus_connection_signal_subscribe (manager->priv->connection,
1150 NULL, /* interface */
1152 NULL, /* path - TODO: really want wilcard support here */
1154 G_DBUS_SIGNAL_FLAGS_NONE |
1155 G_DBUS_SIGNAL_FLAGS_NO_MATCH_RULE,
1158 NULL); /* user_data_free_func */
1163 /* TODO: we could report this to the user
1164 g_warning ("Message bus daemon does not support path_namespace: %s (%s %d)",
1166 g_quark_to_string (error->domain),
1170 g_error_free (error);
1172 /* no need to call RemoveMatch when done since it didn't work */
1173 g_free (manager->priv->match_rule);
1174 manager->priv->match_rule = NULL;
1176 /* Fallback is to subscribe to *all* signals from the name owner which
1177 * is rather wasteful. It's probably not a big practical problem because
1178 * users typically want all objects that the name owner supplies.
1180 manager->priv->signal_subscription_id =
1181 g_dbus_connection_signal_subscribe (manager->priv->connection,
1183 NULL, /* interface */
1185 NULL, /* path - TODO: really want wilcard support here */
1187 G_DBUS_SIGNAL_FLAGS_NONE,
1190 NULL); /* user_data_free_func */
1195 maybe_unsubscribe_signals (GDBusObjectManagerClient *manager)
1197 g_return_if_fail (G_IS_DBUS_OBJECT_MANAGER_CLIENT (manager));
1199 if (manager->priv->signal_subscription_id > 0)
1201 g_dbus_connection_signal_unsubscribe (manager->priv->connection,
1202 manager->priv->signal_subscription_id);
1203 manager->priv->signal_subscription_id = 0;
1206 if (manager->priv->match_rule != NULL)
1208 /* Since the AddMatch call succeeded this is guaranteed to not
1209 * fail - therefore, don't bother checking the return value
1211 g_dbus_connection_call (manager->priv->connection,
1212 "org.freedesktop.DBus",
1213 "/org/freedesktop/DBus",
1214 "org.freedesktop.DBus",
1216 g_variant_new ("(s)",
1217 manager->priv->match_rule),
1218 NULL, /* reply_type */
1219 G_DBUS_CALL_FLAGS_NONE,
1220 -1, /* default timeout */
1221 NULL, /* GCancellable */
1222 NULL, /* GAsyncReadyCallback */
1223 NULL); /* user data */
1224 g_free (manager->priv->match_rule);
1225 manager->priv->match_rule = NULL;
1230 /* ---------------------------------------------------------------------------------------------------- */
1233 on_notify_g_name_owner (GObject *object,
1237 GDBusObjectManagerClient *manager = G_DBUS_OBJECT_MANAGER_CLIENT (user_data);
1238 gchar *old_name_owner;
1239 gchar *new_name_owner;
1241 g_mutex_lock (&manager->priv->lock);
1242 old_name_owner = manager->priv->name_owner;
1243 new_name_owner = g_dbus_proxy_get_name_owner (manager->priv->control_proxy);
1244 manager->priv->name_owner = NULL;
1246 g_object_ref (manager);
1247 if (g_strcmp0 (old_name_owner, new_name_owner) != 0)
1252 /* remote manager changed; nuke all local proxies */
1253 proxies = g_hash_table_get_values (manager->priv->map_object_path_to_object_proxy);
1254 g_list_foreach (proxies, (GFunc) g_object_ref, NULL);
1255 g_hash_table_remove_all (manager->priv->map_object_path_to_object_proxy);
1257 g_mutex_unlock (&manager->priv->lock);
1259 /* do the :name-owner notify with a NULL name - this way the user knows
1260 * the ::object-proxy-removed following is because the name owner went
1263 g_object_notify (G_OBJECT (manager), "name-owner");
1265 for (l = proxies; l != NULL; l = l->next)
1267 GDBusObjectProxy *object_proxy = G_DBUS_OBJECT_PROXY (l->data);
1268 g_signal_emit_by_name (manager, "object-removed", object_proxy);
1270 g_list_free_full (proxies, g_object_unref);
1272 /* nuke local filter */
1273 maybe_unsubscribe_signals (manager);
1277 g_mutex_unlock (&manager->priv->lock);
1280 if (new_name_owner != NULL)
1285 //g_debug ("repopulating for %s", new_name_owner);
1287 /* TODO: do this async! */
1288 subscribe_signals (manager,
1291 value = g_dbus_proxy_call_sync (manager->priv->control_proxy,
1292 "GetManagedObjects",
1293 NULL, /* parameters */
1294 G_DBUS_CALL_FLAGS_NONE,
1300 maybe_unsubscribe_signals (manager);
1301 g_warning ("Error calling GetManagedObjects() when name owner %s for name %s came back: %s",
1303 manager->priv->name,
1305 g_error_free (error);
1309 process_get_all_result (manager, value, new_name_owner);
1310 g_variant_unref (value);
1313 /* do the :name-owner notify *AFTER* emitting ::object-proxy-added signals - this
1314 * way the user knows that the signals were emitted because the name owner came back
1316 g_mutex_lock (&manager->priv->lock);
1317 manager->priv->name_owner = new_name_owner;
1318 g_mutex_unlock (&manager->priv->lock);
1319 g_object_notify (G_OBJECT (manager), "name-owner");
1322 g_free (old_name_owner);
1323 g_object_unref (manager);
1327 initable_init (GInitable *initable,
1328 GCancellable *cancellable,
1331 GDBusObjectManagerClient *manager = G_DBUS_OBJECT_MANAGER_CLIENT (initable);
1334 GDBusProxyFlags proxy_flags;
1338 if (manager->priv->bus_type != G_BUS_TYPE_NONE)
1340 g_assert (manager->priv->connection == NULL);
1341 manager->priv->connection = g_bus_get_sync (manager->priv->bus_type, cancellable, error);
1342 if (manager->priv->connection == NULL)
1346 proxy_flags = G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES;
1347 if (manager->priv->flags & G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_DO_NOT_AUTO_START)
1348 proxy_flags |= G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START;
1350 manager->priv->control_proxy = g_dbus_proxy_new_sync (manager->priv->connection,
1352 NULL, /* GDBusInterfaceInfo* */
1353 manager->priv->name,
1354 manager->priv->object_path,
1355 "org.freedesktop.DBus.ObjectManager",
1358 if (manager->priv->control_proxy == NULL)
1361 g_signal_connect (G_OBJECT (manager->priv->control_proxy),
1362 "notify::g-name-owner",
1363 G_CALLBACK (on_notify_g_name_owner),
1366 g_signal_connect (manager->priv->control_proxy,
1368 G_CALLBACK (on_control_proxy_g_signal),
1371 manager->priv->name_owner = g_dbus_proxy_get_name_owner (manager->priv->control_proxy);
1372 if (manager->priv->name_owner == NULL && manager->priv->name != NULL)
1374 /* it's perfectly fine if there's no name owner.. we're just going to
1375 * wait until one is ready
1380 /* yay, we can get the objects */
1381 subscribe_signals (manager,
1382 manager->priv->name_owner);
1383 value = g_dbus_proxy_call_sync (manager->priv->control_proxy,
1384 "GetManagedObjects",
1385 NULL, /* parameters */
1386 G_DBUS_CALL_FLAGS_NONE,
1392 maybe_unsubscribe_signals (manager);
1393 g_warn_if_fail (g_signal_handlers_disconnect_by_func (manager->priv->control_proxy,
1394 on_control_proxy_g_signal,
1396 g_object_unref (manager->priv->control_proxy);
1397 manager->priv->control_proxy = NULL;
1401 process_get_all_result (manager, value, manager->priv->name_owner);
1402 g_variant_unref (value);
1412 initable_iface_init (GInitableIface *initable_iface)
1414 initable_iface->init = initable_init;
1418 async_initable_iface_init (GAsyncInitableIface *async_initable_iface)
1420 /* for now, just use default: run GInitable code in thread */
1423 /* ---------------------------------------------------------------------------------------------------- */
1426 add_interfaces (GDBusObjectManagerClient *manager,
1427 const gchar *object_path,
1428 GVariant *ifaces_and_properties,
1429 const gchar *name_owner)
1431 GDBusObjectProxy *op;
1434 const gchar *interface_name;
1435 GVariant *properties;
1436 GList *interface_added_signals, *l;
1437 GDBusProxy *interface_proxy;
1439 g_return_if_fail (name_owner == NULL || g_dbus_is_unique_name (name_owner));
1441 g_mutex_lock (&manager->priv->lock);
1443 interface_added_signals = NULL;
1446 op = g_hash_table_lookup (manager->priv->map_object_path_to_object_proxy, object_path);
1449 GType object_proxy_type;
1450 if (manager->priv->get_proxy_type_func != NULL)
1452 object_proxy_type = manager->priv->get_proxy_type_func (manager,
1455 manager->priv->get_proxy_type_user_data);
1456 g_warn_if_fail (g_type_is_a (object_proxy_type, G_TYPE_DBUS_OBJECT_PROXY));
1460 object_proxy_type = G_TYPE_DBUS_OBJECT_PROXY;
1462 op = g_object_new (object_proxy_type,
1463 "g-connection", manager->priv->connection,
1464 "g-object-path", object_path,
1470 g_variant_iter_init (&iter, ifaces_and_properties);
1471 while (g_variant_iter_next (&iter,
1477 GType interface_proxy_type;
1479 if (manager->priv->get_proxy_type_func != NULL)
1481 interface_proxy_type = manager->priv->get_proxy_type_func (manager,
1484 manager->priv->get_proxy_type_user_data);
1485 g_warn_if_fail (g_type_is_a (interface_proxy_type, G_TYPE_DBUS_PROXY));
1489 interface_proxy_type = G_TYPE_DBUS_PROXY;
1492 /* this is fine - there is no blocking IO because we pass DO_NOT_LOAD_PROPERTIES and
1493 * DO_NOT_CONNECT_SIGNALS and use a unique name
1496 interface_proxy = g_initable_new (interface_proxy_type,
1497 NULL, /* GCancellable */
1499 "g-connection", manager->priv->connection,
1500 "g-flags", G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
1501 G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
1502 "g-name", name_owner,
1503 "g-object-path", object_path,
1504 "g-interface-name", interface_name,
1506 if (interface_proxy == NULL)
1508 g_warning ("%s: Error constructing proxy for path %s and interface %s: %s",
1513 g_error_free (error);
1517 GVariantIter property_iter;
1518 const gchar *property_name;
1519 GVariant *property_value;
1521 /* associate the interface proxy with the object */
1522 g_dbus_interface_set_object (G_DBUS_INTERFACE (interface_proxy),
1523 G_DBUS_OBJECT (op));
1525 g_variant_iter_init (&property_iter, properties);
1526 while (g_variant_iter_next (&property_iter,
1531 g_dbus_proxy_set_cached_property (interface_proxy,
1534 g_variant_unref (property_value);
1537 _g_dbus_object_proxy_add_interface (op, interface_proxy);
1539 interface_added_signals = g_list_append (interface_added_signals, g_object_ref (interface_proxy));
1540 g_object_unref (interface_proxy);
1542 g_variant_unref (properties);
1545 g_mutex_unlock (&manager->priv->lock);
1547 /* now that we don't hold the lock any more, emit signals */
1548 g_object_ref (manager);
1549 for (l = interface_added_signals; l != NULL; l = l->next)
1551 interface_proxy = G_DBUS_PROXY (l->data);
1552 g_signal_emit_by_name (manager, "interface-added", op, interface_proxy);
1553 g_object_unref (interface_proxy);
1555 g_list_free (interface_added_signals);
1559 g_hash_table_insert (manager->priv->map_object_path_to_object_proxy,
1560 g_strdup (object_path),
1562 g_signal_emit_by_name (manager, "object-added", op);
1564 g_object_unref (manager);
1565 g_object_unref (op);
1569 remove_interfaces (GDBusObjectManagerClient *manager,
1570 const gchar *object_path,
1571 const gchar *const *interface_names)
1573 GDBusObjectProxy *op;
1576 guint num_interfaces;
1577 guint num_interfaces_to_remove;
1579 g_mutex_lock (&manager->priv->lock);
1581 op = g_hash_table_lookup (manager->priv->map_object_path_to_object_proxy, object_path);
1584 g_warning ("%s: Processing InterfaceRemoved signal for path %s but no object proxy exists",
1587 g_mutex_unlock (&manager->priv->lock);
1591 interfaces = g_dbus_object_get_interfaces (G_DBUS_OBJECT (op));
1592 num_interfaces = g_list_length (interfaces);
1593 g_list_free_full (interfaces, g_object_unref);
1595 num_interfaces_to_remove = g_strv_length ((gchar **) interface_names);
1597 /* see if we are going to completety remove the object */
1598 g_object_ref (manager);
1599 if (num_interfaces_to_remove == num_interfaces)
1602 g_warn_if_fail (g_hash_table_remove (manager->priv->map_object_path_to_object_proxy, object_path));
1603 g_mutex_unlock (&manager->priv->lock);
1604 g_signal_emit_by_name (manager, "object-removed", op);
1605 g_object_unref (op);
1610 g_mutex_unlock (&manager->priv->lock);
1611 for (n = 0; interface_names != NULL && interface_names[n] != NULL; n++)
1613 GDBusInterface *interface;
1614 interface = g_dbus_object_get_interface (G_DBUS_OBJECT (op), interface_names[n]);
1615 _g_dbus_object_proxy_remove_interface (op, interface_names[n]);
1616 if (interface != NULL)
1618 g_signal_emit_by_name (manager, "interface-removed", op, interface);
1619 g_object_unref (interface);
1622 g_object_unref (op);
1624 g_object_unref (manager);
1630 process_get_all_result (GDBusObjectManagerClient *manager,
1632 const gchar *name_owner)
1635 const gchar *object_path;
1636 GVariant *ifaces_and_properties;
1639 g_return_if_fail (name_owner == NULL || g_dbus_is_unique_name (name_owner));
1641 arg0 = g_variant_get_child_value (value, 0);
1642 g_variant_iter_init (&iter, arg0);
1643 while (g_variant_iter_next (&iter,
1646 &ifaces_and_properties))
1648 add_interfaces (manager, object_path, ifaces_and_properties, name_owner);
1649 g_variant_unref (ifaces_and_properties);
1651 g_variant_unref (arg0);
1655 on_control_proxy_g_signal (GDBusProxy *proxy,
1656 const gchar *sender_name,
1657 const gchar *signal_name,
1658 GVariant *parameters,
1661 GDBusObjectManagerClient *manager = G_DBUS_OBJECT_MANAGER_CLIENT (user_data);
1662 const gchar *object_path;
1664 //g_debug ("yay, g_signal %s: %s\n", signal_name, g_variant_print (parameters, TRUE));
1666 if (g_strcmp0 (signal_name, "InterfacesAdded") == 0)
1668 GVariant *ifaces_and_properties;
1669 g_variant_get (parameters,
1672 &ifaces_and_properties);
1673 add_interfaces (manager, object_path, ifaces_and_properties, manager->priv->name_owner);
1674 g_variant_unref (ifaces_and_properties);
1676 else if (g_strcmp0 (signal_name, "InterfacesRemoved") == 0)
1678 const gchar **ifaces;
1679 g_variant_get (parameters,
1683 remove_interfaces (manager, object_path, ifaces);
1688 /* ---------------------------------------------------------------------------------------------------- */
1690 static const gchar *
1691 g_dbus_object_manager_client_get_object_path (GDBusObjectManager *_manager)
1693 GDBusObjectManagerClient *manager = G_DBUS_OBJECT_MANAGER_CLIENT (_manager);
1694 return manager->priv->object_path;
1697 static GDBusObject *
1698 g_dbus_object_manager_client_get_object (GDBusObjectManager *_manager,
1699 const gchar *object_path)
1701 GDBusObjectManagerClient *manager = G_DBUS_OBJECT_MANAGER_CLIENT (_manager);
1704 g_mutex_lock (&manager->priv->lock);
1705 ret = g_hash_table_lookup (manager->priv->map_object_path_to_object_proxy, object_path);
1708 g_mutex_unlock (&manager->priv->lock);
1712 static GDBusInterface *
1713 g_dbus_object_manager_client_get_interface (GDBusObjectManager *_manager,
1714 const gchar *object_path,
1715 const gchar *interface_name)
1717 GDBusInterface *ret;
1718 GDBusObject *object;
1722 object = g_dbus_object_manager_get_object (_manager, object_path);
1726 ret = g_dbus_object_get_interface (object, interface_name);
1727 g_object_unref (object);
1734 g_dbus_object_manager_client_get_objects (GDBusObjectManager *_manager)
1736 GDBusObjectManagerClient *manager = G_DBUS_OBJECT_MANAGER_CLIENT (_manager);
1739 g_return_val_if_fail (G_IS_DBUS_OBJECT_MANAGER_CLIENT (manager), NULL);
1741 g_mutex_lock (&manager->priv->lock);
1742 ret = g_hash_table_get_values (manager->priv->map_object_path_to_object_proxy);
1743 g_list_foreach (ret, (GFunc) g_object_ref, NULL);
1744 g_mutex_unlock (&manager->priv->lock);
1751 dbus_object_manager_interface_init (GDBusObjectManagerIface *iface)
1753 iface->get_object_path = g_dbus_object_manager_client_get_object_path;
1754 iface->get_objects = g_dbus_object_manager_client_get_objects;
1755 iface->get_object = g_dbus_object_manager_client_get_object;
1756 iface->get_interface = g_dbus_object_manager_client_get_interface;
1759 /* ---------------------------------------------------------------------------------------------------- */