2018-08-12 10:13:49 +08:00
|
|
|
#ifndef FILE_HANDLER_H
|
2018-09-13 22:27:19 +08:00
|
|
|
#define FILE_HANDLER_H
|
2018-08-12 10:13:49 +08:00
|
|
|
|
2019-03-03 06:52:22 +08:00
|
|
|
#include <stdbool.h>
|
2018-08-12 10:13:49 +08:00
|
|
|
#include <SDL2/SDL_mutex.h>
|
|
|
|
#include <SDL2/SDL_thread.h>
|
2019-03-03 06:52:22 +08:00
|
|
|
|
2019-09-30 04:36:56 +08:00
|
|
|
#include "config.h"
|
2018-08-12 10:13:49 +08:00
|
|
|
#include "command.h"
|
2019-11-24 18:53:00 +08:00
|
|
|
#include "util/cbuf.h"
|
2018-08-12 10:13:49 +08:00
|
|
|
|
2018-08-12 10:40:00 +08:00
|
|
|
typedef enum {
|
|
|
|
ACTION_INSTALL_APK,
|
|
|
|
ACTION_PUSH_FILE,
|
|
|
|
} file_handler_action_t;
|
2018-08-12 10:13:49 +08:00
|
|
|
|
2019-05-30 03:46:16 +08:00
|
|
|
struct file_handler_request {
|
|
|
|
file_handler_action_t action;
|
|
|
|
char *file;
|
2018-08-12 10:13:49 +08:00
|
|
|
};
|
|
|
|
|
2019-05-30 03:46:16 +08:00
|
|
|
struct file_handler_request_queue CBUF(struct file_handler_request, 16);
|
|
|
|
|
2018-08-12 10:13:49 +08:00
|
|
|
struct file_handler {
|
2019-05-24 23:24:17 +08:00
|
|
|
char *serial;
|
2019-07-31 07:48:32 +08:00
|
|
|
const char *push_target;
|
2018-08-12 10:13:49 +08:00
|
|
|
SDL_Thread *thread;
|
|
|
|
SDL_mutex *mutex;
|
|
|
|
SDL_cond *event_cond;
|
2019-03-03 06:52:22 +08:00
|
|
|
bool stopped;
|
|
|
|
bool initialized;
|
2018-08-12 10:13:49 +08:00
|
|
|
process_t current_process;
|
2019-05-30 03:46:16 +08:00
|
|
|
struct file_handler_request_queue queue;
|
2018-08-12 10:13:49 +08:00
|
|
|
};
|
|
|
|
|
2019-03-03 06:52:22 +08:00
|
|
|
bool
|
2019-07-31 07:48:32 +08:00
|
|
|
file_handler_init(struct file_handler *file_handler, const char *serial,
|
|
|
|
const char *push_target);
|
2018-08-12 10:13:49 +08:00
|
|
|
|
2019-03-03 03:09:56 +08:00
|
|
|
void
|
|
|
|
file_handler_destroy(struct file_handler *file_handler);
|
2018-08-12 10:13:49 +08:00
|
|
|
|
2019-03-03 06:52:22 +08:00
|
|
|
bool
|
2019-03-03 03:09:56 +08:00
|
|
|
file_handler_start(struct file_handler *file_handler);
|
|
|
|
|
|
|
|
void
|
|
|
|
file_handler_stop(struct file_handler *file_handler);
|
|
|
|
|
|
|
|
void
|
|
|
|
file_handler_join(struct file_handler *file_handler);
|
|
|
|
|
2019-05-24 23:25:31 +08:00
|
|
|
// take ownership of file, and will SDL_free() it
|
2019-03-03 06:52:22 +08:00
|
|
|
bool
|
2019-03-03 03:09:56 +08:00
|
|
|
file_handler_request(struct file_handler *file_handler,
|
|
|
|
file_handler_action_t action,
|
2019-05-24 23:25:31 +08:00
|
|
|
char *file);
|
2018-08-12 10:13:49 +08:00
|
|
|
|
|
|
|
#endif
|