diff options
Diffstat (limited to 'qom/object.c')
-rw-r--r-- | qom/object.c | 52 |
1 files changed, 46 insertions, 6 deletions
diff --git a/qom/object.c b/qom/object.c index 547dcf97c3..b8c732063b 100644 --- a/qom/object.c +++ b/qom/object.c @@ -49,7 +49,6 @@ struct TypeImpl void (*class_init)(ObjectClass *klass, void *data); void (*class_base_init)(ObjectClass *klass, void *data); - void (*class_finalize)(ObjectClass *klass, void *data); void *class_data; @@ -114,7 +113,6 @@ static TypeImpl *type_new(const TypeInfo *info) ti->class_init = info->class_init; ti->class_base_init = info->class_base_init; - ti->class_finalize = info->class_finalize; ti->class_data = info->class_data; ti->instance_init = info->instance_init; @@ -372,6 +370,44 @@ static void object_post_init_with_type(Object *obj, TypeImpl *ti) } } +void object_apply_global_props(Object *obj, const GPtrArray *props, Error **errp) +{ + int i; + + if (!props) { + return; + } + + for (i = 0; i < props->len; i++) { + GlobalProperty *p = g_ptr_array_index(props, i); + Error *err = NULL; + + if (object_dynamic_cast(obj, p->driver) == NULL) { + continue; + } + if (p->optional && !object_property_find(obj, p->property, NULL)) { + continue; + } + p->used = true; + object_property_parse(obj, p->value, p->property, &err); + if (err != NULL) { + error_prepend(&err, "can't apply global %s.%s=%s: ", + p->driver, p->property, p->value); + /* + * If errp != NULL, propagate error and return. + * If errp == NULL, report a warning, but keep going + * with the remaining globals. + */ + if (errp) { + error_propagate(errp, err); + return; + } else { + warn_report_err(err); + } + } + } +} + static void object_initialize_with_type(void *data, size_t size, TypeImpl *type) { Object *obj = data; @@ -417,6 +453,7 @@ void object_initialize_childv(Object *parentobj, const char *propname, { Error *local_err = NULL; Object *obj; + UserCreatable *uc; object_initialize(childobj, size, type); obj = OBJECT(childobj); @@ -431,8 +468,9 @@ void object_initialize_childv(Object *parentobj, const char *propname, goto out; } - if (object_dynamic_cast(obj, TYPE_USER_CREATABLE)) { - user_creatable_complete(obj, &local_err); + uc = (UserCreatable *)object_dynamic_cast(obj, TYPE_USER_CREATABLE); + if (uc) { + user_creatable_complete(uc, &local_err); if (local_err) { object_unparent(obj); goto out; @@ -590,6 +628,7 @@ Object *object_new_with_propv(const char *typename, Object *obj; ObjectClass *klass; Error *local_err = NULL; + UserCreatable *uc; klass = object_class_by_name(typename); if (!klass) { @@ -612,8 +651,9 @@ Object *object_new_with_propv(const char *typename, goto error; } - if (object_dynamic_cast(obj, TYPE_USER_CREATABLE)) { - user_creatable_complete(obj, &local_err); + uc = (UserCreatable *)object_dynamic_cast(obj, TYPE_USER_CREATABLE); + if (uc) { + user_creatable_complete(uc, &local_err); if (local_err) { object_unparent(obj); goto error; |