diff --git a/app/meson.build b/app/meson.build index f4570234..5ddffa95 100644 --- a/app/meson.build +++ b/app/meson.build @@ -11,6 +11,7 @@ src = [ 'src/lockutil.c', 'src/netutil.c', 'src/screen.c', + 'src/server.c', 'src/strutil.c', ] diff --git a/app/src/screen.c b/app/src/screen.c index 2c749c89..dbf73048 100644 --- a/app/src/screen.c +++ b/app/src/screen.c @@ -16,6 +16,7 @@ #include "frames.h" #include "lockutil.h" #include "netutil.h" +#include "server.h" #define DEVICE_NAME_FIELD_LENGTH 64 #define SOCKET_NAME "scrcpy" @@ -65,23 +66,6 @@ static TCPsocket listen_on_port(Uint16 port) { return SDLNet_TCP_Open(&addr); } -static process_t start_server(const char *serial) { - const char *const cmd[] = { - "shell", - "CLASSPATH=/data/local/tmp/scrcpy-server.jar", - "app_process", - "/system/bin", - "com.genymobile.scrcpy.ScrCpyServer" - }; - return adb_execute(serial, cmd, sizeof(cmd) / sizeof(cmd[0])); -} - -static void stop_server(process_t server) { - if (!cmd_terminate(server)) { - SDL_LogError(SDL_LOG_CATEGORY_SYSTEM, "Could not kill: %s", strerror(errno)); - } -} - // name must be at least DEVICE_NAME_FIELD_LENGTH bytes SDL_bool read_initial_device_info(TCPsocket socket, char *device_name, struct size *size) { unsigned char buf[DEVICE_NAME_FIELD_LENGTH + 4]; diff --git a/app/src/server.c b/app/src/server.c new file mode 100644 index 00000000..460976ac --- /dev/null +++ b/app/src/server.c @@ -0,0 +1,21 @@ +#include "command.h" + +#include +#include + +process_t start_server(const char *serial) { + const char *const cmd[] = { + "shell", + "CLASSPATH=/data/local/tmp/scrcpy-server.jar", + "app_process", + "/system/bin", + "com.genymobile.scrcpy.ScrCpyServer" + }; + return adb_execute(serial, cmd, sizeof(cmd) / sizeof(cmd[0])); +} + +void stop_server(process_t server) { + if (!cmd_terminate(server)) { + SDL_LogError(SDL_LOG_CATEGORY_SYSTEM, "Could not terminate server: %s", strerror(errno)); + } +} diff --git a/app/src/server.h b/app/src/server.h new file mode 100644 index 00000000..b89cca48 --- /dev/null +++ b/app/src/server.h @@ -0,0 +1,4 @@ +#include "command.h" + +process_t start_server(const char *serial); +void stop_server(process_t server);