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 - Read a sequence of values
7       from a message
8

SYNOPSIS

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

DESCRIPTION

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       ┌──────────┬──────────────────────────────┬────────────────┬───────────────┬───────────────┐
48Specifier Constant                     Description    Type of the   Types of the  
49       │          │                              │                │ first         subsequent    
50       │          │                              │                │ argument      arguments, if 
51       │          │                              │                │               │ any           
52       ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
53       │"y"       │ SD_BUS_TYPE_BYTE             │ unsigned       │ uint8_t *     │               │
54       │          │                              │ integer        │               │               │
55       ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
56       │"b"       │ SD_BUS_TYPE_BOOLEAN          │ boolean        │ int *         │               │
57       ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
58       │"n"       │ SD_BUS_TYPE_INT16            │ signed         │ int16_t *     │               │
59       │          │                              │ integer        │               │               │
60       ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
61       │"q"       │ SD_BUS_TYPE_UINT16           │ unsigned       │ uint16_t *    │               │
62       │          │                              │ integer        │               │               │
63       ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
64       │"i"       │ SD_BUS_TYPE_INT32            │ signed         │ int32_t *     │               │
65       │          │                              │ integer        │               │               │
66       ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
67       │"u"       │ SD_BUS_TYPE_UINT32           │ unsigned       │ uint32_t *    │               │
68       │          │                              │ integer        │               │               │
69       ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
70       │"x"       │ SD_BUS_TYPE_INT64            │ signed         │ int64_t *     │               │
71       │          │                              │ integer        │               │               │
72       ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
73       │"t"       │ SD_BUS_TYPE_UINT64           │ unsigned       │ uint64_t *    │               │
74       │          │                              │ integer        │               │               │
75       ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
76       │"d"       │ SD_BUS_TYPE_DOUBLE           │ floating-point │ double *      │               │
77       ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
78       │"s"       │ SD_BUS_TYPE_STRING           │ Unicode string │ const char ** │               │
79       ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
80       │"o"       │ SD_BUS_TYPE_OBJECT_PATH      │ object path    │ const char ** │               │
81       ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
82       │"g"       │ SD_BUS_TYPE_SIGNATURE        │ signature      │ const char ** │               │
83       ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
84       │"h"       │ SD_BUS_TYPE_UNIX_FD          │ UNIX file      │ int *         │               │
85       │          │                              │ descriptor     │               │               │
86       ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
87       │"a"       │ SD_BUS_TYPE_ARRAY            │ array          │ int, which    │ n sets of     │
88       │          │                              │                │ specifies the │ arguments     │
89       │          │                              │                │ expected      │ appropriate   │
90       │          │                              │                │ length n of   │ for the array │
91       │          │                              │                │ the array     │ element type  │
92       ├──────────┼──────────────────────────────┼────────────────┼───────────────┼───────────────┤
93       │"v"       │ SD_BUS_TYPE_VARIANT          │ variant        │ signature     │ arguments     │
94       │          │                              │                │ string        │ appropriate   │
95       │          │                              │                │               │ for the types │
96       │          │                              │                │               │ specified by  │
97       │          │                              │                │               │ the signature │
98       ├──────────┼──────────────────────────────┼────────────────┼───────────────┴───────────────┤
99       │"("       │ SD_BUS_TYPE_STRUCT_BEGIN     │ array start    │ arguments appropriate for     │
100       ├──────────┼──────────────────────────────┼────────────────┤ the structure elements        │
101       │")"       │ SD_BUS_TYPE_STRUCT_END       │ array end      │                               │
102       ├──────────┼──────────────────────────────┼────────────────┼───────────────┬───────────────┤
103       │"{"       │ SD_BUS_TYPE_DICT_ENTRY_BEGIN │ dictionary     │ arguments     │ arguments     │
104       │          │                              │ entry start    │ appropriate   │ appropriate   │
105       ├──────────┼──────────────────────────────┼────────────────┤ for the first │ for the       │
106       │"}"       │ SD_BUS_TYPE_DICT_ENTRY_END   │ dictionary     │ type in the   │ second type   │
107       │          │                              │ entry end      │ pair          │ in the pair   │
108       └──────────┴──────────────────────────────┴────────────────┴───────────────┴───────────────┘
109
110       If objects of the specified types are not present at the current
111       position in the message, an error is returned.
112
113       The sd_bus_message_readv() is equivalent to the sd_bus_message_read(),
114       except that it is called with a "va_list" instead of a variable number
115       of arguments. This function does not call the va_end() macro. Because
116       it invokes the va_arg() macro, the value of ap is undefined after the
117       call.
118

RETURN VALUE

120       On success, sd_bus_message_read() and sd_bus_message_readv() return 0
121       or a positive integer. On failure, they return a negative errno-style
122       error code.
123

ERRORS

125       Returned errors may indicate the following problems:
126
127       -EINVAL
128           Specified type string is invalid or the message parameter is NULL.
129
130       -ENXIO
131           The message does not contain the specified type at current
132           position.
133
134       -EBADMSG
135           The message cannot be parsed.
136

NOTES

138       These APIs are implemented as a shared library, which can be compiled
139       and linked to with the libsystemd pkg-config(1) file.
140

EXAMPLES

142       Read a single basic type (a 64-bit integer):
143
144           sd_bus_message *m;
145           int64_t x;
146
147           sd_bus_message_read(m, "x", &x);
148
149       Read all types of integers:
150
151           uint8_t y;
152           int16_t n;
153           uint16_t q;
154           int32_t i;
155           uint32_t u;
156           int32_t x;
157           uint32_t t;
158           double d;
159
160           sd_bus_message_read(m, "ynqiuxtd", &y, &n, &q, &i, &u, &x, &t, &d);
161
162       Read a structure composed of a string and a D-Bus path:
163
164           const char *s, *p;
165
166           sd_bus_message_read(m, "(so)", &s, &p);
167
168       Read a variant, with the real type "gt" (signature, unsigned integer):
169
170           const char *s;
171           uint64_t *v;
172
173           sd_bus_message_read(m, "v", "gt", &s, &v);
174
175       Read a dictionary containing three pairs of type {integer=>string}:
176
177           int i, j, k;
178           const char *s, *t, *u;
179
180           sd_bus_message_read(m, "a{is}", 3, &i, &s, &j, &t, &k, &u);
181
182

SEE ALSO

184       systemd(1), sd-bus(3), sd_bus_message_read_basic(3),
185       sd_bus_message_skip(3), sd_bus_message_append(3)
186
187
188
189systemd 241                                             SD_BUS_MESSAGE_READ(3)
Impressum