RetroArch/tasks/tasks.h

169 lines
4.7 KiB
C
Raw Normal View History

2015-05-05 17:36:58 +02:00
/* RetroArch - A frontend for libretro.
2016-01-10 04:06:50 +01:00
* Copyright (C) 2011-2016 - Daniel De Matteis
2015-05-05 17:36:58 +02:00
*
* 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 COMMON_TASKS_H
#define COMMON_TASKS_H
#include <stdint.h>
#include <boolean.h>
2015-07-08 22:14:31 +02:00
2015-11-30 15:35:57 +01:00
#include "../runloop.h"
2015-05-05 17:36:58 +02:00
#ifdef __cplusplus
extern "C" {
#endif
2016-01-28 09:35:25 +01:00
enum task_ctl_state
{
2016-01-28 09:38:21 +01:00
TASK_CTL_NONE = 0,
2016-01-28 09:48:47 +01:00
/* Deinitializes the task system.
* This deinitializes the task system.
* The tasks that are running at
* the moment will stay on hold
* until TASK_CTL_INIT is called again. */
TASK_CTL_DEINIT,
2016-01-28 09:52:28 +01:00
/* Initializes the task system.
* This initializes the task system
* and chooses an appropriate
* implementation according to the settings.
*
* This must only be called from the main thread. */
TASK_CTL_INIT,
2016-01-28 09:38:21 +01:00
/* Blocks until all tasks have finished.
* This must only be called from the main thread. */
TASK_CTL_WAIT,
2016-01-28 09:45:14 +01:00
/* Checks for finished tasks
* Takes the finished tasks, if any, and runs their callbacks.
* This must only be called from the main thread. */
TASK_CTL_CHECK,
2016-01-28 09:42:55 +01:00
/* Pushes a task
* The task will start as soon as possible. */
TASK_CTL_PUSH,
2016-01-28 09:38:21 +01:00
/* Sends a signal to terminate all the tasks.
*
* This won't terminate the tasks immediately.
* They will finish as soon as possible.
*
* This must only be called from the main thread. */
TASK_CTL_RESET,
2016-01-28 09:35:25 +01:00
};
2015-11-22 20:15:42 -03:00
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 *user_data);
2015-11-22 20:15:42 -03:00
2016-01-28 09:33:09 +01:00
typedef struct
{
char *source_file;
} decompress_task_data_t;
struct rarch_task
{
rarch_task_handler_t handler;
rarch_task_callback_t callback; /* always called from the main loop */
2015-11-22 20:15:42 -03:00
2016-01-28 09:33:09 +01:00
/* set to true by the handler to signal the task has finished executing. */
bool finished;
2015-11-22 20:15:42 -03:00
2016-01-28 09:33:09 +01:00
/* set to true by the task system to signal the task *must* end. */
bool cancelled;
2016-01-28 09:33:09 +01:00
/* created by the handler, destroyed by the user */
void *task_data;
2015-11-22 20:15:42 -03:00
2016-01-28 09:33:09 +01:00
/* owned by the user */
void *user_data;
2015-11-22 20:15:42 -03:00
2016-01-28 09:33:09 +01:00
/* created and destroyed by the code related to the handler */
void *state;
2015-11-22 20:15:42 -03:00
2016-01-28 09:33:09 +01:00
/* created by task handler; destroyed by main loop (after calling the callback) */
char *error;
2015-11-22 20:15:42 -03:00
2016-01-28 09:33:09 +01:00
/* -1 = unmettered, 0-100 progress value */
int8_t progress;
char *title; /* handler can modify but will be free()d automatically if non-null */
2016-01-28 09:33:09 +01:00
/* don't touch this. */
rarch_task_t *next;
2015-11-22 20:15:42 -03:00
};
/**
* @brief Calls func for every running task until it returns true.
*
* @param func
* @param user_data
* @return a task or NULL if not found.
*/
bool rarch_task_find(rarch_task_finder_t func, void *user_data);
2015-05-05 17:36:58 +02:00
#ifdef HAVE_NETWORKING
2015-11-23 11:13:26 -03:00
typedef struct {
char *data;
size_t len;
} http_transfer_data_t;
2015-07-08 21:38:22 +02:00
2015-11-23 11:13:26 -03:00
bool rarch_task_push_http_transfer(const char *url, const char *type, rarch_task_callback_t cb, void *user_data);
2015-05-05 17:36:58 +02:00
#endif
bool rarch_task_push_image_load(const char *fullpath, const char *type, rarch_task_callback_t cb, void *user_data);
#ifdef HAVE_LIBRETRODB
bool rarch_task_push_dbscan(const char *fullpath, bool directory, rarch_task_callback_t cb);
#endif
#ifdef HAVE_OVERLAY
2015-11-23 14:15:19 -03:00
bool rarch_task_push_overlay_load_default(
rarch_task_callback_t cb, void *user_data);
#endif
2015-05-05 17:36:58 +02:00
2015-09-16 22:39:47 +02:00
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);
2015-09-27 00:12:17 +02:00
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);
2015-11-27 17:43:49 -03:00
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);
2016-01-28 09:35:25 +01:00
bool task_ctl(enum task_ctl_state state, void *data);
2015-05-05 17:36:58 +02:00
#ifdef __cplusplus
}
#endif
#endif