]> www.infradead.org Git - users/dwmw2/qemu.git/commitdiff
qom: add property get/set wrappers for links
authorPaolo Bonzini <pbonzini@redhat.com>
Thu, 2 Feb 2012 09:51:57 +0000 (10:51 +0100)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 7 Feb 2012 12:52:41 +0000 (13:52 +0100)
These can set a link to any object, as long as it is included in
the composition tree.

Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
include/qemu/object.h
qom/object.c

index 6c36345814b9b88f7bcd752201b1d4f29df0140d..7d50da907872c75e6931105ee19ce31599473009 100644 (file)
@@ -645,6 +645,30 @@ void object_property_set_str(Object *obj, const char *value,
 char *object_property_get_str(Object *obj, const char *name,
                               struct Error **errp);
 
+/**
+ * object_property_set_link:
+ * @value: the value to be written to the property
+ * @name: the name of the property
+ * @errp: returns an error if this function fails
+ *
+ * Writes an object's canonical path to a property.
+ */
+void object_property_set_link(Object *obj, Object *value,
+                              const char *name, struct Error **errp);
+
+/**
+ * object_property_get_link:
+ * @obj: the object
+ * @name: the name of the property
+ * @errp: returns an error if this function fails
+ *
+ * Returns: the value of the property, resolved from a path to an Object,
+ * or NULL if an error occurs (including when the property value is not a
+ * string or not a valid object path).
+ */
+Object *object_property_get_link(Object *obj, const char *name,
+                                 struct Error **errp);
+
 /**
  * object_property_set_bool:
  * @value: the value to be written to the property
index 686cca00b2d164178fd9ffe04736e68326241e04..5e5b261103c96b05ab7c3e6621871a31b676a636 100644 (file)
@@ -696,6 +696,30 @@ char *object_property_get_str(Object *obj, const char *name,
     return retval;
 }
 
+void object_property_set_link(Object *obj, Object *value,
+                              const char *name, Error **errp)
+{
+    object_property_set_str(obj, object_get_canonical_path(value),
+                            name, errp);
+}
+
+Object *object_property_get_link(Object *obj, const char *name,
+                                 Error **errp)
+{
+    char *str = object_property_get_str(obj, name, errp);
+    Object *target = NULL;
+
+    if (str && *str) {
+        target = object_resolve_path(str, NULL);
+        if (!target) {
+            error_set(errp, QERR_DEVICE_NOT_FOUND, str);
+        }
+    }
+
+    g_free(str);
+    return target;
+}
+
 void object_property_set_bool(Object *obj, bool value,
                               const char *name, Error **errp)
 {