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