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/qmp-output-visitor.h"
19 #include "qapi/qmp-input-visitor.h"
20 #include "qapi-visit.h"
22 static InputEvent
*qapi_clone_InputEvent(InputEvent
*src
)
24 QmpOutputVisitor
*qov
;
28 InputEvent
*dst
= NULL
;
30 qov
= qmp_output_visitor_new();
31 ov
= qmp_output_get_visitor(qov
);
32 visit_type_InputEvent(ov
, &src
, NULL
, &error_abort
);
33 obj
= qmp_output_get_qobject(qov
);
34 qmp_output_visitor_cleanup(qov
);
39 qiv
= qmp_input_visitor_new(obj
);
40 iv
= qmp_input_get_visitor(qiv
);
41 visit_type_InputEvent(iv
, &dst
, NULL
, &error_abort
);
42 qmp_input_visitor_cleanup(qiv
);
48 void replay_save_input_event(InputEvent
*evt
)
50 replay_put_dword(evt
->type
);
53 case INPUT_EVENT_KIND_KEY
:
54 replay_put_dword(evt
->u
.key
->key
->type
);
56 switch (evt
->u
.key
->key
->type
) {
57 case KEY_VALUE_KIND_NUMBER
:
58 replay_put_qword(evt
->u
.key
->key
->u
.number
);
59 replay_put_byte(evt
->u
.key
->down
);
61 case KEY_VALUE_KIND_QCODE
:
62 replay_put_dword(evt
->u
.key
->key
->u
.qcode
);
63 replay_put_byte(evt
->u
.key
->down
);
65 case KEY_VALUE_KIND__MAX
:
70 case INPUT_EVENT_KIND_BTN
:
71 replay_put_dword(evt
->u
.btn
->button
);
72 replay_put_byte(evt
->u
.btn
->down
);
74 case INPUT_EVENT_KIND_REL
:
75 replay_put_dword(evt
->u
.rel
->axis
);
76 replay_put_qword(evt
->u
.rel
->value
);
78 case INPUT_EVENT_KIND_ABS
:
79 replay_put_dword(evt
->u
.abs
->axis
);
80 replay_put_qword(evt
->u
.abs
->value
);
82 case INPUT_EVENT_KIND__MAX
:
88 InputEvent
*replay_read_input_event(void)
98 evt
.type
= replay_get_dword();
100 case INPUT_EVENT_KIND_KEY
:
102 evt
.u
.key
->key
->type
= replay_get_dword();
104 switch (evt
.u
.key
->key
->type
) {
105 case KEY_VALUE_KIND_NUMBER
:
106 evt
.u
.key
->key
->u
.number
= replay_get_qword();
107 evt
.u
.key
->down
= replay_get_byte();
109 case KEY_VALUE_KIND_QCODE
:
110 evt
.u
.key
->key
->u
.qcode
= (QKeyCode
)replay_get_dword();
111 evt
.u
.key
->down
= replay_get_byte();
113 case KEY_VALUE_KIND__MAX
:
118 case INPUT_EVENT_KIND_BTN
:
120 evt
.u
.btn
->button
= (InputButton
)replay_get_dword();
121 evt
.u
.btn
->down
= replay_get_byte();
123 case INPUT_EVENT_KIND_REL
:
125 evt
.u
.rel
->axis
= (InputAxis
)replay_get_dword();
126 evt
.u
.rel
->value
= replay_get_qword();
128 case INPUT_EVENT_KIND_ABS
:
130 evt
.u
.abs
->axis
= (InputAxis
)replay_get_dword();
131 evt
.u
.abs
->value
= replay_get_qword();
133 case INPUT_EVENT_KIND__MAX
:
138 return qapi_clone_InputEvent(&evt
);
141 void replay_input_event(QemuConsole
*src
, InputEvent
*evt
)
143 if (replay_mode
== REPLAY_MODE_PLAY
) {
145 } else if (replay_mode
== REPLAY_MODE_RECORD
) {
146 replay_add_input_event(qapi_clone_InputEvent(evt
));
148 qemu_input_event_send_impl(src
, evt
);
152 void replay_input_sync_event(void)
154 if (replay_mode
== REPLAY_MODE_PLAY
) {
156 } else if (replay_mode
== REPLAY_MODE_RECORD
) {
157 replay_add_input_sync_event();
159 qemu_input_event_sync_impl();