4 * Copyright (c) 2010-2015 Institute for System Programming
5 * of the Russian Academy of Sciences.
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.
12 #include "qemu/osdep.h"
13 #include "qapi/error.h"
14 #include "qemu-common.h"
15 #include "sysemu/replay.h"
16 #include "replay-internal.h"
17 #include "qemu/notify.h"
19 #include "qapi/clone-visitor.h"
21 void replay_save_input_event(InputEvent
*evt
)
26 replay_put_dword(evt
->type
);
29 case INPUT_EVENT_KIND_KEY
:
30 key
= evt
->u
.key
.data
;
31 replay_put_dword(key
->key
->type
);
33 switch (key
->key
->type
) {
34 case KEY_VALUE_KIND_NUMBER
:
35 replay_put_qword(key
->key
->u
.number
.data
);
36 replay_put_byte(key
->down
);
38 case KEY_VALUE_KIND_QCODE
:
39 replay_put_dword(key
->key
->u
.qcode
.data
);
40 replay_put_byte(key
->down
);
42 case KEY_VALUE_KIND__MAX
:
47 case INPUT_EVENT_KIND_BTN
:
48 btn
= evt
->u
.btn
.data
;
49 replay_put_dword(btn
->button
);
50 replay_put_byte(btn
->down
);
52 case INPUT_EVENT_KIND_REL
:
53 move
= evt
->u
.rel
.data
;
54 replay_put_dword(move
->axis
);
55 replay_put_qword(move
->value
);
57 case INPUT_EVENT_KIND_ABS
:
58 move
= evt
->u
.abs
.data
;
59 replay_put_dword(move
->axis
);
60 replay_put_qword(move
->value
);
62 case INPUT_EVENT_KIND__MAX
:
68 InputEvent
*replay_read_input_event(void)
78 evt
.type
= replay_get_dword();
80 case INPUT_EVENT_KIND_KEY
:
81 evt
.u
.key
.data
= &key
;
82 evt
.u
.key
.data
->key
->type
= replay_get_dword();
84 switch (evt
.u
.key
.data
->key
->type
) {
85 case KEY_VALUE_KIND_NUMBER
:
86 evt
.u
.key
.data
->key
->u
.number
.data
= replay_get_qword();
87 evt
.u
.key
.data
->down
= replay_get_byte();
89 case KEY_VALUE_KIND_QCODE
:
90 evt
.u
.key
.data
->key
->u
.qcode
.data
= (QKeyCode
)replay_get_dword();
91 evt
.u
.key
.data
->down
= replay_get_byte();
93 case KEY_VALUE_KIND__MAX
:
98 case INPUT_EVENT_KIND_BTN
:
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();
103 case INPUT_EVENT_KIND_REL
:
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();
108 case INPUT_EVENT_KIND_ABS
:
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();
113 case INPUT_EVENT_KIND__MAX
:
118 return QAPI_CLONE(InputEvent
, &evt
);
121 void replay_input_event(QemuConsole
*src
, InputEvent
*evt
)
123 if (replay_mode
== REPLAY_MODE_PLAY
) {
125 } else if (replay_mode
== REPLAY_MODE_RECORD
) {
126 replay_add_input_event(QAPI_CLONE(InputEvent
, evt
));
128 qemu_input_event_send_impl(src
, evt
);
132 void replay_input_sync_event(void)
134 if (replay_mode
== REPLAY_MODE_PLAY
) {
136 } else if (replay_mode
== REPLAY_MODE_RECORD
) {
137 replay_add_input_sync_event();
139 qemu_input_event_sync_impl();