2015-02-23 01:54:14 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
|
|
|
* Copyright (C) 2011-2015 - 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/>.
|
|
|
|
*/
|
|
|
|
|
2015-03-15 01:00:11 +00:00
|
|
|
#include <retro_miscellaneous.h>
|
|
|
|
#include "runloop.h"
|
2015-02-23 01:54:14 +00:00
|
|
|
#include "general.h"
|
2015-03-15 01:00:11 +00:00
|
|
|
#include "input/input_overlay.h"
|
2015-03-18 04:50:37 +00:00
|
|
|
|
2015-03-18 21:11:53 +00:00
|
|
|
#ifdef HAVE_THREADS
|
|
|
|
#include <rthreads/rthreads.h>
|
|
|
|
#endif
|
|
|
|
|
2015-03-18 04:50:37 +00:00
|
|
|
typedef int (*transfer_cb_t )(void *data, size_t len);
|
|
|
|
|
2015-02-23 01:54:14 +00:00
|
|
|
#ifdef HAVE_NETWORKING
|
|
|
|
#include "net_http.h"
|
2015-03-18 04:50:37 +00:00
|
|
|
|
|
|
|
typedef struct http_handle
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
struct http_connection_t *handle;
|
|
|
|
transfer_cb_t cb;
|
|
|
|
char elem1[PATH_MAX_LENGTH];
|
|
|
|
} connection;
|
|
|
|
msg_queue_t *msg_queue;
|
|
|
|
struct http_t *handle;
|
|
|
|
transfer_cb_t cb;
|
|
|
|
} http_handle_t;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef struct nbio_image_handle
|
|
|
|
{
|
|
|
|
#ifndef IS_SALAMANDER
|
|
|
|
struct texture_image ti;
|
|
|
|
#endif
|
|
|
|
bool is_blocking;
|
|
|
|
bool is_blocking_on_processing;
|
|
|
|
bool is_finished;
|
|
|
|
bool is_finished_with_processing;
|
|
|
|
transfer_cb_t cb;
|
|
|
|
struct rpng_t *handle;
|
|
|
|
unsigned processing_pos_increment;
|
|
|
|
unsigned pos_increment;
|
|
|
|
uint64_t frame_count;
|
|
|
|
uint64_t processing_frame_count;
|
|
|
|
int processing_final_state;
|
|
|
|
msg_queue_t *msg_queue;
|
|
|
|
} nbio_image_handle_t;
|
|
|
|
|
|
|
|
typedef struct nbio_handle
|
|
|
|
{
|
|
|
|
nbio_image_handle_t image;
|
|
|
|
bool is_blocking;
|
|
|
|
bool is_finished;
|
|
|
|
transfer_cb_t cb;
|
|
|
|
struct nbio_t *handle;
|
|
|
|
unsigned pos_increment;
|
|
|
|
uint64_t frame_count;
|
|
|
|
msg_queue_t *msg_queue;
|
|
|
|
} nbio_handle_t;
|
|
|
|
|
2015-03-19 06:18:27 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
THREAD_CODE_INIT = 0,
|
|
|
|
THREAD_CODE_ALIVE,
|
|
|
|
} thread_code_enum;
|
2015-03-18 04:50:37 +00:00
|
|
|
|
|
|
|
typedef struct data_runloop
|
|
|
|
{
|
|
|
|
#ifdef HAVE_NETWORKING
|
|
|
|
http_handle_t http;
|
2015-03-15 02:21:58 +00:00
|
|
|
#endif
|
2015-02-23 01:54:14 +00:00
|
|
|
|
2015-03-18 04:50:37 +00:00
|
|
|
#if 0
|
|
|
|
#ifdef HAVE_LIBRETRODB
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
} db;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nbio_handle_t nbio;
|
2015-03-18 20:26:36 +00:00
|
|
|
bool inited;
|
2015-03-18 21:11:53 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_THREADS
|
|
|
|
bool thread_inited;
|
2015-03-19 06:18:27 +00:00
|
|
|
unsigned thread_code;
|
|
|
|
bool alive;
|
2015-03-18 21:11:53 +00:00
|
|
|
|
|
|
|
slock_t *lock;
|
|
|
|
slock_t *cond_lock;
|
2015-03-18 23:13:54 +00:00
|
|
|
slock_t *overlay_lock;
|
2015-03-18 21:11:53 +00:00
|
|
|
scond_t *cond;
|
|
|
|
sthread_t *thread;
|
|
|
|
#endif
|
2015-03-18 04:50:37 +00:00
|
|
|
} data_runloop_t;
|
|
|
|
|
2015-03-15 02:21:58 +00:00
|
|
|
struct data_runloop g_data_runloop;
|
|
|
|
|
|
|
|
#ifdef HAVE_NETWORKING
|
2015-02-23 01:54:14 +00:00
|
|
|
int cb_core_updater_download(void *data_, size_t len);
|
|
|
|
int cb_core_updater_list(void *data_, size_t len);
|
|
|
|
|
|
|
|
/**
|
2015-03-14 14:50:34 +00:00
|
|
|
* rarch_main_data_http_iterate_transfer:
|
2015-02-23 01:54:14 +00:00
|
|
|
*
|
|
|
|
* Resumes HTTP transfer update.
|
|
|
|
*
|
|
|
|
* Returns: 0 when finished, -1 when we should continue
|
|
|
|
* with the transfer on the next frame.
|
|
|
|
**/
|
2015-03-14 18:59:37 +00:00
|
|
|
static int rarch_main_data_http_iterate_transfer(http_handle_t *http)
|
2015-02-23 01:54:14 +00:00
|
|
|
{
|
|
|
|
size_t pos = 0, tot = 0;
|
|
|
|
|
2015-03-14 18:59:37 +00:00
|
|
|
if (!net_http_update(http->handle, &pos, &tot))
|
2015-02-23 01:54:14 +00:00
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
RARCH_LOG("%.9I64u / %.9I64u \r", (unsigned long long)pos, (unsigned long long)tot);
|
|
|
|
#else
|
|
|
|
RARCH_LOG("%.9llu / %.9llu \r", (unsigned long long)pos, (unsigned long long)tot);
|
|
|
|
#endif
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-14 18:59:37 +00:00
|
|
|
static int rarch_main_data_http_con_iterate_transfer(http_handle_t *http)
|
2015-02-26 04:35:58 +00:00
|
|
|
{
|
2015-03-14 18:59:37 +00:00
|
|
|
if (!net_http_connection_iterate(http->connection.handle))
|
2015-02-26 04:35:58 +00:00
|
|
|
return -1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-14 18:59:37 +00:00
|
|
|
static int rarch_main_data_http_conn_iterate_transfer_parse(http_handle_t *http)
|
2015-02-26 04:35:58 +00:00
|
|
|
{
|
2015-03-14 18:59:37 +00:00
|
|
|
if (net_http_connection_done(http->connection.handle))
|
2015-02-26 04:35:58 +00:00
|
|
|
{
|
2015-03-14 18:59:37 +00:00
|
|
|
if (http->connection.handle && http->connection.cb)
|
2015-03-14 19:04:53 +00:00
|
|
|
http->connection.cb(http, 0);
|
2015-02-26 04:35:58 +00:00
|
|
|
}
|
|
|
|
|
2015-03-14 18:59:37 +00:00
|
|
|
net_http_connection_free(http->connection.handle);
|
2015-02-26 04:35:58 +00:00
|
|
|
|
2015-03-14 18:59:37 +00:00
|
|
|
http->connection.handle = NULL;
|
2015-02-26 04:35:58 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-14 18:59:37 +00:00
|
|
|
static int rarch_main_data_http_iterate_transfer_parse(http_handle_t *http)
|
2015-02-23 01:54:14 +00:00
|
|
|
{
|
|
|
|
size_t len;
|
2015-03-14 18:59:37 +00:00
|
|
|
char *data = (char*)net_http_data(http->handle, &len, false);
|
2015-02-23 01:54:14 +00:00
|
|
|
|
2015-03-14 18:59:37 +00:00
|
|
|
if (data && http->cb)
|
|
|
|
http->cb(data, len);
|
2015-02-23 01:54:14 +00:00
|
|
|
|
2015-03-14 18:59:37 +00:00
|
|
|
net_http_delete(http->handle);
|
2015-02-23 01:54:14 +00:00
|
|
|
|
2015-03-14 18:59:37 +00:00
|
|
|
http->handle = NULL;
|
|
|
|
msg_queue_clear(http->msg_queue);
|
2015-02-23 01:54:14 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-02-26 04:35:58 +00:00
|
|
|
static int cb_http_conn_default(void *data_, size_t len)
|
|
|
|
{
|
2015-03-14 19:04:53 +00:00
|
|
|
http_handle_t *http = (http_handle_t*)data_;
|
2015-02-26 04:35:58 +00:00
|
|
|
|
2015-03-14 19:04:53 +00:00
|
|
|
if (!http)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
http->handle = net_http_new(http->connection.handle);
|
|
|
|
|
|
|
|
if (!http->handle)
|
2015-02-26 04:35:58 +00:00
|
|
|
{
|
|
|
|
RARCH_ERR("Could not create new HTTP session handle.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-03-14 19:04:53 +00:00
|
|
|
http->cb = NULL;
|
2015-02-26 04:35:58 +00:00
|
|
|
|
2015-03-14 19:04:53 +00:00
|
|
|
if (http->connection.elem1[0] != '\0')
|
2015-02-26 04:35:58 +00:00
|
|
|
{
|
2015-03-14 19:04:53 +00:00
|
|
|
if (!strcmp(http->connection.elem1, "cb_core_updater_download"))
|
|
|
|
http->cb = &cb_core_updater_download;
|
|
|
|
if (!strcmp(http->connection.elem1, "cb_core_updater_list"))
|
|
|
|
http->cb = &cb_core_updater_list;
|
2015-02-26 04:35:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-02-23 01:54:14 +00:00
|
|
|
/**
|
2015-03-14 14:50:34 +00:00
|
|
|
* rarch_main_data_http_iterate_poll:
|
2015-02-23 01:54:14 +00:00
|
|
|
*
|
|
|
|
* Polls HTTP message queue to see if any new URLs
|
|
|
|
* are pending.
|
|
|
|
*
|
|
|
|
* If handle is freed, will set up a new http handle.
|
|
|
|
* The transfer will be started on the next frame.
|
|
|
|
*
|
|
|
|
* Returns: 0 when an URL has been pulled and we will
|
|
|
|
* begin transferring on the next frame. Returns -1 if
|
|
|
|
* no HTTP URL has been pulled. Do nothing in that case.
|
|
|
|
**/
|
2015-03-14 18:59:37 +00:00
|
|
|
static int rarch_main_data_http_iterate_poll(http_handle_t *http)
|
2015-02-23 01:54:14 +00:00
|
|
|
{
|
2015-02-26 04:35:58 +00:00
|
|
|
char elem0[PATH_MAX_LENGTH];
|
2015-02-23 01:54:14 +00:00
|
|
|
struct string_list *str_list = NULL;
|
2015-03-14 18:59:37 +00:00
|
|
|
const char *url = msg_queue_pull(http->msg_queue);
|
2015-02-23 01:54:14 +00:00
|
|
|
|
|
|
|
if (!url)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Can only deal with one HTTP transfer at a time for now */
|
2015-03-14 18:59:37 +00:00
|
|
|
if (http->handle)
|
2015-02-23 01:54:14 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
str_list = string_split(url, "|");
|
|
|
|
|
|
|
|
if (!str_list)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (str_list->size > 0)
|
|
|
|
strlcpy(elem0, str_list->elems[0].data, sizeof(elem0));
|
|
|
|
|
2015-03-14 18:59:37 +00:00
|
|
|
http->connection.handle = net_http_connection_new(elem0);
|
2015-02-23 01:54:14 +00:00
|
|
|
|
2015-03-14 18:59:37 +00:00
|
|
|
if (!http->connection.handle)
|
2015-02-23 01:54:14 +00:00
|
|
|
return -1;
|
|
|
|
|
2015-03-14 18:59:37 +00:00
|
|
|
http->connection.cb = &cb_http_conn_default;
|
2015-02-23 01:54:14 +00:00
|
|
|
|
2015-02-26 04:35:58 +00:00
|
|
|
if (str_list->size > 1)
|
2015-03-14 18:59:37 +00:00
|
|
|
strlcpy(http->connection.elem1,
|
2015-02-26 04:35:58 +00:00
|
|
|
str_list->elems[1].data,
|
2015-03-14 18:59:37 +00:00
|
|
|
sizeof(http->connection.elem1));
|
2015-02-23 01:54:14 +00:00
|
|
|
|
|
|
|
string_list_free(str_list);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-02-24 02:01:59 +00:00
|
|
|
#ifdef HAVE_MENU
|
2015-03-14 02:49:59 +00:00
|
|
|
static int cb_image_menu_wallpaper_upload(void *data, size_t len)
|
|
|
|
{
|
|
|
|
nbio_handle_t *nbio = (nbio_handle_t*)data;
|
2015-03-18 18:40:00 +00:00
|
|
|
driver_t *driver = driver_get_ptr();
|
2015-03-14 02:49:59 +00:00
|
|
|
|
|
|
|
if (!nbio || !data)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (nbio->image.processing_final_state == IMAGE_PROCESS_ERROR ||
|
|
|
|
nbio->image.processing_final_state == IMAGE_PROCESS_ERROR_END)
|
|
|
|
return -1;
|
|
|
|
|
2015-03-18 18:40:00 +00:00
|
|
|
if (driver->menu_ctx && driver->menu_ctx->load_background)
|
|
|
|
driver->menu_ctx->load_background(&nbio->image.ti);
|
2015-03-14 02:49:59 +00:00
|
|
|
|
|
|
|
texture_image_free(&nbio->image.ti);
|
|
|
|
|
|
|
|
nbio->image.is_blocking_on_processing = false;
|
|
|
|
nbio->image.is_finished_with_processing = true;
|
|
|
|
nbio->image.is_blocking = true;
|
|
|
|
nbio->image.is_finished = true;
|
|
|
|
nbio->is_blocking = true;
|
|
|
|
nbio->is_finished = true;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-02-25 04:30:30 +00:00
|
|
|
static int cb_image_menu_wallpaper(void *data, size_t len)
|
2015-02-23 04:14:36 +00:00
|
|
|
{
|
2015-03-14 02:18:15 +00:00
|
|
|
int retval;
|
2015-02-25 06:52:54 +00:00
|
|
|
nbio_handle_t *nbio = (nbio_handle_t*)data;
|
2015-02-23 05:03:53 +00:00
|
|
|
|
2015-02-25 06:32:53 +00:00
|
|
|
if (!nbio || !data)
|
2015-02-23 05:03:53 +00:00
|
|
|
return -1;
|
|
|
|
|
2015-02-25 06:32:53 +00:00
|
|
|
if ( !nbio->image.handle->has_ihdr ||
|
|
|
|
!nbio->image.handle->has_idat ||
|
|
|
|
!nbio->image.handle->has_iend)
|
|
|
|
return -1;
|
|
|
|
|
2015-03-14 02:49:59 +00:00
|
|
|
retval = rpng_nbio_load_image_argb_process(nbio->image.handle,
|
|
|
|
&nbio->image.ti.pixels, &nbio->image.ti.width, &nbio->image.ti.height);
|
2015-03-14 02:02:59 +00:00
|
|
|
|
2015-03-14 02:18:15 +00:00
|
|
|
if (retval == IMAGE_PROCESS_ERROR || retval == IMAGE_PROCESS_ERROR_END)
|
|
|
|
return -1;
|
2015-02-23 05:03:53 +00:00
|
|
|
|
2015-03-14 02:49:59 +00:00
|
|
|
nbio->image.cb = &cb_image_menu_wallpaper_upload;
|
2015-02-23 04:14:36 +00:00
|
|
|
|
2015-03-14 02:07:17 +00:00
|
|
|
nbio->image.is_blocking_on_processing = true;
|
|
|
|
nbio->image.is_finished_with_processing = false;
|
2015-03-14 02:49:59 +00:00
|
|
|
nbio->image.is_finished = false;
|
2015-02-23 01:54:14 +00:00
|
|
|
|
2015-02-25 04:30:30 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2015-02-23 04:14:36 +00:00
|
|
|
|
2015-02-25 04:30:30 +00:00
|
|
|
static int cb_nbio_image_menu_wallpaper(void *data, size_t len)
|
|
|
|
{
|
|
|
|
void *ptr = NULL;
|
2015-02-25 06:52:54 +00:00
|
|
|
nbio_handle_t *nbio = (nbio_handle_t*)data;
|
2015-02-25 06:32:53 +00:00
|
|
|
|
|
|
|
if (!nbio || !data)
|
|
|
|
return -1;
|
2015-02-24 02:01:59 +00:00
|
|
|
|
2015-02-25 06:32:53 +00:00
|
|
|
nbio->image.handle = (struct rpng_t*)calloc(1, sizeof(struct rpng_t));
|
|
|
|
nbio->image.cb = &cb_image_menu_wallpaper;
|
2015-02-23 07:24:08 +00:00
|
|
|
|
2015-02-25 06:32:53 +00:00
|
|
|
if (!nbio->image.handle)
|
2015-02-25 07:02:31 +00:00
|
|
|
{
|
|
|
|
nbio->image.cb = NULL;
|
2015-02-25 04:30:30 +00:00
|
|
|
return -1;
|
2015-02-25 07:02:31 +00:00
|
|
|
}
|
2015-02-23 04:14:36 +00:00
|
|
|
|
2015-02-25 06:32:53 +00:00
|
|
|
ptr = nbio_get_ptr(nbio->handle, &len);
|
|
|
|
|
|
|
|
if (!ptr)
|
|
|
|
{
|
|
|
|
free(nbio->image.handle);
|
|
|
|
nbio->image.handle = NULL;
|
2015-02-25 07:02:31 +00:00
|
|
|
nbio->image.cb = NULL;
|
2015-02-25 06:32:53 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
2015-02-23 04:14:36 +00:00
|
|
|
|
2015-02-25 06:32:53 +00:00
|
|
|
nbio->image.handle->buff_data = (uint8_t*)ptr;
|
2015-03-14 02:58:35 +00:00
|
|
|
nbio->image.pos_increment = (len / 2) ? (len / 2) : 1;
|
|
|
|
nbio->image.processing_pos_increment = (len / 4) ? (len / 4) : 1;
|
2015-02-25 04:30:30 +00:00
|
|
|
|
2015-02-25 06:32:53 +00:00
|
|
|
if (!rpng_nbio_load_image_argb_start(nbio->image.handle))
|
2015-02-25 04:30:30 +00:00
|
|
|
{
|
2015-02-25 06:32:53 +00:00
|
|
|
rpng_nbio_load_image_free(nbio->image.handle);
|
2015-02-25 04:30:30 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2015-02-23 04:14:36 +00:00
|
|
|
|
2015-02-25 06:32:53 +00:00
|
|
|
nbio->image.is_blocking = false;
|
|
|
|
nbio->image.is_finished = false;
|
|
|
|
nbio->is_blocking = false;
|
|
|
|
nbio->is_finished = true;
|
2015-02-23 01:54:14 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-03-14 14:50:34 +00:00
|
|
|
static int rarch_main_data_image_iterate_poll(nbio_handle_t *nbio)
|
2015-02-23 04:14:36 +00:00
|
|
|
{
|
2015-02-25 06:38:42 +00:00
|
|
|
const char *path = NULL;
|
|
|
|
|
|
|
|
if (!nbio)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
path = msg_queue_pull(nbio->image.msg_queue);
|
2015-02-23 04:14:36 +00:00
|
|
|
|
|
|
|
if (!path)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Can only deal with one image transfer at a time for now */
|
2015-02-25 06:38:42 +00:00
|
|
|
if (nbio->image.handle)
|
2015-02-23 04:14:36 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* We need to load the image file first. */
|
2015-02-25 06:38:42 +00:00
|
|
|
msg_queue_clear(nbio->msg_queue);
|
|
|
|
msg_queue_push(nbio->msg_queue, path, 0, 1);
|
2015-02-23 04:14:36 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-14 14:50:34 +00:00
|
|
|
static int rarch_main_data_image_iterate_transfer(nbio_handle_t *nbio)
|
2015-02-23 04:14:36 +00:00
|
|
|
{
|
2015-02-25 04:30:30 +00:00
|
|
|
unsigned i;
|
2015-02-25 06:38:42 +00:00
|
|
|
|
|
|
|
if (!nbio)
|
|
|
|
return -1;
|
2015-02-25 04:30:30 +00:00
|
|
|
|
2015-02-25 06:38:42 +00:00
|
|
|
if (nbio->image.is_finished)
|
2015-02-24 02:01:59 +00:00
|
|
|
return 0;
|
|
|
|
|
2015-02-25 06:38:42 +00:00
|
|
|
for (i = 0; i < nbio->image.pos_increment; i++)
|
2015-02-23 04:14:36 +00:00
|
|
|
{
|
2015-02-25 23:50:34 +00:00
|
|
|
if (!rpng_nbio_load_image_argb_iterate(
|
2015-02-25 06:38:42 +00:00
|
|
|
nbio->image.handle->buff_data,
|
|
|
|
nbio->image.handle))
|
2015-02-25 23:50:34 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
nbio->image.handle->buff_data +=
|
|
|
|
4 + 4 + nbio->image.handle->chunk.size + 4;
|
2015-02-23 04:14:36 +00:00
|
|
|
}
|
|
|
|
|
2015-02-25 23:50:34 +00:00
|
|
|
nbio->image.frame_count++;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error:
|
2015-02-23 04:14:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-03-14 14:50:34 +00:00
|
|
|
static int rarch_main_data_image_iterate_process_transfer(nbio_handle_t *nbio)
|
2015-03-14 02:49:59 +00:00
|
|
|
{
|
|
|
|
unsigned i;
|
2015-03-15 00:44:58 +00:00
|
|
|
int retval = 0;
|
2015-03-14 02:49:59 +00:00
|
|
|
|
|
|
|
if (!nbio)
|
|
|
|
return -1;
|
|
|
|
|
2015-03-14 02:58:35 +00:00
|
|
|
for (i = 0; i < nbio->image.processing_pos_increment; i++)
|
2015-03-14 02:49:59 +00:00
|
|
|
{
|
|
|
|
retval = rpng_nbio_load_image_argb_process(nbio->image.handle,
|
|
|
|
&nbio->image.ti.pixels, &nbio->image.ti.width, &nbio->image.ti.height);
|
|
|
|
|
|
|
|
if (retval != IMAGE_PROCESS_NEXT)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-03-14 02:58:35 +00:00
|
|
|
nbio->image.processing_frame_count++;
|
|
|
|
|
2015-03-14 02:49:59 +00:00
|
|
|
if (retval == IMAGE_PROCESS_NEXT)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
nbio->image.processing_final_state = retval;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-03-14 14:50:34 +00:00
|
|
|
static int rarch_main_data_image_iterate_parse_free(nbio_handle_t *nbio)
|
2015-02-23 04:14:36 +00:00
|
|
|
{
|
2015-02-25 07:00:10 +00:00
|
|
|
if (!nbio)
|
|
|
|
return -1;
|
2015-02-23 04:14:36 +00:00
|
|
|
|
2015-02-25 07:00:10 +00:00
|
|
|
rpng_nbio_load_image_free(nbio->image.handle);
|
2015-03-14 02:49:59 +00:00
|
|
|
|
|
|
|
nbio->image.handle = NULL;
|
|
|
|
nbio->image.frame_count = 0;
|
|
|
|
nbio->image.processing_frame_count = 0;
|
2015-02-25 07:00:10 +00:00
|
|
|
|
|
|
|
msg_queue_clear(nbio->image.msg_queue);
|
2015-02-23 04:14:36 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-14 14:50:34 +00:00
|
|
|
static int rarch_main_data_image_iterate_process_transfer_parse(nbio_handle_t *nbio)
|
2015-03-14 02:49:59 +00:00
|
|
|
{
|
|
|
|
size_t len = 0;
|
|
|
|
if (nbio->image.handle && nbio->image.cb)
|
|
|
|
nbio->image.cb(nbio, len);
|
|
|
|
|
|
|
|
RARCH_LOG("Image transfer processing took %d frames.\n", (unsigned)nbio->image.processing_frame_count);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-14 14:50:34 +00:00
|
|
|
static int rarch_main_data_image_iterate_transfer_parse(nbio_handle_t *nbio)
|
2015-02-23 04:14:36 +00:00
|
|
|
{
|
|
|
|
size_t len = 0;
|
2015-02-25 07:00:10 +00:00
|
|
|
if (nbio->image.handle && nbio->image.cb)
|
|
|
|
nbio->image.cb(nbio, len);
|
2015-02-23 04:14:36 +00:00
|
|
|
|
2015-02-26 00:46:08 +00:00
|
|
|
RARCH_LOG("Image transfer took %d frames.\n", (unsigned)nbio->image.frame_count);
|
|
|
|
|
2015-02-23 04:14:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-02-23 01:54:14 +00:00
|
|
|
static int cb_nbio_default(void *data, size_t len)
|
|
|
|
{
|
2015-02-25 06:32:53 +00:00
|
|
|
nbio_handle_t *nbio = (nbio_handle_t*)data;
|
|
|
|
|
|
|
|
if (!data)
|
|
|
|
return -1;
|
|
|
|
|
2015-02-23 01:54:14 +00:00
|
|
|
(void)len;
|
|
|
|
|
2015-02-25 06:32:53 +00:00
|
|
|
nbio->is_blocking = false;
|
|
|
|
nbio->is_finished = true;
|
2015-02-23 01:54:14 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-14 14:50:34 +00:00
|
|
|
static int rarch_main_data_nbio_iterate_poll(nbio_handle_t *nbio)
|
2015-02-23 01:54:14 +00:00
|
|
|
{
|
|
|
|
struct nbio_t* handle;
|
|
|
|
char elem0[PATH_MAX_LENGTH], elem1[PATH_MAX_LENGTH];
|
|
|
|
struct string_list *str_list = NULL;
|
2015-02-25 06:49:13 +00:00
|
|
|
const char *path = NULL;
|
|
|
|
|
|
|
|
if (!nbio)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
path = msg_queue_pull(nbio->msg_queue);
|
2015-02-23 01:54:14 +00:00
|
|
|
|
|
|
|
if (!path)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Can only deal with one NBIO transfer at a time for now */
|
2015-02-25 06:49:13 +00:00
|
|
|
if (nbio->handle)
|
2015-02-23 01:54:14 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
str_list = string_split(path, "|");
|
|
|
|
|
|
|
|
if (!str_list)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (str_list->size > 0)
|
|
|
|
strlcpy(elem0, str_list->elems[0].data, sizeof(elem0));
|
|
|
|
if (str_list->size > 1)
|
|
|
|
strlcpy(elem1, str_list->elems[1].data, sizeof(elem1));
|
|
|
|
|
|
|
|
handle = nbio_open(elem0, NBIO_READ);
|
|
|
|
|
|
|
|
if (!handle)
|
|
|
|
{
|
|
|
|
RARCH_ERR("Could not create new file loading handle.\n");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2015-02-25 06:49:13 +00:00
|
|
|
nbio->handle = handle;
|
|
|
|
nbio->is_blocking = false;
|
|
|
|
nbio->is_finished = false;
|
|
|
|
nbio->cb = &cb_nbio_default;
|
2015-02-23 01:54:14 +00:00
|
|
|
|
|
|
|
if (elem1[0] != '\0')
|
|
|
|
{
|
2015-02-24 02:01:59 +00:00
|
|
|
#ifdef HAVE_MENU
|
|
|
|
if (!strcmp(elem1, "cb_menu_wallpaper"))
|
2015-02-25 06:49:13 +00:00
|
|
|
nbio->cb = &cb_nbio_image_menu_wallpaper;
|
2015-02-23 01:54:14 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
nbio_begin_read(handle);
|
|
|
|
|
|
|
|
string_list_free(str_list);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error:
|
|
|
|
if (str_list)
|
|
|
|
string_list_free(str_list);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-03-14 14:50:34 +00:00
|
|
|
static int rarch_main_data_nbio_iterate_transfer(nbio_handle_t *nbio)
|
2015-02-23 01:54:14 +00:00
|
|
|
{
|
2015-02-25 06:10:04 +00:00
|
|
|
size_t i;
|
2015-02-25 06:38:42 +00:00
|
|
|
|
|
|
|
if (!nbio)
|
|
|
|
return -1;
|
2015-02-25 06:10:04 +00:00
|
|
|
|
2015-02-25 06:38:42 +00:00
|
|
|
nbio->pos_increment = 5;
|
2015-02-25 06:10:04 +00:00
|
|
|
|
2015-02-25 06:38:42 +00:00
|
|
|
if (nbio->is_finished)
|
2015-02-25 04:30:30 +00:00
|
|
|
return 0;
|
|
|
|
|
2015-02-25 06:38:42 +00:00
|
|
|
for (i = 0; i < nbio->pos_increment; i++)
|
2015-02-25 06:10:04 +00:00
|
|
|
{
|
2015-02-25 23:50:34 +00:00
|
|
|
if (nbio_iterate(nbio->handle))
|
|
|
|
goto error;
|
2015-02-25 06:10:04 +00:00
|
|
|
}
|
2015-02-23 01:54:14 +00:00
|
|
|
|
2015-02-25 23:50:34 +00:00
|
|
|
nbio->frame_count++;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error:
|
2015-02-24 02:01:59 +00:00
|
|
|
return -1;
|
2015-02-23 01:54:14 +00:00
|
|
|
}
|
|
|
|
|
2015-03-14 14:50:34 +00:00
|
|
|
static int rarch_main_data_nbio_iterate_parse_free(nbio_handle_t *nbio)
|
2015-02-23 01:54:14 +00:00
|
|
|
{
|
2015-02-25 06:38:42 +00:00
|
|
|
if (!nbio)
|
|
|
|
return -1;
|
|
|
|
if (!nbio->is_finished)
|
2015-02-23 01:54:14 +00:00
|
|
|
return -1;
|
|
|
|
|
2015-02-25 06:38:42 +00:00
|
|
|
nbio_free(nbio->handle);
|
|
|
|
nbio->handle = NULL;
|
|
|
|
nbio->is_blocking = false;
|
|
|
|
nbio->is_finished = false;
|
2015-02-26 00:47:16 +00:00
|
|
|
nbio->frame_count = 0;
|
2015-02-23 01:54:14 +00:00
|
|
|
|
2015-02-25 06:38:42 +00:00
|
|
|
msg_queue_clear(nbio->msg_queue);
|
2015-02-23 01:54:14 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-14 14:50:34 +00:00
|
|
|
static int rarch_main_data_nbio_iterate_parse(nbio_handle_t *nbio)
|
2015-02-23 01:54:14 +00:00
|
|
|
{
|
2015-02-25 06:32:53 +00:00
|
|
|
int len = 0;
|
2015-02-25 06:38:42 +00:00
|
|
|
|
|
|
|
if (!nbio)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (nbio->cb)
|
|
|
|
nbio->cb(nbio, len);
|
2015-02-23 01:54:14 +00:00
|
|
|
|
2015-02-26 00:46:08 +00:00
|
|
|
RARCH_LOG("File transfer took %d frames.\n", (unsigned)nbio->frame_count);
|
|
|
|
|
2015-02-23 01:54:14 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-02-23 02:00:41 +00:00
|
|
|
#ifdef HAVE_MENU
|
2015-03-14 14:50:34 +00:00
|
|
|
static void rarch_main_data_rdl_iterate(void)
|
2015-02-23 02:00:41 +00:00
|
|
|
{
|
2015-03-18 18:40:00 +00:00
|
|
|
driver_t *driver = driver_get_ptr();
|
|
|
|
|
|
|
|
if (!driver->menu->rdl)
|
2015-02-23 02:00:41 +00:00
|
|
|
return;
|
|
|
|
|
2015-03-18 18:40:00 +00:00
|
|
|
if (driver->menu->rdl->blocking)
|
2015-02-23 02:00:41 +00:00
|
|
|
{
|
|
|
|
/* Do nonblocking I/O transfers here. */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-02-24 04:15:10 +00:00
|
|
|
#ifdef HAVE_LIBRETRODB
|
2015-03-18 18:40:00 +00:00
|
|
|
if (!driver->menu->rdl->iterating)
|
2015-02-23 02:00:41 +00:00
|
|
|
{
|
2015-03-18 18:40:00 +00:00
|
|
|
database_info_write_rdl_free(driver->menu->rdl);
|
|
|
|
driver->menu->rdl = NULL;
|
2015-02-23 02:00:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-18 18:40:00 +00:00
|
|
|
database_info_write_rdl_iterate(driver->menu->rdl);
|
2015-02-24 04:15:10 +00:00
|
|
|
#endif
|
2015-02-23 02:00:41 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-03-18 23:13:54 +00:00
|
|
|
static void rarch_main_data_nbio_iterate(bool is_thread, nbio_handle_t *nbio)
|
2015-02-23 01:54:14 +00:00
|
|
|
{
|
2015-02-25 07:00:10 +00:00
|
|
|
if (!nbio)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (nbio->handle)
|
2015-02-23 01:54:14 +00:00
|
|
|
{
|
2015-02-25 07:00:10 +00:00
|
|
|
if (!nbio->is_blocking)
|
2015-02-23 01:54:14 +00:00
|
|
|
{
|
2015-03-14 14:50:34 +00:00
|
|
|
if (rarch_main_data_nbio_iterate_transfer(nbio) == -1)
|
|
|
|
rarch_main_data_nbio_iterate_parse(nbio);
|
2015-02-23 01:54:14 +00:00
|
|
|
}
|
2015-02-25 07:00:10 +00:00
|
|
|
else if (nbio->is_finished)
|
2015-03-14 14:50:34 +00:00
|
|
|
rarch_main_data_nbio_iterate_parse_free(nbio);
|
2015-02-23 01:54:14 +00:00
|
|
|
}
|
|
|
|
else
|
2015-03-14 14:50:34 +00:00
|
|
|
rarch_main_data_nbio_iterate_poll(nbio);
|
2015-02-23 01:54:14 +00:00
|
|
|
|
2015-02-25 07:00:10 +00:00
|
|
|
if (nbio->image.handle)
|
2015-02-23 04:14:36 +00:00
|
|
|
{
|
2015-03-14 02:18:15 +00:00
|
|
|
if (nbio->image.is_blocking_on_processing)
|
|
|
|
{
|
2015-03-14 14:50:34 +00:00
|
|
|
if (rarch_main_data_image_iterate_process_transfer(nbio) == -1)
|
|
|
|
rarch_main_data_image_iterate_process_transfer_parse(nbio);
|
2015-03-14 02:18:15 +00:00
|
|
|
}
|
2015-03-14 02:49:59 +00:00
|
|
|
else if (!nbio->image.is_blocking)
|
2015-02-23 04:14:36 +00:00
|
|
|
{
|
2015-03-14 14:50:34 +00:00
|
|
|
if (rarch_main_data_image_iterate_transfer(nbio) == -1)
|
|
|
|
rarch_main_data_image_iterate_transfer_parse(nbio);
|
2015-02-23 04:14:36 +00:00
|
|
|
}
|
2015-02-25 07:00:10 +00:00
|
|
|
else if (nbio->image.is_finished)
|
2015-03-14 14:50:34 +00:00
|
|
|
rarch_main_data_image_iterate_parse_free(nbio);
|
2015-02-23 04:14:36 +00:00
|
|
|
}
|
|
|
|
else
|
2015-03-14 14:50:34 +00:00
|
|
|
rarch_main_data_image_iterate_poll(nbio);
|
2015-02-25 07:00:10 +00:00
|
|
|
}
|
2015-02-23 04:14:36 +00:00
|
|
|
|
2015-03-14 20:32:48 +00:00
|
|
|
#ifdef HAVE_NETWORKING
|
2015-03-18 23:13:54 +00:00
|
|
|
static void rarch_main_data_http_iterate(bool is_thread, http_handle_t *http)
|
2015-02-25 07:00:10 +00:00
|
|
|
{
|
2015-03-14 14:51:28 +00:00
|
|
|
if (!http)
|
|
|
|
return;
|
|
|
|
|
2015-03-14 14:50:34 +00:00
|
|
|
if (http->connection.handle)
|
2015-02-26 04:35:58 +00:00
|
|
|
{
|
2015-03-14 18:59:37 +00:00
|
|
|
if (!rarch_main_data_http_con_iterate_transfer(http))
|
|
|
|
rarch_main_data_http_conn_iterate_transfer_parse(http);
|
2015-02-26 04:35:58 +00:00
|
|
|
}
|
|
|
|
|
2015-03-14 14:50:34 +00:00
|
|
|
if (http->handle)
|
2015-02-23 01:54:14 +00:00
|
|
|
{
|
2015-03-14 18:59:37 +00:00
|
|
|
if (!rarch_main_data_http_iterate_transfer(http))
|
|
|
|
rarch_main_data_http_iterate_transfer_parse(http);
|
2015-02-23 01:54:14 +00:00
|
|
|
}
|
|
|
|
else
|
2015-03-14 18:59:37 +00:00
|
|
|
rarch_main_data_http_iterate_poll(http);
|
2015-03-14 14:50:34 +00:00
|
|
|
}
|
2015-03-14 20:32:48 +00:00
|
|
|
#endif
|
2015-02-23 01:54:14 +00:00
|
|
|
|
2015-03-14 14:50:34 +00:00
|
|
|
static void rarch_main_data_db_iterate(void)
|
|
|
|
{
|
2015-03-18 18:40:00 +00:00
|
|
|
driver_t *driver = driver_get_ptr();
|
2015-02-23 01:54:14 +00:00
|
|
|
#ifdef HAVE_MENU
|
2015-03-18 18:40:00 +00:00
|
|
|
if (driver->menu && driver->menu->rdl)
|
2015-03-14 14:50:34 +00:00
|
|
|
rarch_main_data_rdl_iterate();
|
2015-02-23 01:54:14 +00:00
|
|
|
#endif
|
|
|
|
}
|
2015-03-14 14:50:34 +00:00
|
|
|
|
2015-03-15 00:46:00 +00:00
|
|
|
#ifdef HAVE_OVERLAY
|
2015-03-18 23:13:54 +00:00
|
|
|
static void rarch_main_data_overlay_iterate(bool is_thread, data_runloop_t *runloop)
|
2015-03-18 22:20:07 +00:00
|
|
|
{
|
2015-03-18 23:13:54 +00:00
|
|
|
driver_t *driver = driver_get_ptr();
|
2015-03-18 18:40:00 +00:00
|
|
|
|
2015-03-18 19:48:17 +00:00
|
|
|
if (rarch_main_is_idle())
|
2015-03-15 00:39:43 +00:00
|
|
|
return;
|
2015-03-18 18:40:00 +00:00
|
|
|
if (!driver->overlay)
|
2015-03-15 00:39:43 +00:00
|
|
|
return;
|
|
|
|
|
2015-03-18 23:13:54 +00:00
|
|
|
#ifdef HAVE_THREADS
|
|
|
|
if (is_thread)
|
|
|
|
slock_lock(runloop->overlay_lock);
|
|
|
|
#endif
|
|
|
|
|
2015-03-18 18:40:00 +00:00
|
|
|
switch (driver->overlay->state)
|
2015-03-15 00:39:43 +00:00
|
|
|
{
|
|
|
|
case OVERLAY_STATUS_NONE:
|
|
|
|
case OVERLAY_STATUS_ALIVE:
|
|
|
|
break;
|
|
|
|
case OVERLAY_STATUS_DEFERRED_LOAD:
|
2015-03-18 18:40:00 +00:00
|
|
|
input_overlay_load_overlays(driver->overlay);
|
2015-03-15 00:39:43 +00:00
|
|
|
break;
|
|
|
|
case OVERLAY_STATUS_DEFERRED_LOADING:
|
2015-03-18 18:40:00 +00:00
|
|
|
input_overlay_load_overlays_iterate(driver->overlay);
|
2015-03-15 00:39:43 +00:00
|
|
|
break;
|
|
|
|
case OVERLAY_STATUS_DEFERRED_LOADING_RESOLVE:
|
2015-03-18 18:40:00 +00:00
|
|
|
input_overlay_load_overlays_resolve_iterate(driver->overlay);
|
2015-03-15 00:39:43 +00:00
|
|
|
break;
|
|
|
|
case OVERLAY_STATUS_DEFERRED_DONE:
|
2015-03-18 18:40:00 +00:00
|
|
|
input_overlay_new_done(driver->overlay);
|
2015-03-15 00:39:43 +00:00
|
|
|
break;
|
|
|
|
case OVERLAY_STATUS_DEFERRED_ERROR:
|
2015-03-18 18:40:00 +00:00
|
|
|
input_overlay_free(driver->overlay);
|
2015-03-15 00:39:43 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2015-03-18 23:13:54 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_THREADS
|
|
|
|
if (is_thread)
|
|
|
|
slock_unlock(runloop->overlay_lock);
|
|
|
|
#endif
|
2015-03-15 00:39:43 +00:00
|
|
|
}
|
2015-03-15 00:46:00 +00:00
|
|
|
#endif
|
2015-03-15 00:39:43 +00:00
|
|
|
|
2015-03-18 22:39:33 +00:00
|
|
|
static void data_runloop_thread_deinit(data_runloop_t *runloop)
|
2015-03-18 04:35:05 +00:00
|
|
|
{
|
2015-03-18 22:13:00 +00:00
|
|
|
if (!runloop->thread_inited)
|
2015-03-18 21:11:53 +00:00
|
|
|
{
|
|
|
|
slock_lock(runloop->cond_lock);
|
2015-03-19 06:18:27 +00:00
|
|
|
runloop->alive = false;
|
2015-03-18 21:11:53 +00:00
|
|
|
scond_signal(runloop->cond);
|
2015-03-19 06:18:27 +00:00
|
|
|
slock_unlock(runloop->cond_lock);
|
2015-03-18 21:11:53 +00:00
|
|
|
sthread_join(runloop->thread);
|
|
|
|
|
|
|
|
slock_free(runloop->lock);
|
|
|
|
slock_free(runloop->cond_lock);
|
2015-03-18 23:13:54 +00:00
|
|
|
slock_free(runloop->overlay_lock);
|
2015-03-18 21:11:53 +00:00
|
|
|
scond_free(runloop->cond);
|
|
|
|
}
|
2015-03-18 22:39:33 +00:00
|
|
|
|
|
|
|
runloop->thread_inited = false;
|
2015-03-18 22:13:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void rarch_main_data_deinit(void)
|
|
|
|
{
|
|
|
|
data_runloop_t *runloop = &g_data_runloop;
|
|
|
|
|
|
|
|
if (!runloop->inited)
|
|
|
|
return;
|
|
|
|
|
|
|
|
#ifdef HAVE_THREADS
|
|
|
|
if (runloop->thread_inited)
|
2015-03-18 22:39:33 +00:00
|
|
|
data_runloop_thread_deinit(runloop);
|
2015-03-18 21:11:53 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
runloop->inited = false;
|
|
|
|
}
|
|
|
|
|
2015-03-18 23:13:54 +00:00
|
|
|
static void data_runloop_iterate(bool is_thread, data_runloop_t *runloop)
|
2015-03-18 21:11:53 +00:00
|
|
|
{
|
|
|
|
#ifdef HAVE_OVERLAY
|
2015-03-18 23:13:54 +00:00
|
|
|
rarch_main_data_overlay_iterate(is_thread, runloop);
|
2015-03-18 21:11:53 +00:00
|
|
|
#endif
|
2015-03-18 23:13:54 +00:00
|
|
|
rarch_main_data_nbio_iterate(is_thread, &runloop->nbio);
|
2015-03-18 21:11:53 +00:00
|
|
|
#ifdef HAVE_NETWORKING
|
2015-03-18 23:13:54 +00:00
|
|
|
rarch_main_data_http_iterate(is_thread, &runloop->http);
|
2015-03-18 21:11:53 +00:00
|
|
|
#endif
|
|
|
|
rarch_main_data_db_iterate();
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_THREADS
|
|
|
|
static void data_thread_loop(void *data)
|
|
|
|
{
|
|
|
|
data_runloop_t *runloop = (data_runloop_t*)data;
|
|
|
|
|
2015-03-18 22:39:33 +00:00
|
|
|
RARCH_LOG("[Data Thread]: Initializing data thread.\n");
|
|
|
|
|
|
|
|
slock_lock(runloop->lock);
|
|
|
|
while (!runloop->thread_inited)
|
|
|
|
scond_wait(runloop->cond, runloop->lock);
|
|
|
|
slock_unlock(runloop->lock);
|
|
|
|
|
|
|
|
RARCH_LOG("[Data Thread]: Starting data thread.\n");
|
|
|
|
|
2015-03-18 23:13:54 +00:00
|
|
|
for (;;)
|
2015-03-18 21:11:53 +00:00
|
|
|
{
|
|
|
|
slock_lock(runloop->lock);
|
2015-03-18 23:13:54 +00:00
|
|
|
|
2015-03-19 06:18:27 +00:00
|
|
|
if (!runloop->alive)
|
2015-03-18 23:13:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
data_runloop_iterate(true, runloop);
|
|
|
|
|
2015-03-18 21:11:53 +00:00
|
|
|
slock_unlock(runloop->lock);
|
|
|
|
}
|
2015-03-18 23:13:54 +00:00
|
|
|
|
|
|
|
RARCH_LOG("[Data Thread]: Stopping data thread.\n");
|
2015-03-18 22:39:33 +00:00
|
|
|
|
|
|
|
data_runloop_thread_deinit(runloop);
|
2015-03-18 21:11:53 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-03-18 22:13:00 +00:00
|
|
|
static void rarch_main_data_thread_init(void)
|
|
|
|
{
|
|
|
|
if ((g_data_runloop.thread = sthread_create(data_thread_loop, &g_data_runloop)))
|
|
|
|
{
|
2015-03-18 23:13:54 +00:00
|
|
|
g_data_runloop.lock = slock_new();
|
|
|
|
g_data_runloop.cond_lock = slock_new();
|
|
|
|
g_data_runloop.overlay_lock = slock_new();
|
|
|
|
g_data_runloop.cond = scond_new();
|
2015-03-18 22:13:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
g_data_runloop.thread = NULL;
|
|
|
|
|
|
|
|
g_data_runloop.thread_inited = (g_data_runloop.thread != NULL);
|
2015-03-18 23:13:54 +00:00
|
|
|
|
2015-03-19 06:18:27 +00:00
|
|
|
if (!g_data_runloop.thread_inited)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_data_runloop.alive = true;
|
|
|
|
g_data_runloop.thread_code = THREAD_CODE_ALIVE;
|
2015-03-18 22:13:00 +00:00
|
|
|
}
|
|
|
|
|
2015-03-18 21:11:53 +00:00
|
|
|
void rarch_main_data_iterate(void)
|
|
|
|
{
|
2015-03-18 21:27:52 +00:00
|
|
|
#ifdef HAVE_THREADS
|
2015-03-18 22:13:00 +00:00
|
|
|
#if 0
|
|
|
|
if (g_settings.menu.threaded_data_runloop_enable)
|
|
|
|
{
|
2015-03-19 06:18:27 +00:00
|
|
|
switch (g_data_runloop.thread_code)
|
|
|
|
{
|
|
|
|
case THREAD_CODE_ALIVE:
|
|
|
|
if (g_data_runloop.alive)
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
case THREAD_CODE_INIT:
|
|
|
|
rarch_main_data_thread_init();
|
|
|
|
break;
|
|
|
|
}
|
2015-03-18 22:13:00 +00:00
|
|
|
}
|
|
|
|
#endif
|
2015-03-18 21:27:52 +00:00
|
|
|
#endif
|
2015-03-18 20:26:36 +00:00
|
|
|
|
2015-03-18 23:13:54 +00:00
|
|
|
data_runloop_iterate(false, &g_data_runloop);
|
2015-03-18 20:26:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void rarch_main_data_init(void)
|
|
|
|
{
|
|
|
|
if (g_data_runloop.inited)
|
|
|
|
return;
|
|
|
|
|
2015-03-18 04:35:05 +00:00
|
|
|
memset(&g_data_runloop, 0, sizeof(g_data_runloop));
|
2015-03-18 20:26:36 +00:00
|
|
|
|
2015-03-18 21:37:27 +00:00
|
|
|
g_data_runloop.thread_inited = false;
|
2015-03-19 06:18:27 +00:00
|
|
|
g_data_runloop.alive = false;
|
2015-03-18 21:37:27 +00:00
|
|
|
|
2015-03-18 20:26:36 +00:00
|
|
|
g_data_runloop.inited = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void rarch_main_data_clear_state(void)
|
|
|
|
{
|
|
|
|
rarch_main_data_deinit();
|
|
|
|
rarch_main_data_init();
|
2015-03-18 04:35:05 +00:00
|
|
|
}
|
|
|
|
|
2015-03-15 01:00:11 +00:00
|
|
|
void rarch_main_data_init_queues(void)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_NETWORKING
|
|
|
|
if (!g_data_runloop.http.msg_queue)
|
|
|
|
rarch_assert(g_data_runloop.http.msg_queue = msg_queue_new(8));
|
|
|
|
#endif
|
|
|
|
if (!g_data_runloop.nbio.msg_queue)
|
|
|
|
rarch_assert(g_data_runloop.nbio.msg_queue = msg_queue_new(8));
|
|
|
|
if (!g_data_runloop.nbio.image.msg_queue)
|
|
|
|
rarch_assert(g_data_runloop.nbio.image.msg_queue = msg_queue_new(8));
|
|
|
|
}
|
|
|
|
|
2015-03-15 05:41:04 +00:00
|
|
|
void rarch_main_data_msg_queue_push(unsigned type,
|
|
|
|
const char *msg, const char *msg2,
|
|
|
|
unsigned prio, unsigned duration, bool flush)
|
|
|
|
{
|
|
|
|
char new_msg[PATH_MAX_LENGTH];
|
|
|
|
msg_queue_t *queue = NULL;
|
|
|
|
|
2015-03-15 05:44:01 +00:00
|
|
|
snprintf(new_msg, sizeof(new_msg), "%s|%s", msg, msg2);
|
2015-03-15 05:41:04 +00:00
|
|
|
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case DATA_TYPE_NONE:
|
|
|
|
break;
|
|
|
|
case DATA_TYPE_FILE:
|
|
|
|
queue = g_data_runloop.nbio.msg_queue;
|
|
|
|
break;
|
|
|
|
case DATA_TYPE_IMAGE:
|
|
|
|
queue = g_data_runloop.nbio.image.msg_queue;
|
|
|
|
break;
|
2015-03-15 18:32:11 +00:00
|
|
|
#ifdef HAVE_NETWORKING
|
2015-03-15 05:41:04 +00:00
|
|
|
case DATA_TYPE_HTTP:
|
|
|
|
queue = g_data_runloop.http.msg_queue;
|
|
|
|
break;
|
2015-03-15 18:32:11 +00:00
|
|
|
#endif
|
2015-03-15 06:07:59 +00:00
|
|
|
#ifdef HAVE_OVERLAY
|
|
|
|
case DATA_TYPE_OVERLAY:
|
|
|
|
break;
|
|
|
|
#endif
|
2015-03-15 05:41:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!queue)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (flush)
|
|
|
|
msg_queue_clear(queue);
|
|
|
|
msg_queue_push(queue, new_msg, prio, duration);
|
|
|
|
}
|
|
|
|
|