dbus message not received at client from server

Calvin Lee cyrus296 at gmail.com
Tue Nov 21 15:35:09 UTC 2017


Anitha,
I'm not sure if I can fix your problem with the information given, but
I'll try to help out. Setting up DBus to be asynchronous requires more
than using `dbus_connection_set_dispatch`. First, both DBusWatch[1] and
DBusTimeout[2] must be honored. Second, the
`dbus_connection_set_dispatch_status_function` is only called if the
status is changed, it does not dispatch anything. In order to dispatch
one must call `dbus_connection_dispatch` as many times as needed. See my
implementation below:
```C static bool should_dispatch = true;
static void dispatch_status(DBusConnection *connection,
DBusDispatchStatus new_status,
                void *_data) {
        if (new_status == DBUS_DISPATCH_DATA_REMAINS) {
                should_dispatch = true;
         }
}
void dispatch_dbus() {
        if (!should_dispatch || !conn) {
                return;
        }
        DBusDispatchStatus status;
        do {
                status = dbus_connection_dispatch(conn);
        } while (status == DBUS_DISPATCH_DATA_REMAINS);
        if (status != DBUS_DISPATCH_COMPLETE) {
                log(L_ERROR, "Cannot dispatch dbus events: %d", status);
        }
        should_dispatch = false;
}
```
I call `dispatch_dbus` each time the main loop runs.
Also `dispatch_status` is the callback to
`dbus_connection_set_dispatch_function`.

Best of luck with your project, if you need any more help please reply
with more information.

Regards,
Calvin

[1]https://dbus.freedesktop.org/doc/api/html/group__DBusWatch.html
[2]https://dbus.freedesktop.org/doc/api/html/group__DBusTimeout.html


More information about the dbus mailing list