core/queue: Add qop_init() queue operation
This function is used to notify a higher layer that a queue has been initialized. That higher layer can return a pointer to be attached to the "private data" field of the queue. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
6e3027d087
commit
8bb7a20ff4
10
core/queue.c
10
core/queue.c
|
@ -29,6 +29,13 @@ static int track_less_than(const void *a, const void *b, void *data)
|
|||
return res;
|
||||
}
|
||||
|
||||
static inline void *__queue_init(struct queue *queue)
|
||||
{
|
||||
if (queue->q_ops)
|
||||
return queue->q_ops->qop_init(queue);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline unsigned int __queue_added(struct queue *queue,
|
||||
struct track *track,
|
||||
unsigned int pos)
|
||||
|
@ -89,8 +96,9 @@ void queue_init(struct queue *queue, unsigned int flags,
|
|||
|
||||
queue->q_cur.it_pos = -1;
|
||||
queue->q_cur.it_iter = NULL;
|
||||
|
||||
_q_init(&queue->q_tracks);
|
||||
|
||||
queue->q_private = __queue_init(queue);
|
||||
}
|
||||
|
||||
void queue_deinit(struct queue *queue)
|
||||
|
|
|
@ -53,6 +53,11 @@ public:
|
|||
|
||||
static CollectionTab *collection_tab;
|
||||
|
||||
static void *collection_init(struct queue *queue)
|
||||
{
|
||||
return collection_tab;
|
||||
}
|
||||
|
||||
static void collection_added(struct queue *queue, unsigned int pos)
|
||||
{
|
||||
if (collection_tab)
|
||||
|
@ -78,6 +83,7 @@ static void collection_updated(struct queue *queue, unsigned int pos)
|
|||
}
|
||||
|
||||
struct queue_ops collection_ops = {
|
||||
collection_init,
|
||||
collection_added,
|
||||
collection_removed,
|
||||
collection_cleared,
|
||||
|
|
|
@ -38,6 +38,11 @@ public:
|
|||
|
||||
static HistoryTab *history_tab;
|
||||
|
||||
static void *history_init(struct queue *queue)
|
||||
{
|
||||
return history_tab;
|
||||
}
|
||||
|
||||
static void history_added(struct queue *queue, unsigned int pos)
|
||||
{
|
||||
if (history_tab)
|
||||
|
@ -60,6 +65,7 @@ static void history_updated(struct queue *queue, unsigned int pos)
|
|||
}
|
||||
|
||||
struct queue_ops history_ops = {
|
||||
history_init,
|
||||
history_added,
|
||||
history_removed,
|
||||
history_cleared,
|
||||
|
|
|
@ -84,6 +84,11 @@ static void on_favorite()
|
|||
playlist_remove(PL_FAVORITED, track);
|
||||
}
|
||||
|
||||
static void *playlist_init(struct queue *queue)
|
||||
{
|
||||
return p_tab;
|
||||
}
|
||||
|
||||
static void playlist_added(struct queue *queue, unsigned int pos)
|
||||
{
|
||||
if (p_tab)
|
||||
|
@ -106,6 +111,7 @@ static void playlist_updated(struct queue *queue, unsigned int pos)
|
|||
}
|
||||
|
||||
struct queue_ops playlist_ops = {
|
||||
playlist_init,
|
||||
playlist_added,
|
||||
playlist_removed,
|
||||
playlist_cleared,
|
||||
|
|
|
@ -23,6 +23,11 @@ static compare_t sort_fields[] = {
|
|||
COMPARE_GENRE, COMPARE_COUNT, COMPARE_PLAYED
|
||||
};
|
||||
|
||||
static void *tempq_init(struct queue *queue)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void tempq_added(struct queue *queue, unsigned int pos)
|
||||
{
|
||||
find_tab(queue)->on_track_added(pos);
|
||||
|
@ -46,6 +51,7 @@ static void tempq_updated(struct queue *queue, unsigned int pos)
|
|||
}
|
||||
|
||||
struct queue_ops tempq_ops = {
|
||||
tempq_init,
|
||||
tempq_added,
|
||||
tempq_removed,
|
||||
tempq_cleared,
|
||||
|
|
|
@ -27,6 +27,9 @@ enum queue_flags {
|
|||
|
||||
|
||||
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 track has been added. */
|
||||
void (*qop_added)(struct queue *, unsigned int);
|
||||
|
||||
|
@ -45,11 +48,12 @@ struct queue_ops {
|
|||
|
||||
|
||||
struct queue {
|
||||
unsigned int q_flags; /* The queue's set of flags. */
|
||||
unsigned int q_length; /* The queue's total runtime (in seconds). */
|
||||
struct _queue q_tracks; /* The queue's list of tracks. */
|
||||
struct _q_iter q_cur; /* The queue's last-played position. */
|
||||
GSList *q_sort; /* The queue's sort order. */
|
||||
unsigned int q_flags; /* The queue's set of flags. */
|
||||
unsigned int q_length; /* The queue's total runtime (in seconds). */
|
||||
struct _queue q_tracks; /* The queue's list of tracks. */
|
||||
struct _q_iter q_cur; /* The queue's last-played position. */
|
||||
GSList *q_sort; /* The queue's sort order. */
|
||||
void *q_private; /* The queue's private data. */
|
||||
|
||||
const struct queue_ops *q_ops; /* The queue's operations vector. */
|
||||
};
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <tests/test.h>
|
||||
|
||||
|
||||
unsigned int count_init = 0;
|
||||
unsigned int count_added = 0;
|
||||
unsigned int count_deleted = 0;
|
||||
unsigned int count_cleared = 0;
|
||||
|
@ -16,6 +17,12 @@ unsigned int count_sort = 0;
|
|||
unsigned int count_updated = 0;
|
||||
|
||||
|
||||
static void *queue_op_init(struct queue *queue)
|
||||
{
|
||||
count_init++;
|
||||
return GUINT_TO_POINTER(count_init);
|
||||
}
|
||||
|
||||
static void queue_op_added(struct queue *queue, unsigned int pos)
|
||||
{
|
||||
count_added++;
|
||||
|
@ -46,6 +53,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_added = queue_op_added,
|
||||
.qop_removed = queue_op_removed,
|
||||
.qop_cleared = queue_op_cleared,
|
||||
|
@ -91,6 +99,9 @@ static void test_init()
|
|||
__test_init_core();
|
||||
|
||||
queue_init(&q, 0, NULL);
|
||||
test_equal(count_init, 0);
|
||||
test_equal(GPOINTER_TO_UINT(q.q_private), 0);
|
||||
|
||||
test_equal(q.q_cur.it_pos, (unsigned int)-1);
|
||||
test_equal(q.q_flags, 0);
|
||||
test_equal(q.q_length, 0);
|
||||
|
@ -99,6 +110,8 @@ static void test_init()
|
|||
test_equal((void *)queue_next(&q), (void *)NULL);
|
||||
|
||||
queue_init(&q, Q_ENABLED | Q_RANDOM, &test_ops);
|
||||
test_equal(count_init, 1);
|
||||
test_equal(GPOINTER_TO_UINT(q.q_private), 1);
|
||||
|
||||
test_equal(q.q_cur.it_pos, (unsigned int)-1);
|
||||
test_equal(q.q_flags, Q_ENABLED | Q_RANDOM);
|
||||
|
|
Loading…
Reference in New Issue