From patchwork Wed Mar 19 05:16:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenchao Xia X-Patchwork-Id: 331621 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id F1ABF2C00BE for ; Wed, 19 Mar 2014 16:21:02 +1100 (EST) Received: from localhost ([::1]:38716 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WQ8w0-0003wA-NM for incoming@patchwork.ozlabs.org; Wed, 19 Mar 2014 01:21:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48298) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WQ8sp-0007I1-9d for qemu-devel@nongnu.org; Wed, 19 Mar 2014 01:17:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WQ8sg-0002bh-Rp for qemu-devel@nongnu.org; Wed, 19 Mar 2014 01:17:43 -0400 Received: from mail-pd0-x231.google.com ([2607:f8b0:400e:c02::231]:42551) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WQ8sg-0002bY-JL for qemu-devel@nongnu.org; Wed, 19 Mar 2014 01:17:34 -0400 Received: by mail-pd0-f177.google.com with SMTP id y10so8081301pdj.22 for ; Tue, 18 Mar 2014 22:17:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=UyLMbgklX5RKUf3vvSYITVF7vRTSGlDw49n7foPX/7Q=; b=jhK39K9llG4wluXcYsNgi/Z2qmO6mweTHBuNE65dSPG+W6yBG3+jSK/tp/lMXXRoeU oBah0xg51N6Gui7eQAPiHRbCNkfsWrjkqI4CJI4eUwaFQ7/WjzD/DSCt/gXWU6FF2mDv A1wzbwqRa8PdHAPMIp1wNg59DE74oK53NbwZS/CvOtYm6FK/G7KQYP8jgjr9FTULjy2K GHDdg/LkmE11niaVwaU0wjGKM8X9t827tcHVIx0rtXPotEshj6PbVhnMIZbubYoWwe74 N6Y5hO5cA9VC/3zZDPAvPY1wFqvpbpAfAfcv+KTlVVH44gPPkS8Tydr51Aa21PQXyLx0 LxVQ== X-Received: by 10.68.231.35 with SMTP id td3mr15184121pbc.137.1395206253754; Tue, 18 Mar 2014 22:17:33 -0700 (PDT) Received: from localhost.localdomain.localdomain ([118.250.20.115]) by mx.google.com with ESMTPSA id gg3sm58235179pbc.34.2014.03.18.22.17.27 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 18 Mar 2014 22:17:32 -0700 (PDT) From: Wenchao Xia To: qemu-devel@nongnu.org Date: Tue, 18 Mar 2014 22:16:41 -0700 Message-Id: <1395206201-22999-6-git-send-email-wenchaoqemu@gmail.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1395206201-22999-1-git-send-email-wenchaoqemu@gmail.com> References: <1395206201-22999-1-git-send-email-wenchaoqemu@gmail.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400e:c02::231 Cc: mdroth@linux.vnet.ibm.com, armbru@redhat.com, Wenchao Xia , lcapitulino@redhat.com Subject: [Qemu-devel] [RFC PATCH V3 5/5] qapi event: convert RTC_CHANGE X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This is just an example of how to use qapi event API, and it bypassed the event throttle queue. A complete convert should be first define all events in qapi-schema.json, use qapi event types in monitor functions, then change caller one by one. Signed-off-by: Wenchao Xia --- monitor.c | 15 +++++++++++++++ qapi-schema.json | 13 +++++++++++++ vl.c | 7 ++----- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/monitor.c b/monitor.c index 342e83b..163f654 100644 --- a/monitor.c +++ b/monitor.c @@ -57,6 +57,7 @@ #include "qapi/qmp/qjson.h" #include "qapi/qmp/json-streamer.h" #include "qapi/qmp/json-parser.h" +#include "qapi/qmp-event.h" #include #include "qemu/osdep.h" #include "cpu.h" @@ -76,6 +77,8 @@ #endif #include "hw/lm32/lm32_pic.h" +#include "qapi-event.h" + //#define DEBUG //#define DEBUG_COMPLETION @@ -632,6 +635,16 @@ monitor_protocol_event_throttle(MonitorEvent event, evstate->data = NULL; } +static void monitor_event_emit(int event_kind, QDict *d, Error **errp) +{ + Monitor *mon; + + QLIST_FOREACH(mon, &mon_list, entry) { + if (monitor_ctrl_mode(mon) && qmp_cmd_mode(mon)) { + monitor_json_emitter(mon, QOBJECT(d)); + } + } +} /* Global, one-time initializer to configure the rate limiting * and initialize state */ @@ -644,6 +657,8 @@ static void monitor_protocol_event_init(void) /* limit the rate of quorum events to avoid hammering the management */ monitor_protocol_event_throttle(QEVENT_QUORUM_REPORT_BAD, 1000); monitor_protocol_event_throttle(QEVENT_QUORUM_FAILURE, 1000); + + qmp_event_set_func_emit(monitor_event_emit); } /** diff --git a/qapi-schema.json b/qapi-schema.json index b68cd44..62918c5 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -4686,3 +4686,16 @@ 'btn' : 'InputBtnEvent', 'rel' : 'InputMoveEvent', 'abs' : 'InputMoveEvent' } } + +## +# @RTC_CHANGE +# +# Emitted when the guest changes the RTC time. +# +# @offset: Offset between base RTC clock (as specified by -rtc base), and +# new RTC clock value +# +# Since: 2.1 +## +{ 'event': 'RTC_CHANGE', + 'data': { 'offset' : 'int' } } diff --git a/vl.c b/vl.c index f0fe48b..08a0e56 100644 --- a/vl.c +++ b/vl.c @@ -117,6 +117,7 @@ int main(int argc, char **argv) #include "ui/qemu-spice.h" #include "qapi/string-input-visitor.h" #include "qom/object_interfaces.h" +#include "qapi-event.h" #define DEFAULT_RAM_SIZE 128 @@ -723,11 +724,7 @@ int qemu_timedate_diff(struct tm *tm) void rtc_change_mon_event(struct tm *tm) { - QObject *data; - - data = qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm)); - monitor_protocol_event(QEVENT_RTC_CHANGE, data); - qobject_decref(data); + qapi_event_send_rtc_change(qemu_timedate_diff(tm), NULL); } static void configure_rtc_date_offset(const char *startdate, int legacy)