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-or-later -->
5
6<refentry id="sd_bus_message_new_method_call"
7          xmlns:xi="http://www.w3.org/2001/XInclude">
8
9  <refentryinfo>
10    <title>sd_bus_message_new_method_call</title>
11    <productname>systemd</productname>
12  </refentryinfo>
13
14  <refmeta>
15    <refentrytitle>sd_bus_message_new_method_call</refentrytitle>
16    <manvolnum>3</manvolnum>
17  </refmeta>
18
19  <refnamediv>
20    <refname>sd_bus_message_new_method_call</refname>
21    <refname>sd_bus_message_new_method_return</refname>
22
23    <refpurpose>Create a method call message</refpurpose>
24  </refnamediv>
25
26  <refsynopsisdiv>
27    <funcsynopsis>
28      <funcsynopsisinfo>#include &lt;systemd/sd-bus.h&gt;</funcsynopsisinfo>
29
30      <funcprototype>
31        <funcdef>int <function>sd_bus_message_new_method_call</function></funcdef>
32        <paramdef>sd_bus *<parameter>bus</parameter></paramdef>
33        <paramdef>sd_bus_message **<parameter>m</parameter></paramdef>
34        <paramdef>const char *<parameter>destination</parameter></paramdef>
35        <paramdef>const char *<parameter>path</parameter></paramdef>
36        <paramdef>const char *<parameter>interface</parameter></paramdef>
37        <paramdef>const char *<parameter>member</parameter></paramdef>
38      </funcprototype>
39
40      <funcprototype>
41        <funcdef>int <function>sd_bus_message_new_method_return</function></funcdef>
42        <paramdef>sd_bus_message *<parameter>call</parameter></paramdef>
43        <paramdef>sd_bus_message **<parameter>m</parameter></paramdef>
44      </funcprototype>
45    </funcsynopsis>
46  </refsynopsisdiv>
47
48  <refsect1>
49    <title>Description</title>
50
51    <para>The <function>sd_bus_message_new_method_call()</function> function creates a new bus
52    message object that encapsulates a D-Bus method call, and returns it in the
53    <parameter>m</parameter> output parameter. The call will be made on the destination
54    <parameter>destination</parameter>, path <parameter>path</parameter>, on the interface
55    <parameter>interface</parameter>, member <parameter>member</parameter>.</para>
56
57    <para>Briefly, the <emphasis>destination</emphasis> is a dot-separated name that identifies a
58    service connected to the bus. The <emphasis>path</emphasis> is a slash-separated identifier of
59    an object within the destination that resembles a file system path. The meaning of this path is
60    defined by the destination. The <emphasis>interface</emphasis> is a dot-separated name that
61    resembles a Java interface name that identifies a group of methods and signals supported by the
62    object identified by path. Methods and signals are collectively called
63    <emphasis>members</emphasis> and are identified by a simple name composed of ASCII letters,
64    numbers, and underscores. See the <ulink
65    url="https://dbus.freedesktop.org/doc/dbus-tutorial.html#concepts">D-Bus Tutorial</ulink> for an
66    in-depth explanation.</para>
67
68    <para>The <parameter>destination</parameter> parameter may be <constant>NULL</constant>. The
69    <parameter>interface</parameter> parameter may be <constant>NULL</constant>, if the destination
70    has only a single member with the given name and there is no ambiguity if the interface name is
71    omitted.</para>
72
73    <para>Note that this is a low level interface. See
74    <citerefentry><refentrytitle>sd_bus_call_method</refentrytitle><manvolnum>3</manvolnum></citerefentry>
75    for a more convenient way of calling D-Bus methods.</para>
76
77    <para>The <function>sd_bus_message_new_method_return()</function> function creates a new bus
78    message object that is a reply to the method call <parameter>call</parameter> and returns it in
79    the <parameter>m</parameter> output parameter. The <parameter>call</parameter> parameter must be
80    a method call message. The sender of <parameter>call</parameter> is used as the destination.
81    </para>
82  </refsect1>
83
84  <refsect1>
85    <title>Return Value</title>
86
87    <para>On success, these functions return a non-negative integer. On failure, they return a
88    negative errno-style error code.</para>
89
90    <refsect2 id='errors'>
91      <title>Errors</title>
92
93      <para>Returned errors may indicate the following problems:</para>
94
95      <variablelist>
96        <varlistentry>
97          <term><constant>-EINVAL</constant></term>
98
99          <listitem><para>The output parameter <parameter>m</parameter> is
100          <constant>NULL</constant>.</para>
101
102          <para>The <parameter>destination</parameter> parameter is non-null and is not a valid D-Bus
103          service name (<literal>org.somewhere.Something</literal>), the <parameter>path</parameter>
104          parameter is not a valid D-Bus path (<literal>/an/object/path</literal>), the
105          <parameter>interface</parameter> parameter is non-null and is not a valid D-Bus interface
106          name (<literal>an.interface.name</literal>), or the <parameter>member</parameter> parameter
107          is not a valid D-Bus member (<literal>Name</literal>).</para>
108
109          <para>The <parameter>call</parameter> parameter is not a method call object.</para>
110          </listitem>
111        </varlistentry>
112
113        <varlistentry>
114          <term><constant>-ENOTCONN</constant></term>
115
116          <listitem><para>The bus parameter <parameter>bus</parameter> is <constant>NULL</constant> or
117          the bus is not connected.</para></listitem>
118        </varlistentry>
119
120        <varlistentry>
121          <term><constant>-ENOMEM</constant></term>
122
123          <listitem><para>Memory allocation failed.</para></listitem>
124        </varlistentry>
125
126        <varlistentry>
127          <term><constant>-EPERM</constant></term>
128
129          <listitem>
130            <para>The <parameter>call</parameter> parameter is not sealed.</para>
131          </listitem>
132        </varlistentry>
133
134        <varlistentry>
135          <term><constant>-EOPNOTSUPP</constant></term>
136
137          <listitem>
138            <para>The <parameter>call</parameter> message does not have a cookie.</para>
139          </listitem>
140        </varlistentry>
141      </variablelist>
142    </refsect2>
143  </refsect1>
144
145  <xi:include href="libsystemd-pkgconfig.xml" />
146
147  <refsect1>
148    <title>Examples</title>
149
150    <example>
151      <title>Make a call to a D-Bus method that takes a single parameter</title>
152
153      <programlisting><xi:include href="print-unit-path.c" parse="text" /></programlisting>
154      <para>This defines a minimally useful program that will open a connection to the bus, create a
155      message object, send it, wait for the reply, and finally extract and print the answer. It does
156      error handling and proper memory management.</para>
157    </example>
158  </refsect1>
159
160  <refsect1>
161    <title>See Also</title>
162
163    <para>
164      <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
165      <citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
166      <citerefentry><refentrytitle>sd_bus_call</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
167      <citerefentry><refentrytitle>sd_bus_call_method</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
168      <citerefentry><refentrytitle>sd_bus_path_encode</refentrytitle><manvolnum>3</manvolnum></citerefentry>
169    </para>
170  </refsect1>
171
172</refentry>
173