]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/sd_bus_message_read.xml
namespace: implicitly adds DeviceAllow= when RootImage= is set
[thirdparty/systemd.git] / man / sd_bus_message_read.xml
1 <?xml version='1.0'?>
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_read"
10 xmlns:xi="http://www.w3.org/2001/XInclude">
11
12 <refentryinfo>
13 <title>sd_bus_message_read</title>
14 <productname>systemd</productname>
15 </refentryinfo>
16
17 <refmeta>
18 <refentrytitle>sd_bus_message_read</refentrytitle>
19 <manvolnum>3</manvolnum>
20 </refmeta>
21
22 <refnamediv>
23 <refname>sd_bus_message_read</refname>
24 <refname>sd_bus_message_readv</refname>
25
26 <refpurpose>Read a sequence of values from a message</refpurpose>
27 </refnamediv>
28
29 <refsynopsisdiv>
30 <funcsynopsis>
31 <funcsynopsisinfo>#include &lt;systemd/sd-bus.h&gt;</funcsynopsisinfo>
32
33 <funcprototype>
34 <funcdef>int <function>sd_bus_message_read</function></funcdef>
35 <paramdef>sd_bus_message *<parameter>m</parameter></paramdef>
36 <paramdef>char char *<parameter>types</parameter></paramdef>
37 <paramdef>...</paramdef>
38 </funcprototype>
39
40 <funcprototype>
41 <funcdef>int <function>sd_bus_message_readv</function></funcdef>
42 <paramdef>sd_bus_message *<parameter>m</parameter></paramdef>
43 <paramdef>char char *<parameter>types</parameter></paramdef>
44 <paramdef>va_list <parameter>ap</parameter></paramdef>
45 </funcprototype>
46 </funcsynopsis>
47 </refsynopsisdiv>
48
49 <refsect1>
50 <title>Description</title>
51
52 <para><function>sd_bus_message_read()</function> reads a sequence of fields from
53 the D-Bus message object <parameter>m</parameter> and advances the read position
54 in the message. The type string <parameter>types</parameter> describes the types
55 of items expected in the message and the field arguments that follow. The type
56 string may be <constant>NULL</constant> or empty, in which case nothing is
57 read.</para>
58
59 <para>The type string is composed of the elements described in
60 <citerefentry><refentrytitle>sd_bus_message_append</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
61 i.e. basic and container types. It must contain zero or more single "complete
62 types". The type string is <constant>NUL</constant>-terminated.</para>
63
64 <para>For each type specified in the type string, one or more arguments need to be specified
65 after the <parameter>types</parameter> parameter, in the same order. The arguments must be
66 pointers to appropriate types (a pointer to <code>int8_t</code> for a <literal>y</literal> in
67 the type string, a pointer to <code>int32_t</code> for an <literal>i</literal>, a pointer to
68 <code>const char*</code> for an <literal>s</literal>, ...) which are set based on the values in
69 the message. As an exception, in case or array and variant types, the first argument is an
70 "input" argument that further specifies how the message should be read. See the table below for
71 a complete list of allowed arguments and their types. Note that, if the basic type is a pointer
72 (e.g., <code>const char *</code> in the case of a string), the argument is a pointer to a
73 pointer, and also the pointer value that is written is only borrowed and the contents must be
74 copied if they are to be used after the end of the messages lifetime.</para>
75
76 <para>Each argument may also be <constant>NULL</constant>, in which case the value is read and
77 ignored.</para>
78
79 <table>
80 <title>Item type specifiers</title>
81
82 <tgroup cols='5'>
83 <colspec colname='specifier' />
84 <colspec colname='constant' />
85 <colspec colname='description' />
86 <colspec colname='type1' />
87 <colspec colname='type2' />
88 <thead>
89 <row>
90 <entry>Specifier</entry>
91 <entry>Constant</entry>
92 <entry>Description</entry>
93 <entry>Type of the first argument</entry>
94 <entry>Types of the subsequent arguments, if any</entry>
95 </row>
96 </thead>
97
98 <tbody>
99 <xi:include href="sd_bus_message_read_basic.xml" xpointer="xpointer(//table[@id='format-specifiers']//tbody/*)" />
100
101 <row>
102 <entry><literal>a</literal></entry>
103 <entry><constant>SD_BUS_TYPE_ARRAY</constant></entry>
104 <entry>array</entry>
105 <entry>int, which specifies the expected length <parameter>n</parameter> of the array</entry>
106 <entry><parameter>n</parameter> sets of arguments appropriate for the array element type</entry>
107 </row>
108
109 <row>
110 <entry><literal>v</literal></entry>
111 <entry><constant>SD_BUS_TYPE_VARIANT</constant></entry>
112 <entry>variant</entry>
113 <entry>signature string</entry>
114 <entry>arguments appropriate for the types specified by the signature</entry>
115 </row>
116
117 <row>
118 <entry><literal>(</literal></entry>
119 <entry><constant>SD_BUS_TYPE_STRUCT_BEGIN</constant></entry>
120 <entry>array start</entry>
121 <entry morerows="1" namest="type1" nameend="type2">arguments appropriate for the structure elements</entry>
122 </row>
123 <row>
124 <entry><literal>)</literal></entry>
125 <entry><constant>SD_BUS_TYPE_STRUCT_END</constant></entry>
126 <entry>array end</entry>
127 </row>
128
129 <row>
130 <entry><literal>{</literal></entry>
131 <entry><constant>SD_BUS_TYPE_DICT_ENTRY_BEGIN</constant></entry>
132 <entry>dictionary entry start</entry>
133 <entry morerows="1">arguments appropriate for the first type in the pair</entry>
134 <entry morerows="1">arguments appropriate for the second type in the pair</entry>
135 </row>
136 <row>
137 <entry><literal>}</literal></entry>
138 <entry><constant>SD_BUS_TYPE_DICT_ENTRY_END</constant></entry>
139 <entry>dictionary entry end</entry>
140 </row>
141 </tbody>
142 </tgroup>
143 </table>
144
145 <para>If objects of the specified types are not present at the current position
146 in the message, an error is returned.
147 </para>
148
149 <para>The <function>sd_bus_message_readv()</function> is equivalent to the
150 <function>sd_bus_message_read()</function>, except that it is called with a
151 <literal>va_list</literal> instead of a variable number of arguments. This
152 function does not call the <function>va_end()</function> macro. Because it
153 invokes the <function>va_arg()</function> macro, the value of
154 <parameter>ap</parameter> is undefined after the call.</para>
155 </refsect1>
156
157 <refsect1>
158 <title>Return Value</title>
159
160 <para>
161 On success, <function>sd_bus_message_read()</function> and
162 <function>sd_bus_message_readv()</function> return 0 or a positive integer. On
163 failure, they return a negative errno-style error code.
164 </para>
165 </refsect1>
166
167 <xi:include href="sd_bus_message_read_basic.xml" xpointer="errors" />
168
169 <xi:include href="libsystemd-pkgconfig.xml" />
170
171 <refsect1>
172 <title>Examples</title>
173
174 <para>Read a single basic type (a 64-bit integer):
175 </para>
176
177 <programlisting>sd_bus_message *m;
178 int64_t x;
179
180 sd_bus_message_read(m, "x", &amp;x);</programlisting>
181
182 <para>Read all types of integers:</para>
183
184 <programlisting>uint8_t y;
185 int16_t n;
186 uint16_t q;
187 int32_t i;
188 uint32_t u;
189 int32_t x;
190 uint32_t t;
191 double d;
192
193 sd_bus_message_read(m, "ynqiuxtd", &amp;y, &amp;n, &amp;q, &amp;i, &amp;u, &amp;x, &amp;t, &amp;d);</programlisting>
194
195 <para>Read a structure composed of a string and a D-Bus path:</para>
196
197 <programlisting>const char *s, *p;
198
199 sd_bus_message_read(m, "(so)", &amp;s, &amp;p);
200 </programlisting>
201
202 <para>Read a variant, with the real type "gt" (signature, unsigned integer):
203 </para>
204
205 <programlisting>const char *s;
206 uint64_t *v;
207
208 sd_bus_message_read(m, "v", "gt", &amp;s, &amp;v);</programlisting>
209
210 <para>Read a dictionary containing three pairs of type {integer=>string}:
211 </para>
212
213 <programlisting>int i, j, k;
214 const char *s, *t, *u;
215
216 sd_bus_message_read(m, "a{is}", 3, &amp;i, &amp;s, &amp;j, &amp;t, &amp;k, &amp;u);
217 </programlisting>
218 </refsect1>
219
220 <refsect1>
221 <title>See Also</title>
222
223 <para>
224 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
225 <citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
226 <citerefentry><refentrytitle>sd_bus_message_read_basic</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
227 <citerefentry><refentrytitle>sd_bus_message_append</refentrytitle><manvolnum>3</manvolnum></citerefentry>
228 </para>
229 </refsect1>
230
231 </refentry>