diff --git a/Makefile.common b/Makefile.common index 91b40fbc79..23599b1ec2 100644 --- a/Makefile.common +++ b/Makefile.common @@ -123,6 +123,7 @@ OBJ += frontend/frontend.o \ intl/msg_hash_us.o \ runloop.o \ tasks/tasks.o \ + tasks/tasks_internal.o \ tasks/task_content.o \ tasks/task_file_transfer.o \ content.o \ diff --git a/griffin/griffin.c b/griffin/griffin.c index a55ef2af65..01cae83ec7 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -701,6 +701,7 @@ RETROARCH #include "../retroarch.c" #include "../runloop.c" #include "../tasks/tasks.c" +#include "../tasks/tasks_internal.c" #include "../msg_hash.c" #include "../intl/msg_hash_de.c" diff --git a/input/input_overlay.c b/input/input_overlay.c index d50821988a..68e2f1dc0d 100644 --- a/input/input_overlay.c +++ b/input/input_overlay.c @@ -33,7 +33,7 @@ #include "../configuration.h" #include "../verbosity.h" -#include "../tasks/tasks.h" +#include "../tasks/tasks_internal.h" #ifdef HAVE_MENU #include "../menu/menu_driver.h" diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index edd27ad67e..b35858e521 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -33,7 +33,7 @@ #include "../../defaults.h" #include "../../cheats.h" #include "../../general.h" -#include "../../tasks/tasks.h" +#include "../../tasks/tasks_internal.h" #include "../../input/input_remapping.h" #include "../../system.h" diff --git a/menu/cbs/menu_cbs_scan.c b/menu/cbs/menu_cbs_scan.c index d1c7aa72f5..d85c3ca632 100644 --- a/menu/cbs/menu_cbs_scan.c +++ b/menu/cbs/menu_cbs_scan.c @@ -22,7 +22,7 @@ #include "../menu_setting.h" #include "../../runloop.h" -#include "../../tasks/tasks.h" +#include "../../tasks/tasks_internal.h" #ifndef BIND_ACTION_SCAN #define BIND_ACTION_SCAN(cbs, name) \ diff --git a/menu/drivers/materialui.c b/menu/drivers/materialui.c index d6815d6120..97f5e6ed29 100644 --- a/menu/drivers/materialui.c +++ b/menu/drivers/materialui.c @@ -42,7 +42,7 @@ #include "../../system.h" #include "../../runloop.h" #include "../../verbosity.h" -#include "../../tasks/tasks.h" +#include "../../tasks/tasks_internal.h" enum { diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index 934b62d113..a3cfb97643 100644 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -45,7 +45,7 @@ #include "../../configuration.h" #include "../../system.h" -#include "../../tasks/tasks.h" +#include "../../tasks/tasks_internal.h" #ifndef XMB_THEME #define XMB_THEME "monochrome" diff --git a/menu/drivers/zarch.c b/menu/drivers/zarch.c index 34ab07606e..087f7e2219 100644 --- a/menu/drivers/zarch.c +++ b/menu/drivers/zarch.c @@ -1,4 +1,5 @@ /* RetroArch - A frontend for libretro. + * Copyright (C) 2011-2016 - Higor Euripedes * Copyright (C) 2011-2016 - Daniel De Matteis * Copyright (C) 2014-2015 - Jean-André Santoni * @@ -49,7 +50,7 @@ #include "../../configuration.h" #include "../../runloop.h" #include "../../verbosity.h" -#include "../../tasks/tasks.h" +#include "../../tasks/tasks_internal.h" #if 0 #define ZARCH_DEBUG diff --git a/menu/menu_driver.c b/menu/menu_driver.c index 49f3f658bf..64b1bc861a 100644 --- a/menu/menu_driver.c +++ b/menu/menu_driver.c @@ -33,7 +33,7 @@ #include "../defaults.h" #include "../frontend/frontend.h" #include "../string_list_special.h" -#include "../tasks/tasks.h" +#include "../tasks/tasks_internal.h" #include "../verbosity.h" static const menu_ctx_driver_t *menu_ctx_drivers[] = { diff --git a/tasks/task_content.c b/tasks/task_content.c index d466d1c2c9..cc88636b92 100644 --- a/tasks/task_content.c +++ b/tasks/task_content.c @@ -16,6 +16,8 @@ #include #include "tasks.h" +#include "tasks_internal.h" + #include "../command_event.h" /* TODO/FIXME - turn this into actual task */ diff --git a/tasks/task_database.c b/tasks/task_database.c index 6aa8dfaad7..00044bd474 100644 --- a/tasks/task_database.c +++ b/tasks/task_database.c @@ -15,13 +15,14 @@ #include #include +#include #include #include #include #include #include -#include "tasks.h" +#include "tasks_internal.h" #ifdef HAVE_LIBRETRODB #include "../database_info.h" diff --git a/tasks/task_decompress.c b/tasks/task_decompress.c index 40c6126ca5..88c23a1d66 100644 --- a/tasks/task_decompress.c +++ b/tasks/task_decompress.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include "tasks.h" diff --git a/tasks/task_file_transfer.c b/tasks/task_file_transfer.c index 1137c17c45..86ff1340a9 100644 --- a/tasks/task_file_transfer.c +++ b/tasks/task_file_transfer.c @@ -26,6 +26,7 @@ #include #include "tasks.h" +#include "tasks_internal.h" #include "../verbosity.h" #define CB_MENU_WALLPAPER 0xb476e505U diff --git a/tasks/task_http.c b/tasks/task_http.c index ea81453e5f..cd1241ce1e 100644 --- a/tasks/task_http.c +++ b/tasks/task_http.c @@ -28,7 +28,7 @@ #include "../file_ops.h" #include "../msg_hash.h" #include "../verbosity.h" -#include "tasks.h" +#include "tasks_internal.h" enum http_status_enum { diff --git a/tasks/tasks.c b/tasks/tasks.c index 48cdf52213..8440b19fe4 100644 --- a/tasks/tasks.c +++ b/tasks/tasks.c @@ -1,4 +1,5 @@ /* RetroArch - A frontend for libretro. + * Copyright (C) 2011-2016 - Higor Euripedes * Copyright (C) 2011-2016 - Daniel De Matteis * * RetroArch is free software: you can redistribute it and/or modify it under the terms @@ -13,10 +14,14 @@ * If not, see . */ +#include #include #include -#include "../msg_hash.h" +#ifdef HAVE_THREADS +#include "../configuration.h" +#endif + #include "tasks.h" #ifdef HAVE_THREADS @@ -68,44 +73,9 @@ static rarch_task_t *task_queue_get(task_queue_t *queue) return task; } -static void task_msg_queue_pushf(unsigned prio, unsigned duration, - bool flush, const char *fmt, ...) -{ - char buf[1024]; - va_list ap; - - va_start(ap, fmt); - vsnprintf(buf, sizeof(buf), fmt, ap); - va_end(ap); - runloop_msg_queue_push(buf, prio, duration, flush); -} - -static void push_task_progress(rarch_task_t *task) -{ - if (task->title) - { - if (task->finished) - { - if (task->error) - task_msg_queue_pushf(1, 60, true, "%s: %s", - msg_hash_to_str(MSG_TASK_FAILED), task->title); - else - task_msg_queue_pushf(1, 60, true, "100%%: %s", task->title); - } - else - { - if (task->progress >= 0 && task->progress <= 100) - task_msg_queue_pushf(1, 60, true, "%i%%: %s", - task->progress, task->title); - else - task_msg_queue_pushf(1, 60, true, "%s...", task->title); - } - } -} - static void rarch_task_internal_gather(void) { - rarch_task_t *task; + rarch_task_t *task = NULL; while ((task = task_queue_get(&tasks_finished)) != NULL) { push_task_progress(task); diff --git a/tasks/tasks.h b/tasks/tasks.h index 2bff25f4c7..d40fc13dc7 100644 --- a/tasks/tasks.h +++ b/tasks/tasks.h @@ -1,4 +1,5 @@ /* RetroArch - A frontend for libretro. + * Copyright (C) 2011-2016 - Higor Euripedes * Copyright (C) 2011-2016 - Daniel De Matteis * * RetroArch is free software: you can redistribute it and/or modify it under the terms @@ -13,14 +14,12 @@ * If not, see . */ -#ifndef COMMON_TASKS_H -#define COMMON_TASKS_H +#ifndef TASKS_HANDLER_H +#define TASKS_HANDLER_H #include #include -#include "../runloop.h" - #ifdef __cplusplus extern "C" { #endif @@ -45,7 +44,8 @@ enum task_ctl_state TASK_CTL_INIT, /** - * Calls func for every running task until it returns true. + * Calls func for every running task + * until it returns true. * Returns a task or NULL if not found. */ TASK_CTL_FIND, @@ -55,7 +55,8 @@ enum task_ctl_state TASK_CTL_WAIT, /* Checks for finished tasks - * Takes the finished tasks, if any, and runs their callbacks. + * Takes the finished tasks, if any, + * and runs their callbacks. * This must only be called from the main thread. */ TASK_CTL_CHECK, @@ -75,8 +76,11 @@ enum task_ctl_state typedef struct rarch_task rarch_task_t; typedef void (*rarch_task_callback_t)(void *task_data, void *user_data, const char *error); + typedef void (*rarch_task_handler_t)(rarch_task_t *task); -typedef bool (*rarch_task_finder_t)(rarch_task_t *task, void *userdata); + +typedef bool (*rarch_task_finder_t)(rarch_task_t *task, + void *userdata); typedef struct { @@ -94,7 +98,8 @@ struct rarch_task * the task has finished executing. */ bool finished; - /* set to true by the task system to signal the task *must* end. */ + /* set to true by the task system + * to signal the task *must* end. */ bool cancelled; /* created by the handler, destroyed by the user */ @@ -113,7 +118,8 @@ struct rarch_task /* -1 = unmettered, 0-100 progress value */ int8_t progress; - /* handler can modify but will be free()d automatically if non-null */ + /* handler can modify but will be + * free()d automatically if non-NULL. */ char *title; /* don't touch this. */ @@ -126,52 +132,7 @@ typedef struct task_finder_data void *userdata; } task_finder_data_t; - -#ifdef HAVE_NETWORKING -typedef struct { - char *data; - size_t len; -} http_transfer_data_t; - -bool rarch_task_push_http_transfer(const char *url, const char *type, - rarch_task_callback_t cb, void *userdata); -#endif - -bool rarch_task_push_image_load(const char *fullpath, const char *type, - rarch_task_callback_t cb, void *userdata); - -#ifdef HAVE_LIBRETRODB -bool rarch_task_push_dbscan(const char *fullpath, - bool directory, rarch_task_callback_t cb); -#endif - -#ifdef HAVE_OVERLAY -bool rarch_task_push_overlay_load_default( - rarch_task_callback_t cb, void *user_data); -#endif - -int find_first_data_track(const char* cue_path, - int32_t* offset, char* track_path, size_t max_len); - -int detect_system(const char* track_path, int32_t offset, - const char** system_name); - -int detect_ps1_game(const char *track_path, char *game_id); - -int detect_psp_game(const char *track_path, char *game_id); - -bool rarch_task_push_decompress( - const char *source_file, - const char *target_dir, - const char *target_file, - const char *subdir, - const char *valid_ext, - rarch_task_callback_t cb, void *user_data); - -bool rarch_task_push_content_load_default( - const char *core_path, const char *fullpath, - bool persist, enum rarch_core_type type, - rarch_task_callback_t cb, void *user_data); +void push_task_progress(rarch_task_t *task); bool task_ctl(enum task_ctl_state state, void *data); diff --git a/tasks/tasks_internal.c b/tasks/tasks_internal.c new file mode 100644 index 0000000000..8b271d15da --- /dev/null +++ b/tasks/tasks_internal.c @@ -0,0 +1,59 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2011-2016 - Higor Euripedes + * Copyright (C) 2011-2016 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#include +#include +#include + +#include "tasks.h" + +#include "../msg_hash.h" +#include "../runloop.h" + +static void task_msg_queue_pushf(unsigned prio, unsigned duration, + bool flush, const char *fmt, ...) +{ + char buf[1024]; + va_list ap; + + va_start(ap, fmt); + vsnprintf(buf, sizeof(buf), fmt, ap); + va_end(ap); + runloop_msg_queue_push(buf, prio, duration, flush); +} + +void push_task_progress(rarch_task_t *task) +{ + if (task->title) + { + if (task->finished) + { + if (task->error) + task_msg_queue_pushf(1, 60, true, "%s: %s", + msg_hash_to_str(MSG_TASK_FAILED), task->title); + else + task_msg_queue_pushf(1, 60, true, "100%%: %s", task->title); + } + else + { + if (task->progress >= 0 && task->progress <= 100) + task_msg_queue_pushf(1, 60, true, "%i%%: %s", + task->progress, task->title); + else + task_msg_queue_pushf(1, 60, true, "%s...", task->title); + } + } +} diff --git a/tasks/tasks_internal.h b/tasks/tasks_internal.h new file mode 100644 index 0000000000..5e74446a8a --- /dev/null +++ b/tasks/tasks_internal.h @@ -0,0 +1,80 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2011-2016 - Higor Euripedes + * Copyright (C) 2011-2016 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ +#ifndef TASKS_HANDLER_INTERNAL_H +#define TASKS_HANDLER_INTERNAL_H + +#include +#include + +#include "tasks.h" + +#include "../runloop.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef HAVE_NETWORKING +typedef struct { + char *data; + size_t len; +} http_transfer_data_t; + +bool rarch_task_push_http_transfer(const char *url, const char *type, + rarch_task_callback_t cb, void *userdata); +#endif + +bool rarch_task_push_image_load(const char *fullpath, const char *type, + rarch_task_callback_t cb, void *userdata); + +#ifdef HAVE_LIBRETRODB +bool rarch_task_push_dbscan(const char *fullpath, + bool directory, rarch_task_callback_t cb); +#endif + +#ifdef HAVE_OVERLAY +bool rarch_task_push_overlay_load_default( + rarch_task_callback_t cb, void *user_data); +#endif + +int find_first_data_track(const char* cue_path, + int32_t* offset, char* track_path, size_t max_len); + +int detect_system(const char* track_path, int32_t offset, + const char** system_name); + +int detect_ps1_game(const char *track_path, char *game_id); + +int detect_psp_game(const char *track_path, char *game_id); + +bool rarch_task_push_decompress( + const char *source_file, + const char *target_dir, + const char *target_file, + const char *subdir, + const char *valid_ext, + rarch_task_callback_t cb, void *user_data); + +bool rarch_task_push_content_load_default( + const char *core_path, const char *fullpath, + bool persist, enum rarch_core_type type, + rarch_task_callback_t cb, void *user_data); + +#ifdef __cplusplus +} +#endif + +#endif