diff options
author | Anthony Liguori <aliguori@us.ibm.com> | 2012-06-25 10:32:46 -0500 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2012-11-16 08:36:12 -0600 |
commit | 0e5588438d921b8686bbf455f400f727b2ff7b62 (patch) | |
tree | 118533dfecdb1f3a36dba52249892659bab10ca4 /qom | |
parent | 68d98d3e42b2b291274537d1ae4092e11d321437 (diff) |
object: add object_property_add_bool (v2)
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
v1 -> v2
- Fix whitespace (Andreas Faerber)
Diffstat (limited to 'qom')
-rw-r--r-- | qom/object.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/qom/object.c b/qom/object.c index e3e9242638..d7092b09d8 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1183,6 +1183,62 @@ void object_property_add_str(Object *obj, const char *name, prop, errp); } +typedef struct BoolProperty +{ + bool (*get)(Object *, Error **); + void (*set)(Object *, bool, Error **); +} BoolProperty; + +static void property_get_bool(Object *obj, Visitor *v, void *opaque, + const char *name, Error **errp) +{ + BoolProperty *prop = opaque; + bool value; + + value = prop->get(obj, errp); + visit_type_bool(v, &value, name, errp); +} + +static void property_set_bool(Object *obj, Visitor *v, void *opaque, + const char *name, Error **errp) +{ + BoolProperty *prop = opaque; + bool value; + Error *local_err = NULL; + + visit_type_bool(v, &value, name, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + + prop->set(obj, value, errp); +} + +static void property_release_bool(Object *obj, const char *name, + void *opaque) +{ + BoolProperty *prop = opaque; + g_free(prop); +} + +void object_property_add_bool(Object *obj, const char *name, + bool (*get)(Object *, Error **), + void (*set)(Object *, bool, Error **), + Error **errp) +{ + BoolProperty *prop = g_malloc0(sizeof(*prop)); + + prop->get = get; + prop->set = set; + + object_property_add(obj, name, "bool", + get ? property_get_bool : NULL, + set ? property_set_bool : NULL, + property_release_bool, + prop, errp); +} + static char *qdev_get_type(Object *obj, Error **errp) { return g_strdup(object_get_typename(obj)); |