qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Anthony Liguori <aliguori@us.ibm.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	Peter Maydell <peter.maydell@linaro.org>,
	Anthony Liguori <aliguori@us.ibm.com>,
	Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>,
	Jan Kiszka <jan.kiszka@siemens.com>,
	Markus Armbruster <armbru@redhat.com>,
	Luiz Capitulino <lcapitulino@redhat.com>
Subject: [Qemu-devel] [PATCH v3 03/20] qom: register legacy properties as new style properties (v2)
Date: Mon, 12 Dec 2011 14:29:27 -0600	[thread overview]
Message-ID: <1323721784-704-4-git-send-email-aliguori@us.ibm.com> (raw)
In-Reply-To: <1323721784-704-1-git-send-email-aliguori@us.ibm.com>

Expose all legacy properties through the new QOM property mechanism.  The qdev
property types are exposed through the 'legacy<>' namespace.  They are always
visited as strings since they do their own string parsing.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
v1 -> v2
 - add bus properties (Gerd)
---
 hw/qdev.c |   86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/qdev.h |    7 +++++
 2 files changed, 93 insertions(+), 0 deletions(-)

diff --git a/hw/qdev.c b/hw/qdev.c
index 94f14c1..6f77af9 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -83,6 +83,7 @@ static DeviceInfo *qdev_find_info(BusInfo *bus_info, const char *name)
 static DeviceState *qdev_create_from_info(BusState *bus, DeviceInfo *info)
 {
     DeviceState *dev;
+    Property *prop;
 
     assert(bus->info == info->bus_info);
     dev = g_malloc0(info->size);
@@ -100,6 +101,15 @@ static DeviceState *qdev_create_from_info(BusState *bus, DeviceInfo *info)
     dev->instance_id_alias = -1;
     QTAILQ_INIT(&dev->properties);
     dev->state = DEV_STATE_CREATED;
+
+    for (prop = dev->info->props; prop && prop->name; prop++) {
+        qdev_property_add_legacy(dev, prop, NULL);
+    }
+
+    for (prop = dev->info->bus_info->props; prop && prop->name; prop++) {
+        qdev_property_add_legacy(dev, prop, NULL);
+    }
+
     return dev;
 }
 
@@ -1075,3 +1085,79 @@ const char *qdev_property_get_type(DeviceState *dev, const char *name, Error **e
 
     return prop->type;
 }
+
+/**
+ * Legacy property handling
+ */
+
+static void qdev_get_legacy_property(DeviceState *dev, Visitor *v, void *opaque,
+                                     const char *name, Error **errp)
+{
+    Property *prop = opaque;
+
+    if (prop->info->print) {
+        char buffer[1024];
+        char *ptr = buffer;
+
+        prop->info->print(dev, prop, buffer, sizeof(buffer));
+        visit_type_str(v, &ptr, name, errp);
+    } else {
+        error_set(errp, QERR_PERMISSION_DENIED);
+    }
+}
+
+static void qdev_set_legacy_property(DeviceState *dev, Visitor *v, void *opaque,
+                                     const char *name, Error **errp)
+{
+    Property *prop = opaque;
+
+    if (dev->state != DEV_STATE_CREATED) {
+        error_set(errp, QERR_PERMISSION_DENIED);
+        return;
+    }
+
+    if (prop->info->parse) {
+        Error *local_err = NULL;
+        char *ptr = NULL;
+
+        visit_type_str(v, &ptr, name, &local_err);
+        if (!local_err) {
+            int ret;
+            ret = prop->info->parse(dev, prop, ptr);
+            if (ret != 0) {
+                error_set(errp, QERR_INVALID_PARAMETER_VALUE,
+                          name, prop->info->name);
+            }
+            g_free(ptr);
+        } else {
+            error_propagate(errp, local_err);
+        }
+    } else {
+        error_set(errp, QERR_PERMISSION_DENIED);
+    }
+}
+
+/**
+ * @qdev_add_legacy_property - adds a legacy property
+ *
+ * Do not use this is new code!  Properties added through this interface will
+ * be given types in the "legacy<>" type namespace.
+ *
+ * Legacy properties are always processed as strings.  The format of the string
+ * depends on the property type.
+ */
+void qdev_property_add_legacy(DeviceState *dev, Property *prop,
+                              Error **errp)
+{
+    gchar *type;
+
+    type = g_strdup_printf("legacy<%s>", prop->info->name);
+
+    qdev_property_add(dev, prop->name, type,
+                      qdev_get_legacy_property,
+                      qdev_set_legacy_property,
+                      NULL,
+                      prop, errp);
+
+    g_free(type);
+}
diff --git a/hw/qdev.h b/hw/qdev.h
index 2df3bb7..3b629d4 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -475,4 +475,11 @@ void qdev_property_set(DeviceState *dev, Visitor *v, const char *name,
 const char *qdev_property_get_type(DeviceState *dev, const char *name,
                                    Error **errp);
 
+/**
+ * @qdev_property_add_legacy - add a legacy @Property to a device
+ *
+ * DO NOT USE THIS IN NEW CODE!
+ */
+void qdev_property_add_legacy(DeviceState *dev, Property *prop, Error **errp);
+
 #endif
-- 
1.7.4.1

  parent reply	other threads:[~2011-12-12 20:30 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-12 20:29 [Qemu-devel] [PATCH v3 00/20] qom: dynamic properties and composition tree Anthony Liguori
2011-12-12 20:29 ` [Qemu-devel] [PATCH v3 01/20] qom: add a reference count to qdev objects Anthony Liguori
2011-12-12 20:29 ` [Qemu-devel] [PATCH v3 02/20] qom: add new dynamic property infrastructure based on Visitors (v2) Anthony Liguori
2011-12-12 20:29 ` Anthony Liguori [this message]
2011-12-12 20:29 ` [Qemu-devel] [PATCH v3 04/20] qom: introduce root device Anthony Liguori
2011-12-12 20:29 ` [Qemu-devel] [PATCH v3 05/20] qdev: provide an interface to return canonical path from root (v2) Anthony Liguori
2011-12-12 20:29 ` [Qemu-devel] [PATCH v3 06/20] qdev: provide a path resolution (v2) Anthony Liguori
2011-12-12 20:29 ` [Qemu-devel] [PATCH v3 07/20] qom: add child properties (composition) (v3) Anthony Liguori
2011-12-12 20:29 ` [Qemu-devel] [PATCH v3 08/20] qom: add link properties (v2) Anthony Liguori
2011-12-12 20:29 ` [Qemu-devel] [PATCH v3 09/20] qapi: allow a 'gen' key to suppress code generation Anthony Liguori
2011-12-12 20:29 ` [Qemu-devel] [PATCH v3 10/20] qmp: add qom-list command Anthony Liguori
2011-12-12 20:29 ` [Qemu-devel] [PATCH v3 11/20] qom: qom_{get, set} monitor commands (v2) Anthony Liguori
2011-12-12 20:29 ` [Qemu-devel] [PATCH v3 12/20] qdev: add explicitly named devices to the root complex Anthony Liguori
2011-12-12 20:29 ` [Qemu-devel] [PATCH v3 13/20] dev: add an anonymous peripheral container Anthony Liguori
2011-12-12 20:29 ` [Qemu-devel] [PATCH v3 14/20] rtc: make piix3 set the rtc as a child (v2) Anthony Liguori
2011-12-12 20:29 ` [Qemu-devel] [PATCH v3 15/20] rtc: add a dynamic property for retrieving the date Anthony Liguori
2011-12-12 20:29 ` [Qemu-devel] [PATCH v3 16/20] qom: optimize qdev_get_canonical_path using a parent link Anthony Liguori
2011-12-12 20:29 ` [Qemu-devel] [PATCH v3 17/20] qom: add vga node to the pc composition tree Anthony Liguori
2011-12-12 20:29 ` [Qemu-devel] [PATCH v3 18/20] qom: add string property type Anthony Liguori
2011-12-12 20:29 ` [Qemu-devel] [PATCH v3 19/20] qdev: add a qdev_get_type() function and expose as a 'type' property Anthony Liguori
2011-12-15 18:10 ` [Qemu-devel] [PATCH v3 00/20] qom: dynamic properties and composition tree Anthony Liguori
2011-12-16  9:42   ` Kevin Wolf
2011-12-16 10:17     ` Paolo Bonzini
2011-12-16 10:36       ` Kevin Wolf
2011-12-16 12:24         ` Paolo Bonzini
2011-12-16 12:55           ` Kevin Wolf
2011-12-16 13:28             ` Paolo Bonzini
2011-12-16 13:52               ` Anthony Liguori
2011-12-16 13:51           ` Anthony Liguori
2011-12-16 13:52             ` Paolo Bonzini
2011-12-16 14:11               ` Anthony Liguori
2011-12-16 14:18             ` Kevin Wolf
2011-12-16 14:54               ` Anthony Liguori
2011-12-16 14:56                 ` Paolo Bonzini
2011-12-16 15:10                 ` Kevin Wolf
2011-12-16 13:49       ` Anthony Liguori
2011-12-16 13:48     ` Anthony Liguori

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=1323721784-704-4-git-send-email-aliguori@us.ibm.com \
    --to=aliguori@us.ibm.com \
    --cc=armbru@redhat.com \
    --cc=jan.kiszka@siemens.com \
    --cc=kwolf@redhat.com \
    --cc=lcapitulino@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@linux.vnet.ibm.com \
    /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).