| 1 |
<?xml version='1.0'?> |
| 2 |
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" |
| 3 |
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"> |
| 4 |
<!-- SPDX-License-Identifier: LGPL-2.1-or-later --> |
| 5 |
|
| 6 |
<refentry id="sd_bus_track_new" xmlns:xi="http://www.w3.org/2001/XInclude"> |
| 7 |
|
| 8 |
<refentryinfo> |
| 9 |
<title>sd_bus_track_new</title> |
| 10 |
<productname>systemd</productname> |
| 11 |
</refentryinfo> |
| 12 |
|
| 13 |
<refmeta> |
| 14 |
<refentrytitle>sd_bus_track_new</refentrytitle> |
| 15 |
<manvolnum>3</manvolnum> |
| 16 |
</refmeta> |
| 17 |
|
| 18 |
<refnamediv> |
| 19 |
<refname>sd_bus_track_new</refname> |
| 20 |
<refname>sd_bus_track_ref</refname> |
| 21 |
<refname>sd_bus_track_unref</refname> |
| 22 |
<refname>sd_bus_track_unrefp</refname> |
| 23 |
<refname>sd_bus_track_set_recursive</refname> |
| 24 |
<refname>sd_bus_track_get_recursive</refname> |
| 25 |
<refname>sd_bus_track_get_bus</refname> |
| 26 |
<refname>sd_bus_track_get_userdata</refname> |
| 27 |
<refname>sd_bus_track_set_userdata</refname> |
| 28 |
|
| 29 |
<refpurpose>Track bus peers</refpurpose> |
| 30 |
</refnamediv> |
| 31 |
|
| 32 |
<refsynopsisdiv> |
| 33 |
<funcsynopsis> |
| 34 |
<funcsynopsisinfo>#include <systemd/sd-bus.h></funcsynopsisinfo> |
| 35 |
|
| 36 |
<funcprototype> |
| 37 |
<funcdef>typedef int (*<function>sd_bus_track_handler_t</function>)</funcdef> |
| 38 |
<paramdef>sd_bus_track *<parameter>track</parameter></paramdef> |
| 39 |
<paramdef>void *<parameter>userdata</parameter></paramdef> |
| 40 |
</funcprototype> |
| 41 |
|
| 42 |
<funcprototype> |
| 43 |
<funcdef>int <function>sd_bus_track_new</function></funcdef> |
| 44 |
<paramdef>sd_bus* <parameter>bus</parameter></paramdef> |
| 45 |
<paramdef>sd_bus_track** <parameter>ret</parameter></paramdef> |
| 46 |
<paramdef>sd_bus_track_handler_t <parameter>handler</parameter></paramdef> |
| 47 |
<paramdef>void* <parameter>userdata</parameter></paramdef> |
| 48 |
</funcprototype> |
| 49 |
|
| 50 |
<funcprototype> |
| 51 |
<funcdef>sd_bus_track *<function>sd_bus_track_ref</function></funcdef> |
| 52 |
<paramdef>sd_bus_track *<parameter>t</parameter></paramdef> |
| 53 |
</funcprototype> |
| 54 |
|
| 55 |
<funcprototype> |
| 56 |
<funcdef>sd_bus_track *<function>sd_bus_track_unref</function></funcdef> |
| 57 |
<paramdef>sd_bus_track *<parameter>t</parameter></paramdef> |
| 58 |
</funcprototype> |
| 59 |
|
| 60 |
<funcprototype> |
| 61 |
<funcdef>void <function>sd_bus_track_unrefp</function></funcdef> |
| 62 |
<paramdef>sd_bus_track **<parameter>t</parameter></paramdef> |
| 63 |
</funcprototype> |
| 64 |
|
| 65 |
<funcprototype> |
| 66 |
<funcdef>int <function>sd_bus_track_get_recursive</function></funcdef> |
| 67 |
<paramdef>sd_bus_track *<parameter>t</parameter></paramdef> |
| 68 |
</funcprototype> |
| 69 |
|
| 70 |
<funcprototype> |
| 71 |
<funcdef>int <function>sd_bus_track_set_recursive</function></funcdef> |
| 72 |
<paramdef>sd_bus_track *<parameter>t</parameter></paramdef> |
| 73 |
<paramdef>int <parameter>b</parameter></paramdef> |
| 74 |
</funcprototype> |
| 75 |
|
| 76 |
<funcprototype> |
| 77 |
<funcdef>sd_bus* <function>sd_bus_track_get_bus</function></funcdef> |
| 78 |
<paramdef>sd_bus_track *<parameter>t</parameter></paramdef> |
| 79 |
</funcprototype> |
| 80 |
|
| 81 |
<funcprototype> |
| 82 |
<funcdef>void* <function>sd_bus_track_get_userdata</function></funcdef> |
| 83 |
<paramdef>sd_bus_track *<parameter>t</parameter></paramdef> |
| 84 |
</funcprototype> |
| 85 |
|
| 86 |
<funcprototype> |
| 87 |
<funcdef>void* <function>sd_bus_track_set_userdata</function></funcdef> |
| 88 |
<paramdef>sd_bus_track *<parameter>t</parameter></paramdef> |
| 89 |
<paramdef>void *userdata</paramdef> |
| 90 |
</funcprototype> |
| 91 |
|
| 92 |
</funcsynopsis> |
| 93 |
</refsynopsisdiv> |
| 94 |
|
| 95 |
<refsect1> |
| 96 |
<title>Description</title> |
| 97 |
|
| 98 |
<para><function>sd_bus_track_new()</function> creates a new bus peer tracking object. The object is allocated for |
| 99 |
the specified bus, and returned in the <parameter>*ret</parameter> parameter. After use, the object should be freed |
| 100 |
again by dropping the acquired reference with <function>sd_bus_track_unref()</function> (see below). A bus peer |
| 101 |
tracking object may be used to keep track of peers on a specific IPC bus, for cases where peers are making use of |
| 102 |
one or more local objects, in order to control the lifecycle of the local objects and ensure they stay around as |
| 103 |
long as the peers needing them are around, and unreferenced (and possibly destroyed) as soon as all relevant peers |
| 104 |
have vanished. Each bus peer tracking object may be used to track zero, one or more peers add a time. References to |
| 105 |
specific bus peers are added via |
| 106 |
<citerefentry><refentrytitle>sd_bus_track_add_name</refentrytitle><manvolnum>3</manvolnum></citerefentry> or |
| 107 |
<function>sd_bus_track_add_sender()</function>. They may be dropped again via |
| 108 |
<function>sd_bus_track_remove_name()</function> and |
| 109 |
<function>sd_bus_track_remove_sender()</function>. Alternatively, references on peers are removed automatically |
| 110 |
when they disconnect from the bus. If non-<constant>NULL</constant> the <parameter>handler</parameter> may specify |
| 111 |
a function that is invoked whenever the last reference is dropped, regardless whether the reference is dropped |
| 112 |
explicitly via <function>sd_bus_track_remove_name()</function> or implicitly because the peer disconnected from the |
| 113 |
bus. The final argument <parameter>userdata</parameter> may be used to attach a generic user data pointer to the |
| 114 |
object. This pointer is passed to the handler callback when it is invoked.</para> |
| 115 |
|
| 116 |
<para><function>sd_bus_track_ref()</function> creates a new reference to a bus peer tracking object. This object |
| 117 |
will not be destroyed until <function>sd_bus_track_unref()</function> has been called as many times plus once |
| 118 |
more. Once the reference count has dropped to zero, the specified object cannot be used anymore, further calls to |
| 119 |
<function>sd_bus_track_ref()</function> or <function>sd_bus_track_unref()</function> on the same object are |
| 120 |
illegal.</para> |
| 121 |
|
| 122 |
<para><function>sd_bus_track_unref()</function> destroys a reference to a bus peer tracking object.</para> |
| 123 |
|
| 124 |
<para><function>sd_bus_track_unrefp()</function> is similar to <function>sd_bus_track_unref()</function> but takes |
| 125 |
a pointer to a pointer to an <type>sd_bus_track</type> object. This call is useful in conjunction with GCC's and |
| 126 |
LLVM's <ulink url="https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html">Clean-up Variable |
| 127 |
Attribute</ulink>. Note that this function is defined as inline function.</para> |
| 128 |
|
| 129 |
<para><function>sd_bus_track_ref()</function>, <function>sd_bus_track_unref()</function> and |
| 130 |
<function>sd_bus_track_unrefp()</function> execute no operation if the passed in bus peer tracking object is |
| 131 |
<constant>NULL</constant>.</para> |
| 132 |
|
| 133 |
<para>Bus peer tracking objects may exist in two modes: by default they operate in non-recursive mode, but may |
| 134 |
optionally be switched into recursive mode. If operating in the default non-recursive mode a peer is either tracked |
| 135 |
or not tracked. In this mode invoking <function>sd_bus_track_add_name()</function> multiple times in a row for the |
| 136 |
same peer is fully equivalent to calling it just once, as the call adds the peer to the set of tracked peers if |
| 137 |
necessary, and executes no operation if the peer is already being tracked. A single invocation of |
| 138 |
<function>sd_bus_track_remove_name()</function> removes the reference on the peer again, regardless how many times |
| 139 |
<function>sd_bus_track_add_name()</function> was called before. If operating in recursive mode, the number of times |
| 140 |
<function>sd_bus_track_add_name()</function> is invoked for the same peer name is counted and |
| 141 |
<function>sd_bus_track_remove_name()</function> must be called the same number of times before the peer is not |
| 142 |
tracked anymore, with the exception when the tracked peer vanishes from the bus, in which case the count is |
| 143 |
irrelevant and the tracking of the specific peer is immediately |
| 144 |
removed. <function>sd_bus_track_get_recursive()</function> may be used to determine whether the bus peer tracking |
| 145 |
object is operating in recursive mode. <function>sd_bus_track_set_recursive()</function> may be used to enable or |
| 146 |
disable recursive mode. By default, a bus peer tracking object operates in non-recursive mode, and |
| 147 |
<function>sd_bus_track_get_recursive()</function> for a newly allocated object hence returns a value equal to |
| 148 |
zero. Use <function>sd_bus_track_set_recursive()</function> to enable recursive mode, right after allocation. It |
| 149 |
takes a boolean argument to enable or disable recursive mode. Note that tracking objects for which |
| 150 |
<function>sd_bus_track_add_name()</function> was already invoked at least once (and which hence track already one |
| 151 |
or more peers) may not be switched from recursive to non-recursive mode anymore.</para> |
| 152 |
|
| 153 |
<para><function>sd_bus_track_get_bus()</function> returns the bus object the bus peer tracking object belongs |
| 154 |
to. It returns the bus object initially passed to <function>sd_bus_track_new()</function> when the object was |
| 155 |
allocated.</para> |
| 156 |
|
| 157 |
<para><function>sd_bus_track_get_userdata()</function> returns the generic user data pointer set on the bus peer |
| 158 |
tracking object at the time of creation using <function>sd_bus_track_new()</function> or at a later time, using |
| 159 |
<function>sd_bus_track_set_userdata()</function>.</para> |
| 160 |
</refsect1> |
| 161 |
|
| 162 |
<refsect1> |
| 163 |
<title>Return Value</title> |
| 164 |
|
| 165 |
<para>On success, <function>sd_bus_track_new()</function> and <function>sd_bus_track_set_recursive()</function> |
| 166 |
return 0 or a positive integer. On failure, they return a negative errno-style error code.</para> |
| 167 |
|
| 168 |
<para><function>sd_bus_track_ref()</function> always returns the argument.</para> |
| 169 |
|
| 170 |
<para><function>sd_bus_track_unref()</function> always returns <constant>NULL</constant>.</para> |
| 171 |
|
| 172 |
<para><function>sd_bus_track_get_recursive()</function> returns 0 if non-recursive mode is selected (default), and |
| 173 |
greater than 0 if recursive mode is selected. On failure a negative errno-style error code is returned.</para> |
| 174 |
|
| 175 |
<para><function>sd_bus_track_get_bus()</function> returns the bus object associated to the bus peer tracking |
| 176 |
object.</para> |
| 177 |
|
| 178 |
<para><function>sd_bus_track_get_userdata()</function> returns the generic user data pointer associated with the |
| 179 |
bus peer tracking object. <function>sd_bus_track_set_userdata()</function> returns the previous user data pointer |
| 180 |
set.</para> |
| 181 |
|
| 182 |
</refsect1> |
| 183 |
|
| 184 |
<refsect1> |
| 185 |
<title>Reference ownership</title> |
| 186 |
|
| 187 |
<para>The <function>sd_bus_track_new()</function> function creates a new object and the caller owns the sole |
| 188 |
reference. When not needed anymore, this reference should be destroyed with |
| 189 |
<function>sd_bus_track_unref()</function>. |
| 190 |
</para> |
| 191 |
|
| 192 |
<refsect2> |
| 193 |
<title>Errors</title> |
| 194 |
|
| 195 |
<para>Returned errors may indicate the following problems:</para> |
| 196 |
|
| 197 |
<variablelist> |
| 198 |
|
| 199 |
<varlistentry> |
| 200 |
<term><constant>-EBUSY</constant></term> |
| 201 |
|
| 202 |
<listitem><para>Bus peers have already been added to the bus peer tracking object and |
| 203 |
<function>sd_bus_track_set_recursive()</function> was called to change tracking mode. |
| 204 |
</para></listitem> |
| 205 |
</varlistentry> |
| 206 |
|
| 207 |
<varlistentry> |
| 208 |
<term><constant>-EINVAL</constant></term> |
| 209 |
|
| 210 |
<listitem><para>Specified parameter is invalid |
| 211 |
(<constant>NULL</constant> in case of output |
| 212 |
parameters).</para></listitem> |
| 213 |
</varlistentry> |
| 214 |
|
| 215 |
<varlistentry> |
| 216 |
<term><constant>-ENOMEM</constant></term> |
| 217 |
|
| 218 |
<listitem><para>Memory allocation failed.</para></listitem> |
| 219 |
</varlistentry> |
| 220 |
|
| 221 |
</variablelist> |
| 222 |
</refsect2> |
| 223 |
</refsect1> |
| 224 |
|
| 225 |
<xi:include href="libsystemd-pkgconfig.xml" /> |
| 226 |
|
| 227 |
<refsect1> |
| 228 |
<title>History</title> |
| 229 |
<para><function>sd_bus_track_new()</function>, |
| 230 |
<function>sd_bus_track_handler_t()</function>, |
| 231 |
<function>sd_bus_track_ref()</function>, |
| 232 |
<function>sd_bus_track_unref()</function>, |
| 233 |
<function>sd_bus_track_unrefp()</function>, |
| 234 |
<function>sd_bus_track_get_recursive()</function>, |
| 235 |
<function>sd_bus_track_set_recursive()</function>, |
| 236 |
<function>sd_bus_track_get_bus()</function>, |
| 237 |
<function>sd_bus_track_get_userdata()</function>, and |
| 238 |
<function>sd_bus_track_set_userdata()</function> were added in version 232.</para> |
| 239 |
</refsect1> |
| 240 |
|
| 241 |
<refsect1> |
| 242 |
<title>See Also</title> |
| 243 |
|
| 244 |
<para><simplelist type="inline"> |
| 245 |
<member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> |
| 246 |
<member><citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 247 |
<member><citerefentry><refentrytitle>sd_bus_track_add_name</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 248 |
</simplelist></para> |
| 249 |
</refsect1> |
| 250 |
|
| 251 |
</refentry> |