From 1bb5e103ab50a1aa562f2db8612d76151ad32791 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 24 Aug 2021 15:01:48 +1000 Subject: [PATCH] Split connect into an additional connect_done This allows us to transmit extra information about the client before the server has to decide on whether it wants to connect us. Signed-off-by: Peter Hutterer --- proto/ei.proto | 42 +++++++++++++++++++++++------------------- src/libei-proto.c | 10 ++++++++++ src/libei-proto.h | 1 + src/libei.c | 8 ++++++-- src/libeis-client.c | 10 +++++++++- src/libeis-proto.c | 3 +++ src/libeis-proto.h | 1 + 7 files changed, 53 insertions(+), 22 deletions(-) diff --git a/proto/ei.proto b/proto/ei.proto index 54831f2..b5be3ca 100644 --- a/proto/ei.proto +++ b/proto/ei.proto @@ -73,6 +73,9 @@ message Connect { string name = 1; } +message ConnectDone { +}; + message Disconnect { } @@ -166,25 +169,26 @@ message Frame { message ClientMessage { oneof msg { Connect connect = 1; - Disconnect disconnect = 2; - BindSeat bind_seat = 3; - UnbindSeat unbind_seat = 4; - CloseDevice close_device = 5; - PointerRelative pointer_relative = 6; - PointerAbsolute pointer_absolute = 7; - PointerScroll pointer_scroll = 8; - PointerScrollDiscrete pointer_scroll_discrete = 9; - PointerScrollStop pointer_scroll_stop = 10; - PointerButton pointer_button = 11; - KeyboardKey keyboard_key = 12; - TouchDown touch_down = 13; - TouchMotion touch_motion = 14; - TouchUp touch_up = 15; - ConfigureName configure_name = 16; - ConfigureCapabilities configure_caps = 17; - Frame frame = 18; - StartEmulating start_emulating = 19; - StopEmulating stop_emulating = 20; + ConnectDone connect_done = 2; + Disconnect disconnect = 3; + BindSeat bind_seat = 4; + UnbindSeat unbind_seat = 5; + CloseDevice close_device = 6; + PointerRelative pointer_relative = 7; + PointerAbsolute pointer_absolute = 8; + PointerScroll pointer_scroll = 9; + PointerScrollDiscrete pointer_scroll_discrete = 10; + PointerScrollStop pointer_scroll_stop = 11; + PointerButton pointer_button = 12; + KeyboardKey keyboard_key = 13; + TouchDown touch_down = 14; + TouchMotion touch_motion = 15; + TouchUp touch_up = 16; + ConfigureName configure_name = 17; + ConfigureCapabilities configure_caps = 18; + Frame frame = 19; + StartEmulating start_emulating = 20; + StopEmulating stop_emulating = 21; } } diff --git a/src/libei-proto.c b/src/libei-proto.c index 65d8523..650869d 100644 --- a/src/libei-proto.c +++ b/src/libei-proto.c @@ -147,6 +147,7 @@ log_wire_message(struct ei *ei, const ClientMessage *msg, int error) case CLIENT_MESSAGE__MSG__NOT_SET: abort(); MSG_STRING_CASE(CONNECT); + MSG_STRING_CASE(CONNECT_DONE); MSG_STRING_CASE(DISCONNECT); MSG_STRING_CASE(BIND_SEAT); MSG_STRING_CASE(UNBIND_SEAT); @@ -229,6 +230,14 @@ ei_proto_send_connect(struct ei *ei) return ei_proto_send_msg(ei, &msg); } +static int +ei_proto_send_connect_done(struct ei *ei) +{ + prepare_msg(CONNECT_DONE, ConnectDone, connect_done); + + return ei_proto_send_msg(ei, &msg); +} + static int ei_proto_send_disconnect(struct ei *ei) { @@ -436,6 +445,7 @@ ei_proto_send_frame(struct ei_device *device) static const struct ei_proto_requests requests = { .connect = ei_proto_send_connect, + .connect_done = ei_proto_send_connect_done, .disconnect = ei_proto_send_disconnect, .bind_seat = ei_proto_send_bind_seat, .unbind_seat = ei_proto_send_unbind_seat, diff --git a/src/libei-proto.h b/src/libei-proto.h index d44583f..94bd356 100644 --- a/src/libei-proto.h +++ b/src/libei-proto.h @@ -58,6 +58,7 @@ struct ei_proto_interface { struct ei_proto_requests { int (*connect)(struct ei *ei); + int (*connect_done)(struct ei *ei); int (*disconnect)(struct ei *ei); int (*bind_seat)(struct ei_seat *seat, uint32_t capabilities); int (*unbind_seat)(struct ei_seat *seat); diff --git a/src/libei.c b/src/libei.c index 704583e..e5de6bf 100644 --- a/src/libei.c +++ b/src/libei.c @@ -858,11 +858,15 @@ ei_set_connection(struct ei *ei, int fd) ei->source = source_ref(source); ei->state = EI_STATE_BACKEND; rc = ei->requests->connect(ei); + if (rc == 0) { + rc = ei->requests->connect_done(ei); + } + if (rc == 0) { + ei->state = EI_STATE_CONNECTING; + } if (rc != 0) { log_error(ei, "message failed to send: %s\n", strerror(-rc)); ei_disconnect(ei); - } else { - ei->state = EI_STATE_CONNECTING; } } diff --git a/src/libeis-client.c b/src/libeis-client.c index 35a85cd..29959f1 100644 --- a/src/libeis-client.c +++ b/src/libeis-client.c @@ -528,9 +528,16 @@ client_msg_configure_capabilities(struct eis_client *client, bool policy_is_allo static int client_msg_connect(struct eis_client *client, const char *name) { - eis_queue_connect_event(client); if (client->name == NULL) client->name = xstrdup(name); + + return 0; +} + +static int +client_msg_connect_done(struct eis_client *client) +{ + eis_queue_connect_event(client); client->state = EIS_CLIENT_STATE_CONNECTING; return 0; @@ -544,6 +551,7 @@ client_msg_disconnect(struct eis_client *client) static const struct eis_proto_interface intf_state_new = { .connect = client_msg_connect, + .connect_done = client_msg_connect_done, .disconnect = client_msg_disconnect, .configure_name = client_msg_configure_name, .configure_capabilities = client_msg_configure_capabilities, diff --git a/src/libeis-proto.c b/src/libeis-proto.c index 4608166..14fda87 100644 --- a/src/libeis-proto.c +++ b/src/libeis-proto.c @@ -296,6 +296,9 @@ eis_proto_handle_message(struct eis_client *client, case CLIENT_MESSAGE__MSG_CONNECT: rc = call(connect, client, proto->connect->name); break; + case CLIENT_MESSAGE__MSG_CONNECT_DONE: + rc = call(connect_done, client); + break; case CLIENT_MESSAGE__MSG_DISCONNECT: rc = call(disconnect, client); break; diff --git a/src/libeis-proto.h b/src/libeis-proto.h index 7cf3f44..bcc6089 100644 --- a/src/libeis-proto.h +++ b/src/libeis-proto.h @@ -36,6 +36,7 @@ /* callbacks invoked during eis_proto_parse_message() */ struct eis_proto_interface { int (*connect)(struct eis_client *client, const char *name); + int (*connect_done)(struct eis_client *client); int (*disconnect)(struct eis_client *client); int (*bind_seat)(struct eis_client *client, uint32_t seatid, uint32_t capabilities); int (*unbind_seat)(struct eis_client *client, uint32_t seatid);