qom: move object_set_prop_keyval into object.c
This matches the location of the object_set_props and object_set_propv methods, since this method is not inherently tied to the user creatable interface. As part of this, object_set_props_from_qdict is also exposed as a public API since it is still called from object_interfaces.c. Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
@@ -748,6 +748,37 @@ bool object_set_props(Object *obj, Error **errp, ...) G_GNUC_NULL_TERMINATED;
|
||||
*/
|
||||
bool object_set_propv(Object *obj, va_list vargs, Error **errp);
|
||||
|
||||
/**
|
||||
* object_set_props_from_qdict:
|
||||
* @obj: a QOM object
|
||||
* @qdict: a dictionary with the properties to be set
|
||||
* @v: a visitor to iterate over @dict
|
||||
* @errp: pointer to error object
|
||||
*
|
||||
* For each key in the dictionary, set the corresponding
|
||||
* property in @obj.
|
||||
*
|
||||
* Returns: %true on success, %false on error.
|
||||
*/
|
||||
bool object_set_props_from_qdict(Object *obj, const QDict *qdict,
|
||||
Visitor *v, Error **errp);
|
||||
|
||||
/**
|
||||
* object_set_props_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.
|
||||
*
|
||||
* Returns: %true on success, %false on error.
|
||||
*/
|
||||
bool object_set_props_from_keyval(Object *obj, const QDict *qdict,
|
||||
bool from_json, Error **errp);
|
||||
|
||||
/**
|
||||
* object_initialize:
|
||||
* @obj: A pointer to the memory to be used for the object.
|
||||
@@ -914,22 +945,6 @@ type_init(do_qemu_init_ ## type_array)
|
||||
*/
|
||||
bool type_print_class_properties(const char *type);
|
||||
|
||||
/**
|
||||
* object_set_props_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.
|
||||
*
|
||||
* Returns: %true on success, %false on error.
|
||||
*/
|
||||
bool object_set_props_from_keyval(Object *obj, const QDict *qdict,
|
||||
bool from_json, Error **errp);
|
||||
|
||||
/**
|
||||
* object_class_dynamic_cast_assert:
|
||||
* @klass: The #ObjectClass to attempt to cast.
|
||||
|
||||
36
qom/object.c
36
qom/object.c
@@ -23,6 +23,7 @@
|
||||
#include "qapi/qobject-input-visitor.h"
|
||||
#include "qapi/forward-visitor.h"
|
||||
#include "qapi/qapi-builtin-visit.h"
|
||||
#include "qobject/qdict.h"
|
||||
#include "qobject/qjson.h"
|
||||
#include "qemu/id.h"
|
||||
#include "qapi/qmp/qerror.h"
|
||||
@@ -838,6 +839,41 @@ bool object_set_propv(Object *obj,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool object_set_props_from_qdict(Object *obj, const QDict *qdict,
|
||||
Visitor *v, Error **errp)
|
||||
{
|
||||
ERRP_GUARD();
|
||||
const QDictEntry *e;
|
||||
|
||||
if (!visit_start_struct(v, NULL, NULL, 0, errp)) {
|
||||
return false;
|
||||
}
|
||||
for (e = qdict_first(qdict); e; e = qdict_next(qdict, e)) {
|
||||
if (!object_property_set(obj, e->key, v, errp)) {
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
visit_check_struct(v, errp);
|
||||
out:
|
||||
visit_end_struct(v, NULL);
|
||||
|
||||
return *errp == NULL;
|
||||
}
|
||||
|
||||
bool object_set_props_from_keyval(Object *obj, const QDict *qdict,
|
||||
bool from_json, Error **errp)
|
||||
{
|
||||
bool ret;
|
||||
Visitor *v;
|
||||
if (from_json) {
|
||||
v = qobject_input_visitor_new(QOBJECT(qdict));
|
||||
} else {
|
||||
v = qobject_input_visitor_new_keyval(QOBJECT(qdict));
|
||||
}
|
||||
ret = object_set_props_from_qdict(obj, qdict, v, errp);
|
||||
visit_free(v);
|
||||
return ret;
|
||||
}
|
||||
|
||||
Object *object_dynamic_cast(Object *obj, const char *typename)
|
||||
{
|
||||
|
||||
@@ -44,42 +44,6 @@ bool user_creatable_can_be_deleted(UserCreatable *uc)
|
||||
}
|
||||
}
|
||||
|
||||
static bool object_set_props_from_qdict(Object *obj, const QDict *qdict,
|
||||
Visitor *v, Error **errp)
|
||||
{
|
||||
ERRP_GUARD();
|
||||
const QDictEntry *e;
|
||||
|
||||
if (!visit_start_struct(v, NULL, NULL, 0, errp)) {
|
||||
return false;
|
||||
}
|
||||
for (e = qdict_first(qdict); e; e = qdict_next(qdict, e)) {
|
||||
if (!object_property_set(obj, e->key, v, errp)) {
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
visit_check_struct(v, errp);
|
||||
out:
|
||||
visit_end_struct(v, NULL);
|
||||
|
||||
return *errp == NULL;
|
||||
}
|
||||
|
||||
bool object_set_props_from_keyval(Object *obj, const QDict *qdict,
|
||||
bool from_json, Error **errp)
|
||||
{
|
||||
bool ret;
|
||||
Visitor *v;
|
||||
if (from_json) {
|
||||
v = qobject_input_visitor_new(QOBJECT(qdict));
|
||||
} else {
|
||||
v = qobject_input_visitor_new_keyval(QOBJECT(qdict));
|
||||
}
|
||||
ret = object_set_props_from_qdict(obj, qdict, v, errp);
|
||||
visit_free(v);
|
||||
return ret;
|
||||
}
|
||||
|
||||
Object *user_creatable_add_type(const char *type, const char *id,
|
||||
const QDict *qdict,
|
||||
Visitor *v, Error **errp)
|
||||
|
||||
Reference in New Issue
Block a user