This adds a class property that references a uint8_t within the object instance and is intended to be a replacement for object_property_add_uint8_ptr().
Signed-off-by: Mark Cave-Ayland <[email protected]> --- include/qom/object.h | 5 +++++ qom/object.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/include/qom/object.h b/include/qom/object.h index 9071d49a29..d5c32844a0 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -2034,6 +2034,11 @@ ObjectProperty *object_property_add_uint64_ptr(Object *obj, const char *name, const uint64_t *v, ObjectPropertyFlags flags); +ObjectProperty *object_class_property_add_uint64_ptr(ObjectClass *klass, + const char *name, + ptrdiff_t v, + ObjectPropertyFlags flags); + ObjectProperty *object_class_static_property_add_uint64_ptr(ObjectClass *klass, const char *name, const uint64_t *v, diff --git a/qom/object.c b/qom/object.c index 3089eba273..3048131435 100644 --- a/qom/object.c +++ b/qom/object.c @@ -2821,6 +2821,30 @@ static void property_class_set_uint32_ptr(Object *obj, Visitor *v, *field = value; } +static void property_class_get_uint64_ptr(Object *obj, Visitor *v, + const char *name, + void *opaque, Error **errp) +{ + uint64_t value = *(uint64_t *)object_class_prop_ptr(obj, + (ptrdiff_t)opaque); + visit_type_uint64(v, name, &value, errp); +} + +static void property_class_set_uint64_ptr(Object *obj, Visitor *v, + const char *name, + void *opaque, Error **errp) +{ + uint64_t *field = (uint64_t *)object_class_prop_ptr(obj, + (ptrdiff_t)opaque); + uint64_t value; + + if (!visit_type_uint64(v, name, &value, errp)) { + return; + } + + *field = value; +} + ObjectProperty * object_property_add_uint8_ptr(Object *obj, const char *name, const uint8_t *v, @@ -3024,6 +3048,26 @@ object_property_add_uint64_ptr(Object *obj, const char *name, getter, setter, NULL, (void *)v); } +ObjectProperty * +object_class_property_add_uint64_ptr(ObjectClass *klass, const char *name, + ptrdiff_t v, + ObjectPropertyFlags flags) +{ + ObjectPropertyAccessor *getter = NULL; + ObjectPropertyAccessor *setter = NULL; + + if ((flags & OBJ_PROP_FLAG_READ) == OBJ_PROP_FLAG_READ) { + getter = property_class_get_uint64_ptr; + } + + if ((flags & OBJ_PROP_FLAG_WRITE) == OBJ_PROP_FLAG_WRITE) { + setter = property_class_set_uint64_ptr; + } + + return object_class_property_add(klass, name, "uint64", + getter, setter, NULL, (void *)v); +} + ObjectProperty * object_class_static_property_add_uint64_ptr(ObjectClass *klass, const char *name, -- 2.43.0
