qom: add object_property_add_const_link

Suggested-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Paolo Bonzini 2015-05-05 18:29:00 +02:00
parent 3751d7c43f
commit fb9e7e334b
2 changed files with 34 additions and 0 deletions

View file

@ -1289,6 +1289,24 @@ void object_property_add_alias(Object *obj, const char *name,
Object *target_obj, const char *target_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

View file

@ -1266,6 +1266,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;