From patchwork Thu Oct 22 14:40:36 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 36693 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3CB99B7BB5 for ; Fri, 23 Oct 2009 02:15:35 +1100 (EST) Received: from localhost ([127.0.0.1]:58804 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N0zO0-0000Uj-0r for incoming@patchwork.ozlabs.org; Thu, 22 Oct 2009 11:15:32 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N0yqX-0000fG-OD for qemu-devel@nongnu.org; Thu, 22 Oct 2009 10:40:57 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N0yqS-0000dU-Ua for qemu-devel@nongnu.org; Thu, 22 Oct 2009 10:40:57 -0400 Received: from [199.232.76.173] (port=46242 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N0yqS-0000dM-Ow for qemu-devel@nongnu.org; Thu, 22 Oct 2009 10:40:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:7157) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N0yqS-0007oC-2z for qemu-devel@nongnu.org; Thu, 22 Oct 2009 10:40:52 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9MEemBD024555; Thu, 22 Oct 2009 10:40:48 -0400 Received: from doriath (vpn-12-94.rdu.redhat.com [10.11.12.94]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n9MEeh0O012705 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Thu, 22 Oct 2009 10:40:46 -0400 Date: Thu, 22 Oct 2009 12:40:36 -0200 From: Luiz Capitulino To: Jamie Lokier Subject: Re: [Qemu-devel] [PATCH] new SDL keyboard shortcuts to start and stop VM Message-ID: <20091022124036.5df991f3@doriath> In-Reply-To: <20091021183503.GA27677@shareable.org> References: <4ADCE635.4060604@codemonkey.ws> <4ADD9388.8040206@redhat.com> <20091020170800.GG32538@redhat.com> <4ADEB7EF.3060800@redhat.com> <5d6222a80910210652q3b005ca6ub950a2014bfbaa41@mail.gmail.com> <5d6222a80910210924j62505b7dtf298754ce65f1c99@mail.gmail.com> <20091021183503.GA27677@shareable.org> Organization: Red Hat Mime-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Kevin Wolf , Glauber Costa , Mulyadi Santosa , qemu-devel@nongnu.org X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org On Wed, 21 Oct 2009 19:35:03 +0100 Jamie Lokier wrote: > Mulyadi Santosa wrote: > > On Wed, Oct 21, 2009 at 11:24 PM, Glauber Costa wrote: > > > You can provide a monitor command to do that > > > > > > something in the lines of: > > > - add_macro > > > - remove_macro > > > - list_macros > > > > Please CMIIW, "command_list" here refers to at least one of monitor > > commands, right? meaning, i.e one could do: > > add_macro ctrl_alt_shift_s "stop" > > > > or extend that so it does: > > add_macro ctrl_alt_shift_s "stop print $pc" > > > > so, it stops the VM followed by printing program counter. > > If the monitor accepted ";" as a command separator, to put multiple > commands on a single line, could just be a quoted > string which is processed as a line. Why is ";" needed? > If we're going to have keyboard macros, it would be nice and probably > very easy to have monitor macros too - monitor commands which expand > to a line in the same way. > > The number of times I've typed things like send_key control-alt-del > and would have appreciated a "cad" macro... Yeah, I agree. When testing migration, for example, I have to type 'migrate -d tcp:0:4444' several times... Maybe there's a smarter way to do this, but the monitor macros idea seems interesting to me. > Syntax idea comes to mind is: > > - Add ";" as command separator. Not difficult, but not trivial. > - add_macro > - remove_macro > - list_macros Why not macro_add? > > - add_key key > - remove_key > - list_keys What's key? Anyway, below there's a patch with an initial implementation. I've implemented it using the "old" monitor style because I didn't want to think about the right "object model" for this yet.. If people think this is interesting I will work on a serious implementation for submission. Ah, it doesn't have macro_del and if we use QObjects we can consider saving its json representation in file so that we can have macro_load. commit e7fa305f82f4f99168166bda437e86d3a6343064 Author: Luiz Capitulino Date: Thu Oct 22 12:26:06 2009 -0200 monitor: Add macro support This is a buggy, untested, initial implementation, which only supports "macro_add" and "macro_list". Example: (qemu) macro_add mi "migrate -d tcp:localhost:4444" Signed-off-by: Luiz Capitulino diff --git a/monitor.c b/monitor.c index 2566f4a..f8e2844 100644 --- a/monitor.c +++ b/monitor.c @@ -107,6 +107,15 @@ struct Monitor { QLIST_ENTRY(Monitor) entry; }; +typedef struct MonitorMacro { + QTAILQ_ENTRY(MonitorMacro) entry; + const char *name; + const char *command_line; +} MonitorMacro; + +static QTAILQ_HEAD(monitor_macros, MonitorMacro) monitor_macros = + QTAILQ_HEAD_INITIALIZER(monitor_macros); + static QLIST_HEAD(mon_list, Monitor) mon_list; static const mon_cmd_t mon_cmds[]; @@ -1909,6 +1918,25 @@ static void do_closefd(Monitor *mon, const QDict *qdict) fdname); } +static void do_macro_add(Monitor *mon, const QDict *qdict) +{ + MonitorMacro *macro; + + macro = qemu_mallocz(sizeof(*macro)); + macro->name = qemu_strdup(qdict_get_str(qdict, "name")); + macro->command_line = qemu_strdup(qdict_get_str(qdict, "command")); + + QTAILQ_INSERT_TAIL(&monitor_macros, macro, entry); +} + +static void do_macro_list(Monitor *mon, const QDict *qdict) +{ + MonitorMacro *macro; + + QTAILQ_FOREACH(macro, &monitor_macros, entry) + monitor_printf(mon, "%s: \"%s\"\n", macro->name, macro->command_line); +} + static void do_loadvm(Monitor *mon, const QDict *qdict) { int saved_vm_running = vm_running; @@ -2902,6 +2930,45 @@ static char *key_get_info(const char *type, char **key) return ++p; } +static const mon_cmd_t *find_command(const char *cmdname) +{ + const mon_cmd_t *cmd; + + /* find the command */ + for (cmd = mon_cmds; cmd->name != NULL; cmd++) { + if (compare_cmd(cmdname, cmd->name)) + return cmd; + } + + return NULL; +} + +static const mon_cmd_t *find_macro(char *cmdname, size_t len, const char **pos) +{ + const char *p; + MonitorMacro *macro; + const mon_cmd_t *cmd; + + QTAILQ_FOREACH(macro, &monitor_macros, entry) { + if (strcmp(macro->name, cmdname) == 0) + break; + } + + if (!macro) + return NULL; + + p = get_command_name(macro->command_line, cmdname, len); + if (!p) + return NULL; + + cmd = find_command(cmdname); + if (!cmd) + return NULL; + + *pos = p; + return cmd; +} + static int default_fmt_format = 'x'; static int default_fmt_size = 4; @@ -2927,15 +2994,13 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon, if (!p) return NULL; - /* find the command */ - for(cmd = mon_cmds; cmd->name != NULL; cmd++) { - if (compare_cmd(cmdname, cmd->name)) - break; - } - - if (cmd->name == NULL) { - monitor_printf(mon, "unknown command: '%s'\n", cmdname); - return NULL; + cmd = find_macro(cmdname, sizeof(cmdname), &p); + if (!cmd) { + cmd = find_command(cmdname); + if (!cmd) { + monitor_printf(mon, "unknown command: '%s'\n", cmdname); + return NULL; + } } /* parse the parameters */ diff --git a/qemu-monitor.hx b/qemu-monitor.hx index 29999c6..37561be 100644 --- a/qemu-monitor.hx +++ b/qemu-monitor.hx @@ -1031,6 +1031,30 @@ Close the file descriptor previously assigned to @var{fdname} using the used by another monitor command. ETEXI + { + .name = "macro_add", + .args_type = "name:s,command:s", + .params = "name command", + .help = "add a new monitor macro", + .mhandler.cmd = do_macro_add, + }, + +STEXI +@item macro_add @var{name} @var{command} +ETEXI + + { + .name = "macro_list", + .args_type = "", + .params = "", + .help = "list monitor macros", + .mhandler.cmd = do_macro_list, + }, + +STEXI +@item macro_list +ETEXI + STEXI @end table ETEXI