qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Luiz Capitulino <lcapitulino@redhat.com>
To: qemu-devel@nongnu.org
Cc: aliguori@us.ibm.com, avi@redhat.com
Subject: [Qemu-devel] [PATCH 05/18] monitor: union for info handlers
Date: Wed,  7 Oct 2009 13:41:51 -0300	[thread overview]
Message-ID: <1254933724-22485-6-git-send-email-lcapitulino@redhat.com> (raw)
In-Reply-To: <1254933724-22485-1-git-send-email-lcapitulino@redhat.com>

This commit adds a union to mon_cmd_t for info handlers and
converts do_info() and info_cmds[] array to use it.

This improves type safety.

Next commit will convert command handlers.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 monitor.c |   77 +++++++++++++++++++++++++++++++------------------------------
 1 files changed, 39 insertions(+), 38 deletions(-)

diff --git a/monitor.c b/monitor.c
index ae0354a..c0569d5 100644
--- a/monitor.c
+++ b/monitor.c
@@ -74,6 +74,9 @@ typedef struct mon_cmd_t {
     void *handler;
     const char *params;
     const char *help;
+    union {
+        void (*info)(Monitor *mon);
+    } mhandler;
 } mon_cmd_t;
 
 /* file descriptors passed via SCM_RIGHTS */
@@ -283,7 +286,6 @@ 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)
         goto help;
@@ -295,8 +297,7 @@ static void do_info(Monitor *mon, const QDict *qdict)
     help_cmd(mon, "info");
     return;
  found:
-    handler = cmd->handler;
-    handler(mon);
+    cmd->mhandler.info(mon);
 }
 
 static void do_info_version(Monitor *mon)
@@ -1816,255 +1817,255 @@ static const mon_cmd_t info_cmds[] = {
     {
         .name       = "version",
         .args_type  = "",
-        .handler    = do_info_version,
         .params     = "",
         .help       = "show the version of QEMU",
+        .mhandler.info = do_info_version,
     },
     {
         .name       = "network",
         .args_type  = "",
-        .handler    = do_info_network,
         .params     = "",
         .help       = "show the network state",
+        .mhandler.info = do_info_network,
     },
     {
         .name       = "chardev",
         .args_type  = "",
-        .handler    = qemu_chr_info,
         .params     = "",
         .help       = "show the character devices",
+        .mhandler.info = qemu_chr_info,
     },
     {
         .name       = "block",
         .args_type  = "",
-        .handler    = bdrv_info,
         .params     = "",
         .help       = "show the block devices",
+        .mhandler.info = bdrv_info,
     },
     {
         .name       = "blockstats",
         .args_type  = "",
-        .handler    = bdrv_info_stats,
         .params     = "",
         .help       = "show block device statistics",
+        .mhandler.info = bdrv_info_stats,
     },
     {
         .name       = "registers",
         .args_type  = "",
-        .handler    = do_info_registers,
         .params     = "",
         .help       = "show the cpu registers",
+        .mhandler.info = do_info_registers,
     },
     {
         .name       = "cpus",
         .args_type  = "",
-        .handler    = do_info_cpus,
         .params     = "",
         .help       = "show infos for each CPU",
+        .mhandler.info = do_info_cpus,
     },
     {
         .name       = "history",
         .args_type  = "",
-        .handler    = do_info_history,
         .params     = "",
         .help       = "show the command line history",
+        .mhandler.info = do_info_history,
     },
     {
         .name       = "irq",
         .args_type  = "",
-        .handler    = irq_info,
         .params     = "",
         .help       = "show the interrupts statistics (if available)",
+        .mhandler.info = irq_info,
     },
     {
         .name       = "pic",
         .args_type  = "",
-        .handler    = pic_info,
         .params     = "",
         .help       = "show i8259 (PIC) state",
+        .mhandler.info = pic_info,
     },
     {
         .name       = "pci",
         .args_type  = "",
-        .handler    = pci_info,
         .params     = "",
         .help       = "show PCI info",
+        .mhandler.info = pci_info,
     },
 #if defined(TARGET_I386) || defined(TARGET_SH4)
     {
         .name       = "tlb",
         .args_type  = "",
-        .handler    = tlb_info,
         .params     = "",
         .help       = "show virtual to physical memory mappings",
+        .mhandler.info = tlb_info,
     },
 #endif
 #if defined(TARGET_I386)
     {
         .name       = "mem",
         .args_type  = "",
-        .handler    = mem_info,
         .params     = "",
         .help       = "show the active virtual memory mappings",
+        .mhandler.info = mem_info,
     },
     {
         .name       = "hpet",
         .args_type  = "",
-        .handler    = do_info_hpet,
         .params     = "",
         .help       = "show state of HPET",
+        .mhandler.info = do_info_hpet,
     },
 #endif
     {
         .name       = "jit",
         .args_type  = "",
-        .handler    = do_info_jit,
         .params     = "",
         .help       = "show dynamic compiler info",
+        .mhandler.info = do_info_jit,
     },
     {
         .name       = "kvm",
         .args_type  = "",
-        .handler    = do_info_kvm,
         .params     = "",
         .help       = "show KVM information",
+        .mhandler.info = do_info_kvm,
     },
     {
         .name       = "numa",
         .args_type  = "",
-        .handler    = do_info_numa,
         .params     = "",
         .help       = "show NUMA information",
+        .mhandler.info = do_info_numa,
     },
     {
         .name       = "usb",
         .args_type  = "",
-        .handler    = usb_info,
         .params     = "",
         .help       = "show guest USB devices",
+        .mhandler.info = usb_info,
     },
     {
         .name       = "usbhost",
         .args_type  = "",
-        .handler    = usb_host_info,
         .params     = "",
         .help       = "show host USB devices",
+        .mhandler.info = usb_host_info,
     },
     {
         .name       = "profile",
         .args_type  = "",
-        .handler    = do_info_profile,
         .params     = "",
         .help       = "show profiling information",
+        .mhandler.info = do_info_profile,
     },
     {
         .name       = "capture",
         .args_type  = "",
-        .handler    = do_info_capture,
         .params     = "",
         .help       = "show capture information",
+        .mhandler.info = do_info_capture,
     },
     {
         .name       = "snapshots",
         .args_type  = "",
-        .handler    = do_info_snapshots,
         .params     = "",
         .help       = "show the currently saved VM snapshots",
+        .mhandler.info = do_info_snapshots,
     },
     {
         .name       = "status",
         .args_type  = "",
-        .handler    = do_info_status,
         .params     = "",
         .help       = "show the current VM status (running|paused)",
+        .mhandler.info = do_info_status,
     },
     {
         .name       = "pcmcia",
         .args_type  = "",
-        .handler    = pcmcia_info,
         .params     = "",
         .help       = "show guest PCMCIA status",
+        .mhandler.info = pcmcia_info,
     },
     {
         .name       = "mice",
         .args_type  = "",
-        .handler    = do_info_mice,
         .params     = "",
         .help       = "show which guest mouse is receiving events",
+        .mhandler.info = do_info_mice,
     },
     {
         .name       = "vnc",
         .args_type  = "",
-        .handler    = do_info_vnc,
         .params     = "",
         .help       = "show the vnc server status",
+        .mhandler.info = do_info_vnc,
     },
     {
         .name       = "name",
         .args_type  = "",
-        .handler    = do_info_name,
         .params     = "",
         .help       = "show the current VM name",
+        .mhandler.info = do_info_name,
     },
     {
         .name       = "uuid",
         .args_type  = "",
-        .handler    = do_info_uuid,
         .params     = "",
         .help       = "show the current VM UUID",
+        .mhandler.info = do_info_uuid,
     },
 #if defined(TARGET_PPC)
     {
         .name       = "cpustats",
         .args_type  = "",
-        .handler    = do_info_cpu_stats,
         .params     = "",
         .help       = "show CPU statistics",
+        .mhandler.info = do_info_cpu_stats,
     },
 #endif
 #if defined(CONFIG_SLIRP)
     {
         .name       = "usernet",
         .args_type  = "",
-        .handler    = do_info_usernet,
         .params     = "",
         .help       = "show user network stack connection states",
+        .mhandler.info = do_info_usernet,
     },
 #endif
     {
         .name       = "migrate",
         .args_type  = "",
-        .handler    = do_info_migrate,
         .params     = "",
         .help       = "show migration status",
+        .mhandler.info = do_info_migrate,
     },
     {
         .name       = "balloon",
         .args_type  = "",
-        .handler    = do_info_balloon,
         .params     = "",
         .help       = "show balloon information",
+        .mhandler.info = do_info_balloon,
     },
     {
         .name       = "qtree",
         .args_type  = "",
-        .handler    = do_info_qtree,
         .params     = "",
         .help       = "show device tree",
+        .mhandler.info = do_info_qtree,
     },
     {
         .name       = "qdm",
         .args_type  = "",
-        .handler    = do_info_qdm,
         .params     = "",
         .help       = "show qdev device model list",
+        .mhandler.info = do_info_qdm,
     },
     {
         .name       = "roms",
         .args_type  = "",
-        .handler    = do_info_roms,
         .params     = "",
         .help       = "show roms",
+        .mhandler.info = do_info_roms,
     },
     {
         .name       = NULL,
-- 
1.6.5.rc2.17.gdbc1b

  parent reply	other threads:[~2009-10-07 16:42 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-07 16:41 [Qemu-devel] [RESEND v3 00/18]: Initial QObject conversion Luiz Capitulino
2009-10-07 16:41 ` [Qemu-devel] [PATCH 01/18] QObject: Accept NULL Luiz Capitulino
2009-10-07 16:41 ` [Qemu-devel] [PATCH 02/18] Introduce QList Luiz Capitulino
2009-10-07 16:41 ` [Qemu-devel] [PATCH 03/18] Introduce QList unit-tests Luiz Capitulino
2009-10-07 16:41 ` [Qemu-devel] [PATCH 04/18] monitor: Convert mon_cmd_t initializations to C99 style Luiz Capitulino
2009-10-07 16:41 ` Luiz Capitulino [this message]
2009-10-07 16:41 ` [Qemu-devel] [PATCH 06/18] monitor: union for command handlers Luiz Capitulino
2009-10-07 16:41 ` [Qemu-devel] [PATCH 07/18] monitor: Add user_print() to mon_cmd_t Luiz Capitulino
2009-10-07 16:41 ` [Qemu-devel] [PATCH 08/18] monitor: Handle new and old style handlers Luiz Capitulino
2009-10-07 16:41 ` [Qemu-devel] [PATCH 09/18] monitor: do_info(): handle new and old info handlers Luiz Capitulino
2009-10-07 16:41 ` [Qemu-devel] [PATCH 10/18] monitor: Convert do_quit() do QObject Luiz Capitulino
2009-10-07 16:41 ` [Qemu-devel] [PATCH 11/18] monitor: Convert do_stop() to QObject Luiz Capitulino
2009-10-07 16:41 ` [Qemu-devel] [PATCH 12/18] monitor: Convert do_system_reset() " Luiz Capitulino
2009-10-07 16:41 ` [Qemu-devel] [PATCH 13/18] monitor: Convert do_system_powerdown() " Luiz Capitulino
2009-10-07 16:42 ` [Qemu-devel] [PATCH 14/18] monitor: Convert do_cont() " Luiz Capitulino
2009-10-07 16:42 ` [Qemu-devel] [PATCH 15/18] monitor: Convert do_balloon() " Luiz Capitulino
2009-10-07 16:42 ` [Qemu-devel] [PATCH 16/18] monitor: Convert do_info_version() " Luiz Capitulino
2009-10-07 16:42 ` [Qemu-devel] [PATCH 17/18] monitor: Convert do_info_balloon() " Luiz Capitulino
2009-10-07 16:42 ` [Qemu-devel] [PATCH 18/18] monitor: Convert do_info_cpus() " Luiz Capitulino
  -- strict thread matches above, loose matches on Subject: below --
2009-10-07 16:31 [Qemu-devel] [PATCH v3 00/18]: Initial QObject conversion Luiz Capitulino
2009-10-07 16:32 ` [Qemu-devel] [PATCH 05/18] monitor: union for info handlers Luiz Capitulino

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1254933724-22485-6-git-send-email-lcapitulino@redhat.com \
    --to=lcapitulino@redhat.com \
    --cc=aliguori@us.ibm.com \
    --cc=avi@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).