qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Andreas Färber" <afaerber@suse.de>
To: qemu-devel@nongnu.org
Cc: "Peter Crosthwaite" <peter.crosthwaite@xilinx.com>,
	"Andreas Färber" <afaerber@suse.de>,
	"Anthony Liguori" <aliguori@amazon.com>
Subject: [Qemu-devel] [PULL 3/7] qom: Add automatic arrayification to object_property_add()
Date: Thu,  4 Sep 2014 19:21:11 +0200	[thread overview]
Message-ID: <1409851275-14941-4-git-send-email-afaerber@suse.de> (raw)
In-Reply-To: <1409851275-14941-1-git-send-email-afaerber@suse.de>

From: Peter Crosthwaite <peter.crosthwaite@xilinx.com>

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>
---
 qom/object.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/qom/object.c b/qom/object.c
index a298b32..da0919a 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) {
-- 
1.8.4.5

  parent reply	other threads:[~2014-09-04 17:21 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-04 17:21 [Qemu-devel] [PULL for-2.1 0/7] QOM devices patch queue 2014-09-04 Andreas Färber
2014-09-04 17:21 ` [Qemu-devel] [PULL 1/7] qom: Make object_child_foreach() safe for objects removal Andreas Färber
2014-09-04 17:21 ` [Qemu-devel] [PULL 2/7] machine: Clean up -machine handling Andreas Färber
2014-09-04 17:21 ` Andreas Färber [this message]
2014-09-04 17:21 ` [Qemu-devel] [PULL 4/7] memory: Remove object_property_add_child_array() Andreas Färber
2014-09-04 17:21 ` [Qemu-devel] [PULL 5/7] qdev: Use error_abort instead of using local_err Andreas Färber
2014-09-04 17:21 ` [Qemu-devel] [PULL 6/7] qdev: Use NULL instead of local_err for qbus_child unrealize Andreas Färber
2014-09-04 17:21 ` [Qemu-devel] [PULL 7/7] qdev: Add cleanup logic in device_set_realized() to avoid resource leak Andreas Färber
2014-09-05 10:15 ` [Qemu-devel] [PULL for-2.1 0/7] QOM devices patch queue 2014-09-04 Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1409851275-14941-4-git-send-email-afaerber@suse.de \
    --to=afaerber@suse.de \
    --cc=aliguori@amazon.com \
    --cc=peter.crosthwaite@xilinx.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).