Machines and accelerators are not user-creatable but they share similar parsing machinery. Export functions that will be used with -machine and -accel in softmmu/vl.c.
Signed-off-by: Paolo Bonzini <pbonz...@redhat.com> --- include/qom/object.h | 21 +++++++++++++++++ qom/object_interfaces.c | 51 +++++++++++++++++++++++++++++------------ 2 files changed, 57 insertions(+), 15 deletions(-) diff --git a/include/qom/object.h b/include/qom/object.h index d378f13a11..cd27facd8a 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -860,6 +860,27 @@ static void do_qemu_init_ ## type_array(void) \ } \ type_init(do_qemu_init_ ## type_array) +/** + * type_print_class_properties: + * @type: a QOM class name + * + * Print the object's class properties to stdout or the monitor. + * Return whether an object was found. + */ +bool type_print_class_properties(const char *type); + +/** + * object_set_properties_from_keyval: + * @obj: a QOM object + * @qdict: a dictionary whose leaf values are strings + * @errp: pointer to error object + * + * For each key in the dictionary, parse the value string and set the + * corresponding property in @obj. + */ +void object_set_properties_from_keyval(Object *obj, const QDict *qdict, + Error **errp); + /** * object_class_dynamic_cast_assert: * @klass: The #ObjectClass to attempt to cast. diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c index 107c378c27..7c6d591731 100644 --- a/qom/object_interfaces.c +++ b/qom/object_interfaces.c @@ -39,13 +39,45 @@ bool user_creatable_can_be_deleted(UserCreatable *uc) } } +static void object_set_properties_from_qdict(Object *obj, const QDict *qdict, + Visitor *v, Error **errp) +{ + const QDictEntry *e; + Error *local_err = NULL; + + if (!visit_start_struct(v, NULL, NULL, 0, &local_err)) { + goto out; + } + for (e = qdict_first(qdict); e; e = qdict_next(qdict, e)) { + if (!object_property_set(obj, e->key, v, &local_err)) { + break; + } + } + if (!local_err) { + visit_check_struct(v, &local_err); + } + visit_end_struct(v, NULL); + +out: + if (local_err) { + error_propagate(errp, local_err); + } +} + +void object_set_properties_from_keyval(Object *obj, const QDict *qdict, + Error **errp) +{ + Visitor *v = qobject_input_visitor_new_keyval(QOBJECT(qdict)); + object_set_properties_from_qdict(obj, qdict, v, errp); + visit_free(v); +} + Object *user_creatable_add_type(const char *type, const char *id, const QDict *qdict, Visitor *v, Error **errp) { Object *obj; ObjectClass *klass; - const QDictEntry *e; Error *local_err = NULL; klass = object_class_by_name(type); @@ -67,18 +99,7 @@ Object *user_creatable_add_type(const char *type, const char *id, assert(qdict); obj = object_new(type); - if (!visit_start_struct(v, NULL, NULL, 0, &local_err)) { - goto out; - } - for (e = qdict_first(qdict); e; e = qdict_next(qdict, e)) { - if (!object_property_set(obj, e->key, v, &local_err)) { - break; - } - } - if (!local_err) { - visit_check_struct(v, &local_err); - } - visit_end_struct(v, NULL); + object_set_properties_from_qdict(obj, qdict, v, &local_err); if (local_err) { goto out; } @@ -177,7 +198,7 @@ void user_creatable_print_types(void) g_slist_free(list); } -static bool user_creatable_print_type_properites(const char *type) +bool type_print_class_properties(const char *type) { ObjectClass *klass; ObjectPropertyIterator iter; @@ -219,7 +240,7 @@ void user_creatable_print_help_from_qdict(const QDict *args) { const char *type = qdict_get_try_str(args, "qom-type"); - if (!type || !user_creatable_print_type_properites(type)) { + if (!type || !type_print_class_properties(type)) { user_creatable_print_types(); } } -- 2.26.2