core/idle: Change idle_init() to take an idle_sync_t

Rather than offering two init functions for testing.  This lets the UI
select if they want async idle tasks (like Album Art fetching).

Implements #90: Give idle_init an async flag
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2016-09-24 09:57:51 -04:00
parent 76ebfaa6d4
commit f46ef37630
14 changed files with 25 additions and 36 deletions

View File

@ -20,12 +20,7 @@ static bool core_defragment(void *data)
void core_init(int *argc, char ***argv, struct core_init_data *init)
{
#ifdef CONFIG_TESTING
if (init->idle_async == false)
idle_init_sync();
else
#endif /* CONFIG_TESTING */
idle_init();
idle_init(init->idle_sync);
settings_init();
tags_init();
playlist_init(init->playlist_cb);

View File

@ -38,17 +38,12 @@ void __idle_thread(gpointer task, gpointer data)
}
void idle_init()
void idle_init(enum idle_sync_t idle_sync)
{
idle_pool = g_thread_pool_new(__idle_thread, NULL, 1, true, NULL);
if (idle_sync == IDLE_ASYNC)
idle_pool = g_thread_pool_new(__idle_thread, NULL, 1, true, NULL);
}
#ifdef CONFIG_TESTING
void idle_init_sync()
{
}
#endif /* CONFIG_TESTING */
void idle_deinit()
{
struct idle_task *task;

View File

@ -31,9 +31,10 @@ const static gchar *OCARINA_APP = "org.gtk.ocarina";
const static gchar *OCARINA_APP = "org.gtk.ocarina-debug";
#endif
struct core_init_data init_data = {
.playlist_cb = &playlist_cb,
.audio_ops = &audio_ops,
static struct core_init_data init_data = {
.playlist_cb = &playlist_cb,
.audio_ops = &audio_ops,
.idle_sync = IDLE_ASYNC,
};
static int startup_argc;

View File

@ -3,14 +3,13 @@
*/
#ifndef OCARINA_CORE_CORE_H
#define OCARINA_CORE_CORE_H
#include <core/idle.h>
#include <stdbool.h>
struct core_init_data {
struct playlist_callbacks *playlist_cb;
struct audio_ops *audio_ops;
#ifdef CONFIG_TESTING
bool idle_async;
#endif /* CONFIG_TESTING */
enum idle_sync_t idle_sync;
};

View File

@ -24,10 +24,7 @@ enum idle_sync_t {
/* Called to initialize the idle queue. */
void idle_init();
#ifdef CONFIG_TESTING
void idle_init_sync();
#endif /* CONFIG_TESTING */
void idle_init(enum idle_sync_t);
/* Called to deinitialize the idle queue. */
void idle_deinit();

View File

@ -19,7 +19,7 @@ static void test_idle(gconstpointer arg)
unsigned int n = GPOINTER_TO_UINT(arg);
cur = -1;
idle_init();
idle_init(IDLE_ASYNC);
g_assert_cmpfloat(idle_progress(), ==, 1.0);
g_assert_false(idle_run_task());

View File

@ -377,7 +377,7 @@ int main(int argc, char **argv)
struct library *library;
int ret;
idle_init_sync();
idle_init(IDLE_SYNC);
settings_init();
tags_init();
playlist_init(&test_cb);

View File

@ -62,7 +62,7 @@ int main(int argc, char **argv)
struct library *library;
int ret;
idle_init_sync();
idle_init(IDLE_SYNC);
settings_init();
tags_init();
playlist_init(NULL);

View File

@ -112,7 +112,7 @@ int main(int argc, char **argv)
{
int ret;
idle_init_sync();
idle_init(IDLE_SYNC);
settings_init();
tags_init();
playlist_init(NULL);

View File

@ -373,7 +373,7 @@ int main(int argc, char **argv)
{
int ret;
idle_init_sync();
idle_init(IDLE_SYNC);
settings_init();
tags_init();
playlist_init(NULL);

View File

@ -78,7 +78,7 @@ int main(int argc, char **argv)
{
int ret;
idle_init_sync();
idle_init(IDLE_SYNC);
settings_init();
tags_init();
playlist_init(NULL);

View File

@ -48,7 +48,7 @@ static void test_album()
struct genre *genre;
struct file f;
idle_init();
idle_init(IDLE_SYNC);
koji = artist_find("Koji Kondo");
genre = genre_find("Video Game Music");
@ -134,7 +134,7 @@ static void test_album_artwork()
const gchar *cache;
idle_deinit();
idle_init();
idle_init(IDLE_ASYNC);
cache = g_get_user_cache_dir();
o_path = g_build_filename(cache, "ocarina-test", "core", "tags", "album", "1998", "Ocarina of Time.jpg", NULL);
@ -182,7 +182,7 @@ int main(int argc, char **argv)
{
int ret;
idle_init_sync();
idle_init(IDLE_SYNC);
artist_db_init();
genre_db_init();
album_db_init();

View File

@ -302,7 +302,7 @@ int main(int argc, char **argv)
int ret;
setlocale(LC_TIME, "C");
idle_init_sync();
idle_init(IDLE_SYNC);
tags_init();
while (idle_run_task()) {}

View File

@ -23,9 +23,11 @@ static struct audio_ops test_audio_ops = {
};
struct core_init_data init_data = {
.audio_ops = &test_audio_ops,
.audio_ops = &test_audio_ops,
#ifdef CONFIG_ALBUM_ART_TEST
.idle_async = true,
.idle_sync = IDLE_ASYNC,
#else /* CONFIG_ALBUM_ART_TEST */
.idle_sync = IDLE_SYNC,
#endif /* CONFIG_ALBUM_ART_TEST */
};