aboutsummaryrefslogtreecommitdiff
path: root/qom/object.c
diff options
context:
space:
mode:
authorPeter Crosthwaite <peter.crosthwaite@xilinx.com>2014-08-19 23:55:52 -0700
committerAndreas Färber <afaerber@suse.de>2014-09-04 16:14:47 +0200
commit339659041f87a76f8b71ad3d12cadfc5f89b4bb3 (patch)
treedfd65efd31731e7a127928d756dc09dfb9ae48f8 /qom/object.c
parentd2659e27e1ec0b5126faa0f4fef78755950b39e6 (diff)
qom: Add automatic arrayification to object_property_add()
If "[*]" is given as the last part of a QOM property name, treat that as an array property. The added property is given the first available name, replacing the * with a decimal number counting from 0. First add with name "foo[*]" will be "foo[0]". Second "foo[1]" and so on. Callers may inspect the ObjectProperty * return value to see what number the added property was given. Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com> Signed-off-by: Andreas Färber <afaerber@suse.de>
Diffstat (limited to 'qom/object.c')
-rw-r--r--qom/object.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/qom/object.c b/qom/object.c
index a298b32f8b..da0919a3dd 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -728,6 +728,27 @@ object_property_add(Object *obj, const char *name, const char *type,
void *opaque, Error **errp)
{
ObjectProperty *prop;
+ size_t name_len = strlen(name);
+
+ if (name_len >= 3 && !memcmp(name + name_len - 3, "[*]", 4)) {
+ int i;
+ ObjectProperty *ret;
+ char *name_no_array = g_strdup(name);
+
+ name_no_array[name_len - 3] = '\0';
+ for (i = 0; ; ++i) {
+ char *full_name = g_strdup_printf("%s[%d]", name_no_array, i);
+
+ ret = object_property_add(obj, full_name, type, get, set,
+ release, opaque, NULL);
+ g_free(full_name);
+ if (ret) {
+ break;
+ }
+ }
+ g_free(name_no_array);
+ return ret;
+ }
QTAILQ_FOREACH(prop, &obj->properties, node) {
if (strcmp(prop->name, name) == 0) {