error: Improve documentation
[qemu/kevin.git] / replay / replay-input.c
blobbc15f592dc8a0dc74029d68e702ca29aab00106b
1 /*
2 * replay-input.c
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"
16 #include "ui/input.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;
24 QmpInputVisitor *qiv;
25 Visitor *ov, *iv;
26 QObject *obj;
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);
34 if (!obj) {
35 return NULL;
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);
42 qobject_decref(obj);
44 return dst;
47 void replay_save_input_event(InputEvent *evt)
49 replay_put_dword(evt->type);
51 switch (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);
59 break;
60 case KEY_VALUE_KIND_QCODE:
61 replay_put_dword(evt->u.key->key->u.qcode);
62 replay_put_byte(evt->u.key->down);
63 break;
64 case KEY_VALUE_KIND__MAX:
65 /* keep gcc happy */
66 break;
68 break;
69 case INPUT_EVENT_KIND_BTN:
70 replay_put_dword(evt->u.btn->button);
71 replay_put_byte(evt->u.btn->down);
72 break;
73 case INPUT_EVENT_KIND_REL:
74 replay_put_dword(evt->u.rel->axis);
75 replay_put_qword(evt->u.rel->value);
76 break;
77 case INPUT_EVENT_KIND_ABS:
78 replay_put_dword(evt->u.abs->axis);
79 replay_put_qword(evt->u.abs->value);
80 break;
81 case INPUT_EVENT_KIND__MAX:
82 /* keep gcc happy */
83 break;
87 InputEvent *replay_read_input_event(void)
89 InputEvent evt;
90 KeyValue keyValue;
91 InputKeyEvent key;
92 key.key = &keyValue;
93 InputBtnEvent btn;
94 InputMoveEvent rel;
95 InputMoveEvent abs;
97 evt.type = replay_get_dword();
98 switch (evt.type) {
99 case INPUT_EVENT_KIND_KEY:
100 evt.u.key = &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();
107 break;
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();
111 break;
112 case KEY_VALUE_KIND__MAX:
113 /* keep gcc happy */
114 break;
116 break;
117 case INPUT_EVENT_KIND_BTN:
118 evt.u.btn = &btn;
119 evt.u.btn->button = (InputButton)replay_get_dword();
120 evt.u.btn->down = replay_get_byte();
121 break;
122 case INPUT_EVENT_KIND_REL:
123 evt.u.rel = &rel;
124 evt.u.rel->axis = (InputAxis)replay_get_dword();
125 evt.u.rel->value = replay_get_qword();
126 break;
127 case INPUT_EVENT_KIND_ABS:
128 evt.u.abs = &abs;
129 evt.u.abs->axis = (InputAxis)replay_get_dword();
130 evt.u.abs->value = replay_get_qword();
131 break;
132 case INPUT_EVENT_KIND__MAX:
133 /* keep gcc happy */
134 break;
137 return qapi_clone_InputEvent(&evt);
140 void replay_input_event(QemuConsole *src, InputEvent *evt)
142 if (replay_mode == REPLAY_MODE_PLAY) {
143 /* Nothing */
144 } else if (replay_mode == REPLAY_MODE_RECORD) {
145 replay_add_input_event(qapi_clone_InputEvent(evt));
146 } else {
147 qemu_input_event_send_impl(src, evt);
151 void replay_input_sync_event(void)
153 if (replay_mode == REPLAY_MODE_PLAY) {
154 /* Nothing */
155 } else if (replay_mode == REPLAY_MODE_RECORD) {
156 replay_add_input_sync_event();
157 } else {
158 qemu_input_event_sync_impl();