1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443
|
'\" t
.TH "SD_BUS_MESSAGE_READ" "3" "" "systemd 241" "sd_bus_message_read"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
sd_bus_message_read, sd_bus_message_readv \- Read a sequence of values from a message
.SH "SYNOPSIS"
.sp
.ft B
.nf
#include <systemd/sd\-bus\&.h>
.fi
.ft
.HP \w'int\ sd_bus_message_read('u
.BI "int sd_bus_message_read(sd_bus_message\ *" "m" ", char\ char\ *" "types" ", \&.\&.\&.);"
.HP \w'int\ sd_bus_message_readv('u
.BI "int sd_bus_message_readv(sd_bus_message\ *" "m" ", char\ char\ *" "types" ", va_list\ " "ap" ");"
.SH "DESCRIPTION"
.PP
\fBsd_bus_message_read()\fR
reads a sequence of fields from the D\-Bus message object
\fIm\fR
and advances the read position in the message\&. The type string
\fItypes\fR
describes the types of items expected in the message and the field arguments that follow\&. The type string may be
\fBNULL\fR
or empty, in which case nothing is read\&.
.PP
The type string is composed of the elements described in
\fBsd_bus_message_append\fR(3), i\&.e\&. basic and container types\&. It must contain zero or more single "complete types"\&. The type string is
\fBNUL\fR\-terminated\&.
.PP
For each type specified in the type string, one or more arguments need to be specified after the
\fItypes\fR
parameter, in the same order\&. The arguments must be pointers to appropriate types (a pointer to
int8_t
for a
"y"
in the type string, a pointer to
int32_t
for an
"i", a pointer to
const char*
for an
"s", \&.\&.\&.) which are set based on the values in the message\&. As an exception, in case or array and variant types, the first argument is an "input" argument that further specifies how the message should be read\&. See the table below for a complete list of allowed arguments and their types\&. Note that, if the basic type is a pointer (e\&.g\&.,
const char *
in the case of a string), the argument is a pointer to a pointer, and also the pointer value that is written is only borrowed and the contents must be copied if they are to be used after the end of the messages lifetime\&.
.PP
Each argument may also be
\fBNULL\fR, in which case the value is read and ignored\&.
.sp
.it 1 an-trap
.nr an-no-space-flag 1
.nr an-break-flag 1
.br
.B Table\ \&1.\ \&Item type specifiers
.TS
allbox tab(:);
lB lB lB lB lB.
T{
Specifier
T}:T{
Constant
T}:T{
Description
T}:T{
Type of the first argument
T}:T{
Types of the subsequent arguments, if any
T}
.T&
l l l l l
l l l l l
l l l l l
l l l l l
l l l l l
l l l l l
l l l l l
l l l l l
l l l l l
l l l l l
l l l l l
l l l l l
l l l l l
l l l l l
l l l l l
l l l l s
l l l ^ ^
l l l l l
l l l ^ ^.
T{
"y"
T}:T{
\fBSD_BUS_TYPE_BYTE\fR
T}:T{
unsigned integer
T}:T{
uint8_t *
T}:T{
\ \&
T}
T{
"b"
T}:T{
\fBSD_BUS_TYPE_BOOLEAN\fR
T}:T{
boolean
T}:T{
int *
T}:T{
\ \&
T}
T{
"n"
T}:T{
\fBSD_BUS_TYPE_INT16\fR
T}:T{
signed integer
T}:T{
int16_t *
T}:T{
\ \&
T}
T{
"q"
T}:T{
\fBSD_BUS_TYPE_UINT16\fR
T}:T{
unsigned integer
T}:T{
uint16_t *
T}:T{
\ \&
T}
T{
"i"
T}:T{
\fBSD_BUS_TYPE_INT32\fR
T}:T{
signed integer
T}:T{
int32_t *
T}:T{
\ \&
T}
T{
"u"
T}:T{
\fBSD_BUS_TYPE_UINT32\fR
T}:T{
unsigned integer
T}:T{
uint32_t *
T}:T{
\ \&
T}
T{
"x"
T}:T{
\fBSD_BUS_TYPE_INT64\fR
T}:T{
signed integer
T}:T{
int64_t *
T}:T{
\ \&
T}
T{
"t"
T}:T{
\fBSD_BUS_TYPE_UINT64\fR
T}:T{
unsigned integer
T}:T{
uint64_t *
T}:T{
\ \&
T}
T{
"d"
T}:T{
\fBSD_BUS_TYPE_DOUBLE\fR
T}:T{
floating\-point
T}:T{
double *
T}:T{
\ \&
T}
T{
"s"
T}:T{
\fBSD_BUS_TYPE_STRING\fR
T}:T{
Unicode string
T}:T{
const char **
T}:T{
\ \&
T}
T{
"o"
T}:T{
\fBSD_BUS_TYPE_OBJECT_PATH\fR
T}:T{
object path
T}:T{
const char **
T}:T{
\ \&
T}
T{
"g"
T}:T{
\fBSD_BUS_TYPE_SIGNATURE\fR
T}:T{
signature
T}:T{
const char **
T}:T{
\ \&
T}
T{
"h"
T}:T{
\fBSD_BUS_TYPE_UNIX_FD\fR
T}:T{
UNIX file descriptor
T}:T{
int *
T}:T{
\ \&
T}
T{
"a"
T}:T{
\fBSD_BUS_TYPE_ARRAY\fR
T}:T{
array
T}:T{
int, which specifies the expected length \fIn\fR of the array
T}:T{
\fIn\fR sets of arguments appropriate for the array element type
T}
T{
"v"
T}:T{
\fBSD_BUS_TYPE_VARIANT\fR
T}:T{
variant
T}:T{
signature string
T}:T{
arguments appropriate for the types specified by the signature
T}
T{
"("
T}:T{
\fBSD_BUS_TYPE_STRUCT_BEGIN\fR
T}:T{
array start
T}:T{
arguments appropriate for the structure elements
T}
T{
")"
T}:T{
\fBSD_BUS_TYPE_STRUCT_END\fR
T}:T{
array end
T}::
T{
"{"
T}:T{
\fBSD_BUS_TYPE_DICT_ENTRY_BEGIN\fR
T}:T{
dictionary entry start
T}:T{
arguments appropriate for the first type in the pair
T}:T{
arguments appropriate for the second type in the pair
T}
T{
"}"
T}:T{
\fBSD_BUS_TYPE_DICT_ENTRY_END\fR
T}:T{
dictionary entry end
T}::
.TE
.sp 1
.PP
If objects of the specified types are not present at the current position in the message, an error is returned\&.
.PP
The
\fBsd_bus_message_readv()\fR
is equivalent to the
\fBsd_bus_message_read()\fR, except that it is called with a
"va_list"
instead of a variable number of arguments\&. This function does not call the
\fBva_end()\fR
macro\&. Because it invokes the
\fBva_arg()\fR
macro, the value of
\fIap\fR
is undefined after the call\&.
.SH "RETURN VALUE"
.PP
On success,
\fBsd_bus_message_read()\fR
and
\fBsd_bus_message_readv()\fR
return 0 or a positive integer\&. On failure, they return a negative errno\-style error code\&.
.SH "ERRORS"
.PP
Returned errors may indicate the following problems:
.PP
\fB\-EINVAL\fR
.RS 4
Specified type string is invalid or the message parameter is
\fBNULL\fR\&.
.RE
.PP
\fB\-ENXIO\fR
.RS 4
The message does not contain the specified type at current position\&.
.RE
.PP
\fB\-EBADMSG\fR
.RS 4
The message cannot be parsed\&.
.RE
.SH "NOTES"
.PP
These APIs are implemented as a shared library, which can be compiled and linked to with the
\fBlibsystemd\fR\ \&\fBpkg-config\fR(1)
file\&.
.SH "EXAMPLES"
.PP
Read a single basic type (a 64\-bit integer):
.sp
.if n \{\
.RS 4
.\}
.nf
sd_bus_message *m;
int64_t x;
sd_bus_message_read(m, "x", &x);
.fi
.if n \{\
.RE
.\}
.PP
Read all types of integers:
.sp
.if n \{\
.RS 4
.\}
.nf
uint8_t y;
int16_t n;
uint16_t q;
int32_t i;
uint32_t u;
int32_t x;
uint32_t t;
double d;
sd_bus_message_read(m, "ynqiuxtd", &y, &n, &q, &i, &u, &x, &t, &d);
.fi
.if n \{\
.RE
.\}
.PP
Read a structure composed of a string and a D\-Bus path:
.sp
.if n \{\
.RS 4
.\}
.nf
const char *s, *p;
sd_bus_message_read(m, "(so)", &s, &p);
.fi
.if n \{\
.RE
.\}
.PP
Read a variant, with the real type "gt" (signature, unsigned integer):
.sp
.if n \{\
.RS 4
.\}
.nf
const char *s;
uint64_t *v;
sd_bus_message_read(m, "v", "gt", &s, &v);
.fi
.if n \{\
.RE
.\}
.PP
Read a dictionary containing three pairs of type {integer=>string}:
.sp
.if n \{\
.RS 4
.\}
.nf
int i, j, k;
const char *s, *t, *u;
sd_bus_message_read(m, "a{is}", 3, &i, &s, &j, &t, &k, &u);
.fi
.if n \{\
.RE
.\}
.SH "SEE ALSO"
.PP
\fBsystemd\fR(1),
\fBsd-bus\fR(3),
\fBsd_bus_message_read_basic\fR(3),
\fBsd_bus_message_skip\fR(3),
\fBsd_bus_message_append\fR(3)
|