qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Benoît Canet" <benoit.canet@nodalink.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, pbonzini@redhat.com,
	"Benoît Canet" <benoit.canet@nodalink.com>,
	stefanha@redhat.com
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	[thread overview]
Message-ID: <1408109759-1100-11-git-send-email-benoit.canet@nodalink.com> (raw)
In-Reply-To: <1408109759-1100-1-git-send-email-benoit.canet@nodalink.com>

The extracted function are help_cmd, do_help_cmd, do_trace_event_set_state,
and do_trace_file.

Signed-off-by: Benoît Canet <benoit.canet@nodalink.com>
---
 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);
+}
+
+/* @args[@arg_index] 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);
-}
-
-/* @args[@arg_index] 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

  parent reply	other threads:[~2014-08-15 13:37 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-15 13:35 [Qemu-devel] [PATCH v2 00/26] Extract qmp.c and monitor.c core and wire QMP into qemu-nbd Benoît Canet
2014-08-15 13:35 ` [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 13:35 ` [Qemu-devel] [PATCH v2 02/26] monitor: Make some function public Benoît Canet
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 03/26] monitor: Convert Monitor reset_seen field too boolean Benoît Canet
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 04/26] monitor: Convert mon_cmd_t to MonitorCommand Benoît Canet
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 05/26] monitor: Extract monitor-system.h header Benoît Canet
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 06/26] monitor: Make monitor_fprintf public before extracting it Benoît Canet
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 07/26] monitor: Extract monitor_fprintf to monitor-system.c Benoît Canet
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 08/26] monitor: Extract qmp_human_monitor_command into monitor-system.c Benoît Canet
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 09/26] monitor: Make some function to extract public Benoît Canet
2014-08-15 13:35 ` Benoît Canet [this message]
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 11/26] monitor: Make do_info_help public Benoît Canet
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 12/26] monitor: Extract do_info_help in monitor-system.c Benoît Canet
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 13/26] monitor: Make some monitor functions public before moving them " Benoît Canet
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 14/26] monitor: Make do_loadvm public before moving it to monitor-system.c Benoît Canet
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 15/26] monitor: Move do_loadvm from monitor.c " Benoît Canet
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 16/26] monitor: Make commands public before moving them " Benoît Canet
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 17/26] monitor: Move MonitorCommand arrays and some function from monitor.c " Benoît Canet
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 18/26] monitor: Move more functions " Benoît Canet
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 19/26] monitor: Move two net " Benoît Canet
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 20/26] monitor: Move qmp_rtc_reset_reinjection " Benoît Canet
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 21/26] monitor-system: Switch back functions to static Benoît Canet
2014-08-15 13:35 ` [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 13:35 ` [Qemu-devel] [PATCH v2 23/26] monitor: Cleanup monitor.c includes after extracting monitor-system.c Benoît Canet
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 24/26] qemu-nbd: build QAPI block core into qemu-nbd Benoît Canet
2014-08-15 13:35 ` [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 13:35 ` [Qemu-devel] [PATCH v2 26/26] qemu-nbd: Add --qmp option to qemu-nbd Benoît Canet

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=1408109759-1100-11-git-send-email-benoit.canet@nodalink.com \
    --to=benoit.canet@nodalink.com \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /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).