[systemd-devel] How to get array[struct type] using sd_bus_message_* API's
Lennart Poettering
lennart at poettering.net
Fri Nov 19 08:33:22 UTC 2021
On Fr, 19.11.21 12:31, Manojkiran Eda (manojkiran.eda at gmail.com) wrote:
> In the `busctl monitor` i could confirm that i am getting a message of
> signature a{sas} from the dbus call, and here is the logic that I could
> come up with to read the data.
>
> r = sd_bus_message_enter_container(reply, SD_BUS_TYPE_ARRAY, "{sas}");
> if (r < 0)
> goto exit;
> while ((r = sd_bus_message_enter_container(reply,
> SD_BUS_TYPE_DICT_ENTRY,
> "sas")) > 0)
> {
> char* service = NULL;
> r = sd_bus_message_read(reply, "s", &service);
> if (r < 0)
> goto exit;
> printf("service = %s\n", service);
> r = sd_bus_message_enter_container(reply, 'a', "s");
> if (r < 0)
> goto exit;
> for (;;)
> {
> const char* s;
> r = sd_bus_message_read(reply, "s", &s);
> if (r < 0)
> goto exit;
> if (r == 0)
> break;
> printf("%s\n", s);
> }
> }
>
> Output:
> service = xyz.openbmc_project.EntityManager
> org.freedesktop.DBus.Introspectable
> org.freedesktop.DBus.Peer
> org.freedesktop.DBus.Properties
>
> But, I was only able to get the data from the first dictionary, can anyone
> help me to solve this issue? what am I missing?
You always need to leaver each container again once you read its
contents. i.e. each sd_bus_message_enter_container(…) must be paired
with sd_bus_message_leave_container(…)
Lennart
--
Lennart Poettering, Berlin
More information about the systemd-devel
mailing list