[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 36/59] object: add class property initializer
From: |
Paolo Bonzini |
Subject: |
[PULL 36/59] object: add class property initializer |
Date: |
Thu, 23 Jan 2020 14:50:26 +0100 |
From: Marc-André Lureau <address@hidden>
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>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <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 54a5488..29f47d3 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -309,6 +309,8 @@ typedef struct InterfaceInfo InterfaceInfo;
*/
+typedef struct ObjectProperty ObjectProperty;
+
/**
* ObjectPropertyAccessor:
* @obj: the object that owns the property
@@ -356,7 +358,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;
@@ -365,8 +376,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 e921363..cd7ce81 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -478,6 +478,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;
@@ -491,6 +504,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);
--
1.8.3.1
- [PULL 26/59] target/arm/kvm: Use CPUState::kvm_state in kvm_arm_pmu_supported(), (continued)
- [PULL 26/59] target/arm/kvm: Use CPUState::kvm_state in kvm_arm_pmu_supported(), Paolo Bonzini, 2020/01/23
- [PULL 27/59] qom/object: Display more helpful message when a parent is missing, Paolo Bonzini, 2020/01/23
- [PULL 28/59] accel: Introduce the current_accel() wrapper, Paolo Bonzini, 2020/01/23
- [PULL 29/59] accel: Replace current_machine->accelerator by current_accel() wrapper, Paolo Bonzini, 2020/01/23
- [PULL 30/59] accel/tcg: Sanitize include path, Paolo Bonzini, 2020/01/23
- [PULL 31/59] object: add extra sanity checks, Paolo Bonzini, 2020/01/23
- [PULL 32/59] qdev: remove duplicated qdev_property_add_static() doc, Paolo Bonzini, 2020/01/23
- [PULL 33/59] qdev: remove extraneous error, Paolo Bonzini, 2020/01/23
- [PULL 34/59] qdev: move helper function to monitor/misc, Paolo Bonzini, 2020/01/23
- [PULL 35/59] object: avoid extra class property key duplication, Paolo Bonzini, 2020/01/23
- [PULL 36/59] object: add class property initializer,
Paolo Bonzini <=
- [PULL 37/59] object: make object_class_property_add* return property, Paolo Bonzini, 2020/01/23
- [PULL 38/59] qstring: add qstring_free(), Paolo Bonzini, 2020/01/23
- [PULL 39/59] object: add object_property_set_default, Paolo Bonzini, 2020/01/23
- [PULL 40/59] object: do not free class properties, Paolo Bonzini, 2020/01/23
- [PULL 41/59] object: check strong flag with &, Paolo Bonzini, 2020/01/23
- [PULL 42/59] object: rename link "child" to "target", Paolo Bonzini, 2020/01/23
- [PULL 43/59] object: add direct link flag, Paolo Bonzini, 2020/01/23
- [PULL 44/59] object: express const link with link property, Paolo Bonzini, 2020/01/23
- [PULL 45/59] object: add object_class_property_add_link(), Paolo Bonzini, 2020/01/23
- [PULL 46/59] object: release all props, Paolo Bonzini, 2020/01/23