[PATCH v2 06/10] qom: Add object_property_add_bool_ptr()
Peter Xu <[email protected]> Tue, 9 Jun 2026 13:25:10 -0400
| Newsgroups | org.nongnu.qemu-rust,org.nongnu.qemu-arm,org.nongnu.qemu-devel |
|---|---|
| Message-ID | <[email protected]> |
Add a helper to set qom property via a bool pointer. Signed-off-by: Peter Xu <[email protected]> --- include/qom/object-property-ptr.h | 15 ++++++++++++ qom/object-property-ptr.c | 39 +++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/include/qom/object-property-ptr.h b/include/qom/object-property-ptr.h index 6066c377fb..9cd8600094 100644 --- a/include/qom/object-property-ptr.h +++ b/include/qom/object-property-ptr.h @@ -16,6 +16,21 @@ typedef enum { OBJ_PROP_FLAG_READWRITE = (OBJ_PROP_FLAG_READ | OBJ_PROP_FLAG_WRITE), } ObjectPropertyFlags; +/** + * object_property_add_bool_ptr: + * @obj: the object to add a property to + * @name: the name of the property + * @v: pointer to value + * @flags: bitwise-or'd ObjectPropertyFlags + * + * Add a property of type 'bool' to the object. + * + * Returns: The newly added property on success, or %NULL on failure. + */ +ObjectProperty * +object_property_add_bool_ptr(Object *obj, const char *name, const bool *v, + ObjectPropertyFlags flags); + /** * object_property_add_uint8_ptr: * @obj: the object to add a property to diff --git a/qom/object-property-ptr.c b/qom/object-property-ptr.c index 02c01ed7f0..49f223da7b 100644 --- a/qom/object-property-ptr.c +++ b/qom/object-property-ptr.c @@ -7,6 +7,26 @@ #include "qom/object.h" #include "qapi/visitor.h" +static void property_get_bool_ptr(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + bool value = *(bool *)opaque; + visit_type_bool(v, name, &value, errp); +} + +static void property_set_bool_ptr(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + bool *field = opaque; + bool value; + + if (!visit_type_bool(v, name, &value, errp)) { + return; + } + + *field = value; +} + static void property_get_uint8_ptr(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { @@ -87,6 +107,25 @@ static void property_set_uint64_ptr(Object *obj, Visitor *v, const char *name, *field = value; } +ObjectProperty * +object_property_add_bool_ptr(Object *obj, const char *name, + const bool *v, ObjectPropertyFlags flags) +{ + ObjectPropertyAccessor *getter = NULL; + ObjectPropertyAccessor *setter = NULL; + + if ((flags & OBJ_PROP_FLAG_READ) == OBJ_PROP_FLAG_READ) { + getter = property_get_bool_ptr; + } + + if ((flags & OBJ_PROP_FLAG_WRITE) == OBJ_PROP_FLAG_WRITE) { + setter = property_set_bool_ptr; + } + + return object_property_add(obj, name, "bool", + getter, setter, NULL, (void *)v); +} + ObjectProperty * object_property_add_uint8_ptr(Object *obj, const char *name, const uint8_t *v, -- 2.53.0