GNOME Bugzilla – Bug 643489
gio-2.0 GDBus subtree function and data fixes
Last modified: 2012-01-22 08:42:21 UTC
Created attachment 182092 [details] [review] gio-2.0 fixed subtree functions, fixed for real usage GDBusInterfaceVTable and GDBusSubtreeVTable should be structs as they can't be created with no other way if they were considered classes. The delegates were wrong, since they should return arrays (of pointers) not just pointers. Patch attached fixes this, allowing to use code like this: ============================================================================ const string introspection_xml = """<node> <interface name='org.example.SubtreeDemo'> <method name='Hello'>" <arg type='s' name='greeting' direction='in'/> <arg type='s' name='response' direction='out'/> </method>" </interface> </node>"""; const string introspection_xml2 = """<node> <interface name='org.example.SubtreeDemo2'> <method name='Hello2'>" <arg type='s' name='greeting2' direction='in'/> <arg type='s' name='response2' direction='out'/> </method>" </interface> <interface name='org.example.SubtreeDemo3'> <method name='Hello3'>" <arg type='s' name='greeting3' direction='in'/> <arg type='i' name='greeting4' direction='in'/> <arg type='s' name='response3' direction='out'/> <arg type='i' name='response4' direction='out'/> </method>" </interface> </node>"""; const string[] sub_nodes = {"aaa", "bbb", "Oooooook"}; DBusInterfaceInfo[] interface_info; const DBusInterfaceVTable ivtable = { null, null, null }; const DBusSubtreeVTable treetable = {enumerate, introspect, dispatch}; unowned DBusInterfaceVTable? dispatch(GLib.DBusConnection connection, string sender, string object_path, string interface_name, string node, void* out_user_data) { print(@"Dispatch $sender, $object_path, $interface_name, $node\n"); if (ivtable.method_call == null) return null; return ivtable; } [CCode (array_length = false, array_null_terminated = true)] string[]? enumerate(GLib.DBusConnection connection, string sender, string object_path) { print(@"Enumerate $sender, $object_path\n"); string[] services = {}; foreach (var s in sub_nodes) services += s; services += null; return services; } [CCode (array_length = false, array_null_terminated = true)] DBusInterfaceInfo[]? introspect(GLib.DBusConnection connection, string sender, string object_path, string? node) { print(@"Introspect $sender, $object_path, %s\n".printf(node)); DBusInterfaceInfo[] interfaces = {}; foreach (var i in interface_info) interfaces += i; interfaces += null; return interfaces; } void on_bus_aquired (DBusConnection conn) { try { var introspection_data = new DBusNodeInfo.for_xml(introspection_xml); interface_info = {}; interface_info += introspection_data.lookup_interface("org.example.SubtreeDemo"); introspection_data = new DBusNodeInfo.for_xml(introspection_xml2); foreach (var id in introspection_data.interfaces) interface_info += id; conn.register_subtree("/org/example/demo/subtree", treetable, GLib.DBusSubtreeFlags.DISPATCH_TO_UNENUMERATED_NODES); } catch (Error e) { stderr.printf ("Could not register service\n"); } } void main () { Bus.own_name (BusType.SESSION, "org.example.Demo", BusNameOwnerFlags.NONE, on_bus_aquired, () => {}, () => stderr.printf ("Could not aquire name\n")); new MainLoop ().run (); }
Created attachment 183366 [details] [review] gio-2.0 fixed subtree functions for valid vtable usage v2 Previous patch fixed, removing some auto-generated invalid code. Now a subtree can be created using DBusConnection.register_subtree_vtable
Created attachment 183369 [details] [review] gio-2.0 fixed subtree functions for valid vtable usage v3 New patch version, I forgot to include some data in the previous one... Sorry. :P
When patches for bug 644420 this patch can be improved, removing some custom code and just using metadata for delegates.
commit 132d0a4eae887462d1f8fc885c3d9a66ef383d78 Author: Evan Nemerson <evan@coeus-group.com> Date: Wed Jan 11 22:41:43 2012 -0800 gio-2.0: switch to GIR