dbus_connection_set_wakeup_main_function
Colin Walters
walters at verbum.org
Wed Feb 4 18:06:46 PST 2009
On Wed, Feb 4, 2009 at 4:44 PM, Robert Greenwalt <rgreenwalt at google.com> wrote:
> I inherited a bit of code that was polling using
> dbus_connection_read_write_dispatch. It worked fine, but it was polling. I
> decided to change that to an asynchronous model and looked at the
> DBusWatch/Timeout stuff but it looked like overkill for my needs. I
> continued looking and found dbus_connection_set_wakeup_main_function. From
> the comment: "This function is responsible for waking up the main loop when
> some change has happened to the connection that the mainloop needs to
> reconsider" it sounded perfect. Call me when I need to do stuff and I'll do
> stuff (non-polled used of read_write_dispatch).
>
> It doesn't work. It kinda works. I get some incoming messages. Outgoing
> messages seem to go out. It just those few missed messages that spoil the
> whole thing.
Are multiple threads involved here?
> I can go and implement the DBusWatch/Timeout interface, but I'm curious:
> what purpose does dbus_connection_set_wakeup_main_function serve? How must
> it be suplimented to make a fully functional solution? If that's not
> possible, why does it remain in the API?
I'm not an expert in this area of the code, but I believe it's correct
to say that to be able to use libdbus asynchronously (without polling
of any sort), it's required to provide the watch/timeout
implementations. For example, when you send a message, libdbus queues
a timeout to synthesize an error if a reply doesn't return within a
specified period of time. To do that, it needs to know how to queue a
timeout.
Basically you need a mainloop which can monitor file descriptors and
invoke callbacks after a specified period of time. Can you give any
more details about what kind of host environment you have? For
example if it's feasible to use GLib for you, I'd recommend that. If
not we'd be able to look at other options.
More information about the dbus
mailing list