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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
|
<?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">
<!--
This file is part of systemd.
Copyright 2016 Lennart Poettering
systemd is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
-->
<refentry id="sd_bus_track_new">
<refentryinfo>
<title>sd_bus_track_new</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_new</refentrytitle>
<manvolnum>3</manvolnum>
</refmeta>
<refnamediv>
<refname>sd_bus_track_new</refname>
<refname>sd_bus_track_ref</refname>
<refname>sd_bus_track_unref</refname>
<refname>sd_bus_track_unrefp</refname>
<refname>sd_bus_track_set_recursive</refname>
<refname>sd_bus_track_get_recursive</refname>
<refname>sd_bus_track_get_bus</refname>
<refname>sd_bus_track_get_userdata</refname>
<refname>sd_bus_track_set_userdata</refname>
<refpurpose>Track bus peers</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcsynopsisinfo>#include <systemd/sd-bus.h></funcsynopsisinfo>
<funcprototype>
<funcdef>int <function>sd_bus_track_new</function></funcdef>
<paramdef>sd_bus* <parameter>bus</parameter></paramdef>
<paramdef>sd_bus_track** <parameter>ret</parameter></paramdef>
<paramdef>sd_bus_track_handler_t <parameter>handler</parameter></paramdef>
<paramdef>void* <parameter>userdata</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>sd_bus_track *<function>sd_bus_track_ref</function></funcdef>
<paramdef>sd_bus_track *<parameter>t</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>sd_bus_track *<function>sd_bus_track_unref</function></funcdef>
<paramdef>sd_bus_track *<parameter>t</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>void <function>sd_bus_track_unrefp</function></funcdef>
<paramdef>sd_bus_track **<parameter>t</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>int <function>sd_bus_track_get_recursive</function></funcdef>
<paramdef>sd_bus_track *<parameter>t</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>int <function>sd_bus_track_set_recursive</function></funcdef>
<paramdef>sd_bus_track *<parameter>t</parameter></paramdef>
<paramdef>int <parameter>b</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>sd_bus* <function>sd_bus_track_get_bus</function></funcdef>
<paramdef>sd_bus_track *<parameter>t</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>void* <function>sd_bus_track_get_userdata</function></funcdef>
<paramdef>sd_bus_track *<parameter>t</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>void* <function>sd_bus_track_set_userdata</function></funcdef>
<paramdef>sd_bus_track *<parameter>t</parameter></paramdef>
<paramdef>void *userdata</paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>Description</title>
<para><function>sd_bus_track_new()</function> creates a new bus peer tracking object. The object is allocated for
the specified bus, and returned in the <parameter>*ret</parameter> parameter. After use, the object should be freed
again by dropping the acquired reference with <function>sd_bus_track_unref()</function> (see below). A bus peer
tracking object may be used to keep track of peers on a specific IPC bus, for cases where peers are making use of
one or more local objects, in order to control the lifecycle of the local objects and ensure they stay around as
long as the peers needing them are around, and unreferenced (and possibly destroyed) as soon as all relevant peers
have vanished. Each bus peer tracking object may be used to track zero, one or more peers add a time. References to
specific bus peers are added via
<citerefentry><refentrytitle>sd_bus_track_add_name</refentrytitle><manvolnum>3</manvolnum></citerefentry> or
<function>sd_bus_track_add_sender()</function>. They may be dropped again via
<function>sd_bus_track_remove_name()</function> and
<function>sd_bus_track_remove_sender()</function>. Alternatively, references on peers are removed automatically
when they disconnect from the bus. If non-NULL the <parameter>handler</parameter> may specify a function that is
invoked whenever the last reference is dropped, regardless whether the reference is dropped explicitly via
<function>sd_bus_track_remove_name()</function> or implicitly because the peer disconnected from the bus. The final
argument <parameter>userdata</parameter> may be used to attach a generic user data pointer to the object. This
pointer is passed to the handler callback when it is invoked.</para>
<para><function>sd_bus_track_ref()</function> creates a new reference to a bus peer tracking object. This object
will not be destroyed until <function>sd_bus_track_unref()</function> has been called as many times plus once
more. Once the reference count has dropped to zero, the specified object cannot be used anymore, further calls to
<function>sd_bus_track_ref()</function> or <function>sd_bus_track_unref()</function> on the same object are
illegal.</para>
<para><function>sd_bus_track_unref()</function> destroys a reference to a bus peer tracking object.</para>
<para><function>sd_bus_track_unrefp()</function> is similar to <function>sd_bus_track_unref()</function> but takes
a pointer to a pointer to an <type>sd_bus_track</type> object. This call is useful in conjunction with GCC's and
LLVM's <ulink url="https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html">Clean-up Variable
Attribute</ulink>. Note that this function is defined as inline function.</para>
<para><function>sd_bus_track_ref()</function>, <function>sd_bus_track_unref()</function> and
<function>sd_bus_track_unrefp()</function> execute no operation if the passed in bus peer tracking object is
<constant>NULL</constant>.</para>
<para>Bus peer tracking objects may exist in two modes: by default they operate in non-recursive mode, but may
optionally be switched into recursive mode. If operating in the default non-recursive mode a peer is either tracked
or not tracked. In this mode invoking <function>sd_bus_track_add_name()</function> multiple times in a row for the
same peer is fully equivalent to calling it just once, as the call adds the peer to the set of tracked peers if
necessary, and executes no operation if the peer is already being tracked. A single invocation of
<function>sd_bus_track_remove_name()</function> removes the reference on the peer again, regardless how many times
<function>sd_bus_track_add_name()</function> was called before. If operating in recursive mode, the number of times
<function>sd_bus_track_add_name()</function> is invoked for the same peer name is counted and
<function>sd_bus_track_remove_name()</function> must be called the same number of times before the peer is not
tracked anymore, with the exception when the tracked peer vanishes from the bus, in which case the count is
irrelevant and the tracking of the specific peer is immediately
removed. <function>sd_bus_track_get_recursive()</function> may be used to determine whether the bus peer tracking
object is operating in recursive mode. <function>sd_bus_track_set_recursive()</function> may be used to enable or
disable recursive mode. By default a bus peer tracking object operates in non-recursive mode, and
<function>sd_bus_track_get_recursive()</function> for a newly allocated object hence returns a value equal to
zero. Use <function>sd_bus_track_set_recursive()</function> to enable recursive mode, right after allocation. It
takes a boolean argument to enable or disable recursive mode. Note that tracking objects for which
<function>sd_bus_track_add_name()</function> was already invoked at least once (and which hence track already one
or more peers) may not be switched from recursive to non-recursive mode anymore.</para>
<para><function>sd_bus_track_get_bus()</function> returns the bus object the bus peer tracking object belongs
to. It returns the bus object initially passed to <function>sd_bus_track_new()</function> when the object was
allocated.</para>
<para><function>sd_bus_track_get_userdata()</function> returns the generic user data pointer set on the bus peer
tracking object at the time of creation using <function>sd_bus_track_new()</function> or at a later time, using
<function>sd_bus_track_set_userdata()</function>.</para>
</refsect1>
<refsect1>
<title>Return Value</title>
<para>On success, <function>sd_bus_track_new()</function> and <function>sd_bus_track_set_recursive()</function>
return 0 or a positive integer. On failure, they return a negative errno-style error code.</para>
<para><function>sd_bus_track_ref()</function> always returns the argument.</para>
<para><function>sd_bus_track_unref()</function> always returns <constant>NULL</constant>.</para>
<para><function>sd_bus_track_get_recursive()</function> returns 0 if non-recursive mode is selected (default), and
greater than 0 if recursive mode is selected. On failure a negative errno-style error code is returned.</para>
<para><function>sd_bus_track_get_bus()</function> returns the bus object associated to the bus peer tracking
object.</para>
<para><function>sd_bus_track_get_userdata()</function> returns the generic user data pointer associated with the
bus peer tracking object. <function>sd_bus_track_set_userdata()</function> returns the previous user data pointer
set.</para>
</refsect1>
<refsect1>
<title>Reference ownership</title>
<para>The <function>sd_bus_track_new()</function> function creates a new object and the caller owns the sole
reference. When not needed anymore, this reference should be destroyed with
<function>sd_bus_track_unref()</function>.
</para>
</refsect1>
<refsect1>
<title>Errors</title>
<para>Returned errors may indicate the following problems:</para>
<variablelist>
<varlistentry>
<term><constant>-EBUSY</constant></term>
<listitem><para>Bus peers have already been added to the bus peer tracking object and
<function>sd_bus_track_set_recursive()</function> was called to change tracking mode.</para></listitem>
</varlistentry>
<varlistentry>
<term><constant>-EINVAL</constant></term>
<listitem><para>Specified parameter is invalid
(<constant>NULL</constant> in case of output
parameters).</para></listitem>
</varlistentry>
<varlistentry>
<term><constant>-ENOMEM</constant></term>
<listitem><para>Memory allocation failed.</para></listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Notes</title>
<para><function>sd_bus_track_new()</function> and the other calls described here are available as a shared library,
which can be compiled and linked to with the <constant>libsystemd</constant> <citerefentry
project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry> file.</para>
</refsect1>
<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_add_name</refentrytitle><manvolnum>3</manvolnum></citerefentry>
</para>
</refsect1>
</refentry>
|