Refactor task_http.c
This commit is contained in:
parent
74627d1497
commit
dcd5a4fdcc
|
@ -117,9 +117,6 @@ bool rarch_main_data_active(data_runloop_t *runloop)
|
|||
{
|
||||
bool active = false;
|
||||
driver_t *driver = driver_get_ptr();
|
||||
#ifdef HAVE_NETWORKING
|
||||
http_handle_t *http = runloop ? &runloop->http : NULL;
|
||||
#endif
|
||||
#ifdef HAVE_LIBRETRODB
|
||||
database_info_handle_t *db = runloop ? runloop->db.handle : NULL;
|
||||
if (db && db->status != DATABASE_STATUS_NONE)
|
||||
|
@ -137,9 +134,9 @@ bool rarch_main_data_active(data_runloop_t *runloop)
|
|||
if (rarch_main_data_nbio_get_handle())
|
||||
active = true;
|
||||
#ifdef HAVE_NETWORKING
|
||||
if (http && http->handle != NULL)
|
||||
if (rarch_main_data_http_get_handle())
|
||||
active = true;
|
||||
if (http && http->connection.handle != NULL)
|
||||
if (rarch_main_data_http_conn_get_handle())
|
||||
active = true;
|
||||
#endif
|
||||
|
||||
|
@ -288,6 +285,7 @@ void rarch_main_data_clear_state(void)
|
|||
return;
|
||||
|
||||
rarch_main_data_nbio_init();
|
||||
rarch_main_data_http_init();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -16,9 +16,6 @@
|
|||
#ifndef __RETROARCH_DATA_RUNLOOP_H
|
||||
#define __RETROARCH_DATA_RUNLOOP_H
|
||||
|
||||
#include <file/nbio.h>
|
||||
#include <formats/image.h>
|
||||
#include <formats/rpng.h>
|
||||
#include <queues/message_queue.h>
|
||||
#include <retro_miscellaneous.h>
|
||||
#ifdef HAVE_THREADS
|
||||
|
@ -45,32 +42,6 @@ enum runloop_data_type
|
|||
DATA_TYPE_DB
|
||||
};
|
||||
|
||||
#ifdef HAVE_NETWORKING
|
||||
enum http_status_enum
|
||||
{
|
||||
HTTP_STATUS_POLL = 0,
|
||||
HTTP_STATUS_CONNECTION_TRANSFER,
|
||||
HTTP_STATUS_CONNECTION_TRANSFER_PARSE,
|
||||
HTTP_STATUS_TRANSFER,
|
||||
HTTP_STATUS_TRANSFER_PARSE,
|
||||
HTTP_STATUS_TRANSFER_PARSE_FREE
|
||||
};
|
||||
|
||||
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;
|
||||
unsigned status;
|
||||
} http_handle_t;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LIBRETRODB
|
||||
typedef struct database_state_handle
|
||||
{
|
||||
|
@ -94,10 +65,6 @@ typedef struct db_handle
|
|||
|
||||
typedef struct data_runloop
|
||||
{
|
||||
#ifdef HAVE_NETWORKING
|
||||
http_handle_t http;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LIBRETRODB
|
||||
db_handle_t db;
|
||||
#endif
|
||||
|
|
|
@ -15,6 +15,9 @@
|
|||
|
||||
#include <string.h>
|
||||
|
||||
#include <file/nbio.h>
|
||||
#include <formats/image.h>
|
||||
#include <formats/rpng.h>
|
||||
#include <compat/strl.h>
|
||||
#include <retro_miscellaneous.h>
|
||||
#include <queues/message_queue.h>
|
||||
|
|
|
@ -42,9 +42,40 @@
|
|||
|
||||
extern char core_updater_path[PATH_MAX_LENGTH];
|
||||
|
||||
enum http_status_enum
|
||||
{
|
||||
HTTP_STATUS_POLL = 0,
|
||||
HTTP_STATUS_CONNECTION_TRANSFER,
|
||||
HTTP_STATUS_CONNECTION_TRANSFER_PARSE,
|
||||
HTTP_STATUS_TRANSFER,
|
||||
HTTP_STATUS_TRANSFER_PARSE,
|
||||
HTTP_STATUS_TRANSFER_PARSE_FREE
|
||||
};
|
||||
|
||||
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;
|
||||
unsigned status;
|
||||
} http_handle_t;
|
||||
|
||||
int cb_core_updater_list(void *data_, size_t len);
|
||||
int cb_core_content_list(void *data_, size_t len);
|
||||
|
||||
http_handle_t *http_ptr;
|
||||
|
||||
void *rarch_main_data_http_get_ptr(void)
|
||||
{
|
||||
return http_ptr;
|
||||
}
|
||||
|
||||
#ifdef HAVE_ZLIB
|
||||
static int zlib_extract_core_callback(const char *name, const char *valid_exts,
|
||||
const uint8_t *cdata, unsigned cmode, uint32_t csize, uint32_t size,
|
||||
|
@ -406,8 +437,7 @@ static int rarch_main_data_http_iterate_transfer(void *data)
|
|||
|
||||
void rarch_main_data_http_iterate(bool is_thread, void *data)
|
||||
{
|
||||
data_runloop_t *runloop = (data_runloop_t*)data;
|
||||
http_handle_t *http = runloop ? &runloop->http : NULL;
|
||||
http_handle_t *http = rarch_main_data_http_get_ptr();
|
||||
if (!http)
|
||||
return;
|
||||
|
||||
|
@ -437,10 +467,10 @@ void rarch_main_data_http_iterate(bool is_thread, void *data)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void rarch_main_data_http_init_msg_queue(void)
|
||||
{
|
||||
data_runloop_t *runloop = rarch_main_data_get_ptr();
|
||||
http_handle_t *http = runloop ? &runloop->http : NULL;
|
||||
http_handle_t *http = rarch_main_data_http_get_ptr();
|
||||
if (!http)
|
||||
return;
|
||||
|
||||
|
@ -448,11 +478,36 @@ void rarch_main_data_http_init_msg_queue(void)
|
|||
rarch_assert(http->msg_queue = msg_queue_new(8));
|
||||
}
|
||||
|
||||
|
||||
msg_queue_t *rarch_main_data_http_get_msg_queue_ptr(void)
|
||||
{
|
||||
data_runloop_t *runloop = rarch_main_data_get_ptr();
|
||||
http_handle_t *http = runloop ? &runloop->http : NULL;
|
||||
http_handle_t *http = rarch_main_data_http_get_ptr();
|
||||
if (!http)
|
||||
return NULL;
|
||||
return http->msg_queue;
|
||||
}
|
||||
|
||||
void *rarch_main_data_http_get_handle(void)
|
||||
{
|
||||
http_handle_t *http = rarch_main_data_http_get_ptr();
|
||||
if (!http)
|
||||
return NULL;
|
||||
if (http->handle == NULL)
|
||||
return NULL;
|
||||
return http->handle;
|
||||
}
|
||||
|
||||
void *rarch_main_data_http_conn_get_handle(void)
|
||||
{
|
||||
http_handle_t *http = rarch_main_data_http_get_ptr();
|
||||
if (!http)
|
||||
return NULL;
|
||||
if (http->connection.handle == NULL)
|
||||
return NULL;
|
||||
return http->connection.handle;
|
||||
}
|
||||
|
||||
void rarch_main_data_http_init(void)
|
||||
{
|
||||
http_ptr = (http_handle_t*)calloc(1, sizeof(*http_ptr));
|
||||
}
|
||||
|
|
|
@ -55,6 +55,14 @@ void rarch_main_data_http_iterate(bool is_thread,
|
|||
msg_queue_t *rarch_main_data_http_get_msg_queue_ptr(void);
|
||||
|
||||
void rarch_main_data_http_init_msg_queue(void);
|
||||
|
||||
void *rarch_main_data_http_get_handle(void);
|
||||
|
||||
void *rarch_main_data_http_conn_get_handle(void);
|
||||
|
||||
void rarch_main_data_http_init(void);
|
||||
|
||||
void *rarch_main_data_http_get_ptr(void);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_RPNG
|
||||
|
|
Loading…
Reference in New Issue