From 44a57ed863659556170b7de043f0b0a44c46f5b5 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Mon, 2 May 2016 07:52:18 -0400 Subject: [PATCH] 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 --- core/collection.c | 2 +- core/history.c | 2 +- core/playlists/system.c | 2 +- core/queue.c | 8 ++++---- core/tempq.c | 2 +- gui/collection.c | 2 +- gui/history.c | 2 +- gui/playlist.c | 2 +- gui/tempq.c | 2 +- include/core/queue.h | 4 ++-- tests/core/queue.c | 18 +++++++++--------- tests/gui/model.c | 2 +- tests/gui/queue.c | 4 ++-- 13 files changed, 26 insertions(+), 26 deletions(-) diff --git a/core/collection.c b/core/collection.c index 8f1adbca..805a6f2c 100644 --- a/core/collection.c +++ b/core/collection.c @@ -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); } diff --git a/core/history.c b/core/history.c index 0283b9cf..8a75453e 100644 --- a/core/history.c +++ b/core/history.c @@ -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() diff --git a/core/playlists/system.c b/core/playlists/system.c index fe6a9fa7..add4d12d 100644 --- a/core/playlists/system.c +++ b/core/playlists/system.c @@ -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); diff --git a/core/queue.c b/core/queue.c index 70b95fbd..9f0fc55a 100644 --- a/core/queue.c +++ b/core/queue.c @@ -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) diff --git a/core/tempq.c b/core/tempq.c index d80f37df..cc285aa5 100644 --- a/core/tempq.c +++ b/core/tempq.c @@ -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; } diff --git a/gui/collection.c b/gui/collection.c index cd6b0a4a..92b6eba6 100644 --- a/gui/collection.c +++ b/gui/collection.c @@ -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); } diff --git a/gui/history.c b/gui/history.c index 73d39576..5a805534 100644 --- a/gui/history.c +++ b/gui/history.c @@ -5,7 +5,7 @@ #include -static void *__history_init(struct queue *queue) +static void *__history_init(struct queue *queue, void *data) { return gui_queue_alloc(queue, "History", 0); } diff --git a/gui/playlist.c b/gui/playlist.c index abc6a70b..e46ad796 100644 --- a/gui/playlist.c +++ b/gui/playlist.c @@ -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); } diff --git a/gui/tempq.c b/gui/tempq.c index 8fba777b..928cc472 100644 --- a/gui/tempq.c +++ b/gui/tempq.c @@ -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; diff --git a/include/core/queue.h b/include/core/queue.h index b132967b..3bf28b31 100644 --- a/include/core/queue.h +++ b/include/core/queue.h @@ -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 *); diff --git a/tests/core/queue.c b/tests/core/queue.c index 770dae59..c363ed54 100644 --- a/tests/core/queue.c +++ b/tests/core/queue.c @@ -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)); diff --git a/tests/gui/model.c b/tests/gui/model.c index 82a3ade8..dffc0b21 100644 --- a/tests/gui/model.c +++ b/tests/gui/model.c @@ -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); } diff --git a/tests/gui/queue.c b/tests/gui/queue.c index 92858d34..13d7e958 100644 --- a/tests/gui/queue.c +++ b/tests/gui/queue.c @@ -15,7 +15,7 @@ #include #include -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);