aboutsummaryrefslogtreecommitdiff
path: root/qom/object_interfaces.c
diff options
context:
space:
mode:
Diffstat (limited to 'qom/object_interfaces.c')
-rw-r--r--qom/object_interfaces.c51
1 files changed, 50 insertions, 1 deletions
diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
index 02c3934329..e10a5cf6f0 100644
--- a/qom/object_interfaces.c
+++ b/qom/object_interfaces.c
@@ -2,10 +2,13 @@
#include "qemu/cutils.h"
#include "qapi/error.h"
+#include "qapi/qapi-commands-qom.h"
+#include "qapi/qapi-visit-qom.h"
#include "qapi/qmp/qdict.h"
#include "qapi/qmp/qerror.h"
#include "qapi/qmp/qjson.h"
#include "qapi/qobject-input-visitor.h"
+#include "qapi/qobject-output-visitor.h"
#include "qom/object_interfaces.h"
#include "qemu/help_option.h"
#include "qemu/id.h"
@@ -113,6 +116,30 @@ out:
return obj;
}
+void user_creatable_add_qapi(ObjectOptions *options, Error **errp)
+{
+ Visitor *v;
+ QObject *qobj;
+ QDict *props;
+ Object *obj;
+
+ v = qobject_output_visitor_new(&qobj);
+ visit_type_ObjectOptions(v, NULL, &options, &error_abort);
+ visit_complete(v, &qobj);
+ visit_free(v);
+
+ props = qobject_to(QDict, qobj);
+ qdict_del(props, "qom-type");
+ qdict_del(props, "id");
+
+ v = qobject_input_visitor_new(QOBJECT(props));
+ obj = user_creatable_add_type(ObjectType_str(options->qom_type),
+ options->id, props, v, errp);
+ object_unref(obj);
+ qobject_unref(qobj);
+ visit_free(v);
+}
+
Object *user_creatable_add_opts(QemuOpts *opts, Error **errp)
{
Visitor *v;
@@ -256,7 +283,7 @@ bool user_creatable_print_help(const char *type, QemuOpts *opts)
return false;
}
-void user_creatable_print_help_from_qdict(QDict *args)
+static void user_creatable_print_help_from_qdict(QDict *args)
{
const char *type = qdict_get_try_str(args, "qom-type");
@@ -265,6 +292,28 @@ void user_creatable_print_help_from_qdict(QDict *args)
}
}
+void user_creatable_process_cmdline(const char *optarg)
+{
+ QDict *args;
+ bool help;
+ Visitor *v;
+ ObjectOptions *options;
+
+ args = keyval_parse(optarg, "qom-type", &help, &error_fatal);
+ if (help) {
+ user_creatable_print_help_from_qdict(args);
+ exit(EXIT_SUCCESS);
+ }
+
+ v = qobject_input_visitor_new_keyval(QOBJECT(args));
+ visit_type_ObjectOptions(v, NULL, &options, &error_fatal);
+ visit_free(v);
+ qobject_unref(args);
+
+ user_creatable_add_qapi(options, &error_fatal);
+ qapi_free_ObjectOptions(options);
+}
+
bool user_creatable_del(const char *id, Error **errp)
{
QemuOptsList *opts_list;