[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 46/59] object: add object_class_property_add_link()
From: |
Paolo Bonzini |
Subject: |
[PULL 46/59] object: add object_class_property_add_link() |
Date: |
Thu, 23 Jan 2020 14:48:49 +0100 |
From: Marc-André Lureau <address@hidden>
Signed-off-by: Marc-André Lureau <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
include/qom/object.h | 9 +++++++++
qom/object.c | 46 +++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 54 insertions(+), 1 deletion(-)
diff --git a/include/qom/object.h b/include/qom/object.h
index 5b02be6..ead9129 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -1531,6 +1531,7 @@ typedef enum {
/* private */
OBJ_PROP_LINK_DIRECT = 0x2,
+ OBJ_PROP_LINK_CLASS = 0x4,
} ObjectPropertyLinkFlags;
/**
@@ -1579,6 +1580,14 @@ void object_property_add_link(Object *obj, const char
*name,
ObjectPropertyLinkFlags flags,
Error **errp);
+ObjectProperty *object_class_property_add_link(ObjectClass *oc,
+ const char *name,
+ const char *type, ptrdiff_t offset,
+ void (*check)(const Object *obj, const char
*name,
+ Object *val, Error **errp),
+ ObjectPropertyLinkFlags flags,
+ Error **errp);
+
/**
* object_property_add_str:
* @obj: the object to add a property to
diff --git a/qom/object.c b/qom/object.c
index e6617c2..202d576 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -1732,6 +1732,7 @@ typedef struct {
union {
Object **targetp;
Object *target; /* if OBJ_PROP_LINK_DIRECT, when holding the pointer
*/
+ ptrdiff_t offset; /* if OBJ_PROP_LINK_CLASS */
};
void (*check)(const Object *, const char *, Object *, Error **);
ObjectPropertyLinkFlags flags;
@@ -1742,6 +1743,8 @@ object_link_get_targetp(Object *obj, LinkProperty *lprop)
{
if (lprop->flags & OBJ_PROP_LINK_DIRECT) {
return &lprop->target;
+ } else if (lprop->flags & OBJ_PROP_LINK_CLASS) {
+ return (void *)obj + lprop->offset;
} else {
return lprop->targetp;
}
@@ -1857,7 +1860,9 @@ static void object_release_link_property(Object *obj,
const char *name,
if ((prop->flags & OBJ_PROP_LINK_STRONG) && *targetp) {
object_unref(*targetp);
}
- g_free(prop);
+ if (!(prop->flags & OBJ_PROP_LINK_CLASS)) {
+ g_free(prop);
+ }
}
static void object_add_link_prop(Object *obj, const char *name,
@@ -1910,6 +1915,45 @@ void object_property_add_link(Object *obj, const char
*name,
object_add_link_prop(obj, name, type, targetp, check, flags, errp);
}
+ObjectProperty *
+object_class_property_add_link(ObjectClass *oc,
+ const char *name,
+ const char *type, ptrdiff_t offset,
+ void (*check)(const Object *obj, const char *name,
+ Object *val, Error **errp),
+ ObjectPropertyLinkFlags flags,
+ Error **errp)
+{
+ Error *local_err = NULL;
+ LinkProperty *prop = g_new0(LinkProperty, 1);
+ gchar *full_type;
+ ObjectProperty *op;
+
+ prop->offset = offset;
+ prop->check = check;
+ prop->flags = flags | OBJ_PROP_LINK_CLASS;
+
+ full_type = g_strdup_printf("link<%s>", type);
+
+ op = object_class_property_add(oc, name, full_type,
+ object_get_link_property,
+ check ? object_set_link_property : NULL,
+ object_release_link_property,
+ prop,
+ &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ g_free(prop);
+ goto out;
+ }
+
+ op->resolve = object_resolve_link_property;
+
+out:
+ g_free(full_type);
+ return op;
+}
+
void object_property_add_const_link(Object *obj, const char *name,
Object *target, Error **errp)
{
--
1.8.3.1
- [PULL 38/59] object: make object_class_property_add* return property, (continued)
- [PULL 38/59] object: make object_class_property_add* return property, Paolo Bonzini, 2020/01/23
- [PULL 39/59] qstring: add qstring_free(), Paolo Bonzini, 2020/01/23
- [PULL 40/59] object: add object_property_set_defaut_{bool, str, int, uint}(), Paolo Bonzini, 2020/01/23
- [PULL 41/59] object: do not free class properties, Paolo Bonzini, 2020/01/23
- [PULL 42/59] object: check strong flag with &, Paolo Bonzini, 2020/01/23
- [PULL 43/59] object: rename link "child" to "target", Paolo Bonzini, 2020/01/23
- [PULL 47/59] object: release all props, Paolo Bonzini, 2020/01/23
- [PULL 44/59] object: add direct link flag, Paolo Bonzini, 2020/01/23
- [PULL 45/59] object: express const link with link property, Paolo Bonzini, 2020/01/23
- [PULL 48/59] object: return self in object_ref(), Paolo Bonzini, 2020/01/23
- [PULL 46/59] object: add object_class_property_add_link(),
Paolo Bonzini <=
- [PULL 50/59] qdev: move instance properties to class properties, Paolo Bonzini, 2020/01/23
- [PULL 49/59] qdev: set properties with device_class_set_props(), Paolo Bonzini, 2020/01/23