xref: /openbmc/qemu/replay/replay-input.c (revision 05caa062)
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     InputMultiTouchEvent *mtt;
26     replay_put_dword(evt->type);
27 
28     switch (evt->type) {
29     case INPUT_EVENT_KIND_KEY:
30         key = evt->u.key.data;
31         replay_put_dword(key->key->type);
32 
33         switch (key->key->type) {
34         case KEY_VALUE_KIND_NUMBER:
35             replay_put_qword(key->key->u.number.data);
36             replay_put_byte(key->down);
37             break;
38         case KEY_VALUE_KIND_QCODE:
39             replay_put_dword(key->key->u.qcode.data);
40             replay_put_byte(key->down);
41             break;
42         case KEY_VALUE_KIND__MAX:
43             /* keep gcc happy */
44             break;
45         }
46         break;
47     case INPUT_EVENT_KIND_BTN:
48         btn = evt->u.btn.data;
49         replay_put_dword(btn->button);
50         replay_put_byte(btn->down);
51         break;
52     case INPUT_EVENT_KIND_REL:
53         move = evt->u.rel.data;
54         replay_put_dword(move->axis);
55         replay_put_qword(move->value);
56         break;
57     case INPUT_EVENT_KIND_ABS:
58         move = evt->u.abs.data;
59         replay_put_dword(move->axis);
60         replay_put_qword(move->value);
61         break;
62     case INPUT_EVENT_KIND_MTT:
63         mtt = evt->u.mtt.data;
64         replay_put_dword(mtt->type);
65         replay_put_qword(mtt->slot);
66         replay_put_qword(mtt->tracking_id);
67         replay_put_dword(mtt->axis);
68         replay_put_qword(mtt->value);
69         break;
70     case INPUT_EVENT_KIND__MAX:
71         /* keep gcc happy */
72         break;
73     }
74 }
75 
76 InputEvent *replay_read_input_event(void)
77 {
78     InputEvent evt;
79     KeyValue keyValue;
80     InputKeyEvent key;
81     key.key = &keyValue;
82     InputBtnEvent btn;
83     InputMoveEvent rel;
84     InputMoveEvent abs;
85     InputMultiTouchEvent mtt;
86 
87     evt.type = replay_get_dword();
88     switch (evt.type) {
89     case INPUT_EVENT_KIND_KEY:
90         evt.u.key.data = &key;
91         evt.u.key.data->key->type = replay_get_dword();
92 
93         switch (evt.u.key.data->key->type) {
94         case KEY_VALUE_KIND_NUMBER:
95             evt.u.key.data->key->u.number.data = replay_get_qword();
96             evt.u.key.data->down = replay_get_byte();
97             break;
98         case KEY_VALUE_KIND_QCODE:
99             evt.u.key.data->key->u.qcode.data = (QKeyCode)replay_get_dword();
100             evt.u.key.data->down = replay_get_byte();
101             break;
102         case KEY_VALUE_KIND__MAX:
103             /* keep gcc happy */
104             break;
105         }
106         break;
107     case INPUT_EVENT_KIND_BTN:
108         evt.u.btn.data = &btn;
109         evt.u.btn.data->button = (InputButton)replay_get_dword();
110         evt.u.btn.data->down = replay_get_byte();
111         break;
112     case INPUT_EVENT_KIND_REL:
113         evt.u.rel.data = &rel;
114         evt.u.rel.data->axis = (InputAxis)replay_get_dword();
115         evt.u.rel.data->value = replay_get_qword();
116         break;
117     case INPUT_EVENT_KIND_ABS:
118         evt.u.abs.data = &abs;
119         evt.u.abs.data->axis = (InputAxis)replay_get_dword();
120         evt.u.abs.data->value = replay_get_qword();
121         break;
122     case INPUT_EVENT_KIND_MTT:
123         evt.u.mtt.data = &mtt;
124         evt.u.mtt.data->type = (InputMultiTouchType)replay_get_dword();
125         evt.u.mtt.data->slot = replay_get_qword();
126         evt.u.mtt.data->tracking_id = replay_get_qword();
127         evt.u.mtt.data->axis = (InputAxis)replay_get_dword();
128         evt.u.mtt.data->value = replay_get_qword();
129         break;
130     case INPUT_EVENT_KIND__MAX:
131         /* keep gcc happy */
132         break;
133     }
134 
135     return QAPI_CLONE(InputEvent, &evt);
136 }
137 
138 void replay_input_event(QemuConsole *src, InputEvent *evt)
139 {
140     if (replay_mode == REPLAY_MODE_PLAY) {
141         /* Nothing */
142     } else if (replay_mode == REPLAY_MODE_RECORD) {
143         replay_add_input_event(QAPI_CLONE(InputEvent, evt));
144     } else {
145         qemu_input_event_send_impl(src, evt);
146     }
147 }
148 
149 void replay_input_sync_event(void)
150 {
151     if (replay_mode == REPLAY_MODE_PLAY) {
152         /* Nothing */
153     } else if (replay_mode == REPLAY_MODE_RECORD) {
154         replay_add_input_sync_event();
155     } else {
156         qemu_input_event_sync_impl();
157     }
158 }
159