Add the flags argument in object_property_try_add() and
object_class_property_try_add(), allowing callers to explicitly specify
the property flags during creation.
This will be helpful to extend qdev property definition to support
marking as deprecated or internal-only.
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
---
include/qom/object.h | 21 ++++++++++++++++-----
qom/object.c | 19 ++++++++++---------
2 files changed, 26 insertions(+), 14 deletions(-)
diff --git a/include/qom/object.h b/include/qom/object.h
index 060db136988b..7d8a7be1bad3 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -1103,6 +1103,11 @@ void object_unref(void *obj);
* @release: called when the property is removed from the object. This is
* meant to allow a property to free its opaque upon object
* destruction. This may be NULL.
+ * @flags: property flags used to control property uses. The
+ * OBJ_PROP_FLAG_READ and OBJ_PROP_FLAG_WRITE flags are automatically
+ * set based on the presence of the @get and @set callbacks. The value
+ * passed here is bitwise-ORed with those automatic flags. Pass 0 if no
+ * other flags are needed.
* @opaque: an opaque pointer to pass to the callbacks for the property
* @errp: pointer to error object
*
@@ -1114,12 +1119,13 @@ ObjectProperty *object_property_try_add(Object *obj, const char *name,
ObjectPropertyAccessor *get,
ObjectPropertyAccessor *set,
ObjectPropertyRelease *release,
+ ObjectPropertyFlags flags,
void *opaque, Error **errp);
/**
* object_property_add:
- * Same as object_property_try_add() with @errp hardcoded to
- * &error_abort.
+ * Same as object_property_try_add() with @flags hardcoded to 0 and @errp
+ * hardcoded to &error_abort.
*
* @obj: the object to add a property to
* @name: the name of the property. This can contain any character except for
@@ -1164,6 +1170,11 @@ void object_property_del(Object *obj, const char *name);
* @release: called when the property is removed from the object. This is
* meant to allow a property to free its opaque upon object
* destruction. This may be NULL.
+ * @flags: property flags used to control property uses. The
+ * OBJ_PROP_FLAG_READ and OBJ_PROP_FLAG_WRITE flags are automatically
+ * set based on the presence of the @get and @set callbacks. The value
+ * passed here is bitwise-ORed with those automatic flags. Pass 0 if no
+ * other flags are needed.
* @opaque: an opaque pointer to pass to the callbacks for the property
* @errp: pointer to error object
*
@@ -1175,13 +1186,13 @@ ObjectProperty *object_class_property_try_add(ObjectClass *klass, const char *na
ObjectPropertyAccessor *get,
ObjectPropertyAccessor *set,
ObjectPropertyRelease *release,
+ ObjectPropertyFlags flags,
void *opaque, Error **errp);
-
/**
* object_class_property_add:
- * Same as object_class_property_try_add() with @errp hardcoded to
- * &error_abort.
+ * Same as object_class_property_try_add() with @flags hardcoded to 0 and @errp
+ * hardcoded to &error_abort.
*
* @klass: the object class to add a property to
* @name: the name of the property. This can contain any character except for
diff --git a/qom/object.c b/qom/object.c
index f101b48154d1..543e42cd6f16 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -1233,10 +1233,9 @@ void object_unref(void *objptr)
}
}
-static inline void object_property_flags_init(ObjectProperty *prop)
+static inline void object_property_flags_init(ObjectProperty *prop,
+ ObjectPropertyFlags flags)
{
- uint8_t flags = 0;
-
if (prop->set) {
flags |= OBJ_PROP_FLAG_WRITE;
}
@@ -1251,6 +1250,7 @@ object_property_try_add(Object *obj, const char *name, const char *type,
ObjectPropertyAccessor *get,
ObjectPropertyAccessor *set,
ObjectPropertyRelease *release,
+ ObjectPropertyFlags flags,
void *opaque, Error **errp)
{
ObjectProperty *prop;
@@ -1266,7 +1266,7 @@ object_property_try_add(Object *obj, const char *name, const char *type,
char *full_name = g_strdup_printf("%s[%d]", name_no_array, i);
ret = object_property_try_add(obj, full_name, type, get, set,
- release, opaque, NULL);
+ release, flags, opaque, NULL);
g_free(full_name);
if (ret) {
break;
@@ -1292,7 +1292,7 @@ object_property_try_add(Object *obj, const char *name, const char *type,
prop->set = set;
prop->release = release;
prop->opaque = opaque;
- object_property_flags_init(prop);
+ object_property_flags_init(prop, flags);
g_hash_table_insert(obj->properties, prop->name, prop);
return prop;
@@ -1306,7 +1306,7 @@ object_property_add(Object *obj, const char *name, const char *type,
void *opaque)
{
return object_property_try_add(obj, name, type, get, set, release,
- opaque, &error_abort);
+ 0, opaque, &error_abort);
}
ObjectProperty *
@@ -1316,6 +1316,7 @@ object_class_property_try_add(ObjectClass *klass,
ObjectPropertyAccessor *get,
ObjectPropertyAccessor *set,
ObjectPropertyRelease *release,
+ ObjectPropertyFlags flags,
void *opaque, Error **errp)
{
ObjectProperty *prop;
@@ -1336,7 +1337,7 @@ object_class_property_try_add(ObjectClass *klass,
prop->set = set;
prop->release = release;
prop->opaque = opaque;
- object_property_flags_init(prop);
+ object_property_flags_init(prop, flags);
g_hash_table_insert(klass->properties, prop->name, prop);
return prop;
@@ -1352,7 +1353,7 @@ object_class_property_add(ObjectClass *klass,
void *opaque)
{
return object_class_property_try_add(klass, name, type, get, set, release,
- opaque, &error_abort);
+ 0, opaque, &error_abort);
}
ObjectProperty *object_property_find(Object *obj, const char *name)
@@ -1863,7 +1864,7 @@ object_property_try_add_child(Object *obj, const char *name,
type = g_strdup_printf("child<%s>", object_get_typename(child));
op = object_property_try_add(obj, name, type, object_get_child_property,
- NULL, object_finalize_child_property,
+ NULL, object_finalize_child_property, 0,
child, errp);
if (!op) {
return NULL;
--
2.34.1