From 2d75583fb2a8fdb71b9ee880dc0cf4605ab7bc6c Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 13 May 2010 01:04:29 -0400 Subject: [PATCH] Fill out the export section of the migration guide --- docs/reference/gio/migrating-gdbus.xml | 66 ++++++++++++++++++++++++++ gio/tests/gdbus-example-export.c | 6 ++- 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/docs/reference/gio/migrating-gdbus.xml b/docs/reference/gio/migrating-gdbus.xml index 48a87fc9b..14e70b702 100644 --- a/docs/reference/gio/migrating-gdbus.xml +++ b/docs/reference/gio/migrating-gdbus.xml @@ -287,6 +287,72 @@ on_proxy_appeared (GDBusConnection *connection,
Exporting objects + + + With dbus-glib, exporting an object over D-Bus works by generating + a bunch of glue code from your introspection XML with + dbus-binding-tool. The glue code gets included in + your source, and you need to call + + dbus_g_object_type_install_info (TYPE_MYOBJECT, + &dbus_glib_myobject_object_info); + + in your class_init() function to tell dbus-glib about your type. + To actually export an instance, you call + + dbus_g_connection_register_g_object (system_bus_connection, + my_object_path, + G_OBJECT (my_object)); + + + + + The GDBus way of exporting an object works by embedding the + introspection XML in the source, creating introspection data + structures from it with g_dbus_node_info_new_for_xml(), and + passing that along when you register the object: + " + " " + " " + " " + " " + " " + " " + ""; + + /* parse introspection data */ + introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL); + + / + id = g_dbus_connection_register_object (connection, + "/org/gtk/GDBus/TestObject", + "org.gtk.GDBus.TestPeerInterface", + introspection_data->interfaces[0], + &interface_vtable, + NULL, /* user_data */ + NULL, /* user_data_free_func */ + NULL); /* GError** */ + +]]> + + + + The actual implementation of the exported object is done by specifying + a #GDBusInterfaceVTable that has method_call(), get_property() and + set_property() methods. There is no direct support beyond that for + exporting #GObjects, so there is quite a bit of manual work involved, + as you can see in the following example. + + + Since the VTable methods don't have any direct #GObject support, we + pass the exported object as @user_data. Also note that we have to handle + the emission of the PropertiesChanged signal ourselves, by connecting + to ::notify. + + Exporting a GObjectFIXME: MISSING XINCLUDE CONTENT
diff --git a/gio/tests/gdbus-example-export.c b/gio/tests/gdbus-example-export.c index 5965ed8ce..0f222cebf 100644 --- a/gio/tests/gdbus-example-export.c +++ b/gio/tests/gdbus-example-export.c @@ -1,7 +1,7 @@ #include #include -* ---------------------------------------------------------------------------------------------------- */ +/* ---------------------------------------------------------------------------------------------------- */ /* The object we want to export */ typedef struct _MyObjectClass MyObjectClass; @@ -129,6 +129,8 @@ my_object_change_count (MyObject *myobj, g_object_notify (G_OBJECT (myobj), "count"); } +/* ---------------------------------------------------------------------------------------------------- */ + static GDBusNodeInfo *introspection_data = NULL; /* Introspection data for the service we are exporting */ @@ -247,7 +249,7 @@ send_property_change (GObject *obj, g_dbus_connection_emit_signal (connection, NULL, "/org/myorg/MyObject", - "org.myorg.MyObject", + "org.freedesktop.DBus.Properties", "PropertiesChanged", g_variant_new ("(sa{sv})", "org.myorg.MyObject",