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/qmp-output-visitor.h"
20 #include "qapi/qmp-input-visitor.h"
21 #include "qapi-visit.h"
23 static InputEvent
*qapi_clone_InputEvent(InputEvent
*src
)
25 QmpOutputVisitor
*qov
;
29 InputEvent
*dst
= NULL
;
31 qov
= qmp_output_visitor_new();
32 ov
= qmp_output_get_visitor(qov
);
33 visit_type_InputEvent(ov
, NULL
, &src
, &error_abort
);
34 obj
= qmp_output_get_qobject(qov
);
35 qmp_output_visitor_cleanup(qov
);
40 qiv
= qmp_input_visitor_new(obj
);
41 iv
= qmp_input_get_visitor(qiv
);
42 visit_type_InputEvent(iv
, NULL
, &dst
, &error_abort
);
43 qmp_input_visitor_cleanup(qiv
);
49 void replay_save_input_event(InputEvent
*evt
)
54 replay_put_dword(evt
->type
);
57 case INPUT_EVENT_KIND_KEY
:
58 key
= evt
->u
.key
.data
;
59 replay_put_dword(key
->key
->type
);
61 switch (key
->key
->type
) {
62 case KEY_VALUE_KIND_NUMBER
:
63 replay_put_qword(key
->key
->u
.number
.data
);
64 replay_put_byte(key
->down
);
66 case KEY_VALUE_KIND_QCODE
:
67 replay_put_dword(key
->key
->u
.qcode
.data
);
68 replay_put_byte(key
->down
);
70 case KEY_VALUE_KIND__MAX
:
75 case INPUT_EVENT_KIND_BTN
:
76 btn
= evt
->u
.btn
.data
;
77 replay_put_dword(btn
->button
);
78 replay_put_byte(btn
->down
);
80 case INPUT_EVENT_KIND_REL
:
81 move
= evt
->u
.rel
.data
;
82 replay_put_dword(move
->axis
);
83 replay_put_qword(move
->value
);
85 case INPUT_EVENT_KIND_ABS
:
86 move
= evt
->u
.abs
.data
;
87 replay_put_dword(move
->axis
);
88 replay_put_qword(move
->value
);
90 case INPUT_EVENT_KIND__MAX
:
96 InputEvent
*replay_read_input_event(void)
106 evt
.type
= replay_get_dword();
108 case INPUT_EVENT_KIND_KEY
:
109 evt
.u
.key
.data
= &key
;
110 evt
.u
.key
.data
->key
->type
= replay_get_dword();
112 switch (evt
.u
.key
.data
->key
->type
) {
113 case KEY_VALUE_KIND_NUMBER
:
114 evt
.u
.key
.data
->key
->u
.number
.data
= replay_get_qword();
115 evt
.u
.key
.data
->down
= replay_get_byte();
117 case KEY_VALUE_KIND_QCODE
:
118 evt
.u
.key
.data
->key
->u
.qcode
.data
= (QKeyCode
)replay_get_dword();
119 evt
.u
.key
.data
->down
= replay_get_byte();
121 case KEY_VALUE_KIND__MAX
:
126 case INPUT_EVENT_KIND_BTN
:
127 evt
.u
.btn
.data
= &btn
;
128 evt
.u
.btn
.data
->button
= (InputButton
)replay_get_dword();
129 evt
.u
.btn
.data
->down
= replay_get_byte();
131 case INPUT_EVENT_KIND_REL
:
132 evt
.u
.rel
.data
= &rel
;
133 evt
.u
.rel
.data
->axis
= (InputAxis
)replay_get_dword();
134 evt
.u
.rel
.data
->value
= replay_get_qword();
136 case INPUT_EVENT_KIND_ABS
:
137 evt
.u
.abs
.data
= &abs
;
138 evt
.u
.abs
.data
->axis
= (InputAxis
)replay_get_dword();
139 evt
.u
.abs
.data
->value
= replay_get_qword();
141 case INPUT_EVENT_KIND__MAX
:
146 return qapi_clone_InputEvent(&evt
);
149 void replay_input_event(QemuConsole
*src
, InputEvent
*evt
)
151 if (replay_mode
== REPLAY_MODE_PLAY
) {
153 } else if (replay_mode
== REPLAY_MODE_RECORD
) {
154 replay_add_input_event(qapi_clone_InputEvent(evt
));
156 qemu_input_event_send_impl(src
, evt
);
160 void replay_input_sync_event(void)
162 if (replay_mode
== REPLAY_MODE_PLAY
) {
164 } else if (replay_mode
== REPLAY_MODE_RECORD
) {
165 replay_add_input_sync_event();
167 qemu_input_event_sync_impl();