]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/sd_bus_message_append.xml
b70ec8309ceac04b48d94e1b0245f6025f3c9aca
[thirdparty/systemd.git] / man / sd_bus_message_append.xml
1 <?xml version='1.0'?> <!--*- Mode: nxml; nxml-child-indent: 2; indent-tabs-mode: nil -*-->
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4
5 <!--
6 SPDX-License-Identifier: LGPL-2.1+
7 -->
8
9 <refentry id="sd_bus_message_append"
10 xmlns:xi="http://www.w3.org/2001/XInclude">
11
12 <refentryinfo>
13 <title>sd_bus_message_append</title>
14 <productname>systemd</productname>
15 </refentryinfo>
16
17 <refmeta>
18 <refentrytitle>sd_bus_message_append</refentrytitle>
19 <manvolnum>3</manvolnum>
20 </refmeta>
21
22 <refnamediv>
23 <refname>sd_bus_message_append</refname>
24 <refname>sd_bus_message_appendv</refname>
25
26 <refpurpose>Attach fields to a D-Bus message based on a type
27 string</refpurpose>
28 </refnamediv>
29
30 <refsynopsisdiv>
31 <funcsynopsis>
32 <funcsynopsisinfo>#include &lt;systemd/sd-bus.h&gt;</funcsynopsisinfo>
33
34 <funcprototype>
35 <funcdef>int sd_bus_message_append</funcdef>
36 <paramdef>sd_bus_message *<parameter>m</parameter></paramdef>
37 <paramdef>const char *<parameter>types</parameter></paramdef>
38 <paramdef></paramdef>
39 </funcprototype>
40
41 <funcprototype>
42 <funcdef>int sd_bus_message_appendv</funcdef>
43 <paramdef>sd_bus_message *<parameter>m</parameter></paramdef>
44 <paramdef>const char *<parameter>types</parameter></paramdef>
45 <paramdef>va_list <parameter>ap</parameter></paramdef>
46 </funcprototype>
47
48 </funcsynopsis>
49 </refsynopsisdiv>
50
51 <refsect1>
52 <title>Description</title>
53
54 <para>The <function>sd_bus_message_append()</function> function
55 appends a sequence of fields to the D-Bus message object
56 <parameter>m</parameter>. The type string
57 <parameter>types</parameter> describes the types of the field
58 arguments that follow. For each type specified in the type string,
59 one or more arguments need to be specified, in the same order as
60 declared in the type string.</para>
61
62 <para>The type string is composed of the elements shown in the
63 table below. It contains zero or more single "complete types".
64 Each complete type may be one of the basic types or a fully
65 described container type. A container type may be a structure with
66 the contained types, a variant, an array with its element type, or
67 a dictionary entry with the contained types. The type string is
68 <constant>NUL</constant>-terminated.</para>
69
70 <para>In case of a basic type, one argument of the corresponding
71 type is expected.</para>
72
73 <para>A structure is denoted by a sequence of complete types
74 between <literal>(</literal> and <literal>)</literal>. This
75 sequence cannot be empty — it must contain at least one type.
76 Arguments corresponding to this nested sequence follow the same
77 rules as if they were not nested.</para>
78
79 <para>A variant is denoted by <literal>v</literal>. Corresponding
80 arguments must begin with a type string denoting a complete type,
81 and following that, arguments corresponding to the specified type.
82 </para>
83
84 <para>An array is denoted by <literal>a</literal> followed by a
85 complete type. Corresponding arguments must begin with the number of
86 entries in the array, followed by the entries themselves,
87 matching the element type of the array.</para>
88
89 <para>A dictionary is an array of dictionary entries, denoted by
90 <literal>a</literal> followed by a pair of complete types between
91 <literal>{</literal> and <literal>}</literal>. The first of those
92 types must be a basic type. Corresponding arguments must begin
93 with the number of dictionary entries, followed by a pair of
94 values for each entry matching the element type of
95 the dictionary entries.</para>
96
97 <para>The <function>sd_bus_message_appendv()</function> is equivalent to
98 the function <function>sd_bus_message_append()</function>,
99 except that it is called with a <literal>va_list</literal> instead of
100 a variable number of arguments. This function does not call the
101 <function>va_end()</function> macro. Because it invokes the
102 <function>va_arg()</function> macro, the value of ap
103 is undefined after the call.</para>
104
105 <para>For further details on the D-Bus type system, please consult
106 the <ulink
107 url="http://dbus.freedesktop.org/doc/dbus-specification.html#type-system">D-Bus
108 Specification</ulink>.</para>
109
110 <table>
111 <title>Item type specifiers</title>
112
113 <tgroup cols='5'>
114 <xi:include href="sd_bus_message_append_basic.xml" xpointer="xpointer(//table[@id='format-specifiers'])//colspec" />
115 <xi:include href="sd_bus_message_append_basic.xml" xpointer="xpointer(//table[@id='format-specifiers']//thead)" />
116
117 <tbody>
118 <xi:include href="sd_bus_message_append_basic.xml" xpointer="xpointer(//table[@id='format-specifiers']//tbody/*)" />
119
120 <row>
121 <entry><literal>a</literal></entry>
122 <entry><constant>SD_BUS_TYPE_ARRAY</constant></entry>
123 <entry>array</entry>
124 <entry>determined by array type and size</entry>
125 <entry>int, followed by array contents</entry>
126 </row>
127
128 <row>
129 <entry><literal>v</literal></entry>
130 <entry><constant>SD_BUS_TYPE_VARIANT</constant></entry>
131 <entry>variant</entry>
132 <entry>determined by the type argument</entry>
133 <entry>signature string, followed by variant contents</entry>
134 </row>
135
136 <row>
137 <entry><literal>(</literal></entry>
138 <entry><constant>SD_BUS_TYPE_STRUCT_BEGIN</constant></entry>
139 <entry>array start</entry>
140 <entry morerows="1">determined by the nested types</entry>
141 <entry morerows="1">structure contents</entry>
142 </row>
143 <row>
144 <entry><literal>)</literal></entry>
145 <entry><constant>SD_BUS_TYPE_STRUCT_END</constant></entry>
146 <entry>array end</entry>
147 </row>
148
149 <row>
150 <entry><literal>{</literal></entry>
151 <entry><constant>SD_BUS_TYPE_DICT_ENTRY_BEGIN</constant></entry>
152 <entry>dictionary entry start</entry>
153 <entry morerows="1">determined by the nested types</entry>
154 <entry morerows="1">dictionary contents</entry>
155 </row>
156 <row>
157 <entry><literal>}</literal></entry>
158 <entry><constant>SD_BUS_TYPE_DICT_ENTRY_END</constant></entry>
159 <entry>dictionary entry end</entry>
160 </row>
161 </tbody>
162 </tgroup>
163 </table>
164
165 <para>For types "s" and "g" (unicode string or signature), the pointer may be
166 <constant>NULL</constant>, which is equivalent to an empty string. See
167 <citerefentry><refentrytitle>sd_bus_message_append_basic</refentrytitle><manvolnum>3</manvolnum></citerefentry>
168 for the precise interpretation of those and other types.</para>
169
170 </refsect1>
171
172 <refsect1>
173 <title>Types String Grammar</title>
174
175 <programlisting>types ::= complete_type*
176 complete_type ::= basic_type | variant | structure | array | dictionary
177 basic_type ::= "y" | "n" | "q" | "u" | "i" | "x" | "t" | "d" |
178 "b" | "h" |
179 "s" | "o" | "g"
180 variant ::= "v"
181 structure ::= "(" complete_type+ ")"
182 array ::= "a" complete_type
183 dictionary ::= "a" "{" basic_type complete_type "}"
184 </programlisting>
185 </refsect1>
186
187 <refsect1>
188 <title>Examples</title>
189
190 <para>Append a single basic type (the string <literal>a string</literal>):
191 </para>
192
193 <programlisting>sd_bus_message *m;
194
195 sd_bus_message_append(m, "s", "a string");</programlisting>
196
197 <para>Append all types of integers:</para>
198
199 <programlisting>uint8_t y = 1;
200 int16_t n = 2;
201 uint16_t q = 3;
202 int32_t i = 4;
203 uint32_t u = 5;
204 int32_t x = 6;
205 uint32_t t = 7;
206 double d = 8.0;
207 sd_bus_message_append(m, "ynqiuxtd", y, n, q, i, u, x, t, d);</programlisting>
208
209 <para>Append a structure composed of a string and a D-Bus path:</para>
210
211 <programlisting>sd_bus_message_append(m, "(so)", "a string", "/a/path");
212 </programlisting>
213
214 <para>Append an array of UNIX file descriptors:</para>
215
216 <programlisting>sd_bus_message_append(m, "ah", 3, STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO);
217 </programlisting>
218
219 <para>Append a variant, with the real type "g" (signature),
220 and value "sdbusisgood":</para>
221
222 <programlisting>sd_bus_message_append(m, "v", "g", "sdbusisgood");</programlisting>
223
224 <para>Append a dictionary containing the mapping {1=>"a", 2=>"b", 3=>""}:
225 </para>
226
227 <programlisting>sd_bus_message_append(m, "a{is}", 3, 1, "a", 2, "b", 3, NULL);
228 </programlisting>
229 </refsect1>
230
231 <refsect1>
232 <title>Return Value</title>
233
234 <para>On success, these functions return 0 or a positive
235 integer. On failure, these functions return a negative
236 errno-style error code.</para>
237 </refsect1>
238
239 <xi:include href="sd_bus_message_append_basic.xml" xpointer="errors" />
240
241 <xi:include href="libsystemd-pkgconfig.xml" />
242
243 <refsect1>
244 <title>See Also</title>
245
246 <para>
247 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
248 <citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
249 <citerefentry><refentrytitle>sd_bus_message_append_basic</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
250 <citerefentry><refentrytitle>sd_bus_message_append_array</refentrytitle><manvolnum>3</manvolnum></citerefentry>
251 </para>
252 </refsect1>
253
254 </refentry>