mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-22 13:33:56 +03:00
sd-bus: Add sd_bus_message_open/close/enter/exit_container docs
This commit is contained in:
parent
31e4abd1a6
commit
7cd40caa66
@ -319,6 +319,12 @@ manpages = [
|
||||
'sd_bus_message_new_method_errorf'],
|
||||
''],
|
||||
['sd_bus_message_new_signal', '3', [], ''],
|
||||
['sd_bus_message_open_container',
|
||||
'3',
|
||||
['sd_bus_message_close_container',
|
||||
'sd_bus_message_enter_container',
|
||||
'sd_bus_message_exit_container'],
|
||||
''],
|
||||
['sd_bus_message_read', '3', ['sd_bus_message_readv'], ''],
|
||||
['sd_bus_message_read_array', '3', [], ''],
|
||||
['sd_bus_message_read_basic', '3', [], ''],
|
||||
|
17
man/sd-bus-container-append.c
Normal file
17
man/sd-bus-container-append.c
Normal file
@ -0,0 +1,17 @@
|
||||
#include <systemd/sd-bus.h>
|
||||
|
||||
int append_strings_to_message(sd_bus_message *m, const char *const *arr) {
|
||||
int r;
|
||||
|
||||
r = sd_bus_message_open_container(m, 'a', "s");
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
for (const char *s = *arr; *s; s++) {
|
||||
r = sd_bus_message_append(m, "s", s);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
return sd_bus_message_close_container(m);
|
||||
}
|
25
man/sd-bus-container-read.c
Normal file
25
man/sd-bus-container-read.c
Normal file
@ -0,0 +1,25 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include <systemd/sd-bus.h>
|
||||
|
||||
int read_strings_from_message(sd_bus_message *m) {
|
||||
int r;
|
||||
|
||||
r = sd_bus_message_enter_container(m, 'a', "s");
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
for (;;) {
|
||||
const char *s;
|
||||
|
||||
r = sd_bus_message_read(m, "s", &s);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r == 0)
|
||||
break;
|
||||
|
||||
printf("%s\n", s);
|
||||
}
|
||||
|
||||
return sd_bus_message_exit_container(m);
|
||||
}
|
@ -95,8 +95,11 @@
|
||||
<citerefentry><refentrytitle>sd_bus_message_append_string_memfd</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
||||
<citerefentry><refentrytitle>sd_bus_message_append_strv</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
||||
<citerefentry><refentrytitle>sd_bus_message_at_end</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
||||
<citerefentry><refentrytitle>sd_bus_message_close_container</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
||||
<citerefentry><refentrytitle>sd_bus_message_copy</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
||||
<citerefentry><refentrytitle>sd_bus_message_dump</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
||||
<citerefentry><refentrytitle>sd_bus_message_enter_container</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
||||
<citerefentry><refentrytitle>sd_bus_message_exit_container</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
||||
<citerefentry><refentrytitle>sd_bus_message_get_allow_interactive_authorization</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
||||
<citerefentry><refentrytitle>sd_bus_message_get_cookie</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
||||
<citerefentry><refentrytitle>sd_bus_message_get_errno</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
||||
@ -113,6 +116,7 @@
|
||||
<citerefentry><refentrytitle>sd_bus_message_new_method_call</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
||||
<citerefentry><refentrytitle>sd_bus_message_new_method_error</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
||||
<citerefentry><refentrytitle>sd_bus_message_new_signal</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
||||
<citerefentry><refentrytitle>sd_bus_message_open_container</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
||||
<citerefentry><refentrytitle>sd_bus_message_read</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
||||
<citerefentry><refentrytitle>sd_bus_message_read_array</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
||||
<citerefentry><refentrytitle>sd_bus_message_read_basic</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
||||
|
@ -229,7 +229,8 @@ sd_bus_message_append(m, "ynqiuxtd", y, n, q, i, u, x, t, d);</programlisting>
|
||||
<citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
|
||||
<citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
||||
<citerefentry><refentrytitle>sd_bus_message_append_basic</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
||||
<citerefentry><refentrytitle>sd_bus_message_append_array</refentrytitle><manvolnum>3</manvolnum></citerefentry>
|
||||
<citerefentry><refentrytitle>sd_bus_message_append_array</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
||||
<citerefentry><refentrytitle>sd_bus_message_open_container</refentrytitle><manvolnum>3</manvolnum></citerefentry>
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
|
165
man/sd_bus_message_open_container.xml
Normal file
165
man/sd_bus_message_open_container.xml
Normal file
@ -0,0 +1,165 @@
|
||||
<?xml version='1.0'?>
|
||||
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
|
||||
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
|
||||
<!-- SPDX-License-Identifier: LGPL-2.1+ -->
|
||||
|
||||
<refentry id="sd_bus_message_open_container"
|
||||
xmlns:xi="http://www.w3.org/2001/XInclude">
|
||||
|
||||
<refentryinfo>
|
||||
<title>sd_bus_message_open_container</title>
|
||||
<productname>systemd</productname>
|
||||
</refentryinfo>
|
||||
|
||||
<refmeta>
|
||||
<refentrytitle>sd_bus_message_open_container</refentrytitle>
|
||||
<manvolnum>3</manvolnum>
|
||||
</refmeta>
|
||||
|
||||
<refnamediv>
|
||||
<refname>sd_bus_message_open_container</refname>
|
||||
<refname>sd_bus_message_close_container</refname>
|
||||
<refname>sd_bus_message_enter_container</refname>
|
||||
<refname>sd_bus_message_exit_container</refname>
|
||||
|
||||
<refpurpose>Create and move between containers in D-Bus messages</refpurpose>
|
||||
</refnamediv>
|
||||
|
||||
<refsynopsisdiv>
|
||||
<funcsynopsis>
|
||||
<funcsynopsisinfo>#include <systemd/sd-bus.h></funcsynopsisinfo>
|
||||
|
||||
<funcprototype>
|
||||
<funcdef>int sd_bus_message_open_container</funcdef>
|
||||
<paramdef>sd_bus_message *<parameter>m</parameter></paramdef>
|
||||
<paramdef>char <parameter>type</parameter></paramdef>
|
||||
<paramdef>const char *<parameter>contents</parameter></paramdef>
|
||||
</funcprototype>
|
||||
|
||||
<funcprototype>
|
||||
<funcdef>int sd_bus_message_close_container</funcdef>
|
||||
<paramdef>sd_bus_message *<parameter>m</parameter></paramdef>
|
||||
</funcprototype>
|
||||
|
||||
<funcprototype>
|
||||
<funcdef>int sd_bus_message_enter_container</funcdef>
|
||||
<paramdef>sd_bus_message *<parameter>m</parameter></paramdef>
|
||||
<paramdef>char <parameter>type</parameter></paramdef>
|
||||
<paramdef>const char *<parameter>contents</parameter></paramdef>
|
||||
</funcprototype>
|
||||
|
||||
<funcprototype>
|
||||
<funcdef>int sd_bus_message_exit_container</funcdef>
|
||||
<paramdef>sd_bus_message *<parameter>m</parameter></paramdef>
|
||||
</funcprototype>
|
||||
</funcsynopsis>
|
||||
</refsynopsisdiv>
|
||||
|
||||
<refsect1>
|
||||
<title>Description</title>
|
||||
|
||||
<para><function>sd_bus_message_open_container()</function> appends a new container to the message
|
||||
<parameter>m</parameter>. After opening a new container, it can be filled with content using
|
||||
<citerefentry><refentrytitle>sd_bus_message_append</refentrytitle><manvolnum>3</manvolnum></citerefentry>
|
||||
and similar functions. Containers behave like a stack. To nest containers inside each other, call
|
||||
<function>sd_bus_message_open_container()</function> multiple times without calling
|
||||
<function>sd_bus_message_close_container()</function> inbetween. Each container will be nested inside the
|
||||
previous container. <parameter>type</parameter> represents the container type and should be one of
|
||||
<literal>r</literal>, <literal>a</literal>, <literal>v</literal> or <literal>e</literal> as described in
|
||||
<citerefentry><refentrytitle>sd_bus_message_append</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
|
||||
Instead of literals, the corresponding constants <constant>SD_BUS_TYPE_STRUCT</constant>,
|
||||
<constant>SD_BUS_TYPE_ARRAY</constant>, <constant>SD_BUS_TYPE_VARIANT</constant> or
|
||||
<constant>SD_BUS_TYPE_DICT_ENTRY</constant> can also be used. <parameter>contents</parameter> describes
|
||||
the type of the container's elements and should be a D-Bus type string following the rules described in
|
||||
<citerefentry><refentrytitle>sd_bus_message_append</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
|
||||
</para>
|
||||
|
||||
<para><function>sd_bus_message_close_container()</function> closes the last container opened with
|
||||
<function>sd_bus_message_open_container()</function>. On success, the write pointer of the message
|
||||
<parameter>m</parameter> is positioned after the closed container in its parent container or in
|
||||
<parameter>m</parameter> itself if there is no parent container.</para>
|
||||
|
||||
<para><function>sd_bus_message_enter_container()</function> enters the next container of the message
|
||||
<parameter>m</parameter>. It behaves mostly the same as
|
||||
<function>sd_bus_message_open_container()</function>. Entering a container allows reading its contents
|
||||
with
|
||||
<citerefentry><refentrytitle>sd_bus_message_read</refentrytitle><manvolnum>3</manvolnum></citerefentry>
|
||||
and similar functions. <parameter>type</parameter> and <parameter>contents</parameter> are the same as in
|
||||
<function>sd_bus_message_open_container()</function>.</para>
|
||||
|
||||
<para><function>sd_bus_message_exit_container()</function> exits the scope of the last container entered
|
||||
with <function>sd_bus_message_enter_container()</function>. It behaves mostly the same as
|
||||
<function>sd_bus_message_close_container()</function>.</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1>
|
||||
<title>Return Value</title>
|
||||
|
||||
<para>On success, these functions return a non-negative integer. On failure, they return a negative
|
||||
errno-style error code.</para>
|
||||
|
||||
<refsect2>
|
||||
<title>Errors</title>
|
||||
|
||||
<para>Returned errors may indicate the following problems:</para>
|
||||
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term><constant>-EINVAL</constant></term>
|
||||
|
||||
<listitem><para><parameter>m</parameter> or <parameter>contents</parameter> are
|
||||
<constant>NULL</constant> or <parameter>type</parameter> is invalid.</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><constant>-EPERM</constant></term>
|
||||
|
||||
<listitem><para>The message <parameter>m</parameter> is already sealed.</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><constant>-ESTALE</constant></term>
|
||||
|
||||
<listitem><para>The message <parameter>m</parameter> is in an invalid state.</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><constant>-ENOMEM</constant></term>
|
||||
|
||||
<listitem><para>Memory allocation failed.</para></listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</refsect2>
|
||||
</refsect1>
|
||||
|
||||
<xi:include href="libsystemd-pkgconfig.xml" />
|
||||
|
||||
<refsect1>
|
||||
<title>Examples</title>
|
||||
|
||||
<example>
|
||||
<title>Append an array of strings to a message</title>
|
||||
|
||||
<programlisting><xi:include href="sd-bus-container-append.c" parse="text" /></programlisting>
|
||||
</example>
|
||||
|
||||
<example>
|
||||
<title>Read an array of strings from a message</title>
|
||||
|
||||
<programlisting><xi:include href="sd-bus-container-read.c" parse="text" /></programlisting>
|
||||
</example>
|
||||
</refsect1>
|
||||
|
||||
<refsect1>
|
||||
<title>See Also</title>
|
||||
|
||||
<para>
|
||||
<citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
|
||||
<citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
||||
<citerefentry><refentrytitle>sd_bus_message_append</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
||||
<citerefentry><refentrytitle>sd_bus_message_read</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
||||
<ulink url="https://dbus.freedesktop.org/doc/dbus-specification.html">The D-Bus specification</ulink>
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
</refentry>
|
@ -228,7 +228,8 @@ sd_bus_message_read(m, "a{is}", 3, &i, &s, &j, &t, &k, &
|
||||
<citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
||||
<citerefentry><refentrytitle>sd_bus_message_read_basic</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
||||
<citerefentry><refentrytitle>sd_bus_message_skip</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
||||
<citerefentry><refentrytitle>sd_bus_message_append</refentrytitle><manvolnum>3</manvolnum></citerefentry>
|
||||
<citerefentry><refentrytitle>sd_bus_message_append</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
||||
<citerefentry><refentrytitle>sd_bus_message_enter_container</refentrytitle><manvolnum>3</manvolnum></citerefentry>
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user