[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 04/12] qom: Add instance_config() to TypeInfo
From: |
Kevin Wolf |
Subject: |
[RFC PATCH 04/12] qom: Add instance_config() to TypeInfo |
Date: |
Wed, 3 Nov 2021 18:29:54 +0100 |
Instead of providing the whole configuration through property setters,
object_config() can now use the instance_config() callback. Options that
are not consumed by the callback (e.g. because they belong to a parent
class that hasn't been converted to the new callback yet) are still set
as properties.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
include/qom/object.h | 4 ++++
qom/object.c | 15 +++++++++++++++
2 files changed, 19 insertions(+)
diff --git a/include/qom/object.h b/include/qom/object.h
index d67ba2411d..e60cacb54b 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -384,6 +384,9 @@ struct Object
* for initializing its own members.
* @instance_post_init: This function is called to finish initialization of
* an object, after all @instance_init functions were called.
+ * @instance_config: This function is called to set the initial configuration
+ * of an object. If not provided, configuration is done through property
+ * setters.
* @instance_finalize: This function is called during object destruction. This
* is called before the parent @instance_finalize function has been called.
* An object should only free the members that are unique to its type in this
@@ -419,6 +422,7 @@ struct TypeInfo
size_t instance_align;
void (*instance_init)(Object *obj);
void (*instance_post_init)(Object *obj);
+ bool (*instance_config)(Object *obj, Visitor *v, Error **errp);
void (*instance_finalize)(Object *obj);
bool abstract;
diff --git a/qom/object.c b/qom/object.c
index d8da362987..6cacfa9ab1 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -60,6 +60,7 @@ struct TypeImpl
void (*instance_init)(Object *obj);
void (*instance_post_init)(Object *obj);
+ bool (*instance_config)(Object *obj, Visitor *v, Error **errp);
void (*instance_finalize)(Object *obj);
bool abstract;
@@ -124,6 +125,7 @@ static TypeImpl *type_new(const TypeInfo *info)
ti->instance_init = info->instance_init;
ti->instance_post_init = info->instance_post_init;
+ ti->instance_config = info->instance_config;
ti->instance_finalize = info->instance_finalize;
ti->abstract = info->abstract;
@@ -303,6 +305,7 @@ static void type_initialize(TypeImpl *ti)
assert(ti->abstract);
assert(!ti->instance_init);
assert(!ti->instance_post_init);
+ assert(!ti->instance_config);
assert(!ti->instance_finalize);
assert(!ti->num_interfaces);
}
@@ -607,11 +610,23 @@ void object_initialize_child_internal(Object *parent,
void object_configure(Object *obj, Visitor *v, Error **errp)
{
+ TypeImpl *ti;
const char *key;
if (!visit_start_struct(v, NULL, NULL, 0, errp)) {
return;
}
+
+ /* Call .instance_config, including for all parent classes */
+ for (ti = obj->class->type; ti; ti = ti->parent_type) {
+ if (ti->instance_config) {
+ if (!ti->instance_config(obj, v, errp)) {
+ goto out;
+ }
+ }
+ }
+
+ /* Set options not consumed by .instance_config as properties */
while ((key = visit_next_struct_member(v))) {
if (!object_property_set(obj, key, v, errp)) {
goto out;
--
2.31.1
- [RFC PATCH 00/12] QOM/QAPI integration part 1, Kevin Wolf, 2021/11/03
- [RFC PATCH 02/12] qom: Create object_configure(), Kevin Wolf, 2021/11/03
- [RFC PATCH 01/12] qapi: Add visit_next_struct_member(), Kevin Wolf, 2021/11/03
- [RFC PATCH 03/12] qom: Make object_configure() public, Kevin Wolf, 2021/11/03
- [RFC PATCH 04/12] qom: Add instance_config() to TypeInfo,
Kevin Wolf <=
- [RFC PATCH 05/12] rng-random: Implement .instance_config, Kevin Wolf, 2021/11/03
- [RFC PATCH 06/12] rng-backend: Implement .instance_config, Kevin Wolf, 2021/11/03
- [RFC PATCH 07/12] qapi: Allow defining QOM classes, Kevin Wolf, 2021/11/03
- [RFC PATCH 08/12] qapi: Create qom-config:... type for classes, Kevin Wolf, 2021/11/03
- [RFC PATCH 09/12] qapi/qom: Convert rng-backend/random to class, Kevin Wolf, 2021/11/03
- [RFC PATCH 12/12] qapi/qom: Add class definition for rng-egd, Kevin Wolf, 2021/11/03
- [RFC PATCH 11/12] qapi/qom: Add class definition for rng-builtin, Kevin Wolf, 2021/11/03