aboutsummaryrefslogtreecommitdiff
path: root/hmp.c
diff options
context:
space:
mode:
authorAmos Kong <akong@redhat.com>2012-08-31 10:56:26 +0800
committerLuiz Capitulino <lcapitulino@redhat.com>2012-09-05 15:48:57 -0300
commite4c8f004c55d9da3eae3e14df740238bf805b5d6 (patch)
tree15dfdb6d109c4d093fa08e4f7fa79bfbaf29c6b1 /hmp.c
parent1048c88f03545fa42bdebb077871a743a614d2ab (diff)
qapi: convert sendkey
Convert 'sendkey' to use QAPI. QAPI passes key's index of mapping table to qmp_send_key(), not keycode. So we use help functions to convert key/code to index of key_defs, and 'index' will be converted to 'keycode' inside qmp_send_key(). For qmp, QAPI would check invalid key and raise error. For hmp, invalid key is checked in hmp_send_key(). 'send-key' of QMP doesn't support key in hexadecimal format. Signed-off-by: Amos Kong <akong@redhat.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Diffstat (limited to 'hmp.c')
-rw-r--r--hmp.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/hmp.c b/hmp.c
index 81c8acb67a..ba99b2fb30 100644
--- a/hmp.c
+++ b/hmp.c
@@ -19,6 +19,7 @@
#include "qemu-timer.h"
#include "qmp-commands.h"
#include "monitor.h"
+#include "console.h"
static void hmp_handle_error(Monitor *mon, Error **errp)
{
@@ -1102,3 +1103,57 @@ void hmp_closefd(Monitor *mon, const QDict *qdict)
qmp_closefd(fdname, &errp);
hmp_handle_error(mon, &errp);
}
+
+void hmp_send_key(Monitor *mon, const QDict *qdict)
+{
+ const char *keys = qdict_get_str(qdict, "keys");
+ QKeyCodeList *keylist, *head = NULL, *tmp = NULL;
+ int has_hold_time = qdict_haskey(qdict, "hold-time");
+ int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
+ Error *err = NULL;
+ char keyname_buf[16];
+ char *separator;
+ int keyname_len, idx;
+
+ while (1) {
+ separator = strchr(keys, '-');
+ keyname_len = separator ? separator - keys : strlen(keys);
+ pstrcpy(keyname_buf, sizeof(keyname_buf), keys);
+
+ /* Be compatible with old interface, convert user inputted "<" */
+ if (!strncmp(keyname_buf, "<", 1) && keyname_len == 1) {
+ pstrcpy(keyname_buf, sizeof(keyname_buf), "less");
+ keyname_len = 4;
+ }
+ keyname_buf[keyname_len] = 0;
+
+ idx = index_from_key(keyname_buf);
+ if (idx == Q_KEY_CODE_MAX) {
+ monitor_printf(mon, "invalid parameter: %s\n", keyname_buf);
+ break;
+ }
+
+ keylist = g_malloc0(sizeof(*keylist));
+ keylist->value = idx;
+ keylist->next = NULL;
+
+ if (!head) {
+ head = keylist;
+ }
+ if (tmp) {
+ tmp->next = keylist;
+ }
+ tmp = keylist;
+
+ if (!separator) {
+ break;
+ }
+ keys = separator + 1;
+ }
+
+ if (idx != Q_KEY_CODE_MAX) {
+ qmp_send_key(head, has_hold_time, hold_time, &err);
+ }
+ hmp_handle_error(mon, &err);
+ qapi_free_QKeyCodeList(head);
+}