After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 643489 - gio-2.0 GDBus subtree function and data fixes
gio-2.0 GDBus subtree function and data fixes
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Bindings
0.11.x
Other Linux
: Normal major
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks: 644751 644779
 
 
Reported: 2011-02-28 14:01 UTC by Marco Trevisan (Treviño)
Modified: 2012-01-22 08:42 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gio-2.0 fixed subtree functions, fixed for real usage (8.83 KB, patch)
2011-02-28 14:01 UTC, Marco Trevisan (Treviño)
none Details | Review
gio-2.0 fixed subtree functions for valid vtable usage v2 (6.53 KB, patch)
2011-03-14 18:14 UTC, Marco Trevisan (Treviño)
none Details | Review
gio-2.0 fixed subtree functions for valid vtable usage v3 (9.77 KB, patch)
2011-03-14 18:18 UTC, Marco Trevisan (Treviño)
none Details | Review

Description Marco Trevisan (Treviño) 2011-02-28 14:01:41 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 ();
}
Comment 1 Marco Trevisan (Treviño) 2011-03-14 18:14:24 UTC
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
Comment 2 Marco Trevisan (Treviño) 2011-03-14 18:18:25 UTC
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
Comment 3 Marco Trevisan (Treviño) 2011-03-15 01:09:40 UTC
When patches for bug 644420 this patch can be improved, removing some custom code and just using metadata for delegates.
Comment 4 Evan Nemerson 2012-01-22 08:42:21 UTC
commit 132d0a4eae887462d1f8fc885c3d9a66ef383d78
Author: Evan Nemerson <evan@coeus-group.com>
Date:   Wed Jan 11 22:41:43 2012 -0800

    gio-2.0: switch to GIR