]>
Commit | Line | Data |
---|---|---|
ee312992 PD |
1 | /* |
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 | ||
d38ea87a | 12 | #include "qemu/osdep.h" |
ee312992 PD |
13 | #include "sysemu/replay.h" |
14 | #include "replay-internal.h" | |
15 | #include "qemu/notify.h" | |
16 | #include "ui/input.h" | |
b6954712 | 17 | #include "qapi/clone-visitor.h" |
9af23989 | 18 | #include "qapi/qapi-visit-ui.h" |
ee312992 PD |
19 | |
20 | void replay_save_input_event(InputEvent *evt) | |
21 | { | |
b5a1b443 EB |
22 | InputKeyEvent *key; |
23 | InputBtnEvent *btn; | |
24 | InputMoveEvent *move; | |
ee312992 PD |
25 | replay_put_dword(evt->type); |
26 | ||
27 | switch (evt->type) { | |
28 | case INPUT_EVENT_KIND_KEY: | |
32bafa8f | 29 | key = evt->u.key.data; |
b5a1b443 | 30 | replay_put_dword(key->key->type); |
ee312992 | 31 | |
b5a1b443 | 32 | switch (key->key->type) { |
ee312992 | 33 | case KEY_VALUE_KIND_NUMBER: |
32bafa8f | 34 | replay_put_qword(key->key->u.number.data); |
b5a1b443 | 35 | replay_put_byte(key->down); |
ee312992 PD |
36 | break; |
37 | case KEY_VALUE_KIND_QCODE: | |
32bafa8f | 38 | replay_put_dword(key->key->u.qcode.data); |
b5a1b443 | 39 | replay_put_byte(key->down); |
ee312992 | 40 | break; |
7fb1cf16 | 41 | case KEY_VALUE_KIND__MAX: |
ee312992 PD |
42 | /* keep gcc happy */ |
43 | break; | |
44 | } | |
45 | break; | |
46 | case INPUT_EVENT_KIND_BTN: | |
32bafa8f | 47 | btn = evt->u.btn.data; |
b5a1b443 EB |
48 | replay_put_dword(btn->button); |
49 | replay_put_byte(btn->down); | |
ee312992 PD |
50 | break; |
51 | case INPUT_EVENT_KIND_REL: | |
32bafa8f | 52 | move = evt->u.rel.data; |
b5a1b443 EB |
53 | replay_put_dword(move->axis); |
54 | replay_put_qword(move->value); | |
ee312992 PD |
55 | break; |
56 | case INPUT_EVENT_KIND_ABS: | |
32bafa8f | 57 | move = evt->u.abs.data; |
b5a1b443 EB |
58 | replay_put_dword(move->axis); |
59 | replay_put_qword(move->value); | |
ee312992 | 60 | break; |
7fb1cf16 | 61 | case INPUT_EVENT_KIND__MAX: |
ee312992 PD |
62 | /* keep gcc happy */ |
63 | break; | |
64 | } | |
65 | } | |
66 | ||
67 | InputEvent *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: | |
32bafa8f EB |
80 | evt.u.key.data = &key; |
81 | evt.u.key.data->key->type = replay_get_dword(); | |
ee312992 | 82 | |
32bafa8f | 83 | switch (evt.u.key.data->key->type) { |
ee312992 | 84 | case KEY_VALUE_KIND_NUMBER: |
32bafa8f EB |
85 | evt.u.key.data->key->u.number.data = replay_get_qword(); |
86 | evt.u.key.data->down = replay_get_byte(); | |
ee312992 PD |
87 | break; |
88 | case KEY_VALUE_KIND_QCODE: | |
32bafa8f EB |
89 | evt.u.key.data->key->u.qcode.data = (QKeyCode)replay_get_dword(); |
90 | evt.u.key.data->down = replay_get_byte(); | |
ee312992 | 91 | break; |
7fb1cf16 | 92 | case KEY_VALUE_KIND__MAX: |
ee312992 PD |
93 | /* keep gcc happy */ |
94 | break; | |
95 | } | |
96 | break; | |
97 | case INPUT_EVENT_KIND_BTN: | |
32bafa8f EB |
98 | evt.u.btn.data = &btn; |
99 | evt.u.btn.data->button = (InputButton)replay_get_dword(); | |
100 | evt.u.btn.data->down = replay_get_byte(); | |
ee312992 PD |
101 | break; |
102 | case INPUT_EVENT_KIND_REL: | |
32bafa8f EB |
103 | evt.u.rel.data = &rel; |
104 | evt.u.rel.data->axis = (InputAxis)replay_get_dword(); | |
105 | evt.u.rel.data->value = replay_get_qword(); | |
ee312992 PD |
106 | break; |
107 | case INPUT_EVENT_KIND_ABS: | |
32bafa8f EB |
108 | evt.u.abs.data = &abs; |
109 | evt.u.abs.data->axis = (InputAxis)replay_get_dword(); | |
110 | evt.u.abs.data->value = replay_get_qword(); | |
ee312992 | 111 | break; |
7fb1cf16 | 112 | case INPUT_EVENT_KIND__MAX: |
ee312992 PD |
113 | /* keep gcc happy */ |
114 | break; | |
115 | } | |
116 | ||
b6954712 | 117 | return QAPI_CLONE(InputEvent, &evt); |
ee312992 PD |
118 | } |
119 | ||
120 | void 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) { | |
b6954712 | 125 | replay_add_input_event(QAPI_CLONE(InputEvent, evt)); |
ee312992 PD |
126 | } else { |
127 | qemu_input_event_send_impl(src, evt); | |
128 | } | |
129 | } | |
130 | ||
131 | void 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 | } |