From patchwork Fri Nov 27 00:59:03 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 39604 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 5DFF11007D1 for ; Fri, 27 Nov 2009 12:23:06 +1100 (EST) Received: from localhost ([127.0.0.1]:47396 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NDpY6-0006kq-Mi for incoming@patchwork.ozlabs.org; Thu, 26 Nov 2009 20:23:02 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NDpBl-0001tv-Oh for qemu-devel@nongnu.org; Thu, 26 Nov 2009 19:59:57 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NDpBg-0001oz-2B for qemu-devel@nongnu.org; Thu, 26 Nov 2009 19:59:56 -0500 Received: from [199.232.76.173] (port=48302 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NDpBf-0001oh-Lz for qemu-devel@nongnu.org; Thu, 26 Nov 2009 19:59:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:4297) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NDpBe-0004Sz-QM for qemu-devel@nongnu.org; Thu, 26 Nov 2009 19:59:51 -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 nAR0xn5x020827 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 26 Nov 2009 19:59:50 -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 nAR0xmjG024975; Thu, 26 Nov 2009 19:59:49 -0500 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Thu, 26 Nov 2009 22:59:03 -0200 Message-Id: <1259283550-3597-14-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 13/20] QMP: Asynchronous events infrastructure 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 Asynchronous events are generated with a call to monitor_protocol_event(). This function builds the right data-type and emit the event right away. The emitted data is always a JSON object and its format is as follows: { "event": json-string, "timestamp": { "seconds": json-number, "microseconds": json-number }, "data": json-value } This design is based on ideas by Amit Shah . Signed-off-by: Luiz Capitulino --- monitor.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ monitor.h | 6 ++++++ qemu-tool.c | 4 ++++ 3 files changed, 60 insertions(+), 0 deletions(-) diff --git a/monitor.c b/monitor.c index 0d4380d..a555f12 100644 --- a/monitor.c +++ b/monitor.c @@ -307,6 +307,56 @@ static void monitor_protocol_emitter(Monitor *mon, QObject *data) QDECREF(qmp); } +static void timestamp_put(QDict *qdict) +{ + int err; + QObject *obj; + struct timeval tv; + + err = gettimeofday(&tv, NULL); + if (err < 0) + return; + + obj = qobject_from_jsonf("{ 'seconds': %" PRId64 ", " + "'microseconds': %" PRId64 " }", + (int64_t) tv.tv_sec, (int64_t) tv.tv_usec); + assert(obj != NULL); + + qdict_put_obj(qdict, "timestamp", obj); +} + +/** + * monitor_protocol_event(): Generate a Monitor event + * + * Event-specific data can be emitted through the (optional) 'data' parameter. + */ +void monitor_protocol_event(MonitorEvent event, QObject *data) +{ + QDict *qmp; + const char *event_name; + Monitor *mon = cur_mon; + + assert(event < EVENT_MAX); + + if (!monitor_ctrl_mode(mon)) + return; + + switch (event) { + default: + abort(); + break; + } + + qmp = qdict_new(); + timestamp_put(qmp); + qdict_put(qmp, "event", qstring_from_str(event_name)); + if (data) + qdict_put_obj(qmp, "data", data); + + monitor_json_emitter(mon, QOBJECT(qmp)); + QDECREF(qmp); +} + static int compare_cmd(const char *name, const char *list) { const char *p, *pstart; diff --git a/monitor.h b/monitor.h index 556507c..a1d8b7a 100644 --- a/monitor.h +++ b/monitor.h @@ -13,6 +13,12 @@ extern Monitor *cur_mon; #define MONITOR_USE_READLINE 0x02 #define MONITOR_USE_CONTROL 0x04 +/* QMP events */ +typedef enum MonitorEvent { + EVENT_MAX, +} MonitorEvent; + +void monitor_protocol_event(MonitorEvent event, QObject *data); const char *monitor_cmdline_parse(const char *cmdline, int *flags); void monitor_init(CharDriverState *chr, int flags); diff --git a/qemu-tool.c b/qemu-tool.c index b35ea8e..18b48af 100644 --- a/qemu-tool.c +++ b/qemu-tool.c @@ -56,6 +56,10 @@ int get_async_context_id(void) return 0; } +void monitor_protocol_event(MonitorEvent event, QObject *data) +{ +} + QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque) { QEMUBH *bh;