aboutsummaryrefslogtreecommitdiff
path: root/qom
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2012-02-09 09:52:59 +0100
committerPaolo Bonzini <pbonzini@redhat.com>2012-02-22 08:31:24 +0100
commitb2cd7dee86f27b6307b4bd411133bfb6ebc2be66 (patch)
treea922c847aa76bf0c9af162fec05e0e764e78cc45 /qom
parent2d7799f2cccc54a71268d357403848fb4c48206c (diff)
qom: add generic string parsing/printing
Add generic property accessors that take a string and parse it appropriately for the property type. All the magic here is done by the new string-based visitors. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'qom')
-rw-r--r--qom/object.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/qom/object.c b/qom/object.c
index 0cbd9bb004..941c291bf9 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -13,6 +13,8 @@
#include "qemu/object.h"
#include "qemu-common.h"
#include "qapi/qapi-visit-core.h"
+#include "qapi/string-input-visitor.h"
+#include "qapi/string-output-visitor.h"
/* TODO: replace QObject with a simpler visitor to avoid a dependency
* of the QOM core on QObject? */
@@ -782,6 +784,29 @@ int64_t object_property_get_int(Object *obj, const char *name,
return retval;
}
+void object_property_parse(Object *obj, const char *string,
+ const char *name, Error **errp)
+{
+ StringInputVisitor *mi;
+ mi = string_input_visitor_new(string);
+ object_property_set(obj, string_input_get_visitor(mi), name, errp);
+
+ string_input_visitor_cleanup(mi);
+}
+
+char *object_property_print(Object *obj, const char *name,
+ Error **errp)
+{
+ StringOutputVisitor *mo;
+ char *string;
+
+ mo = string_output_visitor_new();
+ object_property_get(obj, string_output_get_visitor(mo), name, NULL);
+ string = string_output_get_string(mo);
+ string_output_visitor_cleanup(mo);
+ return string;
+}
+
const char *object_property_get_type(Object *obj, const char *name, Error **errp)
{
ObjectProperty *prop = object_property_find(obj, name);