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>
25 #include "gdbusobjectmanager.h"
26 #include "gdbusobjectmanagerserver.h"
27 #include "gdbusobject.h"
28 #include "gdbusobjectskeleton.h"
29 #include "gdbusinterfaceskeleton.h"
30 #include "gdbusconnection.h"
31 #include "gdbusintrospection.h"
32 #include "gdbusmethodinvocation.h"
33 #include "gdbuserror.h"
38 * SECTION:gdbusobjectmanagerserver
39 * @short_description: Service-side object manager
42 * #GDBusObjectManagerServer is used to export #GDBusObject instances using
43 * the standardized <ulink
44 * url="http://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-objectmanager">org.freedesktop.DBus.ObjectManager</ulink>
45 * interface. For example, remote D-Bus clients can get all objects
46 * and properties in a single call. Additionally, any change in the
47 * object hierarchy is broadcast using signals. This means that D-Bus
48 * clients can keep caches up to date by only listening to D-Bus
51 * See #GDBusObjectManagerClient for the client-side code that is
52 * intended to be used with #GDBusObjectManagerServer or any D-Bus
53 * object implementing the org.freedesktop.DBus.ObjectManager
59 GDBusObjectSkeleton *object;
60 GDBusObjectManagerServer *manager;
61 GHashTable *map_iface_name_to_iface;
65 static void registration_data_free (RegistrationData *data);
67 static void g_dbus_object_manager_server_emit_interfaces_added (GDBusObjectManagerServer *manager,
68 RegistrationData *data,
69 const gchar *const *interfaces);
71 static void g_dbus_object_manager_server_emit_interfaces_removed (GDBusObjectManagerServer *manager,
72 RegistrationData *data,
73 const gchar *const *interfaces);
75 struct _GDBusObjectManagerServerPrivate
77 GDBusConnection *connection;
79 gchar *object_path_ending_in_slash;
80 GHashTable *map_object_path_to_data;
91 static void dbus_object_manager_interface_init (GDBusObjectManagerIface *iface);
93 G_DEFINE_TYPE_WITH_CODE (GDBusObjectManagerServer, g_dbus_object_manager_server, G_TYPE_OBJECT,
94 G_IMPLEMENT_INTERFACE (G_TYPE_DBUS_OBJECT_MANAGER, dbus_object_manager_interface_init));
96 static void g_dbus_object_manager_server_constructed (GObject *object);
99 g_dbus_object_manager_server_finalize (GObject *object)
101 GDBusObjectManagerServer *manager = G_DBUS_OBJECT_MANAGER_SERVER (object);
103 g_hash_table_unref (manager->priv->map_object_path_to_data);
104 if (manager->priv->manager_reg_id > 0)
105 g_warn_if_fail (g_dbus_connection_unregister_object (manager->priv->connection, manager->priv->manager_reg_id));
106 g_object_unref (manager->priv->connection);
107 g_free (manager->priv->object_path);
108 g_free (manager->priv->object_path_ending_in_slash);
110 if (G_OBJECT_CLASS (g_dbus_object_manager_server_parent_class)->finalize != NULL)
111 G_OBJECT_CLASS (g_dbus_object_manager_server_parent_class)->finalize (object);
115 g_dbus_object_manager_server_get_property (GObject *_object,
120 GDBusObjectManagerServer *manager = G_DBUS_OBJECT_MANAGER_SERVER (_object);
124 case PROP_CONNECTION:
125 g_value_set_object (value, g_dbus_object_manager_server_get_connection (manager));
128 case PROP_OBJECT_PATH:
129 g_value_set_string (value, g_dbus_object_manager_get_object_path (G_DBUS_OBJECT_MANAGER (manager)));
133 G_OBJECT_WARN_INVALID_PROPERTY_ID (_object, prop_id, pspec);
139 g_dbus_object_manager_server_set_property (GObject *_object,
144 GDBusObjectManagerServer *manager = G_DBUS_OBJECT_MANAGER_SERVER (_object);
148 case PROP_CONNECTION:
149 g_assert (manager->priv->connection == NULL);
150 g_assert (G_IS_DBUS_CONNECTION (g_value_get_object (value)));
151 manager->priv->connection = g_value_dup_object (value);
154 case PROP_OBJECT_PATH:
155 g_assert (manager->priv->object_path == NULL);
156 g_assert (g_variant_is_object_path (g_value_get_string (value)));
157 manager->priv->object_path = g_value_dup_string (value);
158 manager->priv->object_path_ending_in_slash = g_strdup_printf ("%s/", manager->priv->object_path);
162 G_OBJECT_WARN_INVALID_PROPERTY_ID (_object, prop_id, pspec);
168 g_dbus_object_manager_server_class_init (GDBusObjectManagerServerClass *klass)
170 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
172 gobject_class->finalize = g_dbus_object_manager_server_finalize;
173 gobject_class->constructed = g_dbus_object_manager_server_constructed;
174 gobject_class->set_property = g_dbus_object_manager_server_set_property;
175 gobject_class->get_property = g_dbus_object_manager_server_get_property;
178 * GDBusObjectManagerServer:connection:
180 * The #GDBusConnection to export objects on.
184 g_object_class_install_property (gobject_class,
186 g_param_spec_object ("connection",
188 "The connection to export objects on",
189 G_TYPE_DBUS_CONNECTION,
192 G_PARAM_CONSTRUCT_ONLY |
193 G_PARAM_STATIC_STRINGS));
196 * GDBusObjectManagerServer:object-path:
198 * The object path to register the manager object at.
202 g_object_class_install_property (gobject_class,
204 g_param_spec_string ("object-path",
206 "The object path to register the manager object at",
210 G_PARAM_CONSTRUCT_ONLY |
211 G_PARAM_STATIC_STRINGS));
213 g_type_class_add_private (klass, sizeof (GDBusObjectManagerServerPrivate));
217 g_dbus_object_manager_server_init (GDBusObjectManagerServer *manager)
219 manager->priv = G_TYPE_INSTANCE_GET_PRIVATE (manager,
220 G_TYPE_DBUS_OBJECT_MANAGER_SERVER,
221 GDBusObjectManagerServerPrivate);
222 manager->priv->map_object_path_to_data = g_hash_table_new_full (g_str_hash,
225 (GDestroyNotify) registration_data_free);
229 * g_dbus_object_manager_server_new:
230 * @connection: A #GDBusConnection.
231 * @object_path: The object path to export the manager object at.
233 * Creates a new #GDBusObjectManagerServer object.
235 * TODO: make it so that the objects are not exported yet -
236 * e.g. start()/stop() semantics.
238 * Returns: A #GDBusObjectManagerServer object. Free with g_object_unref().
242 GDBusObjectManagerServer *
243 g_dbus_object_manager_server_new (GDBusConnection *connection,
244 const gchar *object_path)
246 g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);
247 g_return_val_if_fail (g_variant_is_object_path (object_path), NULL);
248 return G_DBUS_OBJECT_MANAGER_SERVER (g_object_new (G_TYPE_DBUS_OBJECT_MANAGER_SERVER,
249 "connection", connection,
250 "object-path", object_path,
255 * g_dbus_object_manager_server_get_connection:
256 * @manager: A #GDBusObjectManagerServer
258 * Gets the #GDBusConnection used by @manager.
260 * Returns: (transfer none): A #GDBusConnection object. Do not free,
261 * the object belongs to @manager.
266 g_dbus_object_manager_server_get_connection (GDBusObjectManagerServer *manager)
268 g_return_val_if_fail (G_IS_DBUS_OBJECT_MANAGER_SERVER (manager), NULL);
269 return manager->priv->connection;
272 /* ---------------------------------------------------------------------------------------------------- */
275 registration_data_export_interface (RegistrationData *data,
276 GDBusInterfaceSkeleton *interface_skeleton)
278 GDBusInterfaceInfo *info;
280 const gchar *object_path;
282 object_path = g_dbus_object_get_object_path (G_DBUS_OBJECT (data->object));
284 info = g_dbus_interface_skeleton_get_info (interface_skeleton);
286 if (!g_dbus_interface_skeleton_export (interface_skeleton,
287 data->manager->priv->connection,
291 /* TODO: probably wrong to complain on stderr */
292 g_warning ("%s: Error registering object at %s with interface %s: %s",
297 g_error_free (error);
301 g_assert (g_hash_table_lookup (data->map_iface_name_to_iface, info->name) == NULL);
302 g_hash_table_insert (data->map_iface_name_to_iface,
304 g_object_ref (interface_skeleton));
306 /* if we are already exported, then... */
309 const gchar *interfaces[2];
310 /* emit InterfacesAdded on the ObjectManager object */
311 interfaces[0] = info->name;
312 interfaces[1] = NULL;
313 g_dbus_object_manager_server_emit_interfaces_added (data->manager, data, interfaces);
321 registration_data_unexport_interface (RegistrationData *data,
322 GDBusInterfaceSkeleton *interface_skeleton)
324 GDBusInterfaceInfo *info;
325 GDBusInterfaceSkeleton *iface;
327 info = g_dbus_interface_skeleton_get_info (interface_skeleton);
328 iface = g_hash_table_lookup (data->map_iface_name_to_iface, info->name);
329 g_assert (iface != NULL);
331 g_dbus_interface_skeleton_unexport (iface);
333 g_warn_if_fail (g_hash_table_remove (data->map_iface_name_to_iface, info->name));
335 /* if we are already exported, then... */
338 const gchar *interfaces[2];
339 /* emit InterfacesRemoved on the ObjectManager object */
340 interfaces[0] = info->name;
341 interfaces[1] = NULL;
342 g_dbus_object_manager_server_emit_interfaces_removed (data->manager, data, interfaces);
346 /* ---------------------------------------------------------------------------------------------------- */
349 on_interface_added (GDBusObject *object,
350 GDBusInterface *interface,
353 RegistrationData *data = user_data;
354 registration_data_export_interface (data, G_DBUS_INTERFACE_SKELETON (interface));
358 on_interface_removed (GDBusObject *object,
359 GDBusInterface *interface,
362 RegistrationData *data = user_data;
363 registration_data_unexport_interface (data, G_DBUS_INTERFACE_SKELETON (interface));
366 /* ---------------------------------------------------------------------------------------------------- */
370 registration_data_free (RegistrationData *data)
373 GDBusInterfaceSkeleton *iface;
375 data->exported = FALSE;
377 g_hash_table_iter_init (&iter, data->map_iface_name_to_iface);
378 while (g_hash_table_iter_next (&iter, NULL, (gpointer) &iface))
379 g_dbus_interface_skeleton_unexport (iface);
381 g_signal_handlers_disconnect_by_func (data->object, G_CALLBACK (on_interface_added), data);
382 g_signal_handlers_disconnect_by_func (data->object, G_CALLBACK (on_interface_removed), data);
383 g_object_unref (data->object);
384 g_hash_table_destroy (data->map_iface_name_to_iface);
388 /* ---------------------------------------------------------------------------------------------------- */
391 * g_dbus_object_manager_server_export:
392 * @manager: A #GDBusObjectManagerServer.
393 * @object: A #GDBusObjectSkeleton.
395 * Exports @object on @manager.
397 * If there is already a #GDBusObject exported at the object path,
398 * then the old object is removed.
400 * The object path for @object must be in the hierarchy rooted by the
401 * object path for @manager.
403 * Note that @manager will take a reference on @object for as long as
409 g_dbus_object_manager_server_export (GDBusObjectManagerServer *manager,
410 GDBusObjectSkeleton *object)
412 RegistrationData *data;
413 GList *existing_interfaces;
415 GPtrArray *interface_names;
416 const gchar *object_path;
418 object_path = g_dbus_object_get_object_path (G_DBUS_OBJECT (object));
420 g_return_if_fail (G_IS_DBUS_OBJECT_MANAGER_SERVER (manager));
421 g_return_if_fail (G_IS_DBUS_OBJECT (object));
422 g_return_if_fail (g_str_has_prefix (object_path, manager->priv->object_path_ending_in_slash));
424 interface_names = g_ptr_array_new ();
426 data = g_hash_table_lookup (manager->priv->map_object_path_to_data, object_path);
428 g_dbus_object_manager_server_unexport (manager, object_path);
430 data = g_new0 (RegistrationData, 1);
431 data->object = g_object_ref (object);
432 data->manager = manager;
433 data->map_iface_name_to_iface = g_hash_table_new_full (g_str_hash,
436 (GDestroyNotify) g_object_unref);
438 g_signal_connect (object,
440 G_CALLBACK (on_interface_added),
442 g_signal_connect (object,
444 G_CALLBACK (on_interface_removed),
447 /* Register all known interfaces - note that data->exported is FALSE so
448 * we don't emit any InterfacesAdded signals.
450 existing_interfaces = g_dbus_object_get_interfaces (G_DBUS_OBJECT (object));
451 for (l = existing_interfaces; l != NULL; l = l->next)
453 GDBusInterfaceSkeleton *interface_skeleton = G_DBUS_INTERFACE_SKELETON (l->data);
454 registration_data_export_interface (data, interface_skeleton);
455 g_ptr_array_add (interface_names, g_dbus_interface_skeleton_get_info (interface_skeleton)->name);
457 g_list_foreach (existing_interfaces, (GFunc) g_object_unref, NULL);
458 g_list_free (existing_interfaces);
459 g_ptr_array_add (interface_names, NULL);
461 data->exported = TRUE;
463 /* now emit InterfacesAdded() for all the interfaces */
464 g_dbus_object_manager_server_emit_interfaces_added (manager, data, (const gchar *const *) interface_names->pdata);
465 g_ptr_array_unref (interface_names);
467 g_hash_table_insert (manager->priv->map_object_path_to_data,
468 g_strdup (object_path),
473 * g_dbus_object_manager_server_export_uniquely:
474 * @manager: A #GDBusObjectManagerServer.
475 * @object: An object.
477 * Like g_dbus_object_manager_server_export() but appends a string of
478 * the form <literal>_N</literal> (with N being a natural number) to
479 * @object<!-- -->'s object path if an object with the given path
480 * already exists. As such, the #GDBusObjectProxy:object-path property
481 * of @object may be modified.
486 g_dbus_object_manager_server_export_uniquely (GDBusObjectManagerServer *manager,
487 GDBusObjectSkeleton *object)
489 gchar *orig_object_path;
494 orig_object_path = g_strdup (g_dbus_object_get_object_path (G_DBUS_OBJECT (object)));
496 g_return_if_fail (G_IS_DBUS_OBJECT_MANAGER_SERVER (manager));
497 g_return_if_fail (G_IS_DBUS_OBJECT (object));
498 g_return_if_fail (g_str_has_prefix (orig_object_path, manager->priv->object_path_ending_in_slash));
500 object_path = g_strdup (orig_object_path);
505 RegistrationData *data;
506 data = g_hash_table_lookup (manager->priv->map_object_path_to_data, object_path);
511 g_free (object_path);
512 object_path = g_strdup_printf ("%s_%d", orig_object_path, count++);
517 g_dbus_object_skeleton_set_object_path (G_DBUS_OBJECT_SKELETON (object), object_path);
519 g_dbus_object_manager_server_export (manager, object);
521 g_free (object_path);
522 g_free (orig_object_path);
526 * g_dbus_object_manager_server_unexport:
527 * @manager: A #GDBusObjectManagerServer.
528 * @object_path: An object path.
530 * If @manager has an object at @path, removes the object. Otherwise
533 * Note that @object_path must be in the hierarchy rooted by the
534 * object path for @manager.
536 * Returns: %TRUE if object at @object_path was removed, %FALSE otherwise.
541 g_dbus_object_manager_server_unexport (GDBusObjectManagerServer *manager,
542 const gchar *object_path)
544 RegistrationData *data;
547 g_return_val_if_fail (G_IS_DBUS_OBJECT_MANAGER_SERVER (manager), FALSE);
548 g_return_val_if_fail (g_variant_is_object_path (object_path), FALSE);
549 g_return_val_if_fail (g_str_has_prefix (object_path, manager->priv->object_path_ending_in_slash), FALSE);
553 data = g_hash_table_lookup (manager->priv->map_object_path_to_data, object_path);
556 GPtrArray *interface_names;
558 const gchar *iface_name;
560 interface_names = g_ptr_array_new ();
561 g_hash_table_iter_init (&iter, data->map_iface_name_to_iface);
562 while (g_hash_table_iter_next (&iter, (gpointer) &iface_name, NULL))
563 g_ptr_array_add (interface_names, (gpointer) iface_name);
564 g_ptr_array_add (interface_names, NULL);
565 /* now emit InterfacesRemoved() for all the interfaces */
566 g_dbus_object_manager_server_emit_interfaces_removed (manager, data, (const gchar *const *) interface_names->pdata);
567 g_ptr_array_unref (interface_names);
569 g_hash_table_remove (manager->priv->map_object_path_to_data, object_path);
577 /* ---------------------------------------------------------------------------------------------------- */
579 static const GDBusArgInfo manager_interfaces_added_signal_info_arg0 =
584 (GDBusAnnotationInfo**) NULL,
587 static const GDBusArgInfo manager_interfaces_added_signal_info_arg1 =
590 "interfaces_and_properties",
592 (GDBusAnnotationInfo**) NULL,
595 static const GDBusArgInfo * const manager_interfaces_added_signal_info_arg_pointers[] =
597 &manager_interfaces_added_signal_info_arg0,
598 &manager_interfaces_added_signal_info_arg1,
602 static const GDBusSignalInfo manager_interfaces_added_signal_info =
606 (GDBusArgInfo**) &manager_interfaces_added_signal_info_arg_pointers,
607 (GDBusAnnotationInfo**) NULL
612 static const GDBusArgInfo manager_interfaces_removed_signal_info_arg0 =
617 (GDBusAnnotationInfo**) NULL,
620 static const GDBusArgInfo manager_interfaces_removed_signal_info_arg1 =
625 (GDBusAnnotationInfo**) NULL,
628 static const GDBusArgInfo * const manager_interfaces_removed_signal_info_arg_pointers[] =
630 &manager_interfaces_removed_signal_info_arg0,
631 &manager_interfaces_removed_signal_info_arg1,
635 static const GDBusSignalInfo manager_interfaces_removed_signal_info =
639 (GDBusArgInfo**) &manager_interfaces_removed_signal_info_arg_pointers,
640 (GDBusAnnotationInfo**) NULL
645 static const GDBusSignalInfo * const manager_signal_info_pointers[] =
647 &manager_interfaces_added_signal_info,
648 &manager_interfaces_removed_signal_info,
654 static const GDBusArgInfo manager_get_all_method_info_out_arg0 =
657 "object_paths_interfaces_and_properties",
659 (GDBusAnnotationInfo**) NULL,
662 static const GDBusArgInfo * const manager_get_all_method_info_out_arg_pointers[] =
664 &manager_get_all_method_info_out_arg0,
668 static const GDBusMethodInfo manager_get_all_method_info =
672 (GDBusArgInfo**) NULL,
673 (GDBusArgInfo**) &manager_get_all_method_info_out_arg_pointers,
674 (GDBusAnnotationInfo**) NULL
677 static const GDBusMethodInfo * const manager_method_info_pointers[] =
679 &manager_get_all_method_info,
685 static const GDBusInterfaceInfo manager_interface_info =
688 "org.freedesktop.DBus.ObjectManager",
689 (GDBusMethodInfo **) manager_method_info_pointers,
690 (GDBusSignalInfo **) manager_signal_info_pointers,
691 (GDBusPropertyInfo **) NULL,
692 (GDBusAnnotationInfo **) NULL
696 manager_method_call (GDBusConnection *connection,
698 const gchar *object_path,
699 const gchar *interface_name,
700 const gchar *method_name,
701 GVariant *parameters,
702 GDBusMethodInvocation *invocation,
705 GDBusObjectManagerServer *manager = G_DBUS_OBJECT_MANAGER_SERVER (user_data);
706 GVariantBuilder array_builder;
707 GHashTableIter object_iter;
708 RegistrationData *data;
710 if (g_strcmp0 (method_name, "GetManagedObjects") == 0)
712 g_variant_builder_init (&array_builder, G_VARIANT_TYPE ("a{oa{sa{sv}}}"));
713 g_hash_table_iter_init (&object_iter, manager->priv->map_object_path_to_data);
714 while (g_hash_table_iter_next (&object_iter, NULL, (gpointer) &data))
716 GVariantBuilder interfaces_builder;
717 GHashTableIter interface_iter;
718 GDBusInterfaceSkeleton *iface;
719 const gchar *iter_object_path;
721 g_variant_builder_init (&interfaces_builder, G_VARIANT_TYPE ("a{sa{sv}}"));
722 g_hash_table_iter_init (&interface_iter, data->map_iface_name_to_iface);
723 while (g_hash_table_iter_next (&interface_iter, NULL, (gpointer) &iface))
725 g_variant_builder_add_value (&interfaces_builder,
726 g_variant_new ("{s@a{sv}}",
727 g_dbus_interface_skeleton_get_info (iface)->name,
728 g_dbus_interface_skeleton_get_properties (iface)));
730 iter_object_path = g_dbus_object_get_object_path (G_DBUS_OBJECT (data->object));
731 g_variant_builder_add (&array_builder,
734 &interfaces_builder);
737 g_dbus_method_invocation_return_value (invocation,
738 g_variant_new ("(a{oa{sa{sv}}})",
743 g_dbus_method_invocation_return_error (invocation,
745 G_DBUS_ERROR_UNKNOWN_METHOD,
746 "Unknown method %s - only GetManagedObjects() is supported",
751 static const GDBusInterfaceVTable manager_interface_vtable =
753 manager_method_call, /* handle_method_call */
754 NULL, /* get_property */
755 NULL /* set_property */
758 /* ---------------------------------------------------------------------------------------------------- */
761 g_dbus_object_manager_server_constructed (GObject *object)
763 GDBusObjectManagerServer *manager = G_DBUS_OBJECT_MANAGER_SERVER (object);
767 manager->priv->manager_reg_id = g_dbus_connection_register_object (manager->priv->connection,
768 manager->priv->object_path,
769 (GDBusInterfaceInfo *) &manager_interface_info,
770 &manager_interface_vtable,
772 NULL, /* user_data_free_func */
774 if (manager->priv->manager_reg_id == 0)
776 /* TODO: probably wrong to complain on stderr */
777 g_warning ("%s: Error registering manager at %s: %s",
779 manager->priv->object_path,
781 g_error_free (error);
784 if (G_OBJECT_CLASS (g_dbus_object_manager_server_parent_class)->constructed != NULL)
785 G_OBJECT_CLASS (g_dbus_object_manager_server_parent_class)->constructed (object);
789 g_dbus_object_manager_server_emit_interfaces_added (GDBusObjectManagerServer *manager,
790 RegistrationData *data,
791 const gchar *const *interfaces)
793 GVariantBuilder array_builder;
796 const gchar *object_path;
798 g_variant_builder_init (&array_builder, G_VARIANT_TYPE ("a{sa{sv}}"));
799 for (n = 0; interfaces[n] != NULL; n++)
801 GDBusInterfaceSkeleton *iface;
802 iface = g_hash_table_lookup (data->map_iface_name_to_iface, interfaces[n]);
803 g_assert (iface != NULL);
804 g_variant_builder_add_value (&array_builder,
805 g_variant_new ("{s@a{sv}}",
807 g_dbus_interface_skeleton_get_properties (iface)));
811 object_path = g_dbus_object_get_object_path (G_DBUS_OBJECT (data->object));
812 g_dbus_connection_emit_signal (data->manager->priv->connection,
813 NULL, /* destination_bus_name */
814 manager->priv->object_path,
815 manager_interface_info.name,
817 g_variant_new ("(oa{sa{sv}})",
821 g_assert_no_error (error);
825 g_dbus_object_manager_server_emit_interfaces_removed (GDBusObjectManagerServer *manager,
826 RegistrationData *data,
827 const gchar *const *interfaces)
829 GVariantBuilder array_builder;
832 const gchar *object_path;
834 g_variant_builder_init (&array_builder, G_VARIANT_TYPE ("as"));
835 for (n = 0; interfaces[n] != NULL; n++)
836 g_variant_builder_add (&array_builder, "s", interfaces[n]);
839 object_path = g_dbus_object_get_object_path (G_DBUS_OBJECT (data->object));
840 g_dbus_connection_emit_signal (data->manager->priv->connection,
841 NULL, /* destination_bus_name */
842 manager->priv->object_path,
843 manager_interface_info.name,
845 g_variant_new ("(oas)",
849 g_assert_no_error (error);
852 /* ---------------------------------------------------------------------------------------------------- */
855 g_dbus_object_manager_server_get_objects (GDBusObjectManager *_manager)
857 GDBusObjectManagerServer *manager = G_DBUS_OBJECT_MANAGER_SERVER (_manager);
860 RegistrationData *data;
863 g_hash_table_iter_init (&iter, manager->priv->map_object_path_to_data);
864 while (g_hash_table_iter_next (&iter, NULL, (gpointer) &data))
866 ret = g_list_prepend (ret, g_object_ref (data->object));
873 g_dbus_object_manager_server_get_object_path (GDBusObjectManager *_manager)
875 GDBusObjectManagerServer *manager = G_DBUS_OBJECT_MANAGER_SERVER (_manager);
876 return manager->priv->object_path;
880 g_dbus_object_manager_server_get_object (GDBusObjectManager *_manager,
881 const gchar *object_path)
883 GDBusObjectManagerServer *manager = G_DBUS_OBJECT_MANAGER_SERVER (_manager);
885 RegistrationData *data;
888 data = g_hash_table_lookup (manager->priv->map_object_path_to_data, object_path);
890 ret = g_object_ref (data->object);
894 static GDBusInterface *
895 g_dbus_object_manager_server_get_interface (GDBusObjectManager *_manager,
896 const gchar *object_path,
897 const gchar *interface_name)
904 object = g_dbus_object_manager_get_object (_manager, object_path);
908 ret = g_dbus_object_get_interface (object, interface_name);
909 g_object_unref (object);
916 dbus_object_manager_interface_init (GDBusObjectManagerIface *iface)
918 iface->get_object_path = g_dbus_object_manager_server_get_object_path;
919 iface->get_objects = g_dbus_object_manager_server_get_objects;
920 iface->get_object = g_dbus_object_manager_server_get_object;
921 iface->get_interface = g_dbus_object_manager_server_get_interface;