Received: from eggs.gnu.org ([2001:4830:134:3::10]:33478) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XD5OB-0007qB-MO for qemu-devel@nongnu.org; Fri, 01 Aug 2014 01:28:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XD5O1-0003cg-MX for qemu-devel@nongnu.org; Fri, 01 Aug 2014 01:28:23 -0400 Received: from lputeaux-656-01-25-125.w80-12.abo.wanadoo.fr ([80.12.84.125]:59401 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XD5O1-0003bz-Gm for qemu-devel@nongnu.org; Fri, 01 Aug 2014 01:28:13 -0400 From: =?UTF-8?q?Beno=C3=AEt=20Canet?= Date: Fri, 1 Aug 2014 07:27:04 +0200 Message-Id: <1406870842-17988-7-git-send-email-benoit.canet@irqsave.net> In-Reply-To: <1406870842-17988-1-git-send-email-benoit.canet@irqsave.net> References: <1406870842-17988-1-git-send-email-benoit.canet@irqsave.net> Subject: [Qemu-devel] [PATCH v1 06/24] monitor: Extract qmp_human_monitor_command into monitor-system.c List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, =?UTF-8?q?Beno=C3=AEt=20Canet?= , Benoit Canet , mreitz@redhat.com, stefanha@redhat.com Signed-off-by: Benoit Canet --- 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 a31d1d0..30d8eda 100644 --- a/monitor.c +++ b/monitor.c @@ -551,50 +551,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.0.1