Skip to content

Commit

Permalink
qom: Support JSON in HMP object_add and tools --object
Browse files Browse the repository at this point in the history
Support JSON for --object in all tools and in HMP object_add in the same
way as it is supported in qobject_input_visitor_new_str().

Signed-off-by: Kevin Wolf <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Reviewed-by: Markus Armbruster <[email protected]>
Signed-off-by: Kevin Wolf <[email protected]>
  • Loading branch information
kevmw committed Mar 19, 2021
1 parent f3b70e0 commit 155b5f8
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions qom/object_interfaces.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,25 +296,35 @@ static void user_creatable_print_help_from_qdict(QDict *args)
ObjectOptions *user_creatable_parse_str(const char *optarg, Error **errp)
{
ERRP_GUARD();
QDict *args;
QObject *obj;
bool help;
Visitor *v;
ObjectOptions *options;

args = keyval_parse(optarg, "qom-type", &help, errp);
if (*errp) {
return NULL;
}
if (help) {
user_creatable_print_help_from_qdict(args);
qobject_unref(args);
return NULL;
if (optarg[0] == '{') {
obj = qobject_from_json(optarg, errp);
if (!obj) {
return NULL;
}
v = qobject_input_visitor_new(obj);
} else {
QDict *args = keyval_parse(optarg, "qom-type", &help, errp);
if (*errp) {
return NULL;
}
if (help) {
user_creatable_print_help_from_qdict(args);
qobject_unref(args);
return NULL;
}

obj = QOBJECT(args);
v = qobject_input_visitor_new_keyval(obj);
}

v = qobject_input_visitor_new_keyval(QOBJECT(args));
visit_type_ObjectOptions(v, NULL, &options, errp);
visit_free(v);
qobject_unref(args);
qobject_unref(obj);

return options;
}
Expand Down

0 comments on commit 155b5f8

Please sign in to comment.