]>
Commit | Line | Data |
---|---|---|
953ee402 DDM |
1 | <?xml version='1.0'?> |
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 | ||
6 | <refentry id="sd_bus_call" | |
7 | xmlns:xi="http://www.w3.org/2001/XInclude"> | |
8 | ||
9 | <refentryinfo> | |
10 | <title>sd_bus_call</title> | |
11 | <productname>systemd</productname> | |
12 | </refentryinfo> | |
13 | ||
14 | <refmeta> | |
15 | <refentrytitle>sd_bus_call</refentrytitle> | |
16 | <manvolnum>3</manvolnum> | |
17 | </refmeta> | |
18 | ||
19 | <refnamediv> | |
20 | <refname>sd_bus_call</refname> | |
21 | <refname>sd_bus_call_async</refname> | |
22 | ||
23 | <refpurpose>Invoke a D-Bus method call</refpurpose> | |
24 | </refnamediv> | |
25 | ||
26 | <refsynopsisdiv> | |
27 | <funcsynopsis> | |
28 | <funcsynopsisinfo>#include <systemd/sd-bus.h></funcsynopsisinfo> | |
29 | ||
30 | <funcprototype> | |
31 | <funcdef>int <function>sd_bus_call</function></funcdef> | |
32 | <paramdef>sd_bus *<parameter>bus</parameter></paramdef> | |
33 | <paramdef>sd_bus_message *<parameter>m</parameter></paramdef> | |
34 | <paramdef>uint64_t <parameter>usec</parameter></paramdef> | |
35 | <paramdef>sd_bus_error *<parameter>ret_error</parameter></paramdef> | |
36 | <paramdef>sd_bus_message **<parameter>reply</parameter></paramdef> | |
37 | </funcprototype> | |
38 | ||
39 | <funcprototype> | |
40 | <funcdef>int <function>sd_bus_call_async</function></funcdef> | |
41 | <paramdef>sd_bus *<parameter>bus</parameter></paramdef> | |
42 | <paramdef>sd_bus_slot **<parameter>slot</parameter></paramdef> | |
43 | <paramdef>sd_bus_message *<parameter>m</parameter></paramdef> | |
44 | <paramdef>sd_bus_message_handler_t <parameter>callback</parameter></paramdef> | |
45 | <paramdef>void *<parameter>userdata</parameter></paramdef> | |
46 | <paramdef>uint64_t <parameter>usec</parameter></paramdef> | |
47 | </funcprototype> | |
48 | </funcsynopsis> | |
49 | </refsynopsisdiv> | |
50 | ||
51 | <refsect1> | |
52 | <title>Description</title> | |
53 | ||
54 | <para><function>sd_bus_call()</function> takes a complete bus message object and calls the | |
47203ed0 | 55 | corresponding D-Bus method. On success, the response is stored in <parameter>reply</parameter>. |
953ee402 DDM |
56 | <parameter>usec</parameter> indicates the timeout in microseconds. If |
57 | <parameter>ret_error</parameter> is not <constant>NULL</constant> and | |
47203ed0 DDM |
58 | <function>sd_bus_call()</function> fails (either because of an internal error or because it |
59 | received a D-Bus error reply), <parameter>ret_error</parameter> is initialized to an instance of | |
60 | <structname>sd_bus_error</structname> describing the error.</para> | |
953ee402 DDM |
61 | |
62 | <para><function>sd_bus_call_async()</function> is like <function>sd_bus_call()</function> but | |
47203ed0 DDM |
63 | works asynchronously. The <parameter>callback</parameter> indicates the function to call when |
64 | the response arrives. The <parameter>userdata</parameter> pointer will be passed to the callback | |
65 | function, and may be chosen freely by the caller. If <parameter>slot</parameter> is not | |
66 | <constant>NULL</constant> and <function>sd_bus_call_async()</function> succeeds, | |
953ee402 DDM |
67 | <parameter>slot</parameter> is set to a slot object which can be used to cancel the method call |
68 | at a later time using | |
69 | <citerefentry><refentrytitle>sd_bus_slot_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>. | |
70 | If <parameter>slot</parameter> is <constant>NULL</constant>, the lifetime of the method call is | |
71 | bound to the lifetime of the bus object itself, and it cannot be cancelled independently. See | |
72 | <citerefentry><refentrytitle>sd_bus_slot_set_floating</refentrytitle><manvolnum>3</manvolnum></citerefentry> | |
47203ed0 DDM |
73 | for details. <parameter>callback</parameter> is called when a reply arrives with the reply, |
74 | <parameter>userdata</parameter> and an <structname>sd_bus_error</structname> output | |
75 | parameter as its arguments. Unlike <function>sd_bus_call()</function>, the | |
76 | <structname>sd_bus_error</structname> output parameter passed to the callback will be empty. To | |
77 | determine whether the method call succeeded, use | |
953ee402 | 78 | <citerefentry><refentrytitle>sd_bus_message_is_method_error</refentrytitle><manvolnum>3</manvolnum></citerefentry> |
47203ed0 DDM |
79 | on the reply message passed to the callback instead. If the callback returns zero and the |
80 | <structname>sd_bus_error</structname> output parameter is still empty when the callback | |
81 | inishes, other handlers registered with functions such as | |
82 | <citerefentry><refentrytitle>sd_bus_add_filter</refentrytitle><manvolnum>3</manvolnum></citerefentry> or | |
83 | <citerefentry><refentrytitle>sd_bus_add_match</refentrytitle><manvolnum>3</manvolnum></citerefentry> | |
84 | are given a chance to process the message. If the callback returns a non-zero value or the | |
85 | <structname>sd_bus_error</structname> output parameter is not empty when the callback finishes, | |
86 | no further processing of the message is done. Generally, you want to return zero from the | |
87 | callback to give other registered handlers a chance to process the reply as well.</para> | |
953ee402 | 88 | |
cc46b9d9 DDM |
89 | <para>If <parameter>usec</parameter> is zero, the default D-Bus method call timeout is used. See |
90 | <citerefentry><refentrytitle>sd_bus_get_method_call_timeout</refentrytitle><manvolnum>3</manvolnum></citerefentry>. | |
953ee402 DDM |
91 | </para> |
92 | ||
93 | </refsect1> | |
94 | ||
95 | <refsect1> | |
96 | <title>Return Value</title> | |
97 | ||
98 | <para>On success, these functions return a non-negative integer. On failure, they return a | |
99 | negative errno-style error code.</para> | |
100 | ||
101 | <refsect2 id='errors'> | |
102 | <title>Errors</title> | |
103 | ||
104 | <para>Returned errors may indicate the following problems:</para> | |
105 | ||
106 | <variablelist> | |
107 | <varlistentry> | |
108 | <term><constant>-EINVAL</constant></term> | |
109 | ||
110 | <listitem><para>The input parameter <parameter>m</parameter> is <constant>NULL</constant>. | |
111 | </para></listitem> | |
112 | ||
113 | <listitem><para>The input parameter <parameter>m</parameter> is not a D-Bus method call. | |
114 | To create a new D-Bus method call, use | |
115 | <citerefentry><refentrytitle>sd_bus_message_new_method_call</refentrytitle><manvolnum>3</manvolnum></citerefentry>. | |
116 | </para></listitem> | |
117 | ||
118 | <listitem><para>The input parameter <parameter>m</parameter> has the | |
119 | <constant>BUS_MESSAGE_NO_REPLY_EXPECTED</constant> flag set.</para></listitem> | |
120 | ||
121 | <listitem><para>The input parameter <parameter>error</parameter> is | |
122 | non-<constant>NULL</constant> but was not set to <constant>SD_BUS_ERROR_NULL</constant>. | |
123 | </para></listitem> | |
124 | </varlistentry> | |
125 | ||
126 | <varlistentry> | |
127 | <term><constant>-ECHILD</constant></term> | |
128 | ||
129 | <listitem><para>The bus connection was allocated in a parent process and is being reused | |
130 | in a child process after <function>fork()</function>.</para></listitem> | |
131 | </varlistentry> | |
132 | ||
133 | <varlistentry> | |
134 | <term><constant>-ENOTCONN</constant></term> | |
135 | ||
b0f4c02e DDM |
136 | <listitem><para>The input parameter <parameter>bus</parameter> is |
137 | <constant>NULL</constant> or the bus is not connected.</para></listitem> | |
953ee402 DDM |
138 | </varlistentry> |
139 | ||
140 | <varlistentry> | |
141 | <term><constant>-ECONNRESET</constant></term> | |
142 | ||
b0f4c02e | 143 | <listitem><para>The bus connection was closed while waiting for the response. |
953ee402 DDM |
144 | </para></listitem> |
145 | </varlistentry> | |
146 | ||
147 | <varlistentry> | |
148 | <term><constant>-ETIMEDOUT</constant></term> | |
149 | ||
150 | <listitem><para>A response was not received within the given timeout.</para></listitem> | |
151 | </varlistentry> | |
152 | ||
153 | <varlistentry> | |
154 | <term><constant>-ELOOP</constant></term> | |
155 | ||
156 | <listitem><para>The message <parameter>m</parameter> is addressed to its own client. | |
157 | </para></listitem> | |
158 | </varlistentry> | |
159 | ||
160 | <varlistentry> | |
161 | <term><constant>-ENOMEM</constant></term> | |
162 | ||
163 | <listitem><para>Memory allocation failed.</para></listitem> | |
164 | </varlistentry> | |
165 | </variablelist> | |
166 | </refsect2> | |
167 | </refsect1> | |
168 | ||
169 | <xi:include href="libsystemd-pkgconfig.xml" /> | |
170 | ||
171 | <refsect1> | |
172 | <title>See Also</title> | |
173 | ||
174 | <para> | |
175 | <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, | |
176 | <citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
177 | <citerefentry><refentrytitle>sd_bus_call_method</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
178 | <citerefentry><refentrytitle>sd_bus_call_method_async</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
179 | <citerefentry><refentrytitle>sd_bus_message_new_method_call</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
180 | <citerefentry><refentrytitle>sd_bus_message_append</refentrytitle><manvolnum>3</manvolnum></citerefentry> | |
181 | </para> | |
182 | </refsect1> | |
183 | ||
184 | </refentry> |