diff --git a/Rakefile b/Rakefile index 78a8cf2..79db177 100644 --- a/Rakefile +++ b/Rakefile @@ -2,6 +2,10 @@ task :testCall do sh "dbus-send --type=method_call --print-reply --dest=ca.thume.ddbus.test /root ca.thume.test.test int32:5" end +task :badCall do + sh "dbus-send --type=method_call --print-reply --dest=ca.thume.ddbus.test /root ca.thume.test.test double:5.5" +end + task :testSignal do sh "dbus-send --dest=ca.thume.ddbus.test /signaler ca.thume.test.signal int32:9" end diff --git a/source/ddbus/router.d b/source/ddbus/router.d index 3489aef..92114f9 100644 --- a/source/ddbus/router.d +++ b/source/ddbus/router.d @@ -2,9 +2,12 @@ module ddbus.router; import ddbus.thin; import ddbus.c_lib; +import ddbus.util; import std.string; import std.typecons; import core.memory; +import std.array; +import std.algorithm; struct MessagePattern { string path; @@ -41,9 +44,15 @@ struct MessagePattern { } } -class MessageRouter { +struct MessageHandler { alias HandlerFunc = void delegate(Message call, Connection conn); - HandlerFunc[MessagePattern] callTable; + HandlerFunc func; + string[] argSig; + string[] retSig; +} + +class MessageRouter { + MessageHandler[MessagePattern] callTable; bool handle(Message msg, Connection conn) { MessageType type = msg.type(); @@ -51,9 +60,19 @@ class MessageRouter { return false; auto pattern = MessagePattern(msg); // import std.stdio; debug writeln("Handling ", pattern); - HandlerFunc* handler = (pattern in callTable); + MessageHandler* handler = (pattern in callTable); if(handler is null) return false; - (*handler)(msg,conn); + + // Check for matching argument types + version(DDBusNoChecking) { + + } else { + if(!equal(join(handler.argSig), msg.signature())) { + return false; + } + } + + handler.func(msg,conn); return true; } @@ -70,7 +89,14 @@ class MessageRouter { if(!patt.signal) conn.send(retMsg); } - callTable[patt] = &handlerWrapper; + static string[] args = typeSigArr!Args; + static if(is(Ret==void)) { + static string[] ret = []; + } else { + static string[] ret = [typeSig!Ret]; + } + MessageHandler handleStruct = {func: &handlerWrapper, argSig: args, retSig: ret}; + callTable[patt] = handleStruct; } } diff --git a/source/ddbus/util.d b/source/ddbus/util.d index c30bde2..1161b3f 100644 --- a/source/ddbus/util.d +++ b/source/ddbus/util.d @@ -86,6 +86,14 @@ string typeSigAll(TS...)() if(allCanDBus!TS) { return sig; } +string[] typeSigArr(TS...)() if(allCanDBus!TS) { + string[] sig = []; + foreach(i,T; TS) { + sig ~= typeSig!T(); + } + return sig; +} + int typeCode(T)() if(canDBus!T) { string sig = typeSig!T(); return sig[0];