Patchwork [10/29] monitor: Port handler_1 to use QDict

login
register
mail settings
Submitter Luiz Capitulino
Date Aug. 26, 2009, 5:05 p.m.
Message ID <1251306352-31316-11-git-send-email-lcapitulino@redhat.com>
Download mbox | patch
Permalink /patch/32181/
State Superseded
Headers show

Comments

Luiz Capitulino - Aug. 26, 2009, 5:05 p.m.
This commit ports command handlers that receive one argument to use
the new monitor's dictionary.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 console.h        |    3 +-
 hw/pci-hotplug.c |    4 +-
 migration.c      |    6 +++-
 migration.h      |    4 +-
 monitor.c        |   66 +++++++++++++++++++++++++++++++----------------------
 savevm.c         |   10 +++++---
 sysemu.h         |   13 +++++-----
 vl.c             |   11 +++++----
 8 files changed, 68 insertions(+), 49 deletions(-)

Patch

diff --git a/console.h b/console.h
index 3518339..c8922e4 100644
--- a/console.h
+++ b/console.h
@@ -2,6 +2,7 @@ 
 #define CONSOLE_H
 
 #include "qemu-char.h"
+#include "qdict.h"
 
 /* keyboard/mouse support */
 
@@ -44,7 +45,7 @@  struct MouseTransformInfo {
 };
 
 void do_info_mice(Monitor *mon);
-void do_mouse_set(Monitor *mon, int index);
+void do_mouse_set(Monitor *mon, const QDict *qdict);
 
 /* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
    constants) */
diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c
index 492a893..2a5b0f9 100644
--- a/hw/pci-hotplug.c
+++ b/hw/pci-hotplug.c
@@ -203,9 +203,9 @@  void pci_device_hot_remove(Monitor *mon, const char *pci_addr)
     qemu_system_device_hot_add(bus, slot, 0);
 }
 
-void do_pci_device_hot_remove(Monitor *mon, const char *pci_addr)
+void do_pci_device_hot_remove(Monitor *mon, const QDict *qdict)
 {
-    pci_device_hot_remove(mon, pci_addr);
+    pci_device_hot_remove(mon, qdict_get_str(qdict, "pci_addr"));
 }
 
 static int pci_match_fn(void *dev_private, void *arg)
diff --git a/migration.c b/migration.c
index 1c76914..7d0a555 100644
--- a/migration.c
+++ b/migration.c
@@ -84,11 +84,12 @@  void do_migrate_cancel(Monitor *mon, const QDict *qdict)
         s->cancel(s);
 }
 
-void do_migrate_set_speed(Monitor *mon, const char *value)
+void do_migrate_set_speed(Monitor *mon, const QDict *qdict)
 {
     double d;
     char *ptr;
     FdMigrationState *s;
+    const char *value = qdict_get_str(qdict, "value");
 
     d = strtod(value, &ptr);
     switch (*ptr) {
@@ -122,10 +123,11 @@  uint64_t migrate_max_downtime(void)
     return max_downtime;
 }
 
-void do_migrate_set_downtime(Monitor *mon, const char *value)
+void do_migrate_set_downtime(Monitor *mon, const QDict *qdict)
 {
     char *ptr;
     double d;
+    const char *value = qdict_get_str(qdict, "value");
 
     d = strtod(value, &ptr);
     if (!strcmp(ptr,"ms")) {
diff --git a/migration.h b/migration.h
index 223d2c6..f86c0fd 100644
--- a/migration.h
+++ b/migration.h
@@ -54,11 +54,11 @@  void do_migrate(Monitor *mon, int detach, const char *uri);
 
 void do_migrate_cancel(Monitor *mon, const QDict *qdict);
 
-void do_migrate_set_speed(Monitor *mon, const char *value);
+void do_migrate_set_speed(Monitor *mon, const QDict *qdict);
 
 uint64_t migrate_max_downtime(void);
 
-void do_migrate_set_downtime(Monitor *mon, const char *value);
+void do_migrate_set_downtime(Monitor *mon, const QDict *qdict);
 
 void do_info_migrate(Monitor *mon);
 
diff --git a/monitor.c b/monitor.c
index 8bce694..c82fa31 100644
--- a/monitor.c
+++ b/monitor.c
@@ -254,15 +254,16 @@  static void help_cmd(Monitor *mon, const char *name)
     }
 }
 
-static void do_help_cmd(Monitor *mon, const char *name)
+static void do_help_cmd(Monitor *mon, const QDict *qdict)
 {
-    help_cmd(mon, name);
+    help_cmd(mon, qdict_get_try_str(qdict, "name"));
 }
 
-static void do_commit(Monitor *mon, const char *device)
+static void do_commit(Monitor *mon, const QDict *qdict)
 {
     int all_devices;
     DriveInfo *dinfo;
+    const char *device = qdict_get_str(qdict, "device");
 
     all_devices = !strcmp(device, "all");
     TAILQ_FOREACH(dinfo, &drives, next) {
@@ -273,9 +274,10 @@  static void do_commit(Monitor *mon, const char *device)
     }
 }
 
-static void do_info(Monitor *mon, const char *item)
+static void do_info(Monitor *mon, const QDict *qdict)
 {
     const mon_cmd_t *cmd;
+    const char *item = qdict_get_try_str(qdict, "item");
     void (*handler)(Monitor *);
 
     if (!item)
@@ -387,8 +389,9 @@  static void do_info_cpus(Monitor *mon)
     }
 }
 
-static void do_cpu_set(Monitor *mon, int index)
+static void do_cpu_set(Monitor *mon, const QDict *qdict)
 {
+    int index = qdict_get_int(qdict, "index");
     if (mon_set_cpu(index) < 0)
         monitor_printf(mon, "Invalid CPU index\n");
 }
@@ -522,19 +525,20 @@  static void do_change(Monitor *mon, const char *device, const char *target,
     }
 }
 
-static void do_screen_dump(Monitor *mon, const char *filename)
+static void do_screen_dump(Monitor *mon, const QDict *qdict)
 {
-    vga_hw_screen_dump(filename);
+    vga_hw_screen_dump(qdict_get_str(qdict, "filename"));
 }
 
-static void do_logfile(Monitor *mon, const char *filename)
+static void do_logfile(Monitor *mon, const QDict *qdict)
 {
-    cpu_set_log_filename(filename);
+    cpu_set_log_filename(qdict_get_str(qdict, "filename"));
 }
 
-static void do_log(Monitor *mon, const char *items)
+static void do_log(Monitor *mon, const QDict *qdict)
 {
     int mask;
+    const char *items = qdict_get_str(qdict, "items");
 
     if (!strcmp(items, "none")) {
         mask = 0;
@@ -548,8 +552,9 @@  static void do_log(Monitor *mon, const char *items)
     cpu_set_log(mask);
 }
 
-static void do_singlestep(Monitor *mon, const char *option)
+static void do_singlestep(Monitor *mon, const QDict *qdict)
 {
+    const char *option = qdict_get_try_str(qdict, "option");
     if (!option || !strcmp(option, "on")) {
         singlestep = 1;
     } else if (!strcmp(option, "off")) {
@@ -601,8 +606,9 @@  static void encrypted_bdrv_it(void *opaque, BlockDriverState *bs)
     }
 }
 
-static void do_gdbserver(Monitor *mon, const char *device)
+static void do_gdbserver(Monitor *mon, const QDict *qdict)
 {
+    const char *device = qdict_get_try_str(qdict, "device");
     if (!device)
         device = "tcp::" DEFAULT_GDBSTUB_PORT;
     if (gdbserver_start(device) < 0) {
@@ -616,8 +622,9 @@  static void do_gdbserver(Monitor *mon, const char *device)
     }
 }
 
-static void do_watchdog_action(Monitor *mon, const char *action)
+static void do_watchdog_action(Monitor *mon, const QDict *qdict)
 {
+    const char *action = qdict_get_str(qdict, "action");
     if (select_watchdog_action(action) == -1) {
         monitor_printf(mon, "Unknown watchdog action '%s'\n", action);
     }
@@ -1167,8 +1174,9 @@  static void do_mouse_move(Monitor *mon, const char *dx_str, const char *dy_str,
     kbd_mouse_event(dx, dy, dz, mouse_button_state);
 }
 
-static void do_mouse_button(Monitor *mon, int button_state)
+static void do_mouse_button(Monitor *mon, const QDict *qdict)
 {
+    int button_state = qdict_get_int(qdict, "button_state");
     mouse_button_state = button_state;
     kbd_mouse_event(0, 0, 0, mouse_button_state);
 }
@@ -1223,9 +1231,10 @@  static void do_ioport_write(Monitor *mon, int count, int format, int size,
     }
 }
 
-static void do_boot_set(Monitor *mon, const char *bootdevice)
+static void do_boot_set(Monitor *mon, const QDict *qdict)
 {
     int res;
+    const char *bootdevice = qdict_get_str(qdict, "bootdevice");
 
     res = qemu_boot_set(bootdevice);
     if (res == 0) {
@@ -1467,9 +1476,10 @@  static void do_info_capture(Monitor *mon)
 }
 
 #ifdef HAS_AUDIO
-static void do_stop_capture(Monitor *mon, int n)
+static void do_stop_capture(Monitor *mon, const QDict *qdict)
 {
     int i;
+    int n = qdict_get_int(qdict, "n");
     CaptureState *s;
 
     for (s = capture_head.lh_first, i = 0; s; s = s->entries.le_next, ++i) {
@@ -1504,9 +1514,10 @@  static void do_wav_capture(Monitor *mon, const char *path,
 #endif
 
 #if defined(TARGET_I386)
-static void do_inject_nmi(Monitor *mon, int cpu_index)
+static void do_inject_nmi(Monitor *mon, const QDict *qdict)
 {
     CPUState *env;
+    int cpu_index = qdict_get_int(qdict, "cpu_index");
 
     for (env = first_cpu; env != NULL; env = env->next_cpu)
         if (env->cpu_index == cpu_index) {
@@ -1529,8 +1540,9 @@  static void do_info_status(Monitor *mon)
 }
 
 
-static void do_balloon(Monitor *mon, int value)
+static void do_balloon(Monitor *mon, const QDict *qdict)
 {
+    int value = qdict_get_int(qdict, "value");
     ram_addr_t target = value;
     qemu_balloon(target << 20);
 }
@@ -1559,8 +1571,9 @@  static qemu_acl *find_acl(Monitor *mon, const char *name)
     return acl;
 }
 
-static void do_acl_show(Monitor *mon, const char *aclname)
+static void do_acl_show(Monitor *mon, const QDict *qdict)
 {
+    const char *aclname = qdict_get_str(qdict, "aclname");
     qemu_acl *acl = find_acl(mon, aclname);
     qemu_acl_entry *entry;
     int i = 0;
@@ -1576,8 +1589,9 @@  static void do_acl_show(Monitor *mon, const char *aclname)
     }
 }
 
-static void do_acl_reset(Monitor *mon, const char *aclname)
+static void do_acl_reset(Monitor *mon, const QDict *qdict)
 {
+    const char *aclname = qdict_get_str(qdict, "aclname");
     qemu_acl *acl = find_acl(mon, aclname);
 
     if (acl) {
@@ -1669,8 +1683,9 @@  static void do_inject_mce(Monitor *mon,
 }
 #endif
 
-static void do_getfd(Monitor *mon, const char *fdname)
+static void do_getfd(Monitor *mon, const QDict *qdict)
 {
+    const char *fdname = qdict_get_str(qdict, "fdname");
     mon_fd_t *monfd;
     int fd;
 
@@ -1709,8 +1724,9 @@  static void do_getfd(Monitor *mon, const char *fdname)
     LIST_INSERT_HEAD(&mon->fds, monfd, next);
 }
 
-static void do_closefd(Monitor *mon, const char *fdname)
+static void do_closefd(Monitor *mon, const QDict *qdict)
 {
+    const char *fdname = qdict_get_str(qdict, "fdname");
     mon_fd_t *monfd;
 
     LIST_FOREACH(monfd, &mon->fds, next) {
@@ -2545,7 +2561,6 @@  static void monitor_handle_command(Monitor *mon, const char *cmdline)
     void *str_allocated[MAX_ARGS];
     void *args[MAX_ARGS];
     void (*handler_d)(Monitor *mon, const QDict *qdict);
-    void (*handler_1)(Monitor *mon, void *arg0);
     void (*handler_2)(Monitor *mon, void *arg0, void *arg1);
     void (*handler_3)(Monitor *mon, void *arg0, void *arg1, void *arg2);
     void (*handler_4)(Monitor *mon, void *arg0, void *arg1, void *arg2,
@@ -2837,13 +2852,10 @@  static void monitor_handle_command(Monitor *mon, const char *cmdline)
 
     switch(nb_args) {
     case 0:
+    case 1:
         handler_d = cmd->handler;
         handler_d(mon, qdict);
         break;
-    case 1:
-        handler_1 = cmd->handler;
-        handler_1(mon, args[0]);
-        break;
     case 2:
         handler_2 = cmd->handler;
         handler_2(mon, args[0], args[1]);
diff --git a/savevm.c b/savevm.c
index 69e6b53..2bee2d9 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1049,7 +1049,7 @@  static int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info,
     return ret;
 }
 
-void do_savevm(Monitor *mon, const char *name)
+void do_savevm(Monitor *mon, const QDict *qdict)
 {
     DriveInfo *dinfo;
     BlockDriverState *bs, *bs1;
@@ -1063,6 +1063,7 @@  void do_savevm(Monitor *mon, const char *name)
 #else
     struct timeval tv;
 #endif
+    const char *name = qdict_get_try_str(qdict, "name");
 
     bs = get_bs_snapshots();
     if (!bs) {
@@ -1218,16 +1219,17 @@  void qemu_loadvm(Monitor *mon, const char *name)
         vm_start();
 }
 
-void do_loadvm(Monitor *mon, const char *name)
+void do_loadvm(Monitor *mon, const QDict *qdict)
 {
-    qemu_loadvm(mon, name);
+    qemu_loadvm(mon, qdict_get_str(qdict, "name"));
 }
 
-void do_delvm(Monitor *mon, const char *name)
+void do_delvm(Monitor *mon, const QDict *qdict)
 {
     DriveInfo *dinfo;
     BlockDriverState *bs, *bs1;
     int ret;
+    const char *name = qdict_get_str(qdict, "name");
 
     bs = get_bs_snapshots();
     if (!bs) {
diff --git a/sysemu.h b/sysemu.h
index 23b22b2..7730703 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -5,6 +5,7 @@ 
 #include "qemu-common.h"
 #include "qemu-option.h"
 #include "sys-queue.h"
+#include "qdict.h"
 
 #ifdef _WIN32
 #include <windows.h>
@@ -50,10 +51,10 @@  int qemu_powerdown_requested(void);
 extern qemu_irq qemu_system_powerdown;
 void qemu_system_reset(void);
 
-void do_savevm(Monitor *mon, const char *name);
-void do_loadvm(Monitor *mon, const char *name);
+void do_savevm(Monitor *mon, const QDict *qdict);
+void do_loadvm(Monitor *mon, const QDict *qdict);
 void qemu_loadvm(Monitor *mon, const char *name);
-void do_delvm(Monitor *mon, const char *name);
+void do_delvm(Monitor *mon, const QDict *qdict);
 void do_info_snapshots(Monitor *mon);
 
 void qemu_announce_self(void);
@@ -210,8 +211,8 @@  void destroy_bdrvs(dev_match_fn *match_fn, void *arg);
 void pci_device_hot_add(Monitor *mon, const char *pci_addr, const char *type,
                         const char *opts);
 void drive_hot_add(Monitor *mon, const char *pci_addr, const char *opts);
-void do_pci_device_hot_remove(Monitor *mon, const char *pci_addr);
 void pci_device_hot_remove(Monitor *mon, const char *pci_addr);
+void do_pci_device_hot_remove(Monitor *mon, const QDict *qdict);
 void pci_device_hot_remove_success(int pcibus, int slot);
 
 /* serial ports */
@@ -267,8 +268,8 @@  struct soundhw {
 extern struct soundhw soundhw[];
 #endif
 
-void do_usb_add(Monitor *mon, const char *devname);
-void do_usb_del(Monitor *mon, const char *devname);
+void do_usb_add(Monitor *mon, const QDict *qdict);
+void do_usb_del(Monitor *mon, const QDict *qdict);
 void usb_info(Monitor *mon);
 
 void register_devices(void);
diff --git a/vl.c b/vl.c
index d1ffe04..43b1ebf 100644
--- a/vl.c
+++ b/vl.c
@@ -477,10 +477,11 @@  void do_info_mice(Monitor *mon)
     }
 }
 
-void do_mouse_set(Monitor *mon, int index)
+void do_mouse_set(Monitor *mon, const QDict *qdict)
 {
     QEMUPutMouseEntry *cursor;
     int i = 0;
+    int index = qdict_get_int(qdict, "index");
 
     if (!qemu_put_mouse_event_head) {
         monitor_printf(mon, "No mouse devices connected\n");
@@ -2523,14 +2524,14 @@  static int usb_parse(const char *cmdline)
     return usb_device_add(cmdline, 0);
 }
 
-void do_usb_add(Monitor *mon, const char *devname)
+void do_usb_add(Monitor *mon, const QDict *qdict)
 {
-    usb_device_add(devname, 1);
+    usb_device_add(qdict_get_str(qdict, "devname"), 1);
 }
 
-void do_usb_del(Monitor *mon, const char *devname)
+void do_usb_del(Monitor *mon, const QDict *qdict)
 {
-    usb_device_del(devname);
+    usb_device_del(qdict_get_str(qdict, "devname"));
 }
 
 void usb_info(Monitor *mon)