From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54811) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yj8Ul-0003qN-9K for qemu-devel@nongnu.org; Fri, 17 Apr 2015 11:47:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yj8Uh-0002DA-G5 for qemu-devel@nongnu.org; Fri, 17 Apr 2015 11:47:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42062) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yj8Uh-0002D4-9D for qemu-devel@nongnu.org; Fri, 17 Apr 2015 11:47:51 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t3HFlmFu014759 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Fri, 17 Apr 2015 11:47:50 -0400 Date: Fri, 17 Apr 2015 16:11:40 +0100 From: "Daniel P. Berrange" Message-ID: <20150417151140.GG23619@redhat.com> References: <1429280557-8887-1-git-send-email-berrange@redhat.com> <1429280557-8887-7-git-send-email-berrange@redhat.com> <55311F3B.8060305@redhat.com> <55312044.90604@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <55312044.90604@redhat.com> Subject: Re: [Qemu-devel] [PATCH v1 RFC 06/34] qom: add a object_property_add_enum helper method Reply-To: "Daniel P. Berrange" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: qemu-devel@nongnu.org, Stefan Hajnoczi , Gerd Hoffmann On Fri, Apr 17, 2015 at 05:01:24PM +0200, Paolo Bonzini wrote: > > > On 17/04/2015 16:56, Paolo Bonzini wrote: > > > > > > On 17/04/2015 16:22, Daniel P. Berrange wrote: > >> A QOM property can be parsed as enum using the visit_type_enum() > >> helper method, but this forces callers to use the more complex > >> generic object_property_add() method when registering it. It > >> also requires that users of that object have access to the > >> string map when they want to read the property value. > >> > >> This patch introduces a specialized object_property_add_enum() > >> method which simplifies the use of enum properties, so the > >> setters/getters directly get passed the int value. > >> > >> typedef enum { > >> MYDEV_TYPE_FROG, > >> MYDEV_TYPE_ALLIGATOR, > >> MYDEV_TYPE_PLATYPUS, > >> > >> MYDEV_TYPE_LAST > >> } MyDevType; > >> > >> Then provide a table of enum <-> string mappings > >> > >> static const char *const mydevtypemap[MYDEV_TYPE_LAST + 1] = { > >> [MYDEV_TYPE_FROG] = "frog", > >> [MYDEV_TYPE_ALLIGATOR] = "alligator", > >> [MYDEV_TYPE_PLATYPUS] = "platypus", > >> [MYDEV_TYPE_LAST] = NULL, > >> }; > >> > >> Assuming an object struct of > >> > >> typedef struct { > >> Object parent; > >> MyDevType devtype; > >> ...other fields... > >> } MyDev; > >> > >> The property can then be registered as follows: > >> > >> static int mydev_prop_get_devtype(Object *obj, > >> Error **errp G_GNUC_UNUSED) > >> { > >> MyDev *dev = MYDEV(obj); > >> > >> return dev->devtype; > >> } > >> > >> static void mydev_prop_set_devtype(Object *obj, > >> int value, > >> Error **errp G_GNUC_UNUSED) > >> { > >> MyDev *dev = MYDEV(obj); > >> > >> dev->endpoint = value; > >> } > >> > >> object_property_add_enum(obj, "devtype", > >> mydevtypemap, > >> mydev_prop_get_devtype, > >> mydev_prop_set_devtype, > >> NULL); > > On second thought (after seeing patch 7), please add a property type > argument here. We lose introspection of enum property types otherwise. Can you give me a pointer to where we lose introspection ? The hostmem code just registers its 'policy' property with a type name of 'str', which I've just changed to 'enum' in patch 7, so I didn't think I was regressing anything. Is there some QMP command which you think looses the info that I can verify. > It's possible to use macros so that 'MyEnum' gets translated to two > arguments '"MyEnum", MyEnum_lookup', but I don't think that's worth the > obfuscation. 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 :|