How can i use DBusWatch struct
Havoc Pennington
hp at redhat.com
Wed Sep 19 09:12:32 PDT 2007
Hi,
read_write_dispatch() is an alternative to your own select(). Don't
use it if you are using DBusWatch.
If you use DBusWatch, you need to *also* use DBusTimeout. You also
need to either dispatch() on every iteration of the main loop, *or*
use set_dispatch_status_function() so you know whether to dispatch.
set_wakeup_main_function() only matters if you are using threads.
When a watch is toggled off, you need to remove its file descriptor
from select(), or you will select() on a descriptor that should not be
select()'d on. For example, a write watch will be toggled off if there
are no messages to write.
When your select() sees that a descriptor is ready, you need to call
dbus_watch_handle() on the watch corresponding to that descriptor.
register_object_path() has nothing to do with any of this; it sets up
handlers to run when you dispatch, if a message is dispatched that
goes to that object path.
As it says in the docs, do not use pop_message() in combination with dispatch.
Conceptually here is what is going on:
- there is a list of incoming messages
- there is a list of outgoing messages
- when the connection file descriptor is ready to write,
dbus_watch_handle() will write the outgoing messages to the descriptor
and remove them from the outgoing list
- when the connection file descriptor is ready to read,
dbus_watch_handle() will read the incoming messages from the
descriptor and add them to the incoming list
- when you dbus_connection_dispatch(), each message in turn is
removed from the incoming list and any handlers that you have
registered are invoked, such as those from register_object_path()
- if you use pop_message() the messages are removed from the incoming
queue without being dispatched, which is not what you want
If you are hand-rolling your own C API, remember you also need to
implement object introspection.
Havoc
More information about the dbus
mailing list