Re: dbus message not received at client from server

Calvin Lee <[email protected]>
Newsgroups gmane.comp.freedesktop.dbus
Message-ID <CAG7gSg0SgC11m+VjSVMX50e5THK3qC0yegDgJNatH6in6f4MqQ@mail.gmail.com>
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
_______________________________________________
dbus mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dbus
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.