]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/sd_bus_track_add_name.xml
verify: use manager_load_startable_unit_or_warn() to load units for verification
[thirdparty/systemd.git] / man / sd_bus_track_add_name.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 This file is part of systemd.
9
10 Copyright 2016 Lennart Poettering
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_track_add_name">
27
28 <refentryinfo>
29 <title>sd_bus_track_add_name</title>
30 <productname>systemd</productname>
31
32 <authorgroup>
33 <author>
34 <contrib>Developer</contrib>
35 <firstname>Lennart</firstname>
36 <surname>Poettering</surname>
37 <email>lennart@poettering.net</email>
38 </author>
39 </authorgroup>
40 </refentryinfo>
41
42 <refmeta>
43 <refentrytitle>sd_bus_track_add_name</refentrytitle>
44 <manvolnum>3</manvolnum>
45 </refmeta>
46
47 <refnamediv>
48 <refname>sd_bus_track_add_name</refname>
49 <refname>sd_bus_track_add_sender</refname>
50 <refname>sd_bus_track_remove_name</refname>
51 <refname>sd_bus_track_remove_sender</refname>
52 <refname>sd_bus_track_count</refname>
53 <refname>sd_bus_track_count_sender</refname>
54 <refname>sd_bus_track_count_name</refname>
55 <refname>sd_bus_track_contains</refname>
56 <refname>sd_bus_track_first</refname>
57 <refname>sd_bus_track_next</refname>
58
59 <refpurpose>Add, remove and retrieve bus peers tracked in a bus peer tracking object</refpurpose>
60 </refnamediv>
61
62 <refsynopsisdiv>
63 <funcsynopsis>
64 <funcsynopsisinfo>#include &lt;systemd/sd-bus.h&gt;</funcsynopsisinfo>
65
66 <funcprototype>
67 <funcdef>int <function>sd_bus_track_add_name</function></funcdef>
68 <paramdef>sd_bus_track* <parameter>t</parameter></paramdef>
69 <paramdef>const char* <parameter>name</parameter></paramdef>
70 </funcprototype>
71
72 <funcprototype>
73 <funcdef>int <function>sd_bus_track_add_sender</function></funcdef>
74 <paramdef>sd_bus_track* <parameter>t</parameter></paramdef>
75 <paramdef>sd_bus_message* <parameter>message</parameter></paramdef>
76 </funcprototype>
77
78 <funcprototype>
79 <funcdef>int <function>sd_bus_track_remove_name</function></funcdef>
80 <paramdef>sd_bus_track* <parameter>t</parameter></paramdef>
81 <paramdef>const char* <parameter>name</parameter></paramdef>
82 </funcprototype>
83
84 <funcprototype>
85 <funcdef>int <function>sd_bus_track_remove_sender</function></funcdef>
86 <paramdef>sd_bus_track* <parameter>t</parameter></paramdef>
87 <paramdef>sd_bus_message* <parameter>message</parameter></paramdef>
88 </funcprototype>
89
90 <funcprototype>
91 <funcdef>unsigned <function>sd_bus_track_count</function></funcdef>
92 <paramdef>sd_bus_track* <parameter>t</parameter></paramdef>
93 </funcprototype>
94
95 <funcprototype>
96 <funcdef>int <function>sd_bus_track_count_name</function></funcdef>
97 <paramdef>sd_bus_track* <parameter>t</parameter></paramdef>
98 <paramdef>const char* <parameter>name</parameter></paramdef>
99 </funcprototype>
100
101 <funcprototype>
102 <funcdef>int <function>sd_bus_track_count_sender</function></funcdef>
103 <paramdef>sd_bus_track* <parameter>t</parameter></paramdef>
104 <paramdef>sd_bus_message* <parameter>message</parameter></paramdef>
105 </funcprototype>
106
107 <funcprototype>
108 <funcdef>int <function>sd_bus_track_contains</function></funcdef>
109 <paramdef>sd_bus_track* <parameter>t</parameter></paramdef>
110 <paramdef>const char* <parameter>name</parameter></paramdef>
111 </funcprototype>
112
113 <funcprototype>
114 <funcdef>const char* <function>sd_bus_track_first</function></funcdef>
115 <paramdef>sd_bus_track* <parameter>t</parameter></paramdef>
116 </funcprototype>
117
118 <funcprototype>
119 <funcdef>const char* <function>sd_bus_track_next</function></funcdef>
120 <paramdef>sd_bus_track* <parameter>t</parameter></paramdef>
121 </funcprototype>
122
123 </funcsynopsis>
124 </refsynopsisdiv>
125
126 <refsect1>
127 <title>Description</title>
128
129 <para><function>sd_bus_track_add_name()</function> adds a peer to track to a bus peer tracking object. The first
130 argument should refer to a bus peer tracking object created with
131 <citerefentry><refentrytitle>sd_bus_track_new</refentrytitle><manvolnum>3</manvolnum></citerefentry>, the second
132 name should refer to a D-Bus peer name to track, either in unique or well-known service format. If the name is not
133 tracked yet it will be added to the list of names to track. If it already is being tracked and non-recursive mode
134 is enabled, no operation is executed by this call. If recursive mode is enabled a per-name counter is increased by
135 one each time this call is invoked, and <function>sd_bus_track_remove_name()</function> has to be called as many
136 times as <function>sd_bus_track_add_name()</function> was invoked before in order to stop tracking of the name. Use
137 <citerefentry><refentrytitle>sd_bus_track_set_recursive</refentrytitle><manvolnum>3</manvolnum></citerefentry> to
138 switch from the default non-recursive mode to recursive mode, or back. Note that the specified name is tracked as
139 it is, well-known names are not resolved to unique names by this call. Note that multiple bus peer tracking objects
140 may track the same name.</para>
141
142 <para><function>sd_bus_track_remove_name()</function> undoes the effect of
143 <function>sd_bus_track_add_name()</function> and removes a bus peer name from the list of peers to watch. Depending
144 on whether non-recursive or recursive mode is enabled for the bus peer tracking object this call will either remove
145 the name fully from the tracking object, or will simply decrement the per-name counter by one, removing the name
146 only when the counter reaches zero (see above). Note that a bus peer disconnecting from the bus will implicitly
147 remove its names fully from the bus peer tracking object, regardless of the current per-name counter.</para>
148
149 <para><function>sd_bus_track_add_sender()</function> and <function>sd_bus_track_remove_sender()</function> are
150 similar to <function>sd_bus_track_add_name()</function> and <function>sd_bus_track_remove_name()</function> but
151 take a bus message as argument. The sender of this bus message is determined and added to/removed from the bus peer
152 tracking object. As messages always originate from unique names, and never from well-known names this means that
153 this call will effectively only add unique names to the bus peer tracking object.</para>
154
155 <para><function>sd_bus_track_count()</function> returns the number of names currently being tracked by the
156 specified bus peer tracking object. Note that this function always returns the actual number of names tracked, and
157 hence if <function>sd_bus_track_add_name()</function> has been invoked multiple times for the same name it is only
158 counted as one, regardless if recursive mode is used or not.</para>
159
160 <para><function>sd_bus_track_count_name()</function> returns the current per-name counter for the specified
161 name. If non-recursive mode is used this returns either 1 or 0, depending on whether the specified name has been
162 added to the tracking object before, or not. If recursive mode has been enabled, values larger than 1 may be
163 returned too, in case <function>sd_bus_track_add_name()</function> has been called multiple times for the same
164 name.</para>
165
166 <para><function>sd_bus_track_count_sender()</function> is similar to
167 <function>sd_bus_track_count_name()</function>, but takes a bus message object and returns the per-name counter
168 matching the sender of the message.</para>
169
170 <para><function>sd_bus_track_contains()</function> may be used to determine whether the specified name has been
171 added at least once to the specified bus peer tracking object.</para>
172
173 <para><function>sd_bus_track_first()</function> and <function>sd_bus_track_next()</function> may be used to
174 enumerate all names currently being tracked by the passed bus peer tracking
175 object. <function>sd_bus_track_first()</function> returns the first entry in the object, and resets an internally
176 maintained read index. Each subsequent invocation of <function>sd_bus_track_next()</function> returns the next name
177 contained in the bus object. If the end is reached <constant>NULL</constant> is returned. If no names have been
178 added to the object yet <function>sd_bus_track_first()</function> will return <constant>NULL</constant>
179 immediately. The order in which names are returned is undefined; in particular which name is considered the first
180 returned is not defined. If recursive mode is enabled and the same name has been added multiple times to the bus
181 peer tracking object it is only returned once by this enumeration. If new names are added to or existing names
182 removed from the bus peer tracking object while it is being enumerated the enumeration ends on the next invocation
183 of <function>sd_bus_track_next()</function> as <constant>NULL</constant> is returned.</para>
184 </refsect1>
185
186 <refsect1>
187 <title>Return Value</title>
188
189 <para>On success, <function>sd_bus_track_add_name()</function> and <function>sd_bus_track_add_sender()</function>
190 return 0 if the specified name has already been added to the bus peer tracking object before and positive if it
191 hasn't. On failure, they return a negative errno-style error code.</para>
192
193 <para><function>sd_bus_track_remove_name()</function> and <function>sd_bus_track_remove_sender()</function> return
194 positive if the specified name was previously tracked by the bus peer tracking object and has now been removed. In
195 non-recursive mode, 0 is returned if the specified name was not being tracked yet. In recursive mode
196 <constant>-EUNATCH</constant> is returned in this case. On failure, they return a negative errno-style error
197 code.</para>
198
199 <para><function>sd_bus_track_count()</function> returns the number of names currently being tracked, or 0 on
200 failure.</para>
201
202 <para><function>sd_bus_track_count_name()</function> and <function>sd_bus_track_count_sender()</function> return
203 the current per-name counter for the specified name or the sender of the specified message. Zero is returned for
204 names that are not being tracked yet, a positive value for names added at least once. Larger values than 1 are only
205 returned in recursive mode. On failure, a negative errno-style error code is returned.</para>
206
207 <para><function>sd_bus_track_contains()</function> returns the passed name if it exists in the bus peer tracking
208 object. On failure, and if the name has not been added yet <constant>NULL</constant> is returned.</para>
209
210 <para><function>sd_bus_track_first()</function> and <function>sd_bus_track_next()</function> return the first/next
211 name contained in the bus peer tracking object, and <constant>NULL</constant> if the end of the enumeration is
212 reached and on error.</para>
213 </refsect1>
214
215 <refsect1>
216 <title>Errors</title>
217
218 <para>Returned errors may indicate the following problems:</para>
219
220 <variablelist>
221
222 <varlistentry>
223 <term><constant>-EUNATCH</constant></term>
224
225 <listitem><para><function>sd_bus_track_remove_name()</function> or
226 <function>sd_bus_track_remove_sender()</function> have been invoked for a name not previously added to the bus
227 peer object.</para></listitem>
228 </varlistentry>
229
230 <varlistentry>
231 <term><constant>-EINVAL</constant></term>
232
233 <listitem><para>Specified parameter is invalid.</para></listitem>
234 </varlistentry>
235
236 <varlistentry>
237 <term><constant>-ENOMEM</constant></term>
238
239 <listitem><para>Memory allocation failed.</para></listitem>
240 </varlistentry>
241
242 </variablelist>
243 </refsect1>
244
245 <refsect1>
246 <title>Notes</title>
247
248 <para><function>sd_bus_track_add_name()</function> and the other calls described here are available as a shared library,
249 which can be compiled and linked to with the <constant>libsystemd</constant> <citerefentry
250 project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry> file.</para>
251 </refsect1>
252
253 <refsect1>
254 <title>See Also</title>
255
256 <para>
257 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
258 <citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
259 <citerefentry><refentrytitle>sd_bus_track_new</refentrytitle><manvolnum>3</manvolnum></citerefentry>
260 </para>
261 </refsect1>
262
263 </refentry>