[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 1/3] qom/object : add object_property_add_int8_ptr() property for
From: |
Maheswara Kurapati |
Subject: |
[PATCH 1/3] qom/object : add object_property_add_int8_ptr() property for 8 bit signed integers. |
Date: |
Wed, 13 Jul 2022 20:56:35 -0500 |
Current implementation lacks the support to add signed 8 bit integer
property to an Object. This fix adds the necessary infrastructure
routines.
Signed-off-by: Maheswara Kurapati <quic_mkurapat@quicinc.com>
---
include/qom/object.h | 21 ++++++++++++++++
qom/object.c | 60 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 81 insertions(+)
diff --git a/include/qom/object.h b/include/qom/object.h
index ef7258a5e1..60b88ed685 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -1764,6 +1764,27 @@ typedef enum {
OBJ_PROP_FLAG_READWRITE = (OBJ_PROP_FLAG_READ | OBJ_PROP_FLAG_WRITE),
} ObjectPropertyFlags;
+/**
+ * object_property_add_int8_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 signed integer property in memory. This function will add a
+ * property of type 'int8'.
+ *
+ * Returns: The newly added property on success, or %NULL on failure.
+ */
+ObjectProperty *object_property_add_int8_ptr(Object *obj, const char *name,
+ const int8_t *v,
+ ObjectPropertyFlags flags);
+
+ObjectProperty *object_class_property_add_int8_ptr(ObjectClass *klass,
+ const char *name,
+ const int8_t *v,
+ ObjectPropertyFlags flags);
+
/**
* object_property_add_uint8_ptr:
* @obj: the object to add a property to
diff --git a/qom/object.c b/qom/object.c
index d34608558e..1a0e64157f 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -2450,6 +2450,26 @@ static char *object_get_type(Object *obj, Error **errp)
return g_strdup(object_get_typename(obj));
}
+static void property_get_int8_ptr(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp)
+{
+ int8_t value = *(int8_t *)opaque;
+ visit_type_int8(v, name, &value, errp);
+}
+
+static void property_set_int8_ptr(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp)
+{
+ int8_t *field = opaque;
+ int8_t value;
+
+ if (!visit_type_int8(v, name, &value, errp)) {
+ return;
+ }
+
+ *field = value;
+}
+
static void property_get_uint8_ptr(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
@@ -2530,6 +2550,46 @@ static void property_set_uint64_ptr(Object *obj, Visitor
*v, const char *name,
*field = value;
}
+ObjectProperty *
+object_property_add_int8_ptr(Object *obj, const char *name,
+ const int8_t *v,
+ ObjectPropertyFlags flags)
+{
+ ObjectPropertyAccessor *getter = NULL;
+ ObjectPropertyAccessor *setter = NULL;
+
+ if ((flags & OBJ_PROP_FLAG_READ) == OBJ_PROP_FLAG_READ) {
+ getter = property_get_int8_ptr;
+ }
+
+ if ((flags & OBJ_PROP_FLAG_WRITE) == OBJ_PROP_FLAG_WRITE) {
+ setter = property_set_int8_ptr;
+ }
+
+ return object_property_add(obj, name, "int8",
+ getter, setter, NULL, (void *)v);
+}
+
+ObjectProperty *
+object_class_property_add_int8_ptr(ObjectClass *klass, const char *name,
+ const int8_t *v,
+ ObjectPropertyFlags flags)
+{
+ ObjectPropertyAccessor *getter = NULL;
+ ObjectPropertyAccessor *setter = NULL;
+
+ if ((flags & OBJ_PROP_FLAG_READ) == OBJ_PROP_FLAG_READ) {
+ getter = property_get_int8_ptr;
+ }
+
+ if ((flags & OBJ_PROP_FLAG_WRITE) == OBJ_PROP_FLAG_WRITE) {
+ setter = property_set_int8_ptr;
+ }
+
+ return object_class_property_add(klass, name, "int8",
+ getter, setter, NULL, (void *)v);
+}
+
ObjectProperty *
object_property_add_uint8_ptr(Object *obj, const char *name,
const uint8_t *v,
--
2.25.1