task_file_transfer.c - decouple 'nbio' state from runloop data struct

This commit is contained in:
twinaphex 2015-07-08 20:04:16 +02:00
parent 3aff5a3ee2
commit a1a4bc4057
4 changed files with 84 additions and 17 deletions

View File

@ -88,6 +88,8 @@ void rarch_main_data_free(void)
{
data_runloop_t *runloop = rarch_main_data_get_ptr();
rarch_main_data_nbio_uninit();
if (runloop)
free(runloop);
runloop = NULL;
@ -119,7 +121,7 @@ bool rarch_main_data_active(data_runloop_t *runloop)
bool db_active = false;
driver_t *driver = driver_get_ptr();
nbio_handle_t *nbio = runloop ? &runloop->nbio : NULL;
nbio_handle_t *nbio = (nbio_handle_t*)rarch_main_data_nbio_get_ptr();
#ifdef HAVE_RPNG
nbio_image_handle_t *image = nbio ? &nbio->image : NULL;
#endif
@ -297,6 +299,7 @@ static data_runloop_t *rarch_main_data_new(void)
runloop->inited = true;
return runloop;
}
@ -305,8 +308,14 @@ void rarch_main_data_clear_state(void)
rarch_main_data_deinit();
rarch_main_data_free();
g_data_runloop = rarch_main_data_new();
if (!g_data_runloop)
return;
rarch_main_data_nbio_init();
}
void rarch_main_data_init_queues(void)
{
data_runloop_t *runloop = rarch_main_data_get_ptr();
@ -314,16 +323,14 @@ void rarch_main_data_init_queues(void)
if (!runloop->http.msg_queue)
rarch_assert(runloop->http.msg_queue = msg_queue_new(8));
#endif
if (!runloop->nbio.msg_queue)
rarch_assert(runloop->nbio.msg_queue = msg_queue_new(8));
if (!runloop->nbio.image.msg_queue)
rarch_assert(runloop->nbio.image.msg_queue = msg_queue_new(8));
rarch_main_data_nbio_init_msg_queue();
#ifdef HAVE_LIBRETRODB
if (!runloop->db.msg_queue)
rarch_assert(runloop->db.msg_queue = msg_queue_new(8));
#endif
}
void rarch_main_data_msg_queue_push(unsigned type,
const char *msg, const char *msg2,
unsigned prio, unsigned duration, bool flush)
@ -337,11 +344,15 @@ void rarch_main_data_msg_queue_push(unsigned type,
case DATA_TYPE_NONE:
break;
case DATA_TYPE_FILE:
queue = runloop->nbio.msg_queue;
queue = rarch_main_data_nbio_get_msg_queue_ptr();
if (!queue)
return;
snprintf(new_msg, sizeof(new_msg), "%s|%s", msg, msg2);
break;
case DATA_TYPE_IMAGE:
queue = runloop->nbio.image.msg_queue;
queue = rarch_main_data_nbio_image_get_msg_queue_ptr();
if (!queue)
return;
snprintf(new_msg, sizeof(new_msg), "%s|%s", msg, msg2);
break;
#ifdef HAVE_NETWORKING

View File

@ -151,7 +151,6 @@ typedef struct data_runloop
db_handle_t db;
#endif
nbio_handle_t nbio;
bool inited;
#ifdef HAVE_THREADS
@ -181,6 +180,8 @@ void rarch_main_data_free(void);
void rarch_main_data_init_queues(void);
void rarch_main_data_init(void);
bool rarch_main_data_active(data_runloop_t *runloop);
data_runloop_t *rarch_main_data_get_ptr(void);

View File

@ -21,12 +21,34 @@
#include <string/string_list.h>
#include <rhash.h>
#include "../runloop_data.h"
#include "tasks.h"
#define CB_MENU_WALLPAPER 0xb476e505U
#define CB_MENU_BOXART 0x68b307cdU
static nbio_handle_t *nbio_ptr;
void *rarch_main_data_nbio_get_ptr(void)
{
return nbio_ptr;
}
msg_queue_t *rarch_main_data_nbio_get_msg_queue_ptr(void)
{
nbio_handle_t *nbio = rarch_main_data_nbio_get_ptr();
if (!nbio)
return NULL;
return nbio->msg_queue;
}
msg_queue_t *rarch_main_data_nbio_image_get_msg_queue_ptr(void)
{
nbio_handle_t *nbio = rarch_main_data_nbio_get_ptr();
if (!nbio)
return NULL;
return nbio->image.msg_queue;
}
#ifdef HAVE_MENU
#include "../menu/menu_driver.h"
@ -252,8 +274,7 @@ static int rarch_main_data_image_iterate_transfer_parse(nbio_handle_t *nbio)
void rarch_main_data_nbio_image_iterate(bool is_thread, void *data)
{
data_runloop_t *runloop = (data_runloop_t*)data;
nbio_handle_t *nbio = runloop ? &runloop->nbio : NULL;
nbio_handle_t *nbio = rarch_main_data_nbio_get_ptr();
nbio_image_handle_t *image = nbio ? &nbio->image : NULL;
if (!image || !nbio)
@ -288,11 +309,10 @@ void rarch_main_data_nbio_image_iterate(bool is_thread, void *data)
void rarch_main_data_nbio_image_upload_iterate(bool is_thread,
void *data)
{
data_runloop_t *runloop = (data_runloop_t*)data;
nbio_handle_t *nbio = runloop ? &runloop->nbio : NULL;
nbio_handle_t *nbio = rarch_main_data_nbio_get_ptr();
nbio_image_handle_t *image = nbio ? &nbio->image : NULL;
if (!image || !nbio || !runloop)
if (!image || !nbio)
return;
(void)is_thread;
@ -529,9 +549,8 @@ static int rarch_main_data_nbio_iterate_parse(nbio_handle_t *nbio)
void rarch_main_data_nbio_iterate(bool is_thread, void *data)
{
data_runloop_t *runloop = (data_runloop_t*)data;
nbio_handle_t *nbio = runloop ? &runloop->nbio : NULL;
if (!nbio || !runloop)
nbio_handle_t *nbio = rarch_main_data_nbio_get_ptr();
if (!nbio)
return;
switch (nbio->status)
@ -555,3 +574,27 @@ void rarch_main_data_nbio_iterate(bool is_thread, void *data)
break;
}
}
void rarch_main_data_nbio_init_msg_queue(void)
{
nbio_handle_t *nbio = rarch_main_data_nbio_get_ptr();
if (!nbio)
return;
if (!nbio->msg_queue)
rarch_assert(nbio->msg_queue = msg_queue_new(8));
if (!nbio->image.msg_queue)
rarch_assert(nbio->image.msg_queue = msg_queue_new(8));
}
void rarch_main_data_nbio_uninit(void)
{
if (nbio_ptr)
free(nbio_ptr);
nbio_ptr = NULL;
}
void rarch_main_data_nbio_init(void)
{
nbio_ptr = (nbio_handle_t*)calloc(1, sizeof(*nbio_ptr));
}

View File

@ -24,6 +24,18 @@
extern "C" {
#endif
void rarch_main_data_nbio_uninit(void);
void rarch_main_data_nbio_init(void);
void rarch_main_data_nbio_init_msg_queue(void);
msg_queue_t *rarch_main_data_nbio_get_msg_queue_ptr(void);
msg_queue_t *rarch_main_data_nbio_image_get_msg_queue_ptr(void);
void *rarch_main_data_nbio_get_ptr(void);
#ifdef HAVE_NETWORKING
/**
* rarch_main_data_http_iterate_transfer: