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 <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-01-13 08:18:03 -05:00
parent 8bb7a20ff4
commit 5419711409
7 changed files with 44 additions and 0 deletions

View File

@ -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;
}

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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);

View File

@ -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()