]>
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" | |
19 | #include "qapi/qmp-output-visitor.h" | |
20 | #include "qapi/qmp-input-visitor.h" | |
21 | #include "qapi-visit.h" | |
22 | ||
23 | static InputEvent *qapi_clone_InputEvent(InputEvent *src) | |
24 | { | |
ee312992 PD |
25 | Visitor *ov, *iv; |
26 | QObject *obj; | |
27 | InputEvent *dst = NULL; | |
28 | ||
3b098d56 | 29 | ov = qmp_output_visitor_new(&obj); |
51e72bc1 | 30 | visit_type_InputEvent(ov, NULL, &src, &error_abort); |
3b098d56 | 31 | visit_complete(ov, &obj); |
1830f22a | 32 | visit_free(ov); |
ee312992 PD |
33 | if (!obj) { |
34 | return NULL; | |
35 | } | |
36 | ||
b70ce101 | 37 | iv = qmp_input_visitor_new(obj, true); |
51e72bc1 | 38 | visit_type_InputEvent(iv, NULL, &dst, &error_abort); |
b70ce101 | 39 | visit_free(iv); |
ee312992 PD |
40 | qobject_decref(obj); |
41 | ||
42 | return dst; | |
43 | } | |
44 | ||
45 | void replay_save_input_event(InputEvent *evt) | |
46 | { | |
b5a1b443 EB |
47 | InputKeyEvent *key; |
48 | InputBtnEvent *btn; | |
49 | InputMoveEvent *move; | |
ee312992 PD |
50 | replay_put_dword(evt->type); |
51 | ||
52 | switch (evt->type) { | |
53 | case INPUT_EVENT_KIND_KEY: | |
32bafa8f | 54 | key = evt->u.key.data; |
b5a1b443 | 55 | replay_put_dword(key->key->type); |
ee312992 | 56 | |
b5a1b443 | 57 | switch (key->key->type) { |
ee312992 | 58 | case KEY_VALUE_KIND_NUMBER: |
32bafa8f | 59 | replay_put_qword(key->key->u.number.data); |
b5a1b443 | 60 | replay_put_byte(key->down); |
ee312992 PD |
61 | break; |
62 | case KEY_VALUE_KIND_QCODE: | |
32bafa8f | 63 | replay_put_dword(key->key->u.qcode.data); |
b5a1b443 | 64 | replay_put_byte(key->down); |
ee312992 | 65 | break; |
7fb1cf16 | 66 | case KEY_VALUE_KIND__MAX: |
ee312992 PD |
67 | /* keep gcc happy */ |
68 | break; | |
69 | } | |
70 | break; | |
71 | case INPUT_EVENT_KIND_BTN: | |
32bafa8f | 72 | btn = evt->u.btn.data; |
b5a1b443 EB |
73 | replay_put_dword(btn->button); |
74 | replay_put_byte(btn->down); | |
ee312992 PD |
75 | break; |
76 | case INPUT_EVENT_KIND_REL: | |
32bafa8f | 77 | move = evt->u.rel.data; |
b5a1b443 EB |
78 | replay_put_dword(move->axis); |
79 | replay_put_qword(move->value); | |
ee312992 PD |
80 | break; |
81 | case INPUT_EVENT_KIND_ABS: | |
32bafa8f | 82 | move = evt->u.abs.data; |
b5a1b443 EB |
83 | replay_put_dword(move->axis); |
84 | replay_put_qword(move->value); | |
ee312992 | 85 | break; |
7fb1cf16 | 86 | case INPUT_EVENT_KIND__MAX: |
ee312992 PD |
87 | /* keep gcc happy */ |
88 | break; | |
89 | } | |
90 | } | |
91 | ||
92 | InputEvent *replay_read_input_event(void) | |
93 | { | |
94 | InputEvent evt; | |
95 | KeyValue keyValue; | |
96 | InputKeyEvent key; | |
97 | key.key = &keyValue; | |
98 | InputBtnEvent btn; | |
99 | InputMoveEvent rel; | |
100 | InputMoveEvent abs; | |
101 | ||
102 | evt.type = replay_get_dword(); | |
103 | switch (evt.type) { | |
104 | case INPUT_EVENT_KIND_KEY: | |
32bafa8f EB |
105 | evt.u.key.data = &key; |
106 | evt.u.key.data->key->type = replay_get_dword(); | |
ee312992 | 107 | |
32bafa8f | 108 | switch (evt.u.key.data->key->type) { |
ee312992 | 109 | case KEY_VALUE_KIND_NUMBER: |
32bafa8f EB |
110 | evt.u.key.data->key->u.number.data = replay_get_qword(); |
111 | evt.u.key.data->down = replay_get_byte(); | |
ee312992 PD |
112 | break; |
113 | case KEY_VALUE_KIND_QCODE: | |
32bafa8f EB |
114 | evt.u.key.data->key->u.qcode.data = (QKeyCode)replay_get_dword(); |
115 | evt.u.key.data->down = replay_get_byte(); | |
ee312992 | 116 | break; |
7fb1cf16 | 117 | case KEY_VALUE_KIND__MAX: |
ee312992 PD |
118 | /* keep gcc happy */ |
119 | break; | |
120 | } | |
121 | break; | |
122 | case INPUT_EVENT_KIND_BTN: | |
32bafa8f EB |
123 | evt.u.btn.data = &btn; |
124 | evt.u.btn.data->button = (InputButton)replay_get_dword(); | |
125 | evt.u.btn.data->down = replay_get_byte(); | |
ee312992 PD |
126 | break; |
127 | case INPUT_EVENT_KIND_REL: | |
32bafa8f EB |
128 | evt.u.rel.data = &rel; |
129 | evt.u.rel.data->axis = (InputAxis)replay_get_dword(); | |
130 | evt.u.rel.data->value = replay_get_qword(); | |
ee312992 PD |
131 | break; |
132 | case INPUT_EVENT_KIND_ABS: | |
32bafa8f EB |
133 | evt.u.abs.data = &abs; |
134 | evt.u.abs.data->axis = (InputAxis)replay_get_dword(); | |
135 | evt.u.abs.data->value = replay_get_qword(); | |
ee312992 | 136 | break; |
7fb1cf16 | 137 | case INPUT_EVENT_KIND__MAX: |
ee312992 PD |
138 | /* keep gcc happy */ |
139 | break; | |
140 | } | |
141 | ||
142 | return qapi_clone_InputEvent(&evt); | |
143 | } | |
144 | ||
145 | void replay_input_event(QemuConsole *src, InputEvent *evt) | |
146 | { | |
147 | if (replay_mode == REPLAY_MODE_PLAY) { | |
148 | /* Nothing */ | |
149 | } else if (replay_mode == REPLAY_MODE_RECORD) { | |
150 | replay_add_input_event(qapi_clone_InputEvent(evt)); | |
151 | } else { | |
152 | qemu_input_event_send_impl(src, evt); | |
153 | } | |
154 | } | |
155 | ||
156 | void replay_input_sync_event(void) | |
157 | { | |
158 | if (replay_mode == REPLAY_MODE_PLAY) { | |
159 | /* Nothing */ | |
160 | } else if (replay_mode == REPLAY_MODE_RECORD) { | |
161 | replay_add_input_sync_event(); | |
162 | } else { | |
163 | qemu_input_event_sync_impl(); | |
164 | } | |
165 | } |