From 75c039f22dd2f5017833f140ae9d76cd97dcdfd7 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Sat, 12 Dec 2015 09:18:26 -0500 Subject: [PATCH] core/history: Add history_init() and history_deinit() functions Signed-off-by: Anna Schumaker --- core/core.cpp | 5 ++++- core/deck.cpp | 3 +-- core/history.c | 11 +++++++++++ include/core/deck.h | 2 +- include/core/history.h | 7 +++++++ tests/core/audio.cpp | 4 +++- tests/core/deck.cpp | 3 ++- tests/core/history.c | 12 ++++++++++++ 8 files changed, 41 insertions(+), 6 deletions(-) diff --git a/core/core.cpp b/core/core.cpp index bf1617b9..160c76a8 100644 --- a/core/core.cpp +++ b/core/core.cpp @@ -7,6 +7,7 @@ extern "C" { #include #include +#include #include #include } @@ -18,12 +19,14 @@ void core :: init(struct core_init_data *init) tags_init(); playlist_init(init->playlist_ops); collection_init(init->collection_ops); - deck :: init(init->history_ops, init->tempq_ops); + history_init(init->history_ops); + deck :: init(init->tempq_ops); audio :: init(); } void core :: deinit() { + history_deinit(); collection_deinit(); playlist_deinit(); tags_deinit(); diff --git a/core/deck.cpp b/core/deck.cpp index 65315e3e..78bbad81 100644 --- a/core/deck.cpp +++ b/core/deck.cpp @@ -79,13 +79,12 @@ static void upgrade_v0() } } -void deck :: init(struct queue_ops *history_ops, struct queue_ops *temp_ops) +void deck :: init(struct queue_ops *temp_ops) { unsigned int num; bool upgraded = false; std::list::iterator it; - queue_init(history_get_queue(), Q_ENABLED | Q_REPEAT | Q_NO_SORT | Q_ADD_FRONT, history_ops); file_init(&deck_file, "deck", 1); if (!file_open(&deck_file, OPEN_READ)) diff --git a/core/history.c b/core/history.c index cad193d6..8ce54345 100644 --- a/core/history.c +++ b/core/history.c @@ -4,8 +4,19 @@ #include static struct queue history_queue; +#define HISTORY_FLAGS Q_ENABLED | Q_REPEAT | Q_NO_SORT | Q_ADD_FRONT +void history_init(struct queue_ops *history_ops) +{ + queue_init(&history_queue, HISTORY_FLAGS, history_ops); +} + +void history_deinit() +{ + queue_deinit(&history_queue); +} + struct queue *history_get_queue() { return &history_queue; diff --git a/include/core/deck.h b/include/core/deck.h index 30fb7d9b..a9c62b2c 100644 --- a/include/core/deck.h +++ b/include/core/deck.h @@ -46,7 +46,7 @@ namespace deck /** * Read the deck file from disk and restore the queues. */ - void init(struct queue_ops *, struct queue_ops *); + void init(struct queue_ops *); /** * Save the current queues to a file on disk. diff --git a/include/core/history.h b/include/core/history.h index 4994c6cb..4eb5e730 100644 --- a/include/core/history.h +++ b/include/core/history.h @@ -6,6 +6,13 @@ #include +/* Called to initialize the history queue. */ +void history_init(struct queue_ops *); + +/* Called to deinitialize the history queue. */ +void history_deinit(); + + /* Called to access the queue of recent tracks. */ struct queue *history_get_queue(); diff --git a/tests/core/audio.cpp b/tests/core/audio.cpp index 58ea63c0..00be2438 100644 --- a/tests/core/audio.cpp +++ b/tests/core/audio.cpp @@ -5,6 +5,7 @@ extern "C" { #include #include +#include #include #include } @@ -91,7 +92,8 @@ void test_init() tags_init(); playlist_init(NULL); collection_init(NULL); - deck :: init(NULL, NULL); + history_init(NULL); + deck :: init(NULL); audio :: init(); track = audio :: current_track(); diff --git a/tests/core/deck.cpp b/tests/core/deck.cpp index 89af8107..2a62e64d 100644 --- a/tests/core/deck.cpp +++ b/tests/core/deck.cpp @@ -27,7 +27,8 @@ static void test_init() tags_init(); playlist_init(NULL); collection_init(NULL); - deck :: init(NULL, NULL); + history_init(NULL); + deck :: init(NULL); test_equal(queue_has_flag(collection_get_queue(), Q_RANDOM), true); test_equal(deck :: get_queues().size(), (size_t)2); diff --git a/tests/core/history.c b/tests/core/history.c index 1bb97363..8c97f35f 100644 --- a/tests/core/history.c +++ b/tests/core/history.c @@ -8,7 +8,19 @@ static void test_init() { struct queue *q = history_get_queue(); + history_init(NULL); + test_not_equal((void *)q, NULL); + test_equal(queue_has_flag(q, Q_ENABLED), (bool)true); + test_equal(queue_has_flag(q, Q_REPEAT), (bool)true); + test_equal(queue_has_flag(q, Q_NO_SORT), (bool)true); + test_equal(queue_has_flag(q, Q_ADD_FRONT), (bool)true); + test_equal(queue_has_flag(q, Q_SAVE_SORT), (bool)false); + test_equal(queue_has_flag(q, Q_SAVE_FLAGS), (bool)false); + test_equal((void *)q->q_sort, NULL); + test_equal(queue_size(q), 0); + + history_deinit(); } DECLARE_UNIT_TESTS(