]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/sd_bus_add_match.xml
Merge pull request #8822 from fbuihuu/rfc-tmpfiles-safe-upstream
[thirdparty/systemd.git] / man / sd_bus_add_match.xml
1 <?xml version='1.0'?>
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4
5 <!--
6 SPDX-License-Identifier: LGPL-2.1+
7
8 Copyright © 2016 Julian Orth
9 -->
10
11 <refentry id="sd_bus_add_match">
12
13 <refentryinfo>
14 <title>sd_bus_add_match</title>
15 <productname>systemd</productname>
16 </refentryinfo>
17
18 <refmeta>
19 <refentrytitle>sd_bus_add_match</refentrytitle>
20 <manvolnum>3</manvolnum>
21 </refmeta>
22
23 <refnamediv>
24 <refname>sd_bus_add_match</refname>
25 <refname>sd_bus_add_match_async</refname>
26 <refname>sd_bus_match_signal</refname>
27 <refname>sd_bus_match_signal_async</refname>
28
29 <refpurpose>Add a match rule for incoming message dispatching</refpurpose>
30 </refnamediv>
31
32 <refsynopsisdiv>
33 <funcsynopsis>
34 <funcsynopsisinfo>#include &lt;systemd/sd-bus.h&gt;</funcsynopsisinfo>
35
36 <funcprototype>
37 <funcdef>typedef int (*<function>sd_bus_message_handler_t</function>)</funcdef>
38 <paramdef>sd_bus_message *<parameter>m</parameter></paramdef>
39 <paramdef>void *<parameter>userdata</parameter></paramdef>
40 <paramdef>sd_bus_error *<parameter>ret_error</parameter></paramdef>
41 </funcprototype>
42
43 <funcprototype>
44 <funcdef>int <function>sd_bus_add_match</function></funcdef>
45 <paramdef>sd_bus *<parameter>bus</parameter></paramdef>
46 <paramdef>sd_bus_slot **<parameter>slot</parameter></paramdef>
47 <paramdef>const char *<parameter>match</parameter></paramdef>
48 <paramdef>sd_bus_message_handler_t <parameter>callback</parameter></paramdef>
49 <paramdef>void *<parameter>userdata</parameter></paramdef>
50 </funcprototype>
51
52 <funcprototype>
53 <funcdef>int <function>sd_bus_add_match_async</function></funcdef>
54 <paramdef>sd_bus *<parameter>bus</parameter></paramdef>
55 <paramdef>sd_bus_slot **<parameter>slot</parameter></paramdef>
56 <paramdef>const char *<parameter>match</parameter></paramdef>
57 <paramdef>sd_bus_message_handler_t <parameter>callback</parameter></paramdef>
58 <paramdef>sd_bus_message_handler_t <parameter>install_callback</parameter></paramdef>
59 <paramdef>void *<parameter>userdata</parameter></paramdef>
60 </funcprototype>
61
62 <funcprototype>
63 <funcdef>int <function>sd_bus_match_signal</function></funcdef>
64 <paramdef>sd_bus *<parameter>bus</parameter></paramdef>
65 <paramdef>sd_bus_slot **<parameter>slot</parameter></paramdef>
66 <paramdef>const char *<parameter>sender</parameter></paramdef>
67 <paramdef>const char *<parameter>path</parameter></paramdef>
68 <paramdef>const char *<parameter>interface</parameter></paramdef>
69 <paramdef>const char *<parameter>member</parameter></paramdef>
70 <paramdef>sd_bus_message_handler_t <parameter>callback</parameter></paramdef>
71 <paramdef>void *<parameter>userdata</parameter></paramdef>
72 </funcprototype>
73
74 <funcprototype>
75 <funcdef>int <function>sd_bus_match_signal_async</function></funcdef>
76 <paramdef>sd_bus *<parameter>bus</parameter></paramdef>
77 <paramdef>sd_bus_slot **<parameter>slot</parameter></paramdef>
78 <paramdef>const char *<parameter>sender</parameter></paramdef>
79 <paramdef>const char *<parameter>path</parameter></paramdef>
80 <paramdef>const char *<parameter>interface</parameter></paramdef>
81 <paramdef>const char *<parameter>member</parameter></paramdef>
82 <paramdef>sd_bus_message_handler_t <parameter>callback</parameter></paramdef>
83 <paramdef>sd_bus_message_handler_t <parameter>install_callback</parameter></paramdef>
84 <paramdef>void *<parameter>userdata</parameter></paramdef>
85 </funcprototype>
86
87 </funcsynopsis>
88 </refsynopsisdiv>
89
90 <refsect1>
91 <title>Description</title>
92
93 <para><function>sd_bus_add_match()</function> installs a match rule for messages received on the specified bus
94 connection object <parameter>bus</parameter>. The syntax of the match rule expression passed in
95 <parameter>match</parameter> is described in the <ulink
96 url="https://dbus.freedesktop.org/doc/dbus-specification.html">D-Bus Specification</ulink>. The specified handler
97 function <parameter>callback</parameter> is called for eaching incoming message matching the specified expression,
98 the <parameter>userdata</parameter> parameter is passed as-is to the callback function. The match is installed
99 synchronously when connected to a bus broker, i.e. the call sends a control message requested the match to be added
100 to the broker and waits until the broker confirms the match has been installed successfully.</para>
101
102 <para><function>sd_bus_add_match_async()</function> operates very similar to
103 <function>sd_bus_match_signal()</function>, however it installs the match asynchronously, in a non-blocking
104 fashion: a request is sent to the broker, but the call does not wait for a response. The
105 <parameter>install_callback</parameter> function is called when the response is later received, with the response
106 message from the broker as parameter. If this function is specified as <constant>NULL</constant> a default
107 implementation is used that terminates the bus connection should installing the match fail.</para>
108
109 <para><function>sd_bus_match_signal()</function> is very similar to <function>sd_bus_add_match()</function>, but
110 only matches signals, and instead of a match expression accepts four parameters: <parameter>sender</parameter> (the
111 service name of the sender), <parameter>path</parameter> (the object path of the emitting object),
112 <parameter>interface</parameter> (the interface the signal belongs to), <parameter>member</parameter> (the signal
113 name), from which the match string is internally generated. Optionally, these parameters may be specified as
114 <constant>NULL</constant> in which case the relevant field of incoming signals is not tested.</para>
115
116 <para><function>sd_bus_match_signal_async()</function> combines the signal matching logic of
117 <function>sd_bus_match_signal()</function> with the asynchronous behaviour of
118 <function>sd_bus_add_match_async()</function>.</para>
119
120 <para>On success, and if non-<constant>NULL</constant>, the <parameter>slot</parameter> return parameter will be
121 set to a slot object that may be used as a reference to the installed match, and may be utilized to remove it again
122 at a later time with
123 <citerefentry><refentrytitle>sd_bus_slot_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>. If specified
124 as <constant>NULL</constant> the lifetime of the match is bound to the lifetime of the bus object itself, and the
125 match is generally not removed independently. See
126 <citerefentry><refentrytitle>sd_bus_slot_set_floating</refentrytitle><manvolnum>3</manvolnum></citerefentry> for
127 details.</para>
128
129 <para>The message <parameter>m</parameter> passed to the callback is only borrowed, that is, the callback should
130 not call <citerefentry><refentrytitle>sd_bus_message_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>
131 on it. If the callback wants to hold on to the message beyond the lifetime of the callback, it needs to call
132 <citerefentry><refentrytitle>sd_bus_message_ref</refentrytitle><manvolnum>3</manvolnum></citerefentry> to create a
133 new reference.</para>
134
135 <para>If an error occurs during the callback invocation, the callback should return a negative error number
136 (optionally, a more precise error may be returned in <parameter>ret_error</parameter>, as well). If it wants other
137 callbacks that match the same rule to be called, it should return 0. Otherwise it should return a positive integer.
138 </para>
139
140 <para>If the <parameter>bus</parameter> refers to a direct connection (i.e. not a bus connection, as set with
141 <citerefentry><refentrytitle>sd_bus_set_bus_client</refentrytitle><manvolnum>3</manvolnum></citerefentry>) the
142 match is only installed on the client side, and the synchronous and asynchronous functions operate the same.</para>
143 </refsect1>
144
145 <refsect1>
146 <title>Return Value</title>
147
148 <para>
149 On success, <function>sd_bus_add_match()</function> and the other calls return 0 or a positive integer. On
150 failure, they return a negative errno-style error code.
151 </para>
152 </refsect1>
153
154 <refsect1>
155 <title>Notes</title>
156
157 <para><function>sd_bus_add_match()</function> and the other functions described here are available as a shared
158 library, which can be compiled and linked to with the <constant>libsystemd</constant> <citerefentry
159 project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry> file.</para>
160 </refsect1>
161
162 <refsect1>
163 <title>See Also</title>
164
165 <para>
166 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
167 <citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
168 <citerefentry><refentrytitle>sd_bus_slot_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
169 <citerefentry><refentrytitle>sd_bus_message_ref</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
170 <citerefentry><refentrytitle>sd_bus_set_bus_client</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
171 <citerefentry><refentrytitle>sd_bus_slot_set_floating</refentrytitle><manvolnum>3</manvolnum></citerefentry>
172 </para>
173 </refsect1>
174
175 </refentry>