[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL v2 12/12] qom: Add object_property_add_const_link()
From: |
Andreas Färber |
Subject: |
[Qemu-devel] [PULL v2 12/12] qom: Add object_property_add_const_link() |
Date: |
Wed, 27 May 2015 20:20:23 +0200 |
From: Paolo Bonzini <address@hidden>
This helper adds a read-only link<> property.
Suggested-by: Eduardo Habkost <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
Reviewed-by: Eduardo Habkost <address@hidden>
Signed-off-by: Andreas Färber <address@hidden>
---
include/qom/object.h | 18 ++++++++++++++++++
qom/object.c | 16 ++++++++++++++++
2 files changed, 34 insertions(+)
diff --git a/include/qom/object.h b/include/qom/object.h
index 270a3ef..e8fb863 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -1449,6 +1449,24 @@ void object_property_add_alias(Object *obj, const char
*name,
Error **errp);
/**
+ * object_property_add_const_link:
+ * @obj: the object to add a property to
+ * @name: the name of the property
+ * @target: the object to be referred by the link
+ * @errp: if an error occurs, a pointer to an area to store the error
+ *
+ * Add an unmodifiable link for a property on an object. This function will
+ * add a property of type link<TYPE> where TYPE is the type of @target.
+ *
+ * The caller must ensure that @target stays alive as long as
+ * this property exists. In the case @target is a child of @obj,
+ * this will be the case. Otherwise, the caller is responsible for
+ * taking a reference.
+ */
+void object_property_add_const_link(Object *obj, const char *name,
+ Object *target, Error **errp);
+
+/**
* object_property_set_description:
* @obj: the object owning the property
* @name: the name of the property
diff --git a/qom/object.c b/qom/object.c
index f1b289c..8f0d8a7 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -1386,6 +1386,22 @@ out:
g_free(full_type);
}
+void object_property_add_const_link(Object *obj, const char *name,
+ Object *target, Error **errp)
+{
+ char *link_type;
+ ObjectProperty *op;
+
+ link_type = g_strdup_printf("link<%s>", object_get_typename(target));
+ op = object_property_add(obj, name, link_type,
+ object_get_child_property, NULL,
+ NULL, target, errp);
+ if (op != NULL) {
+ op->resolve = object_resolve_child_property;
+ }
+ g_free(link_type);
+}
+
gchar *object_get_canonical_path_component(Object *obj)
{
ObjectProperty *prop = NULL;
--
2.1.4
- [Qemu-devel] [PULL v2 00/12] QOM devices patch queue 2015-05-27, Andreas Färber, 2015/05/27
- [Qemu-devel] [PULL v2 01/12] qom: strdup() target property name on object_property_add_alias(), Andreas Färber, 2015/05/27
- [Qemu-devel] [PULL v2 04/12] scripts: Add support for path as argument of qom-tree, Andreas Färber, 2015/05/27
- [Qemu-devel] [PULL v2 05/12] backends: Fix typename of 'policy' enum property in hostmem obj, Andreas Färber, 2015/05/27
- [Qemu-devel] [PULL v2 02/12] qdev: Free property names after registering gpio aliases, Andreas Färber, 2015/05/27
- [Qemu-devel] [PULL v2 08/12] qom: Add helper method for getting user objects root, Andreas Färber, 2015/05/27
- [Qemu-devel] [PULL v2 12/12] qom: Add object_property_add_const_link(),
Andreas Färber <=
- [Qemu-devel] [PULL v2 06/12] doc: Document user creatable object types in help text, Andreas Färber, 2015/05/27
- [Qemu-devel] [PULL v2 07/12] vl: Create (most) objects before creating chardev backends, Andreas Färber, 2015/05/27
- [Qemu-devel] [PULL v2 11/12] qom: Add an object_property_add_enum() helper function, Andreas Färber, 2015/05/27
- [Qemu-devel] [PULL v2 10/12] qom: Make enum string tables const-correct, Andreas Färber, 2015/05/27
- [Qemu-devel] [PULL v2 09/12] qom: Add object_new_with_props() / object_new_withpropv() helpers, Andreas Färber, 2015/05/27
- [Qemu-devel] [PULL v2 03/12] tests: Use qtest_add_data_func() consistently, Andreas Färber, 2015/05/27
- Re: [Qemu-devel] [PULL v2 00/12] QOM devices patch queue 2015-05-27, Peter Maydell, 2015/05/28