protocol: move start/stop emulating into the device

This commit is contained in:
Peter Hutterer 2023-02-04 10:10:23 +10:00
parent fadc1853c9
commit 3fc1bdf07a
7 changed files with 136 additions and 196 deletions

View file

@ -148,15 +148,6 @@
<arg name="touchid" type="uint"/>
</request>
<request name="start_emulating">
<arg name="device_id" type="uint"/>
<arg name="sequence" type="uint"/>
</request>
<request name="stop_emulating">
<arg name="device_id" type="uint"/>
</request>
<request name="frame">
<arg name="device_id" type="uint"/>
<arg name="timestamp" type="uint"/>
@ -294,15 +285,6 @@
<arg name="touchid" type="uint"/>
</event>
<event name="start_emulating">
<arg name="device_id" type="uint"/>
<arg name="sequence" type="uint"/>
</event>
<event name="stop_emulating">
<arg name="device_id" type="uint"/>
</event>
<event name="frame">
<arg name="device_id" type="uint"/>
<arg name="timestamp" type="uint"/>
@ -461,6 +443,13 @@
</description>
</request>
<request name="start_emulating">
<arg name="sequence" type="uint"/>
</request>
<request name="stop_emulating">
</request>
<event name="destroyed" since="1">
<description summary="Device removal notification">
This device has been removed and a client should release all
@ -537,6 +526,12 @@
<event name="paused">
</event>
<event name="start_emulating">
<arg name="sequence" type="uint"/>
</event>
<event name="stop_emulating">
</event>
</interface>
</protocol>

View file

@ -216,6 +216,61 @@ handle_msg_paused(struct ei_device *device)
return 0;
}
#define DISCONNECT_IF_SENDER_CONTEXT(device_) do {\
struct ei *ei_ = ei_device_get_context(device_); \
if (ei_is_sender(ei_)) { \
log_bug_client(ei_, "Invalid event from receiver EIS context. Disconnecting"); \
return -ECANCELED; \
} \
} while(0)
static int
handle_msg_start_emulating(struct ei_device *device, uint32_t sequence)
{
DISCONNECT_IF_SENDER_CONTEXT(device);
switch (device->state) {
case EI_DEVICE_STATE_DEAD:
case EI_DEVICE_STATE_NEW:
case EI_DEVICE_STATE_PAUSED:
case EI_DEVICE_STATE_EMULATING:
break;
case EI_DEVICE_STATE_RESUMED:
ei_queue_device_start_emulating_event(device, sequence);
device->state = EI_DEVICE_STATE_EMULATING;
break;
case EI_DEVICE_STATE_REMOVED_FROM_CLIENT:
case EI_DEVICE_STATE_REMOVED_FROM_SERVER:
break;
}
return 0;
}
static int
handle_msg_stop_emulating(struct ei_device *device)
{
DISCONNECT_IF_SENDER_CONTEXT(device);
switch (device->state) {
case EI_DEVICE_STATE_DEAD:
case EI_DEVICE_STATE_NEW:
case EI_DEVICE_STATE_PAUSED:
case EI_DEVICE_STATE_RESUMED:
break;
case EI_DEVICE_STATE_EMULATING:
ei_queue_device_stop_emulating_event(device);
device->state = EI_DEVICE_STATE_RESUMED;
break;
case EI_DEVICE_STATE_REMOVED_FROM_CLIENT:
case EI_DEVICE_STATE_REMOVED_FROM_SERVER:
break;
}
return 0;
}
static const struct ei_device_interface interface = {
.destroyed = handle_msg_destroy,
.name = handle_msg_name,
@ -227,6 +282,8 @@ static const struct ei_device_interface interface = {
.done = handle_msg_done,
.resumed = handle_msg_resumed,
.paused = handle_msg_paused,
.start_emulating = handle_msg_start_emulating,
.stop_emulating = handle_msg_stop_emulating,
};
const struct ei_device_interface *
@ -386,7 +443,7 @@ ei_device_close(struct ei_device *device)
break;
case EI_DEVICE_STATE_EMULATING:
if (ei_is_sender(ei_device_get_context(device)))
ei_send_stop_emulating(device);
ei_device_request_stop_emulating(device);
_fallthrough_;
case EI_DEVICE_STATE_PAUSED:
case EI_DEVICE_STATE_RESUMED:
@ -524,7 +581,9 @@ ei_device_start_emulating(struct ei_device *device, uint32_t sequence)
assert(!device->send_frame_event);
device->state = EI_DEVICE_STATE_EMULATING;
ei_send_start_emulating(device, sequence);
int rc = ei_device_request_start_emulating(device, sequence);
if (rc)
ei_disconnect(ei_device_get_context(device));
}
_public_ void
@ -535,7 +594,9 @@ ei_device_stop_emulating(struct ei_device *device)
ei_device_flush_frame(device);
device->state = EI_DEVICE_STATE_RESUMED;
ei_send_stop_emulating(device);
int rc = ei_device_request_stop_emulating(device);
if (rc)
ei_disconnect(ei_device_get_context(device));
}
_public_ struct ei_region *
@ -896,44 +957,6 @@ ei_device_frame(struct ei_device *device, uint64_t time)
ei_send_frame(device, time);
}
void
ei_device_event_start_emulating(struct ei_device *device, uint32_t sequence)
{
switch (device->state) {
case EI_DEVICE_STATE_DEAD:
case EI_DEVICE_STATE_NEW:
case EI_DEVICE_STATE_PAUSED:
case EI_DEVICE_STATE_EMULATING:
break;
case EI_DEVICE_STATE_RESUMED:
ei_queue_device_start_emulating_event(device, sequence);
device->state = EI_DEVICE_STATE_EMULATING;
break;
case EI_DEVICE_STATE_REMOVED_FROM_CLIENT:
case EI_DEVICE_STATE_REMOVED_FROM_SERVER:
break;
}
}
void
ei_device_event_stop_emulating(struct ei_device *device)
{
switch (device->state) {
case EI_DEVICE_STATE_DEAD:
case EI_DEVICE_STATE_NEW:
case EI_DEVICE_STATE_PAUSED:
case EI_DEVICE_STATE_RESUMED:
break;
case EI_DEVICE_STATE_EMULATING:
ei_queue_device_stop_emulating_event(device);
device->state = EI_DEVICE_STATE_RESUMED;
break;
case EI_DEVICE_STATE_REMOVED_FROM_CLIENT:
case EI_DEVICE_STATE_REMOVED_FROM_SERVER:
break;
}
}
int
ei_device_event_frame(struct ei_device *device, uint64_t time)
{

View file

@ -114,12 +114,6 @@ ei_send_message(struct ei *ei, const struct brei_object *object,
void
ei_add_seat(struct ei_seat *seat);
int
ei_send_start_emulating(struct ei_device *device, uint32_t sequence);
int
ei_send_stop_emulating(struct ei_device *device);
int
ei_send_frame(struct ei_device *device, uint64_t time);

View file

@ -650,34 +650,6 @@ handle_msg_keyboard_modifiers(struct ei_connection *connection, uint32_t devicei
return 0;
}
int
ei_send_start_emulating(struct ei_device *device, uint32_t sequence)
{
struct ei *ei = ei_device_get_context(device);
if (ei->state == EI_STATE_NEW || ei->state == EI_STATE_DISCONNECTED)
return 0;
int rc = ei_connection_request_start_emulating(ei->connection, device->id, sequence);
if (rc)
ei_disconnect(ei);
return rc;
}
int
ei_send_stop_emulating(struct ei_device *device)
{
struct ei *ei = ei_device_get_context(device);
if (ei->state == EI_STATE_NEW || ei->state == EI_STATE_DISCONNECTED)
return 0;
int rc = ei_connection_request_stop_emulating(ei->connection, device->id);
if (rc)
ei_disconnect(ei);
return rc;
}
int
ei_send_frame(struct ei_device *device, uint64_t time)
{
@ -913,36 +885,6 @@ static int handle_msg_disconnected(struct ei_connection *connection, uint32_t re
} \
} while(0)
static int
handle_msg_start_emulating(struct ei_connection *connection, uint32_t deviceid, uint32_t sequence)
{
struct ei *ei = ei_connection_get_context(connection);
DISCONNECT_IF_SENDER_CONTEXT(ei);
struct ei_device *device = ei_find_device(ei, deviceid);
if (device)
ei_device_event_start_emulating(device, sequence);
return 0;
}
static int
handle_msg_stop_emulating(struct ei_connection *connection, uint32_t deviceid)
{
struct ei *ei = ei_connection_get_context(connection);
DISCONNECT_IF_SENDER_CONTEXT(ei);
struct ei_device *device = ei_find_device(ei, deviceid);
if (device)
ei_device_event_stop_emulating(device);
return 0;
}
static int
handle_msg_frame(struct ei_connection *connection, uint32_t deviceid, uint32_t time, uint32_t micros)
{
@ -1175,8 +1117,6 @@ static const struct ei_connection_interface intf_state_connected = {
.keyboard_modifiers = handle_msg_keyboard_modifiers,
/* events */
.start_emulating = handle_msg_start_emulating,
.stop_emulating = handle_msg_stop_emulating,
.pointer_relative = handle_msg_pointer_rel,
.pointer_absolute = handle_msg_pointer_abs,
.pointer_button = handle_msg_pointer_button,

View file

@ -282,36 +282,6 @@ eis_client_setup_done(struct eis_client *client, const char *name, bool is_sende
} \
} while(0)
static int
client_msg_start_emulating(struct eis_connection *connection, uint32_t deviceid, uint32_t sequence)
{
struct eis_client *client = eis_connection_get_client(connection);
DISCONNECT_IF_RECEIVER_CONTEXT(client);
struct eis_device *device = eis_client_find_device(client, deviceid);
if (device)
eis_device_event_start_emulating(device, sequence);
return 0;
}
static int
client_msg_stop_emulating(struct eis_connection *connection, uint32_t deviceid)
{
struct eis_client *client = eis_connection_get_client(connection);
DISCONNECT_IF_RECEIVER_CONTEXT(client);
struct eis_device *device = eis_client_find_device(client, deviceid);
if (device)
eis_device_event_stop_emulating(device);
return 0;
}
static int
client_msg_frame(struct eis_connection *connection, uint32_t deviceid, uint32_t time, uint32_t micros)
{
@ -528,8 +498,6 @@ static const struct eis_connection_interface intf_state_connected = {
.disconnect = client_msg_disconnect,
/* events */
.start_emulating = client_msg_start_emulating,
.stop_emulating = client_msg_stop_emulating,
.pointer_relative = client_msg_pointer_rel,
.pointer_absolute = client_msg_pointer_abs,
.pointer_button = client_msg_pointer_button,

View file

@ -201,8 +201,63 @@ client_msg_release(struct eis_device *device)
return 0;
}
#define DISCONNECT_IF_RECEIVER_CONTEXT(device_) do { \
struct eis_client *client_ = eis_device_get_client(device_); \
if (!eis_client_is_sender(client_)) { \
struct eis *_ctx = eis_client_get_context(client_); \
log_bug_client(_ctx, "Invalid event from receiver ei context. Disconnecting client"); \
return -EINVAL; \
} \
} while(0)
static int
client_msg_start_emulating(struct eis_device *device, uint32_t sequence)
{
DISCONNECT_IF_RECEIVER_CONTEXT(device);
switch (device->state) {
case EIS_DEVICE_STATE_DEAD:
case EIS_DEVICE_STATE_CLOSED_BY_CLIENT:
case EIS_DEVICE_STATE_NEW:
case EIS_DEVICE_STATE_PAUSED:
break;
case EIS_DEVICE_STATE_RESUMED:
eis_queue_device_start_emulating_event(device, sequence);
device->state = EIS_DEVICE_STATE_EMULATING;
break;
case EIS_DEVICE_STATE_EMULATING:
break;
}
return 0;
}
static int
client_msg_stop_emulating(struct eis_device *device)
{
DISCONNECT_IF_RECEIVER_CONTEXT(device);
switch (device->state) {
case EIS_DEVICE_STATE_DEAD:
case EIS_DEVICE_STATE_CLOSED_BY_CLIENT:
case EIS_DEVICE_STATE_NEW:
case EIS_DEVICE_STATE_PAUSED:
case EIS_DEVICE_STATE_RESUMED:
break;
case EIS_DEVICE_STATE_EMULATING:
eis_queue_device_stop_emulating_event(device);
device->state = EIS_DEVICE_STATE_RESUMED;
break;
}
return 0;
}
static const struct eis_device_interface interface = {
.release = client_msg_release,
.start_emulating = client_msg_start_emulating,
.stop_emulating = client_msg_stop_emulating,
};
const struct eis_device_interface *
@ -409,7 +464,7 @@ eis_device_start_emulating(struct eis_device *device, uint32_t sequence)
device->state = EIS_DEVICE_STATE_EMULATING;
handle_request(device, start_emulating, sequence);
eis_device_event_start_emulating(device, sequence);
}
_public_ void
@ -422,7 +477,7 @@ eis_device_stop_emulating(struct eis_device *device)
device->state = EIS_DEVICE_STATE_RESUMED;
handle_request_noargs(device, stop_emulating);
eis_device_event_stop_emulating(device);
}
_public_ void
@ -991,41 +1046,6 @@ eis_device_closed_by_client(struct eis_device *device)
}
}
void
eis_device_event_start_emulating(struct eis_device *device, uint32_t sequence)
{
switch (device->state) {
case EIS_DEVICE_STATE_DEAD:
case EIS_DEVICE_STATE_CLOSED_BY_CLIENT:
case EIS_DEVICE_STATE_NEW:
case EIS_DEVICE_STATE_PAUSED:
break;
case EIS_DEVICE_STATE_RESUMED:
eis_queue_device_start_emulating_event(device, sequence);
device->state = EIS_DEVICE_STATE_EMULATING;
break;
case EIS_DEVICE_STATE_EMULATING:
break;
}
}
void
eis_device_event_stop_emulating(struct eis_device *device)
{
switch (device->state) {
case EIS_DEVICE_STATE_DEAD:
case EIS_DEVICE_STATE_CLOSED_BY_CLIENT:
case EIS_DEVICE_STATE_NEW:
case EIS_DEVICE_STATE_PAUSED:
case EIS_DEVICE_STATE_RESUMED:
break;
case EIS_DEVICE_STATE_EMULATING:
eis_queue_device_stop_emulating_event(device);
device->state = EIS_DEVICE_STATE_RESUMED;
break;
}
}
_public_ void
eis_device_pause(struct eis_device *device)
{

View file

@ -153,10 +153,10 @@ int
eis_device_event_touch_up(struct eis_device *device, uint32_t touchid);
void
eis_device_event_start_emulating(struct eis_device *device, uint32_t sequence);
eis_device_handle_event_start_emulating(struct eis_device *device, uint32_t sequence);
void
eis_device_event_stop_emulating(struct eis_device *device);
eis_device_handle_event_stop_emulating(struct eis_device *device);
void
eis_device_closed_by_client(struct eis_device *device);