From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MJ6JL-00034H-D2 for qemu-devel@nongnu.org; Tue, 23 Jun 2009 09:45:19 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MJ6JG-00030i-3X for qemu-devel@nongnu.org; Tue, 23 Jun 2009 09:45:18 -0400 Received: from [199.232.76.173] (port=55104 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MJ6JF-00030a-Q0 for qemu-devel@nongnu.org; Tue, 23 Jun 2009 09:45:13 -0400 Received: from qw-out-1920.google.com ([74.125.92.148]:27508) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MJ6JF-0004Vx-6Z for qemu-devel@nongnu.org; Tue, 23 Jun 2009 09:45:13 -0400 Received: by qw-out-1920.google.com with SMTP id 4so31398qwk.4 for ; Tue, 23 Jun 2009 06:45:09 -0700 (PDT) Message-ID: <4A40DC62.9030407@codemonkey.ws> Date: Tue, 23 Jun 2009 08:45:06 -0500 From: Anthony Liguori MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH 03/11] QMP: Introduce protocol print functions References: <20090623012838.764dd37a@doriath> In-Reply-To: <20090623012838.764dd37a@doriath> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Luiz Capitulino Cc: aliguori@us.ibm.com, ehabkost@redhat.com, jan.kiszka@siemens.com, dlaor@redhat.com, qemu-devel@nongnu.org, avi@redhat.com Luiz Capitulino wrote: > This change introduces the functions that will be used by the Monitor > to output data in the format defined by the protocol specification. > > There are four functions: > > o monitor_printf_bad() signals a protocol error > o monitor_print_ok() signals successful execution > o monitor_printf_err() used by commands, to signal execution errors > o monitor_printf_data() used by commands, to output data > > For now monitor_print_ok() compilation is disabled to avoid breaking > the build as the function is not currently used. It will be enabled > by a later commit. > > Signed-off-by: Luiz Capitulino > --- > monitor.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > monitor.h | 3 ++ > qemu-tool.c | 12 +++++++++++ > 3 files changed, 78 insertions(+), 0 deletions(-) > > diff --git a/monitor.c b/monitor.c > index 514db00..dfa777d 100644 > --- a/monitor.c > +++ b/monitor.c > @@ -199,6 +199,69 @@ static int monitor_fprintf(FILE *stream, const char *fmt, ...) > return 0; > } > > +/* > + * QEMU Monitor Control print functions > + */ > + > +/* Protocol errors */ > +void monitor_printf_bad(Monitor *mon, const char *fmt, ...) > +{ > + if (monitor_ctrl_mode(mon)) { > + va_list ap; > + > + monitor_puts(mon, "- BAD "); > + > + va_start(ap, fmt); > + monitor_vprintf(mon, fmt, ap); > + va_end(ap); > + } > +} > + > +#if 0 > +/* OK command completion, 'info' commands are special */ > +static void monitor_print_ok(Monitor *mon, const char *cmd, const char *arg) > +{ > + if (!monitor_ctrl_mode(mon)) > + return; > + > + monitor_printf(mon, "+ OK %s", cmd); > + if (!strcmp(cmd, "info")) > + monitor_printf(mon, " %s", arg); > + monitor_puts(mon, " completed\n"); > +} > +#endif > + > +static void monitor_ctrl_pprintf(Monitor *mon, const char *prefix, > + const char *fmt, va_list ap) > +{ > + if (monitor_ctrl_mode(mon)) > + monitor_puts(mon, prefix); > + > + monitor_vprintf(mon, fmt, ap); > +} > + > +/* Should be used by commands to signal errors, will add the prefix > + * '- ERR ' if in control mode */ > +void monitor_printf_err(Monitor *mon, const char *fmt, ...) > +{ > + va_list ap; > + > + va_start(ap, fmt); > + monitor_ctrl_pprintf(mon, "- ERR ", fmt, ap); > + va_end(ap); > +} > + > +/* Should be used by commands to print any output which is not > + * an error, will add the prefix '= ' if in control mode */ > +void monitor_printf_data(Monitor *mon, const char *fmt, ...) > +{ > + va_list ap; > + > + va_start(ap, fmt); > + monitor_ctrl_pprintf(mon, "= ", fmt, ap); > + va_end(ap); > +} > + > static int compare_cmd(const char *name, const char *list) > { > const char *p, *pstart; > diff --git a/monitor.h b/monitor.h > index 48bc056..8b054eb 100644 > --- a/monitor.h > +++ b/monitor.h > @@ -24,6 +24,9 @@ void monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs, > void monitor_vprintf(Monitor *mon, const char *fmt, va_list ap); > void monitor_printf(Monitor *mon, const char *fmt, ...) > __attribute__ ((__format__ (__printf__, 2, 3))); > +void monitor_printf_bad(Monitor *mon, const char *fmt, ...); > +void monitor_printf_err(Monitor *mon, const char *fmt, ...); > +void monitor_printf_data(Monitor *mon, const char *fmt, ...); > Probably could just introduce a flag to monitor_printf(). In fact, you could go kernel style and have: monitor_printf(mon, MON_BAD "bad monitor command\n"); monitor_printf(mon, MON_DATA "some monitor data\n"); With MON_DATA being explicit. If not, make sure to add the format attribute to the printfs. Regards, Anthony Liguori