Skip to content
Snippets Groups Projects
Commit ddf6dae7 authored by Kevin Wolf's avatar Kevin Wolf
Browse files

qom: Add user_creatable_parse_str()


The system emulator has a more complicated way of handling command line
options in that it reorders options before it processes them. This means
that parsing object options and creating the object happen at two
different points. Split the parsing part into a separate function that
can be reused by the system emulator command line.

Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
Acked-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
Acked-by: default avatarPeter Krempa <pkrempa@redhat.com>
Reviewed-by: default avatarEric Blake <eblake@redhat.com>
parent da0a932b
No related branches found
No related tags found
No related merge requests found
......@@ -144,6 +144,21 @@ typedef bool (*user_creatable_add_opts_predicate)(const char *type);
int user_creatable_add_opts_foreach(void *opaque,
QemuOpts *opts, Error **errp);
/**
* user_creatable_parse_str:
* @optarg: the object definition string as passed on the command line
* @errp: if an error occurs, a pointer to an area to store the error
*
* Parses the option for the user creatable object with a keyval parser and
* implicit key 'qom-type', converting the result to ObjectOptions.
*
* If a help option is given, print help instead.
*
* Returns: ObjectOptions on success, NULL when an error occurred (*errp is set
* then) or help was printed (*errp is not set).
*/
ObjectOptions *user_creatable_parse_str(const char *optarg, Error **errp);
/**
* user_creatable_add_from_str:
* @optarg: the object definition string as passed on the command line
......
......@@ -293,7 +293,7 @@ static void user_creatable_print_help_from_qdict(QDict *args)
}
}
bool user_creatable_add_from_str(const char *optarg, Error **errp)
ObjectOptions *user_creatable_parse_str(const char *optarg, Error **errp)
{
ERRP_GUARD();
QDict *args;
......@@ -303,12 +303,12 @@ bool user_creatable_add_from_str(const char *optarg, Error **errp)
args = keyval_parse(optarg, "qom-type", &help, errp);
if (*errp) {
return false;
return NULL;
}
if (help) {
user_creatable_print_help_from_qdict(args);
qobject_unref(args);
return false;
return NULL;
}
v = qobject_input_visitor_new_keyval(QOBJECT(args));
......@@ -316,12 +316,20 @@ bool user_creatable_add_from_str(const char *optarg, Error **errp)
visit_free(v);
qobject_unref(args);
if (*errp) {
goto out;
return options;
}
bool user_creatable_add_from_str(const char *optarg, Error **errp)
{
ERRP_GUARD();
ObjectOptions *options;
options = user_creatable_parse_str(optarg, errp);
if (!options) {
return false;
}
user_creatable_add_qapi(options, errp);
out:
qapi_free_ObjectOptions(options);
return !*errp;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment