awesome

Welcome to awesome bug tracking system.
Tasklist

FS#557 - Move away D-Bus support

Attached to Project: awesome
Opened by Julien Danjou (jd) - Friday, 10 July 2009, 16:13 GMT
Task Type Evolution Request
Category Core
Status New
Assigned To No-one
Operating System All
Severity Low
Priority Normal
Reported Version git/master
Due in Version Undecided
Due Date Undecided
Percent Complete 0%
Votes 2
Private No

Details

Currently, awesome provides a set of D-Bus function to Lua to provide direct access to the bus.

This is totally unrelated to awesome and the C code exporting the dbus module should be moved away to a lua-dbus module.

Such a project does not exist yet, but creating would allow any Lua application to use D-Bus, rather than having it only in awesome.
This task depends upon

Comment by koniu (koniu) - Friday, 10 July 2009, 17:34 GMT
there does seem to be a project like this, however stalled and far from finished

http://luaforge.net/plugins/scmcvs/cvsweb.php/lua-dbus/?cvsroot=lua-dbus
Comment by Uli Schlachter (psychon) - Saturday, 01 August 2009, 14:18 GMT
Yeah, I just found http://luaforge.net/projects/lua-dbus/ too and remembered this.

A problem which I see is that this lua library needs a way to wake up awesome (=register with libev). I don't know how a general purpose library would do this. I guess this is almost impossible....
Comment by Uli Schlachter (psychon) - Tuesday, 17 August 2010, 15:29 GMT
This is a test. Sorry, but please ignore this.
Comment by Konstantin Stepanov (kstep) - Thursday, 06 January 2011, 12:06 GMT
I took a look at lua-dbus in luaforge. The last commit was 23 months ago, and the note in README put me in doubt:

[quote]this binding is in no way usable at this stage. I don't even provide a makefile, this is just an "initial commit" version.[/quote]

Yet, I have just found simpledbus project in github.com at https://github.com/esmil/simpledbus
It looks more alive, IMHO. Is it worth to try out?
Comment by Konstantin Stepanov (kstep) - Thursday, 06 January 2011, 14:39 GMT
I've cloned it to my github account at https://github.com/kstep/simpledbus and hacked it a little, so I can send method requests w/o waiting for reply.
Now I managed to make method request from within awesome with the following code:

local dbus = require("simpledbus")
local bus = dbus.SessionBus()
function set_layout(layout)
-- dest, path, iface, member, no-reply flag, signature, arg0 (layout number)
return bus:call_method('ru.gentoo.kbdd', '/ru/gentoo/kbdd', 'ru.gentoo.kbdd', 'set_layout', true, 'u', layout or 0)
end

set_layout(1)

This code is to control current keyboard layout with kbdd (https://awesome.naquadah.org/wiki/Keyboard_layouts_with_kbdd).
Works like a charm for me.
Comment by Uli Schlachter (psychon) - Thursday, 06 January 2011, 19:34 GMT
So far I only took a quick look at it, but it seems like this wants to replace your main loop or else it wouldn't work. No idea how that could be done with awesome...
Comment by Konstantin Stepanov (kstep) - Thursday, 06 January 2011, 23:44 GMT
I use it to send D-BUS requests, and builtin Awesome D-BUS bindings to listen to signals.
It works this way w/o need to replace main loop (with a small patch to avoid blocking method calls).
Maybe this can help?
Comment by Uli Schlachter (psychon) - Friday, 07 January 2011, 15:40 GMT
The idea with this bug is to remove as much as possible / all dbus-related code from awesome's C core and have all of that be handled by a library. So I'd really be interested in having it all work with simpledbus.
From what I could see from the examples, simpledbus provides a way more highlevel API instead of the lowlevel mess you get from awesome, so that would be a big plus, too. (I.e. instead of hand-writing the introspection XML, you can create objects that are exported to dbus)
Comment by Konstantin Stepanov (kstep) - Saturday, 08 January 2011, 17:11 GMT
I see. So the main problem is in junction point between dbus library and awesome, namely in main loop, needed to listen to dbus events.
As I can get it, it's very difficult to run signal handlers in awesome's context, instead of dbus library context, as this main loop must be somehow moved from awesome private code into alien library. But maybe we can leave some thin glue code in awesome to interface with other library? Just the point to start from. I can't think of better alternatives yet, sorry.
Comment by Uli Schlachter (psychon) - Saturday, 08 January 2011, 17:16 GMT
Yeah, I guess having some kind of API for "when this file descriptor ir readable or writable, call this callback" should be enough.
Alternatively there could be a C function in the dbus library for this kind of thing and awesome would then link against the lua dbus library and do the integration that way.

None of these two approaches works for the current state of simpledbus, I guess.
Comment by Konstantin Stepanov (kstep) - Friday, 04 February 2011, 18:13 GMT
I contacted SimpleDBus author on Github to ask him to pull my patch to avoid
blocking DBUS-calls, and today I received the following answer:

=====
First of all, sorry for the late reply. Your patch looks fine.

There is, however, a big design flaw in SimpleDBus. Having a special purpose
mainloop in a library is a very bad idea. It means you can't really do other
io properly while it runs.

Hence I wrote a Lua Event Machine (lem), which has a built-in eventloop, which
modules can hook into, and I've now rewritten SimpleDBus to a dbus module for
that.

This, however, can't be used inside Awesome. To do this properly you'd need to
rewrite SimpleDBus so you keep your mainloop in Lua, sort of like the luasocket
library does. Either that, or just cut down SimpleDBus so it can only send
signals and do blocking or fire-and-forget method calls.

I, however, have no intention of doing that, which is why I'm abandoning
SimpleDBus. You are of course very welcome to keep your fork and develop on
it.

/Emil
=====

So SimpleDBus can be considered abandoned by now. We can either adapt it to our
needs freely and support it for our own good, or discard it due to lack of original
developer's support.

Comment by Uli Schlachter (psychon) - Friday, 04 February 2011, 18:22 GMT
I guess he means https://github.com/esmil/lem-dbus
I haven't looked into it yet, but if this already has some sort of mainloop which can also work with other stuff, perhaps we could make awesome imitate that event loop or perhaps even use it inside of awesome?
Besides dbus, awesome only really has to handle the X11 connection and timer objects. That doesn't sound like something way too complicated to me...
Comment by Hanspeter Portner (ventosus) - Tuesday, 22 November 2011, 10:09 GMT
I am on the way of writing exactly such a small Lua library, as I was in the need of Lua DBus bindings to write an awesome widget for ConnMan (http://connman.net).
The bindings feature a non-blocking iterative main loop, which can be called as an awesome timer callback.
The code builds on e_dbus from the enlightenment project, as it features a cleaner DBus API than glib, and the DBus low-level C_API is cumbersome to use directly.

It's Pre-Alpha and not feature-complete, it only implements the DBus client functions so far, as this is enough to build awesome widgets.
- send signals
- call methods
- add signal callbacks
But the server functions are to come...

Lua DBus bindings: git://git.code.sf.net/p/ldbus/code
awesome ConnMan widget: git://git.code.sf.net/p/ldbus/connman

As I specifically develop it to work well with awesome, I can include any wishes, as long as the goal o keep it as simple and unbloated as possible, is fulfilled.
Comment by Uli Schlachter (psychon) - Wednesday, 23 November 2011, 16:28 GMT
If you want to integrate this with awesome, I'd suggest using lua-ev for your event loop: https://github.com/brimworks/lua-ev
You can access libev's default loop via (I think) ev.loop.default. Since awesome uses libev's default loop, too, that will magically make everything work.

So why this whole stunt? It would allow integrating this nicely with awesome's main loop without any hacks like an awesome timer callback. Another plus-point would be that youd have no awesome-specific code at all, so this could then be easily used without awesome.

Sadly, brimworks' lua-ev version doesn't work if it can't call ev_loop() itself. My fork of it contains a patch which makes it work with awesome.


Now that I said the above:
Yay! Thanks for writing dbus bindings! As soon as it can replace awesome's built-in dbus code, I'd hapily remove dbus.c from awesome.

Loading...