core/queue: Add extra paramater to queue_init()

This is used to pass through a value to the GUI during queue
initialization.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-05-02 07:52:18 -04:00 committed by Anna Schumaker
parent 7f0e1ecc99
commit 44a57ed863
13 changed files with 26 additions and 26 deletions

View File

@ -158,7 +158,7 @@ bool __collection_init_idle(void *data)
*/
void collection_init(struct queue_ops *ops)
{
queue_init(&c_queue, Q_ENABLED | Q_REPEAT | Q_ADD_FRONT, ops);
queue_init(&c_queue, Q_ENABLED | Q_REPEAT | Q_ADD_FRONT, ops, NULL);
idle_schedule(IDLE_SYNC, __collection_init_idle, NULL);
}

View File

@ -9,7 +9,7 @@ static struct queue history_queue;
void history_init(struct queue_ops *history_ops)
{
queue_init(&history_queue, HISTORY_FLAGS, history_ops);
queue_init(&history_queue, HISTORY_FLAGS, history_ops, NULL);
}
void history_deinit()

View File

@ -189,7 +189,7 @@ void pl_system_init(struct queue_ops *ops)
unsigned int i;
for (i = 0; i < SYS_PL_NUM_PLAYLISTS; i++) {
queue_init(&sys_playlists[i], Q_ENABLED | Q_REPEAT, ops);
queue_init(&sys_playlists[i], Q_ENABLED | Q_REPEAT, ops, NULL);
queue_sort(&sys_playlists[i], COMPARE_ARTIST, true);
queue_sort(&sys_playlists[i], COMPARE_YEAR, false);
queue_sort(&sys_playlists[i], COMPARE_TRACK, false);

View File

@ -28,10 +28,10 @@ static int track_less_than(const void *a, const void *b, void *data)
return res;
}
static inline void *__queue_init(struct queue *queue)
static inline void *__queue_init(struct queue *queue, void *data)
{
if (queue->q_ops)
return queue->q_ops->qop_init(queue);
return queue->q_ops->qop_init(queue, data);
return NULL;
}
@ -133,7 +133,7 @@ static inline void __queue_save(struct queue *queue, enum queue_flags flag)
}
void queue_init(struct queue *queue, unsigned int flags,
const struct queue_ops *ops)
const struct queue_ops *ops, void *data)
{
queue->q_flags = flags;
queue->q_length = 0;
@ -143,7 +143,7 @@ void queue_init(struct queue *queue, unsigned int flags,
g_queue_init(&queue->q_tracks);
queue_iter_init(queue, &queue->q_cur);
queue->q_private = __queue_init(queue);
queue->q_private = __queue_init(queue, data);
}
void queue_deinit(struct queue *queue)

View File

@ -19,7 +19,7 @@ static struct queue *__tempq_alloc(unsigned int flags)
flags = flags | Q_SAVE_FLAGS | Q_SAVE_SORT;
tempq_list = g_slist_append(tempq_list, queue);
queue_init(queue, flags, tempq_ops);
queue_init(queue, flags, tempq_ops, NULL);
return queue;
}

View File

@ -169,7 +169,7 @@ void __collection_selection_changed(GtkTreeSelection *selection,
}
}
static void *__collection_init(struct queue *queue)
static void *__collection_init(struct queue *queue, void *data)
{
return gui_queue_alloc(queue, "Collection", GQ_CAN_RANDOM);
}

View File

@ -5,7 +5,7 @@
#include <gui/sidebar.h>
static void *__history_init(struct queue *queue)
static void *__history_init(struct queue *queue, void *data)
{
return gui_queue_alloc(queue, "History", 0);
}

View File

@ -91,7 +91,7 @@ static void __playlist_update_sizes()
} while (gtk_tree_model_iter_next(model, &iter));
}
static void *__playlist_init(struct queue *queue)
static void *__playlist_init(struct queue *queue, void *data)
{
return gui_queue_alloc(queue, "Playlist", 0);
}

View File

@ -7,7 +7,7 @@
#define TEMPQ_FLAGS (GQ_CAN_RANDOM | GQ_CAN_REPEAT | GQ_CAN_DISABLE)
static void *__tempq_init(struct queue *queue)
static void *__tempq_init(struct queue *queue, void *data)
{
struct gui_queue *gq;

View File

@ -27,7 +27,7 @@ enum queue_flags {
struct queue_ops {
/* Called to tell a higher layer that a queue has been initialized. */
void *(*qop_init)(struct queue *);
void *(*qop_init)(struct queue *, void *);
/* Called to tell a higher layer that a queue is deinitializing. */
void (*qop_deinit)(struct queue *);
@ -112,7 +112,7 @@ static inline struct track *queue_iter_val(struct queue_iter *it)
/* Called to initialize a queue. */
void queue_init(struct queue *, unsigned int, const struct queue_ops *);
void queue_init(struct queue *, unsigned int, const struct queue_ops *, void *);
/* Called to deinitialize a queue. */
void queue_deinit(struct queue *);

View File

@ -20,7 +20,7 @@ unsigned int count_updated = 0;
bool can_erase = true;
static void *queue_op_init(struct queue *queue)
static void *queue_op_init(struct queue *queue, void *data)
{
count_init++;
return GUINT_TO_POINTER(count_init);
@ -115,7 +115,7 @@ static void test_init()
__test_init_core();
queue_init(&q, 0, NULL);
queue_init(&q, 0, NULL, NULL);
test_equal(count_init, 0);
test_equal(GPOINTER_TO_UINT(q.q_private), 0);
@ -134,7 +134,7 @@ static void test_init()
queue_deinit(&q);
test_equal(count_deinit, 0);
queue_init(&q, Q_ENABLED | Q_RANDOM, &test_ops);
queue_init(&q, Q_ENABLED | Q_RANDOM, &test_ops, NULL);
test_equal(count_init, 1);
test_equal(GPOINTER_TO_UINT(q.q_private), 1);
@ -153,7 +153,7 @@ static void test_flags()
{
struct queue q;
queue_init(&q, 0, &test_ops);
queue_init(&q, 0, &test_ops, NULL);
test_equal(q.q_flags, 0);
test_equal(queue_has_flag(&q, Q_ENABLED), (bool)false);
test_equal(queue_has_flag(&q, Q_RANDOM), (bool)false);
@ -209,7 +209,7 @@ static void test_stress(unsigned int N)
count_cleared = 0;
count_updated = 0;
queue_init(&q, 0, &test_ops);
queue_init(&q, 0, &test_ops, NULL);
/* queue_add() */
for (i = 0; i < N; i++) {
@ -327,7 +327,7 @@ static void test_rand_select()
struct queue q;
g_random_set_seed(0);
queue_init(&q, Q_ENABLED | Q_RANDOM, &test_ops);
queue_init(&q, Q_ENABLED | Q_RANDOM, &test_ops, NULL);
/* Call next() on an empty queue. */
for (i = 0; i < 13; i++) {
@ -414,7 +414,7 @@ static void test_sorting()
unsigned int i;
struct queue q;
queue_init(&q, Q_SAVE_SORT | Q_ADD_FRONT, &test_ops);
queue_init(&q, Q_SAVE_SORT | Q_ADD_FRONT, &test_ops, NULL);
for (i = 0; i < 13; i++) {
track = track_get(i);
track->tr_count = (i < 6) ? 4 : 2;
@ -496,8 +496,8 @@ static void test_save_load()
struct queue q, r;
unsigned int i;
queue_init(&q, 0, &test_ops);
queue_init(&r, 0, &test_ops);
queue_init(&q, 0, &test_ops, NULL);
queue_init(&r, 0, &test_ops, NULL);
for (i = 0; i < 13; i++)
queue_add(&q, track_get(i));

View File

@ -21,7 +21,7 @@ void on_row_changed(GtkTreeModel *model, GtkTreePath *path,
GtkTreeIter *iter, gpointer data)
{ count_update++; }
void *test_queue_init(struct queue *queue) { return NULL; }
void *test_queue_init(struct queue *queue, void *data) { return NULL; }
void test_queue_deinit(struct queue *queue) {}
void test_queue_added(struct queue *queue, unsigned int row)
{ gui_queue_model_add(queue->q_private, row); }

View File

@ -15,7 +15,7 @@
#include <tests/gui.h>
#include <tests/test.h>
static void *test_queue_init(struct queue *queue)
static void *test_queue_init(struct queue *queue, void *data)
{
return gui_queue_alloc(queue, "Test Queue",
GQ_CAN_RANDOM | GQ_CAN_REPEAT | GQ_CAN_DISABLE);
@ -50,7 +50,6 @@ static void test_queue()
gtk_init(&argc, NULL);
gui_builder_init("share/ocarina/ocarina6.glade");
queue_init(&q, 0, &test_ops);
gui_view_init();
while (idle_run_task()) {};
@ -63,6 +62,7 @@ static void test_queue()
treeview = GTK_TREE_VIEW(gui_builder_widget("o_treeview"));
/* Test initialization */
queue_init(&q, 0, &test_ops, NULL);
gq = gui_queue(&q);
test_equal((void *)gq->gq_queue, (void *)&q);
test_not_equal((void *)gq->gq_model, NULL);