From 54197114092074d86bcb8eee9eefc60fe8af4344 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Wed, 13 Jan 2016 08:18:03 -0500 Subject: [PATCH] core/queue: Add qop_deinit() queue operation This function is used to notify a higher layer that a queue is being deinitialized. The higher layer should then clean up any state associated with that queue. Signed-off-by: Anna Schumaker --- core/queue.c | 7 +++++++ gui/collection_tab.cpp | 5 +++++ gui/history.cpp | 5 +++++ gui/playlist_tab.cpp | 5 +++++ gui/tabs.cpp | 6 ++++++ include/core/queue.h | 3 +++ tests/core/queue.c | 13 +++++++++++++ 7 files changed, 44 insertions(+) diff --git a/core/queue.c b/core/queue.c index 2fd3fdce..b594a1d2 100644 --- a/core/queue.c +++ b/core/queue.c @@ -36,6 +36,12 @@ static inline void *__queue_init(struct queue *queue) return NULL; } +static inline void __queue_deinit(struct queue *queue) +{ + if (queue->q_ops) + queue->q_ops->qop_deinit(queue); +} + static inline unsigned int __queue_added(struct queue *queue, struct track *track, unsigned int pos) @@ -104,6 +110,7 @@ void queue_init(struct queue *queue, unsigned int flags, void queue_deinit(struct queue *queue) { queue_clear(queue); + __queue_deinit(queue); g_slist_free(queue->q_sort); queue->q_sort = NULL; } diff --git a/gui/collection_tab.cpp b/gui/collection_tab.cpp index 685d38a5..0575d95f 100644 --- a/gui/collection_tab.cpp +++ b/gui/collection_tab.cpp @@ -58,6 +58,10 @@ static void *collection_init(struct queue *queue) return collection_tab; } +static void collection_deinit(struct queue *queue) +{ +} + static void collection_added(struct queue *queue, unsigned int pos) { if (collection_tab) @@ -84,6 +88,7 @@ static void collection_updated(struct queue *queue, unsigned int pos) struct queue_ops collection_ops = { collection_init, + collection_deinit, collection_added, collection_removed, collection_cleared, diff --git a/gui/history.cpp b/gui/history.cpp index 25a693c9..d4deadee 100644 --- a/gui/history.cpp +++ b/gui/history.cpp @@ -43,6 +43,10 @@ static void *history_init(struct queue *queue) return history_tab; } +static void history_deinit(struct queue *queue) +{ +} + static void history_added(struct queue *queue, unsigned int pos) { if (history_tab) @@ -66,6 +70,7 @@ static void history_updated(struct queue *queue, unsigned int pos) struct queue_ops history_ops = { history_init, + history_deinit, history_added, history_removed, history_cleared, diff --git a/gui/playlist_tab.cpp b/gui/playlist_tab.cpp index 44f1c963..5de7146b 100644 --- a/gui/playlist_tab.cpp +++ b/gui/playlist_tab.cpp @@ -89,6 +89,10 @@ static void *playlist_init(struct queue *queue) return p_tab; } +static void playlist_deinit(struct queue *queue) +{ +} + static void playlist_added(struct queue *queue, unsigned int pos) { if (p_tab) @@ -112,6 +116,7 @@ static void playlist_updated(struct queue *queue, unsigned int pos) struct queue_ops playlist_ops = { playlist_init, + playlist_deinit, playlist_added, playlist_removed, playlist_cleared, diff --git a/gui/tabs.cpp b/gui/tabs.cpp index 3481557a..5325cbb7 100644 --- a/gui/tabs.cpp +++ b/gui/tabs.cpp @@ -28,6 +28,11 @@ static void *tempq_init(struct queue *queue) return NULL; } +static void tempq_deinit(struct queue *queue) +{ + +} + static void tempq_added(struct queue *queue, unsigned int pos) { find_tab(queue)->on_track_added(pos); @@ -52,6 +57,7 @@ static void tempq_updated(struct queue *queue, unsigned int pos) struct queue_ops tempq_ops = { tempq_init, + tempq_deinit, tempq_added, tempq_removed, tempq_cleared, diff --git a/include/core/queue.h b/include/core/queue.h index ccb6fd1e..7f6d10f8 100644 --- a/include/core/queue.h +++ b/include/core/queue.h @@ -30,6 +30,9 @@ struct queue_ops { /* Called to tell a higher layer that a queue has been initialized. */ void *(*qop_init)(struct queue *); + /* Called to tell a higher layer that a queue is deinitializing. */ + void (*qop_deinit)(struct queue *); + /* Called to tell a higher layer that a track has been added. */ void (*qop_added)(struct queue *, unsigned int); diff --git a/tests/core/queue.c b/tests/core/queue.c index 22899d40..00e1c737 100644 --- a/tests/core/queue.c +++ b/tests/core/queue.c @@ -9,6 +9,7 @@ unsigned int count_init = 0; +unsigned int count_deinit = 0; unsigned int count_added = 0; unsigned int count_deleted = 0; unsigned int count_cleared = 0; @@ -23,6 +24,11 @@ static void *queue_op_init(struct queue *queue) return GUINT_TO_POINTER(count_init); } +static void queue_op_deinit(struct queue *queue) +{ + count_deinit++; +} + static void queue_op_added(struct queue *queue, unsigned int pos) { count_added++; @@ -54,6 +60,7 @@ static void queue_op_updated(struct queue *queue, unsigned int pos) static const struct queue_ops test_ops = { .qop_init = queue_op_init, + .qop_deinit = queue_op_deinit, .qop_added = queue_op_added, .qop_removed = queue_op_removed, .qop_cleared = queue_op_cleared, @@ -109,6 +116,9 @@ static void test_init() test_equal((void *)q.q_ops, NULL); test_equal((void *)queue_next(&q), (void *)NULL); + queue_deinit(&q); + test_equal(count_deinit, 0); + queue_init(&q, Q_ENABLED | Q_RANDOM, &test_ops); test_equal(count_init, 1); test_equal(GPOINTER_TO_UINT(q.q_private), 1); @@ -119,6 +129,9 @@ static void test_init() test_equal((void *)q.q_sort, NULL); test_equal((void *)q.q_ops, (void *)&test_ops); test_equal((void *)queue_next(&q), (void *)NULL); + + queue_deinit(&q); + test_equal(count_deinit, 1); } static void test_flags()