From 8771b8b2b1076203f7e7311bd50bcecfaea4450f Mon Sep 17 00:00:00 2001 From: Tristan Hume Date: Sun, 3 May 2015 20:52:55 -0400 Subject: [PATCH] Reply to introspection messages. --- source/ddbus/router.d | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/source/ddbus/router.d b/source/ddbus/router.d index 269a95a..58499e5 100644 --- a/source/ddbus/router.d +++ b/source/ddbus/router.d @@ -73,7 +73,7 @@ class MessageRouter { if(pattern.iface == "org.freedesktop.DBus.Introspectable" && pattern.method == "Introspect" && !pattern.signal) { - handleIntrospect(pattern.path, conn); + handleIntrospect(pattern.path, msg, conn); return true; } @@ -116,9 +116,7 @@ class MessageRouter { callTable[patt] = handleStruct; } - static string introspectHeader = ` - + static string introspectHeader = ` `; string introspectXML(string path) { @@ -144,10 +142,14 @@ class MessageRouter { app.put(""); } - string childPath = path ~ "/"; + string childPath = path; + if(!childPath.endsWith("/")) { + childPath ~= "/"; + } auto children = callTable.byKey().filter!(a => (a.path.startsWith(childPath)) && !a.signal)() .map!((s) => s.path.chompPrefix(childPath)) - .map!((s) => s.splitter('/').front); + .map!((s) => s.splitter('/').front) + .uniq(); foreach(child; children) { formattedWrite(app,``,child); } @@ -156,8 +158,10 @@ class MessageRouter { return app.data; } - void handleIntrospect(string path, Connection conn) { - // TODO + void handleIntrospect(string path, Message call, Connection conn) { + auto retMsg = call.createReturn(); + retMsg.build(introspectXML(path)); + conn.sendBlocking(retMsg); } } @@ -196,6 +200,8 @@ unittest{ patt = MessagePattern("/root/wat","ca.thume.tester","lolwut"); router.setHandler!(int,int)(patt,(int p) {return 6;}); - // import std.stdio; - // writeln(router.introspectXML("/root")); + static string introspectResult = ` +`; + router.introspectXML("/root").assertEqual(introspectResult); + router.introspectXML("/").assertEndsWith(``); }