From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LPE2T-0003YX-3y for qemu-devel@nongnu.org; Tue, 20 Jan 2009 05:40:57 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LPE2R-0003Xd-PZ for qemu-devel@nongnu.org; Tue, 20 Jan 2009 05:40:55 -0500 Received: from [199.232.76.173] (port=45405 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LPE2R-0003XR-9i for qemu-devel@nongnu.org; Tue, 20 Jan 2009 05:40:55 -0500 Received: from mx2.redhat.com ([66.187.237.31]:46329) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LPE2Q-0005ap-Py for qemu-devel@nongnu.org; Tue, 20 Jan 2009 05:40:55 -0500 From: Amit Shah Date: Tue, 20 Jan 2009 16:11:05 +0530 Message-Id: <1232448066-32209-1-git-send-email-amit.shah@redhat.com> Subject: [Qemu-devel] [PATCH 1/2] Print asynchronous notifications on request Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: aliguori@us.ibm.com Cc: Amit Shah , qemu-devel@nongnu.org This patch adds the ability to selectively enable asynchronous notifications from individual qemu subsystems by a new 'notify' monitor command. This is helpful for programs currently parsing monitor output. A sample invocation will look like this: (qemu) (qemu) notify vnc on (qemu) # VNC: Closing down connection 127.0.0.1:1 Notice that the output is prefixed by '#'. Also, it will appear on the line that has '(qemu) ' already output on it. Signed-off-by: Amit Shah --- qemu/console.h | 4 ++++ qemu/monitor.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 0 deletions(-) diff --git a/qemu/console.h b/qemu/console.h index 383ea1a..0cf575c 100644 --- a/qemu/console.h +++ b/qemu/console.h @@ -292,6 +292,8 @@ void curses_display_init(DisplayState *ds, int full_screen); /* x_keymap.c */ extern uint8_t _translate_keycode(const int key); +#define MAX_ASYNC_EVENTS 0 + /* FIXME: term_printf et al should probably go elsewhere so everything does not need to include console.h */ /* monitor.c */ @@ -299,6 +301,8 @@ void monitor_init(CharDriverState *hd, int show_banner); void term_puts(const char *str); void term_vprintf(const char *fmt, va_list ap); void term_printf(const char *fmt, ...) __attribute__ ((__format__ (__printf__, 1, 2))); +void term_printf_async(const int event, const char *fmt, ...) + __attribute__ ((__format__ (__printf__, 2, 3))); void term_print_filename(const char *filename); void term_flush(void); void term_print_help(void); diff --git a/qemu/monitor.c b/qemu/monitor.c index 7ff9890..ef871d0 100644 --- a/qemu/monitor.c +++ b/qemu/monitor.c @@ -65,6 +65,8 @@ typedef struct term_cmd_t { const char *help; } term_cmd_t; +int async_printable_events[MAX_ASYNC_EVENTS]; + #define MAX_MON 4 static CharDriverState *monitor_hd[MAX_MON]; static int hide_banner; @@ -122,6 +124,24 @@ void term_printf(const char *fmt, ...) va_end(ap); } +void term_printf_async(const int event, const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + + if (event > MAX_ASYNC_EVENTS) + goto cleanup; + if (!async_printable_events[event]) + goto cleanup; + + term_printf("# "); + term_vprintf(fmt, ap); + +cleanup: + va_end(ap); + return; +} + void term_print_filename(const char *filename) { int i; @@ -210,6 +230,18 @@ static void do_help(const char *name) help_cmd(name); } +static void do_notify_async_events(char *event_str, char *enable) +{ + int event; + + return; + + if (!strcmp(enable, "on")) + async_printable_events[event] = 1; + else + async_printable_events[event] = 0; +} + static void do_commit(const char *device) { int i, all_devices; @@ -1517,6 +1549,8 @@ static const term_cmd_t term_cmds[] = { { "balloon", "i", do_balloon, "target", "request VM to change it's memory allocation (in MB)" }, { "set_link", "ss", do_set_link, "name [up|down]" }, + { "notify", "ss", do_notify_async_events, + "NULL on|off", "enable / disable printing of notifications for the specified event" }, { NULL, NULL, }, }; -- 1.6.0.6