On 01/05/2015 16:09, Eduardo Habkost wrote: > +void object_property_add_const_link(Object *obj, const char *name, > + const char *type, Object *child, > + ObjectPropertyLinkFlags flags, > + Error **errp) > +{ > + Object **childp = g_new0(Object*, 1); > + > + *childp = child; > + object_property_add_link(obj, name, type, childp, NULL, > + flags | OBJ_PROP_LINK_FREE_CHILD_POINTER, errp); > +} > +
This works, but is the extra functionality needed, compared to an alias? Namely, when is flags going to be != 0? FWIW, here is my ./.. patch. I'm all for adding a helper like object_property_add_const_link on top if we go for it. Another possibility is to not introduce any of our patches and reuse the child<> getter and resolve functions in object_property_add_const_link. -------------------- 8< --------------- >From 653ca80e93fcaa94c7fa172edbaef75457d4952d Mon Sep 17 00:00:00 2001 From: Paolo Bonzini <pbonz...@redhat.com> Date: Tue, 31 Mar 2015 13:56:24 +0200 Subject: [PATCH] qom: add . and .. properties Signed-off-by: Paolo Bonzini <pbonz...@redhat.com> --- qom/object.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/qom/object.c b/qom/object.c index b8dff43..3dd87b7 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1783,9 +1783,51 @@ void object_property_set_description(Object *obj, const char *name, op->description = g_strdup(description); } +static void property_get_dot(Object *obj, struct Visitor *v, void *opaque, + const char *name, Error **errp) +{ + gchar *path = object_get_canonical_path(obj); + visit_type_str(v, &path, name, errp); + g_free(path); +} + +static Object *property_resolve_dot(Object *obj, void *opaque, + const gchar *part) +{ + return obj; +} + +static void property_get_dotdot(Object *obj, struct Visitor *v, void *opaque, + const char *name, Error **errp) +{ + if (obj->parent) { + gchar *path = object_get_canonical_path(obj); + visit_type_str(v, &path, name, errp); + g_free(path); + } else { + gchar *path = (gchar *)""; + visit_type_str(v, &path, name, errp); + } +} + +static Object *property_resolve_dotdot(Object *obj, void *opaque, + const gchar *part) +{ + return obj->parent; +} + static void object_instance_init(Object *obj) { + ObjectProperty *op; object_property_add_str(obj, "type", qdev_get_type, NULL, NULL); + + op = object_property_add(obj, ".", "link<Object>", property_get_dot, + NULL, NULL, NULL, NULL); + op->resolve = property_resolve_dot; + + op = object_property_add(obj, "..", "link<Object>", property_get_dotdot, + NULL, NULL, NULL, NULL); + op->resolve = property_resolve_dotdot; } static void register_types(void) -- 2.3.5