From 9a73bcaad2b6c6a65eeb4c864415256f7f927e53 Mon Sep 17 00:00:00 2001 From: Tristan Hume Date: Wed, 29 Apr 2015 18:34:01 -0400 Subject: [PATCH] Added simple wrapper for calling DBus interfaces. --- source/ddbus/simple.d | 43 +++++++++++++++++++++++++++++++++++++++++++ source/ddbus/thin.d | 1 + 2 files changed, 44 insertions(+) create mode 100644 source/ddbus/simple.d diff --git a/source/ddbus/simple.d b/source/ddbus/simple.d new file mode 100644 index 0000000..7f6eb3d --- /dev/null +++ b/source/ddbus/simple.d @@ -0,0 +1,43 @@ +module ddbus.simple; + +import ddbus.thin; +import ddbus.util; +import ddbus.c_lib; +import std.string; + +class PathIface { + this(Connection conn, string dest, string path, string iface) { + this.conn = conn; + this.dest = dest.toStringz(); + this.path = path.toStringz(); + this.iface = iface.toStringz(); + } + + Ret call(Ret, Args...)(string meth, Args args) if(allCanDBus!Args && canDBus!Ret) { + Message msg = new Message(dbus_message_new_method_call(dest,path,iface,meth.toStringz())); + msg.build(args); + Message ret = conn.sendWithReplyBlocking(msg); + return ret.read!Ret(); + } + + Message opDispatch(string meth, Args...)(Args args) { + Message msg = new Message(dbus_message_new_method_call(dest,path,iface,meth.toStringz())); + msg.build(args); + return conn.sendWithReplyBlocking(msg); + } + + Connection conn; + const(char)* dest; + const(char)* path; + const(char)* iface; +} + +unittest { + import dunit.toolkit; + Connection conn = connectToBus(); + PathIface obj = new PathIface(conn, "org.freedesktop.DBus","/org/freedesktop/DBus", + "org.freedesktop.DBus"); + auto names = obj.GetNameOwner("org.freedesktop.DBus").to!string(); + names.assertEqual("org.freedesktop.DBus"); + obj.call!string("GetNameOwner","org.freedesktop.DBus").assertEqual("org.freedesktop.DBus"); +} diff --git a/source/ddbus/thin.d b/source/ddbus/thin.d index c8d67db..ad8bc76 100644 --- a/source/ddbus/thin.d +++ b/source/ddbus/thin.d @@ -54,6 +54,7 @@ class Message { dbus_message_iter_init(msg, &iter); return readIter!T(&iter); } + alias read to; Tup readTuple(Tup)() if(isTuple!Tup && allCanDBus!(Tup.Types)) { DBusMessageIter iter;