man-pages/man3/sd_bus_message_read.3.html
2021-03-31 01:06:50 +01:00

538 lines
9.9 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of SD_BUS_MESSAGE_READ</TITLE>
</HEAD><BODY>
<H1>SD_BUS_MESSAGE_READ</H1>
Section: sd_bus_message_read (3)<BR>Updated: <BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
sd_bus_message_read, sd_bus_message_readv - Read a sequence of values from a message
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<P>
<B>
</B><PRE>
#include &lt;<A HREF="file:///usr/include/systemd/sd-bus.h">systemd/sd-bus.h</A>&gt;
</PRE>
<DL COMPACT>
<DT id="1">
<B>int sd_bus_message_read(sd_bus_message&nbsp;*</B><I>m</I><B>, char&nbsp;char&nbsp;*</B><I>types</I><B>, ...);</B>
<DT id="2">
<B>int sd_bus_message_readv(sd_bus_message&nbsp;*</B><I>m</I><B>, char&nbsp;char&nbsp;*</B><I>types</I><B>, va_list&nbsp;</B><I>ap</I><B>);</B>
</DL>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
<P>
<B>sd_bus_message_read()</B>
<DD>reads a sequence of fields from the D-Bus message object
<I>m</I>
and advances the read position in the message. The type string
<I>types</I>
describes the types of items expected in the message and the field arguments that follow. The type string may be
<B>NULL</B>
or empty, in which case nothing is read.
<P>
The type string is composed of the elements described in
<B><A HREF="/cgi-bin/man/man2html?3+sd_bus_message_append">sd_bus_message_append</A></B>(3), i.e. basic and container types. It must contain zero or more single &quot;complete types&quot;. The type string is
<B>NUL</B>-terminated.
<P>
For each type specified in the type string, one or more arguments need to be specified after the
<I>types</I>
parameter, in the same order. The arguments must be pointers to appropriate types (a pointer to
<B>int8_t</B>
for a
&quot;y&quot;
in the type string, a pointer to
<B>int32_t</B>
for an
&quot;i&quot;, a pointer to
<B>const char*</B>
for an
&quot;s&quot;, ...) 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 &quot;input&quot; 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.,
<B>const char *</B>
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.
<P>
Each argument may also be
<B>NULL</B>, in which case the value is read and ignored.
<P>
<BR>
<B>Table&nbsp;1.&nbsp;Item type specifiers</B>
<TABLE BORDER>
<TR VALIGN=top><TD><B>
Specifier
</B></TD><TD><B>
Constant
</B></TD><TD><B>
Description
</B></TD><TD><B>
Type of the first argument
</B></TD><TD><B>
Types of the subsequent arguments, if any
</B><BR></TD></TR>
<TR VALIGN=top><TD>
&quot;y&quot;
</TD><TD>
<B>SD_BUS_TYPE_BYTE</B>
</TD><TD>
8bit unsigned integer
</TD><TD>
<B>uint8_t *</B>
</TD><TD>
&nbsp;
<BR></TD></TR>
<TR VALIGN=top><TD>
&quot;b&quot;
</TD><TD>
<B>SD_BUS_TYPE_BOOLEAN</B>
</TD><TD>
boolean
</TD><TD>
<B>int *</B> (NB: not <B>bool *</B>)
</TD><TD>
&nbsp;
<BR></TD></TR>
<TR VALIGN=top><TD>
&quot;n&quot;
</TD><TD>
<B>SD_BUS_TYPE_INT16</B>
</TD><TD>
16bit signed integer
</TD><TD>
<B>int16_t *</B>
</TD><TD>
&nbsp;
<BR></TD></TR>
<TR VALIGN=top><TD>
&quot;q&quot;
</TD><TD>
<B>SD_BUS_TYPE_UINT16</B>
</TD><TD>
16bit unsigned integer
</TD><TD>
<B>uint16_t *</B>
</TD><TD>
&nbsp;
<BR></TD></TR>
<TR VALIGN=top><TD>
&quot;i&quot;
</TD><TD>
<B>SD_BUS_TYPE_INT32</B>
</TD><TD>
32bit signed integer
</TD><TD>
<B>int32_t *</B>
</TD><TD>
&nbsp;
<BR></TD></TR>
<TR VALIGN=top><TD>
&quot;u&quot;
</TD><TD>
<B>SD_BUS_TYPE_UINT32</B>
</TD><TD>
32bit unsigned integer
</TD><TD>
<B>uint32_t *</B>
</TD><TD>
&nbsp;
<BR></TD></TR>
<TR VALIGN=top><TD>
&quot;x&quot;
</TD><TD>
<B>SD_BUS_TYPE_INT64</B>
</TD><TD>
64bit signed integer
</TD><TD>
<B>int64_t *</B>
</TD><TD>
&nbsp;
<BR></TD></TR>
<TR VALIGN=top><TD>
&quot;t&quot;
</TD><TD>
<B>SD_BUS_TYPE_UINT64</B>
</TD><TD>
64bit unsigned integer
</TD><TD>
<B>uint64_t *</B>
</TD><TD>
&nbsp;
<BR></TD></TR>
<TR VALIGN=top><TD>
&quot;d&quot;
</TD><TD>
<B>SD_BUS_TYPE_DOUBLE</B>
</TD><TD>
IEEE 754 double precision floating-point
</TD><TD>
<B>double *</B>
</TD><TD>
&nbsp;
<BR></TD></TR>
<TR VALIGN=top><TD>
&quot;s&quot;
</TD><TD>
<B>SD_BUS_TYPE_STRING</B>
</TD><TD>
UTF-8 string
</TD><TD>
<B>const char **</B>
</TD><TD>
&nbsp;
<BR></TD></TR>
<TR VALIGN=top><TD>
&quot;o&quot;
</TD><TD>
<B>SD_BUS_TYPE_OBJECT_PATH</B>
</TD><TD>
D-Bus object path string
</TD><TD>
<B>const char **</B>
</TD><TD>
&nbsp;
<BR></TD></TR>
<TR VALIGN=top><TD>
&quot;g&quot;
</TD><TD>
<B>SD_BUS_TYPE_SIGNATURE</B>
</TD><TD>
D-Bus signature string
</TD><TD>
<B>const char **</B>
</TD><TD>
&nbsp;
<BR></TD></TR>
<TR VALIGN=top><TD>
&quot;h&quot;
</TD><TD>
<B>SD_BUS_TYPE_UNIX_FD</B>
</TD><TD>
UNIX file descriptor
</TD><TD>
<B>int *</B>
</TD><TD>
&nbsp;
<BR></TD></TR>
<TR VALIGN=top><TD>
&quot;a&quot;
</TD><TD>
<B>SD_BUS_TYPE_ARRAY</B>
</TD><TD>
array
</TD><TD>
<B>int</B>, which specifies the expected length <I>n</I> of the array
</TD><TD>
<I>n</I> sets of arguments appropriate for the array element type
<BR></TD></TR>
<TR VALIGN=top><TD>
&quot;v&quot;
</TD><TD>
<B>SD_BUS_TYPE_VARIANT</B>
</TD><TD>
variant
</TD><TD>
signature string
</TD><TD>
arguments appropriate for the types specified by the signature
<BR></TD></TR>
<TR VALIGN=top><TD>
&quot;(&quot;
</TD><TD>
<B>SD_BUS_TYPE_STRUCT_BEGIN</B>
</TD><TD>
array start
</TD><TD VALIGN=center COLSPAN=2 ROWSPAN=2>
arguments appropriate for the structure elements
<BR></TD></TR>
<TR VALIGN=top><TD>
&quot;)&quot;
</TD><TD>
<B>SD_BUS_TYPE_STRUCT_END</B>
</TD><TD>
array end
</TD></TR>
<TR VALIGN=top><TD>
&quot;{&quot;
</TD><TD>
<B>SD_BUS_TYPE_DICT_ENTRY_BEGIN</B>
</TD><TD>
dictionary entry start
</TD><TD VALIGN=center ROWSPAN=2>
arguments appropriate for the first type in the pair
</TD><TD VALIGN=center ROWSPAN=2>
arguments appropriate for the second type in the pair
<BR></TD></TR>
<TR VALIGN=top><TD>
&quot;}&quot;
</TD><TD>
<B>SD_BUS_TYPE_DICT_ENTRY_END</B>
</TD><TD>
dictionary entry end
</TD></TR>
</TABLE>
<P>
<P>
If objects of the specified types are not present at the current position in the message, an error is returned.
<P>
The
<B>sd_bus_message_readv()</B>
is equivalent to the
<B>sd_bus_message_read()</B>, except that it is called with a
&quot;va_list&quot;
instead of a variable number of arguments. This function does not call the
<B>va_end()</B>
macro. Because it invokes the
<B>va_arg()</B>
macro, the value of
<I>ap</I>
is undefined after the call.
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
<P>
On success,
<B>sd_bus_message_read()</B>
and
<B>sd_bus_message_readv()</B>
return 0 or a positive integer. On failure, they return a negative errno-style error code.
<A NAME="lbAF">&nbsp;</A>
<H3>Errors</H3>
<P>
Returned errors may indicate the following problems:
<P>
<B>-EINVAL</B>
<DL COMPACT><DT id="3"><DD>
Specified type string is invalid or the message parameter is
<B>NULL</B>.
</DL>
<P>
<B>-ENXIO</B>
<DL COMPACT><DT id="4"><DD>
The message does not contain the specified type at current position.
</DL>
<P>
<B>-EBADMSG</B>
<DL COMPACT><DT id="5"><DD>
The message cannot be parsed.
</DL>
<A NAME="lbAG">&nbsp;</A>
<H2>NOTES</H2>
<P>
These APIs are implemented as a shared library, which can be compiled and linked to with the
<B>libsystemd</B>&nbsp;<B><A HREF="/cgi-bin/man/man2html?1+pkg-config">pkg-config</A></B>(1)
file.
<A NAME="lbAH">&nbsp;</A>
<H2>EXAMPLES</H2>
<P>
Read a single basic type (a 64-bit integer):
<P>
<DL COMPACT><DT id="6"><DD>
<PRE>
sd_bus_message *m;
int64_t x;
sd_bus_message_read(m, &quot;x&quot;, &amp;x);
</PRE>
</DL>
<P>
Read a boolean value:
<P>
<DL COMPACT><DT id="7"><DD>
<PRE>
sd_bus_message *m;
int x; /* Do not use C99 'bool' type here, it's typically smaller
in memory and would cause memory corruption */
sd_bus_message_read(m, &quot;b&quot;, &amp;x);
</PRE>
</DL>
<P>
Read all types of integers:
<P>
<DL COMPACT><DT id="8"><DD>
<PRE>
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, &quot;ynqiuxtd&quot;, &amp;y, &amp;n, &amp;q, &amp;i, &amp;u, &amp;x, &amp;t, &amp;d);
</PRE>
</DL>
<P>
Read a structure composed of a string and a D-Bus path:
<P>
<DL COMPACT><DT id="9"><DD>
<PRE>
const char *s, *p;
sd_bus_message_read(m, &quot;(so)&quot;, &amp;s, &amp;p);
</PRE>
</DL>
<P>
Read a variant, with the real type &quot;gt&quot; (signature, unsigned integer):
<P>
<DL COMPACT><DT id="10"><DD>
<PRE>
const char *s;
uint64_t *v;
sd_bus_message_read(m, &quot;v&quot;, &quot;gt&quot;, &amp;s, &amp;v);
</PRE>
</DL>
<P>
Read a dictionary containing three pairs of type {integer=&gt;string}:
<P>
<DL COMPACT><DT id="11"><DD>
<PRE>
int i, j, k;
const char *s, *t, *u;
sd_bus_message_read(m, &quot;a{is}&quot;, 3, &amp;i, &amp;s, &amp;j, &amp;t, &amp;k, &amp;u);
</PRE>
</DL>
<A NAME="lbAI">&nbsp;</A>
<H2>SEE ALSO</H2>
<P>
<B><A HREF="/cgi-bin/man/man2html?1+systemd">systemd</A></B>(1),
<B><A HREF="/cgi-bin/man/man2html?3+sd-bus">sd-bus</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+sd_bus_message_read_basic">sd_bus_message_read_basic</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+sd_bus_message_skip">sd_bus_message_skip</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+sd_bus_message_append">sd_bus_message_append</A></B>(3)
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="12"><A HREF="#lbAB">NAME</A><DD>
<DT id="13"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="14"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="15"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DL>
<DT id="16"><A HREF="#lbAF">Errors</A><DD>
</DL>
<DT id="17"><A HREF="#lbAG">NOTES</A><DD>
<DT id="18"><A HREF="#lbAH">EXAMPLES</A><DD>
<DT id="19"><A HREF="#lbAI">SEE ALSO</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:54 GMT, March 31, 2021
</BODY>
</HTML>