From fb748383a27900132147affcb832383efc63813c Mon Sep 17 00:00:00 2001 From: Amit Shah <amit.shah@redhat.com> Date: Fri, 16 Jan 2009 09:26:05 +0530 Subject: [PATCH 27/54] qemu: Print asynchronous notifications on request This patch adds the ability to selectively enable asynchronous notifications from individual qemu subsystems by a new 'notify' monitor command. A sample invocation will look like this: (qemu) <vnc connection closed> (qemu) notify vnc <vnc connection closed> (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. Also notice that there's no qemu prompt after the output. I'm not sure how to fake a 'return' key to the monitor. Signed-off-by: Amit Shah <amit.shah@redhat.com> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> RH-Upstream-status: pending --- 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 d0560bf..9e2c7e7 100644 --- a/qemu/console.h +++ b/qemu/console.h @@ -188,6 +188,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 */ @@ -196,6 +198,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 6cfa0fa..bab627f 100644 --- a/qemu/monitor.c +++ b/qemu/monitor.c @@ -75,6 +75,8 @@ struct term_cmd_t { term_cmd_t* next; }; +int async_printable_events[MAX_ASYNC_EVENTS]; + #define MAX_MON 4 static CharDriverState *monitor_hd[MAX_MON]; static int hide_banner; @@ -133,6 +135,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; @@ -223,6 +243,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; @@ -1571,6 +1603,8 @@ static term_cmd_t term_cmds[] = { #ifdef CONFIG_QXL { "set_qxl_log_level", "i", qxl_do_set_log_level, "", "set qxl log level" }, #endif + { "notify", "ss", do_notify_async_events, + "NULL on|off", "enable / disable printing of notifications for the specified event" }, { NULL, NULL, }, }; -- 1.6.1