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 <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2021-08-24 15:01:48 +10:00
parent a03f547989
commit 1bb5e103ab
7 changed files with 53 additions and 22 deletions

View file

@ -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;
}
}

View file

@ -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,

View file

@ -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);

View file

@ -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;
}
}

View file

@ -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,

View file

@ -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;

View file

@ -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);