]>
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" |
da34e65c | 13 | #include "qapi/error.h" |
ee312992 PD |
14 | #include "qemu-common.h" |
15 | #include "sysemu/replay.h" | |
16 | #include "replay-internal.h" | |
17 | #include "qemu/notify.h" | |
18 | #include "ui/input.h" | |
b6954712 | 19 | #include "qapi/clone-visitor.h" |
ee312992 PD |
20 | |
21 | void replay_save_input_event(InputEvent *evt) | |
22 | { | |
b5a1b443 EB |
23 | InputKeyEvent *key; |
24 | InputBtnEvent *btn; | |
25 | InputMoveEvent *move; | |
ee312992 PD |
26 | replay_put_dword(evt->type); |
27 | ||
28 | switch (evt->type) { | |
29 | case INPUT_EVENT_KIND_KEY: | |
32bafa8f | 30 | key = evt->u.key.data; |
b5a1b443 | 31 | replay_put_dword(key->key->type); |
ee312992 | 32 | |
b5a1b443 | 33 | switch (key->key->type) { |
ee312992 | 34 | case KEY_VALUE_KIND_NUMBER: |
32bafa8f | 35 | replay_put_qword(key->key->u.number.data); |
b5a1b443 | 36 | replay_put_byte(key->down); |
ee312992 PD |
37 | break; |
38 | case KEY_VALUE_KIND_QCODE: | |
32bafa8f | 39 | replay_put_dword(key->key->u.qcode.data); |
b5a1b443 | 40 | replay_put_byte(key->down); |
ee312992 | 41 | break; |
7fb1cf16 | 42 | case KEY_VALUE_KIND__MAX: |
ee312992 PD |
43 | /* keep gcc happy */ |
44 | break; | |
45 | } | |
46 | break; | |
47 | case INPUT_EVENT_KIND_BTN: | |
32bafa8f | 48 | btn = evt->u.btn.data; |
b5a1b443 EB |
49 | replay_put_dword(btn->button); |
50 | replay_put_byte(btn->down); | |
ee312992 PD |
51 | break; |
52 | case INPUT_EVENT_KIND_REL: | |
32bafa8f | 53 | move = evt->u.rel.data; |
b5a1b443 EB |
54 | replay_put_dword(move->axis); |
55 | replay_put_qword(move->value); | |
ee312992 PD |
56 | break; |
57 | case INPUT_EVENT_KIND_ABS: | |
32bafa8f | 58 | move = evt->u.abs.data; |
b5a1b443 EB |
59 | replay_put_dword(move->axis); |
60 | replay_put_qword(move->value); | |
ee312992 | 61 | break; |
7fb1cf16 | 62 | case INPUT_EVENT_KIND__MAX: |
ee312992 PD |
63 | /* keep gcc happy */ |
64 | break; | |
65 | } | |
66 | } | |
67 | ||
68 | InputEvent *replay_read_input_event(void) | |
69 | { | |
70 | InputEvent evt; | |
71 | KeyValue keyValue; | |
72 | InputKeyEvent key; | |
73 | key.key = &keyValue; | |
74 | InputBtnEvent btn; | |
75 | InputMoveEvent rel; | |
76 | InputMoveEvent abs; | |
77 | ||
78 | evt.type = replay_get_dword(); | |
79 | switch (evt.type) { | |
80 | case INPUT_EVENT_KIND_KEY: | |
32bafa8f EB |
81 | evt.u.key.data = &key; |
82 | evt.u.key.data->key->type = replay_get_dword(); | |
ee312992 | 83 | |
32bafa8f | 84 | switch (evt.u.key.data->key->type) { |
ee312992 | 85 | case KEY_VALUE_KIND_NUMBER: |
32bafa8f EB |
86 | evt.u.key.data->key->u.number.data = replay_get_qword(); |
87 | evt.u.key.data->down = replay_get_byte(); | |
ee312992 PD |
88 | break; |
89 | case KEY_VALUE_KIND_QCODE: | |
32bafa8f EB |
90 | evt.u.key.data->key->u.qcode.data = (QKeyCode)replay_get_dword(); |
91 | evt.u.key.data->down = replay_get_byte(); | |
ee312992 | 92 | break; |
7fb1cf16 | 93 | case KEY_VALUE_KIND__MAX: |
ee312992 PD |
94 | /* keep gcc happy */ |
95 | break; | |
96 | } | |
97 | break; | |
98 | case INPUT_EVENT_KIND_BTN: | |
32bafa8f EB |
99 | evt.u.btn.data = &btn; |
100 | evt.u.btn.data->button = (InputButton)replay_get_dword(); | |
101 | evt.u.btn.data->down = replay_get_byte(); | |
ee312992 PD |
102 | break; |
103 | case INPUT_EVENT_KIND_REL: | |
32bafa8f EB |
104 | evt.u.rel.data = &rel; |
105 | evt.u.rel.data->axis = (InputAxis)replay_get_dword(); | |
106 | evt.u.rel.data->value = replay_get_qword(); | |
ee312992 PD |
107 | break; |
108 | case INPUT_EVENT_KIND_ABS: | |
32bafa8f EB |
109 | evt.u.abs.data = &abs; |
110 | evt.u.abs.data->axis = (InputAxis)replay_get_dword(); | |
111 | evt.u.abs.data->value = replay_get_qword(); | |
ee312992 | 112 | break; |
7fb1cf16 | 113 | case INPUT_EVENT_KIND__MAX: |
ee312992 PD |
114 | /* keep gcc happy */ |
115 | break; | |
116 | } | |
117 | ||
b6954712 | 118 | return QAPI_CLONE(InputEvent, &evt); |
ee312992 PD |
119 | } |
120 | ||
121 | void replay_input_event(QemuConsole *src, InputEvent *evt) | |
122 | { | |
123 | if (replay_mode == REPLAY_MODE_PLAY) { | |
124 | /* Nothing */ | |
125 | } else if (replay_mode == REPLAY_MODE_RECORD) { | |
b6954712 | 126 | replay_add_input_event(QAPI_CLONE(InputEvent, evt)); |
ee312992 PD |
127 | } else { |
128 | qemu_input_event_send_impl(src, evt); | |
129 | } | |
130 | } | |
131 | ||
132 | void replay_input_sync_event(void) | |
133 | { | |
134 | if (replay_mode == REPLAY_MODE_PLAY) { | |
135 | /* Nothing */ | |
136 | } else if (replay_mode == REPLAY_MODE_RECORD) { | |
137 | replay_add_input_sync_event(); | |
138 | } else { | |
139 | qemu_input_event_sync_impl(); | |
140 | } | |
141 | } |