]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/sd_bus_add_object.xml
man: fix incorrectly placed full stop
[thirdparty/systemd.git] / man / sd_bus_add_object.xml
CommitLineData
afb9c0c9
ZJS
1<?xml version='1.0'?> <!--*-nxml-*-->
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
9b62e232 6<refentry id="sd_bus_add_object"
afb9c0c9
ZJS
7 xmlns:xi="http://www.w3.org/2001/XInclude">
8
9 <refentryinfo>
9b62e232 10 <title>sd_bus_add_object</title>
afb9c0c9
ZJS
11 <productname>systemd</productname>
12 </refentryinfo>
13
14 <refmeta>
9b62e232 15 <refentrytitle>sd_bus_add_object</refentrytitle>
afb9c0c9
ZJS
16 <manvolnum>3</manvolnum>
17 </refmeta>
18
19 <refnamediv>
fc91667d
DDM
20 <refname>sd_bus_add_object</refname>
21 <refname>sd_bus_add_fallback</refname>
9b62e232
DDM
22 <refname>sd_bus_add_object_vtable</refname>
23 <refname>sd_bus_add_fallback_vtable</refname>
3841fa79 24 <refname>sd_bus_add_filter</refname>
afb9c0c9
ZJS
25 <refname>SD_BUS_VTABLE_START</refname>
26 <refname>SD_BUS_VTABLE_END</refname>
27 <refname>SD_BUS_METHOD_WITH_NAMES_OFFSET</refname>
28 <refname>SD_BUS_METHOD_WITH_NAMES</refname>
29 <refname>SD_BUS_METHOD_WITH_OFFSET</refname>
30 <refname>SD_BUS_METHOD</refname>
31 <refname>SD_BUS_SIGNAL_WITH_NAMES</refname>
32 <refname>SD_BUS_SIGNAL</refname>
33 <refname>SD_BUS_WRITABLE_PROPERTY</refname>
34 <refname>SD_BUS_PROPERTY</refname>
35 <refname>SD_BUS_PARAM</refname>
36
37 <refpurpose>Declare properties and methods for a D-Bus path</refpurpose>
38 </refnamediv>
39
40 <refsynopsisdiv>
41 <funcsynopsis>
42 <funcsynopsisinfo>#include &lt;systemd/sd-bus-vtable.h&gt;</funcsynopsisinfo>
43
af955f91 44 <xi:include href="sd_bus_add_match.xml" xpointer="sd_bus_message_handler_t"/>
afb9c0c9
ZJS
45
46 <funcprototype>
47 <funcdef>typedef int (*<function>sd_bus_property_get_t</function>)</funcdef>
48 <paramdef>sd_bus *<parameter>bus</parameter></paramdef>
49 <paramdef>const char *<parameter>path</parameter></paramdef>
50 <paramdef>const char *<parameter>interface</parameter></paramdef>
51 <paramdef>const char *<parameter>property</parameter></paramdef>
52 <paramdef>sd_bus_message *<parameter>reply</parameter></paramdef>
53 <paramdef>void *<parameter>userdata</parameter></paramdef>
54 <paramdef>sd_bus_error *<parameter>ret_error</parameter></paramdef>
55 </funcprototype>
56
57 <funcprototype>
58 <funcdef>typedef int (*<function>sd_bus_property_set_t</function>)</funcdef>
59 <paramdef>sd_bus *<parameter>bus</parameter></paramdef>
60 <paramdef>const char *<parameter>path</parameter></paramdef>
61 <paramdef>const char *<parameter>interface</parameter></paramdef>
62 <paramdef>const char *<parameter>property</parameter></paramdef>
63 <paramdef>sd_bus_message *<parameter>value</parameter></paramdef>
64 <paramdef>void *<parameter>userdata</parameter></paramdef>
65 <paramdef>sd_bus_error *<parameter>ret_error</parameter></paramdef>
66 </funcprototype>
67
68 <funcprototype>
69 <funcdef>typedef int (*<function>sd_bus_object_find_t</function>)</funcdef>
70 <paramdef>const char *<parameter>path</parameter></paramdef>
71 <paramdef>const char *<parameter>interface</parameter></paramdef>
72 <paramdef>void *<parameter>userdata</parameter></paramdef>
73 <paramdef>void **<parameter>ret_found</parameter></paramdef>
74 <paramdef>sd_bus_error *<parameter>ret_error</parameter></paramdef>
75 </funcprototype>
76
77 <funcprototype>
9b62e232 78 <funcdef>int <function>sd_bus_add_object</function></funcdef>
afb9c0c9
ZJS
79 <paramdef>sd_bus *<parameter>bus</parameter></paramdef>
80 <paramdef>sd_bus_slot **<parameter>slot</parameter></paramdef>
81 <paramdef>const char *<parameter>path</parameter></paramdef>
9b62e232 82 <paramdef>sd_bus_message_handler_t <parameter>callback</parameter></paramdef>
afb9c0c9
ZJS
83 <paramdef>void *<parameter>userdata</parameter></paramdef>
84 </funcprototype>
85
86 <funcprototype>
9b62e232 87 <funcdef>int <function>sd_bus_add_fallback</function></funcdef>
afb9c0c9
ZJS
88 <paramdef>sd_bus *<parameter>bus</parameter></paramdef>
89 <paramdef>sd_bus_slot **<parameter>slot</parameter></paramdef>
9b62e232
DDM
90 <paramdef>const char *<parameter>path</parameter></paramdef>
91 <paramdef>sd_bus_message_handler_t <parameter>callback</parameter></paramdef>
afb9c0c9
ZJS
92 <paramdef>void *<parameter>userdata</parameter></paramdef>
93 </funcprototype>
94
fc91667d 95 <funcprototype>
9b62e232 96 <funcdef>int <function>sd_bus_add_object_vtable</function></funcdef>
fc91667d
DDM
97 <paramdef>sd_bus *<parameter>bus</parameter></paramdef>
98 <paramdef>sd_bus_slot **<parameter>slot</parameter></paramdef>
99 <paramdef>const char *<parameter>path</parameter></paramdef>
9b62e232
DDM
100 <paramdef>const char *<parameter>interface</parameter></paramdef>
101 <paramdef>const sd_bus_vtable *<parameter>vtable</parameter></paramdef>
fc91667d
DDM
102 <paramdef>void *<parameter>userdata</parameter></paramdef>
103 </funcprototype>
104
105 <funcprototype>
9b62e232 106 <funcdef>int <function>sd_bus_add_fallback_vtable</function></funcdef>
fc91667d
DDM
107 <paramdef>sd_bus *<parameter>bus</parameter></paramdef>
108 <paramdef>sd_bus_slot **<parameter>slot</parameter></paramdef>
9b62e232
DDM
109 <paramdef>const char *<parameter>prefix</parameter></paramdef>
110 <paramdef>const char *<parameter>interface</parameter></paramdef>
111 <paramdef>const sd_bus_vtable *<parameter>vtable</parameter></paramdef>
112 <paramdef>sd_bus_object_find_t <parameter>find</parameter></paramdef>
fc91667d
DDM
113 <paramdef>void *<parameter>userdata</parameter></paramdef>
114 </funcprototype>
115
3841fa79
DDM
116 <funcprototype>
117 <funcdef>int <function>sd_bus_add_filter</function></funcdef>
118 <paramdef>sd_bus *<parameter>bus</parameter></paramdef>
119 <paramdef>sd_bus_slot **<parameter>slot</parameter></paramdef>
120 <paramdef>sd_bus_message_handler_t <parameter>callback</parameter></paramdef>
121 <paramdef>void *<parameter>userdata</parameter></paramdef>
122 </funcprototype>
123
afb9c0c9
ZJS
124 <para>
125 <constant>SD_BUS_VTABLE_START(<replaceable>flags</replaceable>)</constant>
126 </para>
127 <para>
128 <constant>SD_BUS_VTABLE_END</constant>
129 </para>
eff7c2d3
DDM
130 <para>
131 <constant>SD_BUS_METHOD_WITH_ARGS_OFFSET(
132 <replaceable>member</replaceable>,
133 <replaceable>args</replaceable>,
134 <replaceable>result</replaceable>,
135 <replaceable>handler</replaceable>,
136 <replaceable>offset</replaceable>,
137 <replaceable>flags</replaceable>)
138 </constant>
139 </para>
140 <para>
141 <constant>SD_BUS_METHOD_WITH_ARGS(
142 <replaceable>member</replaceable>,
143 <replaceable>args</replaceable>,
144 <replaceable>result</replaceable>,
145 <replaceable>handler</replaceable>,
146 <replaceable>flags</replaceable>)
147 </constant>
148 </para>
afb9c0c9
ZJS
149 <para>
150 <constant>SD_BUS_METHOD_WITH_NAMES_OFFSET(
151 <replaceable>member</replaceable>,
152 <replaceable>signature</replaceable>,
153 <replaceable>in_names</replaceable>,
154 <replaceable>result</replaceable>,
155 <replaceable>out_names</replaceable>,
156 <replaceable>handler</replaceable>,
157 <replaceable>offset</replaceable>,
158 <replaceable>flags</replaceable>)
159 </constant>
160 </para>
161 <para>
162 <constant>SD_BUS_METHOD_WITH_NAMES(
163 <replaceable>member</replaceable>,
164 <replaceable>signature</replaceable>,
165 <replaceable>in_names</replaceable>,
166 <replaceable>result</replaceable>,
167 <replaceable>out_names</replaceable>,
168 <replaceable>handler</replaceable>,
169 <replaceable>flags</replaceable>)
170 </constant>
171 </para>
172 <para>
173 <constant>SD_BUS_METHOD_WITH_OFFSET(
174 <replaceable>member</replaceable>,
175 <replaceable>signature</replaceable>,
176 <replaceable>result</replaceable>,
177 <replaceable>handler</replaceable>,
178 <replaceable>offset</replaceable>,
179 <replaceable>flags</replaceable>)
180 </constant>
181 </para>
182 <para>
183 <constant>SD_BUS_METHOD(
184 <replaceable>member</replaceable>,
185 <replaceable>signature</replaceable>,
186 <replaceable>result</replaceable>,
187 <replaceable>handler</replaceable>,
188 <replaceable>flags</replaceable>)
189 </constant>
190 </para>
eff7c2d3
DDM
191 <para>
192 <constant>SD_BUS_SIGNAL_WITH_ARGS(
193 <replaceable>member</replaceable>,
194 <replaceable>args</replaceable>,
195 <replaceable>flags</replaceable>)
196 </constant>
197 </para>
afb9c0c9
ZJS
198 <para>
199 <constant>SD_BUS_SIGNAL_WITH_NAMES(
200 <replaceable>member</replaceable>,
201 <replaceable>signature</replaceable>,
202 <replaceable>names</replaceable>,
203 <replaceable>flags</replaceable>)
204 </constant>
205 </para>
206 <para>
207 <constant>SD_BUS_SIGNAL(
208 <replaceable>member</replaceable>,
209 <replaceable>signature</replaceable>,
210 <replaceable>flags</replaceable>)
211 </constant>
212 </para>
213 <para>
214 <constant>SD_BUS_WRITABLE_PROPERTY(
215 <replaceable>member</replaceable>,
216 <replaceable>signature</replaceable>,
217 <replaceable>get</replaceable>,
218 <replaceable>set</replaceable>,
219 <replaceable>offset</replaceable>,
220 <replaceable>flags</replaceable>)
221 </constant>
222 </para>
223 <para>
224 <constant>SD_BUS_PROPERTY(
225 <replaceable>member</replaceable>,
226 <replaceable>signature</replaceable>,
227 <replaceable>get</replaceable>,
228 <replaceable>offset</replaceable>,
229 <replaceable>flags</replaceable>)
230 </constant>
231 </para>
232 <para>
233 <constant>SD_BUS_PARAM(<replaceable>name</replaceable>)</constant>
eff7c2d3
DDM
234 <constant>SD_BUS_ARGS(<replaceable>...</replaceable>)</constant>
235 <constant>SD_BUS_RESULT(<replaceable>...</replaceable>)</constant>
236 <constant>SD_BUS_NO_ARGS</constant>
237 <constant>SD_BUS_NO_RESULT</constant>
afb9c0c9
ZJS
238 </para>
239 </funcsynopsis>
240 </refsynopsisdiv>
241
242 <refsect1>
243 <title>Description</title>
244
6ba8071c 245 <para><function>sd_bus_add_object_vtable()</function> is used to declare attributes for the
50b88e87
DDM
246 object path <parameter>path</parameter> connected to the bus connection
247 <parameter>bus</parameter> under the interface <parameter>interface</parameter>. The table
248 <parameter>vtable</parameter> may contain property declarations using
249 <constant>SD_BUS_PROPERTY()</constant> or <constant>SD_BUS_WRITABLE_PROPERTY()</constant>,
250 method declarations using <constant>SD_BUS_METHOD()</constant>,
251 <constant>SD_BUS_METHOD_WITH_NAMES()</constant>,
afb9c0c9
ZJS
252 <constant>SD_BUS_METHOD_WITH_OFFSET()</constant>, or
253 <constant>SD_BUS_METHOD_WITH_NAMES_OFFSET()</constant>, and signal declarations using
50b88e87
DDM
254 <constant>SD_BUS_SIGNAL_WITH_NAMES()</constant> or <constant>SD_BUS_SIGNAL()</constant>, see
255 below. The <replaceable>userdata</replaceable> parameter contains a pointer that will be passed
256 to various callback functions. It may be specified as <constant>NULL</constant> if no value is
fc91667d 257 necessary. An interface can have any number of vtables attached to it.</para>
afb9c0c9 258
12880d14 259 <para><function>sd_bus_add_fallback_vtable()</function> is similar to
50b88e87
DDM
260 <function>sd_bus_add_object_vtable()</function>, but is used to register "fallback" attributes.
261 When looking for an attribute declaration, bus object paths registered with
262 <function>sd_bus_add_object_vtable()</function> are checked first. If no match is found, the
263 fallback vtables are checked for each prefix of the bus object path, i.e. with the last
264 slash-separated components successively removed. This allows the vtable to be used for an
265 arbitrary number of dynamically created objects.</para>
266
267 <para>Parameter <replaceable>find</replaceable> is a function which is used to locate the target
268 object based on the bus object path <replaceable>path</replaceable>. It must return
269 <constant>1</constant> and set the <parameter>ret_found</parameter> output parameter if the
270 object is found, return <constant>0</constant> if the object was not found, and return a
271 negative errno-style error code or initialize the error structure
272 <replaceable>ret_error</replaceable> on error. The pointer passed in
273 <parameter>ret_found</parameter> will be used as the <parameter>userdata</parameter> parameter
274 for the callback functions (offset by the <parameter>offset</parameter> offsets as specified in
275 the vtable entries).</para>
afb9c0c9 276
fc91667d
DDM
277 <para><function>sd_bus_add_object()</function> attaches a callback directly to the object path
278 <parameter>path</parameter>. An object path can have any number of callbacks attached to it.
279 Each callback is prepended to the list of callbacks which are always called in order.
280 <function>sd_bus_add_fallback()</function> is similar to
281 <function>sd_bus_add_object()</function> but applies to fallback paths instead.</para>
282
3841fa79
DDM
283 <para><function>sd_bus_add_filter()</function> installs a callback that is invoked for each
284 incoming D-Bus message. Filters can be used to handle logic common to all messages received by
285 a service (e.g. authentication or authorization).</para>
286
fc91667d 287 <para>When a request is received, any associated callbacks are called sequentially until a
9b62e232 288 callback returns a non-zero integer. Return zero from a callback to give other callbacks the
3841fa79
DDM
289 chance to process the request. Callbacks are called in the following order: first, global
290 callbacks installed with <function>sd_bus_add_filter()</function> are called. Second, callbacks
fc91667d
DDM
291 attached directly to the request object path are called, followed by any D-Bus method callbacks
292 attached to the request object path, interface and member. Finally, the property callbacks
293 attached to the request object path, interface and member are called. If the final callback
294 returns zero, an error reply is sent back to the caller indicating no matching object for the
295 request was found. Note that you can return a positive integer from a callback without
296 immediately sending a reply. This informs sd-bus this callback will take responsibility for
297 replying to the request without forcing the callback to produce a reply immediately. This allows
298 a callback to perform any number of asynchronous operations required to construct a reply. Note
9b62e232 299 that if producing a reply takes too long, the method call will time out at the caller.</para>
fc91667d
DDM
300
301 <para>If a callback was invoked to handle a request that expects a reply and the callback
302 returns a negative value, the value is interpreted as a negative errno-style error code and sent
303 back to the caller as a D-Bus error as if
304 <citerefentry><refentrytitle>sd_bus_reply_method_errno</refentrytitle><manvolnum>3</manvolnum></citerefentry>
305 was called. Additionally, all callbacks take a <structname>sd_bus_error</structname> output
306 parameter that can be used to provide more detailed error information. If
307 <parameter>ret_error</parameter> is set when the callback finishes, the corresponding D-Bus
308 error is sent back to the caller as if
309 <citerefentry><refentrytitle>sd_bus_reply_method_error</refentrytitle><manvolnum>3</manvolnum></citerefentry>
310 was called. Any error stored in <parameter>ret_error</parameter> takes priority over any
311 negative values returned by the same callback when determining which error to send back to
312 the caller. Use
313 <citerefentry><refentrytitle>sd_bus_error_set</refentrytitle><manvolnum>3</manvolnum></citerefentry>
314 or one of its variants to set <parameter>ret_error</parameter> and return a negative integer
315 from a callback with a single function call. To send an error reply after a callback has already
316 finished, use
317 <citerefentry><refentrytitle>sd_bus_reply_method_errno</refentrytitle><manvolnum>3</manvolnum></citerefentry>
318 or one of its variants.</para>
319
320 <para>For all functions, a match slot is created internally. If the output parameter
50b88e87
DDM
321 <replaceable>slot</replaceable> is <constant>NULL</constant>, a "floating" slot object is
322 created, see
afb9c0c9 323 <citerefentry><refentrytitle>sd_bus_slot_set_floating</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
50b88e87
DDM
324 Otherwise, a pointer to the slot object is returned. In that case, the reference to the slot
325 object should be dropped when the vtable is not needed anymore, see
afb9c0c9
ZJS
326 <citerefentry><refentrytitle>sd_bus_slot_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
327 </para>
328
329 <refsect2>
330 <title>The <structname>sd_bus_vtable</structname> array</title>
331
332 <para>The array consists of the structures of type <structname>sd_bus_vtable</structname>, but it
333 should never be filled in manually, but through one of the following macros:</para>
334
335 <variablelist>
336 <varlistentry>
337 <term><constant>SD_BUS_VTABLE_START()</constant></term>
338 <term><constant>SD_BUS_VTABLE_END</constant></term>
339
340 <listitem><para>Those must always be the first and last element.</para></listitem>
341 </varlistentry>
342
eff7c2d3
DDM
343 <varlistentry>
344 <term><constant>SD_BUS_METHOD_WITH_ARGS_OFFSET()</constant></term>
345 <term><constant>SD_BUS_METHOD_WITH_ARGS()</constant></term>
346
347 <listitem><para>Declare a D-Bus method with the name <replaceable>member</replaceable>,
348 arguments <replaceable>args</replaceable> and result <replaceable>result</replaceable>.
349 <replaceable>args</replaceable> expects a sequence of argument type/name pairs wrapped in the
350 <constant>SD_BUS_ARGS()</constant> macro. The elements at even indices in this list describe the
351 types of the method's arguments. The method's parameter signature is the concatenation of all the
352 string literals at even indices in <replaceable>args</replaceable>. If a method has no parameters,
353 pass <constant>SD_BUS_NO_ARGS</constant> to <replaceable>args</replaceable>. The elements at uneven
354 indices describe the names of the method's arguments. <replaceable>result</replaceable> expects a
355 sequence of type/name pairs wrapped in the <constant>SD_BUS_RESULT()</constant> macro in the same
356 format as <constant>SD_BUS_ARGS()</constant>. The method's result signature is the concatenation of
357 all the string literals at even indices in <replaceable>result</replaceable>. If a method has no
358 result, pass <constant>SD_BUS_NO_RESULT</constant> to <replaceable>result</replaceable>. Note that
359 argument types are expected to be quoted string literals and argument names are expected to be
360 unquoted string literals. See below for a complete example.</para>
361
362 <para>The handler function <replaceable>handler</replaceable> must be of type
363 <function>sd_bus_message_handler_t</function>. It will be called to handle the incoming messages
364 that call this method. It receives a pointer that is the <replaceable>userdata</replaceable>
365 parameter passed to the registration function offset by <replaceable>offset</replaceable> bytes.
366 This may be used to pass pointers to different fields in the same data structure to different
367 methods in the same vtable. To send a reply from <parameter>handler</parameter>, call
368 <citerefentry><refentrytitle>sd_bus_reply_method_return</refentrytitle><manvolnum>3</manvolnum></citerefentry>
369 with the message the callback was invoked with. Parameter <replaceable>flags</replaceable> is a
370 combination of flags, see below.</para>
371
372 <constant>SD_BUS_METHOD_WITH_ARGS()</constant> is a shorthand for calling
373 <constant>SD_BUS_METHOD_WITH_ARGS_OFFSET()</constant> with an offset of zero.
374 </listitem>
375 </varlistentry>
376
afb9c0c9
ZJS
377 <varlistentry>
378 <term><constant>SD_BUS_METHOD_WITH_NAMES_OFFSET()</constant></term>
379 <term><constant>SD_BUS_METHOD_WITH_NAMES()</constant></term>
380 <term><constant>SD_BUS_METHOD_WITH_OFFSET()</constant></term>
381 <term><constant>SD_BUS_METHOD()</constant></term>
382
50b88e87
DDM
383 <listitem><para>Declare a D-Bus method with the name <replaceable>member</replaceable>,
384 parameter signature <replaceable>signature</replaceable>, result signature
385 <replaceable>result</replaceable>. Parameters <replaceable>in_names</replaceable> and
386 <replaceable>out_names</replaceable> specify the argument names of the input and output
eff7c2d3 387 arguments in the function signature. <replaceable>in_names</replaceable> and
9b62e232 388 <replaceable>out_names</replaceable> should be created using the
eff7c2d3
DDM
389 <constant>SD_BUS_PARAM()</constant> macro, see below. In all other regards, this macro behaves
390 exactly the same as <constant>SD_BUS_METHOD_WITH_ARGS_OFFSET()</constant>.</para>
afb9c0c9
ZJS
391
392 <para><constant>SD_BUS_METHOD_WITH_NAMES()</constant>,
50b88e87
DDM
393 <constant>SD_BUS_METHOD_WITH_OFFSET()</constant>, and <constant>SD_BUS_METHOD()</constant>
394 are variants which specify zero offset (<replaceable>userdata</replaceable> parameter is
395 passed with no change), leave the names unset (i.e. no parameter names), or both.</para>
eff7c2d3
DDM
396
397 <para>Prefer using <constant>SD_BUS_METHOD_WITH_ARGS_OFFSET()</constant> and
398 <constant>SD_BUS_METHOD_WITH_ARGS()</constant> over these macros as they allow specifying argument
399 types and names next to each other which is less error-prone than first specifying all argument
400 types followed by specifying all argument names.</para>
afb9c0c9
ZJS
401 </listitem>
402 </varlistentry>
403
eff7c2d3
DDM
404 <varlistentry>
405 <term><constant>SD_BUS_SIGNAL_WITH_ARGS()</constant></term>
406
407 <listitem><para>>Declare a D-Bus signal with the name <replaceable>member</replaceable> and
408 arguments <replaceable>args</replaceable>. <replaceable>args</replaceable> expects a sequence of
409 argument type/name pairs wrapped in the <constant>SD_BUS_ARGS()</constant> macro. The elements at
410 even indices in this list describe the types of the signal's arguments. The signal's parameter
411 signature is the concatenation of all the string literals at even indices in
412 <replaceable>args</replaceable>. If a signal has no parameters, pass
413 <constant>SD_BUS_NO_ARGS</constant> to <replaceable>args</replaceable>. The elements at uneven
414 indices describe the names of the signal's arguments. Parameter <replaceable>flags</replaceable> is
415 a combination of flags. See below for a complete example.</para></listitem>
416 </varlistentry>
417
afb9c0c9
ZJS
418 <varlistentry>
419 <term><constant>SD_BUS_SIGNAL_WITH_NAMES()</constant></term>
420 <term><constant>SD_BUS_SIGNAL()</constant></term>
421
422 <listitem><para>Declare a D-Bus signal with the name <replaceable>member</replaceable>,
423 parameter signature <replaceable>signature</replaceable>, and argument names
424 <replaceable>names</replaceable>. <replaceable>names</replaceable> should be
425 created using the <constant>SD_BUS_PARAM()</constant> macro, see below.
426 Parameter <replaceable>flags</replaceable> is a combination of flags, see below.
427 </para>
428
eff7c2d3
DDM
429 <para><constant>SD_BUS_SIGNAL()</constant> is equivalent to
430 <constant>SD_BUS_SIGNAL_WITH_NAMES()</constant> with the <replaceable>names</replaceable> parameter
431 unset (i.e. no parameter names).</para>
432
433 <para>Prefer using <constant>SD_BUS_SIGNAL_WITH_ARGS()</constant> over these macros as it allows
434 specifying argument types and names next to each other which is less error-prone than first
435 specifying all argument types followed by specifying all argument names.</para>
afb9c0c9
ZJS
436 </listitem>
437 </varlistentry>
438
439 <varlistentry>
440 <term><constant>SD_BUS_WRITABLE_PROPERTY()</constant></term>
441 <term><constant>SD_BUS_PROPERTY()</constant></term>
442
50b88e87
DDM
443 <listitem><para>Declare a D-Bus property with the name <replaceable>member</replaceable>
444 and value signature <replaceable>signature</replaceable>. Parameters
445 <replaceable>get</replaceable> and <replaceable>set</replaceable> are the getter and
446 setter methods. They are called with a pointer that is the
447 <replaceable>userdata</replaceable> parameter passed to the registration function offset
448 by <replaceable>offset</replaceable> bytes. This may be used pass pointers to different
449 fields in the same data structure to different setters and getters in the same vtable.
450 Parameter <replaceable>flags</replaceable> is a combination of flags, see below.</para>
451
452 <para>The setter and getter methods may be omitted (specified as
6ba8071c 453 <constant>NULL</constant>), if the property is one of the basic types or
50b88e87
DDM
454 <literal>as</literal> in case of read-only properties. In those cases, the
455 <replaceable>userdata</replaceable> and <replaceable>offset</replaceable> parameters must
6ba8071c 456 together point to a valid variable of the corresponding type. A default setter and getter
50b88e87 457 will be provided, which simply copy the argument between this variable and the message.
afb9c0c9
ZJS
458 </para>
459
50b88e87
DDM
460 <para><constant>SD_BUS_PROPERTY()</constant> is used to define a read-only property.
461 </para></listitem>
afb9c0c9
ZJS
462 </varlistentry>
463
464 <varlistentry>
465 <term><constant>SD_BUS_PARAM()</constant></term>
50b88e87
DDM
466 <listitem><para>Parameter names should be wrapped in this macro, see the example below.
467 </para></listitem>
afb9c0c9
ZJS
468 </varlistentry>
469 </variablelist>
470 </refsect2>
471
472 <refsect2>
473 <title>Flags</title>
474
475 <para>The <replaceable>flags</replaceable> parameter is used to specify a combination of
476 <ulink url="https://dbus.freedesktop.org/doc/dbus-specification.html#introspection-format">D-Bus annotations</ulink>.
477 </para>
478
479 <variablelist>
480 <varlistentry>
481 <term><constant>SD_BUS_VTABLE_DEPRECATED</constant></term>
482
483 <listitem><para>Mark this vtable entry as deprecated using the
50b88e87 484 <constant>org.freedesktop.DBus.Deprecated</constant> annotation in introspection data. If
afb9c0c9
ZJS
485 specified for <constant>SD_BUS_VTABLE_START()</constant>, the annotation is applied to the
486 enclosing interface.</para></listitem>
487 </varlistentry>
488
489 <varlistentry>
490 <term><constant>SD_BUS_VTABLE_HIDDEN</constant></term>
491
50b88e87
DDM
492 <listitem><para>Make this vtable entry hidden. It will not be shown in introspection data.
493 If specified for <constant>SD_BUS_VTABLE_START()</constant>, all entries in the array are
494 hidden.</para></listitem>
afb9c0c9
ZJS
495 </varlistentry>
496
497 <varlistentry>
498 <term><constant>SD_BUS_VTABLE_UNPRIVILEGED</constant></term>
499
500 <listitem><para>Mark this vtable entry as unprivileged. If not specified, the
501 <constant>org.freedesktop.systemd1.Privileged</constant> annotation with value
50b88e87 502 <literal>true</literal> will be shown in introspection data.</para></listitem>
afb9c0c9
ZJS
503 </varlistentry>
504
505 <varlistentry>
506 <term><constant>SD_BUS_VTABLE_METHOD_NO_REPLY</constant></term>
507
508 <listitem><para>Mark his vtable entry as a method that will not return a reply using the
509 <constant>org.freedesktop.DBus.Method.NoReply</constant> annotation in introspection data.
510 </para></listitem>
511 </varlistentry>
512
513 <varlistentry>
94c4bbe5
PB
514 <term><constant>SD_BUS_VTABLE_PROPERTY_CONST</constant></term>
515 <term><constant>SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE</constant></term>
516 <term><constant>SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION</constant></term>
afb9c0c9
ZJS
517
518 <listitem><para>Those three flags correspond to different values of the
50b88e87
DDM
519 <constant>org.freedesktop.DBus.Property.EmitsChangedSignal</constant> annotation, which
520 specifies whether the
521 <constant>org.freedesktop.DBus.Properties.PropertiesChanged</constant> signal is emitted
522 whenever the property changes. <constant>SD_BUS_VTABLE_PROPERTY_CONST</constant>
523 corresponds to <constant>const</constant> and means that the property never changes during
524 the lifetime of the object it belongs to, so no signal needs to be emitted.
525 <constant>SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE</constant> corresponds to
526 <constant>true</constant> and means that the signal is emitted.
527 <constant>SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION</constant> corresponds to
528 <constant>invalidates</constant> and means that the signal is emitted, but the value is
529 not included in the signal.</para></listitem>
afb9c0c9
ZJS
530 </varlistentry>
531
532 <varlistentry>
533 <term><constant>SD_BUS_VTABLE_PROPERTY_EXPLICIT</constant></term>
534
50b88e87
DDM
535 <listitem><para>Mark this vtable property entry as requiring explicit request to for the
536 value to be shown (generally because the value is large or slow to calculate). This entry
537 cannot be combined with <constant>SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE</constant>, and will
538 not be shown in property listings by default (e.g. <command>busctl introspect</command>).
539 This corresponds to the <constant>org.freedesktop.systemd1.Explicit</constant> annotation
540 in introspection data.</para></listitem>
afb9c0c9 541 </varlistentry>
0271e9b1
LP
542
543 <varlistentry>
544 <term><constant>SD_BUS_VTABLE_SENSITIVE</constant></term>
545
546 <listitem><para>Mark this vtable method entry as processing sensitive data. When set,
547 incoming method call messages and their outgoing reply messages are marked as sensitive using
548 <citerefentry><refentrytitle>sd_bus_message_sensitive</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
549 so that they are erased from memory when freed.</para></listitem>
550 </varlistentry>
551
552 <varlistentry>
553 <term><constant>SD_BUS_VTABLE_ABSOLUTE_OFFSET</constant></term>
554
555 <listitem><para>Mark this vtable method or property entry so that the user data pointer passed to
556 its associated handler functions is determined slightly differently: instead of adding the offset
557 parameter of the entry to the user data pointer specified during vtable registration, the offset is
558 passed directly, converted to a pointer, without taking the user data pointer specified during
559 vtable registration into account.</para></listitem>
560 </varlistentry>
afb9c0c9
ZJS
561 </variablelist>
562 </refsect2>
563 </refsect1>
564
565 <refsect1>
566 <title>Examples</title>
567
568 <example>
569 <title>Create a simple listener on the bus</title>
570
571 <programlisting><xi:include href="vtable-example.c" parse="text" /></programlisting>
572
50b88e87
DDM
573 <para>This creates a simple client on the bus (the user bus, when run as normal user). We may
574 use the D-Bus <constant>org.freedesktop.DBus.Introspectable.Introspect</constant> call to
575 acquire the XML description of the interface:</para>
afb9c0c9
ZJS
576
577 <programlisting><xi:include href="vtable-example.xml" parse="text" /></programlisting>
578 </example>
579 </refsect1>
580
581 <refsect1>
582 <title>Return Value</title>
583
85eeb142
DDM
584 <para>On success, <function>sd_bus_add_object_vtable()</function> and
585 <function>sd_bus_add_fallback_vtable()</function> return a non-negative integer. On
50b88e87 586 failure, they return a negative errno-style error code.</para>
afb9c0c9
ZJS
587
588 <refsect2>
589 <title>Errors</title>
590
591 <para>Returned errors may indicate the following problems:</para>
592
593 <variablelist>
594 <varlistentry>
595 <term><constant>-EINVAL</constant></term>
596
50b88e87
DDM
597 <listitem><para>One of the required parameters is <constant>NULL</constant> or invalid. A
598 reserved D-Bus interface was passed as the <replaceable>interface</replaceable> parameter.
599 </para></listitem>
afb9c0c9
ZJS
600 </varlistentry>
601
602 <varlistentry>
603 <term><constant>-ENOPKG</constant></term>
604
605 <listitem><para>The bus cannot be resolved.</para></listitem>
606 </varlistentry>
607
608 <varlistentry>
609 <term><constant>-ECHILD</constant></term>
610
611 <listitem><para>The bus was created in a different process.</para></listitem>
612 </varlistentry>
613
614 <varlistentry>
615 <term><constant>-ENOMEM</constant></term>
616
617 <listitem><para>Memory allocation failed.</para></listitem>
618 </varlistentry>
619
620 <varlistentry>
621 <term><constant>-EPROTOTYPE</constant></term>
622
623 <listitem><para><function>sd_bus_add_object_vtable</function> and
50b88e87
DDM
624 <function>sd_bus_add_fallback_vtable</function> have been both called for the same bus
625 object path, which is not allowed.</para></listitem>
afb9c0c9
ZJS
626 </varlistentry>
627
628 <varlistentry>
629 <term><constant>-EEXIST</constant></term>
630
631 <listitem><para>This vtable has already been registered for this
632 <replaceable>interface</replaceable> and <replaceable>path</replaceable>.
633 </para></listitem>
634 </varlistentry>
635 </variablelist>
636 </refsect2>
637 </refsect1>
638
639 <xi:include href="libsystemd-pkgconfig.xml" />
640
641 <refsect1>
642 <title>See Also</title>
643
644 <para>
645 <citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
ad300028
DDM
646 <citerefentry><refentrytitle>busctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
647 <citerefentry><refentrytitle>sd_bus_emit_properties_changed</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
648 <citerefentry><refentrytitle>sd_bus_emit_object_added</refentrytitle><manvolnum>3</manvolnum></citerefentry>
afb9c0c9
ZJS
649 </para>
650 </refsect1>
651</refentry>