monitor: union for info handlers

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.

Patchworks-ID: 35336
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
Luiz Capitulino 2009-10-07 13:41:51 -03:00 committed by Anthony Liguori
parent d7f9b68971
commit 910df89d87

View File

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