This will be used to replace user_creatable_add_type with an impl
that shares most code with object_new_with_props, and is not tied
to the user creatable interface.
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
include/qom/object.h | 19 +++++++++++
qom/object.c | 75 ++++++++++++++++++++++++++++++++++++++++----
2 files changed, 88 insertions(+), 6 deletions(-)
diff --git a/include/qom/object.h b/include/qom/object.h
index be65acff93..fb1cd92d97 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -700,6 +700,25 @@ Object *object_new_with_propv(const char *typename,
va_list vargs,
Error **errp);
+/**
+ * object_new_with_props_from_qdict:
+ * @typename: The name of the type of the object to instantiate.
+ * @parent: the parent object
+ * @id: The unique ID of the object
+ * @props: dictionary of property names and values
+ * @v: visitor to iterate over @props
+ * @errp: pointer to error object
+ *
+ * A variant of object_new_with_props() which accepts the
+ * properties in a QDict.
+ */
+Object *object_new_with_props_from_qdict(const char *typename,
+ Object *parent,
+ const char *id,
+ const QDict *props,
+ Visitor *v,
+ Error **errp);
+
/**
* object_set_props:
* @obj: the object instance to set properties on
diff --git a/qom/object.c b/qom/object.c
index 3f2569d654..a11f559445 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -748,11 +748,14 @@ Object *object_new_with_props(const char *typename,
}
-Object *object_new_with_propv(const char *typename,
- Object *parent,
- const char *id,
- va_list vargs,
- Error **errp)
+static Object *
+object_new_with_props_helper(const char *typename,
+ Object *parent,
+ const char *id,
+ void *props,
+ bool (set_props)(Object *obj, void *props,
+ Error **errp),
+ Error **errp)
{
Object *obj;
ObjectClass *klass;
@@ -777,7 +780,7 @@ Object *object_new_with_propv(const char *typename,
}
obj = object_new_with_type(klass->type);
- if (!object_set_propv(obj, vargs, errp)) {
+ if (!set_props(obj, props, errp)) {
goto error;
}
@@ -803,6 +806,66 @@ Object *object_new_with_propv(const char *typename,
return NULL;
}
+struct ObjectNewVargsData {
+ va_list vargs;
+};
+
+static bool object_new_with_propv_setter(Object *obj,
+ void *props,
+ Error **errp)
+{
+ struct ObjectNewVargsData *data = props;
+ return object_set_propv(obj, data->vargs, errp);
+}
+
+Object *object_new_with_propv(const char *typename,
+ Object *parent,
+ const char *id,
+ va_list vargs,
+ Error **errp)
+{
+ Object *obj;
+ struct ObjectNewVargsData data;
+
+ va_copy(data.vargs, vargs);
+ obj = object_new_with_props_helper(typename,
+ parent,
+ id,
+ &data,
+ object_new_with_propv_setter,
+ errp);
+ va_end(data.vargs);
+ return obj;
+}
+
+struct ObjectNewQDictData {
+ const QDict *props;
+ Visitor *v;
+};
+
+static bool object_new_with_qdict_setter(Object *obj,
+ void *props,
+ Error **errp)
+{
+ struct ObjectNewQDictData *data = props;
+ return object_set_props_from_qdict(obj, data->props, data->v, errp);
+}
+
+Object *object_new_with_props_from_qdict(const char *typename,
+ Object *parent,
+ const char *id,
+ const QDict *props,
+ Visitor *v,
+ Error **errp)
+{
+ struct ObjectNewQDictData data = { props, v };
+ return object_new_with_props_helper(typename,
+ parent,
+ id,
+ &data,
+ object_new_with_qdict_setter,
+ errp);
+}
bool object_set_props(Object *obj,
Error **errp,
--
2.54.0