glib bindings vs. libdus
Thomas Renninger
trenn at gmx.net
Tue Jul 26 01:23:28 EST 2005
John (J5) Palmieri wrote:
> On Mon, 2005-07-25 at 16:17 +0200, Thomas Renninger wrote:
>>Hi,
>>
...
>>Assuming I'd implement a glib mainloop, is this how it would look like?:
>>
>> - Initialising DBus stuff and pass over mainloop.
>
> dbus_connection_setup_with_g_main (DBusConnection *connection,
> GMainContext *context)
>
> the context can be NULL which mean use the main context.
>
>> - In mainloop I set up my file descriptors I like to watch and
>> wait on a select.
>
> You can set watches on IO in glib.
I need something like: int my_dbus_fd_to_listen_on = dbus_watch_get_fd (watch)
(OK, just finished the mail - If I understand it right, I don't need any fds using glib bindings)
>
>> - DBus queries are somehow handled in the background (threaded, I think not?)
>> and I get invoked through callbacks while my mainloop still waits for fds to get readable/writable
>> on the select.
>
> It is handled by the mainloop in the same thread. Are you using the fds
> for watching the bus or something else? The glib mainloop should take
> care of handling any D-Bus message. You don't need to do your own
> checking.
>
Both.
I wait for e.g. /proc/acpi/events, /dev/apm_bios, socket connections (should
be replaced with DBus), and the DBus watch fd on the select.
After getting out of select I check (FD_ISSET) and branch in the appropriate
if/else path (e.g. invoke dbus_watch_handle if dbus_fd is active).
I think I got it. I have to pass a callback that will handle the stuff, that
previously was handled in (if FD_ISSET(dbus_fd,..)).
Or more precise, I pass a filter callback function that invokes the
(if FD_ISSET(dbus_fd,..)) stuff. Mainloop stays NULL.
So, processing will be done in DBus process context, while my daemon process is
still sleeping in select.
I will fidle around a bit with glib bindings and probably use
them instead.
Thanks for help and your fast reply,
Thomas
More information about the dbus
mailing list