Debian Codegraph @

upstream/debian-unstable/man3/sd_bus_add_object.3

raw
1 '\" t
2 .TH "SD_BUS_ADD_OBJECT" "3" "" "systemd 261~rc3" "sd_bus_add_object"
3 .\" -----------------------------------------------------------------
4 .\" * Define some portability stuff
5 .\" -----------------------------------------------------------------
6 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 .\" http://bugs.debian.org/507673
8 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
9 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 .ie \n(.g .ds Aq \(aq
11 .el .ds Aq '
12 .\" -----------------------------------------------------------------
13 .\" * set default formatting
14 .\" -----------------------------------------------------------------
15 .\" disable hyphenation
16 .nh
17 .\" disable justification (adjust text to left margin only)
18 .ad l
19 .\" -----------------------------------------------------------------
20 .\" * MAIN CONTENT STARTS HERE *
21 .\" -----------------------------------------------------------------
22 .SH "NAME"
23 sd_bus_add_object, sd_bus_add_fallback, sd_bus_add_object_vtable, sd_bus_add_fallback_vtable, sd_bus_add_filter, SD_BUS_VTABLE_CAPABILITY, SD_BUS_VTABLE_START, SD_BUS_VTABLE_END, SD_BUS_METHOD_WITH_NAMES_OFFSET, SD_BUS_METHOD_WITH_NAMES, SD_BUS_METHOD_WITH_OFFSET, SD_BUS_METHOD, SD_BUS_SIGNAL_WITH_NAMES, SD_BUS_SIGNAL, SD_BUS_WRITABLE_PROPERTY, SD_BUS_PROPERTY, SD_BUS_PARAM \- Declare properties and methods for a D\-Bus path
24 .SH "SYNOPSIS"
25 .sp
26 .ft B
27 .nf
28 #include <systemd/sd\-bus\-vtable\&.h>
29 .fi
30 .ft
31 .HP \w'typedef\ int\ (*sd_bus_message_handler_t)('u
32 .BI "typedef int (*sd_bus_message_handler_t)(sd_bus_message\ *" "m" ", void\ *" "userdata" ", sd_bus_error\ *" "ret_error" ");"
33 .HP \w'typedef\ int\ (*sd_bus_property_get_t)('u
34 .BI "typedef int (*sd_bus_property_get_t)(sd_bus\ *" "bus" ", const\ char\ *" "path" ", const\ char\ *" "interface" ", const\ char\ *" "property" ", sd_bus_message\ *" "reply" ", void\ *" "userdata" ", sd_bus_error\ *" "ret_error" ");"
35 .HP \w'typedef\ int\ (*sd_bus_property_set_t)('u
36 .BI "typedef int (*sd_bus_property_set_t)(sd_bus\ *" "bus" ", const\ char\ *" "path" ", const\ char\ *" "interface" ", const\ char\ *" "property" ", sd_bus_message\ *" "value" ", void\ *" "userdata" ", sd_bus_error\ *" "ret_error" ");"
37 .HP \w'typedef\ int\ (*sd_bus_object_find_t)('u
38 .BI "typedef int (*sd_bus_object_find_t)(const\ char\ *" "path" ", const\ char\ *" "interface" ", void\ *" "userdata" ", void\ **" "ret_found" ", sd_bus_error\ *" "ret_error" ");"
39 .HP \w'int\ sd_bus_add_object('u
40 .BI "int sd_bus_add_object(sd_bus\ *" "bus" ", sd_bus_slot\ **" "slot" ", const\ char\ *" "path" ", sd_bus_message_handler_t\ " "callback" ", void\ *" "userdata" ");"
41 .HP \w'int\ sd_bus_add_fallback('u
42 .BI "int sd_bus_add_fallback(sd_bus\ *" "bus" ", sd_bus_slot\ **" "slot" ", const\ char\ *" "path" ", sd_bus_message_handler_t\ " "callback" ", void\ *" "userdata" ");"
43 .HP \w'int\ sd_bus_add_object_vtable('u
44 .BI "int sd_bus_add_object_vtable(sd_bus\ *" "bus" ", sd_bus_slot\ **" "slot" ", const\ char\ *" "path" ", const\ char\ *" "interface" ", const\ sd_bus_vtable\ *" "vtable" ", void\ *" "userdata" ");"
45 .HP \w'int\ sd_bus_add_fallback_vtable('u
46 .BI "int sd_bus_add_fallback_vtable(sd_bus\ *" "bus" ", sd_bus_slot\ **" "slot" ", const\ char\ *" "prefix" ", const\ char\ *" "interface" ", const\ sd_bus_vtable\ *" "vtable" ", sd_bus_object_find_t\ " "find" ", void\ *" "userdata" ");"
47 .HP \w'int\ sd_bus_add_filter('u
48 .BI "int sd_bus_add_filter(sd_bus\ *" "bus" ", sd_bus_slot\ **" "slot" ", sd_bus_message_handler_t\ " "callback" ", void\ *" "userdata" ");"
49 .PP
50 \fBSD_BUS_VTABLE_CAPABILITY(\fR\fB\fIcapability\fR\fR\fB)\fR
51 .PP
52 \fBSD_BUS_VTABLE_START(\fR\fB\fIflags\fR\fR\fB)\fR
53 .PP
54 \fBSD_BUS_VTABLE_END\fR
55 .PP
56 \fBSD_BUS_METHOD_WITH_ARGS_OFFSET(\fR\fB\fImember\fR\fR\fB, \fR\fB\fIargs\fR\fR\fB, \fR\fB\fIresult\fR\fR\fB, \fR\fB\fIhandler\fR\fR\fB, \fR\fB\fIoffset\fR\fR\fB, \fR\fB\fIflags\fR\fR\fB) \fR
57 .PP
58 \fBSD_BUS_METHOD_WITH_ARGS(\fR\fB\fImember\fR\fR\fB, \fR\fB\fIargs\fR\fR\fB, \fR\fB\fIresult\fR\fR\fB, \fR\fB\fIhandler\fR\fR\fB, \fR\fB\fIflags\fR\fR\fB) \fR
59 .PP
60 \fBSD_BUS_METHOD_WITH_NAMES_OFFSET(\fR\fB\fImember\fR\fR\fB, \fR\fB\fIsignature\fR\fR\fB, \fR\fB\fIin_names\fR\fR\fB, \fR\fB\fIresult\fR\fR\fB, \fR\fB\fIout_names\fR\fR\fB, \fR\fB\fIhandler\fR\fR\fB, \fR\fB\fIoffset\fR\fR\fB, \fR\fB\fIflags\fR\fR\fB) \fR
61 .PP
62 \fBSD_BUS_METHOD_WITH_NAMES(\fR\fB\fImember\fR\fR\fB, \fR\fB\fIsignature\fR\fR\fB, \fR\fB\fIin_names\fR\fR\fB, \fR\fB\fIresult\fR\fR\fB, \fR\fB\fIout_names\fR\fR\fB, \fR\fB\fIhandler\fR\fR\fB, \fR\fB\fIflags\fR\fR\fB) \fR
63 .PP
64 \fBSD_BUS_METHOD_WITH_OFFSET(\fR\fB\fImember\fR\fR\fB, \fR\fB\fIsignature\fR\fR\fB, \fR\fB\fIresult\fR\fR\fB, \fR\fB\fIhandler\fR\fR\fB, \fR\fB\fIoffset\fR\fR\fB, \fR\fB\fIflags\fR\fR\fB) \fR
65 .PP
66 \fBSD_BUS_METHOD(\fR\fB\fImember\fR\fR\fB, \fR\fB\fIsignature\fR\fR\fB, \fR\fB\fIresult\fR\fR\fB, \fR\fB\fIhandler\fR\fR\fB, \fR\fB\fIflags\fR\fR\fB) \fR
67 .PP
68 \fBSD_BUS_SIGNAL_WITH_ARGS(\fR\fB\fImember\fR\fR\fB, \fR\fB\fIargs\fR\fR\fB, \fR\fB\fIflags\fR\fR\fB) \fR
69 .PP
70 \fBSD_BUS_SIGNAL_WITH_NAMES(\fR\fB\fImember\fR\fR\fB, \fR\fB\fIsignature\fR\fR\fB, \fR\fB\fInames\fR\fR\fB, \fR\fB\fIflags\fR\fR\fB) \fR
71 .PP
72 \fBSD_BUS_SIGNAL(\fR\fB\fImember\fR\fR\fB, \fR\fB\fIsignature\fR\fR\fB, \fR\fB\fIflags\fR\fR\fB) \fR
73 .PP
74 \fBSD_BUS_WRITABLE_PROPERTY(\fR\fB\fImember\fR\fR\fB, \fR\fB\fIsignature\fR\fR\fB, \fR\fB\fIget\fR\fR\fB, \fR\fB\fIset\fR\fR\fB, \fR\fB\fIoffset\fR\fR\fB, \fR\fB\fIflags\fR\fR\fB) \fR
75 .PP
76 \fBSD_BUS_PROPERTY(\fR\fB\fImember\fR\fR\fB, \fR\fB\fIsignature\fR\fR\fB, \fR\fB\fIget\fR\fR\fB, \fR\fB\fIoffset\fR\fR\fB, \fR\fB\fIflags\fR\fR\fB) \fR
77 .PP
78 \fBSD_BUS_PARAM(\fR\fB\fIname\fR\fR\fB)\fR
79 .PP
80 \fBSD_BUS_ARGS(\fR\fB\fI\&.\&.\&.\fR\fR\fB)\fR
81 .PP
82 \fBSD_BUS_RESULT(\fR\fB\fI\&.\&.\&.\fR\fR\fB)\fR
83 .PP
84 \fBSD_BUS_NO_ARGS\fR
85 .PP
86 \fBSD_BUS_NO_RESULT\fR
87 .SH "DESCRIPTION"
88 .PP
89 \fBsd_bus_add_object_vtable()\fR
90 is used to declare attributes for the object path
91 \fIpath\fR
92 connected to the bus connection
93 \fIbus\fR
94 under the interface
95 \fIinterface\fR\&. The table
96 \fIvtable\fR
97 may contain property declarations using
98 \fBSD_BUS_PROPERTY()\fR
99 or
100 \fBSD_BUS_WRITABLE_PROPERTY()\fR, method declarations using
101 \fBSD_BUS_METHOD()\fR,
102 \fBSD_BUS_METHOD_WITH_NAMES()\fR,
103 \fBSD_BUS_METHOD_WITH_OFFSET()\fR, or
104 \fBSD_BUS_METHOD_WITH_NAMES_OFFSET()\fR, and signal declarations using
105 \fBSD_BUS_SIGNAL_WITH_NAMES()\fR
106 or
107 \fBSD_BUS_SIGNAL()\fR, see below\&. The
108 \fIuserdata\fR
109 parameter contains a pointer that will be passed to various callback functions\&. It may be specified as
110 \fBNULL\fR
111 if no value is necessary\&. An interface can have any number of vtables attached to it\&.
112 .PP
113 \fBsd_bus_add_fallback_vtable()\fR
114 is similar to
115 \fBsd_bus_add_object_vtable()\fR, but is used to register "fallback" attributes\&. When looking for an attribute declaration, bus object paths registered with
116 \fBsd_bus_add_object_vtable()\fR
117 are checked first\&. If no match is found, the fallback vtables are checked for each prefix of the bus object path, i\&.e\&. with the last slash\-separated components successively removed\&. This allows the vtable to be used for an arbitrary number of dynamically created objects\&.
118 .PP
119 Parameter
120 \fIfind\fR
121 is a function which is used to locate the target object based on the bus object path
122 \fIpath\fR\&. It must return
123 \fB1\fR
124 and set the
125 \fIret_found\fR
126 output parameter if the object is found, return
127 \fB0\fR
128 if the object was not found, and return a negative errno\-style error code or initialize the error structure
129 \fIret_error\fR
130 on error\&. The pointer passed in
131 \fIret_found\fR
132 will be used as the
133 \fIuserdata\fR
134 parameter for the callback functions (offset by the
135 \fIoffset\fR
136 offsets as specified in the vtable entries)\&.
137 .PP
138 \fBsd_bus_add_object()\fR
139 attaches a callback directly to the object path
140 \fIpath\fR\&. An object path can have any number of callbacks attached to it\&. Each callback is prepended to the list of callbacks which are always called in order\&.
141 \fBsd_bus_add_fallback()\fR
142 is similar to
143 \fBsd_bus_add_object()\fR
144 but applies to fallback paths instead\&.
145 .PP
146 \fBsd_bus_add_filter()\fR
147 installs a callback that is invoked for each incoming D\-Bus message\&. Filters can be used to handle logic common to all messages received by a service (e\&.g\&. authentication or authorization)\&.
148 .PP
149 When a request is received, any associated callbacks are called sequentially until a callback returns a non\-zero integer\&. Return zero from a callback to give other callbacks the chance to process the request\&. Callbacks are called in the following order: first, global callbacks installed with
150 \fBsd_bus_add_filter()\fR
151 are called\&. Second, callbacks attached directly to the request object path are called, followed by any D\-Bus method callbacks attached to the request object path, interface and member\&. Finally, the property callbacks attached to the request object path, interface and member are called\&. If the final callback returns zero, an error reply is sent back to the caller indicating no matching object for the request was found\&.
152 .PP
153 Note that you can return a positive integer from a
154 \fImethod\fR
155 callback without immediately sending a reply\&. This informs sd\-bus this callback will take responsibility for replying to the request without forcing the callback to produce a reply immediately\&. This allows a callback to perform any number of asynchronous operations required to construct a reply\&. However, if producing a reply takes too long, the method call will time out at the caller\&. This is only available to methods and not properties\&.
156 .PP
157 If a callback was invoked to handle a request that expects a reply and the callback returns a negative value, the value is interpreted as a negative errno\-style error code and sent back to the caller as a D\-Bus error as if
158 \fBsd_bus_reply_method_errno\fR(3)
159 was called\&. Additionally, all callbacks take a
160 sd_bus_error
161 output parameter that can be used to provide more detailed error information\&. If
162 \fIret_error\fR
163 is set when the callback finishes, the corresponding D\-Bus error is sent back to the caller as if
164 \fBsd_bus_reply_method_error\fR(3)
165 was called\&. Any error stored in
166 \fIret_error\fR
167 takes priority over any negative values returned by the same callback when determining which error to send back to the caller\&. Use
168 \fBsd_bus_error_set\fR(3)
169 or one of its variants to set
170 \fIret_error\fR
171 and return a negative integer from a callback with a single function call\&. To send an error reply after a callback has already finished, use
172 \fBsd_bus_reply_method_errno\fR(3)
173 or one of its variants\&.
174 .PP
175 For all functions, a match slot is created internally\&. If the output parameter
176 \fIslot\fR
177 is
178 \fBNULL\fR, a "floating" slot object is created, see
179 \fBsd_bus_slot_set_floating\fR(3)\&. Otherwise, a pointer to the slot object is returned\&. In that case, the reference to the slot object should be dropped when the vtable is not needed anymore, see
180 \fBsd_bus_slot_unref\fR(3)\&.
181 .SS "The sd_bus_vtable array"
182 .PP
183 The array consists of the structures of type
184 sd_bus_vtable, but it should never be filled in manually, but through one of the following macros:
185 .PP
186 \fBSD_BUS_VTABLE_START(\fR\fB\fIflags\fR\fR\fB)\fR, \fBSD_BUS_VTABLE_END\fR
187 .RS 4
188 Those must always be the first and last element\&. The
189 \fIflags\fR
190 parameter can be used to set attributes that apply to the whole array; see the "Flags" section below\&.
191 .RE
192 .PP
193 \fBSD_BUS_METHOD_WITH_ARGS_OFFSET()\fR, \fBSD_BUS_METHOD_WITH_ARGS()\fR
194 .RS 4
195 Declare a D\-Bus method with the name
196 \fImember\fR, arguments
197 \fIargs\fR
198 and result
199 \fIresult\fR\&.
200 \fIargs\fR
201 expects a sequence of argument type/name pairs wrapped in the
202 \fBSD_BUS_ARGS()\fR
203 macro\&. The elements at even indices in this list describe the types of the method\*(Aqs arguments\&. The method\*(Aqs parameter signature is the concatenation of all the string literals at even indices in
204 \fIargs\fR\&. If a method has no parameters, pass
205 \fBSD_BUS_NO_ARGS\fR
206 to
207 \fIargs\fR\&. The elements at uneven indices describe the names of the method\*(Aqs arguments\&.
208 \fIresult\fR
209 expects a sequence of type/name pairs wrapped in the
210 \fBSD_BUS_RESULT()\fR
211 macro in the same format as
212 \fBSD_BUS_ARGS()\fR\&. The method\*(Aqs result signature is the concatenation of all the string literals at even indices in
213 \fIresult\fR\&. If a method has no result, pass
214 \fBSD_BUS_NO_RESULT\fR
215 to
216 \fIresult\fR\&. Note that argument types are expected to be quoted string literals and argument names are expected to be unquoted string literals\&. See below for a complete example\&.
217 .sp
218 The handler function
219 \fIhandler\fR
220 must be of type
221 \fBsd_bus_message_handler_t\fR\&. It will be called to handle the incoming messages that call this method\&. It receives a pointer that is the
222 \fIuserdata\fR
223 parameter passed to the registration function offset by
224 \fIoffset\fR
225 bytes\&. This may be used to pass pointers to different fields in the same data structure to different methods in the same vtable\&. To send a reply from
226 \fIhandler\fR, call
227 \fBsd_bus_reply_method_return\fR(3)
228 with the message the callback was invoked with\&. Parameter
229 \fIflags\fR
230 is a combination of flags, see below\&.
231 .sp
232 \fBSD_BUS_METHOD_WITH_ARGS()\fR
233 is a shorthand for calling
234 \fBSD_BUS_METHOD_WITH_ARGS_OFFSET()\fR
235 with an offset of zero\&.
236 .RE
237 .PP
238 \fBSD_BUS_METHOD_WITH_NAMES_OFFSET()\fR, \fBSD_BUS_METHOD_WITH_NAMES()\fR, \fBSD_BUS_METHOD_WITH_OFFSET()\fR, \fBSD_BUS_METHOD()\fR
239 .RS 4
240 Declare a D\-Bus method with the name
241 \fImember\fR, parameter signature
242 \fIsignature\fR, result signature
243 \fIresult\fR\&. Parameters
244 \fIin_names\fR
245 and
246 \fIout_names\fR
247 specify the argument names of the input and output arguments in the function signature\&.
248 \fIin_names\fR
249 and
250 \fIout_names\fR
251 should be created using the
252 \fBSD_BUS_PARAM()\fR
253 macro, see below\&. In all other regards, this macro behaves exactly the same as
254 \fBSD_BUS_METHOD_WITH_ARGS_OFFSET()\fR\&.
255 .sp
256 \fBSD_BUS_METHOD_WITH_NAMES()\fR,
257 \fBSD_BUS_METHOD_WITH_OFFSET()\fR, and
258 \fBSD_BUS_METHOD()\fR
259 are variants which specify zero offset (\fIuserdata\fR
260 parameter is passed with no change), leave the names unset (i\&.e\&. no parameter names), or both\&.
261 .sp
262 Prefer using
263 \fBSD_BUS_METHOD_WITH_ARGS_OFFSET()\fR
264 and
265 \fBSD_BUS_METHOD_WITH_ARGS()\fR
266 over these macros as they allow specifying argument types and names next to each other which is less error\-prone than first specifying all argument types followed by specifying all argument names\&.
267 .RE
268 .PP
269 \fBSD_BUS_SIGNAL_WITH_ARGS()\fR
270 .RS 4
271 Declare a D\-Bus signal with the name
272 \fImember\fR
273 and arguments
274 \fIargs\fR\&.
275 \fIargs\fR
276 expects a sequence of argument type/name pairs wrapped in the
277 \fBSD_BUS_ARGS()\fR
278 macro\&. The elements at even indices in this list describe the types of the signal\*(Aqs arguments\&. The signal\*(Aqs parameter signature is the concatenation of all the string literals at even indices in
279 \fIargs\fR\&. If a signal has no parameters, pass
280 \fBSD_BUS_NO_ARGS\fR
281 to
282 \fIargs\fR\&. The elements at uneven indices describe the names of the signal\*(Aqs arguments\&. Parameter
283 \fIflags\fR
284 is a combination of flags\&. See below for a complete example\&.
285 .RE
286 .PP
287 \fBSD_BUS_SIGNAL_WITH_NAMES()\fR, \fBSD_BUS_SIGNAL()\fR
288 .RS 4
289 Declare a D\-Bus signal with the name
290 \fImember\fR, parameter signature
291 \fIsignature\fR, and argument names
292 \fInames\fR\&.
293 \fInames\fR
294 should be created using the
295 \fBSD_BUS_PARAM()\fR
296 macro, see below\&. Parameter
297 \fIflags\fR
298 is a combination of flags, see below\&.
299 .sp
300 \fBSD_BUS_SIGNAL()\fR
301 is equivalent to
302 \fBSD_BUS_SIGNAL_WITH_NAMES()\fR
303 with the
304 \fInames\fR
305 parameter unset (i\&.e\&. no parameter names)\&.
306 .sp
307 Prefer using
308 \fBSD_BUS_SIGNAL_WITH_ARGS()\fR
309 over these macros as it allows specifying argument types and names next to each other which is less error\-prone than first specifying all argument types followed by specifying all argument names\&.
310 .RE
311 .PP
312 \fBSD_BUS_WRITABLE_PROPERTY()\fR, \fBSD_BUS_PROPERTY()\fR
313 .RS 4
314 Declare a D\-Bus property with the name
315 \fImember\fR
316 and value signature
317 \fIsignature\fR\&. Parameters
318 \fIget\fR
319 and
320 \fIset\fR
321 are the getter and setter methods\&. They are called with a pointer that is the
322 \fIuserdata\fR
323 parameter passed to the registration function offset by
324 \fIoffset\fR
325 bytes\&. This may be used pass pointers to different fields in the same data structure to different setters and getters in the same vtable\&. Parameter
326 \fIflags\fR
327 is a combination of flags, see below\&.
328 .sp
329 The setter and getter methods may be omitted (specified as
330 \fBNULL\fR), if the property is one of the basic types or
331 "as"
332 in case of read\-only properties\&. In those cases, the
333 \fIuserdata\fR
334 and
335 \fIoffset\fR
336 parameters must together point to a valid variable of the corresponding type\&. A default setter and getter will be provided, which simply copy the argument between this variable and the message\&.
337 .sp
338 \fBSD_BUS_PROPERTY()\fR
339 is used to define a read\-only property\&.
340 .RE
341 .PP
342 \fBSD_BUS_PARAM()\fR
343 .RS 4
344 Parameter names should be wrapped in this macro, see the example below\&.
345 .RE
346 .SS "Flags"
347 .PP
348 The
349 \fIflags\fR
350 parameter is used to specify a combination of
351 \m[blue]\fBD\-Bus annotations\fR\m[]\&\s-2\u[1]\d\s+2\&.
352 .PP
353 \fBSD_BUS_VTABLE_DEPRECATED\fR
354 .RS 4
355 Mark this vtable entry as deprecated using the
356 \fBorg\&.freedesktop\&.DBus\&.Deprecated\fR
357 annotation in introspection data\&. If specified for
358 \fBSD_BUS_VTABLE_START()\fR, the annotation is applied to the enclosing interface\&.
359 .RE
360 .PP
361 \fBSD_BUS_VTABLE_HIDDEN\fR
362 .RS 4
363 Make this vtable entry hidden\&. It will not be shown in introspection data\&. If specified for
364 \fBSD_BUS_VTABLE_START()\fR, all entries in the array are hidden\&.
365 .RE
366 .PP
367 \fBSD_BUS_VTABLE_METHOD_NO_REPLY\fR
368 .RS 4
369 Mark this vtable entry as a method that will not return a reply using the
370 \fBorg\&.freedesktop\&.DBus\&.Method\&.NoReply\fR
371 annotation in introspection data\&.
372 .RE
373 .PP
374 \fBSD_BUS_VTABLE_PROPERTY_CONST\fR, \fBSD_BUS_VTABLE_PROPERTY_EMITS_CHANGE\fR, \fBSD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION\fR
375 .RS 4
376 Those three flags correspond to different values of the
377 \fBorg\&.freedesktop\&.DBus\&.Property\&.EmitsChangedSignal\fR
378 annotation, which specifies whether the
379 \fBorg\&.freedesktop\&.DBus\&.Properties\&.PropertiesChanged\fR
380 signal is emitted whenever the property changes\&.
381 \fBSD_BUS_VTABLE_PROPERTY_CONST\fR
382 corresponds to
383 \fBconst\fR
384 and means that the property never changes during the lifetime of the object it belongs to, so no signal needs to be emitted\&.
385 \fBSD_BUS_VTABLE_PROPERTY_EMITS_CHANGE\fR
386 corresponds to
387 \fBtrue\fR
388 and means that the signal is emitted\&.
389 \fBSD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION\fR
390 corresponds to
391 \fBinvalidates\fR
392 and means that the signal is emitted, but the value is not included in the signal\&.
393 .RE
394 .PP
395 \fBSD_BUS_VTABLE_PROPERTY_EXPLICIT\fR
396 .RS 4
397 Mark this vtable property entry as requiring explicit request to for the value to be shown (generally because the value is large or slow to calculate)\&. This entry cannot be combined with
398 \fBSD_BUS_VTABLE_PROPERTY_EMITS_CHANGE\fR, and will not be shown in property listings by default (e\&.g\&.
399 \fBbusctl introspect\fR)\&. This corresponds to the
400 \fBorg\&.freedesktop\&.systemd1\&.Explicit\fR
401 annotation in introspection data\&.
402 .RE
403 .PP
404 \fBSD_BUS_VTABLE_SENSITIVE\fR
405 .RS 4
406 Mark this vtable method entry as processing sensitive data\&. When set, incoming method call messages and their outgoing reply messages are marked as sensitive using
407 \fBsd_bus_message_sensitive\fR(3), so that they are erased from memory when freed\&.
408 .RE
409 .PP
410 \fBSD_BUS_VTABLE_ABSOLUTE_OFFSET\fR
411 .RS 4
412 Mark this vtable method or property entry so that the user data pointer passed to its associated handler functions is determined slightly differently: instead of adding the offset parameter of the entry to the user data pointer specified during vtable registration, the offset is passed directly, converted to a pointer, without taking the user data pointer specified during vtable registration into account\&.
413 .RE
414 .PP
415 \fBSD_BUS_VTABLE_CAPABILITY(\fR\fB\fIcapability\fR\fR\fB)\fR
416 .RS 4
417 Access to this vtable entry will be allowed if the calling process has the capability
418 \fIcapability\fR, as described in
419 \fBsd_bus_query_sender_privilege\fR(3)\&. If used for
420 \fBSD_BUS_VTABLE_START()\fR, provides a default for all entries in the array\&. If not specified, either for an individual entry or the whole array,
421 \fBCAP_SYS_ADMIN\fR
422 is checked by default\&. See
423 \fBcapabilities\fR(7)
424 for information about capabilities\&.
425 .sp
426 Note that vtable entries may be marked as unprivileged and the whole bus may be marked as trusted, see the discussion of
427 \fBSD_BUS_VTABLE_UNPRIVILEGED\fR
428 below\&.
429 .RE
430 .PP
431 \fBSD_BUS_VTABLE_UNPRIVILEGED\fR
432 .RS 4
433 Mark this vtable entry as unprivileged\&. Access to privileged entries is limited to users with appropriate capabilities as described above\&. In practice many vtable entries are marked as unprivileged, and either are open to everyone, or the decision whether to allow access is taken later, e\&.g\&. by delegating to
434 \m[blue]\fBpolkit\fR\m[]\&\s-2\u[2]\d\s+2\&.
435 .sp
436 The whole bus may be marked as trusted, in which case annotations at the entry level are ignored, see
437 \fBsd_bus_set_trusted\fR(3)\&.
438 .sp
439 When
440 \fInot\fR
441 specified, the
442 \fBorg\&.freedesktop\&.systemd1\&.Privileged\fR
443 annotation with value
444 "true"
445 will be shown in introspection data\&.
446 .sp
447 \fBSD_BUS_VTABLE_UNPRIVILEGED\fR
448 may not be applied to read\-only properties, but read access (to both read\-only and writable properties) is always unrestricted\&.
449 .sp
450 Note that this page describes checks implemented in the D\-Bus client\&. The D\-Bus server has an additional policy that may permit or deny connections, see "CONFIGURATION FILE" in
451 \fBdbus-daemon\fR(1)\&.
452 .RE
453 .SH "EXAMPLES"
454 .PP
455 \fBExample\ \&1.\ \&Create a simple listener on the bus\fR
456 .sp
457 .if n \{\
458 .RS 4
459 .\}
460 .nf
461 /* SPDX\-License\-Identifier: MIT\-0 */
462
463 #define _GNU_SOURCE 1
464 #include <errno\&.h>
465 #include <stdbool\&.h>
466 #include <stddef\&.h>
467 #include <stdlib\&.h>
468 #include <stdio\&.h>
469 #include <systemd/sd\-bus\&.h>
470
471 #define _cleanup_(f) __attribute__((cleanup(f)))
472
473 typedef struct object {
474 char *name;
475 uint32_t number;
476 } object;
477
478 static int method(sd_bus_message *m, void *userdata, sd_bus_error *error) {
479 int r;
480
481 printf("Got called with userdata=%p\en", userdata);
482
483 if (sd_bus_message_is_method_call(m,
484 "org\&.freedesktop\&.systemd\&.VtableExample",
485 "Method4"))
486 return 1;
487
488 const char *string;
489 r = sd_bus_message_read(m, "s", &string);
490 if (r < 0) {
491 fprintf(stderr, "sd_bus_message_read() failed: %s\en", strerror(\-r));
492 return 0;
493 }
494
495 r = sd_bus_reply_method_return(m, "s", string);
496 if (r < 0) {
497 fprintf(stderr, "sd_bus_reply_method_return() failed: %s\en", strerror(\-r));
498 return 0;
499 }
500
501 return 1;
502 }
503
504 static const sd_bus_vtable vtable[] = {
505 SD_BUS_VTABLE_START(0),
506 SD_BUS_METHOD(
507 "Method1", "s", "s", method, 0),
508 SD_BUS_METHOD_WITH_NAMES_OFFSET(
509 "Method2",
510 "so", SD_BUS_PARAM(string) SD_BUS_PARAM(path),
511 "s", SD_BUS_PARAM(returnstring),
512 method, offsetof(object, number),
513 SD_BUS_VTABLE_DEPRECATED),
514 SD_BUS_METHOD_WITH_ARGS_OFFSET(
515 "Method3",
516 SD_BUS_ARGS("s", string, "o", path),
517 SD_BUS_RESULT("s", returnstring),
518 method, offsetof(object, number),
519 SD_BUS_VTABLE_UNPRIVILEGED),
520 SD_BUS_METHOD_WITH_ARGS(
521 "Method4",
522 SD_BUS_NO_ARGS,
523 SD_BUS_NO_RESULT,
524 method,
525 SD_BUS_VTABLE_UNPRIVILEGED),
526 SD_BUS_SIGNAL(
527 "Signal1",
528 "so",
529 0),
530 SD_BUS_SIGNAL_WITH_NAMES(
531 "Signal2",
532 "so", SD_BUS_PARAM(string) SD_BUS_PARAM(path),
533 0),
534 SD_BUS_SIGNAL_WITH_ARGS(
535 "Signal3",
536 SD_BUS_ARGS("s", string, "o", path),
537 0),
538 SD_BUS_WRITABLE_PROPERTY(
539 "AutomaticStringProperty", "s", NULL, NULL,
540 offsetof(object, name),
541 SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
542 SD_BUS_WRITABLE_PROPERTY(
543 "AutomaticIntegerProperty", "u", NULL, NULL,
544 offsetof(object, number),
545 SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
546 SD_BUS_VTABLE_END
547 };
548
549 int main(int argc, char **argv) {
550 _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
551 int r;
552
553 sd_bus_default(&bus);
554
555 object object = { \&.number = 666 };
556 object\&.name = strdup("name");
557 if (!object\&.name) {
558 fprintf(stderr, "OOM\en");
559 return EXIT_FAILURE;
560 }
561
562 r = sd_bus_add_object_vtable(bus, NULL,
563 "/org/freedesktop/systemd/VtableExample",
564 "org\&.freedesktop\&.systemd\&.VtableExample",
565 vtable,
566 &object);
567 if (r < 0) {
568 fprintf(stderr, "sd_bus_add_object_vtable() failed: %s\en", strerror(\-r));
569 return EXIT_FAILURE;
570 }
571
572 r = sd_bus_request_name(bus,
573 "org\&.freedesktop\&.systemd\&.VtableExample",
574 0);
575 if (r < 0) {
576 fprintf(stderr, "sd_bus_request_name() failed: %s\en", strerror(\-r));
577 return EXIT_FAILURE;
578 }
579
580 for (;;) {
581 r = sd_bus_wait(bus, UINT64_MAX);
582 if (r < 0) {
583 fprintf(stderr, "sd_bus_wait() failed: %s\en", strerror(\-r));
584 return EXIT_FAILURE;
585 }
586
587 r = sd_bus_process(bus, NULL);
588 if (r < 0) {
589 fprintf(stderr, "sd_bus_process() failed: %s\en", strerror(\-r));
590 return EXIT_FAILURE;
591 }
592 }
593
594 r = sd_bus_release_name(bus, "org\&.freedesktop\&.systemd\&.VtableExample");
595 if (r < 0) {
596 fprintf(stderr, "sd_bus_release_name() failed: %s\en", strerror(\-r));
597 return EXIT_FAILURE;
598 }
599
600 free(object\&.name);
601
602 return 0;
603 }
604 .fi
605 .if n \{\
606 .RE
607 .\}
608 .PP
609 This creates a simple client on the bus (the user bus, when run as normal user)\&. We may use the D\-Bus
610 \fBorg\&.freedesktop\&.DBus\&.Introspectable\&.Introspect\fR
611 call to acquire the XML description of the interface:
612 .sp
613 .if n \{\
614 .RS 4
615 .\}
616 .nf
617 <!DOCTYPE node PUBLIC "\-//freedesktop//DTD D\-BUS Object Introspection 1\&.0//EN"
618 "https://www\&.freedesktop\&.org/standards/dbus/1\&.0/introspect\&.dtd">
619 <!\-\- SPDX\-License\-Identifier: LGPL\-2\&.1\-or\-later \-\->
620 <node>
621 <interface name="org\&.freedesktop\&.DBus\&.Peer">
622 <method name="Ping"/>
623 <method name="GetMachineId">
624 <arg type="s" name="machine_uuid" direction="out"/>
625 </method>
626 </interface>
627 <interface name="org\&.freedesktop\&.DBus\&.Introspectable">
628 <method name="Introspect">
629 <arg name="xml_data" type="s" direction="out"/>
630 </method>
631 </interface>
632 <interface name="org\&.freedesktop\&.DBus\&.Properties">
633 <method name="Get">
634 <arg name="interface_name" direction="in" type="s"/>
635 <arg name="property_name" direction="in" type="s"/>
636 <arg name="value" direction="out" type="v"/>
637 </method>
638 <method name="GetAll">
639 <arg name="interface_name" direction="in" type="s"/>
640 <arg name="props" direction="out" type="a{sv}"/>
641 </method>
642 <method name="Set">
643 <arg name="interface_name" direction="in" type="s"/>
644 <arg name="property_name" direction="in" type="s"/>
645 <arg name="value" direction="in" type="v"/>
646 </method>
647 <signal name="PropertiesChanged">
648 <arg type="s" name="interface_name"/>
649 <arg type="a{sv}" name="changed_properties"/>
650 <arg type="as" name="invalidated_properties"/>
651 </signal>
652 </interface>
653 <interface name="org\&.freedesktop\&.systemd\&.VtableExample">
654 <method name="Method1">
655 <arg type="s" direction="in"/>
656 <arg type="s" direction="out"/>
657 </method>
658 <method name="Method2">
659 <arg type="s" name="string" direction="in"/>
660 <arg type="o" name="path" direction="in"/>
661 <arg type="s" name="returnstring" direction="out"/>
662 <annotation name="org\&.freedesktop\&.DBus\&.Deprecated" value="true"/>
663 </method>
664 <property name="AutomaticStringProperty" type="s" access="readwrite">
665 </property>
666 <property name="AutomaticIntegerProperty" type="u" access="readwrite">
667 <annotation name="org\&.freedesktop\&.DBus\&.Property\&.EmitsChangedSignal" value="invalidates"/>
668 </property>
669 </interface>
670 </node>
671
672 .fi
673 .if n \{\
674 .RE
675 .\}
676 .SH "RETURN VALUE"
677 .PP
678 On success,
679 \fBsd_bus_add_object_vtable()\fR
680 and
681 \fBsd_bus_add_fallback_vtable()\fR
682 return a non\-negative integer\&. On failure, they return a negative errno\-style error code\&.
683 .SS "Errors"
684 .PP
685 Returned errors may indicate the following problems:
686 .PP
687 \fB\-EINVAL\fR
688 .RS 4
689 One of the required parameters is
690 \fBNULL\fR
691 or invalid\&. A reserved D\-Bus interface was passed as the
692 \fIinterface\fR
693 parameter\&.
694 .RE
695 .PP
696 \fB\-ENOPKG\fR
697 .RS 4
698 The bus cannot be resolved\&.
699 .RE
700 .PP
701 \fB\-ECHILD\fR
702 .RS 4
703 The bus was created in a different process, library or module instance\&.
704 .RE
705 .PP
706 \fB\-ENOMEM\fR
707 .RS 4
708 Memory allocation failed\&.
709 .RE
710 .PP
711 \fB\-EPROTOTYPE\fR
712 .RS 4
713 \fBsd_bus_add_object_vtable()\fR
714 and
715 \fBsd_bus_add_fallback_vtable()\fR
716 have been both called for the same bus object path, which is not allowed\&.
717 .RE
718 .PP
719 \fB\-EEXIST\fR
720 .RS 4
721 This vtable has already been registered for this
722 \fIinterface\fR
723 and
724 \fIpath\fR\&.
725 .RE
726 .SH "NOTES"
727 .PP
728 Functions described here are available as a shared library, which can be compiled against and linked to with the
729 \fBlibsystemd\fR\ \&\fBpkg-config\fR(1)
730 file\&.
731 .PP
732 The code described here uses
733 \fBgetenv\fR(3), which is declared to be not multi\-thread\-safe\&. This means that the code calling the functions described here must not call
734 \fBsetenv\fR(3)
735 from a parallel thread\&. It is recommended to only do calls to
736 \fBsetenv()\fR
737 from an early phase of the program when no other threads have been started\&.
738 .SH "HISTORY"
739 .PP
740 \fBsd_bus_property_get_t()\fR,
741 \fBsd_bus_property_set_t()\fR,
742 \fBsd_bus_object_find_t()\fR,
743 \fBsd_bus_add_object()\fR,
744 \fBsd_bus_add_fallback()\fR,
745 \fBsd_bus_add_object_vtable()\fR,
746 \fBsd_bus_add_fallback_vtable()\fR, and
747 \fBsd_bus_add_filter()\fR
748 were added in version 221\&.
749 .SH "SEE ALSO"
750 .PP
751 \fBsd-bus\fR(3), \fBbusctl\fR(1), \fBsd_bus_emit_properties_changed\fR(3), \fBsd_bus_emit_object_added\fR(3)
752 .SH "NOTES"
753 .IP " 1." 4
754 D-Bus annotations
755 .RS 4
756 \%https://dbus.freedesktop.org/doc/dbus-specification.html#introspection-format
757 .RE
758 .IP " 2." 4
759 polkit
760 .RS 4
761 \%https://www.freedesktop.org/software/polkit/docs/latest/
762 .RE