chiark / gitweb /
tree-wide: drop 'This file is part of systemd' blurb
[elogind.git] / src / libelogind / sd-bus / bus-track.c
index 0dd06e9b99a85199dd72a4cef7515398004c0238..846556cb36096666ef6e293b6e12fce15f103e27 100644 (file)
@@ -1,21 +1,6 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
 /***
-  This file is part of systemd.
-
   Copyright 2013 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/>.
 ***/
 
 #include "sd-bus.h"
@@ -44,6 +29,7 @@ struct sd_bus_track {
         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);
 };
@@ -136,6 +122,7 @@ _public_ int sd_bus_track_new(
         sd_bus_track *t;
 
         assert_return(bus, -EINVAL);
+        assert_return(bus = bus_resolve(bus), -ENOPKG);
         assert_return(track, -EINVAL);
 
         if (!bus->bus_client)
@@ -176,18 +163,21 @@ _public_ sd_bus_track* sd_bus_track_unref(sd_bus_track *track) {
                 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);
 }
 
@@ -451,6 +441,22 @@ _public_ void *sd_bus_track_set_userdata(sd_bus_track *track, void *userdata) {
         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);