From 96605cf2bcf14dcb4e5c570cf2437b8225335401 Mon Sep 17 00:00:00 2001 From: WebFreak001 Date: Sun, 23 Apr 2017 16:39:28 +0200 Subject: [PATCH] Documentation updates --- .gitignore | 1 + Readme.md | 32 ++++++++++++++++++++++++++++---- dub.json | 6 +++--- dub.selections.json | 2 +- source/ddbus/bus.d | 6 ++++++ 5 files changed, 39 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index d4337d4..b9314d9 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ __dummy.html /ddbus libddbus.* __test__library__ +/ddbus-test-* diff --git a/Readme.md b/Readme.md index bc7c86e..1281cfb 100644 --- a/Readme.md +++ b/Readme.md @@ -18,7 +18,7 @@ Before using, you will need to have the DBus C library installed on your compute `ddbus` is available on [DUB](http://code.dlang.org/packages/ddbus) so you can simply include it in your `dub.json`: ```json "dependencies": { - "ddbus": "~>1.0.0" + "ddbus": "~>2.0.0" } ``` @@ -62,6 +62,9 @@ Setting read only properties results in a thrown `DBusException`. You can register a delegate into a `MessageRouter` and a main loop in order to handle messages. After that you can request a name so that other DBus clients can connect to your program. +You can return a `Tuple!(args)` to return multiple values (multiple out values in XML) or +return a `Variant!DBusAny` to support returning any dynamic value. + ```d import ddbus; MessageRouter router = new MessageRouter(); @@ -89,8 +92,7 @@ bool gotem = requestName(conn, "ca.thume.ddbus.test"); simpleMainLoop(conn); ``` -Note that `ddbus` currently only supports a simple event loop that is really only suitable for apps that don't do -anything except respond to DBus messages. Other threads handling other things concurrently may or may not work with it. See the todo section for notes on potential `vibe.d` compatibility. +See the Concurrent Updates section for details how to implement this in a custom main loop. ## Thin(ish) Wrapper @@ -133,11 +135,33 @@ you can import the others if you want lower level control. Nothing is hidden so if `ddbus` doesn't provide something you can simply import `c_lib` and use the pointers contained in the thin wrapper structs to do it yourself. +# Concurrent Updates + +If you want to use the DBus connection concurrently with some other features +or library like a GUI or vibe.d you can do so by placing this code in the update/main loop: + +```d +// initialize Connection conn; somewhere +// on update: +if (!conn.tick) + return; +``` + +Or in vibe.d: + +```d +runTask({ + import vibe.core.core : yield; + + while (conn.tick) + yield(); // Or sleep(1.msecs); +}); +``` + # Todo `ddbus` should be complete for everyday use but is missing some fanciness that it easily could and should have: -- [vibe.d](http://vibed.org/) event loop compatibility so that calls don't block everything and more importantly, it is possible to write apps that have a DBus server and can do other things concurrently, like a GUI. - Marshaling of DBus path and file descriptor objects - Better efficiency in some places, particularly the object wrapping allocates tons of delegates for every method. diff --git a/dub.json b/dub.json index 6615adb..1665d57 100644 --- a/dub.json +++ b/dub.json @@ -1,12 +1,12 @@ { "name": "ddbus", "description": "A DBus library for D", - "homepage": "http://github.com/trishume/ddbus", - "copyright": "Copyright © 2015, Tristan Hume", + "homepage": "https://github.com/trishume/ddbus", + "copyright": "Copyright © 2017, Tristan Hume", "license": "MIT", "authors": ["Tristan Hume"], "lflags": ["-ldbus-1"], "dependencies": { - "dunit": "~>1.0.10" + "dunit": "~>1.0.14" } } diff --git a/dub.selections.json b/dub.selections.json index a115f1d..c0dc360 100644 --- a/dub.selections.json +++ b/dub.selections.json @@ -1,6 +1,6 @@ { "fileVersion": 1, "versions": { - "dunit": "1.0.10" + "dunit": "1.0.14" } } \ No newline at end of file diff --git a/source/ddbus/bus.d b/source/ddbus/bus.d index f88cd28..7712590 100644 --- a/source/ddbus/bus.d +++ b/source/ddbus/bus.d @@ -31,6 +31,12 @@ void simpleMainLoop(Connection conn) { while(dbus_connection_read_write_dispatch(conn.conn, -1)) {} // empty loop body } +/// Single tick in the DBus connection which can be used for +/// concurrent updates. +bool tick(Connection conn) { + return cast(bool) dbus_connection_read_write_dispatch(conn.conn, 0); +} + unittest { import dunit.toolkit; Connection conn = connectToBus();