From patchwork Wed Apr 24 12:47:25 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amos Kong X-Patchwork-Id: 239194 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 2A0692C0186 for ; Wed, 24 Apr 2013 22:47:43 +1000 (EST) Received: from localhost ([::1]:47788 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UUz6r-0006XK-EM for incoming@patchwork.ozlabs.org; Wed, 24 Apr 2013 08:47:41 -0400 Received: from eggs.gnu.org ([208.118.235.92]:52469) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UUz6N-0006UE-0U for qemu-devel@nongnu.org; Wed, 24 Apr 2013 08:47:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UUz6H-0007js-W4 for qemu-devel@nongnu.org; Wed, 24 Apr 2013 08:47:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56578) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UUz6H-0007jf-N3 for qemu-devel@nongnu.org; Wed, 24 Apr 2013 08:47:05 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r3OCl4Og029516 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 24 Apr 2013 08:47:04 -0400 Received: from dhcp-8-167.nay.redhat.com ([10.66.4.143]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r3OCl02N017101; Wed, 24 Apr 2013 08:47:01 -0400 From: Amos Kong To: aliguori@us.ibm.com Date: Wed, 24 Apr 2013 20:47:25 +0800 Message-Id: <1366807646-8473-1-git-send-email-akong@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: pbonzini@redhat.com, qemu-devel@nongnu.org, jyang@redhat.com, lcapitulino@redhat.com Subject: [Qemu-devel] [RESEND PATCH 1/2] qapi: introduce strList and visit_type_strList() 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 Currently we can only use ['String'] to add string to a list, it contains some additional JSON structure. "multicast": [ { "str": "01:80:c2:00:00:21" }, { "str": "00:00:00:00:00:00" } ] This patch introdued strList, we can use ['str'] "multicast": [ "01:00:5e:00:00:01", "33:33:ff:12:34:57" ] Signed-off-by: Amos Kong Reviewed-by: Eric Blake --- I used an _ugly_ "#ifndef" to limit it only be defined in qapi-types.h. do you have some suggestion to fix it? --- include/qapi/visitor.h | 2 ++ qapi/qapi-visit-core.c | 23 +++++++++++++++++++++++ scripts/qapi-types.py | 8 ++++++++ 3 files changed, 33 insertions(+), 0 deletions(-) diff --git a/include/qapi/visitor.h b/include/qapi/visitor.h index 1fef18c..a79ce79 100644 --- a/include/qapi/visitor.h +++ b/include/qapi/visitor.h @@ -50,6 +50,8 @@ void visit_type_int64(Visitor *v, int64_t *obj, const char *name, Error **errp); void visit_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp); void visit_type_bool(Visitor *v, bool *obj, const char *name, Error **errp); void visit_type_str(Visitor *v, char **obj, const char *name, Error **errp); +void visit_type_strList(Visitor *m, strList ** obj, const char *name, + Error **errp); void visit_type_number(Visitor *v, double *obj, const char *name, Error **errp); #endif diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c index 401ee6e..dc54cc8 100644 --- a/qapi/qapi-visit-core.c +++ b/qapi/qapi-visit-core.c @@ -257,6 +257,29 @@ void visit_type_str(Visitor *v, char **obj, const char *name, Error **errp) } } +void visit_type_strList(Visitor *m, strList ** obj, const char *name, + Error **errp) +{ + GenericList *i, **prev = (GenericList **)obj; + Error *err = NULL; + + if (!error_is_set(errp)) { + visit_start_list(m, name, &err); + if (!err) { + for (; (i = visit_next_list(m, prev, &err)) != NULL; prev = &i) { + strList *native_i = (strList *)i; + visit_type_str(m, &native_i->value, NULL, &err); + } + error_propagate(errp, err); + err = NULL; + + /* Always call end_list if start_list succeeded. */ + visit_end_list(m, &err); + } + error_propagate(errp, err); + } +} + void visit_type_number(Visitor *v, double *obj, const char *name, Error **errp) { if (!error_is_set(errp)) { diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index 9e19920..f2ca373 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -276,6 +276,14 @@ fdecl.write(mcgen(''' #include #include +#ifndef QGA_QAPI_TYPES_H +typedef struct strList +{ + char *value; + struct strList *next; +} strList; +#endif + ''', guard=guardname(h_file)))