1 #ifndef SERVER_H
2 #define SERVER_H
3 
4 #include <stdbool.h>
5 #include <stdint.h>
6 
7 #include "command.h"
8 #include "net.h"
9 
10 struct server {
11     char *serial;
12     process_t process;
13     socket_t server_socket; // only used if !tunnel_forward
14     socket_t video_socket;
15     socket_t control_socket;
16     uint16_t local_port;
17     bool tunnel_enabled;
18     bool tunnel_forward; // use "adb forward" instead of "adb reverse"
19 };
20 
21 #define SERVER_INITIALIZER {          \
22     .serial = NULL,                   \
23     .process = PROCESS_NONE,          \
24     .server_socket = INVALID_SOCKET,  \
25     .video_socket = INVALID_SOCKET,   \
26     .control_socket = INVALID_SOCKET, \
27     .local_port = 0,                  \
28     .tunnel_enabled = false,          \
29     .tunnel_forward = false,          \
30 }
31 
32 struct server_params {
33     const char *crop;
34     uint16_t local_port;
35     uint16_t max_size;
36     uint32_t bit_rate;
37     bool send_frame_meta;
38     bool control;
39 };
40 
41 // init default values
42 void
43 server_init(struct server *server);
44 
45 // push, enable tunnel et start the server
46 bool
47 server_start(struct server *server, const char *serial,
48              const struct server_params *params);
49 
50 // block until the communication with the server is established
51 bool
52 server_connect_to(struct server *server);
53 
54 // disconnect and kill the server process
55 void
56 server_stop(struct server *server);
57 
58 // close and release sockets
59 void
60 server_destroy(struct server *server);
61 
62 #endif
63