From 6ba0b71e8dd69a3cc2c90e0a7d0acf35ec6b232a Mon Sep 17 00:00:00 2001 From: Greg Bellows Date: Mon, 17 Nov 2014 11:18:20 -0600 Subject: android-console: Add event send command Add the Android emulator console "event send" command and associated help messages. The "send" command is used to initiate a given event on the Android emulator instance. Signed-off-by: Greg Bellows --- android-commands.h | 7 ++++++ android-console.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ android-console.h | 1 + 3 files changed, 75 insertions(+) diff --git a/android-commands.h b/android-commands.h index a0d5b12ea..4172feeba 100644 --- a/android-commands.h +++ b/android-commands.h @@ -86,6 +86,13 @@ static mon_cmd_t android_event_cmds[] = { .help = "list all aliases for a given ", .mhandler.cmd = android_console_event_codes, }, + { + .name = "send", + .args_type = "arg:s?", + .params = "", + .help = "send a series of events to the kernel", + .mhandler.cmd = android_console_event_send, + }, { NULL, NULL, }, }; diff --git a/android-console.c b/android-console.c index ede1b7a45..db7c16a75 100644 --- a/android-console.c +++ b/android-console.c @@ -533,6 +533,7 @@ enum { CMD_EVENT, CMD_EVENT_TYPES, CMD_EVENT_CODES, + CMD_EVENT_SEND, }; static const char *event_help[] = { @@ -550,6 +551,10 @@ static const char *event_help[] = { /* CMD_EVENT_CODES */ "'event codes ' lists all string aliases for a given " "event ", + /* CMD_EVENT_SEND */ + "'event send :: ...' allows your to send one or " + "more hardware events\nto the Android kernel. you can use text names " + "or integers for and " }; void android_console_event_types(Monitor *mon, const QDict *qdict) @@ -618,6 +623,66 @@ void android_console_event_codes(Monitor *mon, const QDict *qdict) monitor_printf(mon, "OK\n"); } +void android_console_event_send(Monitor *mon, const QDict *qdict) +{ + const char *arg = qdict_get_try_str(qdict, "arg"); + char **substr; + int type, code, value = -1; + + if (!arg) { + monitor_printf(mon, + "KO: Usage: event send :: ...\n"); + return; + } + + substr = g_strsplit(arg, ":", 3); + + /* The event type can be a symbol or number. Check that we have a valid + * type string and get the value depending on its format. + */ + if (g_ascii_isdigit(*substr[0])) { + type = g_ascii_strtoull(substr[0], NULL, 0); + } else { + type = gf_get_event_type_value(substr[0]); + } + if (type == -1) { + monitor_printf(mon, "KO: invalid event type in '%s', try 'event " + "list types' for valid values\n", arg); + goto out; + } + + /* The event code can be a symbol or number. Check that we have a valid + * code string and get the value depending on its format. + */ + if (g_ascii_isdigit(*substr[1])) { + code = g_ascii_strtoull(substr[1], NULL, 0); + } else { + code = gf_get_event_code_value(type, substr[1]); + } + if (code == -1) { + monitor_printf(mon, "KO: invalid event code in '%s', try 'event list " + "codes ' for valid values\n", arg); + goto out; + } + + /* The event value can only be a numeric value. Check that the value + * string is value and convert it. + */ + if (!substr[2] || !g_ascii_isdigit(*substr[2])) { + monitor_printf(mon, "KO: invalid event value in '%s', must be an " + "integer\n", arg); + goto out; + } + value = g_ascii_strtoull(substr[2], NULL, 0); + + gf_event_send(type, code, value); + + monitor_printf(mon, "OK\n"); + +out: + g_strfreev(substr); +} + void android_console_event(Monitor *mon, const QDict *qdict) { /* This only gets called for bad subcommands and help requests */ @@ -631,6 +696,8 @@ void android_console_event(Monitor *mon, const QDict *qdict) cmd = CMD_EVENT_TYPES; } else if (strstr(helptext, "codes")) { cmd = CMD_EVENT_CODES; + } else if (strstr(helptext, "send")) { + cmd = CMD_EVENT_SEND; } } diff --git a/android-console.h b/android-console.h index 270f08757..b69feecc0 100644 --- a/android-console.h +++ b/android-console.h @@ -38,6 +38,7 @@ void android_console_power(Monitor *mon, const QDict *qdict); void android_console_event_types(Monitor *mon, const QDict *qdict); void android_console_event_codes(Monitor *mon, const QDict *qdict); +void android_console_event_send(Monitor *mon, const QDict *qdict); void android_console_event(Monitor *mon, const QDict *qdict); void android_monitor_print_error(Monitor *mon, const char *fmt, ...); -- cgit v1.2.3