]>
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 | |
55 | corresponding D-Bus method. The response is stored in <parameter>reply</parameter>. | |
56 | <parameter>usec</parameter> indicates the timeout in microseconds. If | |
57 | <parameter>ret_error</parameter> is not <constant>NULL</constant> and | |
58 | <function>sd_bus_call()</function> returns an error, <parameter>ret_error</parameter> is | |
59 | initialized to an instance of <structname>sd_bus_error</structname> describing the error.</para> | |
60 | ||
61 | <para><function>sd_bus_call_async()</function> is like <function>sd_bus_call()</function> but | |
62 | works asynchronously. The <parameter>callback</parameter> shall reference a function to call | |
63 | when the event source is triggered. The <parameter>userdata</parameter> pointer will be passed | |
64 | to the callback function, and may be chosen freely by the caller. If <parameter>slot</parameter> | |
65 | is not <constant>NULL</constant> and <function>sd_bus_call_async()</function> succeeds, | |
66 | <parameter>slot</parameter> is set to a slot object which can be used to cancel the method call | |
67 | at a later time using | |
68 | <citerefentry><refentrytitle>sd_bus_slot_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>. | |
69 | If <parameter>slot</parameter> is <constant>NULL</constant>, the lifetime of the method call is | |
70 | bound to the lifetime of the bus object itself, and it cannot be cancelled independently. See | |
71 | <citerefentry><refentrytitle>sd_bus_slot_set_floating</refentrytitle><manvolnum>3</manvolnum></citerefentry> | |
72 | for details. The <parameter>callback</parameter> function is called when the response arrives | |
73 | and receives the response, <parameter>userdata</parameter> and a | |
74 | <structname>sd_bus_error</structname> object as its arguments. The | |
75 | <structname>sd_bus_error</structname> object is unused here and should be ignored. If | |
76 | <parameter>callback</parameter> returns a non-negative integer when called, a debug message is | |
77 | logged along with details about the response.</para> | |
78 | ||
79 | <para>To determine whether the method call succeeded, use | |
80 | <citerefentry><refentrytitle>sd_bus_message_is_method_error</refentrytitle><manvolnum>3</manvolnum></citerefentry> | |
81 | on the reply object returned by <function>sd_bus_call()</function> or passed to the callback of | |
82 | <function>sd_bus_call_async()</function>.</para> | |
83 | ||
cc46b9d9 DDM |
84 | <para>If <parameter>usec</parameter> is zero, the default D-Bus method call timeout is used. See |
85 | <citerefentry><refentrytitle>sd_bus_get_method_call_timeout</refentrytitle><manvolnum>3</manvolnum></citerefentry>. | |
953ee402 DDM |
86 | </para> |
87 | ||
88 | </refsect1> | |
89 | ||
90 | <refsect1> | |
91 | <title>Return Value</title> | |
92 | ||
93 | <para>On success, these functions return a non-negative integer. On failure, they return a | |
94 | negative errno-style error code.</para> | |
95 | ||
96 | <refsect2 id='errors'> | |
97 | <title>Errors</title> | |
98 | ||
99 | <para>Returned errors may indicate the following problems:</para> | |
100 | ||
101 | <variablelist> | |
102 | <varlistentry> | |
103 | <term><constant>-EINVAL</constant></term> | |
104 | ||
105 | <listitem><para>The input parameter <parameter>m</parameter> is <constant>NULL</constant>. | |
106 | </para></listitem> | |
107 | ||
108 | <listitem><para>The input parameter <parameter>m</parameter> is not a D-Bus method call. | |
109 | To create a new D-Bus method call, use | |
110 | <citerefentry><refentrytitle>sd_bus_message_new_method_call</refentrytitle><manvolnum>3</manvolnum></citerefentry>. | |
111 | </para></listitem> | |
112 | ||
113 | <listitem><para>The input parameter <parameter>m</parameter> has the | |
114 | <constant>BUS_MESSAGE_NO_REPLY_EXPECTED</constant> flag set.</para></listitem> | |
115 | ||
116 | <listitem><para>The input parameter <parameter>error</parameter> is | |
117 | non-<constant>NULL</constant> but was not set to <constant>SD_BUS_ERROR_NULL</constant>. | |
118 | </para></listitem> | |
119 | </varlistentry> | |
120 | ||
121 | <varlistentry> | |
122 | <term><constant>-ECHILD</constant></term> | |
123 | ||
124 | <listitem><para>The bus connection was allocated in a parent process and is being reused | |
125 | in a child process after <function>fork()</function>.</para></listitem> | |
126 | </varlistentry> | |
127 | ||
128 | <varlistentry> | |
129 | <term><constant>-ENOTCONN</constant></term> | |
130 | ||
131 | <listitem><para>The bus parameter <parameter>bus</parameter> is <constant>NULL</constant> | |
132 | or the bus is not connected.</para></listitem> | |
133 | </varlistentry> | |
134 | ||
135 | <varlistentry> | |
136 | <term><constant>-ECONNRESET</constant></term> | |
137 | ||
138 | <listitem><para>The client was disconnected while waiting for the response. | |
139 | </para></listitem> | |
140 | </varlistentry> | |
141 | ||
142 | <varlistentry> | |
143 | <term><constant>-ETIMEDOUT</constant></term> | |
144 | ||
145 | <listitem><para>A response was not received within the given timeout.</para></listitem> | |
146 | </varlistentry> | |
147 | ||
148 | <varlistentry> | |
149 | <term><constant>-ELOOP</constant></term> | |
150 | ||
151 | <listitem><para>The message <parameter>m</parameter> is addressed to its own client. | |
152 | </para></listitem> | |
153 | </varlistentry> | |
154 | ||
155 | <varlistentry> | |
156 | <term><constant>-ENOMEM</constant></term> | |
157 | ||
158 | <listitem><para>Memory allocation failed.</para></listitem> | |
159 | </varlistentry> | |
160 | </variablelist> | |
161 | </refsect2> | |
162 | </refsect1> | |
163 | ||
164 | <xi:include href="libsystemd-pkgconfig.xml" /> | |
165 | ||
166 | <refsect1> | |
167 | <title>See Also</title> | |
168 | ||
169 | <para> | |
170 | <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, | |
171 | <citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
172 | <citerefentry><refentrytitle>sd_bus_call_method</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
173 | <citerefentry><refentrytitle>sd_bus_call_method_async</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
174 | <citerefentry><refentrytitle>sd_bus_message_new_method_call</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
175 | <citerefentry><refentrytitle>sd_bus_message_append</refentrytitle><manvolnum>3</manvolnum></citerefentry> | |
176 | </para> | |
177 | </refsect1> | |
178 | ||
179 | </refentry> |