Skip to content
Snippets Groups Projects
  1. Jun 22, 2015
  2. Jun 21, 2015
  3. Jun 19, 2015
    • Markus Armbruster's avatar
      qdev: Un-deprecate qdev_init_nofail() · daeba969
      Markus Armbruster authored
      
      It's a perfectly sensible helper function.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Signed-off-by: default avatarAndreas Färber <afaerber@suse.de>
      daeba969
    • Markus Armbruster's avatar
      qdev: Deprecated qdev_init() is finally unused, drop · 0210afe6
      Markus Armbruster authored
      
      qdev_init() is a wrapper around setting property "realized" to true,
      plus error handling that passes errors to qerror_report_err().
      qerror_report_err() is a transitional interface to help with
      converting existing monitor commands to QMP.  It should not be used
      elsewhere.
      
      All code has been modernized to avoid qdev_init() and its
      inappropriate error handling.  We can finally drop it.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Signed-off-by: default avatarAndreas Färber <afaerber@suse.de>
      0210afe6
    • Daniel P. Berrangé's avatar
      qom: Don't pass string table to object_get_enum() function · a3590dac
      Daniel P. Berrangé authored
      
      Now that properties can be explicitly registered as an enum
      type, there is no need to pass the string table to the
      object_get_enum() function. The object property registration
      already has a pointer to the string table.
      
      In changing this method signature, the hostmem backend object
      has to be converted to use the new enum property registration
      code, which simplifies it somewhat.
      
      Signed-off-by: default avatarDaniel P. Berrange <berrange@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Signed-off-by: default avatarAndreas Färber <afaerber@suse.de>
      a3590dac
    • Daniel P. Berrangé's avatar
      qom: Add an object_property_add_enum() helper function · a8e3fbed
      Daniel P. Berrangé authored
      
      A QOM property can be parsed as enum using the visit_type_enum()
      helper function, 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_obj;
            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->devtype = value;
         }
      
         object_property_add_enum(obj, "devtype",
                                  mydevtypemap, "MyDevType",
                                  mydev_prop_get_devtype,
                                  mydev_prop_set_devtype,
                                  NULL);
      
      Note there is no need to check the range of 'value' in
      the setter, because the string->enum conversion code will
      have already done that and reported an error as required.
      
      Signed-off-by: default avatarDaniel P. Berrange <berrange@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Signed-off-by: default avatarAndreas Färber <afaerber@suse.de>
      a8e3fbed
Loading