qemu-img: add support for rate limit in qemu-img commit
[qemu.git] / replay / replay-input.c
1 /*
2 * replay-input.c
3 *
4 * Copyright (c) 2010-2015 Institute for System Programming
5 * of the Russian Academy of Sciences.
6 *
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.
9 *
10 */
11
12 #include "qemu/osdep.h"
13 #include "sysemu/replay.h"
14 #include "replay-internal.h"
15 #include "qemu/notify.h"
16 #include "ui/input.h"
17 #include "qapi/clone-visitor.h"
18 #include "qapi/qapi-visit-ui.h"
19
20 void replay_save_input_event(InputEvent *evt)
21 {
22 InputKeyEvent *key;
23 InputBtnEvent *btn;
24 InputMoveEvent *move;
25 replay_put_dword(evt->type);
26
27 switch (evt->type) {
28 case INPUT_EVENT_KIND_KEY:
29 key = evt->u.key.data;
30 replay_put_dword(key->key->type);
31
32 switch (key->key->type) {
33 case KEY_VALUE_KIND_NUMBER:
34 replay_put_qword(key->key->u.number.data);
35 replay_put_byte(key->down);
36 break;
37 case KEY_VALUE_KIND_QCODE:
38 replay_put_dword(key->key->u.qcode.data);
39 replay_put_byte(key->down);
40 break;
41 case KEY_VALUE_KIND__MAX:
42 /* keep gcc happy */
43 break;
44 }
45 break;
46 case INPUT_EVENT_KIND_BTN:
47 btn = evt->u.btn.data;
48 replay_put_dword(btn->button);
49 replay_put_byte(btn->down);
50 break;
51 case INPUT_EVENT_KIND_REL:
52 move = evt->u.rel.data;
53 replay_put_dword(move->axis);
54 replay_put_qword(move->value);
55 break;
56 case INPUT_EVENT_KIND_ABS:
57 move = evt->u.abs.data;
58 replay_put_dword(move->axis);
59 replay_put_qword(move->value);
60 break;
61 case INPUT_EVENT_KIND__MAX:
62 /* keep gcc happy */
63 break;
64 }
65 }
66
67 InputEvent *replay_read_input_event(void)
68 {
69 InputEvent evt;
70 KeyValue keyValue;
71 InputKeyEvent key;
72 key.key = &keyValue;
73 InputBtnEvent btn;
74 InputMoveEvent rel;
75 InputMoveEvent abs;
76
77 evt.type = replay_get_dword();
78 switch (evt.type) {
79 case INPUT_EVENT_KIND_KEY:
80 evt.u.key.data = &key;
81 evt.u.key.data->key->type = replay_get_dword();
82
83 switch (evt.u.key.data->key->type) {
84 case KEY_VALUE_KIND_NUMBER:
85 evt.u.key.data->key->u.number.data = replay_get_qword();
86 evt.u.key.data->down = replay_get_byte();
87 break;
88 case KEY_VALUE_KIND_QCODE:
89 evt.u.key.data->key->u.qcode.data = (QKeyCode)replay_get_dword();
90 evt.u.key.data->down = replay_get_byte();
91 break;
92 case KEY_VALUE_KIND__MAX:
93 /* keep gcc happy */
94 break;
95 }
96 break;
97 case INPUT_EVENT_KIND_BTN:
98 evt.u.btn.data = &btn;
99 evt.u.btn.data->button = (InputButton)replay_get_dword();
100 evt.u.btn.data->down = replay_get_byte();
101 break;
102 case INPUT_EVENT_KIND_REL:
103 evt.u.rel.data = &rel;
104 evt.u.rel.data->axis = (InputAxis)replay_get_dword();
105 evt.u.rel.data->value = replay_get_qword();
106 break;
107 case INPUT_EVENT_KIND_ABS:
108 evt.u.abs.data = &abs;
109 evt.u.abs.data->axis = (InputAxis)replay_get_dword();
110 evt.u.abs.data->value = replay_get_qword();
111 break;
112 case INPUT_EVENT_KIND__MAX:
113 /* keep gcc happy */
114 break;
115 }
116
117 return QAPI_CLONE(InputEvent, &evt);
118 }
119
120 void replay_input_event(QemuConsole *src, InputEvent *evt)
121 {
122 if (replay_mode == REPLAY_MODE_PLAY) {
123 /* Nothing */
124 } else if (replay_mode == REPLAY_MODE_RECORD) {
125 replay_add_input_event(QAPI_CLONE(InputEvent, evt));
126 } else {
127 qemu_input_event_send_impl(src, evt);
128 }
129 }
130
131 void replay_input_sync_event(void)
132 {
133 if (replay_mode == REPLAY_MODE_PLAY) {
134 /* Nothing */
135 } else if (replay_mode == REPLAY_MODE_RECORD) {
136 replay_add_input_sync_event();
137 } else {
138 qemu_input_event_sync_impl();
139 }
140 }