[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [RFC PATCH 02/12] qom: Create object_configure()
From: |
Markus Armbruster |
Subject: |
Re: [RFC PATCH 02/12] qom: Create object_configure() |
Date: |
Tue, 23 Nov 2021 16:23:59 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) |
Kevin Wolf <kwolf@redhat.com> writes:
> This renames object_set_properties_from_qdict() to object_configure()
> and removes the QDict parameter from it: With visit_next_struct_member()
> it can set all properties without looking at the keys of the QDict.
>
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
> qom/object_interfaces.c | 13 ++++++-------
> 1 file changed, 6 insertions(+), 7 deletions(-)
>
> diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
> index 3b61c195c5..f9f5608194 100644
> --- a/qom/object_interfaces.c
> +++ b/qom/object_interfaces.c
> @@ -42,16 +42,15 @@ bool user_creatable_can_be_deleted(UserCreatable *uc)
> }
> }
>
> -static void object_set_properties_from_qdict(Object *obj, const QDict *qdict,
> - Visitor *v, Error **errp)
> +static void object_configure(Object *obj, Visitor *v, Error **errp)
> {
> - const QDictEntry *e;
> + const char *key;
>
> if (!visit_start_struct(v, NULL, NULL, 0, errp)) {
> return;
> }
> - for (e = qdict_first(qdict); e; e = qdict_next(qdict, e)) {
> - if (!object_property_set(obj, e->key, v, errp)) {
> + while ((key = visit_next_struct_member(v))) {
> + if (!object_property_set(obj, key, v, errp)) {
> goto out;
> }
> }
> @@ -69,7 +68,7 @@ void object_set_properties_from_keyval(Object *obj, const
> QDict *qdict,
> } else {
> v = qobject_input_visitor_new_keyval(QOBJECT(qdict));
> }
> - object_set_properties_from_qdict(obj, qdict, v, errp);
> + object_configure(obj, v, errp);
> visit_free(v);
> }
>
> @@ -108,7 +107,7 @@ Object *user_creatable_add_type(const char *type, const
> char *id,
>
> assert(qdict);
This is the only remaining use of parameter @qdict. Let's drop it.
> obj = object_new(type);
> - object_set_properties_from_qdict(obj, qdict, v, &local_err);
> + object_configure(obj, v, &local_err);
> if (local_err) {
> goto out;
> }
Brief recap how configuration data flows trough QMP object-add to QOM:
* QMP object-add is fully typed: union ObjectOptions. QMP core parses
input via QDict to ObjectOptions (JSON parser + QObject input
visitor), and passes that to qmp_object_add().
* qmp_object_add() passes it on to user_creatable_add_qapi().
Aside: getting rid of the wrapper would be as easy as renaming
user_creatable_add_qapi() to qmp_object_add().
* user_creatable_add_qapi() converts right back to QDict (QObject output
visitor). It extracts the non-properties "qom-type" and "id", and
passes the properties (wrapped in a QObject input visitor) to
user_creatable_add_type().
* user_creatable_add_type() feeds the properties to object_configure(),
formerly object_set_properties_from_qdict().
Your patch simplifies one detail of the last step. Small
simplifications are welcome, too.
The visitor ping-pong remains: input -> output -> input.
We play visitor ping-pong because we reduce the problem "for each member
of ObjectOptions: set property" to the solved problem "set properties
for an input visitor".
Straight solution of the problem: a QOM property output visitor.
Observation, not demand.
- [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
- Re: [RFC PATCH 02/12] qom: Create object_configure(),
Markus Armbruster <=
- [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, 2021/11/03
- [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