]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/sd_bus_add_match.xml
verify: use manager_load_startable_unit_or_warn() to load units for verification
[thirdparty/systemd.git] / man / sd_bus_add_match.xml
CommitLineData
e382c49f 1<?xml version='1.0'?> <!--*- Mode: nxml; nxml-child-indent: 2; indent-tabs-mode: nil -*-->
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<!--
572eb058
ZJS
6 SPDX-License-Identifier: LGPL-2.1+
7
e382c49f 8 This file is part of systemd.
9
10 Copyright 2016 Julian Orth
11
12 systemd is free software; you can redistribute it and/or modify it
13 under the terms of the GNU Lesser General Public License as published by
14 the Free Software Foundation; either version 2.1 of the License, or
15 (at your option) any later version.
16
17 systemd is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 Lesser General Public License for more details.
21
22 You should have received a copy of the GNU Lesser General Public License
23 along with systemd; If not, see <http://www.gnu.org/licenses/>.
24-->
25
26<refentry id="sd_bus_add_match">
27
28 <refentryinfo>
29 <title>sd_bus_add_match</title>
30 <productname>systemd</productname>
31
32 <authorgroup>
33 <author>
34 <firstname>Julian</firstname>
35 <surname>Orth</surname>
36 <email>ju.orth@gmail.com</email>
37 </author>
38 </authorgroup>
39 </refentryinfo>
40
41 <refmeta>
42 <refentrytitle>sd_bus_add_match</refentrytitle>
43 <manvolnum>3</manvolnum>
44 </refmeta>
45
46 <refnamediv>
47 <refname>sd_bus_add_match</refname>
d97eac36
LP
48 <refname>sd_bus_add_match_async</refname>
49 <refname>sd_bus_match_signal</refname>
50 <refname>sd_bus_match_signal_async</refname>
e382c49f 51
d97eac36 52 <refpurpose>Add a match rule for incoming message dispatching</refpurpose>
e382c49f 53 </refnamediv>
54
55 <refsynopsisdiv>
56 <funcsynopsis>
57 <funcsynopsisinfo>#include &lt;systemd/sd-bus.h&gt;</funcsynopsisinfo>
58
d97eac36
LP
59 <funcprototype>
60 <funcdef>typedef int (*<function>sd_bus_message_handler_t</function>)</funcdef>
61 <paramdef>sd_bus_message *<parameter>m</parameter></paramdef>
62 <paramdef>void *<parameter>userdata</parameter></paramdef>
63 <paramdef>sd_bus_error *<parameter>ret_error</parameter></paramdef>
64 </funcprototype>
65
e382c49f 66 <funcprototype>
67 <funcdef>int <function>sd_bus_add_match</function></funcdef>
68 <paramdef>sd_bus *<parameter>bus</parameter></paramdef>
69 <paramdef>sd_bus_slot **<parameter>slot</parameter></paramdef>
70 <paramdef>const char *<parameter>match</parameter></paramdef>
71 <paramdef>sd_bus_message_handler_t <parameter>callback</parameter></paramdef>
72 <paramdef>void *<parameter>userdata</parameter></paramdef>
73 </funcprototype>
74
75 <funcprototype>
d97eac36
LP
76 <funcdef>int <function>sd_bus_add_match_async</function></funcdef>
77 <paramdef>sd_bus *<parameter>bus</parameter></paramdef>
78 <paramdef>sd_bus_slot **<parameter>slot</parameter></paramdef>
79 <paramdef>const char *<parameter>match</parameter></paramdef>
80 <paramdef>sd_bus_message_handler_t <parameter>callback</parameter></paramdef>
81 <paramdef>sd_bus_message_handler_t <parameter>install_callback</parameter></paramdef>
82 <paramdef>void *<parameter>userdata</parameter></paramdef>
83 </funcprototype>
84
85 <funcprototype>
86 <funcdef>int <function>sd_bus_match_signal</function></funcdef>
87 <paramdef>sd_bus *<parameter>bus</parameter></paramdef>
88 <paramdef>sd_bus_slot **<parameter>slot</parameter></paramdef>
89 <paramdef>const char *<parameter>sender</parameter></paramdef>
90 <paramdef>const char *<parameter>path</parameter></paramdef>
91 <paramdef>const char *<parameter>interface</parameter></paramdef>
92 <paramdef>const char *<parameter>member</parameter></paramdef>
93 <paramdef>sd_bus_message_handler_t <parameter>callback</parameter></paramdef>
94 <paramdef>void *<parameter>userdata</parameter></paramdef>
95 </funcprototype>
96
97 <funcprototype>
98 <funcdef>int <function>sd_bus_match_signal_async</function></funcdef>
99 <paramdef>sd_bus *<parameter>bus</parameter></paramdef>
100 <paramdef>sd_bus_slot **<parameter>slot</parameter></paramdef>
101 <paramdef>const char *<parameter>sender</parameter></paramdef>
102 <paramdef>const char *<parameter>path</parameter></paramdef>
103 <paramdef>const char *<parameter>interface</parameter></paramdef>
104 <paramdef>const char *<parameter>member</parameter></paramdef>
105 <paramdef>sd_bus_message_handler_t <parameter>callback</parameter></paramdef>
106 <paramdef>sd_bus_message_handler_t <parameter>install_callback</parameter></paramdef>
e382c49f 107 <paramdef>void *<parameter>userdata</parameter></paramdef>
e382c49f 108 </funcprototype>
d97eac36 109
e382c49f 110 </funcsynopsis>
111 </refsynopsisdiv>
112
113 <refsect1>
114 <title>Description</title>
115
d97eac36
LP
116 <para><function>sd_bus_add_match()</function> installs a match rule for messages received on the specified bus
117 connection object <parameter>bus</parameter>. The syntax of the match rule expression passed in
118 <parameter>match</parameter> is described in the <ulink
119 url="https://dbus.freedesktop.org/doc/dbus-specification.html">D-Bus Specification</ulink>. The specified handler
120 function <parameter>callback</parameter> is called for eaching incoming message matching the specified expression,
121 the <parameter>userdata</parameter> parameter is passed as-is to the callback function. The match is installed
122 synchronously when connected to a bus broker, i.e. the call sends a control message requested the match to be added
123 to the broker and waits until the broker confirms the match has been installed successfully.</para>
124
125 <para><function>sd_bus_add_match_async()</function> operates very similar to
126 <function>sd_bus_match_signal()</function>, however it installs the match asynchronously, in a non-blocking
127 fashion: a request is sent to the broker, but the call does not wait for a response. The
128 <parameter>install_callback</parameter> function is called when the response is later received, with the response
129 message from the broker as parameter. If this function is specified as <constant>NULL</constant> a default
130 implementation is used that terminates the bus connection should installing the match fail.</para>
131
132 <para><function>sd_bus_match_signal()</function> is very similar to <function>sd_bus_add_match()</function>, but
133 only matches signals, and instead of a match expression accepts four parameters: <parameter>sender</parameter> (the
134 service name of the sender), <parameter>path</parameter> (the object path of the emitting object),
135 <parameter>interface</parameter> (the interface the signal belongs to), <parameter>member</parameter> (the signal
136 name), from which the match string is internally generated. Optionally, these parameters may be specified as
137 <constant>NULL</constant> in which case the relevant field of incoming signals is not tested.</para>
138
139 <para><function>sd_bus_match_signal_async()</function> is combines the signal matching logic of
140 <function>sd_bus_match_signal()</function> with the asynchronous behaviour of
141 <function>sd_bus_add_match_async()</function>.</para>
142
143 <para>On success, and if non-<constant>NULL</constant>, the <parameter>slot</parameter> return parameter will be
144 set to a slot object that may be used as a reference to the installed match, and may be utilized to remove it again
145 at a later time with
146 <citerefentry><refentrytitle>sd_bus_slot_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>. If specified
147 as <constant>NULL</constant> the lifetime of the match is bound to the lifetime of the bus object itself, and the
148 match cannot be removed independently.</para>
149
150 <para>The message <parameter>m</parameter> passed to the callback is only borrowed, that is, the callback should
151 not call <citerefentry><refentrytitle>sd_bus_message_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>
152 on it. If the callback wants to hold on to the message beyond the lifetime of the callback, it needs to call
153 <citerefentry><refentrytitle>sd_bus_message_ref</refentrytitle><manvolnum>3</manvolnum></citerefentry> to create a
154 new reference.</para>
155
156 <para>If an error occurs during the callback invocation, the callback should return a negative error number
157 (optionally, a more precise error may be returned in <parameter>ret_error</parameter>, as well). If it wants other
158 callbacks that match the same rule to be called, it should return 0. Otherwise it should return a positive integer.
e382c49f 159 </para>
160
d97eac36
LP
161 <para>If the <parameter>bus</parameter> refers to a direct connection (i.e. not a bus connection, as set with
162 <citerefentry><refentrytitle>sd_bus_set_bus_client</refentrytitle><manvolnum>3</manvolnum></citerefentry>) the
163 match is only installed on the client side, and the synchronous and asynchronous functions operate the same.</para>
164 </refsect1>
e382c49f 165
d97eac36
LP
166 <refsect1>
167 <title>Return Value</title>
6b7af821
LP
168
169 <para>
d97eac36
LP
170 On success, <function>sd_bus_add_match()</function> and the other calls return 0 or a positive integer. On
171 failure, they return a negative errno-style error code.
e382c49f 172 </para>
173 </refsect1>
174
175 <refsect1>
d97eac36 176 <title>Notes</title>
e382c49f 177
d97eac36
LP
178 <para><function>sd_bus_add_match()</function> and the other functions described here are available as a shared
179 library, which can be compiled and linked to with the <constant>libsystemd</constant> <citerefentry
180 project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry> file.</para>
e382c49f 181 </refsect1>
182
183 <refsect1>
184 <title>See Also</title>
185
186 <para>
187 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
d97eac36
LP
188 <citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
189 <citerefentry><refentrytitle>sd_bus_slot_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
190 <citerefentry><refentrytitle>sd_bus_message_ref</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
191 <citerefentry><refentrytitle>sd_bus_set_bus_client</refentrytitle><manvolnum>3</manvolnum></citerefentry>
e382c49f 192 </para>
193 </refsect1>
194
195</refentry>