From patchwork Tue May 6 09:27:50 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hu Tao X-Patchwork-Id: 346120 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 51328140317 for ; Tue, 6 May 2014 19:51:54 +1000 (EST) Received: from localhost ([::1]:33981 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Whc2S-000678-AW for incoming@patchwork.ozlabs.org; Tue, 06 May 2014 05:51:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39188) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WhboL-0008Q4-P0 for qemu-devel@nongnu.org; Tue, 06 May 2014 05:37:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WhboE-0008JM-68 for qemu-devel@nongnu.org; Tue, 06 May 2014 05:37:17 -0400 Received: from [59.151.112.132] (port=11710 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WhboD-0008Dw-Qu for qemu-devel@nongnu.org; Tue, 06 May 2014 05:37:10 -0400 X-IronPort-AV: E=Sophos;i="4.97,996,1389715200"; d="scan'208";a="30131334" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 06 May 2014 17:27:43 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id s469UDpj003127; Tue, 6 May 2014 17:30:13 +0800 Received: from G08FNSTD100614.fnst.cn.fujitsu.com (10.167.226.102) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.146.2; Tue, 6 May 2014 17:30:21 +0800 From: Hu Tao To: Date: Tue, 6 May 2014 17:27:50 +0800 Message-ID: <7016c1e387d966895988062f7431e301f81c7312.1399365798.git.hutao@cn.fujitsu.com> X-Mailer: git-send-email 1.8.5.2.229.g4448466 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.167.226.102] X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Cc: Paolo Bonzini , Igor Mammedov Subject: [Qemu-devel] [PATCH v3.1 29/31] qom: introduce object_property_get_enum and object_property_get_uint16List 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 Signed-off-by: Hu Tao --- include/qom/object.h | 28 ++++++++++++++++++++++++++++ qom/object.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/include/qom/object.h b/include/qom/object.h index a641dcd..b882ccc 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -917,6 +917,34 @@ int64_t object_property_get_int(Object *obj, const char *name, Error **errp); /** + * object_property_get_enum: + * @obj: the object + * @name: the name of the property + * @strings: strings corresponding to enums + * @errp: returns an error if this function fails + * + * Returns: the value of the property, converted to an integer, or + * undefined if an error occurs (including when the property value is not + * an enum). + */ +int object_property_get_enum(Object *obj, const char *name, + const char *strings[], Error **errp); + +/** + * object_property_get_uint16List: + * @obj: the object + * @name: the name of the property + * @list: the returned int list + * @errp: returns an error if this function fails + * + * Returns: the value of the property, converted to integers, or + * undefined if an error occurs (including when the property value is not + * an list of integers). + */ +void object_property_get_uint16List(Object *obj, const char *name, + uint16List **list, Error **errp); + +/** * object_property_set: * @obj: the object * @v: the visitor that will be used to write the property value. This should diff --git a/qom/object.c b/qom/object.c index e42b254..3876618 100644 --- a/qom/object.c +++ b/qom/object.c @@ -13,6 +13,7 @@ #include "qom/object.h" #include "qemu-common.h" #include "qapi/visitor.h" +#include "qapi-visit.h" #include "qapi/string-input-visitor.h" #include "qapi/string-output-visitor.h" #include "qapi/qmp/qerror.h" @@ -938,6 +939,40 @@ int64_t object_property_get_int(Object *obj, const char *name, return retval; } +int object_property_get_enum(Object *obj, const char *name, + const char *strings[], Error **errp) +{ + StringOutputVisitor *sov; + StringInputVisitor *siv; + int ret; + + sov = string_output_visitor_new(false); + object_property_get(obj, string_output_get_visitor(sov), name, errp); + siv = string_input_visitor_new(string_output_get_string(sov)); + string_output_visitor_cleanup(sov); + visit_type_enum(string_input_get_visitor(siv), + &ret, strings, NULL, name, errp); + string_input_visitor_cleanup(siv); + + return ret; +} + +void object_property_get_uint16List(Object *obj, const char *name, + uint16List **list, Error **errp) +{ + StringOutputVisitor *ov; + StringInputVisitor *iv; + + ov = string_output_visitor_new(false); + object_property_get(obj, string_output_get_visitor(ov), + name, errp); + iv = string_input_visitor_new(string_output_get_string(ov)); + visit_type_uint16List(string_input_get_visitor(iv), + list, NULL, errp); + string_output_visitor_cleanup(ov); + string_input_visitor_cleanup(iv); +} + void object_property_parse(Object *obj, const char *string, const char *name, Error **errp) {