2018-02-08 20:47:31 +08:00
|
|
|
#ifndef SERVER_H
|
|
|
|
#define SERVER_H
|
|
|
|
|
2019-03-03 06:52:22 +08:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2019-09-30 04:36:56 +08:00
|
|
|
#include "config.h"
|
2018-01-22 18:22:31 +08:00
|
|
|
#include "command.h"
|
2019-12-10 04:16:09 +08:00
|
|
|
#include "common.h"
|
2019-11-24 18:53:00 +08:00
|
|
|
#include "util/net.h"
|
2018-01-22 18:22:31 +08:00
|
|
|
|
2018-02-08 22:16:27 +08:00
|
|
|
struct server {
|
2019-03-03 07:01:16 +08:00
|
|
|
char *serial;
|
2018-02-08 22:16:27 +08:00
|
|
|
process_t process;
|
2018-03-12 15:35:51 +08:00
|
|
|
socket_t server_socket; // only used if !tunnel_forward
|
2019-05-29 03:03:54 +08:00
|
|
|
socket_t video_socket;
|
|
|
|
socket_t control_socket;
|
2019-12-10 04:16:09 +08:00
|
|
|
struct port_range port_range;
|
|
|
|
uint16_t local_port; // selected from port_range
|
2019-03-03 06:52:22 +08:00
|
|
|
bool tunnel_enabled;
|
|
|
|
bool tunnel_forward; // use "adb forward" instead of "adb reverse"
|
2018-02-08 22:16:27 +08:00
|
|
|
};
|
2018-01-23 22:46:34 +08:00
|
|
|
|
2019-12-10 04:16:09 +08:00
|
|
|
#define SERVER_INITIALIZER { \
|
|
|
|
.serial = NULL, \
|
|
|
|
.process = PROCESS_NONE, \
|
|
|
|
.server_socket = INVALID_SOCKET, \
|
|
|
|
.video_socket = INVALID_SOCKET, \
|
2019-05-29 03:03:54 +08:00
|
|
|
.control_socket = INVALID_SOCKET, \
|
2019-12-10 04:16:09 +08:00
|
|
|
.port_range = { \
|
|
|
|
.first = 0, \
|
|
|
|
.last = 0, \
|
|
|
|
}, \
|
|
|
|
.local_port = 0, \
|
|
|
|
.tunnel_enabled = false, \
|
|
|
|
.tunnel_forward = false, \
|
2018-02-08 22:16:27 +08:00
|
|
|
}
|
|
|
|
|
2019-06-05 05:59:55 +08:00
|
|
|
struct server_params {
|
|
|
|
const char *crop;
|
2019-12-10 04:16:09 +08:00
|
|
|
struct port_range port_range;
|
2019-06-05 05:59:55 +08:00
|
|
|
uint16_t max_size;
|
|
|
|
uint32_t bit_rate;
|
2019-11-18 05:07:19 +08:00
|
|
|
uint16_t max_fps;
|
2020-02-16 19:30:36 +08:00
|
|
|
int8_t lock_video_orientation;
|
2019-06-05 03:31:46 +08:00
|
|
|
bool control;
|
2020-02-24 19:16:38 +08:00
|
|
|
uint16_t display_id;
|
2019-06-05 05:59:55 +08:00
|
|
|
};
|
|
|
|
|
2018-02-08 22:16:27 +08:00
|
|
|
// init default values
|
2019-03-03 03:09:56 +08:00
|
|
|
void
|
|
|
|
server_init(struct server *server);
|
2018-02-08 22:16:27 +08:00
|
|
|
|
|
|
|
// push, enable tunnel et start the server
|
2019-03-03 06:52:22 +08:00
|
|
|
bool
|
2019-03-03 03:09:56 +08:00
|
|
|
server_start(struct server *server, const char *serial,
|
2019-06-05 05:59:55 +08:00
|
|
|
const struct server_params *params);
|
2018-02-08 22:16:27 +08:00
|
|
|
|
|
|
|
// block until the communication with the server is established
|
2019-05-28 19:41:19 +08:00
|
|
|
bool
|
2019-03-03 03:09:56 +08:00
|
|
|
server_connect_to(struct server *server);
|
2018-02-08 22:16:27 +08:00
|
|
|
|
|
|
|
// disconnect and kill the server process
|
2019-03-03 03:09:56 +08:00
|
|
|
void
|
|
|
|
server_stop(struct server *server);
|
2018-02-08 20:47:31 +08:00
|
|
|
|
2018-02-09 19:59:36 +08:00
|
|
|
// close and release sockets
|
2019-03-03 03:09:56 +08:00
|
|
|
void
|
|
|
|
server_destroy(struct server *server);
|
2018-02-09 19:59:36 +08:00
|
|
|
|
2018-02-08 20:47:31 +08:00
|
|
|
#endif
|