mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-04-20 03:25:03 +00:00
installer queue works
This commit is contained in:
parent
6cbb2076fe
commit
d4f1de504f
3 changed files with 26 additions and 12 deletions
|
@ -35,12 +35,13 @@ SDL_bool apk_queue_push(struct apk_queue *queue, const char *apk) {
|
|||
if (apk_queue_is_full(queue)) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
strcpy(queue->data[queue->head],apk);
|
||||
|
||||
strcpy(queue->data[queue->head], apk);
|
||||
queue->head = (queue->head + 1) % APK_QUEUE_SIZE;
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
SDL_bool apk_queue_take(struct apk_queue *queue, char* apk) {
|
||||
SDL_bool apk_queue_take(struct apk_queue *queue, char *apk) {
|
||||
if (apk_queue_is_empty(queue)) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
@ -50,6 +51,7 @@ SDL_bool apk_queue_take(struct apk_queue *queue, char* apk) {
|
|||
}
|
||||
|
||||
SDL_bool installer_init(struct installer *installer, const char* serial) {
|
||||
|
||||
if (!apk_queue_init(&installer->queue)) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
@ -63,8 +65,15 @@ SDL_bool installer_init(struct installer *installer, const char* serial) {
|
|||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
installer->stopped = SDL_FALSE;
|
||||
installer->serial = NULL;
|
||||
if (serial) {
|
||||
installer->serial = SDL_strdup(serial);
|
||||
}
|
||||
|
||||
// TODO(adopi)
|
||||
// installer->initialized = SDL_TRUE;
|
||||
|
||||
installer->stopped = SDL_FALSE;
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
|
@ -87,6 +96,7 @@ SDL_bool installer_push_apk(struct installer *installer, const char* apk) {
|
|||
}
|
||||
|
||||
static SDL_bool process_install(struct installer *installer, const char* filename) {
|
||||
LOGI("%s will be installed",filename);
|
||||
process_t process = adb_install(installer->serial, filename);
|
||||
return process_check_success(process, "adb install");
|
||||
}
|
||||
|
@ -94,6 +104,7 @@ static SDL_bool process_install(struct installer *installer, const char* filenam
|
|||
static int run_installer(void *data) {
|
||||
struct installer *installer = data;
|
||||
|
||||
char current_apk[MAX_FILENAME_SIZE];
|
||||
mutex_lock(installer->mutex);
|
||||
for (;;) {
|
||||
while (!installer->stopped && apk_queue_is_empty(&installer->queue)) {
|
||||
|
@ -103,13 +114,10 @@ static int run_installer(void *data) {
|
|||
// stop immediately, do not process further events
|
||||
break;
|
||||
}
|
||||
char* apk = "";
|
||||
while (apk_queue_take(&installer->queue, apk)) {
|
||||
SDL_bool ok = process_install(installer,apk);
|
||||
SDL_free(apk);
|
||||
while (apk_queue_take(&installer->queue, current_apk)) {
|
||||
SDL_bool ok = process_install(installer,current_apk);
|
||||
if (!ok) {
|
||||
LOGD("Error during installation");
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
#define APK_INSTALLER_H
|
||||
|
||||
#define APK_QUEUE_SIZE 16
|
||||
#define MAX_FILENAME_SIZE 1024
|
||||
|
||||
|
||||
#include "apkinstaller.h"
|
||||
|
||||
|
@ -12,14 +14,13 @@
|
|||
// NOTE(AdoPi) apk_queue and control_event can use a generic queue
|
||||
|
||||
struct apk_queue {
|
||||
char* data[APK_QUEUE_SIZE];
|
||||
char data[APK_QUEUE_SIZE][MAX_FILENAME_SIZE];
|
||||
int tail;
|
||||
int head;
|
||||
};
|
||||
|
||||
|
||||
struct installer {
|
||||
char* serial;
|
||||
const char* serial;
|
||||
SDL_Thread *thread;
|
||||
SDL_mutex *mutex;
|
||||
SDL_cond *event_cond;
|
||||
|
|
|
@ -174,7 +174,12 @@ SDL_bool scrcpy(const char *serial, Uint16 local_port, Uint16 max_size, Uint32 b
|
|||
}
|
||||
|
||||
// TODO(adopi) init the installer when we really want to use it
|
||||
if (!installer_init(&installer, server.serial)) {
|
||||
if (!installer_init(&installer, serial)) {
|
||||
ret = SDL_FALSE;
|
||||
goto finally_stop_and_join_installer;
|
||||
}
|
||||
|
||||
if (!installer_start(&installer)) {
|
||||
ret = SDL_FALSE;
|
||||
goto finally_destroy_installer;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue