]>
Commit | Line | Data |
---|---|---|
514094f9 | 1 | <?xml version='1.0'?> |
3a54a157 ZJS |
2 | <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" |
3 | "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> | |
e382c49f | 4 | |
5 | <!-- | |
572eb058 ZJS |
6 | SPDX-License-Identifier: LGPL-2.1+ |
7 | ||
96b2fb93 | 8 | Copyright © 2016 Julian Orth |
e382c49f | 9 | --> |
10 | ||
11 | <refentry id="sd_bus_message_read_basic"> | |
12 | ||
13 | <refentryinfo> | |
14 | <title>sd_bus_message_read_basic</title> | |
15 | <productname>systemd</productname> | |
e382c49f | 16 | </refentryinfo> |
17 | ||
18 | <refmeta> | |
19 | <refentrytitle>sd_bus_message_read_basic</refentrytitle> | |
20 | <manvolnum>3</manvolnum> | |
21 | </refmeta> | |
22 | ||
23 | <refnamediv> | |
24 | <refname>sd_bus_message_read_basic</refname> | |
25 | ||
26 | <refpurpose>Read a basic type from a message</refpurpose> | |
27 | </refnamediv> | |
28 | ||
29 | <refsynopsisdiv> | |
30 | <funcsynopsis> | |
31 | <funcsynopsisinfo>#include <systemd/sd-bus.h></funcsynopsisinfo> | |
32 | ||
33 | <funcprototype> | |
34 | <funcdef>int <function>sd_bus_message_read_basic</function></funcdef> | |
35 | <paramdef>sd_bus_message *<parameter>m</parameter></paramdef> | |
36 | <paramdef>char <parameter>type</parameter></paramdef> | |
37 | <paramdef>void *<parameter>p</parameter></paramdef> | |
38 | </funcprototype> | |
39 | </funcsynopsis> | |
40 | </refsynopsisdiv> | |
41 | ||
42 | <refsect1> | |
43 | <title>Description</title> | |
44 | ||
45 | <para> | |
46 | <function>sd_bus_message_read_basic()</function> reads a basic type from a | |
47 | message and advances the read position in the message. The set of basic | |
48 | types and their ascii codes passed in <parameter>type</parameter> are | |
49 | described in the <ulink | |
50 | url="https://dbus.freedesktop.org/doc/dbus-specification.html">D-Bus | |
51 | Specification</ulink>. | |
52 | </para> | |
53 | ||
54 | <para> | |
50972aac ZJS |
55 | If <parameter>p</parameter> is not <constant>NULL</constant>, it should contain |
56 | a pointer to an appropriate object. For example, if <parameter>type</parameter> | |
57 | is <constant>'y'</constant>, the object passed in <parameter>p</parameter> | |
979bdc47 | 58 | should have type <type>uint8_t *</type>. If <parameter>type</parameter> is |
50972aac | 59 | <constant>'s'</constant>, the object passed in <parameter>p</parameter> should |
979bdc47 LP |
60 | have type <type>const char **</type>. Note that, if the basic type is a pointer |
61 | (e.g., <type>const char *</type> in the case of a string), the pointer is only | |
50972aac ZJS |
62 | borrowed and the contents must be copied if they are to be used after the end |
63 | of the messages lifetime. Similarly, during the lifetime of such a pointer, the | |
64 | message must not be modified. See the table below for a complete list of allowed | |
65 | types. | |
e382c49f | 66 | </para> |
67 | ||
50972aac ZJS |
68 | <table id='format-specifiers'> |
69 | <title>Item type specifiers</title> | |
70 | ||
71 | <tgroup cols='4'> | |
72 | <colspec colname='specifier' /> | |
73 | <colspec colname='constant' /> | |
74 | <colspec colname='description' /> | |
75 | <colspec colname='ctype' /> | |
76 | <thead> | |
77 | <row> | |
78 | <entry>Specifier</entry> | |
79 | <entry>Constant</entry> | |
80 | <entry>Description</entry> | |
81 | <entry>Expected C Type</entry> | |
82 | </row> | |
83 | </thead> | |
84 | <tbody> | |
85 | <row> | |
86 | <entry><literal>y</literal></entry> | |
87 | <entry><constant>SD_BUS_TYPE_BYTE</constant></entry> | |
e5667705 | 88 | <entry>8bit unsigned integer</entry> |
979bdc47 | 89 | <entry><type>uint8_t *</type></entry> |
50972aac ZJS |
90 | </row> |
91 | ||
92 | <row> | |
93 | <entry><literal>b</literal></entry> | |
94 | <entry><constant>SD_BUS_TYPE_BOOLEAN</constant></entry> | |
95 | <entry>boolean</entry> | |
10c238b2 | 96 | <entry><type>int *</type> (NB: not <type>bool *</type>)</entry> |
50972aac ZJS |
97 | </row> |
98 | ||
99 | <row> | |
100 | <entry><literal>n</literal></entry> | |
101 | <entry><constant>SD_BUS_TYPE_INT16</constant></entry> | |
e5667705 | 102 | <entry>16bit signed integer</entry> |
979bdc47 | 103 | <entry><type>int16_t *</type></entry> |
50972aac ZJS |
104 | </row> |
105 | ||
106 | <row> | |
107 | <entry><literal>q</literal></entry> | |
108 | <entry><constant>SD_BUS_TYPE_UINT16</constant></entry> | |
e5667705 | 109 | <entry>16bit unsigned integer</entry> |
979bdc47 | 110 | <entry><type>uint16_t *</type></entry> |
50972aac ZJS |
111 | </row> |
112 | ||
113 | <row> | |
114 | <entry><literal>i</literal></entry> | |
115 | <entry><constant>SD_BUS_TYPE_INT32</constant></entry> | |
e5667705 | 116 | <entry>32bit signed integer</entry> |
979bdc47 | 117 | <entry><type>int32_t *</type></entry> |
50972aac ZJS |
118 | </row> |
119 | ||
120 | <row> | |
121 | <entry><literal>u</literal></entry> | |
122 | <entry><constant>SD_BUS_TYPE_UINT32</constant></entry> | |
e5667705 | 123 | <entry>32bit unsigned integer</entry> |
979bdc47 | 124 | <entry><type>uint32_t *</type></entry> |
50972aac ZJS |
125 | </row> |
126 | ||
127 | <row> | |
128 | <entry><literal>x</literal></entry> | |
129 | <entry><constant>SD_BUS_TYPE_INT64</constant></entry> | |
e5667705 | 130 | <entry>64bit signed integer</entry> |
979bdc47 | 131 | <entry><type>int64_t *</type></entry> |
50972aac ZJS |
132 | </row> |
133 | ||
134 | <row> | |
135 | <entry><literal>t</literal></entry> | |
136 | <entry><constant>SD_BUS_TYPE_UINT64</constant></entry> | |
e5667705 | 137 | <entry>64bit unsigned integer</entry> |
979bdc47 | 138 | <entry><type>uint64_t *</type></entry> |
50972aac ZJS |
139 | </row> |
140 | ||
141 | <row> | |
142 | <entry><literal>d</literal></entry> | |
143 | <entry><constant>SD_BUS_TYPE_DOUBLE</constant></entry> | |
e5667705 | 144 | <entry>IEEE 754 double precision floating-point</entry> |
979bdc47 | 145 | <entry><type>double *</type></entry> |
50972aac ZJS |
146 | </row> |
147 | ||
148 | <row> | |
149 | <entry><literal>s</literal></entry> | |
150 | <entry><constant>SD_BUS_TYPE_STRING</constant></entry> | |
e5667705 | 151 | <entry>UTF-8 string</entry> |
979bdc47 | 152 | <entry><type>const char **</type></entry> |
50972aac ZJS |
153 | </row> |
154 | ||
155 | <row> | |
156 | <entry><literal>o</literal></entry> | |
157 | <entry><constant>SD_BUS_TYPE_OBJECT_PATH</constant></entry> | |
6dea2361 | 158 | <entry>D-Bus object path string</entry> |
979bdc47 | 159 | <entry><type>const char **</type></entry> |
50972aac ZJS |
160 | </row> |
161 | ||
162 | <row> | |
163 | <entry><literal>g</literal></entry> | |
164 | <entry><constant>SD_BUS_TYPE_SIGNATURE</constant></entry> | |
e5667705 | 165 | <entry>D-Bus signature string</entry> |
979bdc47 | 166 | <entry><type>const char **</type></entry> |
50972aac ZJS |
167 | </row> |
168 | ||
169 | <row> | |
170 | <entry><literal>h</literal></entry> | |
171 | <entry><constant>SD_BUS_TYPE_UNIX_FD</constant></entry> | |
172 | <entry>UNIX file descriptor</entry> | |
979bdc47 | 173 | <entry><type>int *</type></entry> |
50972aac ZJS |
174 | </row> |
175 | </tbody> | |
176 | </tgroup> | |
177 | </table> | |
178 | ||
e382c49f | 179 | <para> |
180 | If there is no object of the specified type at the current position in the | |
181 | message, an error is returned. | |
182 | </para> | |
183 | </refsect1> | |
184 | ||
185 | <refsect1> | |
186 | <title>Return Value</title> | |
187 | ||
188 | <para> | |
189 | On success, <function>sd_bus_message_read_basic()</function> returns 0 or | |
190 | a positive integer. On failure, it returns a negative errno-style error | |
191 | code. | |
192 | </para> | |
e382c49f | 193 | |
b1de39de ZJS |
194 | <refsect2 id='errors'> |
195 | <title>Errors</title> | |
50972aac | 196 | |
b1de39de | 197 | <para>Returned errors may indicate the following problems:</para> |
50972aac | 198 | |
b1de39de ZJS |
199 | <variablelist> |
200 | <varlistentry> | |
201 | <term><constant>-EINVAL</constant></term> | |
50972aac | 202 | |
b1de39de ZJS |
203 | <listitem><para>Specified type string is invalid or the message parameter is |
204 | <constant>NULL</constant>.</para></listitem> | |
205 | </varlistentry> | |
50972aac | 206 | |
b1de39de ZJS |
207 | <varlistentry> |
208 | <term><constant>-ENXIO</constant></term> | |
50972aac | 209 | |
b1de39de ZJS |
210 | <listitem><para>The message does not contain the specified type at current position. |
211 | </para></listitem> | |
212 | </varlistentry> | |
50972aac | 213 | |
b1de39de ZJS |
214 | <varlistentry> |
215 | <term><constant>-EBADMSG</constant></term> | |
50972aac | 216 | |
b1de39de ZJS |
217 | <listitem><para>The message cannot be parsed.</para></listitem> |
218 | </varlistentry> | |
219 | </variablelist> | |
220 | </refsect2> | |
50972aac ZJS |
221 | </refsect1> |
222 | ||
e382c49f | 223 | <refsect1> |
224 | <title>See Also</title> | |
225 | ||
226 | <para> | |
227 | <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, | |
228 | <citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
50972aac | 229 | <citerefentry><refentrytitle>sd_bus_message_append_basic</refentrytitle><manvolnum>3</manvolnum></citerefentry>, |
58df2afb | 230 | <citerefentry><refentrytitle>sd_bus_message_skip</refentrytitle><manvolnum>3</manvolnum></citerefentry>, |
50972aac | 231 | <citerefentry><refentrytitle>sd_bus_message_read</refentrytitle><manvolnum>3</manvolnum></citerefentry> |
e382c49f | 232 | </para> |
233 | </refsect1> | |
234 | ||
235 | </refentry> |