qom: drop user_creatable_add_type method
This can be replaced by object_new_with_props_from_qdict, which does functionally the same job, but the caller does not own the returned reference, instead the parent object owns it. In one case we can use object_new_with_props_from_qdict_owned instead since the object is not intended to have any parent. Tested-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:
@@ -79,8 +79,8 @@ qauthz_list_file_load(QAuthZListFile *fauthz, Error **errp)
|
|||||||
|
|
||||||
v = qobject_input_visitor_new(obj);
|
v = qobject_input_visitor_new(obj);
|
||||||
|
|
||||||
ret = (QAuthZ *)user_creatable_add_type(TYPE_QAUTHZ_LIST,
|
ret = QAUTHZ(object_new_with_props_from_qdict_parentless(
|
||||||
NULL, pdict, v, errp);
|
TYPE_QAUTHZ_LIST, pdict, v, errp));
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
visit_free(v);
|
visit_free(v);
|
||||||
|
|||||||
@@ -69,24 +69,6 @@ bool user_creatable_complete(UserCreatable *uc, Error **errp);
|
|||||||
*/
|
*/
|
||||||
bool user_creatable_can_be_deleted(UserCreatable *uc);
|
bool user_creatable_can_be_deleted(UserCreatable *uc);
|
||||||
|
|
||||||
/**
|
|
||||||
* user_creatable_add_type:
|
|
||||||
* @type: the object type name
|
|
||||||
* @id: the unique ID for the object
|
|
||||||
* @qdict: the object properties
|
|
||||||
* @v: the visitor
|
|
||||||
* @errp: if an error occurs, a pointer to an area to store the error
|
|
||||||
*
|
|
||||||
* Create an instance of the user creatable object @type, placing
|
|
||||||
* it in the object composition tree with name @id, initializing
|
|
||||||
* it with properties from @qdict
|
|
||||||
*
|
|
||||||
* Returns: the newly created object or NULL on error
|
|
||||||
*/
|
|
||||||
Object *user_creatable_add_type(const char *type, const char *id,
|
|
||||||
const QDict *qdict,
|
|
||||||
Visitor *v, Error **errp);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* user_creatable_add_qapi:
|
* user_creatable_add_qapi:
|
||||||
* @options: the object definition
|
* @options: the object definition
|
||||||
|
|||||||
@@ -44,75 +44,11 @@ bool user_creatable_can_be_deleted(UserCreatable *uc)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Object *user_creatable_add_type(const char *type, const char *id,
|
|
||||||
const QDict *qdict,
|
|
||||||
Visitor *v, Error **errp)
|
|
||||||
{
|
|
||||||
ERRP_GUARD();
|
|
||||||
Object *obj;
|
|
||||||
ObjectClass *klass;
|
|
||||||
Error *local_err = NULL;
|
|
||||||
|
|
||||||
if (id != NULL && !id_wellformed(id)) {
|
|
||||||
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "id", "an identifier");
|
|
||||||
error_append_hint(errp, "Identifiers consist of letters, digits, "
|
|
||||||
"'-', '.', '_', starting with a letter.\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
klass = module_object_class_by_name(type);
|
|
||||||
if (!klass) {
|
|
||||||
error_setg(errp, "invalid object type: %s", type);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!object_class_dynamic_cast(klass, TYPE_USER_CREATABLE)) {
|
|
||||||
error_setg(errp, "object type '%s' isn't supported by object-add",
|
|
||||||
type);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (object_class_is_abstract(klass)) {
|
|
||||||
error_setg(errp, "object type '%s' is abstract", type);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(qdict);
|
|
||||||
obj = object_new_with_class(klass);
|
|
||||||
object_set_props_from_qdict(obj, qdict, v, &local_err);
|
|
||||||
if (local_err) {
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (id != NULL) {
|
|
||||||
object_property_try_add_child(object_get_objects_root(),
|
|
||||||
id, obj, &local_err);
|
|
||||||
if (local_err) {
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!user_creatable_complete(USER_CREATABLE(obj), &local_err)) {
|
|
||||||
if (id != NULL) {
|
|
||||||
object_property_del(object_get_objects_root(), id);
|
|
||||||
}
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
out:
|
|
||||||
if (local_err) {
|
|
||||||
error_propagate(errp, local_err);
|
|
||||||
object_unref(obj);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
void user_creatable_add_qapi(ObjectOptions *options, Error **errp)
|
void user_creatable_add_qapi(ObjectOptions *options, Error **errp)
|
||||||
{
|
{
|
||||||
Visitor *v;
|
Visitor *v;
|
||||||
QObject *qobj;
|
QObject *qobj;
|
||||||
QDict *props;
|
QDict *props;
|
||||||
Object *obj;
|
|
||||||
|
|
||||||
v = qobject_output_visitor_new(&qobj);
|
v = qobject_output_visitor_new(&qobj);
|
||||||
visit_type_ObjectOptions(v, NULL, &options, &error_abort);
|
visit_type_ObjectOptions(v, NULL, &options, &error_abort);
|
||||||
@@ -124,9 +60,9 @@ void user_creatable_add_qapi(ObjectOptions *options, Error **errp)
|
|||||||
qdict_del(props, "id");
|
qdict_del(props, "id");
|
||||||
|
|
||||||
v = qobject_input_visitor_new(QOBJECT(props));
|
v = qobject_input_visitor_new(QOBJECT(props));
|
||||||
obj = user_creatable_add_type(ObjectType_str(options->qom_type),
|
object_new_with_props_from_qdict(ObjectType_str(options->qom_type),
|
||||||
options->id, props, v, errp);
|
object_get_objects_root(),
|
||||||
object_unref(obj);
|
options->id, props, v, errp);
|
||||||
qobject_unref(qobj);
|
qobject_unref(qobj);
|
||||||
visit_free(v);
|
visit_free(v);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -461,10 +461,9 @@ static void test_dummy_createlist_parentless(void)
|
|||||||
static bool test_create_obj(QDict *qdict, Error **errp)
|
static bool test_create_obj(QDict *qdict, Error **errp)
|
||||||
{
|
{
|
||||||
Visitor *v = qobject_input_visitor_new_keyval(QOBJECT(qdict));
|
Visitor *v = qobject_input_visitor_new_keyval(QOBJECT(qdict));
|
||||||
Object *obj = user_creatable_add_type(TYPE_DUMMY, "dev0", qdict, v, errp);
|
Object *obj = object_new_with_props_from_qdict(
|
||||||
|
TYPE_DUMMY, object_get_objects_root(), "dev0", qdict, v, errp);
|
||||||
visit_free(v);
|
visit_free(v);
|
||||||
object_unref(obj);
|
|
||||||
return !!obj;
|
return !!obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user