aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Bellows <greg.bellows@linaro.org>2014-11-17 11:18:20 -0600
committerGreg Bellows <greg.bellows@linaro.org>2015-01-15 16:18:58 -0600
commit6ba0b71e8dd69a3cc2c90e0a7d0acf35ec6b232a (patch)
tree6ce742495c3b83f9ce40be9bcf12b14e71dc03bf
parentf06bd269ea2ae7ff0ff518ba00f0a1f1ed60d995 (diff)
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 <greg.bellows@linaro.org>
-rw-r--r--android-commands.h7
-rw-r--r--android-console.c67
-rw-r--r--android-console.h1
3 files changed, 75 insertions, 0 deletions
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 <code> aliases for a given <type>",
.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 <type>' lists all <code> string aliases for a given "
"event <type>",
+ /* CMD_EVENT_SEND */
+ "'event send <type>:<code>:<value> ...' allows your to send one or "
+ "more hardware events\nto the Android kernel. you can use text names "
+ "or integers for <type> and <code>"
};
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 <type>:<code>:<value> ...\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 <type>' 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, ...);