Start making rnbio_handle chain

This commit is contained in:
twinaphex 2015-02-22 07:34:33 +01:00
parent 98b0728604
commit f233ccb141
4 changed files with 125 additions and 11 deletions

View file

@ -33,6 +33,7 @@
#include <retro_miscellaneous.h>
#include "gfx/video_viewport.h"
#include <file/nbio.h>
#include <formats/rpng.h>
#include "playlist.h"
@ -593,6 +594,8 @@ struct global
struct
{
transfer_cb_t cb;
struct nbio_t *handle;
msg_queue_t *msg_queue;
} nbio;

View file

@ -332,7 +332,7 @@ void rpng_nbio_load_image_free(struct rpng_t *rpng)
struct rpng_t *rpng_nbio_load_image_argb_init(const char *path)
{
size_t file_len;
struct nbio_t* nbread = NULL;
struct nbio_t* handle = NULL;
struct rpng_t *rpng = (struct rpng_t*)calloc(1, sizeof(struct rpng_t));
if (!rpng)
@ -340,14 +340,14 @@ struct rpng_t *rpng_nbio_load_image_argb_init(const char *path)
rpng->userdata = (void*)nbio_open(path, NBIO_READ);
nbread = (struct nbio_t*)rpng->userdata;
handle = (struct nbio_t*)rpng->userdata;
if (!nbread)
if (!handle)
goto error;
rpng->ptr = nbio_get_ptr(nbread, &file_len);
rpng->ptr = nbio_get_ptr(handle, &file_len);
nbio_begin_read(nbread);
nbio_begin_read(handle);
return rpng;
@ -364,17 +364,17 @@ bool rpng_nbio_load_image_argb_start(struct rpng_t *rpng)
unsigned i;
size_t file_len;
char header[8];
struct nbio_t *nbread = NULL;
struct nbio_t *handle = NULL;
if (!rpng)
return false;
nbread = (struct nbio_t*)rpng->userdata;
handle = (struct nbio_t*)rpng->userdata;
if (!nbread)
if (!handle)
return false;
rpng->ptr = nbio_get_ptr(nbread, &file_len);
rpng->ptr = nbio_get_ptr(handle, &file_len);
if (!rpng->ptr)
return false;

View file

@ -2615,6 +2615,8 @@ bool rarch_main_command(unsigned cmd)
#endif
if (!g_extern.nbio.msg_queue)
rarch_assert(g_extern.nbio.msg_queue = msg_queue_new(8));
if (!g_extern.images.msg_queue)
rarch_assert(g_extern.images.msg_queue = msg_queue_new(8));
break;
case RARCH_CMD_BSV_MOVIE_DEINIT:
if (g_extern.bsv.movie)

113
runloop.c
View file

@ -878,10 +878,37 @@ static int rarch_main_iterate_quit(void)
return -1;
}
static int rarch_main_iterate_nbio_transfer(void)
{
size_t pos = 0, tot = 0;
if (!nbio_iterate(g_extern.nbio.handle))
return -1;
return 0;
}
static int rarch_main_iterate_nbio_parse(void)
{
size_t len;
char *data = nbio_get_ptr(g_extern.nbio.handle, &len);
if (data && g_extern.nbio.cb)
g_extern.nbio.cb(data, len);
nbio_free(g_extern.nbio.handle);
g_extern.nbio.handle = NULL;
msg_queue_clear(g_extern.nbio.msg_queue);
return 0;
}
#ifdef HAVE_NETWORKING
int cb_core_updater_download(void *data_, size_t len);
int cb_core_updater_list(void *data_, size_t len);
/**
* rarch_main_iterate_http_transfer:
*
@ -919,8 +946,6 @@ static int rarch_main_iterate_http_parse(void)
g_extern.http.handle = NULL;
msg_queue_clear(g_extern.http.msg_queue);
msg_queue_clear(g_extern.nbio.msg_queue);
msg_queue_clear(g_extern.images.msg_queue);
return 0;
}
@ -986,6 +1011,82 @@ static int rarch_main_iterate_http_poll(void)
}
#endif
#ifdef HAVE_OVERLAY
static int cb_nbio_image_overlay_load(void *data, size_t len)
{
(void)data;
(void)len;
return 0;
}
#endif
static int cb_nbio_default(void *data, size_t len)
{
(void)data;
(void)len;
return 0;
}
static int rarch_main_iterate_nbio_poll(void)
{
struct nbio_t* handle;
char elem0[PATH_MAX_LENGTH], elem1[PATH_MAX_LENGTH];
struct string_list *str_list = NULL;
const char *path = msg_queue_pull(g_extern.nbio.msg_queue);
if (!path)
return -1;
/* Can only deal with one HTTP transfer at a time for now */
if (g_extern.nbio.handle)
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;
}
g_extern.nbio.handle = handle;
g_extern.nbio.cb = NULL;
if (elem1[0] != '\0')
{
#ifdef HAVE_OVERLAY
if (!strcmp(elem1, "cb_image_overlay_load"))
g_extern.nbio.cb = &cb_nbio_image_overlay_load;
else
#endif
g_extern.nbio.cb = &cb_nbio_default;
}
nbio_begin_read(handle);
string_list_free(str_list);
return 0;
error:
if (str_list)
string_list_free(str_list);
return -1;
}
#ifdef HAVE_MENU
static void rarch_main_iterate_rdl(void)
{
@ -1107,6 +1208,14 @@ int rarch_main_iterate(void)
if (driver.overlay)
rarch_main_iterate_overlay_state();
#endif
if (g_extern.nbio.handle)
{
if (!rarch_main_iterate_nbio_transfer())
rarch_main_iterate_nbio_parse();
}
else
rarch_main_iterate_nbio_poll();
#ifdef HAVE_NETWORKING
if (g_extern.http.handle)