-#include "gdbus-example-objectmanager-generated.h"
+#include "gdbus-object-manager-example/objectmanager-gen.h"
/* ---------------------------------------------------------------------------------------------------- */
gboolean make_happy,
gpointer user_data)
{
-
if ((make_sad && make_happy) || (!make_sad && !make_happy))
{
g_dbus_method_invocation_return_dbus_error (invocation,
const gchar *name,
gpointer user_data)
{
- GDBusObjectStub *object;
+ ExampleObjectSkeleton *object;
guint n;
- g_debug ("bus acquired");
+ g_print ("Acquired a message bus connection\n");
+
+ /* Create a new org.freedesktop.DBus.ObjectManager rooted at /example/Animals */
+ manager = g_dbus_object_manager_server_new ("/example/Animals");
- manager = g_dbus_object_manager_server_new (connection, "/example/Animals");
for (n = 0; n < 10; n++)
{
gchar *s;
ExampleAnimal *animal;
+ /* Create a new D-Bus object at the path /example/Animals/N where N is 000..009 */
s = g_strdup_printf ("/example/Animals/%03d", n);
- object = g_dbus_object_stub_new (s);
+ object = example_object_skeleton_new (s);
g_free (s);
- animal = example_animal_stub_new ();
+ /* Make the newly created object export the interface
+ * org.gtk.GDBus.Example.ObjectManager.Animal (note
+ * that @object takes its own reference to @animal).
+ */
+ animal = example_animal_skeleton_new ();
example_animal_set_mood (animal, "Happy");
+ example_object_skeleton_set_animal (object, animal);
+ g_object_unref (animal);
+
+ /* Cats are odd animals - so some of our objects implement the
+ * org.gtk.GDBus.Example.ObjectManager.Cat interface in addition
+ * to the .Animal interface
+ */
+ if (n % 2 == 1)
+ {
+ ExampleCat *cat;
+ cat = example_cat_skeleton_new ();
+ example_object_skeleton_set_cat (object, cat);
+ g_object_unref (cat);
+ }
- /* Handle Poke() method invocations */
+ /* Handle Poke() D-Bus method invocations on the .Animal interface */
g_signal_connect (animal,
"handle-poke",
G_CALLBACK (on_animal_poke),
NULL); /* user_data */
- g_dbus_object_stub_add_interface (object, G_DBUS_INTERFACE_STUB (animal));
- g_object_unref (animal);
-
- g_dbus_object_manager_server_export (manager, object);
+ /* Export the object (@manager takes its own reference to @object) */
+ g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object));
g_object_unref (object);
}
+
+ /* Export all objects */
+ g_dbus_object_manager_server_set_connection (manager, connection);
}
static void
const gchar *name,
gpointer user_data)
{
- g_debug ("name acquired");
+ g_print ("Acquired the name %s\n", name);
}
static void
const gchar *name,
gpointer user_data)
{
- g_debug ("name lost");
+ g_print ("Lost the name %s\n", name);
}
GMainLoop *loop;
guint id;
- g_type_init ();
-
loop = g_main_loop_new (NULL, FALSE);
id = g_bus_own_name (G_BUS_TYPE_SESSION,