Re: How to get array[struct type] using sd_bus_message_* API's

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fr, 19.11.21 12:31, Manojkiran Eda (manojkiran.eda@xxxxxxxxx) 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



[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux