From patchwork Wed Oct 7 16:32:02 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 35319 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id AE5A1B7B7D for ; Thu, 8 Oct 2009 03:42:31 +1100 (EST) Received: from localhost ([127.0.0.1]:39040 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MvZas-0001zp-8U for incoming@patchwork.ozlabs.org; Wed, 07 Oct 2009 12:42:26 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MvZRX-0006yD-Hd for qemu-devel@nongnu.org; Wed, 07 Oct 2009 12:32:47 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MvZRS-0006vj-A4 for qemu-devel@nongnu.org; Wed, 07 Oct 2009 12:32:46 -0400 Received: from [199.232.76.173] (port=48036 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MvZRR-0006vD-GG for qemu-devel@nongnu.org; Wed, 07 Oct 2009 12:32:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43481) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MvZRQ-0003tK-Rz for qemu-devel@nongnu.org; Wed, 07 Oct 2009 12:32:41 -0400 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n97GWe7a016238; Wed, 7 Oct 2009 12:32:40 -0400 Received: from localhost (vpn-12-190.rdu.redhat.com [10.11.12.190]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n97GWcDP029900; Wed, 7 Oct 2009 12:32:39 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Wed, 7 Oct 2009 13:32:02 -0300 Message-Id: <1254933135-21888-6-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1254933135-21888-1-git-send-email-lcapitulino@redhat.com> References: <1254933135-21888-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: aliguori@us.ibm.com, avi@redhat.com Subject: [Qemu-devel] [PATCH 05/18] monitor: union for info handlers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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,