2 #include "gdbus-object-manager-example/gdbus-example-objectmanager-generated.h"
4 /* ---------------------------------------------------------------------------------------------------- */
7 print_objects (GDBusObjectManager *manager)
12 g_print ("Object manager at %s\n", g_dbus_object_manager_get_object_path (manager));
13 objects = g_dbus_object_manager_get_objects (manager);
14 for (l = objects; l != NULL; l = l->next)
16 ExampleObject *object = EXAMPLE_OBJECT (l->data);
19 g_print (" - Object at %s\n", g_dbus_object_get_object_path (G_DBUS_OBJECT (object)));
21 interfaces = g_dbus_object_get_interfaces (G_DBUS_OBJECT (object));
22 for (ll = interfaces; ll != NULL; ll = ll->next)
24 GDBusInterface *interface = G_DBUS_INTERFACE (ll->data);
25 g_print (" - Interface %s\n", g_dbus_interface_get_info (interface)->name);
27 /* Note that @interface is really a GDBusProxy instance - and additionally also
28 * an ExampleAnimal or ExampleCat instance - either of these can be used to
29 * invoke methods on the remote object. For example, the generated function
31 * void example_animal_call_poke_sync (ExampleAnimal *proxy,
33 * gboolean make_happy,
34 * GCancellable *cancellable,
37 * can be used to call the Poke() D-Bus method on the .Animal interface.
38 * Additionally, the generated function
40 * const gchar *example_animal_get_mood (ExampleAnimal *object);
42 * can be used to get the value of the :Mood property.
45 g_list_free_full (interfaces, g_object_unref);
47 g_list_free_full (objects, g_object_unref);
51 on_object_added (GDBusObjectManager *manager,
56 owner = g_dbus_object_manager_client_get_name_owner (G_DBUS_OBJECT_MANAGER_CLIENT (manager));
57 g_print ("Added object at %s (owner %s)\n", g_dbus_object_get_object_path (object), owner);
62 on_object_removed (GDBusObjectManager *manager,
67 owner = g_dbus_object_manager_client_get_name_owner (G_DBUS_OBJECT_MANAGER_CLIENT (manager));
68 g_print ("Removed object at %s (owner %s)\n", g_dbus_object_get_object_path (object), owner);
73 on_notify_name_owner (GObject *object,
77 GDBusObjectManagerClient *manager = G_DBUS_OBJECT_MANAGER_CLIENT (object);
80 name_owner = g_dbus_object_manager_client_get_name_owner (manager);
81 g_print ("name-owner: %s\n", name_owner);
86 on_interface_proxy_properties_changed (GDBusObjectManagerClient *manager,
87 GDBusObjectProxy *object_proxy,
88 GDBusProxy *interface_proxy,
89 GVariant *changed_properties,
90 const gchar *const *invalidated_properties,
98 g_print ("Properties Changed on %s:\n", g_dbus_object_get_object_path (G_DBUS_OBJECT (object_proxy)));
99 g_variant_iter_init (&iter, changed_properties);
100 while (g_variant_iter_next (&iter, "{&sv}", &key, &value))
102 s = g_variant_print (value, TRUE);
103 g_print (" %s -> %s\n", key, s);
104 g_variant_unref (value);
110 main (gint argc, gchar *argv[])
112 GDBusObjectManager *manager;
120 loop = g_main_loop_new (NULL, FALSE);
123 manager = example_object_manager_client_new_for_bus_sync (G_BUS_TYPE_SESSION,
124 G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE,
125 "org.gtk.GDBus.Examples.ObjectManager",
127 NULL, /* GCancellable */
131 g_printerr ("Error getting object manager client: %s", error->message);
132 g_error_free (error);
136 name_owner = g_dbus_object_manager_client_get_name_owner (G_DBUS_OBJECT_MANAGER_CLIENT (manager));
137 g_print ("name-owner: %s\n", name_owner);
140 print_objects (manager);
142 g_signal_connect (manager,
143 "notify::name-owner",
144 G_CALLBACK (on_notify_name_owner),
146 g_signal_connect (manager,
148 G_CALLBACK (on_object_added),
150 g_signal_connect (manager,
152 G_CALLBACK (on_object_removed),
154 g_signal_connect (manager,
155 "interface-proxy-properties-changed",
156 G_CALLBACK (on_interface_proxy_properties_changed),
159 g_main_loop_run (loop);
163 g_object_unref (manager);
165 g_main_loop_unref (loop);