Lines Matching defs:track
24 #include "bus-track.h"
59 static void bus_track_add_to_queue(sd_bus_track *track) {
60 assert(track);
62 if (track->in_queue)
65 if (!track->handler)
68 LIST_PREPEND(queue, track->bus->track_queue, track);
69 track->in_queue = true;
72 static void bus_track_remove_from_queue(sd_bus_track *track) {
73 assert(track);
75 if (!track->in_queue)
78 LIST_REMOVE(queue, track->bus->track_queue, track);
79 track->in_queue = false;
84 sd_bus_track **track,
91 assert_return(track, -EINVAL);
107 *track = t;
111 _public_ sd_bus_track* sd_bus_track_ref(sd_bus_track *track) {
113 if (!track)
116 assert(track->n_ref > 0);
118 track->n_ref++;
120 return track;
123 _public_ sd_bus_track* sd_bus_track_unref(sd_bus_track *track) {
126 if (!track)
129 assert(track->n_ref > 0);
131 if (track->n_ref > 1) {
132 track->n_ref --;
136 while ((n = hashmap_first_key(track->names)))
137 sd_bus_track_remove_name(track, n);
139 bus_track_remove_from_queue(track);
140 hashmap_free(track->names);
141 sd_bus_unref(track->bus);
142 free(track);
148 sd_bus_track *track = userdata;
153 assert(track);
159 sd_bus_track_remove_name(track, name);
163 _public_ int sd_bus_track_add_name(sd_bus_track *track, const char *name) {
169 assert_return(track, -EINVAL);
172 r = hashmap_ensure_allocated(&track->names, &string_hash_ops);
182 r = sd_bus_add_match(track->bus, &slot, match, on_name_owner_changed, track);
186 r = hashmap_put(track->names, n, slot);
194 r = sd_bus_get_name_creds(track->bus, n, 0, NULL);
196 hashmap_remove(track->names, n);
203 bus_track_remove_from_queue(track);
204 track->modified = true;
209 _public_ int sd_bus_track_remove_name(sd_bus_track *track, const char *name) {
215 if (!track)
218 slot = hashmap_remove2(track->names, (char*) name, (void**) &n);
222 if (hashmap_isempty(track->names))
223 bus_track_add_to_queue(track);
225 track->modified = true;
230 _public_ unsigned sd_bus_track_count(sd_bus_track *track) {
231 if (!track)
234 return hashmap_size(track->names);
237 _public_ const char* sd_bus_track_contains(sd_bus_track *track, const char *name) {
238 assert_return(track, NULL);
241 return hashmap_get(track->names, (void*) name) ? name : NULL;
244 _public_ const char* sd_bus_track_first(sd_bus_track *track) {
247 if (!track)
250 track->modified = false;
251 track->iterator = ITERATOR_FIRST;
253 hashmap_iterate(track->names, &track->iterator, NULL, (const void**) &n);
257 _public_ const char* sd_bus_track_next(sd_bus_track *track) {
260 if (!track)
263 if (track->modified)
266 hashmap_iterate(track->names, &track->iterator, NULL, (const void**) &n);
270 _public_ int sd_bus_track_add_sender(sd_bus_track *track, sd_bus_message *m) {
273 assert_return(track, -EINVAL);
280 return sd_bus_track_add_name(track, sender);
283 _public_ int sd_bus_track_remove_sender(sd_bus_track *track, sd_bus_message *m) {
286 assert_return(track, -EINVAL);
293 return sd_bus_track_remove_name(track, sender);
296 _public_ sd_bus* sd_bus_track_get_bus(sd_bus_track *track) {
297 assert_return(track, NULL);
299 return track->bus;
302 void bus_track_dispatch(sd_bus_track *track) {
305 assert(track);
306 assert(track->in_queue);
307 assert(track->handler);
309 bus_track_remove_from_queue(track);
311 sd_bus_track_ref(track);
313 r = track->handler(track, track->userdata);
315 log_debug_errno(r, "Failed to process track handler: %m");
317 bus_track_add_to_queue(track);
319 sd_bus_track_unref(track);
322 _public_ void *sd_bus_track_get_userdata(sd_bus_track *track) {
323 assert_return(track, NULL);
325 return track->userdata;
328 _public_ void *sd_bus_track_set_userdata(sd_bus_track *track, void *userdata) {
331 assert_return(track, NULL);
333 ret = track->userdata;
334 track->userdata = userdata;