diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2015-11-06 11:31:40 +0000 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2015-11-06 11:31:40 +0000 |
commit | 9319738080faeb09876ce2017fcaea4937c475ee (patch) | |
tree | bf2b6e1c46b44d0e28fe4de89b034de7f2e8343d /replay/replay-input.c | |
parent | 3aa88b31290c7cbbbae344efdece659194b95c70 (diff) | |
parent | ee312992a323530ea2cda8680f3a34746c72db8f (diff) |
Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream-replay' into staging
So here it is, let's see what happens.
# gpg: Signature made Fri 06 Nov 2015 09:30:34 GMT using RSA key ID 78C7AE83
# gpg: Good signature from "Paolo Bonzini <bonzini@gnu.org>"
# gpg: aka "Paolo Bonzini <pbonzini@redhat.com>"
* remotes/bonzini/tags/for-upstream-replay:
replay: recording of the user input
replay: command line options
replay: replay blockers for devices
replay: initialization and deinitialization
replay: ptimer
bottom halves: introduce bh call function
replay: checkpoints
icount: improve counting for record/replay
replay: shutdown event
replay: recording and replaying clock ticks
replay: asynchronous events infrastructure
replay: interrupts and exceptions
cpu: replay instructions sequence
cpu-exec: allow temporary disabling icount
replay: introduce icount event
replay: introduce mutex to protect the replay log
replay: internal functions for replay log
replay: global variables and function stubs
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'replay/replay-input.c')
-rw-r--r-- | replay/replay-input.c | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/replay/replay-input.c b/replay/replay-input.c new file mode 100644 index 0000000000..98798955a1 --- /dev/null +++ b/replay/replay-input.c @@ -0,0 +1,160 @@ +/* + * replay-input.c + * + * Copyright (c) 2010-2015 Institute for System Programming + * of the Russian Academy of Sciences. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu-common.h" +#include "sysemu/replay.h" +#include "replay-internal.h" +#include "qemu/notify.h" +#include "ui/input.h" +#include "qapi/qmp-output-visitor.h" +#include "qapi/qmp-input-visitor.h" +#include "qapi-visit.h" + +static InputEvent *qapi_clone_InputEvent(InputEvent *src) +{ + QmpOutputVisitor *qov; + QmpInputVisitor *qiv; + Visitor *ov, *iv; + QObject *obj; + InputEvent *dst = NULL; + + qov = qmp_output_visitor_new(); + ov = qmp_output_get_visitor(qov); + visit_type_InputEvent(ov, &src, NULL, &error_abort); + obj = qmp_output_get_qobject(qov); + qmp_output_visitor_cleanup(qov); + if (!obj) { + return NULL; + } + + qiv = qmp_input_visitor_new(obj); + iv = qmp_input_get_visitor(qiv); + visit_type_InputEvent(iv, &dst, NULL, &error_abort); + qmp_input_visitor_cleanup(qiv); + qobject_decref(obj); + + return dst; +} + +void replay_save_input_event(InputEvent *evt) +{ + replay_put_dword(evt->type); + + switch (evt->type) { + case INPUT_EVENT_KIND_KEY: + replay_put_dword(evt->u.key->key->type); + + switch (evt->u.key->key->type) { + case KEY_VALUE_KIND_NUMBER: + replay_put_qword(evt->u.key->key->u.number); + replay_put_byte(evt->u.key->down); + break; + case KEY_VALUE_KIND_QCODE: + replay_put_dword(evt->u.key->key->u.qcode); + replay_put_byte(evt->u.key->down); + break; + case KEY_VALUE_KIND_MAX: + /* keep gcc happy */ + break; + } + break; + case INPUT_EVENT_KIND_BTN: + replay_put_dword(evt->u.btn->button); + replay_put_byte(evt->u.btn->down); + break; + case INPUT_EVENT_KIND_REL: + replay_put_dword(evt->u.rel->axis); + replay_put_qword(evt->u.rel->value); + break; + case INPUT_EVENT_KIND_ABS: + replay_put_dword(evt->u.abs->axis); + replay_put_qword(evt->u.abs->value); + break; + case INPUT_EVENT_KIND_MAX: + /* keep gcc happy */ + break; + } +} + +InputEvent *replay_read_input_event(void) +{ + InputEvent evt; + KeyValue keyValue; + InputKeyEvent key; + key.key = &keyValue; + InputBtnEvent btn; + InputMoveEvent rel; + InputMoveEvent abs; + + evt.type = replay_get_dword(); + switch (evt.type) { + case INPUT_EVENT_KIND_KEY: + evt.u.key = &key; + evt.u.key->key->type = replay_get_dword(); + + switch (evt.u.key->key->type) { + case KEY_VALUE_KIND_NUMBER: + evt.u.key->key->u.number = replay_get_qword(); + evt.u.key->down = replay_get_byte(); + break; + case KEY_VALUE_KIND_QCODE: + evt.u.key->key->u.qcode = (QKeyCode)replay_get_dword(); + evt.u.key->down = replay_get_byte(); + break; + case KEY_VALUE_KIND_MAX: + /* keep gcc happy */ + break; + } + break; + case INPUT_EVENT_KIND_BTN: + evt.u.btn = &btn; + evt.u.btn->button = (InputButton)replay_get_dword(); + evt.u.btn->down = replay_get_byte(); + break; + case INPUT_EVENT_KIND_REL: + evt.u.rel = &rel; + evt.u.rel->axis = (InputAxis)replay_get_dword(); + evt.u.rel->value = replay_get_qword(); + break; + case INPUT_EVENT_KIND_ABS: + evt.u.abs = &abs; + evt.u.abs->axis = (InputAxis)replay_get_dword(); + evt.u.abs->value = replay_get_qword(); + break; + case INPUT_EVENT_KIND_MAX: + /* keep gcc happy */ + break; + } + + return qapi_clone_InputEvent(&evt); +} + +void replay_input_event(QemuConsole *src, InputEvent *evt) +{ + if (replay_mode == REPLAY_MODE_PLAY) { + /* Nothing */ + } else if (replay_mode == REPLAY_MODE_RECORD) { + replay_add_input_event(qapi_clone_InputEvent(evt)); + } else { + qemu_input_event_send_impl(src, evt); + } +} + +void replay_input_sync_event(void) +{ + if (replay_mode == REPLAY_MODE_PLAY) { + /* Nothing */ + } else if (replay_mode == REPLAY_MODE_RECORD) { + replay_add_input_sync_event(); + } else { + qemu_input_event_sync_impl(); + } +} |