2 <!DOCTYPE refentry PUBLIC
"-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4 <!-- SPDX-License-Identifier: LGPL-2.1+ -->
6 <refentry id=
"sd_bus_message_append"
7 xmlns:
xi=
"http://www.w3.org/2001/XInclude">
10 <title>sd_bus_message_append
</title>
11 <productname>systemd
</productname>
15 <refentrytitle>sd_bus_message_append
</refentrytitle>
16 <manvolnum>3</manvolnum>
20 <refname>sd_bus_message_append
</refname>
21 <refname>sd_bus_message_appendv
</refname>
23 <refpurpose>Attach fields to a D-Bus message based on a type string
</refpurpose>
28 <funcsynopsisinfo>#include
<systemd/sd-bus.h
></funcsynopsisinfo>
31 <funcdef>int sd_bus_message_append
</funcdef>
32 <paramdef>sd_bus_message *
<parameter>m
</parameter></paramdef>
33 <paramdef>const char *
<parameter>types
</parameter></paramdef>
34 <paramdef>…
</paramdef>
38 <funcdef>int sd_bus_message_appendv
</funcdef>
39 <paramdef>sd_bus_message *
<parameter>m
</parameter></paramdef>
40 <paramdef>const char *
<parameter>types
</parameter></paramdef>
41 <paramdef>va_list
<parameter>ap
</parameter></paramdef>
48 <title>Description
</title>
50 <para>The
<function>sd_bus_message_append()
</function> function appends a sequence of fields to
51 the D-Bus message object
<parameter>m
</parameter>. The type string
<parameter>types
</parameter>
52 describes the types of the field arguments that follow. For each type specified in the type
53 string, one or more arguments need to be specified, in the same order as declared in the type
56 <para>The type string is composed of the elements shown in the table below. It contains zero or
57 more single
"complete types". Each complete type may be one of the basic types or a fully
58 described container type. A container type may be a structure with the contained types, a
59 variant, an array with its element type, or a dictionary entry with the contained types. The
60 type string is
<constant>NUL
</constant>-terminated.
</para>
62 <para>In case of a basic type, one argument of the corresponding type is expected.
</para>
64 <para>A structure is denoted by a sequence of complete types between
<literal>(
</literal> and
65 <literal>)
</literal>. This sequence cannot be empty — it must contain at least one type.
66 Arguments corresponding to this nested sequence follow the same rules as if they were not
69 <para>A variant is denoted by
<literal>v
</literal>. Corresponding arguments must begin with a
70 type string denoting a complete type, and following that, arguments corresponding to the
71 specified type.
</para>
73 <para>An array is denoted by
<literal>a
</literal> followed by a complete type. Corresponding
74 arguments must begin with the number of entries in the array, followed by the entries
75 themselves, matching the element type of the array.
</para>
77 <para>A dictionary is an array of dictionary entries, denoted by
<literal>a
</literal> followed
78 by a pair of complete types between
<literal>{
</literal> and
<literal>}
</literal>. The first of
79 those types must be a basic type. Corresponding arguments must begin with the number of
80 dictionary entries, followed by a pair of values for each entry matching the element type of the
81 dictionary entries.
</para>
83 <para><function>sd_bus_message_appendv()
</function> is equivalent to
84 <function>sd_bus_message_append()
</function>, except that it is called with a
85 <literal>va_list
</literal> instead of a variable number of arguments. This function does not
86 call the
<function>va_end()
</function> macro. Because it invokes the
87 <function>va_arg()
</function> macro, the value of
<parameter>ap
</parameter> is undefined after
90 <para>For further details on the D-Bus type system, please consult the
91 <ulink url=
"http://dbus.freedesktop.org/doc/dbus-specification.html#type-system">D-Bus Specification
</ulink>.
95 <title>Item type specifiers
</title>
98 <xi:include href=
"sd_bus_message_append_basic.xml" xpointer=
"xpointer(//table[@id='format-specifiers'])//colspec" />
99 <xi:include href=
"sd_bus_message_append_basic.xml" xpointer=
"xpointer(//table[@id='format-specifiers']//thead)" />
102 <xi:include href=
"sd_bus_message_append_basic.xml" xpointer=
"xpointer(//table[@id='format-specifiers']//tbody/*)" />
105 <entry><literal>a
</literal></entry>
106 <entry><constant>SD_BUS_TYPE_ARRAY
</constant></entry>
108 <entry>determined by array type and size
</entry>
109 <entry>int, followed by array contents
</entry>
113 <entry><literal>v
</literal></entry>
114 <entry><constant>SD_BUS_TYPE_VARIANT
</constant></entry>
115 <entry>variant
</entry>
116 <entry>determined by the type argument
</entry>
117 <entry>signature string, followed by variant contents
</entry>
121 <entry><literal>(
</literal></entry>
122 <entry><constant>SD_BUS_TYPE_STRUCT_BEGIN
</constant></entry>
123 <entry>array start
</entry>
124 <entry morerows=
"1">determined by the nested types
</entry>
125 <entry morerows=
"1">structure contents
</entry>
128 <entry><literal>)
</literal></entry>
129 <entry><constant>SD_BUS_TYPE_STRUCT_END
</constant></entry>
130 <entry>array end
</entry>
134 <entry><literal>{
</literal></entry>
135 <entry><constant>SD_BUS_TYPE_DICT_ENTRY_BEGIN
</constant></entry>
136 <entry>dictionary entry start
</entry>
137 <entry morerows=
"1">determined by the nested types
</entry>
138 <entry morerows=
"1">dictionary contents
</entry>
141 <entry><literal>}
</literal></entry>
142 <entry><constant>SD_BUS_TYPE_DICT_ENTRY_END
</constant></entry>
143 <entry>dictionary entry end
</entry>
149 <para>For types
"s" and
"g" (unicode string or signature), the pointer may be
150 <constant>NULL
</constant>, which is equivalent to an empty string. See
151 <citerefentry><refentrytitle>sd_bus_message_append_basic
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
152 for the precise interpretation of those and other types.
</para>
156 <title>Types String Grammar
</title>
158 <programlisting>types ::= complete_type*
159 complete_type ::= basic_type | variant | structure | array | dictionary
160 basic_type ::=
"y" |
"n" |
"q" |
"u" |
"i" |
"x" |
"t" |
"d" |
164 structure ::=
"(" complete_type+
")"
165 array ::=
"a" complete_type
166 dictionary ::=
"a" "{" basic_type complete_type
"}"
171 <title>Examples
</title>
173 <para>Append a single basic type (the string
<literal>a string
</literal>):
176 <programlisting>sd_bus_message *m;
178 sd_bus_message_append(m,
"s",
"a string");
</programlisting>
180 <para>Append all types of integers:
</para>
182 <programlisting>uint8_t y =
1;
190 sd_bus_message_append(m,
"ynqiuxtd", y, n, q, i, u, x, t, d);
</programlisting>
192 <para>Append a structure composed of a string and a D-Bus path:
</para>
194 <programlisting>sd_bus_message_append(m,
"(so)",
"a string",
"/a/path");
197 <para>Append an array of UNIX file descriptors:
</para>
199 <programlisting>sd_bus_message_append(m,
"ah",
3, STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO);
202 <para>Append a variant, with the real type
"g" (signature),
203 and value
"sdbusisgood":
</para>
205 <programlisting>sd_bus_message_append(m,
"v",
"g",
"sdbusisgood");
</programlisting>
207 <para>Append a dictionary containing the mapping {
1=
>"a",
2=
>"b",
3=
>""}:
210 <programlisting>sd_bus_message_append(m,
"a{is}",
3,
1,
"a",
2,
"b",
3, NULL);
215 <title>Return Value
</title>
217 <para>On success, these functions return a non-negative integer. On failure, they return a
218 negative errno-style error code.
</para>
220 <xi:include href=
"sd_bus_message_append_basic.xml" xpointer=
"errors" />
223 <xi:include href=
"libsystemd-pkgconfig.xml" />
226 <title>See Also
</title>
229 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
230 <citerefentry><refentrytitle>sd-bus
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
231 <citerefentry><refentrytitle>sd_bus_message_append_basic
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
232 <citerefentry><refentrytitle>sd_bus_message_append_array
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
233 <citerefentry><refentrytitle>sd_bus_message_open_container
</refentrytitle><manvolnum>3</manvolnum></citerefentry>