Extract server-related functions

To lighten screen.c, move start_server() and stop_server() to a separate
file.
This commit is contained in:
Romain Vimont 2018-01-22 11:22:31 +01:00
parent 52af91f6b0
commit 7d67696b7e
4 changed files with 27 additions and 17 deletions

View file

@ -11,6 +11,7 @@ src = [
'src/lockutil.c',
'src/netutil.c',
'src/screen.c',
'src/server.c',
'src/strutil.c',
]

View file

@ -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];

21
app/src/server.c Normal file
View file

@ -0,0 +1,21 @@
#include "command.h"
#include <SDL2/SDL_log.h>
#include <errno.h>
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));
}
}

4
app/src/server.h Normal file
View file

@ -0,0 +1,4 @@
#include "command.h"
process_t start_server(const char *serial);
void stop_server(process_t server);