object: make object_class_property_add* return property

This will help calling other ObjectProperty associated functions
easily after.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20200110153039.1379601-9-marcandre.lureau@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Marc-André Lureau 2020-01-10 19:30:21 +04:00 committed by Paolo Bonzini
parent 2a1be4b348
commit a3a162113e
2 changed files with 60 additions and 28 deletions

View File

@ -1539,7 +1539,8 @@ void object_property_add_str(Object *obj, const char *name,
void (*set)(Object *, const char *, Error **), void (*set)(Object *, const char *, Error **),
Error **errp); Error **errp);
void object_class_property_add_str(ObjectClass *klass, const char *name, ObjectProperty *object_class_property_add_str(ObjectClass *klass,
const char *name,
char *(*get)(Object *, Error **), char *(*get)(Object *, Error **),
void (*set)(Object *, const char *, void (*set)(Object *, const char *,
Error **), Error **),
@ -1561,7 +1562,8 @@ void object_property_add_bool(Object *obj, const char *name,
void (*set)(Object *, bool, Error **), void (*set)(Object *, bool, Error **),
Error **errp); Error **errp);
void object_class_property_add_bool(ObjectClass *klass, const char *name, ObjectProperty *object_class_property_add_bool(ObjectClass *klass,
const char *name,
bool (*get)(Object *, Error **), bool (*get)(Object *, Error **),
void (*set)(Object *, bool, Error **), void (*set)(Object *, bool, Error **),
Error **errp); Error **errp);
@ -1585,7 +1587,8 @@ void object_property_add_enum(Object *obj, const char *name,
void (*set)(Object *, int, Error **), void (*set)(Object *, int, Error **),
Error **errp); Error **errp);
void object_class_property_add_enum(ObjectClass *klass, const char *name, ObjectProperty *object_class_property_add_enum(ObjectClass *klass,
const char *name,
const char *typename, const char *typename,
const QEnumLookup *lookup, const QEnumLookup *lookup,
int (*get)(Object *, Error **), int (*get)(Object *, Error **),
@ -1606,7 +1609,8 @@ void object_property_add_tm(Object *obj, const char *name,
void (*get)(Object *, struct tm *, Error **), void (*get)(Object *, struct tm *, Error **),
Error **errp); Error **errp);
void object_class_property_add_tm(ObjectClass *klass, const char *name, ObjectProperty *object_class_property_add_tm(ObjectClass *klass,
const char *name,
void (*get)(Object *, struct tm *, Error **), void (*get)(Object *, struct tm *, Error **),
Error **errp); Error **errp);
@ -1622,7 +1626,8 @@ void object_class_property_add_tm(ObjectClass *klass, const char *name,
*/ */
void object_property_add_uint8_ptr(Object *obj, const char *name, void object_property_add_uint8_ptr(Object *obj, const char *name,
const uint8_t *v, Error **errp); const uint8_t *v, Error **errp);
void object_class_property_add_uint8_ptr(ObjectClass *klass, const char *name, ObjectProperty *object_class_property_add_uint8_ptr(ObjectClass *klass,
const char *name,
const uint8_t *v, Error **errp); const uint8_t *v, Error **errp);
/** /**
@ -1637,7 +1642,8 @@ void object_class_property_add_uint8_ptr(ObjectClass *klass, const char *name,
*/ */
void object_property_add_uint16_ptr(Object *obj, const char *name, void object_property_add_uint16_ptr(Object *obj, const char *name,
const uint16_t *v, Error **errp); const uint16_t *v, Error **errp);
void object_class_property_add_uint16_ptr(ObjectClass *klass, const char *name, ObjectProperty *object_class_property_add_uint16_ptr(ObjectClass *klass,
const char *name,
const uint16_t *v, Error **errp); const uint16_t *v, Error **errp);
/** /**
@ -1652,7 +1658,8 @@ void object_class_property_add_uint16_ptr(ObjectClass *klass, const char *name,
*/ */
void object_property_add_uint32_ptr(Object *obj, const char *name, void object_property_add_uint32_ptr(Object *obj, const char *name,
const uint32_t *v, Error **errp); const uint32_t *v, Error **errp);
void object_class_property_add_uint32_ptr(ObjectClass *klass, const char *name, ObjectProperty *object_class_property_add_uint32_ptr(ObjectClass *klass,
const char *name,
const uint32_t *v, Error **errp); const uint32_t *v, Error **errp);
/** /**
@ -1667,7 +1674,8 @@ void object_class_property_add_uint32_ptr(ObjectClass *klass, const char *name,
*/ */
void object_property_add_uint64_ptr(Object *obj, const char *name, void object_property_add_uint64_ptr(Object *obj, const char *name,
const uint64_t *v, Error **errp); const uint64_t *v, Error **errp);
void object_class_property_add_uint64_ptr(ObjectClass *klass, const char *name, ObjectProperty *object_class_property_add_uint64_ptr(ObjectClass *klass,
const char *name,
const uint64_t *v, Error **errp); const uint64_t *v, Error **errp);
/** /**

View File

@ -2065,7 +2065,8 @@ void object_property_add_str(Object *obj, const char *name,
} }
} }
void object_class_property_add_str(ObjectClass *klass, const char *name, ObjectProperty *
object_class_property_add_str(ObjectClass *klass, const char *name,
char *(*get)(Object *, Error **), char *(*get)(Object *, Error **),
void (*set)(Object *, const char *, void (*set)(Object *, const char *,
Error **), Error **),
@ -2073,11 +2074,12 @@ void object_class_property_add_str(ObjectClass *klass, const char *name,
{ {
Error *local_err = NULL; Error *local_err = NULL;
StringProperty *prop = g_malloc0(sizeof(*prop)); StringProperty *prop = g_malloc0(sizeof(*prop));
ObjectProperty *rv;
prop->get = get; prop->get = get;
prop->set = set; prop->set = set;
object_class_property_add(klass, name, "string", rv = object_class_property_add(klass, name, "string",
get ? property_get_str : NULL, get ? property_get_str : NULL,
set ? property_set_str : NULL, set ? property_set_str : NULL,
property_release_str, property_release_str,
@ -2086,6 +2088,8 @@ void object_class_property_add_str(ObjectClass *klass, const char *name,
error_propagate(errp, local_err); error_propagate(errp, local_err);
g_free(prop); g_free(prop);
} }
return rv;
} }
typedef struct BoolProperty typedef struct BoolProperty
@ -2155,18 +2159,20 @@ void object_property_add_bool(Object *obj, const char *name,
} }
} }
void object_class_property_add_bool(ObjectClass *klass, const char *name, ObjectProperty *
object_class_property_add_bool(ObjectClass *klass, const char *name,
bool (*get)(Object *, Error **), bool (*get)(Object *, Error **),
void (*set)(Object *, bool, Error **), void (*set)(Object *, bool, Error **),
Error **errp) Error **errp)
{ {
Error *local_err = NULL; Error *local_err = NULL;
BoolProperty *prop = g_malloc0(sizeof(*prop)); BoolProperty *prop = g_malloc0(sizeof(*prop));
ObjectProperty *rv;
prop->get = get; prop->get = get;
prop->set = set; prop->set = set;
object_class_property_add(klass, name, "bool", rv = object_class_property_add(klass, name, "bool",
get ? property_get_bool : NULL, get ? property_get_bool : NULL,
set ? property_set_bool : NULL, set ? property_set_bool : NULL,
property_release_bool, property_release_bool,
@ -2175,6 +2181,8 @@ void object_class_property_add_bool(ObjectClass *klass, const char *name,
error_propagate(errp, local_err); error_propagate(errp, local_err);
g_free(prop); g_free(prop);
} }
return rv;
} }
static void property_get_enum(Object *obj, Visitor *v, const char *name, static void property_get_enum(Object *obj, Visitor *v, const char *name,
@ -2240,7 +2248,8 @@ void object_property_add_enum(Object *obj, const char *name,
} }
} }
void object_class_property_add_enum(ObjectClass *klass, const char *name, ObjectProperty *
object_class_property_add_enum(ObjectClass *klass, const char *name,
const char *typename, const char *typename,
const QEnumLookup *lookup, const QEnumLookup *lookup,
int (*get)(Object *, Error **), int (*get)(Object *, Error **),
@ -2249,12 +2258,13 @@ void object_class_property_add_enum(ObjectClass *klass, const char *name,
{ {
Error *local_err = NULL; Error *local_err = NULL;
EnumProperty *prop = g_malloc(sizeof(*prop)); EnumProperty *prop = g_malloc(sizeof(*prop));
ObjectProperty *rv;
prop->lookup = lookup; prop->lookup = lookup;
prop->get = get; prop->get = get;
prop->set = set; prop->set = set;
object_class_property_add(klass, name, typename, rv = object_class_property_add(klass, name, typename,
get ? property_get_enum : NULL, get ? property_get_enum : NULL,
set ? property_set_enum : NULL, set ? property_set_enum : NULL,
property_release_enum, property_release_enum,
@ -2263,6 +2273,8 @@ void object_class_property_add_enum(ObjectClass *klass, const char *name,
error_propagate(errp, local_err); error_propagate(errp, local_err);
g_free(prop); g_free(prop);
} }
return rv;
} }
typedef struct TMProperty { typedef struct TMProperty {
@ -2343,16 +2355,18 @@ void object_property_add_tm(Object *obj, const char *name,
} }
} }
void object_class_property_add_tm(ObjectClass *klass, const char *name, ObjectProperty *
object_class_property_add_tm(ObjectClass *klass, const char *name,
void (*get)(Object *, struct tm *, Error **), void (*get)(Object *, struct tm *, Error **),
Error **errp) Error **errp)
{ {
Error *local_err = NULL; Error *local_err = NULL;
TMProperty *prop = g_malloc0(sizeof(*prop)); TMProperty *prop = g_malloc0(sizeof(*prop));
ObjectProperty *rv;
prop->get = get; prop->get = get;
object_class_property_add(klass, name, "struct tm", rv = object_class_property_add(klass, name, "struct tm",
get ? property_get_tm : NULL, NULL, get ? property_get_tm : NULL, NULL,
property_release_tm, property_release_tm,
prop, &local_err); prop, &local_err);
@ -2360,6 +2374,8 @@ void object_class_property_add_tm(ObjectClass *klass, const char *name,
error_propagate(errp, local_err); error_propagate(errp, local_err);
g_free(prop); g_free(prop);
} }
return rv;
} }
static char *qdev_get_type(Object *obj, Error **errp) static char *qdev_get_type(Object *obj, Error **errp)
@ -2402,11 +2418,13 @@ void object_property_add_uint8_ptr(Object *obj, const char *name,
NULL, NULL, (void *)v, errp); NULL, NULL, (void *)v, errp);
} }
void object_class_property_add_uint8_ptr(ObjectClass *klass, const char *name, ObjectProperty *
object_class_property_add_uint8_ptr(ObjectClass *klass, const char *name,
const uint8_t *v, Error **errp) const uint8_t *v, Error **errp)
{ {
object_class_property_add(klass, name, "uint8", property_get_uint8_ptr, return object_class_property_add(klass, name, "uint8",
NULL, NULL, (void *)v, errp); property_get_uint8_ptr,
NULL, NULL, (void *)v, errp);
} }
void object_property_add_uint16_ptr(Object *obj, const char *name, void object_property_add_uint16_ptr(Object *obj, const char *name,
@ -2416,11 +2434,13 @@ void object_property_add_uint16_ptr(Object *obj, const char *name,
NULL, NULL, (void *)v, errp); NULL, NULL, (void *)v, errp);
} }
void object_class_property_add_uint16_ptr(ObjectClass *klass, const char *name, ObjectProperty *
object_class_property_add_uint16_ptr(ObjectClass *klass, const char *name,
const uint16_t *v, Error **errp) const uint16_t *v, Error **errp)
{ {
object_class_property_add(klass, name, "uint16", property_get_uint16_ptr, return object_class_property_add(klass, name, "uint16",
NULL, NULL, (void *)v, errp); property_get_uint16_ptr,
NULL, NULL, (void *)v, errp);
} }
void object_property_add_uint32_ptr(Object *obj, const char *name, void object_property_add_uint32_ptr(Object *obj, const char *name,
@ -2430,11 +2450,13 @@ void object_property_add_uint32_ptr(Object *obj, const char *name,
NULL, NULL, (void *)v, errp); NULL, NULL, (void *)v, errp);
} }
void object_class_property_add_uint32_ptr(ObjectClass *klass, const char *name, ObjectProperty *
object_class_property_add_uint32_ptr(ObjectClass *klass, const char *name,
const uint32_t *v, Error **errp) const uint32_t *v, Error **errp)
{ {
object_class_property_add(klass, name, "uint32", property_get_uint32_ptr, return object_class_property_add(klass, name, "uint32",
NULL, NULL, (void *)v, errp); property_get_uint32_ptr,
NULL, NULL, (void *)v, errp);
} }
void object_property_add_uint64_ptr(Object *obj, const char *name, void object_property_add_uint64_ptr(Object *obj, const char *name,
@ -2444,11 +2466,13 @@ void object_property_add_uint64_ptr(Object *obj, const char *name,
NULL, NULL, (void *)v, errp); NULL, NULL, (void *)v, errp);
} }
void object_class_property_add_uint64_ptr(ObjectClass *klass, const char *name, ObjectProperty *
object_class_property_add_uint64_ptr(ObjectClass *klass, const char *name,
const uint64_t *v, Error **errp) const uint64_t *v, Error **errp)
{ {
object_class_property_add(klass, name, "uint64", property_get_uint64_ptr, return object_class_property_add(klass, name, "uint64",
NULL, NULL, (void *)v, errp); property_get_uint64_ptr,
NULL, NULL, (void *)v, errp);
} }
typedef struct { typedef struct {