core/history: Add history_init() and history_deinit() functions

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-12-12 09:18:26 -05:00
parent 77d4815eb6
commit 75c039f22d
8 changed files with 41 additions and 6 deletions

View File

@ -7,6 +7,7 @@
extern "C" {
#include <core/collection.h>
#include <core/filter.h>
#include <core/history.h>
#include <core/playlist.h>
#include <core/tags/tags.h>
}
@ -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();

View File

@ -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<TempQueue>::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))

View File

@ -4,8 +4,19 @@
#include <core/history.h>
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;

View File

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

View File

@ -6,6 +6,13 @@
#include <core/queue.h>
/* 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();

View File

@ -5,6 +5,7 @@
extern "C" {
#include <core/collection.h>
#include <core/filter.h>
#include <core/history.h>
#include <core/playlist.h>
#include <core/tags/tags.h>
}
@ -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();

View File

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

View File

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