Move server-related code to server.c

The file server.c already existed, but exposed a low-level API. Make it
higher-level, so that scrcpy.c does not handle server details directly.
This commit is contained in:
Romain Vimont
2018-02-08 15:16:27 +01:00
parent 6c578b5caa
commit 28c5cc030b
7 changed files with 161 additions and 104 deletions

View File

@@ -1,13 +1,34 @@
#ifndef SERVER_H
#define SERVER_H
#include <SDL2/SDL_net.h>
#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);
struct server {
process_t process;
TCPsocket server_socket;
TCPsocket device_socket;
SDL_bool adb_reverse_enabled;
};
process_t start_server(const char *serial, Uint16 max_size, Uint32 bit_rate);
void stop_server(process_t server);
#define SERVER_INITIALIZER { \
.process = PROCESS_NONE, \
.server_socket = NULL, \
.device_socket = NULL, \
.adb_reverse_enabled = SDL_FALSE, \
}
// init default values
void server_init(struct server *server);
// push, enable tunnel et start the server
SDL_bool server_start(struct server *server, const char *serial, Uint16 local_port,
Uint16 max_size, Uint32 bit_rate);
// block until the communication with the server is established
TCPsocket server_connect_to(struct server *server);
// disconnect and kill the server process
void server_stop(struct server *server, const char *serial);
#endif