Create tasks_internal and split up RA-specific task code to outside

This commit is contained in:
twinaphex 2016-02-09 17:12:39 +01:00
parent c60c9fbd86
commit ce2869b4d8
18 changed files with 179 additions and 101 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -42,7 +42,7 @@
#include "../../system.h"
#include "../../runloop.h"
#include "../../verbosity.h"
#include "../../tasks/tasks.h"
#include "../../tasks/tasks_internal.h"
enum
{

View File

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

View File

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

View File

@ -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[] = {

View File

@ -16,6 +16,8 @@
#include <stdlib.h>
#include "tasks.h"
#include "tasks_internal.h"
#include "../command_event.h"
/* TODO/FIXME - turn this into actual task */

View File

@ -15,13 +15,14 @@
#include <compat/strcasestr.h>
#include <compat/strl.h>
#include <retro_miscellaneous.h>
#include <retro_endianness.h>
#include <string/stdstring.h>
#include <file/dir_list.h>
#include <file/file_path.h>
#include <queues/message_queue.h>
#include "tasks.h"
#include "tasks_internal.h"
#ifdef HAVE_LIBRETRODB
#include "../database_info.h"

View File

@ -21,6 +21,7 @@
#include <string/stdstring.h>
#include <file/file_path.h>
#include <file/file_archive.h>
#include <retro_miscellaneous.h>
#include <retro_stat.h>
#include "tasks.h"

View File

@ -26,6 +26,7 @@
#include <rhash.h>
#include "tasks.h"
#include "tasks_internal.h"
#include "../verbosity.h"
#define CB_MENU_WALLPAPER 0xb476e505U

View File

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

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#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);

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef COMMON_TASKS_H
#define COMMON_TASKS_H
#ifndef TASKS_HANDLER_H
#define TASKS_HANDLER_H
#include <stdint.h>
#include <boolean.h>
#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);

59
tasks/tasks_internal.c Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#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);
}
}
}

80
tasks/tasks_internal.h Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef TASKS_HANDLER_INTERNAL_H
#define TASKS_HANDLER_INTERNAL_H
#include <stdint.h>
#include <boolean.h>
#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