mirror of https://gitee.com/openkylin/qemu.git
qom: export more functions for use with non-UserCreatable objects
Machines and accelerators are not user-creatable but they are going to share similar command-line parsing machinery. Export functions that will be used with -machine and -accel in softmmu/vl.c. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
d47a8b3b69
commit
3bb6944585
|
@ -861,6 +861,29 @@ static void do_qemu_init_ ## type_array(void) \
|
||||||
} \
|
} \
|
||||||
type_init(do_qemu_init_ ## type_array)
|
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 with the properties to be set
|
||||||
|
* @from_json: true if leaf values of @qdict are typed, false if they
|
||||||
|
* are strings
|
||||||
|
* @errp: pointer to error object
|
||||||
|
*
|
||||||
|
* For each key in the dictionary, parse the value string if needed,
|
||||||
|
* then set the corresponding property in @obj.
|
||||||
|
*/
|
||||||
|
void object_set_properties_from_keyval(Object *obj, const QDict *qdict,
|
||||||
|
bool from_json, Error **errp);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* object_class_dynamic_cast_assert:
|
* object_class_dynamic_cast_assert:
|
||||||
* @klass: The #ObjectClass to attempt to cast.
|
* @klass: The #ObjectClass to attempt to cast.
|
||||||
|
|
|
@ -42,6 +42,44 @@ 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,
|
||||||
|
bool from_json, Error **errp)
|
||||||
|
{
|
||||||
|
Visitor *v;
|
||||||
|
if (from_json) {
|
||||||
|
v = qobject_input_visitor_new(QOBJECT(qdict));
|
||||||
|
} else {
|
||||||
|
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,
|
Object *user_creatable_add_type(const char *type, const char *id,
|
||||||
const QDict *qdict,
|
const QDict *qdict,
|
||||||
Visitor *v, Error **errp)
|
Visitor *v, Error **errp)
|
||||||
|
@ -49,7 +87,6 @@ Object *user_creatable_add_type(const char *type, const char *id,
|
||||||
ERRP_GUARD();
|
ERRP_GUARD();
|
||||||
Object *obj;
|
Object *obj;
|
||||||
ObjectClass *klass;
|
ObjectClass *klass;
|
||||||
const QDictEntry *e;
|
|
||||||
Error *local_err = NULL;
|
Error *local_err = NULL;
|
||||||
|
|
||||||
if (id != NULL && !id_wellformed(id)) {
|
if (id != NULL && !id_wellformed(id)) {
|
||||||
|
@ -78,18 +115,7 @@ Object *user_creatable_add_type(const char *type, const char *id,
|
||||||
|
|
||||||
assert(qdict);
|
assert(qdict);
|
||||||
obj = object_new(type);
|
obj = object_new(type);
|
||||||
if (!visit_start_struct(v, NULL, NULL, 0, &local_err)) {
|
object_set_properties_from_qdict(obj, qdict, v, &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);
|
|
||||||
if (local_err) {
|
if (local_err) {
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -178,7 +204,7 @@ static void user_creatable_print_types(void)
|
||||||
g_slist_free(list);
|
g_slist_free(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool user_creatable_print_type_properites(const char *type)
|
bool type_print_class_properties(const char *type)
|
||||||
{
|
{
|
||||||
ObjectClass *klass;
|
ObjectClass *klass;
|
||||||
ObjectPropertyIterator iter;
|
ObjectPropertyIterator iter;
|
||||||
|
@ -224,7 +250,7 @@ bool user_creatable_print_help(const char *type, QemuOpts *opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qemu_opt_has_help_opt(opts)) {
|
if (qemu_opt_has_help_opt(opts)) {
|
||||||
return user_creatable_print_type_properites(type);
|
return type_print_class_properties(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -234,7 +260,7 @@ static void user_creatable_print_help_from_qdict(QDict *args)
|
||||||
{
|
{
|
||||||
const char *type = qdict_get_try_str(args, "qom-type");
|
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();
|
user_creatable_print_types();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue