proper way to destroy and init installer

This commit is contained in:
Adonis Najimi 2018-05-14 23:05:03 +02:00
parent 527d55b0c0
commit d6e35b0090
3 changed files with 10 additions and 22 deletions

View file

@ -5,7 +5,6 @@
#include "log.h"
#include "command.h"
// NOTE(adopi) this can be more generic:
// it could be used with a command queue instead of a filename queue
// then we would have a generic invoker (useful if we want to handle more async commands)
@ -82,9 +81,6 @@ void installer_destroy(struct installer *installer) {
SDL_DestroyMutex(installer->mutex);
apk_queue_destroy(&installer->queue);
SDL_free((void *) installer->serial);
installer->initialized = SDL_FALSE;
installer->stopped = SDL_FALSE;
installer->current_process = PROCESS_NONE;
}
SDL_bool installer_install_apk(struct installer *installer, const char *apk) {

View file

@ -27,17 +27,6 @@ struct installer {
struct apk_queue queue;
};
#define INSTALLER_INITIALIZER { \
.serial = NULL, \
.thread = NULL, \
.mutex = NULL, \
.event_cond = NULL, \
.stopped = SDL_FALSE, \
.initialized = SDL_FALSE, \
.current_process = PROCESS_NONE \
}
SDL_bool installer_init(struct installer *installer, const char *serial);
void installer_destroy(struct installer *installer);

View file

@ -29,7 +29,7 @@ static struct screen screen = SCREEN_INITIALIZER;
static struct frames frames;
static struct decoder decoder;
static struct controller controller;
static struct installer installer = INSTALLER_INITIALIZER;
static struct installer installer;
static struct input_manager input_manager = {
.controller = &controller,
@ -152,8 +152,11 @@ SDL_bool scrcpy(const char *serial, Uint16 local_port, Uint16 max_size, Uint32 b
goto finally_destroy_server;
}
// TODO(adopi) check failure
installer_init(&installer,server.serial);
if (!installer_init(&installer,server.serial)) {
ret = SDL_FALSE;
server_stop(&server);
goto finally_destroy_frames;
}
decoder_init(&decoder, &frames, device_socket);
@ -191,13 +194,13 @@ finally_destroy_controller:
controller_destroy(&controller);
finally_stop_decoder:
decoder_stop(&decoder);
// stop installer
installer_stop(&installer);
installer_join(&installer);
installer_destroy(&installer);
// stop the server before decoder_join() to wake up the decoder
server_stop(&server);
decoder_join(&decoder);
finally_destroy_installer:
installer_stop(&installer);
installer_join(&installer);
installer_destroy(&installer);
finally_destroy_frames:
frames_destroy(&frames);
finally_destroy_server: