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
, NULL
, &src
, &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
, NULL
, &dst
, &error_abort
);
42 qmp_input_visitor_cleanup(qiv
);
48 void replay_save_input_event(InputEvent
*evt
)
53 replay_put_dword(evt
->type
);
56 case INPUT_EVENT_KIND_KEY
:
58 replay_put_dword(key
->key
->type
);
60 switch (key
->key
->type
) {
61 case KEY_VALUE_KIND_NUMBER
:
62 replay_put_qword(key
->key
->u
.number
);
63 replay_put_byte(key
->down
);
65 case KEY_VALUE_KIND_QCODE
:
66 replay_put_dword(key
->key
->u
.qcode
);
67 replay_put_byte(key
->down
);
69 case KEY_VALUE_KIND__MAX
:
74 case INPUT_EVENT_KIND_BTN
:
76 replay_put_dword(btn
->button
);
77 replay_put_byte(btn
->down
);
79 case INPUT_EVENT_KIND_REL
:
81 replay_put_dword(move
->axis
);
82 replay_put_qword(move
->value
);
84 case INPUT_EVENT_KIND_ABS
:
86 replay_put_dword(move
->axis
);
87 replay_put_qword(move
->value
);
89 case INPUT_EVENT_KIND__MAX
:
95 InputEvent
*replay_read_input_event(void)
105 evt
.type
= replay_get_dword();
107 case INPUT_EVENT_KIND_KEY
:
109 evt
.u
.key
->key
->type
= replay_get_dword();
111 switch (evt
.u
.key
->key
->type
) {
112 case KEY_VALUE_KIND_NUMBER
:
113 evt
.u
.key
->key
->u
.number
= replay_get_qword();
114 evt
.u
.key
->down
= replay_get_byte();
116 case KEY_VALUE_KIND_QCODE
:
117 evt
.u
.key
->key
->u
.qcode
= (QKeyCode
)replay_get_dword();
118 evt
.u
.key
->down
= replay_get_byte();
120 case KEY_VALUE_KIND__MAX
:
125 case INPUT_EVENT_KIND_BTN
:
127 evt
.u
.btn
->button
= (InputButton
)replay_get_dword();
128 evt
.u
.btn
->down
= replay_get_byte();
130 case INPUT_EVENT_KIND_REL
:
132 evt
.u
.rel
->axis
= (InputAxis
)replay_get_dword();
133 evt
.u
.rel
->value
= replay_get_qword();
135 case INPUT_EVENT_KIND_ABS
:
137 evt
.u
.abs
->axis
= (InputAxis
)replay_get_dword();
138 evt
.u
.abs
->value
= replay_get_qword();
140 case INPUT_EVENT_KIND__MAX
:
145 return qapi_clone_InputEvent(&evt
);
148 void replay_input_event(QemuConsole
*src
, InputEvent
*evt
)
150 if (replay_mode
== REPLAY_MODE_PLAY
) {
152 } else if (replay_mode
== REPLAY_MODE_RECORD
) {
153 replay_add_input_event(qapi_clone_InputEvent(evt
));
155 qemu_input_event_send_impl(src
, evt
);
159 void replay_input_sync_event(void)
161 if (replay_mode
== REPLAY_MODE_PLAY
) {
163 } else if (replay_mode
== REPLAY_MODE_RECORD
) {
164 replay_add_input_sync_event();
166 qemu_input_event_sync_impl();