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