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">
6 SPDX-License-Identifier: LGPL-2.1+
8 This file is part of systemd.
10 Copyright 2016 Julian Orth
13 <refentry id=
"sd_bus_add_match">
16 <title>sd_bus_add_match
</title>
17 <productname>systemd
</productname>
21 <firstname>Julian
</firstname>
22 <surname>Orth
</surname>
23 <email>ju.orth@gmail.com
</email>
29 <refentrytitle>sd_bus_add_match
</refentrytitle>
30 <manvolnum>3</manvolnum>
34 <refname>sd_bus_add_match
</refname>
35 <refname>sd_bus_add_match_async
</refname>
36 <refname>sd_bus_match_signal
</refname>
37 <refname>sd_bus_match_signal_async
</refname>
39 <refpurpose>Add a match rule for incoming message dispatching
</refpurpose>
44 <funcsynopsisinfo>#include
<systemd/sd-bus.h
></funcsynopsisinfo>
47 <funcdef>typedef int (*
<function>sd_bus_message_handler_t
</function>)
</funcdef>
48 <paramdef>sd_bus_message *
<parameter>m
</parameter></paramdef>
49 <paramdef>void *
<parameter>userdata
</parameter></paramdef>
50 <paramdef>sd_bus_error *
<parameter>ret_error
</parameter></paramdef>
54 <funcdef>int
<function>sd_bus_add_match
</function></funcdef>
55 <paramdef>sd_bus *
<parameter>bus
</parameter></paramdef>
56 <paramdef>sd_bus_slot **
<parameter>slot
</parameter></paramdef>
57 <paramdef>const char *
<parameter>match
</parameter></paramdef>
58 <paramdef>sd_bus_message_handler_t
<parameter>callback
</parameter></paramdef>
59 <paramdef>void *
<parameter>userdata
</parameter></paramdef>
63 <funcdef>int
<function>sd_bus_add_match_async
</function></funcdef>
64 <paramdef>sd_bus *
<parameter>bus
</parameter></paramdef>
65 <paramdef>sd_bus_slot **
<parameter>slot
</parameter></paramdef>
66 <paramdef>const char *
<parameter>match
</parameter></paramdef>
67 <paramdef>sd_bus_message_handler_t
<parameter>callback
</parameter></paramdef>
68 <paramdef>sd_bus_message_handler_t
<parameter>install_callback
</parameter></paramdef>
69 <paramdef>void *
<parameter>userdata
</parameter></paramdef>
73 <funcdef>int
<function>sd_bus_match_signal
</function></funcdef>
74 <paramdef>sd_bus *
<parameter>bus
</parameter></paramdef>
75 <paramdef>sd_bus_slot **
<parameter>slot
</parameter></paramdef>
76 <paramdef>const char *
<parameter>sender
</parameter></paramdef>
77 <paramdef>const char *
<parameter>path
</parameter></paramdef>
78 <paramdef>const char *
<parameter>interface
</parameter></paramdef>
79 <paramdef>const char *
<parameter>member
</parameter></paramdef>
80 <paramdef>sd_bus_message_handler_t
<parameter>callback
</parameter></paramdef>
81 <paramdef>void *
<parameter>userdata
</parameter></paramdef>
85 <funcdef>int
<function>sd_bus_match_signal_async
</function></funcdef>
86 <paramdef>sd_bus *
<parameter>bus
</parameter></paramdef>
87 <paramdef>sd_bus_slot **
<parameter>slot
</parameter></paramdef>
88 <paramdef>const char *
<parameter>sender
</parameter></paramdef>
89 <paramdef>const char *
<parameter>path
</parameter></paramdef>
90 <paramdef>const char *
<parameter>interface
</parameter></paramdef>
91 <paramdef>const char *
<parameter>member
</parameter></paramdef>
92 <paramdef>sd_bus_message_handler_t
<parameter>callback
</parameter></paramdef>
93 <paramdef>sd_bus_message_handler_t
<parameter>install_callback
</parameter></paramdef>
94 <paramdef>void *
<parameter>userdata
</parameter></paramdef>
101 <title>Description
</title>
103 <para><function>sd_bus_add_match()
</function> installs a match rule for messages received on the specified bus
104 connection object
<parameter>bus
</parameter>. The syntax of the match rule expression passed in
105 <parameter>match
</parameter> is described in the
<ulink
106 url=
"https://dbus.freedesktop.org/doc/dbus-specification.html">D-Bus Specification
</ulink>. The specified handler
107 function
<parameter>callback
</parameter> is called for eaching incoming message matching the specified expression,
108 the
<parameter>userdata
</parameter> parameter is passed as-is to the callback function. The match is installed
109 synchronously when connected to a bus broker, i.e. the call sends a control message requested the match to be added
110 to the broker and waits until the broker confirms the match has been installed successfully.
</para>
112 <para><function>sd_bus_add_match_async()
</function> operates very similar to
113 <function>sd_bus_match_signal()
</function>, however it installs the match asynchronously, in a non-blocking
114 fashion: a request is sent to the broker, but the call does not wait for a response. The
115 <parameter>install_callback
</parameter> function is called when the response is later received, with the response
116 message from the broker as parameter. If this function is specified as
<constant>NULL
</constant> a default
117 implementation is used that terminates the bus connection should installing the match fail.
</para>
119 <para><function>sd_bus_match_signal()
</function> is very similar to
<function>sd_bus_add_match()
</function>, but
120 only matches signals, and instead of a match expression accepts four parameters:
<parameter>sender
</parameter> (the
121 service name of the sender),
<parameter>path
</parameter> (the object path of the emitting object),
122 <parameter>interface
</parameter> (the interface the signal belongs to),
<parameter>member
</parameter> (the signal
123 name), from which the match string is internally generated. Optionally, these parameters may be specified as
124 <constant>NULL
</constant> in which case the relevant field of incoming signals is not tested.
</para>
126 <para><function>sd_bus_match_signal_async()
</function> is combines the signal matching logic of
127 <function>sd_bus_match_signal()
</function> with the asynchronous behaviour of
128 <function>sd_bus_add_match_async()
</function>.
</para>
130 <para>On success, and if non-
<constant>NULL
</constant>, the
<parameter>slot
</parameter> return parameter will be
131 set to a slot object that may be used as a reference to the installed match, and may be utilized to remove it again
133 <citerefentry><refentrytitle>sd_bus_slot_unref
</refentrytitle><manvolnum>3</manvolnum></citerefentry>. If specified
134 as
<constant>NULL
</constant> the lifetime of the match is bound to the lifetime of the bus object itself, and the
135 match cannot be removed independently.
</para>
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>
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.
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>
154 <title>Return Value
</title>
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.
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>libsystemd
</constant> <citerefentry
167 project='die-net'
><refentrytitle>pkg-config
</refentrytitle><manvolnum>1</manvolnum></citerefentry> file.
</para>
171 <title>See Also
</title>
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>