2 <!DOCTYPE refentry PUBLIC
"-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
6 SPDX-License-Identifier: LGPL-2.1+
9 <refentry id=
"sd_bus_message_read"
10 xmlns:
xi=
"http://www.w3.org/2001/XInclude">
13 <title>sd_bus_message_read
</title>
14 <productname>systemd
</productname>
18 <refentrytitle>sd_bus_message_read
</refentrytitle>
19 <manvolnum>3</manvolnum>
23 <refname>sd_bus_message_read
</refname>
24 <refname>sd_bus_message_readv
</refname>
26 <refpurpose>Read a sequence of values from a message
</refpurpose>
31 <funcsynopsisinfo>#include
<systemd/sd-bus.h
></funcsynopsisinfo>
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>
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>
50 <title>Description
</title>
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
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>
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>
76 <para>Each argument may also be
<constant>NULL
</constant>, in which case the value is read and
80 <title>Item type specifiers
</title>
83 <colspec colname='specifier'
/>
84 <colspec colname='constant'
/>
85 <colspec colname='description'
/>
86 <colspec colname='type1'
/>
87 <colspec colname='type2'
/>
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>
99 <xi:include href=
"sd_bus_message_read_basic.xml" xpointer=
"xpointer(//table[@id='format-specifiers']//tbody/*)" />
102 <entry><literal>a
</literal></entry>
103 <entry><constant>SD_BUS_TYPE_ARRAY
</constant></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>
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>
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>
124 <entry><literal>)
</literal></entry>
125 <entry><constant>SD_BUS_TYPE_STRUCT_END
</constant></entry>
126 <entry>array end
</entry>
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>
137 <entry><literal>}
</literal></entry>
138 <entry><constant>SD_BUS_TYPE_DICT_ENTRY_END
</constant></entry>
139 <entry>dictionary entry end
</entry>
145 <para>If objects of the specified types are not present at the current position
146 in the message, an error is returned.
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>
158 <title>Return Value
</title>
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.
167 <xi:include href=
"sd_bus_message_read_basic.xml" xpointer=
"errors" />
169 <xi:include href=
"libsystemd-pkgconfig.xml" />
172 <title>Examples
</title>
174 <para>Read a single basic type (a
64-bit integer):
177 <programlisting>sd_bus_message *m;
180 sd_bus_message_read(m,
"x",
&x);
</programlisting>
182 <para>Read all types of integers:
</para>
184 <programlisting>uint8_t y;
193 sd_bus_message_read(m,
"ynqiuxtd",
&y,
&n,
&q,
&i,
&u,
&x,
&t,
&d);
</programlisting>
195 <para>Read a structure composed of a string and a D-Bus path:
</para>
197 <programlisting>const char *s, *p;
199 sd_bus_message_read(m,
"(so)",
&s,
&p);
202 <para>Read a variant, with the real type
"gt" (signature, unsigned integer):
205 <programlisting>const char *s;
208 sd_bus_message_read(m,
"v",
"gt",
&s,
&v);
</programlisting>
210 <para>Read a dictionary containing three pairs of type {integer=
>string}:
213 <programlisting>int i, j, k;
214 const char *s, *t, *u;
216 sd_bus_message_read(m,
"a{is}",
3,
&i,
&s,
&j,
&t,
&k,
&u);
221 <title>See Also
</title>
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_skip
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
228 <citerefentry><refentrytitle>sd_bus_message_append
</refentrytitle><manvolnum>3</manvolnum></citerefentry>