qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH v2 08/26] monitor: Extract qmp_human_monitor_command


From: Benoît Canet
Subject: [Qemu-devel] [PATCH v2 08/26] monitor: Extract qmp_human_monitor_command into monitor-system.c
Date: Fri, 15 Aug 2014 15:35:40 +0200

Signed-off-by: Benoît Canet <address@hidden>
---
 monitor-system.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 monitor.c        | 44 --------------------------------------------
 2 files changed, 43 insertions(+), 44 deletions(-)

diff --git a/monitor-system.c b/monitor-system.c
index 51ca21f..90758db 100644
--- a/monitor-system.c
+++ b/monitor-system.c
@@ -67,3 +67,46 @@ int GCC_FMT_ATTR(2, 3) monitor_fprintf(FILE *stream,
     return 0;
 }
 
+static void monitor_data_destroy(Monitor *mon)
+{
+    QDECREF(mon->outbuf);
+    qemu_mutex_destroy(&mon->out_lock);
+}
+
+char *qmp_human_monitor_command(const char *command_line, bool has_cpu_index,
+                                int64_t cpu_index, Error **errp)
+{
+    char *output = NULL;
+    Monitor *old_mon, hmp;
+
+    monitor_data_init(&hmp);
+    hmp.skip_flush = true;
+
+    old_mon = cur_mon;
+    cur_mon = &hmp;
+
+    if (has_cpu_index) {
+        int ret = monitor_set_cpu(cpu_index);
+        if (ret < 0) {
+            cur_mon = old_mon;
+            error_set(errp, QERR_INVALID_PARAMETER_VALUE, "cpu-index",
+                      "a CPU number");
+            goto out;
+        }
+    }
+
+    handle_user_command(&hmp, command_line);
+    cur_mon = old_mon;
+
+    qemu_mutex_lock(&hmp.out_lock);
+    if (qstring_get_length(hmp.outbuf) > 0) {
+        output = g_strdup(qstring_get_str(hmp.outbuf));
+    } else {
+        output = g_strdup("");
+    }
+    qemu_mutex_unlock(&hmp.out_lock);
+
+out:
+    monitor_data_destroy(&hmp);
+    return output;
+}
diff --git a/monitor.c b/monitor.c
index 24f4a53..106efb5 100644
--- a/monitor.c
+++ b/monitor.c
@@ -552,50 +552,6 @@ void monitor_data_init(Monitor *mon)
     mon->cmd_table = mon_cmds;
 }
 
-static void monitor_data_destroy(Monitor *mon)
-{
-    QDECREF(mon->outbuf);
-    qemu_mutex_destroy(&mon->out_lock);
-}
-
-char *qmp_human_monitor_command(const char *command_line, bool has_cpu_index,
-                                int64_t cpu_index, Error **errp)
-{
-    char *output = NULL;
-    Monitor *old_mon, hmp;
-
-    monitor_data_init(&hmp);
-    hmp.skip_flush = true;
-
-    old_mon = cur_mon;
-    cur_mon = &hmp;
-
-    if (has_cpu_index) {
-        int ret = monitor_set_cpu(cpu_index);
-        if (ret < 0) {
-            cur_mon = old_mon;
-            error_set(errp, QERR_INVALID_PARAMETER_VALUE, "cpu-index",
-                      "a CPU number");
-            goto out;
-        }
-    }
-
-    handle_user_command(&hmp, command_line);
-    cur_mon = old_mon;
-
-    qemu_mutex_lock(&hmp.out_lock);
-    if (qstring_get_length(hmp.outbuf) > 0) {
-        output = g_strdup(qstring_get_str(hmp.outbuf));
-    } else {
-        output = g_strdup("");
-    }
-    qemu_mutex_unlock(&hmp.out_lock);
-
-out:
-    monitor_data_destroy(&hmp);
-    return output;
-}
-
 int compare_cmd(const char *name, const char *list)
 {
     const char *p, *pstart;
-- 
2.1.0.rc1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]