systemd/man/sd_bus_message_new_method_call.xml
2020-11-09 13:23:58 +09:00

173 lines
7.2 KiB
XML

<?xml version='1.0'?>
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
<!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
<refentry id="sd_bus_message_new_method_call"
xmlns:xi="http://www.w3.org/2001/XInclude">
<refentryinfo>
<title>sd_bus_message_new_method_call</title>
<productname>systemd</productname>
</refentryinfo>
<refmeta>
<refentrytitle>sd_bus_message_new_method_call</refentrytitle>
<manvolnum>3</manvolnum>
</refmeta>
<refnamediv>
<refname>sd_bus_message_new_method_call</refname>
<refname>sd_bus_message_new_method_return</refname>
<refpurpose>Create a method call message</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcsynopsisinfo>#include &lt;systemd/sd-bus.h&gt;</funcsynopsisinfo>
<funcprototype>
<funcdef>int <function>sd_bus_message_new_method_call</function></funcdef>
<paramdef>sd_bus *<parameter>bus</parameter></paramdef>
<paramdef>sd_bus_message **<parameter>m</parameter></paramdef>
<paramdef>const char *<parameter>destination</parameter></paramdef>
<paramdef>const char *<parameter>path</parameter></paramdef>
<paramdef>const char *<parameter>interface</parameter></paramdef>
<paramdef>const char *<parameter>member</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>int <function>sd_bus_message_new_method_return</function></funcdef>
<paramdef>sd_bus_message *<parameter>call</parameter></paramdef>
<paramdef>sd_bus_message **<parameter>m</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>Description</title>
<para>The <function>sd_bus_message_new_method_call()</function> function creates a new bus
message object that encapsulates a D-Bus method call, and returns it in the
<parameter>m</parameter> output parameter. The call will be made on the destination
<parameter>destination</parameter>, path <parameter>path</parameter>, on the interface
<parameter>interface</parameter>, member <parameter>member</parameter>.</para>
<para>Briefly, the <emphasis>destination</emphasis> is a dot-separated name that identifies a
service connected to the bus. The <emphasis>path</emphasis> is a slash-separated identifier of
an object within the destination that resembles a file system path. The meaning of this path is
defined by the destination. The <emphasis>interface</emphasis> is a dot-separated name that
resembles a Java interface name that identifies a group of methods and signals supported by the
object identified by path. Methods and signals are collectively called
<emphasis>members</emphasis> and are identified by a simple name composed of ASCII letters,
numbers, and underscores. See the <ulink
url="https://dbus.freedesktop.org/doc/dbus-tutorial.html#concepts">D-Bus Tutorial</ulink> for an
in-depth explanation.</para>
<para>The <parameter>destination</parameter> parameter may be <constant>NULL</constant>. The
<parameter>interface</parameter> parameter may be <constant>NULL</constant>, if the destination
has only a single member with the given name and there is no ambiguity if the interface name is
omitted.</para>
<para>Note that this is a low level interface. See
<citerefentry><refentrytitle>sd_bus_call_method</refentrytitle><manvolnum>3</manvolnum></citerefentry>
for a more convenient way of calling D-Bus methods.</para>
<para>The <function>sd_bus_message_new_method_return()</function> function creates a new bus
message object that is a reply to the method call <parameter>call</parameter> and returns it in
the <parameter>m</parameter> output parameter. The <parameter>call</parameter> parameter must be
a method call message. The sender of <parameter>call</parameter> is used as the destination.
</para>
</refsect1>
<refsect1>
<title>Return Value</title>
<para>On success, these functions return a non-negative integer. On failure, they return a
negative errno-style error code.</para>
<refsect2 id='errors'>
<title>Errors</title>
<para>Returned errors may indicate the following problems:</para>
<variablelist>
<varlistentry>
<term><constant>-EINVAL</constant></term>
<listitem><para>The output parameter <parameter>m</parameter> is
<constant>NULL</constant>.</para>
<para>The <parameter>destination</parameter> parameter is non-null and is not a valid D-Bus
service name (<literal>org.somewhere.Something</literal>), the <parameter>path</parameter>
parameter is not a valid D-Bus path (<literal>/an/object/path</literal>), the
<parameter>interface</parameter> parameter is non-null and is not a valid D-Bus interface
name (<literal>an.interface.name</literal>), or the <parameter>member</parameter> parameter
is not a valid D-Bus member (<literal>Name</literal>).</para>
<para>The <parameter>call</parameter> parameter is not a method call object.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><constant>-ENOTCONN</constant></term>
<listitem><para>The bus parameter <parameter>bus</parameter> is <constant>NULL</constant> or
the bus is not connected.</para></listitem>
</varlistentry>
<varlistentry>
<term><constant>-ENOMEM</constant></term>
<listitem><para>Memory allocation failed.</para></listitem>
</varlistentry>
<varlistentry>
<term><constant>-EPERM</constant></term>
<listitem>
<para>The <parameter>call</parameter> parameter is not sealed.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><constant>-EOPNOTSUPP</constant></term>
<listitem>
<para>The <parameter>call</parameter> message does not have a cookie.</para>
</listitem>
</varlistentry>
</variablelist>
</refsect2>
</refsect1>
<xi:include href="libsystemd-pkgconfig.xml" />
<refsect1>
<title>Examples</title>
<example>
<title>Make a call to a D-Bus method that takes a single parameter</title>
<programlisting><xi:include href="print-unit-path.c" parse="text" /></programlisting>
<para>This defines a minimally useful program that will open a connection to the bus, create a
message object, send it, wait for the reply, and finally extract and print the answer. It does
error handling and proper memory management.</para>
</example>
</refsect1>
<refsect1>
<title>See Also</title>
<para>
<citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_call</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_call_method</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_path_encode</refentrytitle><manvolnum>3</manvolnum></citerefentry>
</para>
</refsect1>
</refentry>