qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v1 RFC 06/34] qom: add a object_property_add_enu


From: Daniel P. Berrange
Subject: Re: [Qemu-devel] [PATCH v1 RFC 06/34] qom: add a object_property_add_enum helper method
Date: Fri, 17 Apr 2015 16:11:40 +0100
User-agent: Mutt/1.5.23 (2014-03-12)

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 :|



reply via email to

[Prev in Thread] Current Thread [Next in Thread]