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