blob: 1147e3d34e41824efa52c2ca1360bb7742746918 [file] [log] [blame]
Pavel Dovgalyukee312992015-09-17 19:25:24 +03001/*
2 * replay-input.c
3 *
4 * Copyright (c) 2010-2015 Institute for System Programming
5 * of the Russian Academy of Sciences.
6 *
7 * This work is licensed under the terms of the GNU GPL, version 2 or later.
8 * See the COPYING file in the top-level directory.
9 *
10 */
11
Peter Maydelld38ea872016-01-29 17:50:05 +000012#include "qemu/osdep.h"
Pavel Dovgalyukee312992015-09-17 19:25:24 +030013#include "sysemu/replay.h"
14#include "replay-internal.h"
15#include "qemu/notify.h"
16#include "ui/input.h"
Eric Blakeb6954712016-06-09 10:48:46 -060017#include "qapi/clone-visitor.h"
Markus Armbruster9af23982018-02-11 10:36:01 +010018#include "qapi/qapi-visit-ui.h"
Pavel Dovgalyukee312992015-09-17 19:25:24 +030019
20void replay_save_input_event(InputEvent *evt)
21{
Eric Blakeb5a1b442016-03-03 09:16:49 -070022 InputKeyEvent *key;
23 InputBtnEvent *btn;
24 InputMoveEvent *move;
Pavel Dovgalyukee312992015-09-17 19:25:24 +030025 replay_put_dword(evt->type);
26
27 switch (evt->type) {
28 case INPUT_EVENT_KIND_KEY:
Eric Blake32bafa82016-03-17 16:48:37 -060029 key = evt->u.key.data;
Eric Blakeb5a1b442016-03-03 09:16:49 -070030 replay_put_dword(key->key->type);
Pavel Dovgalyukee312992015-09-17 19:25:24 +030031
Eric Blakeb5a1b442016-03-03 09:16:49 -070032 switch (key->key->type) {
Pavel Dovgalyukee312992015-09-17 19:25:24 +030033 case KEY_VALUE_KIND_NUMBER:
Eric Blake32bafa82016-03-17 16:48:37 -060034 replay_put_qword(key->key->u.number.data);
Eric Blakeb5a1b442016-03-03 09:16:49 -070035 replay_put_byte(key->down);
Pavel Dovgalyukee312992015-09-17 19:25:24 +030036 break;
37 case KEY_VALUE_KIND_QCODE:
Eric Blake32bafa82016-03-17 16:48:37 -060038 replay_put_dword(key->key->u.qcode.data);
Eric Blakeb5a1b442016-03-03 09:16:49 -070039 replay_put_byte(key->down);
Pavel Dovgalyukee312992015-09-17 19:25:24 +030040 break;
Eric Blake7fb1cf12015-11-18 01:52:57 -070041 case KEY_VALUE_KIND__MAX:
Pavel Dovgalyukee312992015-09-17 19:25:24 +030042 /* keep gcc happy */
43 break;
44 }
45 break;
46 case INPUT_EVENT_KIND_BTN:
Eric Blake32bafa82016-03-17 16:48:37 -060047 btn = evt->u.btn.data;
Eric Blakeb5a1b442016-03-03 09:16:49 -070048 replay_put_dword(btn->button);
49 replay_put_byte(btn->down);
Pavel Dovgalyukee312992015-09-17 19:25:24 +030050 break;
51 case INPUT_EVENT_KIND_REL:
Eric Blake32bafa82016-03-17 16:48:37 -060052 move = evt->u.rel.data;
Eric Blakeb5a1b442016-03-03 09:16:49 -070053 replay_put_dword(move->axis);
54 replay_put_qword(move->value);
Pavel Dovgalyukee312992015-09-17 19:25:24 +030055 break;
56 case INPUT_EVENT_KIND_ABS:
Eric Blake32bafa82016-03-17 16:48:37 -060057 move = evt->u.abs.data;
Eric Blakeb5a1b442016-03-03 09:16:49 -070058 replay_put_dword(move->axis);
59 replay_put_qword(move->value);
Pavel Dovgalyukee312992015-09-17 19:25:24 +030060 break;
Eric Blake7fb1cf12015-11-18 01:52:57 -070061 case INPUT_EVENT_KIND__MAX:
Pavel Dovgalyukee312992015-09-17 19:25:24 +030062 /* keep gcc happy */
63 break;
64 }
65}
66
67InputEvent *replay_read_input_event(void)
68{
69 InputEvent evt;
70 KeyValue keyValue;
71 InputKeyEvent key;
72 key.key = &keyValue;
73 InputBtnEvent btn;
74 InputMoveEvent rel;
75 InputMoveEvent abs;
76
77 evt.type = replay_get_dword();
78 switch (evt.type) {
79 case INPUT_EVENT_KIND_KEY:
Eric Blake32bafa82016-03-17 16:48:37 -060080 evt.u.key.data = &key;
81 evt.u.key.data->key->type = replay_get_dword();
Pavel Dovgalyukee312992015-09-17 19:25:24 +030082
Eric Blake32bafa82016-03-17 16:48:37 -060083 switch (evt.u.key.data->key->type) {
Pavel Dovgalyukee312992015-09-17 19:25:24 +030084 case KEY_VALUE_KIND_NUMBER:
Eric Blake32bafa82016-03-17 16:48:37 -060085 evt.u.key.data->key->u.number.data = replay_get_qword();
86 evt.u.key.data->down = replay_get_byte();
Pavel Dovgalyukee312992015-09-17 19:25:24 +030087 break;
88 case KEY_VALUE_KIND_QCODE:
Eric Blake32bafa82016-03-17 16:48:37 -060089 evt.u.key.data->key->u.qcode.data = (QKeyCode)replay_get_dword();
90 evt.u.key.data->down = replay_get_byte();
Pavel Dovgalyukee312992015-09-17 19:25:24 +030091 break;
Eric Blake7fb1cf12015-11-18 01:52:57 -070092 case KEY_VALUE_KIND__MAX:
Pavel Dovgalyukee312992015-09-17 19:25:24 +030093 /* keep gcc happy */
94 break;
95 }
96 break;
97 case INPUT_EVENT_KIND_BTN:
Eric Blake32bafa82016-03-17 16:48:37 -060098 evt.u.btn.data = &btn;
99 evt.u.btn.data->button = (InputButton)replay_get_dword();
100 evt.u.btn.data->down = replay_get_byte();
Pavel Dovgalyukee312992015-09-17 19:25:24 +0300101 break;
102 case INPUT_EVENT_KIND_REL:
Eric Blake32bafa82016-03-17 16:48:37 -0600103 evt.u.rel.data = &rel;
104 evt.u.rel.data->axis = (InputAxis)replay_get_dword();
105 evt.u.rel.data->value = replay_get_qword();
Pavel Dovgalyukee312992015-09-17 19:25:24 +0300106 break;
107 case INPUT_EVENT_KIND_ABS:
Eric Blake32bafa82016-03-17 16:48:37 -0600108 evt.u.abs.data = &abs;
109 evt.u.abs.data->axis = (InputAxis)replay_get_dword();
110 evt.u.abs.data->value = replay_get_qword();
Pavel Dovgalyukee312992015-09-17 19:25:24 +0300111 break;
Eric Blake7fb1cf12015-11-18 01:52:57 -0700112 case INPUT_EVENT_KIND__MAX:
Pavel Dovgalyukee312992015-09-17 19:25:24 +0300113 /* keep gcc happy */
114 break;
115 }
116
Eric Blakeb6954712016-06-09 10:48:46 -0600117 return QAPI_CLONE(InputEvent, &evt);
Pavel Dovgalyukee312992015-09-17 19:25:24 +0300118}
119
120void replay_input_event(QemuConsole *src, InputEvent *evt)
121{
122 if (replay_mode == REPLAY_MODE_PLAY) {
123 /* Nothing */
124 } else if (replay_mode == REPLAY_MODE_RECORD) {
Eric Blakeb6954712016-06-09 10:48:46 -0600125 replay_add_input_event(QAPI_CLONE(InputEvent, evt));
Pavel Dovgalyukee312992015-09-17 19:25:24 +0300126 } else {
127 qemu_input_event_send_impl(src, evt);
128 }
129}
130
131void replay_input_sync_event(void)
132{
133 if (replay_mode == REPLAY_MODE_PLAY) {
134 /* Nothing */
135 } else if (replay_mode == REPLAY_MODE_RECORD) {
136 replay_add_input_sync_event();
137 } else {
138 qemu_input_event_sync_impl();
139 }
140}