core/collection: Initialize the collection through an idle task
Scan over all tracks in the database first, and then schedule a collection update. Implements #13: Load collection queue through an idle task Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
bd1e20bc56
commit
f706ccb77c
|
@ -112,19 +112,12 @@ static void __validate_library(void *data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void __collection_init_idle(void *data)
|
||||||
|
|
||||||
/*
|
|
||||||
* External API begins here
|
|
||||||
*/
|
|
||||||
void collection_init(struct queue_ops *ops)
|
|
||||||
{
|
{
|
||||||
struct db_entry *track, *next;
|
struct db_entry *track, *next;
|
||||||
unsigned int i, n = 0;
|
unsigned int i, n = 0;
|
||||||
int field, ascending;
|
int field, ascending;
|
||||||
|
|
||||||
queue_init(&c_queue, Q_ENABLED | Q_REPEAT | Q_ADD_FRONT, ops);
|
|
||||||
|
|
||||||
db_for_each(track, next, track_db_get()) {
|
db_for_each(track, next, track_db_get()) {
|
||||||
if (TRACK(track)->tr_library->li_enabled &&
|
if (TRACK(track)->tr_library->li_enabled &&
|
||||||
!playlist_has(PL_HIDDEN, TRACK(track)))
|
!playlist_has(PL_HIDDEN, TRACK(track)))
|
||||||
|
@ -155,6 +148,17 @@ void collection_init(struct queue_ops *ops)
|
||||||
collection_update_all();
|
collection_update_all();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* External API begins here
|
||||||
|
*/
|
||||||
|
void collection_init(struct queue_ops *ops)
|
||||||
|
{
|
||||||
|
queue_init(&c_queue, Q_ENABLED | Q_REPEAT | Q_ADD_FRONT, ops);
|
||||||
|
idle_schedule(__collection_init_idle, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
void collection_deinit()
|
void collection_deinit()
|
||||||
{
|
{
|
||||||
queue_deinit(&c_queue);
|
queue_deinit(&c_queue);
|
||||||
|
|
|
@ -22,6 +22,13 @@ static void test_init()
|
||||||
test_not_equal((void *)q, NULL);
|
test_not_equal((void *)q, NULL);
|
||||||
test_equal(queue_has_flag(q, Q_ENABLED), (bool)true);
|
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_REPEAT), (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(queue_has_flag(q, Q_ADD_FRONT), (bool)true);
|
||||||
|
|
||||||
|
while (idle_run_task()) {};
|
||||||
|
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_SAVE_SORT), (bool)true);
|
test_equal(queue_has_flag(q, Q_SAVE_SORT), (bool)true);
|
||||||
test_equal(queue_has_flag(q, Q_SAVE_FLAGS), (bool)true);
|
test_equal(queue_has_flag(q, Q_SAVE_FLAGS), (bool)true);
|
||||||
test_equal(queue_has_flag(q, Q_ADD_FRONT), (bool)false);
|
test_equal(queue_has_flag(q, Q_ADD_FRONT), (bool)false);
|
||||||
|
@ -211,6 +218,7 @@ static void test_save_load()
|
||||||
}
|
}
|
||||||
|
|
||||||
collection_init(NULL);
|
collection_init(NULL);
|
||||||
|
while (idle_run_task()) {};
|
||||||
test_equal(queue_size(q), track_db_get()->db_size / 2);
|
test_equal(queue_size(q), track_db_get()->db_size / 2);
|
||||||
test_equal(g_slist_length(q->q_sort), 2);
|
test_equal(g_slist_length(q->q_sort), 2);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue