Use sc_ prefix for controller

This commit is contained in:
Romain Vimont 2022-01-14 22:17:30 +01:00
parent 5f7ddff8ae
commit 3a4d5c7f18
10 changed files with 75 additions and 74 deletions

View file

@ -5,7 +5,7 @@
#include "util/log.h"
bool
controller_init(struct controller *controller, sc_socket control_socket,
sc_controller_init(struct sc_controller *controller, sc_socket control_socket,
struct sc_acksync *acksync) {
cbuf_init(&controller->queue);
@ -34,7 +34,7 @@ controller_init(struct controller *controller, sc_socket control_socket,
}
void
controller_destroy(struct controller *controller) {
sc_controller_destroy(struct sc_controller *controller) {
sc_cond_destroy(&controller->msg_cond);
sc_mutex_destroy(&controller->mutex);
@ -47,7 +47,7 @@ controller_destroy(struct controller *controller) {
}
bool
controller_push_msg(struct controller *controller,
sc_controller_push_msg(struct sc_controller *controller,
const struct control_msg *msg) {
if (sc_get_log_level() <= SC_LOG_LEVEL_VERBOSE) {
control_msg_log(msg);
@ -64,7 +64,7 @@ controller_push_msg(struct controller *controller,
}
static bool
process_msg(struct controller *controller, const struct control_msg *msg) {
process_msg(struct sc_controller *controller, const struct control_msg *msg) {
static unsigned char serialized_msg[CONTROL_MSG_MAX_SIZE];
size_t length = control_msg_serialize(msg, serialized_msg);
if (!length) {
@ -77,7 +77,7 @@ process_msg(struct controller *controller, const struct control_msg *msg) {
static int
run_controller(void *data) {
struct controller *controller = data;
struct sc_controller *controller = data;
for (;;) {
sc_mutex_lock(&controller->mutex);
@ -106,7 +106,7 @@ run_controller(void *data) {
}
bool
controller_start(struct controller *controller) {
sc_controller_start(struct sc_controller *controller) {
LOGD("Starting controller thread");
bool ok = sc_thread_create(&controller->thread, run_controller,
@ -117,7 +117,7 @@ controller_start(struct controller *controller) {
}
if (!receiver_start(&controller->receiver)) {
controller_stop(controller);
sc_controller_stop(controller);
sc_thread_join(&controller->thread, NULL);
return false;
}
@ -126,7 +126,7 @@ controller_start(struct controller *controller) {
}
void
controller_stop(struct controller *controller) {
sc_controller_stop(struct sc_controller *controller) {
sc_mutex_lock(&controller->mutex);
controller->stopped = true;
sc_cond_signal(&controller->msg_cond);
@ -134,7 +134,7 @@ controller_stop(struct controller *controller) {
}
void
controller_join(struct controller *controller) {
sc_controller_join(struct sc_controller *controller) {
sc_thread_join(&controller->thread, NULL);
receiver_join(&controller->receiver);
}

View file

@ -12,36 +12,36 @@
#include "util/net.h"
#include "util/thread.h"
struct control_msg_queue CBUF(struct control_msg, 64);
struct sc_control_msg_queue CBUF(struct control_msg, 64);
struct controller {
struct sc_controller {
sc_socket control_socket;
sc_thread thread;
sc_mutex mutex;
sc_cond msg_cond;
bool stopped;
struct control_msg_queue queue;
struct sc_control_msg_queue queue;
struct receiver receiver;
};
bool
controller_init(struct controller *controller, sc_socket control_socket,
sc_controller_init(struct sc_controller *controller, sc_socket control_socket,
struct sc_acksync *acksync);
void
controller_destroy(struct controller *controller);
sc_controller_destroy(struct sc_controller *controller);
bool
controller_start(struct controller *controller);
sc_controller_start(struct sc_controller *controller);
void
controller_stop(struct controller *controller);
sc_controller_stop(struct sc_controller *controller);
void
controller_join(struct controller *controller);
sc_controller_join(struct sc_controller *controller);
bool
controller_push_msg(struct controller *controller,
sc_controller_push_msg(struct sc_controller *controller,
const struct control_msg *msg);
#endif

View file

@ -157,7 +157,7 @@ sc_input_manager_init(struct sc_input_manager *im,
}
static void
send_keycode(struct controller *controller, enum android_keycode keycode,
send_keycode(struct sc_controller *controller, enum android_keycode keycode,
enum sc_action action, const char *name) {
// send DOWN event
struct control_msg msg;
@ -169,50 +169,50 @@ send_keycode(struct controller *controller, enum android_keycode keycode,
msg.inject_keycode.metastate = 0;
msg.inject_keycode.repeat = 0;
if (!controller_push_msg(controller, &msg)) {
if (!sc_controller_push_msg(controller, &msg)) {
LOGW("Could not request 'inject %s'", name);
}
}
static inline void
action_home(struct controller *controller, enum sc_action action) {
action_home(struct sc_controller *controller, enum sc_action action) {
send_keycode(controller, AKEYCODE_HOME, action, "HOME");
}
static inline void
action_back(struct controller *controller, enum sc_action action) {
action_back(struct sc_controller *controller, enum sc_action action) {
send_keycode(controller, AKEYCODE_BACK, action, "BACK");
}
static inline void
action_app_switch(struct controller *controller, enum sc_action action) {
action_app_switch(struct sc_controller *controller, enum sc_action action) {
send_keycode(controller, AKEYCODE_APP_SWITCH, action, "APP_SWITCH");
}
static inline void
action_power(struct controller *controller, enum sc_action action) {
action_power(struct sc_controller *controller, enum sc_action action) {
send_keycode(controller, AKEYCODE_POWER, action, "POWER");
}
static inline void
action_volume_up(struct controller *controller, enum sc_action action) {
action_volume_up(struct sc_controller *controller, enum sc_action action) {
send_keycode(controller, AKEYCODE_VOLUME_UP, action, "VOLUME_UP");
}
static inline void
action_volume_down(struct controller *controller, enum sc_action action) {
action_volume_down(struct sc_controller *controller, enum sc_action action) {
send_keycode(controller, AKEYCODE_VOLUME_DOWN, action, "VOLUME_DOWN");
}
static inline void
action_menu(struct controller *controller, enum sc_action action) {
action_menu(struct sc_controller *controller, enum sc_action action) {
send_keycode(controller, AKEYCODE_MENU, action, "MENU");
}
// turn the screen on if it was off, press BACK otherwise
// If the screen is off, it is turned on only on ACTION_DOWN
static void
press_back_or_turn_screen_on(struct controller *controller,
press_back_or_turn_screen_on(struct sc_controller *controller,
enum sc_action action) {
struct control_msg msg;
msg.type = CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON;
@ -220,49 +220,49 @@ press_back_or_turn_screen_on(struct controller *controller,
? AKEY_EVENT_ACTION_DOWN
: AKEY_EVENT_ACTION_UP;
if (!controller_push_msg(controller, &msg)) {
if (!sc_controller_push_msg(controller, &msg)) {
LOGW("Could not request 'press back or turn screen on'");
}
}
static void
expand_notification_panel(struct controller *controller) {
expand_notification_panel(struct sc_controller *controller) {
struct control_msg msg;
msg.type = CONTROL_MSG_TYPE_EXPAND_NOTIFICATION_PANEL;
if (!controller_push_msg(controller, &msg)) {
if (!sc_controller_push_msg(controller, &msg)) {
LOGW("Could not request 'expand notification panel'");
}
}
static void
expand_settings_panel(struct controller *controller) {
expand_settings_panel(struct sc_controller *controller) {
struct control_msg msg;
msg.type = CONTROL_MSG_TYPE_EXPAND_SETTINGS_PANEL;
if (!controller_push_msg(controller, &msg)) {
if (!sc_controller_push_msg(controller, &msg)) {
LOGW("Could not request 'expand settings panel'");
}
}
static void
collapse_panels(struct controller *controller) {
collapse_panels(struct sc_controller *controller) {
struct control_msg msg;
msg.type = CONTROL_MSG_TYPE_COLLAPSE_PANELS;
if (!controller_push_msg(controller, &msg)) {
if (!sc_controller_push_msg(controller, &msg)) {
LOGW("Could not request 'collapse notification panel'");
}
}
static bool
get_device_clipboard(struct controller *controller,
get_device_clipboard(struct sc_controller *controller,
enum get_clipboard_copy_key copy_key) {
struct control_msg msg;
msg.type = CONTROL_MSG_TYPE_GET_CLIPBOARD;
msg.get_clipboard.copy_key = copy_key;
if (!controller_push_msg(controller, &msg)) {
if (!sc_controller_push_msg(controller, &msg)) {
LOGW("Could not request 'get device clipboard'");
return false;
}
@ -271,7 +271,7 @@ get_device_clipboard(struct controller *controller,
}
static bool
set_device_clipboard(struct controller *controller, bool paste,
set_device_clipboard(struct sc_controller *controller, bool paste,
uint64_t sequence) {
char *text = SDL_GetClipboardText();
if (!text) {
@ -292,7 +292,7 @@ set_device_clipboard(struct controller *controller, bool paste,
msg.set_clipboard.text = text_dup;
msg.set_clipboard.paste = paste;
if (!controller_push_msg(controller, &msg)) {
if (!sc_controller_push_msg(controller, &msg)) {
free(text_dup);
LOGW("Could not request 'set device clipboard'");
return false;
@ -302,13 +302,13 @@ set_device_clipboard(struct controller *controller, bool paste,
}
static void
set_screen_power_mode(struct controller *controller,
set_screen_power_mode(struct sc_controller *controller,
enum screen_power_mode mode) {
struct control_msg msg;
msg.type = CONTROL_MSG_TYPE_SET_SCREEN_POWER_MODE;
msg.set_screen_power_mode.mode = mode;
if (!controller_push_msg(controller, &msg)) {
if (!sc_controller_push_msg(controller, &msg)) {
LOGW("Could not request 'set screen power mode'");
}
}
@ -330,7 +330,7 @@ switch_fps_counter_state(struct fps_counter *fps_counter) {
}
static void
clipboard_paste(struct controller *controller) {
clipboard_paste(struct sc_controller *controller) {
char *text = SDL_GetClipboardText();
if (!text) {
LOGW("Could not get clipboard text: %s", SDL_GetError());
@ -352,18 +352,18 @@ clipboard_paste(struct controller *controller) {
struct control_msg msg;
msg.type = CONTROL_MSG_TYPE_INJECT_TEXT;
msg.inject_text.text = text_dup;
if (!controller_push_msg(controller, &msg)) {
if (!sc_controller_push_msg(controller, &msg)) {
free(text_dup);
LOGW("Could not request 'paste clipboard'");
}
}
static void
rotate_device(struct controller *controller) {
rotate_device(struct sc_controller *controller) {
struct control_msg msg;
msg.type = CONTROL_MSG_TYPE_ROTATE_DEVICE;
if (!controller_push_msg(controller, &msg)) {
if (!sc_controller_push_msg(controller, &msg)) {
LOGW("Could not request device rotation");
}
}
@ -415,7 +415,7 @@ simulate_virtual_finger(struct sc_input_manager *im,
msg.inject_touch_event.pressure = up ? 0.0f : 1.0f;
msg.inject_touch_event.buttons = 0;
if (!controller_push_msg(im->controller, &msg)) {
if (!sc_controller_push_msg(im->controller, &msg)) {
LOGW("Could not request 'inject virtual finger event'");
return false;
}
@ -436,7 +436,7 @@ sc_input_manager_process_key(struct sc_input_manager *im,
// control: indicates the state of the command-line option --no-control
bool control = im->control;
struct controller *controller = im->controller;
struct sc_controller *controller = im->controller;
SDL_Keycode keycode = event->keysym.sym;
uint16_t mod = event->keysym.mod;

View file

@ -14,7 +14,7 @@
#include "trait/mouse_processor.h"
struct sc_input_manager {
struct controller *controller;
struct sc_controller *controller;
struct sc_screen *screen;
struct sc_key_processor *kp;
@ -43,7 +43,7 @@ struct sc_input_manager {
};
struct sc_input_manager_params {
struct controller *controller;
struct sc_controller *controller;
struct sc_screen *screen;
struct sc_key_processor *kp;
struct sc_mouse_processor *mp;

View file

@ -284,7 +284,7 @@ sc_key_processor_process_key(struct sc_key_processor *kp,
struct control_msg msg;
if (convert_input_key(event, &msg, ki->key_inject_mode, ki->repeat)) {
if (!controller_push_msg(ki->controller, &msg)) {
if (!sc_controller_push_msg(ki->controller, &msg)) {
LOGW("Could not request 'inject keycode'");
}
}
@ -316,7 +316,7 @@ sc_key_processor_process_text(struct sc_key_processor *kp,
LOGW("Could not strdup input text");
return;
}
if (!controller_push_msg(ki->controller, &msg)) {
if (!sc_controller_push_msg(ki->controller, &msg)) {
free(msg.inject_text.text);
LOGW("Could not request 'inject text'");
}
@ -324,7 +324,7 @@ sc_key_processor_process_text(struct sc_key_processor *kp,
void
sc_keyboard_inject_init(struct sc_keyboard_inject *ki,
struct controller *controller,
struct sc_controller *controller,
enum sc_key_inject_mode key_inject_mode,
bool forward_key_repeat) {
ki->controller = controller;

View file

@ -12,7 +12,7 @@
struct sc_keyboard_inject {
struct sc_key_processor key_processor; // key processor trait
struct controller *controller;
struct sc_controller *controller;
// SDL reports repeated events as a boolean, but Android expects the actual
// number of repetitions. This variable keeps track of the count.
@ -24,7 +24,7 @@ struct sc_keyboard_inject {
void
sc_keyboard_inject_init(struct sc_keyboard_inject *ki,
struct controller *controller,
struct sc_controller *controller,
enum sc_key_inject_mode key_inject_mode,
bool forward_key_repeat);

View file

@ -76,7 +76,7 @@ sc_mouse_processor_process_mouse_motion(struct sc_mouse_processor *mp,
},
};
if (!controller_push_msg(mi->controller, &msg)) {
if (!sc_controller_push_msg(mi->controller, &msg)) {
LOGW("Could not request 'inject mouse motion event'");
}
}
@ -97,7 +97,7 @@ sc_mouse_processor_process_mouse_click(struct sc_mouse_processor *mp,
},
};
if (!controller_push_msg(mi->controller, &msg)) {
if (!sc_controller_push_msg(mi->controller, &msg)) {
LOGW("Could not request 'inject mouse click event'");
}
}
@ -117,7 +117,7 @@ sc_mouse_processor_process_mouse_scroll(struct sc_mouse_processor *mp,
},
};
if (!controller_push_msg(mi->controller, &msg)) {
if (!sc_controller_push_msg(mi->controller, &msg)) {
LOGW("Could not request 'inject mouse scroll event'");
}
}
@ -138,14 +138,14 @@ sc_mouse_processor_process_touch(struct sc_mouse_processor *mp,
},
};
if (!controller_push_msg(mi->controller, &msg)) {
if (!sc_controller_push_msg(mi->controller, &msg)) {
LOGW("Could not request 'inject touch event'");
}
}
void
sc_mouse_inject_init(struct sc_mouse_inject *mi,
struct controller *controller) {
struct sc_controller *controller) {
mi->controller = controller;
static const struct sc_mouse_processor_ops ops = {

View file

@ -12,10 +12,11 @@
struct sc_mouse_inject {
struct sc_mouse_processor mouse_processor; // mouse processor trait
struct controller *controller;
struct sc_controller *controller;
};
void
sc_mouse_inject_init(struct sc_mouse_inject *mi, struct controller *controller);
sc_mouse_inject_init(struct sc_mouse_inject *mi,
struct sc_controller *controller);
#endif

View file

@ -43,7 +43,7 @@ struct scrcpy {
#ifdef HAVE_V4L2
struct sc_v4l2_sink v4l2_sink;
#endif
struct controller controller;
struct sc_controller controller;
struct file_handler file_handler;
#ifdef HAVE_AOA_HID
struct sc_aoa aoa;
@ -546,13 +546,13 @@ aoa_hid_end:
mp = &s->mouse_inject.mouse_processor;
}
if (!controller_init(&s->controller, s->server.control_socket,
if (!sc_controller_init(&s->controller, s->server.control_socket,
acksync)) {
goto end;
}
controller_initialized = true;
if (!controller_start(&s->controller)) {
if (!sc_controller_start(&s->controller)) {
goto end;
}
controller_started = true;
@ -562,7 +562,7 @@ aoa_hid_end:
msg.type = CONTROL_MSG_TYPE_SET_SCREEN_POWER_MODE;
msg.set_screen_power_mode.mode = SCREEN_POWER_MODE_OFF;
if (!controller_push_msg(&s->controller, &msg)) {
if (!sc_controller_push_msg(&s->controller, &msg)) {
LOGW("Could not request 'set screen power mode'");
}
}
@ -646,7 +646,7 @@ end:
}
#endif
if (controller_started) {
controller_stop(&s->controller);
sc_controller_stop(&s->controller);
}
if (file_handler_initialized) {
file_handler_stop(&s->file_handler);
@ -687,10 +687,10 @@ end:
}
if (controller_started) {
controller_join(&s->controller);
sc_controller_join(&s->controller);
}
if (controller_initialized) {
controller_destroy(&s->controller);
sc_controller_destroy(&s->controller);
}
if (recorder_initialized) {

View file

@ -60,7 +60,7 @@ struct sc_screen {
};
struct sc_screen_params {
struct controller *controller;
struct sc_controller *controller;
struct sc_key_processor *kp;
struct sc_mouse_processor *mp;