dbus message not received at client from server
Calvin Lee
cyrus296 at gmail.com
Thu Nov 23 19:51:23 UTC 2017
Anitha,
Yes, there is a reason that your callback is not called. The reason is
the status is by default `DBUS_DISPATCH_DATA_REMAINS`. Therefore one
must dispatch until the status changes to `DBUS_STATUS_COMPLETE`
before the callback is called for the first time.
This is shown in the code snipped that I sent. In my program I
initialize my dispatch status flag as `static bool should_dispatch =
true;` which shows that `dbus_connection_dispatch` should be called
immediately.
Perhaps this should be mentioned in documentation somewhere, because
it was not obvious to me and I dealt with this problem as well.
Best of luck,
Calvin
On Wed, Nov 22, 2017 at 11:50 PM, Anitha Chandrasekar
<anitha.chandrasekar at sasken.com> wrote:
> Hi All,
>
> As said below,
> `dbus_connection_set_dispatch_status_function` is only called if the status is changed
>
> Here the " dispatch_status" callback is set calling, dbus_connection_set_dispatch_status_function(conn, dispatch_status, NULL, NULL);
>
> we see that this callback is not being called, even when the data is available. This happens only in certain case, rest of time this code is working fine.
>
> (Since we see that using dbus-monitor that the message is sent , but this status has not changed
> dbus-monitor logs->
> error time=1509954378.310314 sender=:1.3 -> destination=:1.12 error_name=org.bluez.Error.Failed reply_serial=52
> string "Not connected" ).
>
> -> Please refer to this link(sample reference code of gdbus library of bluez stack),
> https://kernel.googlesource.com/pub/scm/bluetooth/bluez/+/5.9/gdbus/mainloop.c
>
> Any idea why this status callback not called, even when the message is sent from dbus sender?
>
> Regards,
> Anitha
>
> ________________________________________
> From: dbus [dbus-bounces at lists.freedesktop.org] on behalf of Calvin Lee [cyrus296 at gmail.com]
> Sent: Tuesday, November 21, 2017 9:05 PM
> To: dbus at lists.freedesktop.org
> Subject: Re: dbus message not received at client from server
>
> 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
> dbus at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dbus
>
> ________________________________
>
> SASKEN BUSINESS DISCLAIMER: This message may contain confidential, proprietary or legally privileged information. In case you are not the original intended Recipient of the message, you must not, directly or indirectly, use, disclose, distribute, print, or copy any part of this message and you are requested to delete it and inform the sender. Any views expressed in this message are those of the individual sender unless otherwise stated. Nothing contained in this message shall be construed as an offer or acceptance of any offer by Sasken Technologies Limited ( formerly known as "Sasken Communication Technologies Limited" ) unless sent with that express intent and with due authority of Sasken. Sasken has taken enough precautions to prevent the spread of viruses. However the company accepts no liability for any damage caused by any virus transmitted by this email.
> Read Disclaimer at http://www.sasken.com/mail-disclaimer/
>
> ________________________________
--
-Calvin Lee
More information about the dbus
mailing list