chiark / gitweb /
sd-login: read list of uids of sessions from UIDS not ACTIVE_SESSIONS
[elogind.git] / man / sd_bus_track_new.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   This file is part of systemd.
7
8   Copyright 2016 Lennart Poettering
9
10   systemd is free software; you can redistribute it and/or modify it
11   under the terms of the GNU Lesser General Public License as published by
12   the Free Software Foundation; either version 2.1 of the License, or
13   (at your option) any later version.
14
15   systemd is distributed in the hope that it will be useful, but
16   WITHOUT ANY WARRANTY; without even the implied warranty of
17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18   Lesser General Public License for more details.
19
20   You should have received a copy of the GNU Lesser General Public License
21   along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 -->
23
24 <refentry id="sd_bus_track_new">
25
26   <refentryinfo>
27     <title>sd_bus_track_new</title>
28     <productname>systemd</productname>
29
30     <authorgroup>
31       <author>
32         <contrib>Developer</contrib>
33         <firstname>Lennart</firstname>
34         <surname>Poettering</surname>
35         <email>lennart@poettering.net</email>
36       </author>
37     </authorgroup>
38   </refentryinfo>
39
40   <refmeta>
41     <refentrytitle>sd_bus_track_new</refentrytitle>
42     <manvolnum>3</manvolnum>
43   </refmeta>
44
45   <refnamediv>
46     <refname>sd_bus_track_new</refname>
47     <refname>sd_bus_track_ref</refname>
48     <refname>sd_bus_track_unref</refname>
49     <refname>sd_bus_track_unrefp</refname>
50     <refname>sd_bus_track_set_recursive</refname>
51     <refname>sd_bus_track_get_recursive</refname>
52     <refname>sd_bus_track_get_bus</refname>
53     <refname>sd_bus_track_get_userdata</refname>
54     <refname>sd_bus_track_set_userdata</refname>
55
56     <refpurpose>Track bus peers</refpurpose>
57   </refnamediv>
58
59   <refsynopsisdiv>
60     <funcsynopsis>
61       <funcsynopsisinfo>#include &lt;systemd/sd-bus.h&gt;</funcsynopsisinfo>
62
63       <funcprototype>
64         <funcdef>int <function>sd_bus_track_new</function></funcdef>
65         <paramdef>sd_bus* <parameter>bus</parameter></paramdef>
66         <paramdef>sd_bus_track** <parameter>ret</parameter></paramdef>
67         <paramdef>sd_bus_track_handler_t <parameter>handler</parameter></paramdef>
68         <paramdef>void* <parameter>userdata</parameter></paramdef>
69       </funcprototype>
70
71       <funcprototype>
72         <funcdef>sd_bus_track *<function>sd_bus_track_ref</function></funcdef>
73         <paramdef>sd_bus_track *<parameter>t</parameter></paramdef>
74       </funcprototype>
75
76       <funcprototype>
77         <funcdef>sd_bus_track *<function>sd_bus_track_unref</function></funcdef>
78         <paramdef>sd_bus_track *<parameter>t</parameter></paramdef>
79       </funcprototype>
80
81       <funcprototype>
82         <funcdef>void <function>sd_bus_track_unrefp</function></funcdef>
83         <paramdef>sd_bus_track **<parameter>t</parameter></paramdef>
84       </funcprototype>
85
86       <funcprototype>
87         <funcdef>int <function>sd_bus_track_get_recursive</function></funcdef>
88         <paramdef>sd_bus_track *<parameter>t</parameter></paramdef>
89       </funcprototype>
90
91       <funcprototype>
92         <funcdef>int <function>sd_bus_track_set_recursive</function></funcdef>
93         <paramdef>sd_bus_track *<parameter>t</parameter></paramdef>
94         <paramdef>int <parameter>b</parameter></paramdef>
95       </funcprototype>
96
97       <funcprototype>
98         <funcdef>sd_bus* <function>sd_bus_track_get_bus</function></funcdef>
99         <paramdef>sd_bus_track *<parameter>t</parameter></paramdef>
100       </funcprototype>
101
102       <funcprototype>
103         <funcdef>void* <function>sd_bus_track_get_userdata</function></funcdef>
104         <paramdef>sd_bus_track *<parameter>t</parameter></paramdef>
105       </funcprototype>
106
107       <funcprototype>
108         <funcdef>void* <function>sd_bus_track_set_userdata</function></funcdef>
109         <paramdef>sd_bus_track *<parameter>t</parameter></paramdef>
110         <paramdef>void *userdata</paramdef>
111       </funcprototype>
112
113     </funcsynopsis>
114   </refsynopsisdiv>
115
116   <refsect1>
117     <title>Description</title>
118
119     <para><function>sd_bus_track_new()</function> creates a new bus peer tracking object. The object is allocated for
120     the specified bus, and returned in the <parameter>*ret</parameter> parameter. After use, the object should be freed
121     again by dropping the acquired reference with <function>sd_bus_track_unref()</function> (see below). A bus peer
122     tracking object may be used to keep track of peers on a specific IPC bus, for cases where peers are making use of
123     one or more local objects, in order to control the lifecycle of the local objects and ensure they stay around as
124     long as the peers needing them are around, and unreferenced (and possibly destroyed) as soon as all relevant peers
125     have vanished. Each bus peer tracking object may be used to track zero, one or more peers add a time. References to
126     specific bus peers are added via
127     <citerefentry><refentrytitle>sd_bus_track_add_name</refentrytitle><manvolnum>3</manvolnum></citerefentry> or
128     <function>sd_bus_track_add_sender()</function>. They may be dropped again via
129     <function>sd_bus_track_remove_name()</function> and
130     <function>sd_bus_track_remove_sender()</function>. Alternatively, references on peers are removed automatically
131     when they disconnect from the bus.  If non-NULL the <parameter>handler</parameter> may specify a function that is
132     invoked whenever the last reference is dropped, regardless whether the reference is dropped explicitly via
133     <function>sd_bus_track_remove_name()</function> or implicitly because the peer disconnected from the bus. The final
134     argument <parameter>userdata</parameter> may be used to attach a generic user data pointer to the object. This
135     pointer is passed to the handler callback when it is invoked.</para>
136
137     <para><function>sd_bus_track_ref()</function> creates a new reference to a bus peer tracking object. This object
138     will not be destroyed until <function>sd_bus_track_unref()</function> has been called as many times plus once
139     more. Once the reference count has dropped to zero, the specified object cannot be used anymore, further calls to
140     <function>sd_bus_track_ref()</function> or <function>sd_bus_track_unref()</function> on the same object are
141     illegal.</para>
142
143     <para><function>sd_bus_track_unref()</function> destroys a reference to a bus peer tracking object.</para>
144
145     <para><function>sd_bus_track_unrefp()</function> is similar to <function>sd_bus_track_unref()</function> but takes
146     a pointer to a pointer to an <type>sd_bus_track</type> object. This call is useful in conjunction with GCC's and
147     LLVM's <ulink url="https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html">Clean-up Variable
148     Attribute</ulink>. Note that this function is defined as inline function.</para>
149
150     <para><function>sd_bus_track_ref()</function>, <function>sd_bus_track_unref()</function> and
151     <function>sd_bus_track_unrefp()</function> execute no operation if the passed in bus peer tracking object is
152     <constant>NULL</constant>.</para>
153
154     <para>Bus peer tracking objects may exist in two modes: by default they operate in non-recursive mode, but may
155     optionally be switched into recursive mode. If operating in the default non-recursive mode a peer is either tracked
156     or not tracked. In this mode invoking <function>sd_bus_track_add_name()</function> multiple times in a row for the
157     same peer is fully equivalent to calling it just once, as the call adds the peer to the set of tracked peers if
158     necessary, and executes no operation if the peer is already being tracked. A single invocation of
159     <function>sd_bus_track_remove_name()</function> removes the reference on the peer again, regardless how many times
160     <function>sd_bus_track_add_name()</function> was called before. If operating in recursive mode, the number of times
161     <function>sd_bus_track_add_name()</function> is invoked for the same peer name is counted and
162     <function>sd_bus_track_remove_name()</function> must be called the same number of times before the peer is not
163     tracked anymore, with the exception when the tracked peer vanishes from the bus, in which case the count is
164     irrelevant and the tracking of the specific peer is immediately
165     removed. <function>sd_bus_track_get_recursive()</function> may be used to determine whether the bus peer tracking
166     object is operating in recursive mode. <function>sd_bus_track_set_recursive()</function> may be used to enable or
167     disable recursive mode. By default a bus peer tracking object operates in non-recursive mode, and
168     <function>sd_bus_track_get_recursive()</function> for a newly allocated object hence returns a value equal to
169     zero. Use <function>sd_bus_track_set_recursive()</function> to enable recursive mode, right after allocation. It
170     takes a boolean argument to enable or disable recursive mode. Note that tracking objects for which
171     <function>sd_bus_track_add_name()</function> was already invoked at least once (and which hence track already one
172     or more peers) may not be switched from recursive to non-recursive mode anymore.</para>
173
174     <para><function>sd_bus_track_get_bus()</function> returns the bus object the bus peer tracking object belongs
175     to. It returns the bus object initially passed to <function>sd_bus_track_new()</function> when the object was
176     allocated.</para>
177
178     <para><function>sd_bus_track_get_userdata()</function> returns the generic user data pointer set on the bus peer
179     tracking object at the time of creation using <function>sd_bus_track_new()</function> or at a later time, using
180     <function>sd_bus_track_set_userdata()</function>.</para>
181   </refsect1>
182
183   <refsect1>
184     <title>Return Value</title>
185
186     <para>On success, <function>sd_bus_track_new()</function> and <function>sd_bus_track_set_recursive()</function>
187     return 0 or a positive integer. On failure, they return a negative errno-style error code.</para>
188
189     <para><function>sd_bus_track_ref()</function> always returns the argument.</para>
190
191     <para><function>sd_bus_track_unref()</function> always returns <constant>NULL</constant>.</para>
192
193     <para><function>sd_bus_track_get_recursive()</function> returns 0 if non-recursive mode is selected (default), and
194     greater than 0 if recursive mode is selected. On failure a negative errno-style error code is returned.</para>
195
196     <para><function>sd_bus_track_get_bus()</function> returns the bus object associated to the bus peer tracking
197     object.</para>
198
199     <para><function>sd_bus_track_get_userdata()</function> returns the generic user data pointer associated with the
200     bus peer tracking object. <function>sd_bus_track_set_userdata()</function> returns the previous user data pointer
201     set.</para>
202
203   </refsect1>
204
205   <refsect1>
206     <title>Reference ownership</title>
207
208     <para>The <function>sd_bus_track_new()</function> function creates a new object and the caller owns the sole
209     reference. When not needed anymore, this reference should be destroyed with
210     <function>sd_bus_track_unref()</function>.
211     </para>
212   </refsect1>
213
214   <refsect1>
215     <title>Errors</title>
216
217     <para>Returned errors may indicate the following problems:</para>
218
219     <variablelist>
220
221       <varlistentry>
222         <term><constant>-EBUSY</constant></term>
223
224         <listitem><para>Bus peers have already been added to the bus peer tracking object and
225         <function>sd_bus_track_set_recursive()</function> was called to change tracking mode.</para></listitem>
226       </varlistentry>
227
228       <varlistentry>
229         <term><constant>-EINVAL</constant></term>
230
231         <listitem><para>Specified parameter is invalid
232         (<constant>NULL</constant> in case of output
233         parameters).</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_new()</function> and the other calls described here are available as a shared library,
249     which can be compiled and linked to with the <constant>libelogind</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_add_name</refentrytitle><manvolnum>3</manvolnum></citerefentry>
260     </para>
261   </refsect1>
262
263 </refentry>