PDA

View Full Version : HAL & DBusConnection & Qt main loop integration



juannm
14th January 2009, 20:04
Hello,
I'm playing with HAL and writing a console application in order to write a message when plugging a usb pendrive.

The problem is that libhal must be initialized with a call to the following function (from the HAL API):


bool libhal_ctx_set_dbus_connection (LibHalContext *ctx, DBusConnection *conn);

so a DBusConnection instance is needed.

I can create one the "standard" way, by calling (from the D-Bus API):


DBusConnection* dbus_bus_get(DBusBusType type, DBusError *error);

but then this DBusConnection is not integrated with the Qt main loop, so later in the code, when calling "return app.exec()" my program enters the main loop and nothing shows up in the console.

I thought about using the DBusConnection created inside QDBusConnection::systemBus(), because I expect it to be integrated with the Qt main loop (but then maybe I'm wrong), maybe using the "Unique Connection Name" of the connection (given by QDBusConnection::baseService()), but then I would need some method like "DBusConnection* dbus_bus_get_by_unique_name(char* name)", and that doesn't seem to exist in the D-Bus API.

Am I facing this issue the wrong way? Any comments or suggestions are truly appreciated :)

wysota
14th January 2009, 20:45
I think you can listen to HAL signals directly using DBUS without any HAL calls. HAL is a normal DBUS service.

juannm
14th January 2009, 23:34
I think you can listen to HAL signals directly using DBUS without any HAL calls. HAL is a normal DBUS service.

Yes it is, in fact the original way of accessing HAL is though its DBUS interface. But it also ships with two C libraries to link the code with (namely libhal and libhal-storage). I just wanted to use those and forget about dbus stuff (except on initialization), just for the fun of learning how to use it.

libdbus has a glib adaptor that allows to create a connection integrated with the main loop, and it seems to also have a qt3 version of the same adaptor.

So I just wanted to know whether someone else has been using libhal (not simply HAL's d-bus interface) + Qt4 and ask him about this.

wysota
15th January 2009, 08:06
Qt4 itself uses the glib loop, so there is a chance it will work out of the box although having to link against a library you need only for a few calls that can be safely done without the library seems like an overkill.