diff --git a/src/library.c b/src/library.c index 12a56c7a..e60776eb 100644 --- a/src/library.c +++ b/src/library.c @@ -689,6 +689,21 @@ library_is_exiting() return scan_exit; } +/* + * Execute the function 'func' with the given argument 'arg' in the library thread. + * + * The pointer passed as argument is freed in the library thread after func returned. + * + * @param func The function to be executed + * @param arg Argument passed to func + * @return 0 if triggering the function execution succeeded, -1 on failure. + */ +int +library_exec_async(command_function func, void *arg) +{ + return commands_exec_async(cmdbase, func, arg); +} + static void * library(void *arg) { diff --git a/src/library.h b/src/library.h index b703fbdf..b07a64bf 100644 --- a/src/library.h +++ b/src/library.h @@ -23,6 +23,7 @@ #include #include +#include "commands.h" #include "db.h" /* @@ -88,6 +89,9 @@ library_set_scanning(bool is_scanning); bool library_is_exiting(); +int +library_exec_async(command_function func, void *arg); + int library_init(); diff --git a/src/spotify.c b/src/spotify.c index d0b06b3d..005e04df 100644 --- a/src/spotify.c +++ b/src/spotify.c @@ -413,6 +413,9 @@ fptr_assign_all() // End of ugly part +static enum command_state +scan_webapi(void *arg, int *ret); + /* ------------------------------- MISC HELPERS ---------------------------- */ static int @@ -1993,7 +1996,8 @@ spotify_oauth_callback(struct evbuffer *evbuf, struct evkeyvalq *param, const ch // Received a valid access token spotify_access_token_valid = true; - // TODO Trigger init-scan after successful access to spotifywebapi + // Trigger scan after successful access to spotifywebapi + library_exec_async(scan_webapi, NULL); evbuffer_add_printf(evbuf, "ok, all done

\n"); @@ -2312,6 +2316,14 @@ fullrescan() return 0; } +/* Thread: httpd */ +static enum command_state +scan_webapi(void *arg, int *ret) +{ + *ret = rescan(); + return COMMAND_END; +} + /* Thread: main */ int spotify_init(void)