chiark / gitweb /
e3de69873b1bcf6ec3af767d75a10848b679c1c0
[elogind.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 This file is part of systemd.
7
8 Copyright 2014 Zbigniew Jędrzejewski-Szmek
9
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 -->
23
24 <refentry id="sd_bus_message_append" conditional="ENABLE_KDBUS"
25           xmlns:xi="http://www.w3.org/2001/XInclude">
26
27   <refentryinfo>
28     <title>sd_bus_message_append</title>
29     <productname>systemd</productname>
30
31     <authorgroup>
32       <author>
33         <contrib>A monkey with a typewriter</contrib>
34         <firstname>Zbigniew</firstname>
35         <surname>Jędrzejewski-Szmek</surname>
36         <email>zbyszek@in.waw.pl</email>
37       </author>
38     </authorgroup>
39   </refentryinfo>
40
41   <refmeta>
42     <refentrytitle>sd_bus_message_append</refentrytitle>
43     <manvolnum>3</manvolnum>
44   </refmeta>
45
46   <refnamediv>
47     <refname>sd_bus_message_append</refname>
48
49     <refpurpose>Attach parts of message based on a format string</refpurpose>
50   </refnamediv>
51
52   <refsynopsisdiv>
53     <funcsynopsis>
54       <funcsynopsisinfo>#include &lt;systemd/sd-bus.h&gt;</funcsynopsisinfo>
55
56       <funcprototype>
57         <funcdef>int sd_bus_message_append</funcdef>
58         <paramdef>sd_bus_message *<parameter>m</parameter></paramdef>
59         <paramdef>const char *<parameter>types</parameter></paramdef>
60         <paramdef>...</paramdef>
61       </funcprototype>
62     </funcsynopsis>
63   </refsynopsisdiv>
64
65   <refsect1>
66     <title>Description</title>
67
68     <para>The <function>sd_bus_message_append</function> function appends
69     a sequence of items to message <parameter>m</parameter>. The
70     format string <parameter>types</parameter> describes the types of
71     arguments that follow.</para>
72
73     <para>The format string is composed of the elements shown in the
74     table below. It contains zero or more single "complete types".
75     Each complete type may be one of the basic types or a fully
76     described container type. A container type may be a structure, a
77     variant type code, an array with its element type, or a dictionary
78     with its entry type. The format string is
79     <constant>NUL</constant>-terminated.</para>
80
81     <para>In case of a basic type, one argument of the corresponding
82     type is expected.</para>
83
84     <para>A structure is denoted by a sequence of complete types
85     between <literal>(</literal> and <literal>)</literal>. This
86     sequence cannot be empty — it must contain at least one type.
87     Arguments corresponding to this nested sequence follow the same
88     rules as if they were not nested.</para>
89
90     <para>A variant is denoted by <literal>v</literal>. Correspoding
91     arguments must include a format string denoting a complete type,
92     and following that, arguments corresponding to the specified type.
93     </para>
94
95     <para>An array is denoted by <literal>a</literal> followed by a
96     complete type. Corresponding arguments must include the size of
97     the array, and then repeated this number of times, arguments
98     corresponding to the nested type.</para>
99
100     <para>A dictionary is an array of dictionary entries, denoted by
101     <literal>a</literal> followed by a pair of complete types between
102     <literal>{</literal> and <literal>}</literal>. The first of those
103     types must be a basic type. Corresponding arguments must include
104     the size of the dictionary, and then repeated this number of
105     times, arguments corresponding to each of the two nested
106     types.</para>
107
108     <table>
109       <title>Item format specifiers</title>
110
111       <tgroup cols='4'>
112         <xi:include href="sd_bus_message_append_basic.xml" xpointer="xpointer(//table[@id='format-specifiers'])//colspec" />
113         <xi:include href="sd_bus_message_append_basic.xml" xpointer="xpointer(//table[@id='format-specifiers']//thead)" />
114
115         <tbody>
116           <xi:include href="sd_bus_message_append_basic.xml" xpointer="xpointer(//table[@id='format-specifiers']//tbody/*)" />
117
118           <row>
119             <entry><literal>a</literal></entry>
120             <entry><constant>SD_BUS_TYPE_ARRAY</constant></entry>
121             <entry>array</entry>
122             <entry>determined by array type and size</entry>
123           </row>
124
125           <row>
126             <entry><literal>v</literal></entry>
127             <entry><constant>SD_BUS_TYPE_VARIANT</constant></entry>
128             <entry>variant</entry>
129             <entry>determined by the type argument</entry>
130           </row>
131
132           <row>
133             <entry><literal>(</literal></entry>
134             <entry><constant>SD_BUS_TYPE_STRUCT_BEGIN</constant></entry>
135             <entry>array start</entry>
136             <entry morerows="1">determined by the nested types</entry>
137           </row>
138           <row>
139             <entry><literal>)</literal></entry>
140             <entry><constant>SD_BUS_TYPE_STRUCT_END</constant></entry>
141             <entry>array end</entry>
142           </row>
143
144           <row>
145             <entry><literal>{</literal></entry>
146             <entry><constant>SD_BUS_TYPE_DICT_ENTRY_BEGIN</constant></entry>
147             <entry>dictionary entry start</entry>
148             <entry morerows="1">determined by the nested types</entry>
149           </row>
150           <row>
151             <entry><literal>}</literal></entry>
152             <entry><constant>SD_BUS_TYPE_DICT_ENTRY_END</constant></entry>
153             <entry>dictionary entry end</entry>
154           </row>
155        </tbody>
156       </tgroup>
157     </table>
158   </refsect1>
159
160   <refsect1>
161     <title>Types string grammar</title>
162
163     <programlisting>types ::= complete_type*
164 complete_type ::= basic_type | variant | structure | array | dictionary
165 basic_type ::= "y" | "n" | "q" | "u" | "i" | "x" | "t" | "d" |
166                "b" | "h" |
167                "s" | "o" | "g"
168 variant ::= "v"
169 structure ::= "(" complete_type+ ")"
170 array ::= "a" complete_type
171 dictionary ::= "a" "{" basic_type complete_type "}"
172 </programlisting>
173   </refsect1>
174
175   <refsect1>
176     <title>Examples</title>
177
178     <para>Append a single basic type (the string <literal>a string</literal>):
179     </para>
180
181     <programlisting>sd_bus_message *m;
182 ...
183 sd_bus_message_append(m, "s", "a string");</programlisting>
184
185     <para>Append all types of integers:</para>
186
187     <programlisting>uint8_t y = 1;
188 int16_t n = 2;
189 uint16_t q = 3;
190 int32_t i = 4;
191 uint32_t u = 5;
192 int32_t x = 6;
193 uint32_t t = 7;
194 double d = 8.0;
195 sd_bus_message_append(m, "ynqiuxtd", y, n, q, i, u, x, t, d);</programlisting>
196
197      <para>Append a structure composed of string and a D-Bus path:</para>
198
199      <programlisting>sd_bus_message_append(m, "(so)", "a string", "/a/path");
200 </programlisting>
201
202      <para>Append an array of UNIX file descriptors:</para>
203
204      <programlisting>sd_bus_message_append(m, "ah", 3, STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO);
205 </programlisting>
206
207      <para>Append a variant, with the real type "g" (signature),
208      and value "sdbusisgood":</para>
209
210      <programlisting>sd_bus_message_append(m, "v", "g", "sdbusisgood");</programlisting>
211
212      <para>Append a dictionary containing the mapping {1=>"a", 2=>"b", 3=>""}:
213      </para>
214
215      <programlisting>sd_bus_message_append(m, "a{is}", 3, 1, "a", 2, "b", 3, NULL);
216      </programlisting>
217   </refsect1>
218
219   <refsect1>
220     <title>Return Value</title>
221
222     <para>On success, this call returns 0 or a positive
223     integer. On failure, this call returns a negative
224     errno-style error code.</para>
225   </refsect1>
226
227   <xi:include href="sd_bus_message_append_basic.xml" xpointer="errors" />
228
229   <refsect1>
230     <title>Notes</title>
231
232     <para><function>sd_bus_open_user()</function> and other functions
233     described here are available as a shared library, which can be
234     compiled and linked to with the
235     <constant>libsystemd-bus</constant> <citerefentry project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
236     file.</para>
237   </refsect1>
238
239   <refsect1>
240     <title>See Also</title>
241
242     <para>
243       <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
244       <citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
245       <citerefentry><refentrytitle>sd_bus_new</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
246       <citerefentry><refentrytitle>sd_bus_ref</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
247       <citerefentry><refentrytitle>sd_bus_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
248       <citerefentry><refentrytitle>ssh</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
249       <citerefentry><refentrytitle>systemd-machined.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
250       <citerefentry><refentrytitle>machinectl</refentrytitle><manvolnum>1</manvolnum></citerefentry>
251     </para>
252   </refsect1>
253
254 </refentry>