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-or-later -->
6 <refentry id="sd_bus_call_method"
7 xmlns:xi="http://www.w3.org/2001/XInclude">
10 <title>sd_bus_call_method</title>
11 <productname>systemd</productname>
15 <refentrytitle>sd_bus_call_method</refentrytitle>
16 <manvolnum>3</manvolnum>
20 <refname>sd_bus_call_method</refname>
21 <refname>sd_bus_call_methodv</refname>
22 <refname>sd_bus_call_method_async</refname>
23 <refname>sd_bus_call_method_asyncv</refname>
25 <refpurpose>Initialize a bus message object and invoke the corresponding D-Bus method call
31 <funcsynopsisinfo>#include <systemd/sd-bus.h></funcsynopsisinfo>
33 <xi:include href="sd_bus_add_match.xml" xpointer="sd_bus_message_handler_t"/>
36 <funcdef>int <function>sd_bus_call_method</function></funcdef>
37 <paramdef>sd_bus *<parameter>bus</parameter></paramdef>
38 <paramdef>const char *<parameter>destination</parameter></paramdef>
39 <paramdef>const char *<parameter>path</parameter></paramdef>
40 <paramdef>const char *<parameter>interface</parameter></paramdef>
41 <paramdef>const char *<parameter>member</parameter></paramdef>
42 <paramdef>sd_bus_error *<parameter>ret_error</parameter></paramdef>
43 <paramdef>sd_bus_message **<parameter>reply</parameter></paramdef>
44 <paramdef>const char *<parameter>types</parameter></paramdef>
45 <paramdef>...</paramdef>
49 <funcdef>int <function>sd_bus_call_methodv</function></funcdef>
50 <paramdef>sd_bus *<parameter>bus</parameter></paramdef>
51 <paramdef>const char *<parameter>destination</parameter></paramdef>
52 <paramdef>const char *<parameter>path</parameter></paramdef>
53 <paramdef>const char *<parameter>interface</parameter></paramdef>
54 <paramdef>const char *<parameter>member</parameter></paramdef>
55 <paramdef>sd_bus_error *<parameter>ret_error</parameter></paramdef>
56 <paramdef>sd_bus_message **<parameter>reply</parameter></paramdef>
57 <paramdef>const char *<parameter>types</parameter></paramdef>
58 <paramdef>va_list <parameter>ap</parameter></paramdef>
62 <funcdef>int <function>sd_bus_call_method_async</function></funcdef>
63 <paramdef>sd_bus *<parameter>bus</parameter></paramdef>
64 <paramdef>sd_bus_slot **<parameter>slot</parameter></paramdef>
65 <paramdef>const char *<parameter>destination</parameter></paramdef>
66 <paramdef>const char *<parameter>path</parameter></paramdef>
67 <paramdef>const char *<parameter>interface</parameter></paramdef>
68 <paramdef>const char *<parameter>member</parameter></paramdef>
69 <paramdef>sd_bus_message_handler_t <parameter>callback</parameter></paramdef>
70 <paramdef>void *<parameter>userdata</parameter></paramdef>
71 <paramdef>const char *<parameter>types</parameter></paramdef>
72 <paramdef>...</paramdef>
76 <funcdef>int <function>sd_bus_call_method_asyncv</function></funcdef>
77 <paramdef>sd_bus *<parameter>bus</parameter></paramdef>
78 <paramdef>sd_bus_slot **<parameter>slot</parameter></paramdef>
79 <paramdef>const char *<parameter>destination</parameter></paramdef>
80 <paramdef>const char *<parameter>path</parameter></paramdef>
81 <paramdef>const char *<parameter>interface</parameter></paramdef>
82 <paramdef>const char *<parameter>member</parameter></paramdef>
83 <paramdef>sd_bus_message_handler_t <parameter>callback</parameter></paramdef>
84 <paramdef>void *<parameter>userdata</parameter></paramdef>
85 <paramdef>const char *<parameter>types</parameter></paramdef>
86 <paramdef>va_list <parameter>ap</parameter></paramdef>
92 <title>Description</title>
94 <para><function>sd_bus_call_method()</function> is a convenience function for initializing a
95 bus message object and calling the corresponding D-Bus method. It combines the
96 <citerefentry><refentrytitle>sd_bus_message_new_method_call</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
97 <citerefentry><refentrytitle>sd_bus_message_append</refentrytitle><manvolnum>3</manvolnum></citerefentry> and
98 <citerefentry><refentrytitle>sd_bus_call</refentrytitle><manvolnum>3</manvolnum></citerefentry>
99 functions into a single function call.</para>
101 <para><function>sd_bus_call_method_async()</function> is a convenience function for initializing
102 a bus message object and calling the corresponding D-Bus method asynchronously. It combines the
103 <citerefentry><refentrytitle>sd_bus_message_new_method_call</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
104 <citerefentry><refentrytitle>sd_bus_message_append</refentrytitle><manvolnum>3</manvolnum></citerefentry> and
105 <citerefentry><refentrytitle>sd_bus_call_async</refentrytitle><manvolnum>3</manvolnum></citerefentry>
106 functions into a single function call.</para>
110 <title>Return Value</title>
112 <para>On success, these functions return a non-negative integer. On failure, they return a
113 negative errno-style error code.</para>
115 <refsect2 id='errors'>
116 <title>Errors</title>
118 <para>See the man pages of
119 <citerefentry><refentrytitle>sd_bus_message_new_method_call</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
120 <citerefentry><refentrytitle>sd_bus_message_append</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
121 <citerefentry><refentrytitle>sd_bus_call</refentrytitle><manvolnum>3</manvolnum></citerefentry> and
122 <citerefentry><refentrytitle>sd_bus_call_async</refentrytitle><manvolnum>3</manvolnum></citerefentry>
123 for a list of possible errors.</para>
127 <xi:include href="libsystemd-pkgconfig.xml" />
130 <title>Examples</title>
133 <title>Make a call to a D-Bus method that takes a single parameter</title>
135 <programlisting><xi:include href="print-unit-path-call-method.c" parse="text" /></programlisting>
136 <para>This defines a minimally useful program that will open a connection to the bus, call a method,
137 wait for the reply, and finally extract and print the answer. It does error handling and proper
138 memory management.</para>
143 <title>History</title>
144 <para><function>sd_bus_call_method()</function>,
145 <function>sd_bus_call_methodv()</function>,
146 <function>sd_bus_call_method_async()</function>, and
147 <function>sd_bus_call_method_asyncv()</function> were added in version 246.</para>
151 <title>See Also</title>
154 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
155 <citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
156 <citerefentry><refentrytitle>sd_bus_message_new_method_call</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
157 <citerefentry><refentrytitle>sd_bus_message_append</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
158 <citerefentry><refentrytitle>sd_bus_call</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
159 <citerefentry><refentrytitle>sd_bus_set_property</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
160 <citerefentry><refentrytitle>sd_bus_emit_signal</refentrytitle><manvolnum>3</manvolnum></citerefentry>