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-common.h"
13 #include "sysemu/replay.h"
14 #include "replay-internal.h"
15 #include "qemu/notify.h"
17 #include "qapi/qmp-output-visitor.h"
18 #include "qapi/qmp-input-visitor.h"
19 #include "qapi-visit.h"
21 static InputEvent
*qapi_clone_InputEvent(InputEvent
*src
)
23 QmpOutputVisitor
*qov
;
27 InputEvent
*dst
= NULL
;
29 qov
= qmp_output_visitor_new();
30 ov
= qmp_output_get_visitor(qov
);
31 visit_type_InputEvent(ov
, &src
, NULL
, &error_abort
);
32 obj
= qmp_output_get_qobject(qov
);
33 qmp_output_visitor_cleanup(qov
);
38 qiv
= qmp_input_visitor_new(obj
);
39 iv
= qmp_input_get_visitor(qiv
);
40 visit_type_InputEvent(iv
, &dst
, NULL
, &error_abort
);
41 qmp_input_visitor_cleanup(qiv
);
47 void replay_save_input_event(InputEvent
*evt
)
49 replay_put_dword(evt
->type
);
52 case INPUT_EVENT_KIND_KEY
:
53 replay_put_dword(evt
->u
.key
->key
->type
);
55 switch (evt
->u
.key
->key
->type
) {
56 case KEY_VALUE_KIND_NUMBER
:
57 replay_put_qword(evt
->u
.key
->key
->u
.number
);
58 replay_put_byte(evt
->u
.key
->down
);
60 case KEY_VALUE_KIND_QCODE
:
61 replay_put_dword(evt
->u
.key
->key
->u
.qcode
);
62 replay_put_byte(evt
->u
.key
->down
);
64 case KEY_VALUE_KIND_MAX
:
69 case INPUT_EVENT_KIND_BTN
:
70 replay_put_dword(evt
->u
.btn
->button
);
71 replay_put_byte(evt
->u
.btn
->down
);
73 case INPUT_EVENT_KIND_REL
:
74 replay_put_dword(evt
->u
.rel
->axis
);
75 replay_put_qword(evt
->u
.rel
->value
);
77 case INPUT_EVENT_KIND_ABS
:
78 replay_put_dword(evt
->u
.abs
->axis
);
79 replay_put_qword(evt
->u
.abs
->value
);
81 case INPUT_EVENT_KIND_MAX
:
87 InputEvent
*replay_read_input_event(void)
97 evt
.type
= replay_get_dword();
99 case INPUT_EVENT_KIND_KEY
:
101 evt
.u
.key
->key
->type
= replay_get_dword();
103 switch (evt
.u
.key
->key
->type
) {
104 case KEY_VALUE_KIND_NUMBER
:
105 evt
.u
.key
->key
->u
.number
= replay_get_qword();
106 evt
.u
.key
->down
= replay_get_byte();
108 case KEY_VALUE_KIND_QCODE
:
109 evt
.u
.key
->key
->u
.qcode
= (QKeyCode
)replay_get_dword();
110 evt
.u
.key
->down
= replay_get_byte();
112 case KEY_VALUE_KIND_MAX
:
117 case INPUT_EVENT_KIND_BTN
:
119 evt
.u
.btn
->button
= (InputButton
)replay_get_dword();
120 evt
.u
.btn
->down
= replay_get_byte();
122 case INPUT_EVENT_KIND_REL
:
124 evt
.u
.rel
->axis
= (InputAxis
)replay_get_dword();
125 evt
.u
.rel
->value
= replay_get_qword();
127 case INPUT_EVENT_KIND_ABS
:
129 evt
.u
.abs
->axis
= (InputAxis
)replay_get_dword();
130 evt
.u
.abs
->value
= replay_get_qword();
132 case INPUT_EVENT_KIND_MAX
:
137 return qapi_clone_InputEvent(&evt
);
140 void replay_input_event(QemuConsole
*src
, InputEvent
*evt
)
142 if (replay_mode
== REPLAY_MODE_PLAY
) {
144 } else if (replay_mode
== REPLAY_MODE_RECORD
) {
145 replay_add_input_event(qapi_clone_InputEvent(evt
));
147 qemu_input_event_send_impl(src
, evt
);
151 void replay_input_sync_event(void)
153 if (replay_mode
== REPLAY_MODE_PLAY
) {
155 } else if (replay_mode
== REPLAY_MODE_RECORD
) {
156 replay_add_input_sync_event();
158 qemu_input_event_sync_impl();