diff --git a/source/ddbus/router.d b/source/ddbus/router.d index 49744ba..a712334 100644 --- a/source/ddbus/router.d +++ b/source/ddbus/router.d @@ -99,7 +99,10 @@ class MessageRouter { auto retMsg = call.createReturn(); static if(!is(Ret == void)) { Ret ret = handler(args.expand); - retMsg.build(ret); + static if (is(Ret == Tuple!T, T...)) + retMsg.build!T(ret.expand); + else + retMsg.build(ret); } else { handler(args.expand); } @@ -110,7 +113,7 @@ class MessageRouter { static if(is(Ret==void)) { static string[] ret = []; } else { - static string[] ret = [typeSig!Ret]; + static string[] ret = typeSigReturn!Ret; } MessageHandler handleStruct = {func: &handlerWrapper, argSig: args, retSig: ret}; callTable[patt] = handleStruct; @@ -199,12 +202,17 @@ unittest{ router.setHandler!(void,int,string)(patt,(int p, string p2) {}); patt = MessagePattern("/root/wat","ca.thume.tester","lolwut"); router.setHandler!(int,int)(patt,(int p) {return 6;}); + patt = MessagePattern("/root/foo","ca.thume.tester","lolwut"); + router.setHandler!(Tuple!(string,string,int),int)(patt,(int p) {Tuple!(string,string,int) ret; ret[0] = "a"; ret[1] = "b"; ret[2] = p; return ret;}); patt = MessagePattern("/troll","ca.thume.tester","wow"); router.setHandler!(void)(patt,{return;}); // TODO: these tests rely on nondeterministic hash map ordering static string introspectResult = ` -`; +`; router.introspectXML("/root").assertEqual(introspectResult); + static string introspectResult2 = ` +`; + router.introspectXML("/root/foo").assertEqual(introspectResult2); router.introspectXML("/").assertEndsWith(``); } diff --git a/source/ddbus/util.d b/source/ddbus/util.d index c2b0065..6a77432 100644 --- a/source/ddbus/util.d +++ b/source/ddbus/util.d @@ -98,6 +98,13 @@ string typeSig(T)() if(canDBus!T) { } } +string[] typeSigReturn(T)() if(canDBus!T) { + static if(is(T == Tuple!TS, TS...)) + return typeSigArr!TS; + else + return [typeSig!T]; +} + string typeSigAll(TS...)() if(allCanDBus!TS) { string sig = ""; foreach(i,T; TS) {