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 | 52 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/include/qom/object.h b/include/qom/object.h index 89c23d45ab..a55f9d0e97 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -1956,6 +1956,11 @@ ObjectProperty *object_property_add_uint8_ptr(Object *obj, const char *name, const uint8_t *v, ObjectPropertyFlags flags); +ObjectProperty *object_class_property_add_uint8_ptr(ObjectClass *klass, + const char *name, + ptrdiff_t v, + ObjectPropertyFlags flags); + ObjectProperty *object_class_static_property_add_uint8_ptr(ObjectClass *klass, const char *name, const uint8_t *v, diff --git a/qom/object.c b/qom/object.c index d10bf848c0..263c313cd2 100644 --- a/qom/object.c +++ b/qom/object.c @@ -2741,6 +2741,38 @@ static void property_set_uint64_ptr(Object *obj, Visitor *v, const char *name, *field = value; } +static void *object_class_prop_ptr(Object *obj, ptrdiff_t offset) +{ + void *ptr = obj; + ptr += offset; + + return ptr; +} + +static void property_class_get_uint8_ptr(Object *obj, Visitor *v, + const char *name, + void *opaque, Error **errp) +{ + uint8_t value = *(uint8_t *)object_class_prop_ptr(obj, + (ptrdiff_t)opaque); + visit_type_uint8(v, name, &value, errp); +} + +static void property_class_set_uint8_ptr(Object *obj, Visitor *v, + const char *name, + void *opaque, Error **errp) +{ + uint8_t *field = (uint8_t *)object_class_prop_ptr(obj, + (ptrdiff_t)opaque); + uint8_t value; + + if (!visit_type_uint8(v, name, &value, errp)) { + return; + } + + *field = value; +} + ObjectProperty * object_property_add_uint8_ptr(Object *obj, const char *name, const uint8_t *v, @@ -2761,6 +2793,26 @@ object_property_add_uint8_ptr(Object *obj, const char *name, getter, setter, NULL, (void *)v); } +ObjectProperty * +object_class_property_add_uint8_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_uint8_ptr; + } + + if ((flags & OBJ_PROP_FLAG_WRITE) == OBJ_PROP_FLAG_WRITE) { + setter = property_class_set_uint8_ptr; + } + + return object_class_property_add(klass, name, "uint8", + getter, setter, NULL, (void *)v); +} + ObjectProperty * object_class_static_property_add_uint8_ptr(ObjectClass *klass, const char *name, -- 2.43.0
