[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 06/26] object: add class property initializer
From: |
Marc-André Lureau |
Subject: |
[PATCH 06/26] object: add class property initializer |
Date: |
Sun, 1 Dec 2019 15:15:11 +0400 |
This callback is used to set default value in following patch "object:
add object_property_set_defaut_{bool,str,int,uint}()".
Signed-off-by: Marc-André Lureau <address@hidden>
---
include/qom/object.h | 16 ++++++++++++++--
qom/object.c | 14 ++++++++++++++
2 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/include/qom/object.h b/include/qom/object.h
index 128d00c77f..e15ebd486b 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -303,6 +303,8 @@ typedef struct InterfaceInfo InterfaceInfo;
*/
+typedef struct ObjectProperty ObjectProperty;
+
/**
* ObjectPropertyAccessor:
* @obj: the object that owns the property
@@ -350,7 +352,16 @@ typedef void (ObjectPropertyRelease)(Object *obj,
const char *name,
void *opaque);
-typedef struct ObjectProperty
+/**
+ * ObjectPropertyInit:
+ * @obj: the object that owns the property
+ * @prop: the property to set
+ *
+ * Called when a property is initialized.
+ */
+typedef void (ObjectPropertyInit)(Object *obj, ObjectProperty *prop);
+
+struct ObjectProperty
{
gchar *name;
gchar *type;
@@ -359,8 +370,9 @@ typedef struct ObjectProperty
ObjectPropertyAccessor *set;
ObjectPropertyResolve *resolve;
ObjectPropertyRelease *release;
+ ObjectPropertyInit *init;
void *opaque;
-} ObjectProperty;
+};
/**
* ObjectUnparent:
diff --git a/qom/object.c b/qom/object.c
index f1e1e0947b..4b9f8d8668 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -450,6 +450,19 @@ void object_apply_compat_props(Object *obj)
}
}
+static void object_class_property_init_all(Object *obj)
+{
+ ObjectPropertyIterator iter;
+ ObjectProperty *prop;
+
+ object_class_property_iter_init(&iter, object_get_class(obj));
+ while ((prop = object_property_iter_next(&iter))) {
+ if (prop->init) {
+ prop->init(obj, prop);
+ }
+ }
+}
+
static void object_initialize_with_type(void *data, size_t size, TypeImpl
*type)
{
Object *obj = data;
@@ -463,6 +476,7 @@ static void object_initialize_with_type(void *data, size_t
size, TypeImpl *type)
memset(obj, 0, type->instance_size);
obj->class = type->class;
object_ref(obj);
+ object_class_property_init_all(obj);
obj->properties = g_hash_table_new_full(g_str_hash, g_str_equal,
NULL, object_property_free);
object_init_with_type(obj, type);
--
2.24.0
- [PATCH 00/26] Make QDev use class properties, Marc-André Lureau, 2019/12/01
- [PATCH 01/26] object: add extra sanity checks, Marc-André Lureau, 2019/12/01
- [PATCH 02/26] qdev: remove duplicated qdev_property_add_static() doc, Marc-André Lureau, 2019/12/01
- [PATCH 03/26] qdev: remove extraneous error, Marc-André Lureau, 2019/12/01
- [PATCH 04/26] qdev: move helper function to monitor/misc, Marc-André Lureau, 2019/12/01
- [PATCH 05/26] object: avoid extra class property key duplication, Marc-André Lureau, 2019/12/01
- [PATCH 06/26] object: add class property initializer,
Marc-André Lureau <=
- [PATCH 07/26] object: add object_property_get_defaut(), Marc-André Lureau, 2019/12/01
- [PATCH 08/26] object: make object_class_property_add* return property, Marc-André Lureau, 2019/12/01
- [PATCH 09/26] qstring: add qstring_free(), Marc-André Lureau, 2019/12/01
- [PATCH 10/26] object: add object_property_set_defaut_{bool, str, int, uint}(), Marc-André Lureau, 2019/12/01
- [PATCH 11/26] object: do not free class properties, Marc-André Lureau, 2019/12/01
- [PATCH 12/26] object: check strong flag with &, Marc-André Lureau, 2019/12/01
- [PATCH 13/26] object: rename link "child" to "target", Marc-André Lureau, 2019/12/01
- [PATCH 14/26] object: add direct link flag, Marc-André Lureau, 2019/12/01
- [PATCH 15/26] object: express const link with link property, Marc-André Lureau, 2019/12/01
- [PATCH 16/26] object: add object_class_property_add_link(), Marc-André Lureau, 2019/12/01