1 <?xml version='
1.0'
?> <!--*- Mode: nxml; nxml-child-indent: 2; indent-tabs-mode: nil -*-->
2 <!DOCTYPE refentry PUBLIC
"-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
6 SPDX-License-Identifier: LGPL-2.1+
8 This file is part of systemd.
10 Copyright 2014 Zbigniew Jędrzejewski-Szmek
13 <refentry id=
"sd_bus_message_append_basic">
16 <title>sd_bus_message_append_basic
</title>
17 <productname>systemd
</productname>
21 <contrib>A monkey with a typewriter
</contrib>
22 <firstname>Zbigniew
</firstname>
23 <surname>Jędrzejewski-Szmek
</surname>
24 <email>zbyszek@in.waw.pl
</email>
30 <refentrytitle>sd_bus_message_append_basic
</refentrytitle>
31 <manvolnum>3</manvolnum>
35 <refname>sd_bus_message_append_basic
</refname>
37 <refpurpose>Attach a single field to a message
</refpurpose>
42 <funcsynopsisinfo>#include
<systemd/sd-bus.h
></funcsynopsisinfo>
45 <funcdef>int sd_bus_message_append_basic
</funcdef>
46 <paramdef>sd_bus_message *
<parameter>m
</parameter></paramdef>
47 <paramdef>char
<parameter>type
</parameter></paramdef>
48 <paramdef>const void *
<parameter>p
</parameter></paramdef>
54 <title>Description
</title>
56 <para><function>sd_bus_message_append_basic()
</function> appends a
57 single field to the message
<parameter>m
</parameter>. The
58 parameter
<parameter>type
</parameter> determines how the pointer
59 <parameter>p
</parameter> is interpreted.
60 <parameter>type
</parameter> must be one of the basic types as
62 url=
"http://dbus.freedesktop.org/doc/dbus-specification.html#basic-types">Basic
63 Types
</ulink> section of the D-Bus specification, and listed in
67 <table id='format-specifiers'
>
68 <title>Item type specifiers
</title>
71 <colspec colname='specifier'
/>
72 <colspec colname='constant'
/>
73 <colspec colname='description'
/>
74 <colspec colname='size'
/>
75 <colspec colname='ctype'
/>
78 <entry>Specifier
</entry>
79 <entry>Constant
</entry>
80 <entry>Description
</entry>
82 <entry>Expected C Type
</entry>
87 <entry><literal>y
</literal></entry>
88 <entry><constant>SD_BUS_TYPE_BYTE
</constant></entry>
89 <entry>unsigned integer
</entry>
91 <entry>uint8_t
</entry>
95 <entry><literal>b
</literal></entry>
96 <entry><constant>SD_BUS_TYPE_BOOLEAN
</constant></entry>
97 <entry>boolean
</entry>
98 <entry>4 bytes
</entry>
103 <entry><literal>n
</literal></entry>
104 <entry><constant>SD_BUS_TYPE_INT16
</constant></entry>
105 <entry>signed integer
</entry>
106 <entry>2 bytes
</entry>
107 <entry>int16_t
</entry>
111 <entry><literal>q
</literal></entry>
112 <entry><constant>SD_BUS_TYPE_UINT16
</constant></entry>
113 <entry>unsigned integer
</entry>
114 <entry>2 bytes
</entry>
115 <entry>uint16_t
</entry>
119 <entry><literal>i
</literal></entry>
120 <entry><constant>SD_BUS_TYPE_INT32
</constant></entry>
121 <entry>signed integer
</entry>
122 <entry>4 bytes
</entry>
123 <entry>int32_t
</entry>
127 <entry><literal>u
</literal></entry>
128 <entry><constant>SD_BUS_TYPE_UINT32
</constant></entry>
129 <entry>unsigned integer
</entry>
130 <entry>4 bytes
</entry>
131 <entry>uint32_t
</entry>
135 <entry><literal>x
</literal></entry>
136 <entry><constant>SD_BUS_TYPE_INT64
</constant></entry>
137 <entry>signed integer
</entry>
138 <entry>8 bytes
</entry>
139 <entry>int64_t
</entry>
143 <entry><literal>t
</literal></entry>
144 <entry><constant>SD_BUS_TYPE_UINT64
</constant></entry>
145 <entry>unsigned integer
</entry>
146 <entry>8 bytes
</entry>
147 <entry>uint64_t
</entry>
151 <entry><literal>d
</literal></entry>
152 <entry><constant>SD_BUS_TYPE_DOUBLE
</constant></entry>
153 <entry>floating-point
</entry>
154 <entry>8 bytes
</entry>
155 <entry>double
</entry>
159 <entry><literal>s
</literal></entry>
160 <entry><constant>SD_BUS_TYPE_STRING
</constant></entry>
161 <entry>Unicode string
</entry>
162 <entry>variable
</entry>
163 <entry>char[]
</entry>
167 <entry><literal>o
</literal></entry>
168 <entry><constant>SD_BUS_TYPE_OBJECT_PATH
</constant></entry>
169 <entry>object path
</entry>
170 <entry>variable
</entry>
171 <entry>char[]
</entry>
175 <entry><literal>g
</literal></entry>
176 <entry><constant>SD_BUS_TYPE_SIGNATURE
</constant></entry>
177 <entry>signature
</entry>
178 <entry>variable
</entry>
179 <entry>char[]
</entry>
183 <entry><literal>h
</literal></entry>
184 <entry><constant>SD_BUS_TYPE_UNIX_FD
</constant></entry>
185 <entry>UNIX file descriptor
</entry>
186 <entry>4 bytes
</entry>
193 <para>The value of the parameter is copied into a memory area held
194 by the message object, stays in the possession of the caller and
195 may hence be freely changed after this call without affecting the
196 bus message it has been added to. If
<parameter>type
</parameter>
197 is
<literal>h
</literal> (UNIX file descriptor), the descriptor is
198 duplicated by this call and the passed descriptor stays in
199 possession of the caller.
</para>
201 <para>For types
<literal>s
</literal>,
<literal>o
</literal>, and
202 <literal>g
</literal>, the parameter
<parameter>p
</parameter> is
203 interpreted as a pointer to a
<constant>NUL
</constant>-terminated
204 character sequence. As a special case, a
<constant>NULL
</constant>
205 pointer is interpreted as an empty string. The string should be
206 valid Unicode string encoded as UTF-
8. In case of the two latter
207 types, the additional requirements for a D-Bus object path or
208 type signature should be satisfied. Those requirements should be
209 verified by the recipient of the message.
214 <title>Return Value
</title>
216 <para>On success, this call returns
0 or a positive integer. On
217 failure, it returns a negative errno-style error code.
</para>
220 <refsect1 id='errors'
>
221 <title>Errors
</title>
223 <para>Returned errors may indicate the following problems:
</para>
228 <term><constant>-EINVAL
</constant></term>
230 <listitem><para>Specified parameter is invalid.
235 <term><constant>-EPERM
</constant></term>
237 <listitem><para>Message has been sealed.
242 <term><constant>-ESTALE
</constant></term>
244 <listitem><para>Message is in invalid state.
249 <term><constant>-ENXIO
</constant></term>
251 <listitem><para>Message cannot be appended to.
256 <term><constant>-ENOMEM
</constant></term>
258 <listitem><para>Memory allocation failed.
</para></listitem>
266 <para>The
<function>sd_bus_append_basic()
</function> function
267 described here is available as a shared library, which can be
268 compiled and linked to with the
269 <constant>libsystemd
</constant> <citerefentry project='die-net'
><refentrytitle>pkg-config
</refentrytitle><manvolnum>1</manvolnum></citerefentry>
274 <title>See Also
</title>
277 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
278 <citerefentry><refentrytitle>sd-bus
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
279 <citerefentry><refentrytitle>sd_bus_message_append
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
280 <ulink url=
"http://dbus.freedesktop.org/doc/dbus-specification.html">The D-Bus specification
</ulink>