Tracking DBusWatches

Havoc Pennington hp at redhat.com
Mon Feb 5 14:41:17 PST 2007


tsuraan wrote:
> 
> The low-level API docs seem good; I'm just missing the bird's eye view.  
> I'm trying to figure out what exactly dbus needs the program to do.  
> When using the set_watch_functions, do dbus method calls (from within 
> the program) turn into DBusWatch objects that need sending and 
> recieving, or does dbus_connection_send attempt to use the socket 
> directly?  I assume from the docs (" Adds a message to the outgoing 
> message queue.") that it's the former, but I'm just not entirely clear 
> on everything yet.

The socket is owned by and used directly by the DBusConnection; libdbus 
will write the DBusMessage to it (and read DBusMessage from it). The 
DBusWatch is just so you can select() or poll() on both the 
DBusConnection socket *and* some other descriptors specific to your 
application at the same time. In other words DBusWatch tells you which 
descriptors libdbus wants you to include in your main loop 
(select()/poll()).

If you don't have any other descriptors you can ignore DBusWatch and 
just block in dbus_connection_read_write(), which will simply block on 
the connection socket.

dbus_connection_send() will do two things:
  - insert the DBusMessage into an outgoing queue
  - if the queue goes from 0 messages to 1 messages, it will enable the
    write watch, which would cause your main loop to wake up

When you then call dbus_watch_handle() on the write watch, or call 
dbus_connection_read_write(), the outgoing message queue will be drained 
by writing it out to the socket.

Havoc


More information about the dbus mailing list