[systemd-devel] Sending complex structures over sd-bus
Lennart Poettering
lennart at poettering.net
Thu Oct 25 12:14:06 UTC 2018
On Do, 25.10.18 03:06, guhan balasubramanian (guhan.sac at gmail.com) wrote:
> Hi,
>
> I am trying to use the sd-bus to send structures that are a bit complex in
> nature.
>
> For example, consider the following:
>
> struct complex_struct {
> int some_integers[10];
> char *str;
> } cs;
>
> cs property_to_send[10];
>
> This d-bus property would be something like "a(ais)".
>
> Assuming I want to send the above array, I am trying to right the
> property's function handler in the sd_bus_server for the same.
>
> I know the open and close container can be used for simple arrays. I am
> finding it hard to make it work for the nested array case. Can some one
> please help point me to any example or references for the same?
You open the outer container first, and then the inner one.
When creating the message:
sd_bus_message_open_container(m, 'a', "(ais)"); /* open outer array */
for (i = 0; i < 10; i++) {
sd_bus_message_open_container(m, 'r', "ais"); /* open array item structure */
sd_bus_message_open_container(m, 'a', "i"); /* open inner array */
for (j = 0; j < 10; j++)
sd_bus_message_append(m, "i", 4711);
sd_bus_message_close_container(m); /* close inner array */
sd_bus_message_append(m, "s", "test string");
sd_bus_message_close_container(m); /* close array item structre */
}
sd_bus_message_close_container(m); /* close outer array */
And when processing a message it's kinda the same, you just use
enter/exit rather than open/close for the containers...
Lennart
--
Lennart Poettering, Red Hat
More information about the systemd-devel
mailing list