]>
Commit | Line | Data |
---|---|---|
7cd40caa DDM |
1 | <?xml version='1.0'?> |
2 | <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" | |
3 | "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> | |
4 | <!-- SPDX-License-Identifier: LGPL-2.1+ --> | |
5 | ||
6 | <refentry id="sd_bus_message_open_container" | |
7 | xmlns:xi="http://www.w3.org/2001/XInclude"> | |
8 | ||
9 | <refentryinfo> | |
10 | <title>sd_bus_message_open_container</title> | |
11 | <productname>systemd</productname> | |
12 | </refentryinfo> | |
13 | ||
14 | <refmeta> | |
15 | <refentrytitle>sd_bus_message_open_container</refentrytitle> | |
16 | <manvolnum>3</manvolnum> | |
17 | </refmeta> | |
18 | ||
19 | <refnamediv> | |
20 | <refname>sd_bus_message_open_container</refname> | |
21 | <refname>sd_bus_message_close_container</refname> | |
22 | <refname>sd_bus_message_enter_container</refname> | |
23 | <refname>sd_bus_message_exit_container</refname> | |
24 | ||
25 | <refpurpose>Create and move between containers in D-Bus messages</refpurpose> | |
26 | </refnamediv> | |
27 | ||
28 | <refsynopsisdiv> | |
29 | <funcsynopsis> | |
30 | <funcsynopsisinfo>#include <systemd/sd-bus.h></funcsynopsisinfo> | |
31 | ||
32 | <funcprototype> | |
33 | <funcdef>int sd_bus_message_open_container</funcdef> | |
34 | <paramdef>sd_bus_message *<parameter>m</parameter></paramdef> | |
35 | <paramdef>char <parameter>type</parameter></paramdef> | |
36 | <paramdef>const char *<parameter>contents</parameter></paramdef> | |
37 | </funcprototype> | |
38 | ||
39 | <funcprototype> | |
40 | <funcdef>int sd_bus_message_close_container</funcdef> | |
41 | <paramdef>sd_bus_message *<parameter>m</parameter></paramdef> | |
42 | </funcprototype> | |
43 | ||
44 | <funcprototype> | |
45 | <funcdef>int sd_bus_message_enter_container</funcdef> | |
46 | <paramdef>sd_bus_message *<parameter>m</parameter></paramdef> | |
47 | <paramdef>char <parameter>type</parameter></paramdef> | |
48 | <paramdef>const char *<parameter>contents</parameter></paramdef> | |
49 | </funcprototype> | |
50 | ||
51 | <funcprototype> | |
52 | <funcdef>int sd_bus_message_exit_container</funcdef> | |
53 | <paramdef>sd_bus_message *<parameter>m</parameter></paramdef> | |
54 | </funcprototype> | |
55 | </funcsynopsis> | |
56 | </refsynopsisdiv> | |
57 | ||
58 | <refsect1> | |
59 | <title>Description</title> | |
60 | ||
61 | <para><function>sd_bus_message_open_container()</function> appends a new container to the message | |
62 | <parameter>m</parameter>. After opening a new container, it can be filled with content using | |
63 | <citerefentry><refentrytitle>sd_bus_message_append</refentrytitle><manvolnum>3</manvolnum></citerefentry> | |
64 | and similar functions. Containers behave like a stack. To nest containers inside each other, call | |
65 | <function>sd_bus_message_open_container()</function> multiple times without calling | |
2d4f8cf4 | 66 | <function>sd_bus_message_close_container()</function> in between. Each container will be nested inside the |
7cd40caa DDM |
67 | previous container. <parameter>type</parameter> represents the container type and should be one of |
68 | <literal>r</literal>, <literal>a</literal>, <literal>v</literal> or <literal>e</literal> as described in | |
69 | <citerefentry><refentrytitle>sd_bus_message_append</refentrytitle><manvolnum>3</manvolnum></citerefentry>. | |
70 | Instead of literals, the corresponding constants <constant>SD_BUS_TYPE_STRUCT</constant>, | |
71 | <constant>SD_BUS_TYPE_ARRAY</constant>, <constant>SD_BUS_TYPE_VARIANT</constant> or | |
72 | <constant>SD_BUS_TYPE_DICT_ENTRY</constant> can also be used. <parameter>contents</parameter> describes | |
73 | the type of the container's elements and should be a D-Bus type string following the rules described in | |
74 | <citerefentry><refentrytitle>sd_bus_message_append</refentrytitle><manvolnum>3</manvolnum></citerefentry>. | |
75 | </para> | |
76 | ||
77 | <para><function>sd_bus_message_close_container()</function> closes the last container opened with | |
78 | <function>sd_bus_message_open_container()</function>. On success, the write pointer of the message | |
79 | <parameter>m</parameter> is positioned after the closed container in its parent container or in | |
80 | <parameter>m</parameter> itself if there is no parent container.</para> | |
81 | ||
82 | <para><function>sd_bus_message_enter_container()</function> enters the next container of the message | |
8d29a1b9 | 83 | <parameter>m</parameter> for reading. It behaves mostly the same as |
7cd40caa DDM |
84 | <function>sd_bus_message_open_container()</function>. Entering a container allows reading its contents |
85 | with | |
86 | <citerefentry><refentrytitle>sd_bus_message_read</refentrytitle><manvolnum>3</manvolnum></citerefentry> | |
87 | and similar functions. <parameter>type</parameter> and <parameter>contents</parameter> are the same as in | |
88 | <function>sd_bus_message_open_container()</function>.</para> | |
89 | ||
90 | <para><function>sd_bus_message_exit_container()</function> exits the scope of the last container entered | |
91 | with <function>sd_bus_message_enter_container()</function>. It behaves mostly the same as | |
8d29a1b9 LP |
92 | <function>sd_bus_message_close_container()</function>. Note that |
93 | <function>sd_bus_message_exit_container()</function> may only be called after iterating through all | |
94 | members of the container, i.e. reading or skipping them. Use | |
95 | <citerefentry><refentrytitle>sd_bus_message_skip</refentrytitle><manvolnum>3</manvolnum></citerefentry> | |
96 | to skip over felds of a container in order to be able to exit the container with | |
97 | <function>sd_bus_message_exit_container()</function> without reading all members.</para> | |
7cd40caa DDM |
98 | </refsect1> |
99 | ||
100 | <refsect1> | |
101 | <title>Return Value</title> | |
102 | ||
103 | <para>On success, these functions return a non-negative integer. On failure, they return a negative | |
104 | errno-style error code.</para> | |
105 | ||
106 | <refsect2> | |
107 | <title>Errors</title> | |
108 | ||
109 | <para>Returned errors may indicate the following problems:</para> | |
110 | ||
111 | <variablelist> | |
112 | <varlistentry> | |
113 | <term><constant>-EINVAL</constant></term> | |
114 | ||
115 | <listitem><para><parameter>m</parameter> or <parameter>contents</parameter> are | |
116 | <constant>NULL</constant> or <parameter>type</parameter> is invalid.</para></listitem> | |
117 | </varlistentry> | |
118 | ||
119 | <varlistentry> | |
120 | <term><constant>-EPERM</constant></term> | |
121 | ||
122 | <listitem><para>The message <parameter>m</parameter> is already sealed.</para></listitem> | |
123 | </varlistentry> | |
124 | ||
125 | <varlistentry> | |
126 | <term><constant>-ESTALE</constant></term> | |
127 | ||
128 | <listitem><para>The message <parameter>m</parameter> is in an invalid state.</para></listitem> | |
129 | </varlistentry> | |
130 | ||
131 | <varlistentry> | |
132 | <term><constant>-ENOMEM</constant></term> | |
133 | ||
134 | <listitem><para>Memory allocation failed.</para></listitem> | |
135 | </varlistentry> | |
8d29a1b9 LP |
136 | |
137 | <varlistentry> | |
138 | <term><constant>-EBUSY</constant></term> | |
139 | ||
140 | <listitem><para><function>sd_bus_message_exit_container()</function> was called but there are | |
141 | unread members left in the container.</para></listitem> | |
142 | </varlistentry> | |
7cd40caa DDM |
143 | </variablelist> |
144 | </refsect2> | |
145 | </refsect1> | |
146 | ||
147 | <xi:include href="libsystemd-pkgconfig.xml" /> | |
148 | ||
149 | <refsect1> | |
150 | <title>Examples</title> | |
151 | ||
152 | <example> | |
153 | <title>Append an array of strings to a message</title> | |
154 | ||
155 | <programlisting><xi:include href="sd-bus-container-append.c" parse="text" /></programlisting> | |
156 | </example> | |
157 | ||
158 | <example> | |
159 | <title>Read an array of strings from a message</title> | |
160 | ||
161 | <programlisting><xi:include href="sd-bus-container-read.c" parse="text" /></programlisting> | |
162 | </example> | |
163 | </refsect1> | |
164 | ||
165 | <refsect1> | |
166 | <title>See Also</title> | |
167 | ||
168 | <para> | |
169 | <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, | |
170 | <citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
171 | <citerefentry><refentrytitle>sd_bus_message_append</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
172 | <citerefentry><refentrytitle>sd_bus_message_read</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
8d29a1b9 | 173 | <citerefentry><refentrytitle>sd_bus_message_skip</refentrytitle><manvolnum>3</manvolnum></citerefentry>, |
7cd40caa DDM |
174 | <ulink url="https://dbus.freedesktop.org/doc/dbus-specification.html">The D-Bus specification</ulink> |
175 | </para> | |
176 | </refsect1> | |
177 | ||
178 | </refentry> |