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