<refnamediv>
<refname>sd_bus_slot_set_destroy_callback</refname>
<refname>sd_bus_slot_get_destroy_callback</refname>
+ <refname>sd_bus_track_set_destroy_callback</refname>
+ <refname>sd_bus_track_get_destroy_callback</refname>
+ <refname>sd_bus_destroy_t</refname>
<refpurpose>Define the callback function for resource cleanup.</refpurpose>
</refnamediv>
<paramdef>sd_bus_slot *<parameter>slot</parameter></paramdef>
<paramdef>sd_bus_destroy_t *<parameter>callback</parameter></paramdef>
</funcprototype>
+
+ <funcprototype>
+ <funcdef>int <function>sd_bus_track_set_destroy_callback</function></funcdef>
+ <paramdef>sd_bus_track *<parameter>track</parameter></paramdef>
+ <paramdef>sd_bus_destroy_t <parameter>callback</parameter></paramdef>
+ </funcprototype>
+
+ <funcprototype>
+ <funcdef>int <function>sd_bus_track_get_destroy_callback</function></funcdef>
+ <paramdef>sd_bus_track *<parameter>track</parameter></paramdef>
+ <paramdef>sd_bus_destroy_t *<parameter>callback</parameter></paramdef>
+ </funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>Description</title>
- <para><function>sd_bus_slot_set_destroy_callback()</function> sets
- <parameter>callback</parameter> as the callback function to be called right before the bus slot
- object <parameter>slot</parameter> is deallocated. The <parameter>userdata</parameter> pointer
- from the slot object will be passed as the <parameter>userdata</parameter> parameter. This
- pointer can be set specified as an argument to the constuctor functions, see
- <citerefentry><refentrytitle>sd_bus_add_match</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
- or directly, see
- <citerefentry><refentrytitle>sd_bus_set_userdata</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
- This callback function is called even if <parameter>userdata</parameter> is
- <constant>NULL</constant>.</para>
+ <para><function>sd_bus_slot_set_destroy_callback()</function> sets <parameter>callback</parameter> as the callback
+ function to be called right before the bus slot object <parameter>slot</parameter> is deallocated. The
+ <parameter>userdata</parameter> pointer from the slot object will be passed as the <parameter>userdata</parameter>
+ parameter. This pointer can be set by an argument to the constructor functions, see
+ <citerefentry><refentrytitle>sd_bus_add_match</refentrytitle><manvolnum>3</manvolnum></citerefentry>, or directly,
+ see <citerefentry><refentrytitle>sd_bus_slot_set_userdata</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
+ This callback function is called even if <parameter>userdata</parameter> is <constant>NULL</constant>. Note that
+ this callback is invoked at a time where the bus slot object itself is already invalidated, and executing
+ operations or taking new references to the bus slot object is not permissible.</para>
<para><function>sd_bus_slot_get_destroy_callback()</function> returns the current callback
for <parameter>slot</parameter> in the <parameter>callback</parameter> parameter.</para>
+
+ <para><function>sd_bus_track_set_destroy_callback()</function> and
+ <function>sd_bus_track_get_destroy_callback</function> provide equivalent functionality for the
+ <parameter>userdata</parameter> pointer associated with bus peer tracking objects. For details about bus peer
+ tracking objects, see
+ <citerefentry><refentrytitle>sd_bus_track_new</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para>
</refsect1>
<refsect1>
<title>Return Value</title>
- <para>On success, <function>sd_bus_slot_set_destroy_callback()</function> returns 0 or a
- positive integer. On failure, it returns a negative errno-style error code.</para>
+ <para>On success, <function>sd_bus_slot_set_destroy_callback()</function> and
+ <function>sd_bus_track_set_destroy_callback()</function> return 0 or a positive integer. On failure, they return a
+ negative errno-style error code.</para>
- <para><function>sd_bus_slot_get_destroy_callback()</function> returns 1 if the destroy callback
- function is set, 0 if not. On failure, it returns a negative errno-style error code.</para>
+ <para><function>sd_bus_slot_get_destroy_callback()</function> and
+ <function>sd_bus_track_get_destroy_callback</function> return positive if the destroy callback function is set, 0
+ if not. On failure, they return a negative errno-style error code.</para>
</refsect1>
<refsect1>
<varlistentry>
<term><constant>-EINVAL</constant></term>
- <listitem><para>The <parameter>slot</parameter> parameter is <constant>NULL</constant>.
- </para></listitem>
+ <listitem><para>The <parameter>slot</parameter> or <parameter>track</parameter> parameter is
+ <constant>NULL</constant>.</para></listitem>
</varlistentry>
</variablelist>
</refsect1>
<para>
<citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
- <citerefentry><refentrytitle>sd_bus_slot_set_floating</refentrytitle><manvolnum>3</manvolnum></citerefentry>
+ <citerefentry><refentrytitle>sd_bus_slot_set_floating</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
+ <citerefentry><refentrytitle>sd_bus_add_match</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
+ <citerefentry><refentrytitle>sd_bus_track_new</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
+ <citerefentry><refentrytitle>sd_bus_slot_set_userdata</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
+ <citerefentry><refentrytitle>sd_bus_track_set_userdata</refentrytitle><manvolnum>3</manvolnum></citerefentry>
</para>
</refsect1>
bool in_queue:1; /* In bus->track_queue? */
bool modified:1;
bool recursive:1;
+ sd_bus_destroy_t destroy_callback;
LIST_FIELDS(sd_bus_track, tracks);
};
return NULL;
assert(track->n_ref > 0);
+ track->n_ref--;
- if (track->n_ref > 1) {
- track->n_ref--;
+ if (track->n_ref > 0)
return NULL;
- }
if (track->in_list)
LIST_REMOVE(tracks, track->bus->tracks, track);
bus_track_remove_from_queue(track);
- hashmap_free_with_destructor(track->names, track_item_free);
- sd_bus_unref(track->bus);
+ track->names = hashmap_free_with_destructor(track->names, track_item_free);
+ track->bus = sd_bus_unref(track->bus);
+
+ if (track->destroy_callback)
+ track->destroy_callback(track->userdata);
+
return mfree(track);
}
return ret;
}
+_public_ int sd_bus_track_set_destroy_callback(sd_bus_track *track, sd_bus_destroy_t callback) {
+ assert_return(track, -EINVAL);
+
+ track->destroy_callback = callback;
+ return 0;
+}
+
+_public_ int sd_bus_track_get_destroy_callback(sd_bus_track *track, sd_bus_destroy_t *ret) {
+ assert_return(track, -EINVAL);
+
+ if (ret)
+ *ret = track->destroy_callback;
+
+ return !!track->destroy_callback;
+}
+
_public_ int sd_bus_track_set_recursive(sd_bus_track *track, int b) {
assert_return(track, -EINVAL);