a3590dac | 27-May-2015 |
Daniel P. Berrange <berrange@redhat.com> |
qom: Don't pass string table to object_get_enum() function
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() functi
qom: Don't pass string table to object_get_enum() function
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: Daniel P. Berrange <berrange@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Andreas Färber <afaerber@suse.de>
show more ...
|
a8e3fbed | 13-May-2015 |
Daniel P. Berrange <berrange@redhat.com> |
qom: Add an object_property_add_enum() helper function
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 objec
qom: Add an object_property_add_enum() helper function
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: Daniel P. Berrange <berrange@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Andreas Färber <afaerber@suse.de>
show more ...
|
2e4450ff | 13-May-2015 |
Daniel P. Berrange <berrange@redhat.com> |
qom: Make enum string tables const-correct
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
qom: Make enum string tables const-correct
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: Daniel P. Berrange <berrange@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Andreas Färber <afaerber@suse.de>
show more ...
|
a31bdae5 | 13-May-2015 |
Daniel P. Berrange <berrange@redhat.com> |
qom: Add object_new_with_props() / object_new_withpropv() helpers
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 co
qom: Add object_new_with_props() / object_new_withpropv() helpers
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: Daniel P. Berrange <berrange@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Andreas Färber <afaerber@suse.de>
show more ...
|
08225676 | 12-Sep-2014 |
Peter Maydell <peter.maydell@linaro.org> |
exec.c: Record watchpoint fault address and direction
When we check whether we've hit a watchpoint we know the address that we were attempting to access and whether it was a read or a write. Record
exec.c: Record watchpoint fault address and direction
When we check whether we've hit a watchpoint we know the address that we were attempting to access and whether it was a read or a write. Record this information in the CPUWatchpoint struct so that target-specific code can report it to the guest.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Richard Henderson <rth@twiddle.net>
show more ...
|