mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-27 20:33:54 -06:00
qom: add a generic mechanism to resolve paths
It may be desirable to have custom link<> properties that do more than just store an object. Even the addition of a "check" function is not enough if setting the link has side effects or if a non-standard reference counting is preferrable. Avoid the assumption that the opaque field of a link<> is a LinkProperty struct, by adding a generic "resolve" callback to ObjectProperty. This fixes aliases of link properties. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
ef7c7ff6d4
commit
64607d0881
2 changed files with 82 additions and 34 deletions
|
@ -303,6 +303,25 @@ typedef void (ObjectPropertyAccessor)(Object *obj,
|
|||
const char *name,
|
||||
Error **errp);
|
||||
|
||||
/**
|
||||
* ObjectPropertyResolve:
|
||||
* @obj: the object that owns the property
|
||||
* @opaque: the opaque registered with the property
|
||||
* @part: the name of the property
|
||||
*
|
||||
* Resolves the #Object corresponding to property @part.
|
||||
*
|
||||
* The returned object can also be used as a starting point
|
||||
* to resolve a relative path starting with "@part".
|
||||
*
|
||||
* Returns: If @path is the path that led to @obj, the function
|
||||
* returns the #Object corresponding to "@path/@part".
|
||||
* If "@path/@part" is not a valid object path, it returns #NULL.
|
||||
*/
|
||||
typedef Object *(ObjectPropertyResolve)(Object *obj,
|
||||
void *opaque,
|
||||
const char *part);
|
||||
|
||||
/**
|
||||
* ObjectPropertyRelease:
|
||||
* @obj: the object that owns the property
|
||||
|
@ -321,6 +340,7 @@ typedef struct ObjectProperty
|
|||
gchar *type;
|
||||
ObjectPropertyAccessor *get;
|
||||
ObjectPropertyAccessor *set;
|
||||
ObjectPropertyResolve *resolve;
|
||||
ObjectPropertyRelease *release;
|
||||
void *opaque;
|
||||
|
||||
|
@ -787,12 +807,16 @@ void object_unref(Object *obj);
|
|||
* destruction. This may be NULL.
|
||||
* @opaque: an opaque pointer to pass to the callbacks for the property
|
||||
* @errp: returns an error if this function fails
|
||||
*
|
||||
* Returns: The #ObjectProperty; this can be used to set the @resolve
|
||||
* callback for child and link properties.
|
||||
*/
|
||||
void object_property_add(Object *obj, const char *name, const char *type,
|
||||
ObjectPropertyAccessor *get,
|
||||
ObjectPropertyAccessor *set,
|
||||
ObjectPropertyRelease *release,
|
||||
void *opaque, Error **errp);
|
||||
ObjectProperty *object_property_add(Object *obj, const char *name,
|
||||
const char *type,
|
||||
ObjectPropertyAccessor *get,
|
||||
ObjectPropertyAccessor *set,
|
||||
ObjectPropertyRelease *release,
|
||||
void *opaque, Error **errp);
|
||||
|
||||
void object_property_del(Object *obj, const char *name, Error **errp);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue