From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42852) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bNhnX-0004Df-Ht for qemu-devel@nongnu.org; Thu, 14 Jul 2016 10:39:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bNhnT-0006mg-Pu for qemu-devel@nongnu.org; Thu, 14 Jul 2016 10:39:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42514) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bNhnT-0006mb-JK for qemu-devel@nongnu.org; Thu, 14 Jul 2016 10:39:27 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E8F9AC049D52 for ; Thu, 14 Jul 2016 14:39:25 +0000 (UTC) Date: Thu, 14 Jul 2016 15:39:22 +0100 From: "Daniel P. Berrange" Message-ID: <20160714143922.GJ18778@redhat.com> Reply-To: "Daniel P. Berrange" References: <1468505770-20694-1-git-send-email-berrange@redhat.com> <5787A056.5090705@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <5787A056.5090705@redhat.com> Subject: Re: [Qemu-devel] [PATCH] qmp: add support for mixed typed input visitor List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: qemu-devel@nongnu.org On Thu, Jul 14, 2016 at 08:23:18AM -0600, Eric Blake wrote: > On 07/14/2016 08:16 AM, Daniel P. Berrange wrote: > > Add a qmp_mixed_input_visitor_new() method which returns > > a QMP input visitor that accepts either strings or the > > native data types. > > > > Signed-off-by: Daniel P. Berrange > > --- > > > > NB, just a demo - this should have tests added before submitting > > for real. > > > > > > > +static void qmp_input_type_int64_mixed(Visitor *v, const char *name, int64_t *obj, > > + Error **errp) > > +{ > > + QmpInputVisitor *qiv = to_qiv(v); > > + QObject *qobj = qmp_input_get_object(qiv, name, true); > > This consumes the key out of the QDict input stream... I did say it was not tested :-) > > + > > + if (qobj && qobj->type == QTYPE_QSTRING) { > > + qmp_input_type_int64_str(v, name, obj, errp); > > then calls a helper function that also wants to consume the key. You'll > have to use qmp_input_get_object(,false) for this to work (in other > words, do a peek instead of consume when deciding which other helper to > use). > > > > + > > +Visitor *qmp_mixed_input_visitor_new(QObject *obj, bool strict) > > +{ > > I guess it's not too hard to generate 'qmp_mixed_input_visitor_new' > instead of 'qmp_input_visitor_new' when 'autocast':true is set in QAPI, > so that's a minor tweak to my series. Your version also has the benefit > of not changing all existing callers to add another parameter. Yep, that's the main reason I went for separate constructor. It'd be equally fine to have a enum param in the existing constructor which just picked different callbacks. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|