Skip to content
Snippets Groups Projects
  1. Jul 09, 2015
  2. Jun 22, 2015
  3. Jun 19, 2015
    • 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
    • Daniel P. Berrangé's avatar
      qom: Make enum string tables const-correct · 2e4450ff
      Daniel P. Berrangé authored
      
      The enum string table parameters in various QOM/QAPI methods
      are declared 'const char *strings[]'. This results in const
      warnings if passed a variable that was declared as
      
         static const char * const strings[] = { .... };
      
      Add the extra const annotation to the parameters, since
      neither the string elements, nor the array itself should
      ever be modified.
      
      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>
      2e4450ff
    • Daniel P. Berrangé's avatar
      qom: Add object_new_with_props() / object_new_withpropv() helpers · a31bdae5
      Daniel P. Berrangé authored
      
      It is reasonably common to want to create an object, set a
      number of properties, register it in the hierarchy and then
      mark it as complete (if a user creatable type). This requires
      quite a lot of error prone, verbose, boilerplate code to achieve.
      
      First a pair of functions object_set_props() / object_set_propv()
      are added which allow for a list of objects to be set in
      one single API call.
      
      Then object_new_with_props() / object_new_with_propv() constructors
      are added which simplify the sequence of calls to create an
      object, populate properties, register in the object composition
      tree and mark the object complete, into a single method call.
      
      Usage would be:
      
         Error *err = NULL;
         Object *obj;
         obj = object_new_with_propv(TYPE_MEMORY_BACKEND_FILE,
                                     object_get_objects_root(),
                                     "hostmem0",
                                     &err,
                                     "share", "yes",
                                     "mem-path", "/dev/shm/somefile",
                                     "prealloc", "yes",
                                     "size", "1048576",
                                     NULL);
      
      Note all property values are passed in string form and will
      be parsed into their required data types, using normal QOM
      semantics for parsing from string format.
      
      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>
      a31bdae5
    • Daniel P. Berrangé's avatar
      qom: Add helper function for getting user objects root · bc2256c4
      Daniel P. Berrangé authored
      
      Add object_get_objects_root() function which is a convenience for
      obtaining the Object * located at /objects in the object
      composition tree. Convert existing code over to use the new
      API where appropriate.
      
      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>
      bc2256c4
    • Eduardo Habkost's avatar
      qom: strdup() target property name on object_property_add_alias() · 1590d266
      Eduardo Habkost authored
      
      With this, object_property_add_alias() callers can safely free the
      target property name, like what already happens with the 'name' argument
      to all object_property_add*() functions.
      
      Signed-off-by: default avatarEduardo Habkost <ehabkost@redhat.com>
      Reviewed-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Reviewed-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      Signed-off-by: default avatarAndreas Färber <afaerber@suse.de>
      1590d266
  4. Jun 05, 2015
  5. Apr 01, 2015
  6. Mar 31, 2015
  7. Mar 19, 2015
  8. Mar 09, 2015
  9. Feb 18, 2015
  10. Dec 20, 2014
  11. Nov 02, 2014
  12. Oct 23, 2014
  13. Oct 15, 2014
  14. Sep 25, 2014
  15. Sep 12, 2014
  16. Sep 04, 2014
  17. Sep 02, 2014
  18. Aug 17, 2014
  19. Jul 01, 2014
  20. Jun 30, 2014
  21. Jun 29, 2014
  22. Jun 19, 2014
Loading