summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Bellows <greg.bellows@linaro.org>2014-11-17 11:18:20 -0600
committerGreg Bellows <greg.bellows@linaro.org>2014-11-19 17:08:01 -0600
commit3f5eaa428b46b5c9491ae6faa611545358f17e60 (patch)
tree262793f1c7f6e1a98fdd83ca627d157dafda8480
parentcdf616c2f67e6b1a422e861009a72ef5bd27c4c0 (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 25a9a3a01..30ba9e64f 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 9562e7557..5eabd9e24 100644
--- a/android-console.c
+++ b/android-console.c
@@ -517,6 +517,7 @@ enum {
CMD_EVENT,
CMD_EVENT_TYPES,
CMD_EVENT_CODES,
+ CMD_EVENT_SEND,
};
static const char *event_help[] = {
@@ -534,6 +535,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)
@@ -602,6 +607,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 */
@@ -615,6 +680,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, ...);