This adds a class property that references a uint16_t within the object instance
and is intended to be a replacement for object_property_add_uint16_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 a55f9d0e97..a175505d40 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -1982,6 +1982,11 @@ ObjectProperty *object_property_add_uint16_ptr(Object 
*obj, const char *name,
                                     const uint16_t *v,
                                     ObjectPropertyFlags flags);
 
+ObjectProperty *object_class_property_add_uint16_ptr(ObjectClass *klass,
+                                    const char *name,
+                                    ptrdiff_t v,
+                                    ObjectPropertyFlags flags);
+
 ObjectProperty *object_class_static_property_add_uint16_ptr(ObjectClass *klass,
                                           const char *name,
                                           const uint16_t *v,
diff --git a/qom/object.c b/qom/object.c
index 263c313cd2..52e47068ed 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -2773,6 +2773,30 @@ static void property_class_set_uint8_ptr(Object *obj, 
Visitor *v,
     *field = value;
 }
 
+static void property_class_get_uint16_ptr(Object *obj, Visitor *v,
+                                          const char *name,
+                                          void *opaque, Error **errp)
+{
+    uint16_t value = *(uint16_t *)object_class_prop_ptr(obj,
+                                                        (ptrdiff_t)opaque);
+    visit_type_uint16(v, name, &value, errp);
+}
+
+static void property_class_set_uint16_ptr(Object *obj, Visitor *v,
+                                          const char *name,
+                                          void *opaque, Error **errp)
+{
+    uint16_t *field = (uint16_t *)object_class_prop_ptr(obj,
+                                                        (ptrdiff_t)opaque);
+    uint16_t value;
+
+    if (!visit_type_uint16(v, name, &value, errp)) {
+        return;
+    }
+
+    *field = value;
+}
+
 ObjectProperty *
 object_property_add_uint8_ptr(Object *obj, const char *name,
                               const uint8_t *v,
@@ -2854,6 +2878,26 @@ object_property_add_uint16_ptr(Object *obj, const char 
*name,
                                getter, setter, NULL, (void *)v);
 }
 
+ObjectProperty *
+object_class_property_add_uint16_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_uint16_ptr;
+    }
+
+    if ((flags & OBJ_PROP_FLAG_WRITE) == OBJ_PROP_FLAG_WRITE) {
+        setter = property_class_set_uint16_ptr;
+    }
+
+    return object_class_property_add(klass, name, "uint16",
+                                     getter, setter, NULL, (void *)v);
+}
+
 ObjectProperty *
 object_class_static_property_add_uint16_ptr(ObjectClass *klass,
                                             const char *name,
-- 
2.43.0


Reply via email to