mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-07-28 11:49:10 +00:00
Rename "event" to "message"
After the recent refactorings, a "control event" is not necessarily an "event" (it may be a "command"). Similarly, the unique "device event" used to send the device clipboard content is more a "reponse" to the request from the client than an "event". Rename both to "message", and rename the message types to better describe their intent.
This commit is contained in:
parent
f710d76c9e
commit
28980bbc90
28 changed files with 777 additions and 778 deletions
|
@ -19,7 +19,7 @@ controller_init(struct controller *controller, socket_t control_socket) {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!(controller->event_cond = SDL_CreateCond())) {
|
||||
if (!(controller->msg_cond = SDL_CreateCond())) {
|
||||
receiver_destroy(&controller->receiver);
|
||||
SDL_DestroyMutex(controller->mutex);
|
||||
return false;
|
||||
|
@ -33,39 +33,39 @@ controller_init(struct controller *controller, socket_t control_socket) {
|
|||
|
||||
void
|
||||
controller_destroy(struct controller *controller) {
|
||||
SDL_DestroyCond(controller->event_cond);
|
||||
SDL_DestroyCond(controller->msg_cond);
|
||||
SDL_DestroyMutex(controller->mutex);
|
||||
|
||||
struct control_event event;
|
||||
while (cbuf_take(&controller->queue, &event)) {
|
||||
control_event_destroy(&event);
|
||||
struct control_msg msg;
|
||||
while (cbuf_take(&controller->queue, &msg)) {
|
||||
control_msg_destroy(&msg);
|
||||
}
|
||||
|
||||
receiver_destroy(&controller->receiver);
|
||||
}
|
||||
|
||||
bool
|
||||
controller_push_event(struct controller *controller,
|
||||
const struct control_event *event) {
|
||||
controller_push_msg(struct controller *controller,
|
||||
const struct control_msg *msg) {
|
||||
mutex_lock(controller->mutex);
|
||||
bool was_empty = cbuf_is_empty(&controller->queue);
|
||||
bool res = cbuf_push(&controller->queue, *event);
|
||||
bool res = cbuf_push(&controller->queue, *msg);
|
||||
if (was_empty) {
|
||||
cond_signal(controller->event_cond);
|
||||
cond_signal(controller->msg_cond);
|
||||
}
|
||||
mutex_unlock(controller->mutex);
|
||||
return res;
|
||||
}
|
||||
|
||||
static bool
|
||||
process_event(struct controller *controller,
|
||||
const struct control_event *event) {
|
||||
unsigned char serialized_event[CONTROL_EVENT_SERIALIZED_MAX_SIZE];
|
||||
int length = control_event_serialize(event, serialized_event);
|
||||
process_msg(struct controller *controller,
|
||||
const struct control_msg *msg) {
|
||||
unsigned char serialized_msg[CONTROL_MSG_SERIALIZED_MAX_SIZE];
|
||||
int length = control_msg_serialize(msg, serialized_msg);
|
||||
if (!length) {
|
||||
return false;
|
||||
}
|
||||
int w = net_send_all(controller->control_socket, serialized_event, length);
|
||||
int w = net_send_all(controller->control_socket, serialized_msg, length);
|
||||
return w == length;
|
||||
}
|
||||
|
||||
|
@ -76,22 +76,22 @@ run_controller(void *data) {
|
|||
for (;;) {
|
||||
mutex_lock(controller->mutex);
|
||||
while (!controller->stopped && cbuf_is_empty(&controller->queue)) {
|
||||
cond_wait(controller->event_cond, controller->mutex);
|
||||
cond_wait(controller->msg_cond, controller->mutex);
|
||||
}
|
||||
if (controller->stopped) {
|
||||
// stop immediately, do not process further events
|
||||
// stop immediately, do not process further msgs
|
||||
mutex_unlock(controller->mutex);
|
||||
break;
|
||||
}
|
||||
struct control_event event;
|
||||
bool non_empty = cbuf_take(&controller->queue, &event);
|
||||
struct control_msg msg;
|
||||
bool non_empty = cbuf_take(&controller->queue, &msg);
|
||||
SDL_assert(non_empty);
|
||||
mutex_unlock(controller->mutex);
|
||||
|
||||
bool ok = process_event(controller, &event);
|
||||
control_event_destroy(&event);
|
||||
bool ok = process_msg(controller, &msg);
|
||||
control_msg_destroy(&msg);
|
||||
if (!ok) {
|
||||
LOGD("Cannot write event to socket");
|
||||
LOGD("Cannot write msg to socket");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ void
|
|||
controller_stop(struct controller *controller) {
|
||||
mutex_lock(controller->mutex);
|
||||
controller->stopped = true;
|
||||
cond_signal(controller->event_cond);
|
||||
cond_signal(controller->msg_cond);
|
||||
mutex_unlock(controller->mutex);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue