[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 1/4] qom: object*_property_add_bool_ptr() functions
From: |
Eduardo Habkost |
Subject: |
[PATCH 1/4] qom: object*_property_add_bool_ptr() functions |
Date: |
Thu, 22 Oct 2020 18:31:37 -0400 |
Provide helpers for registering boolean properties that simply
read/write a struct field, to reduce the need to manually write
property getters and setters.
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: Eduardo Habkost <ehabkost@redhat.com>
Cc: qemu-devel@nongnu.org
---
include/qom/object.h | 23 +++++++++++++++++++++++
qom/object.c | 31 +++++++++++++++++++++++++++++++
2 files changed, 54 insertions(+)
diff --git a/include/qom/object.h b/include/qom/object.h
index a124cf897d..954a26c567 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -1815,6 +1815,29 @@ ObjectProperty
*object_class_property_add_uint64_ptr(ObjectClass *klass,
ptrdiff_t offset,
ObjectPropertyFlags flags);
+/**
+ * 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 an bool property in memory. This function will add a
+ * property of type 'bool'.
+ *
+ * Returns: The newly added property on success, or %NULL on failure.
+ */
+ObjectProperty *
+object_property_add_bool_ptr(Object *obj, const char *name,
+ bool *v,
+ ObjectPropertyFlags flags);
+
+ObjectProperty *
+object_class_property_add_bool_ptr(ObjectClass *klass,
+ const char *name,
+ ptrdiff_t offset,
+ ObjectPropertyFlags flags);
+
/**
* object_property_add_alias:
* @obj: the object to add a property to
diff --git a/qom/object.c b/qom/object.c
index 73f27b8b7e..2abc2bda33 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -2713,6 +2713,37 @@ object_class_property_add_uint64_ptr(ObjectClass *klass,
const char *name,
flags, offset);
}
+static void property_visit_bool_ptr(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp)
+{
+ PointerProperty *prop = opaque;
+ bool *field = pointer_property_get_ptr(obj, prop);
+ visit_type_bool(v, name, field, errp);
+}
+
+ObjectProperty *
+object_property_add_bool_ptr(Object *obj, const char *name,
+ bool *v,
+ ObjectPropertyFlags flags)
+{
+ return object_property_add_uint_ptr(obj, name, "bool",
+ property_visit_bool_ptr,
+ property_visit_bool_ptr,
+ flags,
+ (void *)v);
+}
+
+ObjectProperty *
+object_class_property_add_bool_ptr(ObjectClass *klass, const char *name,
+ ptrdiff_t offset,
+ ObjectPropertyFlags flags)
+{
+ return object_class_property_add_uint_ptr(klass, name, "bool",
+ property_visit_bool_ptr,
+ property_visit_bool_ptr,
+ flags, offset);
+}
+
typedef struct {
Object *target_obj;
char *target_name;
--
2.28.0