Discussion:
Reading an "ao" signature message with the sdbus c library?
(too old to reply)
James Johnson
2017-08-17 20:43:37 UTC
Permalink
Raw Message
Hello,

Can someone please point me to the correct method for reading an "ao"
signature dbus message using the sd_bus C api?

I am trying to read all the network devices with the following call:

result = sd_bus_get_property(m_bus, "org.freedesktop.NetworkManager",
"/org/freedesktop/NetworkManager",
"org.freedesktop.NetworkManager",
"AllDevices", &error,
&msgCall, "ao");
I have tried:

char * ptr;
size_t size;

result = sd_bus_message_read_array(msgCall, 'o', &ptr, &size);

as well as:

result = sd_bus_message_read(msgCall, "ao", ptr);

but these both return an error. I am not sure what method to use to parse
the returned message when it is an array of path objects.

Please note this interface gives me the following when executed via the
busctl command:

[***@macbookpro]$ busctl --verbose get-property
org.freedesktop.NetworkManager /org/freedesktop/NetworkManager
org.freedesktop.NetworkManager AllDevices
ARRAY "o" {
OBJECT_PATH "/org/freedesktop/NetworkManager/Devices/1";
OBJECT_PATH "/org/freedesktop/NetworkManager/Devices/3";
OBJECT_PATH "/org/freedesktop/NetworkManager/Devices/11";
OBJECT_PATH "/org/freedesktop/NetworkManager/Devices/12";
};


Thanks!
Jimmy
James Johnson
2017-08-17 20:58:02 UTC
Permalink
Raw Message
Hello,


It looks like I figured out my problem, I have to use:

result = sd_bus_message_enter_container(msgCall, 'a', "o");

before I try reading the array with :

result = sd_bus_message_read(msgCall, "o", &ptr);

Thanks,
Jimmy
Post by James Johnson
Hello,
Can someone please point me to the correct method for reading an "ao"
signature dbus message using the sd_bus C api?
result = sd_bus_get_property(m_bus, "org.freedesktop.NetworkManager",
"/org/freedesktop/NetworkManager",
"org.freedesktop.NetworkManager",
"AllDevices", &error,
&msgCall, "ao");
char * ptr;
size_t size;
result = sd_bus_message_read_array(msgCall, 'o', &ptr, &size);
result = sd_bus_message_read(msgCall, "ao", ptr);
but these both return an error. I am not sure what method to use to parse
the returned message when it is an array of path objects.
Please note this interface gives me the following when executed via the
org.freedesktop.NetworkManager /org/freedesktop/NetworkManager
org.freedesktop.NetworkManager AllDevices
ARRAY "o" {
OBJECT_PATH "/org/freedesktop/NetworkManager/Devices/1";
OBJECT_PATH "/org/freedesktop/NetworkManager/Devices/3";
OBJECT_PATH "/org/freedesktop/NetworkManager/Devices/11";
OBJECT_PATH "/org/freedesktop/NetworkManager/Devices/12";
};
Thanks!
Jimmy
Lennart Poettering
2017-08-31 13:53:45 UTC
Permalink
Raw Message
Post by James Johnson
Hello,
Can someone please point me to the correct method for reading an "ao"
signature dbus message using the sd_bus C api?
result = sd_bus_get_property(m_bus, "org.freedesktop.NetworkManager",
"/org/freedesktop/NetworkManager",
"org.freedesktop.NetworkManager",
"AllDevices", &error,
&msgCall, "ao");
char * ptr;
size_t size;
result = sd_bus_message_read_array(msgCall, 'o', &ptr, &size);
_read_array() only works for trivial types, not for strings and
other variable length types. If you have such complex types you need
to enter the array with _enter_container() and then _read() each item
individually...

But I see you already figure that out...

Lennart
--
Lennart Poettering, Red Hat
Loading...