Display and control your Android device
Move server-related functions to server.c
Romain Vimontd7b00a9babf7
diff --git a/app/src/screen.c b/app/src/screen.cindex dbf73048..9edfae34 100644--- a/app/src/screen.c+++ b/app/src/screen.c@@ -19,7 +19,6 @@#include "server.h"#define DEVICE_NAME_FIELD_LENGTH 64-#define SOCKET_NAME "scrcpy"#define DISPLAY_MARGINS 96#define MIN(X,Y) (X) < (Y) ? (X) : (Y)#define MAX(X,Y) (X) > (Y) ? (X) : (Y)@@ -371,16 +370,12 @@ void event_loop(void) {SDL_bool show_screen(const char *serial, Uint16 local_port) {SDL_bool ret = 0;- const char *server_jar_path = getenv("SCRCPY_SERVER_JAR");- if (!server_jar_path) {- server_jar_path = "scrcpy-server.jar";- }- process_t push_proc = adb_push(serial, server_jar_path, "/data/local/tmp/");+ process_t push_proc = push_server(serial);if (wait_for_success(push_proc, "adb push")) {return SDL_FALSE;}- process_t reverse_tunnel_proc = adb_reverse(serial, SOCKET_NAME, local_port);+ process_t reverse_tunnel_proc = enable_tunnel(serial, local_port);if (wait_for_success(reverse_tunnel_proc, "adb reverse")) {return SDL_FALSE;}@@ -531,7 +526,7 @@ screen_finally_destroy_frames:frames_destroy(&frames);screen_finally_adb_reverse_remove:{- process_t remove = adb_reverse_remove(serial, SOCKET_NAME);+ process_t remove = disable_tunnel(serial);if (remove != PROCESS_NONE) {// ignore failurecmd_simple_wait(remove, NULL);diff --git a/app/src/server.c b/app/src/server.cindex 460976ac..92ba1d2d 100644--- a/app/src/server.c+++ b/app/src/server.c@@ -3,6 +3,24 @@#include <SDL2/SDL_log.h>#include <errno.h>+#define SOCKET_NAME "scrcpy"++process_t push_server(const char *serial) {+ const char *server_jar_path = getenv("SCRCPY_SERVER_JAR");+ if (!server_jar_path) {+ server_jar_path = "scrcpy-server.jar";+ }+ return adb_push(serial, server_jar_path, "/data/local/tmp/");+}++process_t enable_tunnel(const char *serial, Uint16 local_port) {+ return adb_reverse(serial, SOCKET_NAME, local_port);+}++process_t disable_tunnel(const char *serial) {+ return adb_reverse_remove(serial, SOCKET_NAME);+}+process_t start_server(const char *serial) {const char *const cmd[] = {"shell",diff --git a/app/src/server.h b/app/src/server.hindex b89cca48..45279bee 100644--- a/app/src/server.h+++ b/app/src/server.h@@ -1,4 +1,8 @@#include "command.h"+process_t push_server(const char *serial);+process_t enable_tunnel(const char *serial, Uint16 local_port);+process_t disable_tunnel(const char *serial);+process_t start_server(const char *serial);void stop_server(process_t server);