Debian Codegraph @

upstream/debian-unstable/man3/sd_bus_call.3

raw
1 '\" t
2 .TH "SD_BUS_CALL" "3" "" "systemd 261~rc3" "sd_bus_call"
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_call, sd_bus_call_async \- Invoke a D\-Bus method call
24 .SH "SYNOPSIS"
25 .sp
26 .ft B
27 .nf
28 #include <systemd/sd\-bus\&.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'int\ sd_bus_call('u
34 .BI "int sd_bus_call(sd_bus\ *" "bus" ", sd_bus_message\ *" "m" ", uint64_t\ " "usec" ", sd_bus_error\ *" "ret_error" ", sd_bus_message\ **" "reply" ");"
35 .HP \w'int\ sd_bus_call_async('u
36 .BI "int sd_bus_call_async(sd_bus\ *" "bus" ", sd_bus_slot\ **" "slot" ", sd_bus_message\ *" "m" ", sd_bus_message_handler_t\ " "callback" ", void\ *" "userdata" ", uint64_t\ " "usec" ");"
37 .SH "DESCRIPTION"
38 .PP
39 \fBsd_bus_call()\fR
40 takes a complete bus message object and calls the corresponding D\-Bus method\&. On success, the response is stored in
41 \fIreply\fR\&.
42 \fIusec\fR
43 indicates the timeout in microseconds\&. If
44 \fIret_error\fR
45 is not
46 \fBNULL\fR
47 and
48 \fBsd_bus_call()\fR
49 fails (either because of an internal error or because it received a D\-Bus error reply),
50 \fIret_error\fR
51 is initialized to an instance of
52 sd_bus_error
53 describing the error\&.
54 .PP
55 \fBsd_bus_call_async()\fR
56 is like
57 \fBsd_bus_call()\fR
58 but works asynchronously\&. The
59 \fIcallback\fR
60 indicates the function to call when the response arrives\&. The
61 \fIuserdata\fR
62 pointer will be passed to the callback function, and may be chosen freely by the caller\&. If
63 \fIslot\fR
64 is not
65 \fBNULL\fR
66 and
67 \fBsd_bus_call_async()\fR
68 succeeds,
69 \fIslot\fR
70 is set to a slot object which can be used to cancel the method call at a later time using
71 \fBsd_bus_slot_unref\fR(3)\&. If
72 \fIslot\fR
73 is
74 \fBNULL\fR, the lifetime of the method call is bound to the lifetime of the bus object itself, and it cannot be cancelled independently\&. See
75 \fBsd_bus_slot_set_floating\fR(3)
76 for details\&.
77 \fIcallback\fR
78 is called when a reply arrives with the reply,
79 \fIuserdata\fR
80 and an
81 sd_bus_error
82 output parameter as its arguments\&. Unlike
83 \fBsd_bus_call()\fR, the
84 sd_bus_error
85 output parameter passed to the callback will be empty\&. To determine whether the method call succeeded, use
86 \fBsd_bus_message_is_method_error\fR(3)
87 on the reply message passed to the callback instead\&. If the callback returns zero and the
88 sd_bus_error
89 output parameter is still empty when the callback finishes, other handlers registered with functions such as
90 \fBsd_bus_add_filter\fR(3)
91 or
92 \fBsd_bus_add_match\fR(3)
93 are given a chance to process the message\&. If the callback returns a non\-zero value or the
94 sd_bus_error
95 output parameter is not empty when the callback finishes, no further processing of the message is done\&. Generally, you want to return zero from the callback to give other registered handlers a chance to process the reply as well\&. (Note that the
96 sd_bus_error
97 parameter is an output parameter of the callback function, not an input parameter; it can be used to propagate errors from the callback handler, it will not receive any error that was received as method reply\&.)
98 .PP
99 The message
100 \fIm\fR
101 passed to the callback is only borrowed, that is, the callback should not call
102 \fBsd_bus_message_unref\fR(3)
103 on it\&. If the callback wants to hold on to the message beyond the lifetime of the callback, it needs to call
104 \fBsd_bus_message_ref\fR(3)
105 to create a new reference\&.
106 .PP
107 If
108 \fIusec\fR
109 is zero, the default D\-Bus method call timeout is used\&. See
110 \fBsd_bus_get_method_call_timeout\fR(3)\&.
111 .SH "RETURN VALUE"
112 .PP
113 On success, these functions return a non\-negative integer\&. On failure, they return a negative errno\-style error code\&.
114 .SS "Errors"
115 .PP
116 When
117 \fBsd_bus_call()\fR
118 internally receives a D\-Bus error reply, it will set
119 \fIret_error\fR
120 if it is not
121 \fBNULL\fR, and will return a negative value mapped from the error reply, see
122 \fBsd_bus_error_get_errno\fR(3)\&.
123 .PP
124 Returned errors may indicate the following problems:
125 .PP
126 \fB\-EINVAL\fR
127 .RS 4
128 The input parameter
129 \fIm\fR
130 is
131 \fBNULL\fR\&.
132 .sp
133 The input parameter
134 \fIm\fR
135 is not a D\-Bus method call\&. To create a new D\-Bus method call, use
136 \fBsd_bus_message_new_method_call\fR(3)\&.
137 .sp
138 The input parameter
139 \fIm\fR
140 has the
141 \fBBUS_MESSAGE_NO_REPLY_EXPECTED\fR
142 flag set\&.
143 .sp
144 The input parameter
145 \fIerror\fR
146 is non\-\fBNULL\fR
147 but was not set to
148 \fBSD_BUS_ERROR_NULL\fR\&.
149 .RE
150 .PP
151 \fB\-ECHILD\fR
152 .RS 4
153 The bus connection was allocated in a parent process and is being reused in a child process after
154 \fBfork()\fR\&.
155 .RE
156 .PP
157 \fB\-ENOTCONN\fR
158 .RS 4
159 The input parameter
160 \fIbus\fR
161 is
162 \fBNULL\fR
163 or the bus is not connected\&.
164 .RE
165 .PP
166 \fB\-ECONNRESET\fR
167 .RS 4
168 The bus connection was closed while waiting for the response\&.
169 .RE
170 .PP
171 \fB\-ETIMEDOUT\fR
172 .RS 4
173 A response was not received within the given timeout\&.
174 .RE
175 .PP
176 \fB\-ELOOP\fR
177 .RS 4
178 The message
179 \fIm\fR
180 is addressed to its own client\&.
181 .RE
182 .PP
183 \fB\-ENOMEM\fR
184 .RS 4
185 Memory allocation failed\&.
186 .RE
187 .SH "NOTES"
188 .PP
189 Functions described here are available as a shared library, which can be compiled against and linked to with the
190 \fBlibsystemd\fR\ \&\fBpkg-config\fR(1)
191 file\&.
192 .PP
193 The code described here uses
194 \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
195 \fBsetenv\fR(3)
196 from a parallel thread\&. It is recommended to only do calls to
197 \fBsetenv()\fR
198 from an early phase of the program when no other threads have been started\&.
199 .SH "HISTORY"
200 .PP
201 \fBsd_bus_call()\fR
202 and
203 \fBsd_bus_call_async()\fR
204 were added in version 221\&.
205 .SH "SEE ALSO"
206 .PP
207 \fBsystemd\fR(1), \fBsd-bus\fR(3), \fBsd_bus_call_method\fR(3), \fBsd_bus_call_method_async\fR(3), \fBsd_bus_message_new_method_call\fR(3), \fBsd_bus_message_append\fR(3), \fBsd_bus_error\fR(3)