Now that all callers use object_class_property_add_qapi_enum(), remove the legacy object_property_add_enum() and object_class_property_add_enum() functions along with their EnumProperty struct and property_get_enum / property_set_enum helpers.
Simplify object_property_get_enum() to assert on qapi_type rather than falling back to the old EnumProperty opaque data. Signed-off-by: Marc-André Lureau <[email protected]> --- include/qom/object.h | 31 ++----------------- qom/object.c | 84 ++-------------------------------------------------- 2 files changed, 5 insertions(+), 110 deletions(-) diff --git a/include/qom/object.h b/include/qom/object.h index 0eaa02688b0..14238e4b844 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -1577,12 +1577,12 @@ char *object_get_canonical_path(const Object *obj); * because it was ambiguous, or %NULL. Set to %false on success. * * There are two types of supported paths--absolute paths and partial paths. - * + * * Absolute paths are derived from the root object and can follow child<> or * link<> properties. Since they can follow link<> properties, they can be * arbitrarily long. Absolute paths look like absolute filenames and are * prefixed with a leading slash. - * + * * Partial paths look like relative filenames. They do not begin with a * prefix. The matching rules for partial paths are subtle but designed to make * specifying objects easy. At each level of the composition tree, the partial @@ -1797,33 +1797,6 @@ ObjectProperty *object_class_property_add_bool(ObjectClass *klass, bool (*get)(Object *, Error **), void (*set)(Object *, bool, Error **)); -/** - * object_property_add_enum: - * @obj: the object to add a property to - * @name: the name of the property - * @typename: the name of the enum data type - * @lookup: enum value namelookup table - * @get: the getter or %NULL if the property is write-only. - * @set: the setter or %NULL if the property is read-only - * - * Add an enum property using getters/setters. This function will add a - * property of type '@typename'. - * - * Returns: The newly added property on success, or %NULL on failure. - */ -ObjectProperty *object_property_add_enum(Object *obj, const char *name, - const char *typename, - const QEnumLookup *lookup, - int (*get)(Object *, Error **), - void (*set)(Object *, int, Error **)); - -ObjectProperty *object_class_property_add_enum(ObjectClass *klass, - const char *name, - const char *typename, - const QEnumLookup *lookup, - int (*get)(Object *, Error **), - void (*set)(Object *, int, Error **)); - /** * struct QapiEnumProp - Descriptor for a QOM property backed by a QAPI enum type * diff --git a/qom/object.c b/qom/object.c index 164907289a6..48d7a88ee43 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1055,7 +1055,7 @@ static void object_class_foreach_tramp(gpointer key, gpointer value, return; } - if (data->implements_type && + if (data->implements_type && !object_class_dynamic_cast(k, data->implements_type)) { return; } @@ -1603,12 +1603,6 @@ uint64_t object_property_get_uint(Object *obj, const char *name, return retval; } -typedef struct EnumProperty { - const QEnumLookup *lookup; - int (*get)(Object *, Error **); - void (*set)(Object *, int, Error **); -} EnumProperty; - int object_property_get_enum(Object *obj, const char *name, const char *typename, Error **errp) { @@ -1632,12 +1626,8 @@ int object_property_get_enum(Object *obj, const char *name, return -1; } - if (prop->qapi_type) { - ret = qapi_enum_parse(prop->qapi_type->lookup, str, -1, errp); - } else { - EnumProperty *enumprop = prop->opaque; - ret = qapi_enum_parse(enumprop->lookup, str, -1, errp); - } + assert(prop->qapi_type); + ret = qapi_enum_parse(prop->qapi_type->lookup, str, -1, errp); g_free(str); return ret; @@ -2362,74 +2352,6 @@ object_class_property_add_bool(ObjectClass *klass, const char *name, prop); } -static void property_get_enum(Object *obj, Visitor *v, const char *name, - void *opaque, Error **errp) -{ - EnumProperty *prop = opaque; - int value; - Error *err = NULL; - - value = prop->get(obj, &err); - if (err) { - error_propagate(errp, err); - return; - } - - visit_type_enum(v, name, &value, prop->lookup, errp); -} - -static void property_set_enum(Object *obj, Visitor *v, const char *name, - void *opaque, Error **errp) -{ - EnumProperty *prop = opaque; - int value; - - if (!visit_type_enum(v, name, &value, prop->lookup, errp)) { - return; - } - prop->set(obj, value, errp); -} - -ObjectProperty * -object_property_add_enum(Object *obj, const char *name, - const char *typename, - const QEnumLookup *lookup, - int (*get)(Object *, Error **), - void (*set)(Object *, int, Error **)) -{ - EnumProperty *prop = g_malloc(sizeof(*prop)); - - prop->lookup = lookup; - prop->get = get; - prop->set = set; - - return object_property_add(obj, name, typename, - get ? property_get_enum : NULL, - set ? property_set_enum : NULL, - property_release_data, - prop); -} - -ObjectProperty * -object_class_property_add_enum(ObjectClass *klass, const char *name, - const char *typename, - const QEnumLookup *lookup, - int (*get)(Object *, Error **), - void (*set)(Object *, int, Error **)) -{ - EnumProperty *prop = g_malloc(sizeof(*prop)); - - prop->lookup = lookup; - prop->get = get; - prop->set = set; - - return object_class_property_add(klass, name, typename, - get ? property_get_enum : NULL, - set ? property_set_enum : NULL, - NULL, - prop); -} - static void get_qapi_enum(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { -- 2.54.0
