From patchwork Thu May 1 04:26:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenchao Xia X-Patchwork-Id: 344401 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id D5568140116 for ; Thu, 1 May 2014 14:30:07 +1000 (EST) Received: from localhost ([::1]:60312 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WfidJ-0004C2-NK for incoming@patchwork.ozlabs.org; Thu, 01 May 2014 00:30:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49165) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wfiap-00080x-7x for qemu-devel@nongnu.org; Thu, 01 May 2014 00:27:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wfiag-0002EZ-5V for qemu-devel@nongnu.org; Thu, 01 May 2014 00:27:31 -0400 Received: from mail-ie0-x229.google.com ([2607:f8b0:4001:c03::229]:39348) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wfiag-0002EJ-04 for qemu-devel@nongnu.org; Thu, 01 May 2014 00:27:22 -0400 Received: by mail-ie0-f169.google.com with SMTP id rl12so3078969iec.0 for ; Wed, 30 Apr 2014 21:27:21 -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=u62n0N59/2hOi8fg2zUpVa4D+eeCZe65ALDt11LmKng=; b=wpRY/WEjs3tB+iI3Wq+nnFSUjoQ+EMkzl5dosZkXgrtRAVBZozFf9JcavwhjSPrpbU dnJhIGb/EaLWKUHwggkhDSXmP5LLmEXQLjUBjUuPDNaUNwzbEC7zZsYtHRZ8qhS1k1aj HISpBvC9TGjvEMEPPnNcOq3ouu1bRXzt3TkDEkagGClg6iW/m4ER+BwRiXLSACQYCPeZ zehNTMLpADcKm/Apd/YBcxt8JlcZc0GDbI7bgqMB1SNJl16AaR97WEZJqohuTFc9yEas d/FW+XGIo8zkNBsuXfAPNIjAmyAlwVszeqDdsONJNoGUgMjuUtWTg5Dba0TFPbs7FmLJ fObQ== X-Received: by 10.42.185.72 with SMTP id cn8mr66980icb.63.1398918441522; Wed, 30 Apr 2014 21:27:21 -0700 (PDT) Received: from localhost.localdomain.localdomain ([118.250.93.201]) by mx.google.com with ESMTPSA id ii7sm4626797igb.17.2014.04.30.21.27.17 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 Apr 2014 21:27:21 -0700 (PDT) From: Wenchao Xia To: qemu-devel@nongnu.org Date: Wed, 30 Apr 2014 21:26:36 -0700 Message-Id: <1398918422-3019-3-git-send-email-wenchaoqemu@gmail.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1398918422-3019-1-git-send-email-wenchaoqemu@gmail.com> References: <1398918422-3019-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:4001:c03::229 Cc: mdroth@linux.vnet.ibm.com, armbru@redhat.com, Wenchao Xia , lcapitulino@redhat.com Subject: [Qemu-devel] [PATCH V5 02/28] qapi: add event helper functions 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 file holds some functions that do not need to be generated. Signed-off-by: Wenchao Xia Reviewed-by: Eric Blake --- include/qapi/qmp-event.h | 27 +++++++++++++++++ qapi/Makefile.objs | 1 + qapi/qmp-event.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+), 0 deletions(-) create mode 100644 include/qapi/qmp-event.h create mode 100644 qapi/qmp-event.c diff --git a/include/qapi/qmp-event.h b/include/qapi/qmp-event.h new file mode 100644 index 0000000..02b6ce5 --- /dev/null +++ b/include/qapi/qmp-event.h @@ -0,0 +1,27 @@ +/* + * QMP Event related + * + * Copyright (c) 2014 Wenchao Xia + * + * Authors: + * Wenchao Xia + * + * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. + * See the COPYING.LIB file in the top-level directory. + * + */ + +#ifndef QMP_EVENT_H +#define QMP_EVENT_H + +#include "qapi/error.h" +#include "qapi/qmp/qdict.h" + +typedef void (*QMPEventFuncEmit)(int event_kind, QDict *dict, Error **errp); + +void qmp_event_set_func_emit(QMPEventFuncEmit emit); + +QMPEventFuncEmit qmp_event_get_func_emit(void); + +QDict *qmp_event_build_dict(const char *event_name); +#endif diff --git a/qapi/Makefile.objs b/qapi/Makefile.objs index 1f9c973..d14b769 100644 --- a/qapi/Makefile.objs +++ b/qapi/Makefile.objs @@ -3,3 +3,4 @@ util-obj-y += qmp-output-visitor.o qmp-registry.o qmp-dispatch.o util-obj-y += string-input-visitor.o string-output-visitor.o util-obj-y += opts-visitor.o +util-obj-y += qmp-event.o diff --git a/qapi/qmp-event.c b/qapi/qmp-event.c new file mode 100644 index 0000000..0d1ce0b --- /dev/null +++ b/qapi/qmp-event.c @@ -0,0 +1,74 @@ +/* + * QMP Event related + * + * Copyright (c) 2014 Wenchao Xia + * + * Authors: + * Wenchao Xia + * + * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. + * See the COPYING.LIB file in the top-level directory. + * + */ + +#include + +#include "qemu-common.h" +#include "qapi/qmp-event.h" +#include "qapi/qmp/qstring.h" +#include "qapi/qmp/qjson.h" + +#ifdef _WIN32 +#include "sysemu/os-win32.h" +#endif + +#ifdef CONFIG_POSIX +#include "sysemu/os-posix.h" +#endif + +static QMPEventFuncEmit qmp_emit; + +void qmp_event_set_func_emit(QMPEventFuncEmit emit) +{ + qmp_emit = emit; +} + +QMPEventFuncEmit qmp_event_get_func_emit(void) +{ + return qmp_emit; +} + +static void timestamp_put(QDict *qdict) +{ + int err; + QObject *obj; + qemu_timeval tv; + int64_t sec, usec; + + err = qemu_gettimeofday(&tv); + if (err < 0) { + /* Put -1 to indicate failure of getting host time */ + sec = -1; + usec = -1; + } else { + sec = tv.tv_sec; + usec = tv.tv_usec; + } + + obj = qobject_from_jsonf("{ 'seconds': %" PRId64 ", " + "'microseconds': %" PRId64 " }", + sec, usec); + qdict_put_obj(qdict, "timestamp", obj); +} + +/* + * Build a QDict, then fill event name and time stamp, caller should free the + * QDict after usage. + */ +QDict *qmp_event_build_dict(const char *event_name) +{ + QDict *dict = qdict_new(); + qdict_put(dict, "event", qstring_from_str(event_name)); + timestamp_put(dict); + return dict; +}