how to get the DBusConnection for dbus_connection_dispatch from a DBusWatch of a DBusServer ?

Havoc Pennington hp at pobox.com
Thu Jun 18 06:34:31 PDT 2009


Hi,

On Thu, Jun 18, 2009 at 8:58 AM, Alexander
Neundorf<neundorf at eit.uni-kl.de> wrote:
> So if poll() tells me that something happened on the fd for the server watch,
> then I call
> dbus_watch_handle(watch, flags);
> What is flags then ?
> The documentation says its similar to the POLLIN/POLLOUT etc. flags. So can I
> just use the .revents field from struct pollfd ?

Well, dbus has its own flags enum iirc, but yes you should calculate
the flags from revents

> And what will the handler do then ?

It might read from the socket for DBusConnection in order to add to
the message queue, or in the DBusServer case it might accept a
connection.

> (I did that now and I don't see any effect)

The effect on a connection will (often, not always) be a change in
dispatch status, and on a server it will be to get a new connection.

>> This is true of the connection watches and timeouts also really; you
>> don't dispatch when the watch is ready, you dispatch when dispatch
>> status changes. (set_dispatch_status_function or whatever)
>
> I don't understand what you mean.
> Is it correct to call poll() on all the file descriptors ?
> What should I do then ?
> If I don't call dbus_connection_dispatch(), who will call this status
> callback ?

The status callback will be called when handling the watch or timeout
results in a change in dispatch status.

The GLib main loop is a very generalized main loop model, which you
could copy; its steps (prepare, check, poll, dispatch) are roughly the
same ones you need for any main loop.
http://library.gnome.org/devel/glib/unstable/glib-The-Main-Event-Loop.html

The idea is: block on file descriptors; on wakeup, buffer data from
the descriptors; dispatch (process the buffered data or otherwise do
any work that needs doing); block on mainloop again.

Havoc


More information about the dbus mailing list