1SD_BUS_MESSAGE_READ(3) sd_bus_message_read SD_BUS_MESSAGE_READ(3)
2
3
4
6 sd_bus_message_read, sd_bus_message_readv - Read a sequence of values
7 from a message
8
10 #include <systemd/sd-bus.h>
11
12 int sd_bus_message_read(sd_bus_message *m, char char *types, ...);
13
14 int sd_bus_message_readv(sd_bus_message *m, char char *types,
15 va_list ap);
16
18 sd_bus_message_read() reads a sequence of fields from the D-Bus message
19 object m and advances the read position in the message. The type string
20 types describes the types of items expected in the message and the
21 field arguments that follow. The type string may be NULL or empty, in
22 which case nothing is read.
23
24 The type string is composed of the elements described in
25 sd_bus_message_append(3), i.e. basic and container types. It must
26 contain zero or more single "complete types". The type string is
27 NUL-terminated.
28
29 For each type specified in the type string, one or more arguments need
30 to be specified after the types parameter, in the same order. The
31 arguments must be pointers to appropriate types (a pointer to int8_t
32 for a "y" in the type string, a pointer to int32_t for an "i", a
33 pointer to const char* for an "s", ...) which are set based on the
34 values in the message. As an exception, in case or array and variant
35 types, the first argument is an "input" argument that further specifies
36 how the message should be read. See the table below for a complete list
37 of allowed arguments and their types. Note that, if the basic type is a
38 pointer (e.g., const char * in the case of a string), the argument is a
39 pointer to a pointer, and also the pointer value that is written is
40 only borrowed and the contents must be copied if they are to be used
41 after the end of the messages lifetime.
42
43 Each argument may also be NULL, in which case the value is read and
44 ignored.
45
46 Table 1. Item type specifiers
47 ┌──────────┬──────────────────────────────┬────────────────┬───────────────┬───────────────┐
48 │Specifier │ Constant │ Description │ Type of the │ Types of the │
49 │ │ │ │ first │ subsequent │
50 │ │ │ │ argument │ arguments, if │
51 │ │ │ │ │ any │
52 ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
53 │"y" │ SD_BUS_TYPE_BYTE │ 8bit unsigned │ uint8_t * │ │
54 │ │ │ integer │ │ │
55 ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
56 │"b" │ SD_BUS_TYPE_BOOLEAN │ boolean │ int * (NB: │ │
57 │ │ │ │ not bool *) │ │
58 ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
59 │"n" │ SD_BUS_TYPE_INT16 │ 16bit signed │ int16_t * │ │
60 │ │ │ integer │ │ │
61 ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
62 │"q" │ SD_BUS_TYPE_UINT16 │ 16bit │ uint16_t * │ │
63 │ │ │ unsigned │ │ │
64 │ │ │ integer │ │ │
65 ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
66 │"i" │ SD_BUS_TYPE_INT32 │ 32bit signed │ int32_t * │ │
67 │ │ │ integer │ │ │
68 ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
69 │"u" │ SD_BUS_TYPE_UINT32 │ 32bit │ uint32_t * │ │
70 │ │ │ unsigned │ │ │
71 │ │ │ integer │ │ │
72 ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
73 │"x" │ SD_BUS_TYPE_INT64 │ 64bit signed │ int64_t * │ │
74 │ │ │ integer │ │ │
75 ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
76 │"t" │ SD_BUS_TYPE_UINT64 │ 64bit │ uint64_t * │ │
77 │ │ │ unsigned │ │ │
78 │ │ │ integer │ │ │
79 ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
80 │"d" │ SD_BUS_TYPE_DOUBLE │ IEEE 754 │ double * │ │
81 │ │ │ double │ │ │
82 │ │ │ precision │ │ │
83 │ │ │ floating-point │ │ │
84 ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
85 │"s" │ SD_BUS_TYPE_STRING │ UTF-8 string │ const char ** │ │
86 ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
87 │"o" │ SD_BUS_TYPE_OBJECT_PATH │ D-Bus object │ const char ** │ │
88 │ │ │ path string │ │ │
89 ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
90 │"g" │ SD_BUS_TYPE_SIGNATURE │ D-Bus │ const char ** │ │
91 │ │ │ signature │ │ │
92 │ │ │ string │ │ │
93 ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
94 │"h" │ SD_BUS_TYPE_UNIX_FD │ UNIX file │ int * │ │
95 │ │ │ descriptor │ │ │
96 ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
97 │"a" │ SD_BUS_TYPE_ARRAY │ array │ int, which │ n sets of │
98 │ │ │ │ specifies the │ arguments │
99 │ │ │ │ expected │ appropriate │
100 │ │ │ │ length n of │ for the array │
101 │ │ │ │ the array │ element type │
102 ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
103 │"v" │ SD_BUS_TYPE_VARIANT │ variant │ signature │ arguments │
104 │ │ │ │ string │ appropriate │
105 │ │ │ │ │ for the types │
106 │ │ │ │ │ specified by │
107 │ │ │ │ │ the signature │
108 ├──────────┼──────────────────────────────┼────────────────┼───────────────┴───────────────┤
109 │"(" │ SD_BUS_TYPE_STRUCT_BEGIN │ array start │ arguments appropriate for │
110 ├──────────┼──────────────────────────────┼────────────────┤ the structure elements │
111 │")" │ SD_BUS_TYPE_STRUCT_END │ array end │ │
112 ├──────────┼──────────────────────────────┼────────────────┼───────────────┬───────────────┤
113 │"{" │ SD_BUS_TYPE_DICT_ENTRY_BEGIN │ dictionary │ arguments │ arguments │
114 │ │ │ entry start │ appropriate │ appropriate │
115 ├──────────┼──────────────────────────────┼────────────────┤ for the first │ for the │
116 │"}" │ SD_BUS_TYPE_DICT_ENTRY_END │ dictionary │ type in the │ second type │
117 │ │ │ entry end │ pair │ in the pair │
118 └──────────┴──────────────────────────────┴────────────────┴───────────────┴───────────────┘
119
120 If objects of the specified types are not present at the current
121 position in the message, an error is returned.
122
123 The sd_bus_message_readv() is equivalent to the sd_bus_message_read(),
124 except that it is called with a "va_list" instead of a variable number
125 of arguments. This function does not call the va_end() macro. Because
126 it invokes the va_arg() macro, the value of ap is undefined after the
127 call.
128
130 On success, sd_bus_message_read() and sd_bus_message_readv() return 0
131 or a positive integer. On failure, they return a negative errno-style
132 error code.
133
134 Errors
135 Returned errors may indicate the following problems:
136
137 -EINVAL
138 Specified type string is invalid or the message parameter is NULL.
139
140 -ENXIO
141 The message does not contain the specified type at current
142 position.
143
144 -EBADMSG
145 The message cannot be parsed.
146
148 These APIs are implemented as a shared library, which can be compiled
149 and linked to with the libsystemd pkg-config(1) file.
150
152 Read a single basic type (a 64-bit integer):
153
154 sd_bus_message *m;
155 int64_t x;
156
157 sd_bus_message_read(m, "x", &x);
158
159 Read a boolean value:
160
161 sd_bus_message *m;
162 int x; /* Do not use C99 'bool' type here, it's typically smaller
163 in memory and would cause memory corruption */
164
165 sd_bus_message_read(m, "b", &x);
166
167 Read all types of integers:
168
169 uint8_t y;
170 int16_t n;
171 uint16_t q;
172 int32_t i;
173 uint32_t u;
174 int32_t x;
175 uint32_t t;
176 double d;
177
178 sd_bus_message_read(m, "ynqiuxtd", &y, &n, &q, &i, &u, &x, &t, &d);
179
180 Read a structure composed of a string and a D-Bus path:
181
182 const char *s, *p;
183
184 sd_bus_message_read(m, "(so)", &s, &p);
185
186 Read a variant, with the real type "gt" (signature, unsigned integer):
187
188 const char *s;
189 uint64_t *v;
190
191 sd_bus_message_read(m, "v", "gt", &s, &v);
192
193 Read a dictionary containing three pairs of type {integer=>string}:
194
195 int i, j, k;
196 const char *s, *t, *u;
197
198 sd_bus_message_read(m, "a{is}", 3, &i, &s, &j, &t, &k, &u);
199
200
202 systemd(1), sd-bus(3), sd_bus_message_read_basic(3),
203 sd_bus_message_skip(3), sd_bus_message_append(3)
204
205
206
207systemd 245 SD_BUS_MESSAGE_READ(3)