Commit e22b1e99 authored by Aurelien Jarno's avatar Aurelien Jarno
Browse files

Merge branch 'queue/qmp' of git://repo.or.cz/qemu/qmp-unstable

* 'queue/qmp' of git://repo.or.cz/qemu/qmp-unstable:
  tcx: tcx_screen_dump(): add error handling
  tcx: tcx24_screen_dump(): add error handling
  g364fb: g364fb_screen_dump(): add error handling
  omap_lcdc: omap_ppm_save(): add error handling
  omap_lcdc: rename ppm_save() to omap_ppm_save()
  vga: ppm_save(): add error handling
  qapi: convert screendump
  console: vga_hw_screen_dump_ptr: take Error argument
  error: add error_setg()
  json-parser: Fix potential NULL pointer segfault
  qapi: Fix potential NULL pointer segfault
  qapi: convert sendkey
  monitor: move key_defs[] table and introduce two help functions
  qapi: add the QKeyCode enum
  qapi: generate list struct and visit_list for enum
  hmp: rename arguments
  monitor: rename keyname '<' to 'less'
  fix doc of using raw values with sendkey
  Add support for pretty-printing response in qmp-shell
parents a32354e2 0ab6b636
Loading
Loading
Loading
Loading
+33 −13
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@
import qmp
import readline
import sys
import pprint

class QMPCompleter(list):
    def complete(self, text, state):
@@ -52,10 +53,11 @@ class QMPShellBadPort(QMPShellError):
# TODO: QMPShell's interface is a bit ugly (eg. _fill_completion() and
#       _execute_cmd()). Let's design a better one.
class QMPShell(qmp.QEMUMonitorProtocol):
    def __init__(self, address):
    def __init__(self, address, pp=None):
        qmp.QEMUMonitorProtocol.__init__(self, self.__get_address(address))
        self._greeting = None
        self._completer = None
        self._pp = pp

    def __get_address(self, arg):
        """
@@ -114,6 +116,10 @@ class QMPShell(qmp.QEMUMonitorProtocol):
        if resp is None:
            print 'Disconnected'
            return False

        if self._pp is not None:
            self._pp.pprint(resp)
        else:
            print resp
        return True

@@ -222,21 +228,35 @@ def die(msg):
def fail_cmdline(option=None):
    if option:
        sys.stderr.write('ERROR: bad command-line option \'%s\'\n' % option)
    sys.stderr.write('qemu-shell [ -H ] < UNIX socket path> | < TCP address:port >\n')
    sys.stderr.write('qemu-shell [ -p ] [ -H ] < UNIX socket path> | < TCP address:port >\n')
    sys.exit(1)

def main():
    addr = ''
    qemu = None
    hmp = False
    pp = None

    try:
        if len(sys.argv) == 2:
            qemu = QMPShell(sys.argv[1])
            addr = sys.argv[1]
        elif len(sys.argv) == 3:
            if sys.argv[1] != '-H':
                fail_cmdline(sys.argv[1])
            qemu = HMPShell(sys.argv[2])
            addr = sys.argv[2]
        for arg in sys.argv[1:]:
            if arg == "-H":
                if qemu is not None:
                    fail_cmdline(arg)
                hmp = True
            elif arg == "-p":
                if pp is not None:
                    fail_cmdline(arg)
                pp = pprint.PrettyPrinter(indent=4)
            else:
                if qemu is not None:
                    fail_cmdline(arg)
                if hmp:
                    qemu = HMPShell(arg)
                else:
                    qemu = QMPShell(arg, pp)
                addr = arg

        if qemu is None:
            fail_cmdline()
    except QMPShellBadPort:
        die('bad port number in command-line')
+4 −3
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@
#include "qemu-common.h"
#include "console.h"
#include "qemu-timer.h"
#include "qmp-commands.h"

//#define DEBUG_CONSOLE
#define DEFAULT_BACKSCROLL 512
@@ -176,7 +177,7 @@ void vga_hw_invalidate(void)
        active_console->hw_invalidate(active_console->hw);
}

void vga_hw_screen_dump(const char *filename)
void qmp_screendump(const char *filename, Error **errp)
{
    TextConsole *previous_active_console;
    bool cswitch;
@@ -190,9 +191,9 @@ void vga_hw_screen_dump(const char *filename)
        console_select(0);
    }
    if (consoles[0] && consoles[0]->hw_screen_dump) {
        consoles[0]->hw_screen_dump(consoles[0]->hw, filename, cswitch);
        consoles[0]->hw_screen_dump(consoles[0]->hw, filename, cswitch, errp);
    } else {
        error_report("screen dump not implemented");
        error_setg(errp, "device doesn't support screendump\n");
    }

    if (cswitch) {
+8 −2
Original line number Diff line number Diff line
@@ -6,6 +6,8 @@
#include "notify.h"
#include "monitor.h"
#include "trace.h"
#include "qapi-types.h"
#include "error.h"

/* keyboard/mouse support */

@@ -343,7 +345,8 @@ static inline void console_write_ch(console_ch_t *dest, uint32_t ch)

typedef void (*vga_hw_update_ptr)(void *);
typedef void (*vga_hw_invalidate_ptr)(void *);
typedef void (*vga_hw_screen_dump_ptr)(void *, const char *, bool cswitch);
typedef void (*vga_hw_screen_dump_ptr)(void *, const char *, bool cswitch,
                                       Error **errp);
typedef void (*vga_hw_text_update_ptr)(void *, console_ch_t *);

DisplayState *graphic_console_init(vga_hw_update_ptr update,
@@ -354,7 +357,6 @@ DisplayState *graphic_console_init(vga_hw_update_ptr update,

void vga_hw_update(void);
void vga_hw_invalidate(void);
void vga_hw_screen_dump(const char *filename);
void vga_hw_text_update(console_ch_t *chardata);

int is_graphic_console(void);
@@ -397,4 +399,8 @@ static inline int vnc_display_pw_expire(DisplayState *ds, time_t expires)
/* curses.c */
void curses_display_init(DisplayState *ds, int full_screen);

/* input.c */
int index_from_key(const char *key);
int index_from_keycode(int code);

#endif
+6 −0
Original line number Diff line number Diff line
@@ -29,6 +29,12 @@ typedef struct Error Error;
 */
void error_set(Error **err, ErrorClass err_class, const char *fmt, ...) GCC_FMT_ATTR(3, 4);

/**
 * Same as error_set(), but sets a generic error
 */
#define error_setg(err, fmt, ...) \
    error_set(err, ERROR_CLASS_GENERIC_ERROR, fmt, ## __VA_ARGS__)

/**
 * Returns true if an indirect pointer to an error is pointing to a valid
 * error object.
+6 −7
Original line number Diff line number Diff line
@@ -194,8 +194,7 @@ ETEXI
        .args_type  = "filename:F",
        .params     = "filename",
        .help       = "save screen into PPM image 'filename'",
        .user_print = monitor_user_noop,
        .mhandler.cmd_new = do_screen_dump,
        .mhandler.cmd = hmp_screen_dump,
    },

STEXI
@@ -502,19 +501,19 @@ ETEXI

    {
        .name       = "sendkey",
        .args_type  = "string:s,hold_time:i?",
        .args_type  = "keys:s,hold-time:i?",
        .params     = "keys [hold_ms]",
        .help       = "send keys to the VM (e.g. 'sendkey ctrl-alt-f1', default hold time=100 ms)",
        .mhandler.cmd = do_sendkey,
        .mhandler.cmd = hmp_send_key,
    },

STEXI
@item sendkey @var{keys}
@findex sendkey

Send @var{keys} to the emulator. @var{keys} could be the name of the
key or @code{#} followed by the raw value in either decimal or hexadecimal
format. Use @code{-} to press several keys simultaneously. Example:
Send @var{keys} to the guest. @var{keys} could be the name of the
key or the raw value in hexadecimal format. Use @code{-} to press
several keys simultaneously. Example:
@example
sendkey ctrl-alt-f1
@end example
Loading