[systemd-devel] How to get array[struct type] using sd_bus_message_* API's
Manojkiran Eda
manojkiran.eda at gmail.com
Fri Nov 19 07:01:16 UTC 2021
Hi All,
I am a beginner, trying to learn the sd_bus API's.
I am trying to replicate the following busctl call to get information:
$ busctl call xyz.openbmc_project.ObjectMapper
/xyz/openbmc_project/object_mapper xyz.openbmc_project.ObjectMapper
GetObject sas /xyz/openbmc_project/inventory 0 --verbose
MESSAGE "a{sas}" {
ARRAY "{sas}" {
DICT_ENTRY "sas" {
STRING "xyz.openbmc_project.EntityManager";
ARRAY "s" {
STRING
"org.freedesktop.DBus.Introspectable";
STRING "org.freedesktop.DBus.Peer";
STRING "org.freedesktop.DBus.Properties";
};
};
DICT_ENTRY "sas" {
STRING "xyz.openbmc_project.Inventory.Manager";
ARRAY "s" {
STRING
"org.freedesktop.DBus.Introspectable";
STRING "org.freedesktop.DBus.ObjectManager";
STRING "org.freedesktop.DBus.Peer";
STRING "org.freedesktop.DBus.Properties";
STRING
"xyz.openbmc_project.Inventory.Manager";
};
};
DICT_ENTRY "sas" {
STRING "xyz.openbmc_project.ObjectMapper";
ARRAY "s" {
STRING
"org.freedesktop.DBus.Introspectable";
STRING "org.freedesktop.DBus.Peer";
STRING "org.freedesktop.DBus.Properties";
};
};
DICT_ENTRY "sas" {
STRING "xyz.openbmc_project.PLDM";
ARRAY "s" {
STRING
"org.freedesktop.DBus.Introspectable";
STRING "org.freedesktop.DBus.ObjectManager";
STRING "org.freedesktop.DBus.Peer";
STRING "org.freedesktop.DBus.Properties";
};
};
};
};
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?
Thanks,
Manoj
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20211119/ee11cfc9/attachment-0001.htm>
More information about the systemd-devel
mailing list