Sachin Hottigoudar
Sachin Hottigoudar

Reputation: 41

How to use DBusWatch functions to receive asynchronous requests?

I've seen the program illustrated in DBusWatch and DBusTimeout examples, but I don't understand why the following code is used in dispatch() function:

while (dbus_connection_get_dispatch_status(c) == DBUS_DISPATCH_DATA_REMAINS)
    dbus_connection_dispatch(c);

Upvotes: 2

Views: 541

Answers (1)

minghua
minghua

Reputation: 6593

The dbus_connection_dispatch() triggers the top level main loop action in dbus library which in turn will dispatch the steps of actions into other functions. The actual bus message receiving should be in a user handler function.

It can be an example on the bind9 code by apple. The message handling is triggered in these steps according to my reading:

  • The select() returns in the main loop with a fd set by the dbus watch.
  • The main loop calls process_watches() which walks the tree and call process_watch().
  • In the end, it looks like the dbus message is handled by a call through

    (*(cs->mf)) ( cs, type, reply, serial, dest, path, member, interface, 0L, sender, signature, message, 0L, 0L, 0L, cs->def_mf_obj);

The cs->mf should be holding a user handler function added by dbus_svc_add_filter().

Upvotes: 2

Related Questions