]>
Commit | Line | Data |
---|---|---|
6e866b33 | 1 | <?xml version='1.0'?> |
bb4f798a MB |
2 | <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" |
3 | "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> | |
5a920b42 MP |
4 | |
5 | <!-- | |
52ad194e MB |
6 | SPDX-License-Identifier: LGPL-2.1+ |
7 | ||
b012e921 | 8 | Copyright © 2016 Julian Orth |
5a920b42 MP |
9 | --> |
10 | ||
6e866b33 | 11 | <refentry id="sd_bus_add_match" xmlns:xi="http://www.w3.org/2001/XInclude"> |
5a920b42 MP |
12 | |
13 | <refentryinfo> | |
14 | <title>sd_bus_add_match</title> | |
15 | <productname>systemd</productname> | |
5a920b42 MP |
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> | |
1d42b86d MB |
25 | <refname>sd_bus_add_match_async</refname> |
26 | <refname>sd_bus_match_signal</refname> | |
27 | <refname>sd_bus_match_signal_async</refname> | |
5a920b42 | 28 | |
1d42b86d | 29 | <refpurpose>Add a match rule for incoming message dispatching</refpurpose> |
5a920b42 MP |
30 | </refnamediv> |
31 | ||
32 | <refsynopsisdiv> | |
33 | <funcsynopsis> | |
34 | <funcsynopsisinfo>#include <systemd/sd-bus.h></funcsynopsisinfo> | |
35 | ||
1d42b86d MB |
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 | ||
5a920b42 MP |
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> | |
1d42b86d MB |
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> | |
5a920b42 | 84 | <paramdef>void *<parameter>userdata</parameter></paramdef> |
5a920b42 | 85 | </funcprototype> |
1d42b86d | 86 | |
5a920b42 MP |
87 | </funcsynopsis> |
88 | </refsynopsisdiv> | |
89 | ||
90 | <refsect1> | |
91 | <title>Description</title> | |
92 | ||
1d42b86d MB |
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 | ||
b012e921 | 116 | <para><function>sd_bus_match_signal_async()</function> combines the signal matching logic of |
1d42b86d MB |
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 | |
b012e921 MB |
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> | |
1d42b86d MB |
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. | |
5a920b42 MP |
138 | </para> |
139 | ||
1d42b86d MB |
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> | |
5a920b42 | 144 | |
1d42b86d MB |
145 | <refsect1> |
146 | <title>Return Value</title> | |
81c58355 MB |
147 | |
148 | <para> | |
1d42b86d MB |
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. | |
5a920b42 MP |
151 | </para> |
152 | </refsect1> | |
153 | ||
154 | <refsect1> | |
1d42b86d | 155 | <title>Notes</title> |
5a920b42 | 156 | |
6e866b33 | 157 | <xi:include href="libsystemd-pkgconfig.xml" xpointer="pkgconfig-text"/> |
5a920b42 MP |
158 | </refsect1> |
159 | ||
160 | <refsect1> | |
161 | <title>See Also</title> | |
162 | ||
163 | <para> | |
164 | <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, | |
1d42b86d MB |
165 | <citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>, |
166 | <citerefentry><refentrytitle>sd_bus_slot_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
167 | <citerefentry><refentrytitle>sd_bus_message_ref</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
b012e921 MB |
168 | <citerefentry><refentrytitle>sd_bus_set_bus_client</refentrytitle><manvolnum>3</manvolnum></citerefentry>, |
169 | <citerefentry><refentrytitle>sd_bus_slot_set_floating</refentrytitle><manvolnum>3</manvolnum></citerefentry> | |
5a920b42 MP |
170 | </para> |
171 | </refsect1> | |
172 | ||
173 | </refentry> |