[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 10/26] monitor: Extract a couple of function to m
From: |
Benoît Canet |
Subject: |
[Qemu-devel] [PATCH v2 10/26] monitor: Extract a couple of function to monitor-system.c |
Date: |
Fri, 15 Aug 2014 15:35:42 +0200 |
The extracted function are help_cmd, do_help_cmd, do_trace_event_set_state,
and do_trace_file.
Signed-off-by: Benoît Canet <address@hidden>
---
monitor-system.c | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
monitor.c | 121 -------------------------------------------------------
2 files changed, 121 insertions(+), 121 deletions(-)
diff --git a/monitor-system.c b/monitor-system.c
index 90758db..e725a42 100644
--- a/monitor-system.c
+++ b/monitor-system.c
@@ -110,3 +110,124 @@ out:
monitor_data_destroy(&hmp);
return output;
}
+
+static void help_cmd_dump_one(Monitor *mon,
+ const MonitorCommand *cmd,
+ char **prefix_args,
+ int prefix_args_nb)
+{
+ int i;
+
+ for (i = 0; i < prefix_args_nb; i++) {
+ monitor_printf(mon, "%s ", prefix_args[i]);
+ }
+ monitor_printf(mon, "%s %s -- %s\n", cmd->name, cmd->params, cmd->help);
+}
+
+/* @address@hidden is the valid command need to find in @cmds */
+static void help_cmd_dump(Monitor *mon, const MonitorCommand *cmds,
+ char **args, int nb_args, int arg_index)
+{
+ const MonitorCommand *cmd;
+
+ /* No valid arg need to compare with, dump all in *cmds */
+ if (arg_index >= nb_args) {
+ for (cmd = cmds; cmd->name != NULL; cmd++) {
+ help_cmd_dump_one(mon, cmd, args, arg_index);
+ }
+ return;
+ }
+
+ /* Find one entry to dump */
+ for (cmd = cmds; cmd->name != NULL; cmd++) {
+ if (compare_cmd(args[arg_index], cmd->name)) {
+ if (cmd->sub_table) {
+ /* continue with next arg */
+ help_cmd_dump(mon, cmd->sub_table,
+ args, nb_args, arg_index + 1);
+ } else {
+ help_cmd_dump_one(mon, cmd, args, arg_index);
+ }
+ break;
+ }
+ }
+}
+
+void help_cmd(Monitor *mon, const char *name)
+{
+ char *args[MAX_ARGS];
+ int nb_args = 0;
+
+ /* 1. parse user input */
+ if (name) {
+ /* special case for log, directly dump and return */
+ if (!strcmp(name, "log")) {
+ const QEMULogItem *item;
+ monitor_printf(mon, "Log items (comma separated):\n");
+ monitor_printf(mon, "%-10s %s\n", "none", "remove all logs");
+ for (item = qemu_log_items; item->mask != 0; item++) {
+ monitor_printf(mon, "%-10s %s\n", item->name, item->help);
+ }
+ return;
+ }
+
+ if (parse_cmdline(name, &nb_args, args) < 0) {
+ return;
+ }
+ }
+
+ /* 2. dump the contents according to parsed args */
+ help_cmd_dump(mon, mon->cmd_table, args, nb_args, 0);
+
+ free_cmdline_args(args, nb_args);
+}
+
+void do_help_cmd(Monitor *mon, const QDict *qdict)
+{
+ help_cmd(mon, qdict_get_try_str(qdict, "name"));
+}
+
+void do_trace_event_set_state(Monitor *mon, const QDict *qdict)
+{
+ const char *tp_name = qdict_get_str(qdict, "name");
+ bool new_state = qdict_get_bool(qdict, "option");
+
+ bool found = false;
+ TraceEvent *ev = NULL;
+ while ((ev = trace_event_pattern(tp_name, ev)) != NULL) {
+ found = true;
+ if (!trace_event_get_state_static(ev)) {
+ monitor_printf(mon, "event \"%s\" is not traceable\n", tp_name);
+ } else {
+ trace_event_set_state_dynamic(ev, new_state);
+ }
+ }
+ if (!trace_event_is_pattern(tp_name) && !found) {
+ monitor_printf(mon, "unknown event name \"%s\"\n", tp_name);
+ }
+}
+
+#ifdef CONFIG_TRACE_SIMPLE
+void do_trace_file(Monitor *mon, const QDict *qdict)
+{
+ const char *op = qdict_get_try_str(qdict, "op");
+ const char *arg = qdict_get_try_str(qdict, "arg");
+
+ if (!op) {
+ st_print_trace_file_status((FILE *)mon, &monitor_fprintf);
+ } else if (!strcmp(op, "on")) {
+ st_set_trace_file_enabled(true);
+ } else if (!strcmp(op, "off")) {
+ st_set_trace_file_enabled(false);
+ } else if (!strcmp(op, "flush")) {
+ st_flush_trace_buffer();
+ } else if (!strcmp(op, "set")) {
+ if (arg) {
+ st_set_trace_file(arg);
+ }
+ } else {
+ monitor_printf(mon, "unexpected argument \"%s\"\n", op);
+ help_cmd(mon, "trace-file");
+ }
+}
+#endif
diff --git a/monitor.c b/monitor.c
index 12ec622..a807ff9 100644
--- a/monitor.c
+++ b/monitor.c
@@ -698,127 +698,6 @@ int parse_cmdline(const char *cmdline, int *pnb_args,
char **args)
return -1;
}
-static void help_cmd_dump_one(Monitor *mon,
- const MonitorCommand *cmd,
- char **prefix_args,
- int prefix_args_nb)
-{
- int i;
-
- for (i = 0; i < prefix_args_nb; i++) {
- monitor_printf(mon, "%s ", prefix_args[i]);
- }
- monitor_printf(mon, "%s %s -- %s\n", cmd->name, cmd->params, cmd->help);
-}
-
-/* @address@hidden is the valid command need to find in @cmds */
-static void help_cmd_dump(Monitor *mon, const MonitorCommand *cmds,
- char **args, int nb_args, int arg_index)
-{
- const MonitorCommand *cmd;
-
- /* No valid arg need to compare with, dump all in *cmds */
- if (arg_index >= nb_args) {
- for (cmd = cmds; cmd->name != NULL; cmd++) {
- help_cmd_dump_one(mon, cmd, args, arg_index);
- }
- return;
- }
-
- /* Find one entry to dump */
- for (cmd = cmds; cmd->name != NULL; cmd++) {
- if (compare_cmd(args[arg_index], cmd->name)) {
- if (cmd->sub_table) {
- /* continue with next arg */
- help_cmd_dump(mon, cmd->sub_table,
- args, nb_args, arg_index + 1);
- } else {
- help_cmd_dump_one(mon, cmd, args, arg_index);
- }
- break;
- }
- }
-}
-
-void help_cmd(Monitor *mon, const char *name)
-{
- char *args[MAX_ARGS];
- int nb_args = 0;
-
- /* 1. parse user input */
- if (name) {
- /* special case for log, directly dump and return */
- if (!strcmp(name, "log")) {
- const QEMULogItem *item;
- monitor_printf(mon, "Log items (comma separated):\n");
- monitor_printf(mon, "%-10s %s\n", "none", "remove all logs");
- for (item = qemu_log_items; item->mask != 0; item++) {
- monitor_printf(mon, "%-10s %s\n", item->name, item->help);
- }
- return;
- }
-
- if (parse_cmdline(name, &nb_args, args) < 0) {
- return;
- }
- }
-
- /* 2. dump the contents according to parsed args */
- help_cmd_dump(mon, mon->cmd_table, args, nb_args, 0);
-
- free_cmdline_args(args, nb_args);
-}
-
-void do_help_cmd(Monitor *mon, const QDict *qdict)
-{
- help_cmd(mon, qdict_get_try_str(qdict, "name"));
-}
-
-void do_trace_event_set_state(Monitor *mon, const QDict *qdict)
-{
- const char *tp_name = qdict_get_str(qdict, "name");
- bool new_state = qdict_get_bool(qdict, "option");
-
- bool found = false;
- TraceEvent *ev = NULL;
- while ((ev = trace_event_pattern(tp_name, ev)) != NULL) {
- found = true;
- if (!trace_event_get_state_static(ev)) {
- monitor_printf(mon, "event \"%s\" is not traceable\n", tp_name);
- } else {
- trace_event_set_state_dynamic(ev, new_state);
- }
- }
- if (!trace_event_is_pattern(tp_name) && !found) {
- monitor_printf(mon, "unknown event name \"%s\"\n", tp_name);
- }
-}
-
-#ifdef CONFIG_TRACE_SIMPLE
-void do_trace_file(Monitor *mon, const QDict *qdict)
-{
- const char *op = qdict_get_try_str(qdict, "op");
- const char *arg = qdict_get_try_str(qdict, "arg");
-
- if (!op) {
- st_print_trace_file_status((FILE *)mon, &monitor_fprintf);
- } else if (!strcmp(op, "on")) {
- st_set_trace_file_enabled(true);
- } else if (!strcmp(op, "off")) {
- st_set_trace_file_enabled(false);
- } else if (!strcmp(op, "flush")) {
- st_flush_trace_buffer();
- } else if (!strcmp(op, "set")) {
- if (arg) {
- st_set_trace_file(arg);
- }
- } else {
- monitor_printf(mon, "unexpected argument \"%s\"\n", op);
- help_cmd(mon, "trace-file");
- }
-}
-#endif
-
static void user_monitor_complete(void *opaque, QObject *ret_data)
{
MonitorCompletionData *data = (MonitorCompletionData *)opaque;
--
2.1.0.rc1
- [Qemu-devel] [PATCH v2 06/26] monitor: Make monitor_fprintf public before extracting it, (continued)
- [Qemu-devel] [PATCH v2 06/26] monitor: Make monitor_fprintf public before extracting it, Benoît Canet, 2014/08/15
- [Qemu-devel] [PATCH v2 01/26] qmp: Extract system emulation related code from qmp.c into qmp-system.c, Benoît Canet, 2014/08/15
- [Qemu-devel] [PATCH v2 11/26] monitor: Make do_info_help public, Benoît Canet, 2014/08/15
- [Qemu-devel] [PATCH v2 07/26] monitor: Extract monitor_fprintf to monitor-system.c, Benoît Canet, 2014/08/15
- [Qemu-devel] [PATCH v2 12/26] monitor: Extract do_info_help in monitor-system.c, Benoît Canet, 2014/08/15
- [Qemu-devel] [PATCH v2 02/26] monitor: Make some function public, Benoît Canet, 2014/08/15
- [Qemu-devel] [PATCH v2 08/26] monitor: Extract qmp_human_monitor_command into monitor-system.c, Benoît Canet, 2014/08/15
- [Qemu-devel] [PATCH v2 24/26] qemu-nbd: build QAPI block core into qemu-nbd, Benoît Canet, 2014/08/15
- [Qemu-devel] [PATCH v2 05/26] monitor: Extract monitor-system.h header, Benoît Canet, 2014/08/15
- [Qemu-devel] [PATCH v2 20/26] monitor: Move qmp_rtc_reset_reinjection from monitor.c to monitor-system.c, Benoît Canet, 2014/08/15
- [Qemu-devel] [PATCH v2 10/26] monitor: Extract a couple of function to monitor-system.c,
Benoît Canet <=
- [Qemu-devel] [PATCH v2 22/26] monitor: Extract hardware dependent completion function from monitor.c to monitor-system.c, Benoît Canet, 2014/08/15
- [Qemu-devel] [PATCH v2 09/26] monitor: Make some function to extract public, Benoît Canet, 2014/08/15
- [Qemu-devel] [PATCH v2 19/26] monitor: Move two net functions from monitor.c to monitor-system.c, Benoît Canet, 2014/08/15
- [Qemu-devel] [PATCH v2 15/26] monitor: Move do_loadvm from monitor.c to monitor-system.c, Benoît Canet, 2014/08/15
- [Qemu-devel] [PATCH v2 26/26] qemu-nbd: Add --qmp option to qemu-nbd., Benoît Canet, 2014/08/15
- [Qemu-devel] [PATCH v2 18/26] monitor: Move more functions from monitor.c to monitor-system.c, Benoît Canet, 2014/08/15
- [Qemu-devel] [PATCH v2 23/26] monitor: Cleanup monitor.c includes after extracting monitor-system.c, Benoît Canet, 2014/08/15
- [Qemu-devel] [PATCH v2 14/26] monitor: Make do_loadvm public before moving it to monitor-system.c, Benoît Canet, 2014/08/15
- [Qemu-devel] [PATCH v2 25/26] qapi: Add a script to filter qmp-commands-old.h to generate a subset of it., Benoît Canet, 2014/08/15
- [Qemu-devel] [PATCH v2 16/26] monitor: Make commands public before moving them to monitor-system.c, Benoît Canet, 2014/08/15