1SD_BUS_MESSAGE_READ(3)        sd_bus_message_read       SD_BUS_MESSAGE_READ(3)
2
3
4

NAME

6       sd_bus_message_read, sd_bus_message_readv, sd_bus_message_peek_type -
7       Read a sequence of values from a message
8

SYNOPSIS

10       #include <systemd/sd-bus.h>
11
12       int sd_bus_message_read(sd_bus_message *m, const char *types, ...);
13
14       int sd_bus_message_readv(sd_bus_message *m, const char *types,
15                                va_list ap);
16
17       int sd_bus_message_peek_type(sd_bus_message *m, char *type,
18                                    const char **contents);
19

DESCRIPTION

21       sd_bus_message_read() reads a sequence of fields from the D-Bus message
22       object m and advances the read position in the message. The type string
23       types describes the types of items expected in the message and the
24       field arguments that follow. The type string may be NULL or empty, in
25       which case nothing is read.
26
27       The type string is composed of the elements described in
28       sd_bus_message_append(3), i.e. basic and container types. It must
29       contain zero or more single "complete types". The type string is
30       NUL-terminated.
31
32       For each type specified in the type string, one or more arguments need
33       to be specified after the types parameter, in the same order. The
34       arguments must be pointers to appropriate types (a pointer to int8_t
35       for a "y" in the type string, a pointer to int32_t for an "i", a
36       pointer to const char* for an "s", ...) which are set based on the
37       values in the message. As an exception, in case of array and variant
38       types, the first argument is an "input" argument that further specifies
39       how the message should be read. See the table below for a complete list
40       of allowed arguments and their types. Note that, if the basic type is a
41       pointer (e.g., const char * in the case of a string), the argument is a
42       pointer to a pointer, and also the pointer value that is written is
43       only borrowed and the contents must be copied if they are to be used
44       after the end of the message's lifetime. If the type is "h" (UNIX file
45       descriptor), the descriptor is not duplicated by this call and the
46       returned descriptor remains in possession of the message object, and
47       needs to be duplicated by the caller in order to keep an open reference
48       to it after the message object is freed.
49
50       Each argument may also be NULL, in which case the value is read and
51       ignored.
52
53       Table 1. Item type specifiers
54       ┌──────────┬──────────────────────────────┬────────────────┬───────────────┬───────────────┐
55Specifier Constant                     Description    Type of the   Types of the  
56       │          │                              │                │ first         subsequent    
57       │          │                              │                │ argument      arguments, if 
58       │          │                              │                │               │ any           
59       ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
60       │"y"       │ SD_BUS_TYPE_BYTE             │ 8-bit          │ uint8_t *     │               │
61       │          │                              │ unsigned       │               │               │
62       │          │                              │ integer        │               │               │
63       ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
64       │"b"       │ SD_BUS_TYPE_BOOLEAN          │ boolean        │ int * (NB:    │               │
65       │          │                              │                │ not bool *)   │               │
66       ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
67       │"n"       │ SD_BUS_TYPE_INT16            │ 16-bit signed  │ int16_t *     │               │
68       │          │                              │ integer        │               │               │
69       ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
70       │"q"       │ SD_BUS_TYPE_UINT16           │ 16-bit         │ uint16_t *    │               │
71       │          │                              │ unsigned       │               │               │
72       │          │                              │ integer        │               │               │
73       ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
74       │"i"       │ SD_BUS_TYPE_INT32            │ 32-bit signed  │ int32_t *     │               │
75       │          │                              │ integer        │               │               │
76       ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
77       │"u"       │ SD_BUS_TYPE_UINT32           │ 32-bit         │ uint32_t *    │               │
78       │          │                              │ unsigned       │               │               │
79       │          │                              │ integer        │               │               │
80       ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
81       │"x"       │ SD_BUS_TYPE_INT64            │ 64-bit signed  │ int64_t *     │               │
82       │          │                              │ integer        │               │               │
83       ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
84       │"t"       │ SD_BUS_TYPE_UINT64           │ 64-bit         │ uint64_t *    │               │
85       │          │                              │ unsigned       │               │               │
86       │          │                              │ integer        │               │               │
87       ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
88       │"d"       │ SD_BUS_TYPE_DOUBLE           │ IEEE 754       │ double *      │               │
89       │          │                              │ double         │               │               │
90       │          │                              │ precision      │               │               │
91       │          │                              │ floating-point │               │               │
92       ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
93       │"s"       │ SD_BUS_TYPE_STRING           │ UTF-8 string   │ const char ** │               │
94       ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
95       │"o"       │ SD_BUS_TYPE_OBJECT_PATH      │ D-Bus object   │ const char ** │               │
96       │          │                              │ path string    │               │               │
97       ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
98       │"g"       │ SD_BUS_TYPE_SIGNATURE        │ D-Bus          │ const char ** │               │
99       │          │                              │ signature      │               │               │
100       │          │                              │ string         │               │               │
101       ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
102       │"h"       │ SD_BUS_TYPE_UNIX_FD          │ UNIX file      │ int *         │               │
103       │          │                              │ descriptor     │               │               │
104       ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
105       │"a"       │ SD_BUS_TYPE_ARRAY            │ array          │ int, which    │ n sets of     │
106       │          │                              │                │ specifies the │ arguments     │
107       │          │                              │                │ expected      │ appropriate   │
108       │          │                              │                │ length n of   │ for the array │
109       │          │                              │                │ the array     │ element type  │
110       ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
111       │"v"       │ SD_BUS_TYPE_VARIANT          │ variant        │ signature     │ arguments     │
112       │          │                              │                │ string        │ appropriate   │
113       │          │                              │                │               │ for the types │
114       │          │                              │                │               │ specified by  │
115       │          │                              │                │               │ the signature │
116       ├──────────┼──────────────────────────────┼────────────────┼───────────────┴───────────────┤
117       │"("       │ SD_BUS_TYPE_STRUCT_BEGIN     │ array start    │ arguments appropriate for     │
118       ├──────────┼──────────────────────────────┼────────────────┤ the structure elements        │
119       │")"       │ SD_BUS_TYPE_STRUCT_END       │ array end      │                               │
120       ├──────────┼──────────────────────────────┼────────────────┼───────────────┬───────────────┤
121       │"{"       │ SD_BUS_TYPE_DICT_ENTRY_BEGIN │ dictionary     │ arguments     │ arguments     │
122       │          │                              │ entry start    │ appropriate   │ appropriate   │
123       ├──────────┼──────────────────────────────┼────────────────┤ for the first │ for the       │
124       │"}"       │ SD_BUS_TYPE_DICT_ENTRY_END   │ dictionary     │ type in the   │ second type   │
125       │          │                              │ entry end      │ pair          │ in the pair   │
126       └──────────┴──────────────────────────────┴────────────────┴───────────────┴───────────────┘
127
128       If objects of the specified types are not present at the current
129       position in the message, an error is returned.
130
131       The sd_bus_message_readv() is equivalent to the sd_bus_message_read(),
132       except that it is called with a "va_list" instead of a variable number
133       of arguments. This function does not call the va_end() macro. Because
134       it invokes the va_arg() macro, the value of ap is undefined after the
135       call.
136
137       sd_bus_message_peek_type() determines the type of the next element in m
138       to be read by sd_bus_message_read() or similar functions. On success,
139       the type is stored in type, if it is not NULL. If the type is a
140       container type, the type of its elements is stored in contents, if it
141       is not NULL. If this function successfully determines the type of the
142       next element in m, it returns a positive integer. If there are no more
143       elements to be read, it returns zero.
144

RETURN VALUE

146       On success, these functions return a non-negative integer. On failure,
147       they return a negative errno-style error code.
148
149   Errors
150       Returned errors may indicate the following problems:
151
152       -EINVAL
153           Specified type string is invalid or the message parameter is NULL.
154
155       -ENXIO
156           The message does not contain the specified type at current
157           position.
158
159       -EBADMSG
160           The message cannot be parsed.
161
162       -EBUSY
163           When reading from a container, this error will be returned if
164           unread elements are left in the container.
165

NOTES

167       Functions described here are available as a shared library, which can
168       be compiled against and linked to with the libsystemd pkg-config(1)
169       file.
170
171       The code described here uses getenv(3), which is declared to be not
172       multi-thread-safe. This means that the code calling the functions
173       described here must not call setenv(3) from a parallel thread. It is
174       recommended to only do calls to setenv() from an early phase of the
175       program when no other threads have been started.
176

EXAMPLES

178       Read a single basic type (a 64-bit integer):
179
180           sd_bus_message *m;
181           int64_t x;
182
183           sd_bus_message_read(m, "x", &x);
184
185       Read a boolean value:
186
187           sd_bus_message *m;
188           int x; /* Do not use C99 'bool' type here, it's typically smaller
189                     in memory and would cause memory corruption */
190
191           sd_bus_message_read(m, "b", &x);
192
193       Read all types of integers:
194
195           uint8_t y;
196           int16_t n;
197           uint16_t q;
198           int32_t i;
199           uint32_t u;
200           int32_t x;
201           uint32_t t;
202           double d;
203
204           sd_bus_message_read(m, "ynqiuxtd", &y, &n, &q, &i, &u, &x, &t, &d);
205
206       Read a structure composed of a string and a D-Bus path:
207
208           const char *s, *p;
209
210           sd_bus_message_read(m, "(so)", &s, &p);
211
212       Read a variant, with the real type "gt" (signature, unsigned integer):
213
214           const char *s;
215           uint64_t *v;
216
217           sd_bus_message_read(m, "v", "gt", &s, &v);
218
219       Read a dictionary containing three pairs of type {integer=>string}:
220
221           int i, j, k;
222           const char *s, *t, *u;
223
224           sd_bus_message_read(m, "a{is}", 3, &i, &s, &j, &t, &k, &u);
225
226
227       Read a single file descriptor, and duplicate it in order to keep it
228       open after the message is freed.
229
230           sd_bus_message *m;
231           int fd, fd_copy;
232
233           sd_bus_message_read(m, "h", &fd);
234           fd_copy = fcntl(fd, FD_DUPFD_CLOEXEC, 3);
235

SEE ALSO

237       systemd(1), sd-bus(3), sd_bus_message_read_basic(3),
238       sd_bus_message_skip(3), sd_bus_message_append(3),
239       sd_bus_message_enter_container(3)
240
241
242
243systemd 254                                             SD_BUS_MESSAGE_READ(3)
Impressum