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 "qemu-common.h"
14 #include "sysemu/replay.h"
15 #include "replay-internal.h"
16 #include "qemu/notify.h"
18 #include "qapi/clone-visitor.h"
20 void replay_save_input_event(InputEvent
*evt
)
25 replay_put_dword(evt
->type
);
28 case INPUT_EVENT_KIND_KEY
:
29 key
= evt
->u
.key
.data
;
30 replay_put_dword(key
->key
->type
);
32 switch (key
->key
->type
) {
33 case KEY_VALUE_KIND_NUMBER
:
34 replay_put_qword(key
->key
->u
.number
.data
);
35 replay_put_byte(key
->down
);
37 case KEY_VALUE_KIND_QCODE
:
38 replay_put_dword(key
->key
->u
.qcode
.data
);
39 replay_put_byte(key
->down
);
41 case KEY_VALUE_KIND__MAX
:
46 case INPUT_EVENT_KIND_BTN
:
47 btn
= evt
->u
.btn
.data
;
48 replay_put_dword(btn
->button
);
49 replay_put_byte(btn
->down
);
51 case INPUT_EVENT_KIND_REL
:
52 move
= evt
->u
.rel
.data
;
53 replay_put_dword(move
->axis
);
54 replay_put_qword(move
->value
);
56 case INPUT_EVENT_KIND_ABS
:
57 move
= evt
->u
.abs
.data
;
58 replay_put_dword(move
->axis
);
59 replay_put_qword(move
->value
);
61 case INPUT_EVENT_KIND__MAX
:
67 InputEvent
*replay_read_input_event(void)
77 evt
.type
= replay_get_dword();
79 case INPUT_EVENT_KIND_KEY
:
80 evt
.u
.key
.data
= &key
;
81 evt
.u
.key
.data
->key
->type
= replay_get_dword();
83 switch (evt
.u
.key
.data
->key
->type
) {
84 case KEY_VALUE_KIND_NUMBER
:
85 evt
.u
.key
.data
->key
->u
.number
.data
= replay_get_qword();
86 evt
.u
.key
.data
->down
= replay_get_byte();
88 case KEY_VALUE_KIND_QCODE
:
89 evt
.u
.key
.data
->key
->u
.qcode
.data
= (QKeyCode
)replay_get_dword();
90 evt
.u
.key
.data
->down
= replay_get_byte();
92 case KEY_VALUE_KIND__MAX
:
97 case INPUT_EVENT_KIND_BTN
:
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();
102 case INPUT_EVENT_KIND_REL
:
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();
107 case INPUT_EVENT_KIND_ABS
:
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();
112 case INPUT_EVENT_KIND__MAX
:
117 return QAPI_CLONE(InputEvent
, &evt
);
120 void replay_input_event(QemuConsole
*src
, InputEvent
*evt
)
122 if (replay_mode
== REPLAY_MODE_PLAY
) {
124 } else if (replay_mode
== REPLAY_MODE_RECORD
) {
125 replay_add_input_event(QAPI_CLONE(InputEvent
, evt
));
127 qemu_input_event_send_impl(src
, evt
);
131 void replay_input_sync_event(void)
133 if (replay_mode
== REPLAY_MODE_PLAY
) {
135 } else if (replay_mode
== REPLAY_MODE_RECORD
) {
136 replay_add_input_sync_event();
138 qemu_input_event_sync_impl();