From patchwork Thu Jan 2 23:10:34 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 306440 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 40B4D2C0082 for ; Fri, 3 Jan 2014 18:14:38 +1100 (EST) Received: from localhost ([::1]:48482 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vyyxo-0005nk-2P for incoming@patchwork.ozlabs.org; Fri, 03 Jan 2014 02:14:36 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50724) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vyyua-0001Gy-KB for qemu-devel@nongnu.org; Fri, 03 Jan 2014 02:11:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VyyuH-00045Z-EV for qemu-devel@nongnu.org; Fri, 03 Jan 2014 02:11:16 -0500 Received: from e28smtp01.in.ibm.com ([122.248.162.1]:33951) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VyyuF-000458-6d for qemu-devel@nongnu.org; Fri, 03 Jan 2014 02:10:57 -0500 Received: from /spool/local by e28smtp01.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 3 Jan 2014 12:40:49 +0530 Received: from d28dlp02.in.ibm.com (9.184.220.127) by e28smtp01.in.ibm.com (192.168.1.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 3 Jan 2014 12:40:46 +0530 Received: from d28relay01.in.ibm.com (d28relay01.in.ibm.com [9.184.220.58]) by d28dlp02.in.ibm.com (Postfix) with ESMTP id 532073940023 for ; Fri, 3 Jan 2014 12:40:46 +0530 (IST) Received: from d28av02.in.ibm.com (d28av02.in.ibm.com [9.184.220.64]) by d28relay01.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s037Abkr27787396 for ; Fri, 3 Jan 2014 12:40:37 +0530 Received: from d28av02.in.ibm.com (localhost [127.0.0.1]) by d28av02.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s037AiK6017781 for ; Fri, 3 Jan 2014 12:40:45 +0530 Received: from RH64wenchao ([9.181.129.59]) by d28av02.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id s037Abuj017206; Fri, 3 Jan 2014 12:40:43 +0530 From: Wenchao Xia To: qemu-devel@nongnu.org Date: Fri, 3 Jan 2014 07:10:34 +0800 Message-Id: <1388704234-22498-6-git-send-email-xiawenc@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1388704234-22498-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1388704234-22498-1-git-send-email-xiawenc@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14010307-4790-0000-0000-00000C112E19 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 122.248.162.1 Cc: Wenchao Xia , mreitz@redhat.com, armbru@redhat.com, lcapitulino@redhat.com Subject: [Qemu-devel] [RFC PATCH V2 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 calller one by one. Signed-off-by: Wenchao Xia --- monitor.c | 14 ++++++++++++++ qapi-schema.json | 3 +++ vl.c | 7 ++----- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/monitor.c b/monitor.c index 845f608..8dca027 100644 --- a/monitor.c +++ b/monitor.c @@ -74,6 +74,8 @@ #endif #include "hw/lm32/lm32_pic.h" +#include "qapi-event.h" + //#define DEBUG //#define DEBUG_COMPLETION @@ -628,6 +630,16 @@ monitor_protocol_event_throttle(MonitorEvent event, evstate->data = NULL; } +static void monitor_event_emit(QAPIEvent ev, 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 */ @@ -637,6 +649,8 @@ static void monitor_protocol_event_init(void) monitor_protocol_event_throttle(QEVENT_RTC_CHANGE, 1000); monitor_protocol_event_throttle(QEVENT_BALLOON_CHANGE, 1000); monitor_protocol_event_throttle(QEVENT_WATCHDOG, 1000); + + qapi_event_set_func_emit(monitor_event_emit); } /** diff --git a/qapi-schema.json b/qapi-schema.json index 9b51dcc..60ddf44 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -4247,3 +4247,6 @@ # Since: 1.7 ## { 'command': 'blockdev-add', 'data': { 'options': 'BlockdevOptions' } } + +{ 'event': 'RTC_CHANGE', + 'data': { 'offset' : 'int' } } diff --git a/vl.c b/vl.c index 7511e70..7726116 100644 --- a/vl.c +++ b/vl.c @@ -170,6 +170,7 @@ int main(int argc, char **argv) #include "ui/qemu-spice.h" #include "qapi/string-input-visitor.h" +#include "qapi-event.h" //#define DEBUG_NET //#define DEBUG_SLIRP @@ -743,11 +744,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)