From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MIxcn-0007ky-Oi for qemu-devel@nongnu.org; Tue, 23 Jun 2009 00:28:49 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MIxck-0007jT-1b for qemu-devel@nongnu.org; Tue, 23 Jun 2009 00:28:49 -0400 Received: from [199.232.76.173] (port=35673 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MIxcj-0007jO-N2 for qemu-devel@nongnu.org; Tue, 23 Jun 2009 00:28:45 -0400 Received: from mx2.redhat.com ([66.187.237.31]:32789) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MIxcj-00037Y-6a for qemu-devel@nongnu.org; Tue, 23 Jun 2009 00:28:45 -0400 Date: Tue, 23 Jun 2009 01:28:38 -0300 From: Luiz Capitulino Message-ID: <20090623012838.764dd37a@doriath> In-Reply-To: References: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH 03/11] QMP: Introduce protocol print functions List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aliguori@us.ibm.com, ehabkost@redhat.com, jan.kiszka@siemens.com, dlaor@redhat.com, avi@redhat.com 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, ...); void monitor_print_filename(Monitor *mon, const char *filename); void monitor_flush(Monitor *mon); diff --git a/qemu-tool.c b/qemu-tool.c index c08f061..2ba9983 100644 --- a/qemu-tool.c +++ b/qemu-tool.c @@ -40,6 +40,18 @@ void monitor_print_filename(Monitor *mon, const char *filename) { } +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, ...) +{ +} + QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque) { QEMUBH *bh; -- 1.6.3.GIT