309 lines
7.8 KiB
HTML
309 lines
7.8 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of SD_BUS_MESSAGE_NEW_METHOD_CALL</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>SD_BUS_MESSAGE_NEW_METHOD_CALL</H1>
|
|
Section: sd_bus_message_new_method_call (3)<BR>Updated: <BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
sd_bus_message_new_method_call, sd_bus_message_new_method_return - Create a method call message
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<P>
|
|
<B>
|
|
</B><PRE>
|
|
#include <<A HREF="file:///usr/include/systemd/sd-bus.h">systemd/sd-bus.h</A>>
|
|
</PRE>
|
|
|
|
|
|
<DL COMPACT>
|
|
<DT id="1">
|
|
<B>int sd_bus_message_new_method_call(sd_bus *</B><I>bus</I><B>, sd_bus_message **</B><I>m</I><B>, const char *</B><I>destination</I><B>, const char *</B><I>path</I><B>, const char *</B><I>interface</I><B>, const char *</B><I>member</I><B>);</B>
|
|
|
|
<DT id="2">
|
|
<B>int sd_bus_message_new_method_return(sd_bus_message *</B><I>call</I><B>, sd_bus_message **</B><I>m</I><B>);</B>
|
|
|
|
</DL>
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
<P>
|
|
|
|
<DD>The
|
|
<B>sd_bus_message_new_method_call()</B>
|
|
function creates a new bus message object that encapsulates a D-Bus method call, and returns it in the
|
|
<I>m</I>
|
|
output parameter. The call will be made on the destination
|
|
<I>destination</I>, path
|
|
<I>path</I>, on the interface
|
|
<I>interface</I>, member
|
|
<I>member</I>.
|
|
<P>
|
|
|
|
Briefly, the
|
|
<I>destination</I>
|
|
is a dot-separated name that identifies a service connected to the bus. The
|
|
<I>path</I>
|
|
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
|
|
<I>interface</I>
|
|
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
|
|
<I>members</I>
|
|
and are identified by a simple name composed of ASCII letters, numbers, and underscores. See the
|
|
m[blue]<B>D-Bus Tutorial</B>m[]<FONT SIZE="-2">[1]</FONT>
|
|
for an in-depth explanation.
|
|
<P>
|
|
|
|
The
|
|
<I>destination</I>
|
|
parameter may be
|
|
<B>NULL</B>. The
|
|
<I>interface</I>
|
|
parameter may be
|
|
<B>NULL</B>, if the destination has only a single member with the given name and there is no ambiguity if the interface name is omitted.
|
|
<P>
|
|
|
|
The
|
|
<B>sd_bus_message_new_method_call()</B>
|
|
function creates a new bus message object that is a reply to the method call
|
|
<I>call</I>
|
|
and returns it in the
|
|
<I>m</I>
|
|
output parameter. The
|
|
<I>call</I>
|
|
parameter must be a method call message. The sender of
|
|
<I>call</I>
|
|
is used as the destination.
|
|
<A NAME="lbAE"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
<P>
|
|
|
|
This function returns 0 if the message object was successfully created, and a negative errno-style error code otherwise.
|
|
<A NAME="lbAF"> </A>
|
|
<H3>Errors</H3>
|
|
|
|
<P>
|
|
|
|
Returned errors may indicate the following problems:
|
|
<P>
|
|
|
|
<B>-EINVAL</B>
|
|
<DL COMPACT><DT id="3"><DD>
|
|
The output parameter
|
|
<I>m</I>
|
|
is
|
|
<B>NULL</B>.
|
|
<P>
|
|
The
|
|
<I>destination</I>
|
|
parameter is non-null and is not a valid D-Bus service name ("org.somewhere.Something"), the
|
|
<I>path</I>
|
|
parameter is not a valid D-Bus path ("/an/object/path"), the
|
|
<I>interface</I>
|
|
parameter is non-null and is not a valid D-Bus interface name ("an.interface.name"), or the
|
|
<I>member</I>
|
|
parameter is not a valid D-Bus member ("Name").
|
|
<P>
|
|
The
|
|
<I>call</I>
|
|
parameter is not a method call object.
|
|
</DL>
|
|
|
|
<P>
|
|
|
|
<B>-ENOTCONN</B>
|
|
<DL COMPACT><DT id="4"><DD>
|
|
The bus parameter
|
|
<I>bus</I>
|
|
is
|
|
<B>NULL</B>
|
|
or the bus is not connected.
|
|
</DL>
|
|
|
|
<P>
|
|
|
|
<B>-ENOMEM</B>
|
|
<DL COMPACT><DT id="5"><DD>
|
|
Memory allocation failed.
|
|
</DL>
|
|
|
|
<P>
|
|
|
|
<B>-EPERM</B>
|
|
<DL COMPACT><DT id="6"><DD>
|
|
The
|
|
<I>call</I>
|
|
parameter is not sealed.
|
|
</DL>
|
|
|
|
<P>
|
|
|
|
<B>-EOPNOTSUPP</B>
|
|
<DL COMPACT><DT id="7"><DD>
|
|
The
|
|
<I>call</I>
|
|
message does not have a cookie.
|
|
</DL>
|
|
|
|
<A NAME="lbAG"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
<P>
|
|
|
|
These APIs are implemented as a shared library, which can be compiled and linked to with the
|
|
<B>libsystemd</B> <B><A HREF="/cgi-bin/man/man2html?1+pkg-config">pkg-config</A></B>(1)
|
|
file.
|
|
<A NAME="lbAH"> </A>
|
|
<H2>EXAMPLES</H2>
|
|
|
|
<P>
|
|
|
|
<B>Example 1. Make a call to a D-Bus method that takes a single parameter</B>
|
|
<P>
|
|
<DL COMPACT><DT id="8"><DD>
|
|
|
|
|
|
|
|
<PRE>
|
|
#include <<A HREF="file:///usr/include/stdio.h">stdio.h</A>>
|
|
#include <<A HREF="file:///usr/include/string.h">string.h</A>>
|
|
#include <<A HREF="file:///usr/include/unistd.h">unistd.h</A>>
|
|
#include <<A HREF="file:///usr/include/sys/types.h">sys/types.h</A>>
|
|
|
|
#include <<A HREF="file:///usr/include/systemd/sd-bus.h">systemd/sd-bus.h</A>>
|
|
#define _cleanup_(f) __attribute__((cleanup(f)))
|
|
|
|
/* This is equivalent to:
|
|
* busctl call org.freedesktop.systemd1 /org/freedesktop/systemd1 \
|
|
* org.freedesktop.systemd1.Manager GetUnitByPID $$
|
|
*
|
|
* Compile with 'cc -lsystemd print-unit-path.c'
|
|
*/
|
|
|
|
#define DESTINATION "org.freedesktop.systemd1"
|
|
#define PATH "/org/freedesktop/systemd1"
|
|
#define INTERFACE "org.freedesktop.systemd1.Manager"
|
|
#define MEMBER "GetUnitByPID"
|
|
|
|
static int log_error(int error, const char *message) {
|
|
fprintf(stderr, "%s: %s\n", message, strerror(-error));
|
|
return error;
|
|
}
|
|
|
|
static int print_unit_path(sd_bus *bus) {
|
|
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
|
|
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
|
|
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
|
|
int r;
|
|
|
|
r = sd_bus_message_new_method_call(bus, &m,
|
|
DESTINATION, PATH, INTERFACE, MEMBER);
|
|
if (r < 0)
|
|
return log_error(r, "Failed to create bus message");
|
|
|
|
r = sd_bus_message_append(m, "u", (unsigned) getpid());
|
|
if (r < 0)
|
|
return log_error(r, "Failed to append to bus message");
|
|
|
|
r = sd_bus_call(bus, m, -1, &error, &reply);
|
|
if (r < 0)
|
|
return log_error(r, "Call failed");
|
|
|
|
const char *ans;
|
|
r = sd_bus_message_read(reply, "o", &ans);
|
|
if (r < 0)
|
|
return log_error(r, "Failed to read reply");
|
|
|
|
printf("Unit path is \"%s\".\n", ans);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int main(int argc, char **argv) {
|
|
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
|
|
int r;
|
|
|
|
r = sd_bus_open_system(&bus);
|
|
if (r < 0)
|
|
return log_error(r, "Failed to acquire bus");
|
|
|
|
print_unit_path(bus);
|
|
}
|
|
</PRE>
|
|
|
|
</DL>
|
|
|
|
|
|
|
|
|
|
<P>
|
|
|
|
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.
|
|
<A NAME="lbAI"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<P>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?1+systemd">systemd</A></B>(1),
|
|
<B><A HREF="/cgi-bin/man/man2html?3+sd-bus">sd-bus</A></B>(3),
|
|
<B><A HREF="/cgi-bin/man/man2html?3+sd_bus_path_encode">sd_bus_path_encode</A></B>(3)
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
<DL COMPACT>
|
|
<DT id="9"> 1.<DD>
|
|
D-Bus Tutorial
|
|
<DL COMPACT><DT id="10"><DD>
|
|
<A HREF="https://dbus.freedesktop.org/doc/dbus-tutorial.html#concepts">https://dbus.freedesktop.org/doc/dbus-tutorial.html#concepts</A>
|
|
</DL>
|
|
|
|
<P>
|
|
</DL>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="11"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="12"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="13"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="14"><A HREF="#lbAE">RETURN VALUE</A><DD>
|
|
<DL>
|
|
<DT id="15"><A HREF="#lbAF">Errors</A><DD>
|
|
</DL>
|
|
<DT id="16"><A HREF="#lbAG">NOTES</A><DD>
|
|
<DT id="17"><A HREF="#lbAH">EXAMPLES</A><DD>
|
|
<DT id="18"><A HREF="#lbAI">SEE ALSO</A><DD>
|
|
<DT id="19"><A HREF="#lbAJ">NOTES</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:54 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|