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 "qapi/error.h" 14 #include "qemu-common.h" 15 #include "sysemu/replay.h" 16 #include "replay-internal.h" 17 #include "qemu/notify.h" 18 #include "ui/input.h" 19 #include "qapi/clone-visitor.h" 20 21 void replay_save_input_event(InputEvent *evt) 22 { 23 InputKeyEvent *key; 24 InputBtnEvent *btn; 25 InputMoveEvent *move; 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__MAX: 63 /* keep gcc happy */ 64 break; 65 } 66 } 67 68 InputEvent *replay_read_input_event(void) 69 { 70 InputEvent evt; 71 KeyValue keyValue; 72 InputKeyEvent key; 73 key.key = &keyValue; 74 InputBtnEvent btn; 75 InputMoveEvent rel; 76 InputMoveEvent abs; 77 78 evt.type = replay_get_dword(); 79 switch (evt.type) { 80 case INPUT_EVENT_KIND_KEY: 81 evt.u.key.data = &key; 82 evt.u.key.data->key->type = replay_get_dword(); 83 84 switch (evt.u.key.data->key->type) { 85 case KEY_VALUE_KIND_NUMBER: 86 evt.u.key.data->key->u.number.data = replay_get_qword(); 87 evt.u.key.data->down = replay_get_byte(); 88 break; 89 case KEY_VALUE_KIND_QCODE: 90 evt.u.key.data->key->u.qcode.data = (QKeyCode)replay_get_dword(); 91 evt.u.key.data->down = replay_get_byte(); 92 break; 93 case KEY_VALUE_KIND__MAX: 94 /* keep gcc happy */ 95 break; 96 } 97 break; 98 case INPUT_EVENT_KIND_BTN: 99 evt.u.btn.data = &btn; 100 evt.u.btn.data->button = (InputButton)replay_get_dword(); 101 evt.u.btn.data->down = replay_get_byte(); 102 break; 103 case INPUT_EVENT_KIND_REL: 104 evt.u.rel.data = &rel; 105 evt.u.rel.data->axis = (InputAxis)replay_get_dword(); 106 evt.u.rel.data->value = replay_get_qword(); 107 break; 108 case INPUT_EVENT_KIND_ABS: 109 evt.u.abs.data = &abs; 110 evt.u.abs.data->axis = (InputAxis)replay_get_dword(); 111 evt.u.abs.data->value = replay_get_qword(); 112 break; 113 case INPUT_EVENT_KIND__MAX: 114 /* keep gcc happy */ 115 break; 116 } 117 118 return QAPI_CLONE(InputEvent, &evt); 119 } 120 121 void replay_input_event(QemuConsole *src, InputEvent *evt) 122 { 123 if (replay_mode == REPLAY_MODE_PLAY) { 124 /* Nothing */ 125 } else if (replay_mode == REPLAY_MODE_RECORD) { 126 replay_add_input_event(QAPI_CLONE(InputEvent, evt)); 127 } else { 128 qemu_input_event_send_impl(src, evt); 129 } 130 } 131 132 void replay_input_sync_event(void) 133 { 134 if (replay_mode == REPLAY_MODE_PLAY) { 135 /* Nothing */ 136 } else if (replay_mode == REPLAY_MODE_RECORD) { 137 replay_add_input_sync_event(); 138 } else { 139 qemu_input_event_sync_impl(); 140 } 141 } 142