From: Ryan McClue <re.mcclue@protonmail.com>
To: Denis Kenzior <denkenz@gmail.com>
Cc: "ell@lists.linux.dev" <ell@lists.linux.dev>
Subject: Re: Sending and Receiving DBUS Message
Date: Fri, 17 Jun 2022 04:57:38 +0000 [thread overview]
Message-ID: <Yf3F4N4nJ3gEDc_40X7xmoTA9QM3f5flX4S9k6KlO76jGIQUGy1P5T_H8zg42WfbhZwOVIt-P0I3Lu6JKed1n2rGEUsRD5cangC4ADneh40=@protonmail.com> (raw)
In-Reply-To: <603b4d33-aa7b-1974-f41b-d9930d5f0eba@gmail.com>
Thank you again. Yes, I just blindly assumed that no arguments required no setup.
My issue now is parsing "oa{sa{sv}}" as matched by the Bluez InterfacesAdded signal.
I believe this extends to parsing any nested dictionary.
I tried looking in 'unit/*' for examples, however they only parse string keys, not the actual nested dictionary.
Consider my example code:
static void cb(struct l_dbus_message *msg, void *user_data) {
struct l_dbus_message_iter root_keys_iter, device_keys_iter = {0};
struct l_dbus_message_iter root_values_iter, device_values_iter = {0};
bool argument_received = false;
const char *object = NULL;
bool have_msg = l_dbus_message_get_arguments(msg, "oa{sa{sv}}", &object, &root_keys_iter);
if (have_msg) {
while (true) {
const char *root_key = NULL;
argument_received = l_dbus_message_iter_next_entry(&root_keys_iter, &root_key, &root_values_iter);
if (!argument_received) break;
if (strcmp(root_key, "org.bluez.Device1") == 0) {
argument_received = l_dbus_message_iter_get_variant(&root_values_iter, "a{sv}", &device_keys_iter);
if (argument_received) {
break;
} else {
printf("org.bluez.Device1 dict expected but not received\n");
exit(1);
}
}
}
} else {
printf("InterfacesAdded dict expected but not received\n");
exit(1);
}
}
The message "org.bluez.Device1 dict expected but not received" was printed. Why?
--
Ryan McClue, Sydney
Sent with Proton Mail secure email.
------- Original Message -------
On Wednesday, June 15th, 2022 at 1:53 PM, Denis Kenzior <denkenz@gmail.com> wrote:
> Hi Ryan,
>
> > > > struct l_dbus_message *msg = l_dbus_message_new_method_call(conn, "org.bluez", "/org/bluez/hci0",
> > > > "org.bluez.Adapter1", "StartDiscovery");
>
>
> You also need to make sure to set the arguments on the message. In your case:
>
> l_dbus_message_set_arguments(msg, "");
>
> We probably should have l_dbus_send* reject messages which have not been setup
> properly. But since you're not checking the error, it wouldn't really help :)
>
> > > > l_dbus_send_with_reply(conn, msg, start_discovery_callback, NULL, NULL);
> > > >
> > > > l_dbus_message_unref(msg);
>
>
> Here's a functional example based on your code.
>
> http://dpaste.com/8GVMYE3DY
>
> Regards,
> -Denis
prev parent reply other threads:[~2022-06-17 5:06 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-07 11:05 Sending and Receiving DBUS Message Ryan McClue
2022-06-07 15:07 ` Denis Kenzior
2022-06-14 8:32 ` Ryan McClue
2022-06-14 14:48 ` Denis Kenzior
2022-06-15 0:41 ` Ryan McClue
2022-06-15 3:53 ` Denis Kenzior
2022-06-17 4:57 ` Ryan McClue [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='Yf3F4N4nJ3gEDc_40X7xmoTA9QM3f5flX4S9k6KlO76jGIQUGy1P5T_H8zg42WfbhZwOVIt-P0I3Lu6JKed1n2rGEUsRD5cangC4ADneh40=@protonmail.com' \
--to=re.mcclue@protonmail.com \
--cc=denkenz@gmail.com \
--cc=ell@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).