diff --git a/src/libeis-device.c b/src/libeis-device.c index e07441b..18a5927 100644 --- a/src/libeis-device.c +++ b/src/libeis-device.c @@ -223,44 +223,55 @@ client_msg_release(struct eis_device *device) static struct brei_result * client_msg_start_emulating(struct eis_device *device, uint32_t sequence) { + struct brei_result *result = NULL; + 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_EMULATING: + result = brei_result_new(EIS_CONNECTION_DISCONNECT_REASON_PROTOCOL, + "Invalid device state %ud for a start_emulating event", device->state); 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: + case EIS_DEVICE_STATE_PAUSED: + /* race condition, that's fine */ break; } - return 0; + return result; } static struct brei_result * client_msg_stop_emulating(struct eis_device *device) { + struct brei_result *result = NULL; + 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: + result = brei_result_new(EIS_CONNECTION_DISCONNECT_REASON_PROTOCOL, + "Invalid device state %ud for a stop_emulating event", device->state); break; case EIS_DEVICE_STATE_EMULATING: eis_queue_device_stop_emulating_event(device); device->state = EIS_DEVICE_STATE_RESUMED; break; + case EIS_DEVICE_STATE_PAUSED: + /* race condition, that's fine */ + break; } - return 0; + return result; } static struct brei_result *