From patchwork Fri Nov 27 00:58:58 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 39599 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 72C341007D1 for ; Fri, 27 Nov 2009 12:13:19 +1100 (EST) Received: from localhost ([127.0.0.1]:53326 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NDpOe-0000UR-3L for incoming@patchwork.ozlabs.org; Thu, 26 Nov 2009 20:13:16 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NDpBY-0001gj-7Q for qemu-devel@nongnu.org; Thu, 26 Nov 2009 19:59:44 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NDpBT-0001eJ-PA for qemu-devel@nongnu.org; Thu, 26 Nov 2009 19:59:43 -0500 Received: from [199.232.76.173] (port=48294 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NDpBT-0001eB-B5 for qemu-devel@nongnu.org; Thu, 26 Nov 2009 19:59:39 -0500 Received: from mx1.redhat.com ([209.132.183.28]:3273) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NDpBS-0004QR-Ko for qemu-devel@nongnu.org; Thu, 26 Nov 2009 19:59:39 -0500 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nAR0xbHB024351 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 26 Nov 2009 19:59:37 -0500 Received: from localhost (vpn-10-232.rdu.redhat.com [10.11.10.232]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nAR0xaYP024950; Thu, 26 Nov 2009 19:59:36 -0500 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Thu, 26 Nov 2009 22:58:58 -0200 Message-Id: <1259283550-3597-9-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1259283550-3597-1-git-send-email-lcapitulino@redhat.com> References: <1259283550-3597-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: aliguori@us.ibm.com, avi@redhat.com, armbru@redhat.com Subject: [Qemu-devel] [PATCH 08/20] QMP: Initial support X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This commit adds initial QMP support in QEMU. It's important to notice that most QMP code will be part of the Monitor. Input will be read by monitor_control_read(). Currently it does nothing but next patches will add proper input support. The function monitor_json_emitter(), as its name implies, is used by the Monitor to emit JSON output. In this commit it's used by monitor_control_event() to print our greeting message. Finally, control mode support is also added to monitor_init(), allowing QMP to be really enabled. Signed-off-by: Luiz Capitulino --- monitor.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 51 insertions(+), 2 deletions(-) diff --git a/monitor.c b/monitor.c index 02dea2e..c333b7a 100644 --- a/monitor.c +++ b/monitor.c @@ -50,6 +50,7 @@ #include "qdict.h" #include "qstring.h" #include "qerror.h" +#include "qjson.h" //#define DEBUG //#define DEBUG_COMPLETION @@ -255,6 +256,17 @@ static void monitor_print_qobject(Monitor *mon, const QObject *data) monitor_puts(mon, "\n"); } +static void monitor_json_emitter(Monitor *mon, const QObject *data) +{ + QString *json; + + json = qobject_to_json(data); + assert(json != NULL); + + monitor_printf(mon, "%s\n", qstring_get_str(json)); + QDECREF(json); +} + static int compare_cmd(const char *name, const char *list) { const char *p, *pstart; @@ -3579,6 +3591,20 @@ static int monitor_can_read(void *opaque) return (mon->suspend_cnt == 0) ? 128 : 0; } +/** + * monitor_control_read(): Read and handle QMP input + */ +static void monitor_control_read(void *opaque, const uint8_t *buf, int size) +{ + Monitor *old_mon = cur_mon; + + cur_mon = opaque; + + // TODO: read QMP input + + cur_mon = old_mon; +} + static void monitor_read(void *opaque, const uint8_t *buf, int size) { Monitor *old_mon = cur_mon; @@ -3622,6 +3648,23 @@ void monitor_resume(Monitor *mon) readline_show_prompt(mon->rs); } +/** + * monitor_control_event(): Print QMP gretting + */ +static void monitor_control_event(void *opaque, int event) +{ + if (event == CHR_EVENT_OPENED) { + QObject *data; + Monitor *mon = opaque; + + data = qobject_from_jsonf("{ 'QMP': { 'capabilities': [] } }"); + assert(data != NULL); + + monitor_json_emitter(mon, data); + qobject_decref(data); + } +} + static void monitor_event(void *opaque, int event) { Monitor *mon = opaque; @@ -3708,8 +3751,14 @@ void monitor_init(CharDriverState *chr, int flags) monitor_read_command(mon, 0); } - qemu_chr_add_handlers(chr, monitor_can_read, monitor_read, monitor_event, - mon); + if (monitor_ctrl_mode(mon)) { + /* Control mode requires special handlers */ + qemu_chr_add_handlers(chr, monitor_can_read, monitor_control_read, + monitor_control_event, mon); + } else { + qemu_chr_add_handlers(chr, monitor_can_read, monitor_read, + monitor_event, mon); + } QLIST_INSERT_HEAD(&mon_list, mon, entry); if (!cur_mon || (flags & MONITOR_IS_DEFAULT))