This will be used to set the class alias property for a specific object. Note
that this function is only required for class properties, and will assert at
runtime if an attempt is made to use it on an object alias property.

Signed-off-by: Mark Cave-Ayland <[email protected]>
---
 include/qom/object.h | 13 +++++++++++++
 qom/object.c         | 19 +++++++++++++++++++
 2 files changed, 32 insertions(+)

diff --git a/include/qom/object.h b/include/qom/object.h
index 659b70651a..80c400e1b6 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -2055,6 +2055,19 @@ object_class_property_add_alias(ObjectClass *klass, 
const char *name,
                                 const char *target_type,
                                 const char *target_name);
 
+/**
+ * object_property_set_alias:
+ * @obj: the object upon which to set the alias property
+ * @name: the name of the alias property
+ * @target_obj: the object to forward property access to
+ *
+ * Set an alias property on an object to point to @target_obj.  This is only
+ * required for class properties, and will assert at runtime if used on an
+ * object property.
+ */
+void object_property_set_alias(Object *obj, const char *name,
+                               Object *target_obj);
+
 /**
  * object_property_add_const_link:
  * @obj: the object to add a property to
diff --git a/qom/object.c b/qom/object.c
index a1b0ea19a0..7c8849d75a 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -3071,6 +3071,25 @@ object_class_property_add_alias(ObjectClass *klass, 
const char *name,
     return op;
 }
 
+void object_property_set_alias(Object *obj, const char *name,
+                               Object *target_obj)
+{
+    AliasProperty *prop;
+    ObjectProperty *op;
+    Object **target_objp;
+
+    op = object_property_find_err(obj, name, &error_abort);
+    prop = op->opaque;
+    assert(prop->flags & OBJ_PROP_ALIAS_CLASS);
+
+    target_objp = object_alias_get_targetp(obj, prop);
+    if (*target_objp) {
+        object_unref(*target_objp);
+    }
+    *target_objp = target_obj;
+    object_ref(*target_objp);
+}
+
 void object_property_set_description(Object *obj, const char *name,
                                      const char *description)
 {
-- 
2.43.0


Reply via email to