From patchwork Sun Jul 18 12:43:55 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Goldish X-Patchwork-Id: 112603 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o6IChuVc003109 for ; Sun, 18 Jul 2010 12:43:56 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754713Ab0GRMnq (ORCPT ); Sun, 18 Jul 2010 08:43:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:15274 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754705Ab0GRMnp (ORCPT ); Sun, 18 Jul 2010 08:43:45 -0400 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o6IChh1w011888 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 18 Jul 2010 08:43:43 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o6IChgP4012883; Sun, 18 Jul 2010 08:43:42 -0400 Received: from localhost.localdomain (dhcp-1-188.tlv.redhat.com [10.35.1.188]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id o6ICheCB018298; Sun, 18 Jul 2010 08:43:41 -0400 From: Michael Goldish To: qemu-devel@nongnu.org, kvm@vger.kernel.org Cc: Michael Goldish Subject: [PATCH] Monitor: Convert do_sendkey() to QObject, QError Date: Sun, 18 Jul 2010 15:43:55 +0300 Message-Id: <1279457035-28657-1-git-send-email-mgoldish@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Sun, 18 Jul 2010 12:43:56 +0000 (UTC) diff --git a/monitor.c b/monitor.c index d5377de..082c29d 100644 --- a/monitor.c +++ b/monitor.c @@ -1614,7 +1614,7 @@ static void release_keys(void *opaque) } } -static void do_sendkey(Monitor *mon, const QDict *qdict) +static int do_sendkey(Monitor *mon, const QDict *qdict, QObject **ret_data) { char keyname_buf[16]; char *separator; @@ -1636,18 +1636,18 @@ static void do_sendkey(Monitor *mon, const QDict *qdict) if (keyname_len > 0) { pstrcpy(keyname_buf, sizeof(keyname_buf), string); if (keyname_len > sizeof(keyname_buf) - 1) { - monitor_printf(mon, "invalid key: '%s...'\n", keyname_buf); - return; + qerror_report(QERR_INVALID_KEY, keyname_buf); + return -1; } if (i == MAX_KEYCODES) { - monitor_printf(mon, "too many keys\n"); - return; + qerror_report(QERR_TOO_MANY_KEYS); + return -1; } keyname_buf[keyname_len] = 0; keycode = get_keycode(keyname_buf); if (keycode < 0) { - monitor_printf(mon, "unknown key: '%s'\n", keyname_buf); - return; + qerror_report(QERR_UNKNOWN_KEY, keyname_buf); + return -1; } keycodes[i++] = keycode; } @@ -1666,6 +1666,7 @@ static void do_sendkey(Monitor *mon, const QDict *qdict) /* delayed key up events */ qemu_mod_timer(key_timer, qemu_get_clock(vm_clock) + muldiv64(get_ticks_per_sec(), hold_time, 1000)); + return 0; } static int mouse_button_state; diff --git a/qemu-monitor.hx b/qemu-monitor.hx index f7e46c4..8b6cf09 100644 --- a/qemu-monitor.hx +++ b/qemu-monitor.hx @@ -532,7 +532,8 @@ ETEXI .args_type = "string:s,hold_time:i?", .params = "keys [hold_ms]", .help = "send keys to the VM (e.g. 'sendkey ctrl-alt-f1', default hold time=100 ms)", - .mhandler.cmd = do_sendkey, + .user_print = monitor_user_noop, + .mhandler.cmd_new = do_sendkey, }, STEXI @@ -549,6 +550,25 @@ sendkey ctrl-alt-f1 This command is useful to send keys that your graphical user interface intercepts at low level, such as @code{ctrl-alt-f1} in X Window. ETEXI +SQMP +sendkey +------- + +Send keys to the emulator. + +Arguments: + +- "string": key names or key codes in hexadecimal format separated by dashes (json-string) +- "hold_time": duration in milliseconds to hold the keys down (json-int, optional, default=100) + +Example: + +-> { "execute": "sendkey", "arguments": { "string": "ctrl-alt-f1" } } +<- { "return": {} } + +Note: if several keys are given they are pressed simultaneously. + +EQMP { .name = "system_reset", diff --git a/qerror.c b/qerror.c index 44d0bf8..34a698e 100644 --- a/qerror.c +++ b/qerror.c @@ -117,6 +117,10 @@ static const QErrorStringTable qerror_table[] = { .desc = "Invalid block format '%(name)'", }, { + .error_fmt = QERR_INVALID_KEY, + .desc = "Invalid key '%(key)...'", + }, + { .error_fmt = QERR_INVALID_PARAMETER, .desc = "Invalid parameter '%(name)'", }, @@ -185,10 +189,18 @@ static const QErrorStringTable qerror_table[] = { .desc = "Too many open files", }, { + .error_fmt = QERR_TOO_MANY_KEYS, + .desc = "Too many keys", + }, + { .error_fmt = QERR_UNDEFINED_ERROR, .desc = "An undefined error has ocurred", }, { + .error_fmt = QERR_UNKNOWN_KEY, + .desc = "Unknown key '%(key)'", + }, + { .error_fmt = QERR_VNC_SERVER_FAILED, .desc = "Could not start VNC server on %(target)", }, diff --git a/qerror.h b/qerror.h index 77ae574..a23630c 100644 --- a/qerror.h +++ b/qerror.h @@ -103,6 +103,9 @@ QError *qobject_to_qerror(const QObject *obj); #define QERR_INVALID_BLOCK_FORMAT \ "{ 'class': 'InvalidBlockFormat', 'data': { 'name': %s } }" +#define QERR_INVALID_KEY \ + "{ 'class': 'InvalidKey', 'data': { 'key': %s } }" + #define QERR_INVALID_PARAMETER \ "{ 'class': 'InvalidParameter', 'data': { 'name': %s } }" @@ -154,9 +157,15 @@ QError *qobject_to_qerror(const QObject *obj); #define QERR_TOO_MANY_FILES \ "{ 'class': 'TooManyFiles', 'data': {} }" +#define QERR_TOO_MANY_KEYS \ + "{ 'class': 'TooManyKeys', 'data': {} }" + #define QERR_UNDEFINED_ERROR \ "{ 'class': 'UndefinedError', 'data': {} }" +#define QERR_UNKNOWN_KEY \ + "{ 'class': 'UnknownKey', 'data': { 'key': %s } }" + #define QERR_VNC_SERVER_FAILED \ "{ 'class': 'VNCServerFailed', 'data': { 'target': %s } }"