Patchwork [v2,8/8] qom: register qdev properties also as non-legacy properties

login
register
mail settings
Submitter Paolo Bonzini
Date Dec. 16, 2011, 4:47 p.m.
Message ID <1324054053-20484-9-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/131871/
State New
Headers show

Comments

Paolo Bonzini - Dec. 16, 2011, 4:47 p.m.
Push legacy properties into a legacy<...> namespace, and make them
available with correct types too.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/qdev.c |   28 +++++++++++++++++++++++++---
 hw/qdev.h |    7 +++----
 2 files changed, 28 insertions(+), 7 deletions(-)
Anthony Liguori - Dec. 16, 2011, 5:05 p.m.
On 12/16/2011 10:47 AM, Paolo Bonzini wrote:
> Push legacy properties into a legacy<...>  namespace, and make them
> available with correct types too.
>
> Signed-off-by: Paolo Bonzini<pbonzini@redhat.com>
> ---
>   hw/qdev.c |   28 +++++++++++++++++++++++++---
>   hw/qdev.h |    7 +++----
>   2 files changed, 28 insertions(+), 7 deletions(-)
>
> diff --git a/hw/qdev.c b/hw/qdev.c
> index 426ea71..2f7defc 100644
> --- a/hw/qdev.c
> +++ b/hw/qdev.c
> @@ -80,6 +80,9 @@ static DeviceInfo *qdev_find_info(BusInfo *bus_info, const char *name)
>       return NULL;
>   }
>
> +static void qdev_property_add_legacy(DeviceState *dev, Property *prop,
> +                                     Error **errp);
> +
>   static DeviceState *qdev_create_from_info(BusState *bus, DeviceInfo *info)
>   {
>       DeviceState *dev;
> @@ -104,10 +107,12 @@ static DeviceState *qdev_create_from_info(BusState *bus, DeviceInfo *info)
>
>       for (prop = dev->info->props; prop&&  prop->name; prop++) {
>           qdev_property_add_legacy(dev, prop, NULL);
> +        qdev_property_add_static(dev, prop, NULL);
>       }
>
>       for (prop = dev->info->bus_info->props; prop&&  prop->name; prop++) {
>           qdev_property_add_legacy(dev, prop, NULL);
> +        qdev_property_add_static(dev, prop, NULL);
>       }
>
>       qdev_property_add_str(dev, "type", qdev_get_type, NULL, NULL);
> @@ -1174,7 +1179,7 @@ static void qdev_set_legacy_property(DeviceState *dev, Visitor *v, void *opaque,
>    * @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.
> + * be given names and types in the "legacy<>" type namespace.
>    *
>    * Legacy properties are always processed as strings.  The format of the string
>    * depends on the property type.
> @@ -1182,18 +1187,35 @@ static void qdev_set_legacy_property(DeviceState *dev, Visitor *v, void *opaque,
>   void qdev_property_add_legacy(DeviceState *dev, Property *prop,
>                                 Error **errp)
>   {
> -    gchar *type;
> +    gchar *name, *type;
>
> +    name = g_strdup_printf("legacy<%s>", prop->name);

Okay, let's make this name legacy-%s to make it clear that it's not type. 
Otherwise, the patch looks good.

Regards,

Anthony Liguori


>       type = g_strdup_printf("legacy<%s>",
>                              prop->info->legacy_name ?: prop->info->name);
>
> -    qdev_property_add(dev, prop->name, type,
> +    qdev_property_add(dev, name, type,
>                         prop->info->print ? qdev_get_legacy_property : NULL,
>                         prop->info->parse ? qdev_set_legacy_property : NULL,
>                         NULL,
>                         prop, errp);
>
>       g_free(type);
> +    g_free(name);
> +}
> +
> +/**
> + * @qdev_property_add_static - add a @Property to a device.
> + *
> + * Static properties access data in a struct.  The actual type of the
> + * property and the field depends on the property type.
> + */
> +void qdev_property_add_static(DeviceState *dev, Property *prop,
> +                              Error **errp)
> +{
> +    qdev_property_add(dev, prop->name, prop->info->name,
> +                      prop->info->get, prop->info->set,
> +                      NULL,
> +                      prop, errp);
>   }
>
>   DeviceState *qdev_get_root(void)
> diff --git a/hw/qdev.h b/hw/qdev.h
> index 8002644..3410e77 100644
> --- a/hw/qdev.h
> +++ b/hw/qdev.h
> @@ -487,11 +487,10 @@ 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!
> + * @qdev_property_add_static - add a @Property to a device referencing a
> + * field in a struct.
>    */
> -void qdev_property_add_legacy(DeviceState *dev, Property *prop, Error **errp);
> +void qdev_property_add_static(DeviceState *dev, Property *prop, Error **errp);
>
>   /**
>    * @qdev_get_root - returns the root device of the composition tree

Patch

diff --git a/hw/qdev.c b/hw/qdev.c
index 426ea71..2f7defc 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -80,6 +80,9 @@  static DeviceInfo *qdev_find_info(BusInfo *bus_info, const char *name)
     return NULL;
 }
 
+static void qdev_property_add_legacy(DeviceState *dev, Property *prop,
+                                     Error **errp);
+
 static DeviceState *qdev_create_from_info(BusState *bus, DeviceInfo *info)
 {
     DeviceState *dev;
@@ -104,10 +107,12 @@  static DeviceState *qdev_create_from_info(BusState *bus, DeviceInfo *info)
 
     for (prop = dev->info->props; prop && prop->name; prop++) {
         qdev_property_add_legacy(dev, prop, NULL);
+        qdev_property_add_static(dev, prop, NULL);
     }
 
     for (prop = dev->info->bus_info->props; prop && prop->name; prop++) {
         qdev_property_add_legacy(dev, prop, NULL);
+        qdev_property_add_static(dev, prop, NULL);
     }
 
     qdev_property_add_str(dev, "type", qdev_get_type, NULL, NULL);
@@ -1174,7 +1179,7 @@  static void qdev_set_legacy_property(DeviceState *dev, Visitor *v, void *opaque,
  * @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.
+ * be given names and types in the "legacy<>" type namespace.
  *
  * Legacy properties are always processed as strings.  The format of the string
  * depends on the property type.
@@ -1182,18 +1187,35 @@  static void qdev_set_legacy_property(DeviceState *dev, Visitor *v, void *opaque,
 void qdev_property_add_legacy(DeviceState *dev, Property *prop,
                               Error **errp)
 {
-    gchar *type;
+    gchar *name, *type;
 
+    name = g_strdup_printf("legacy<%s>", prop->name);
     type = g_strdup_printf("legacy<%s>",
                            prop->info->legacy_name ?: prop->info->name);
 
-    qdev_property_add(dev, prop->name, type,
+    qdev_property_add(dev, name, type,
                       prop->info->print ? qdev_get_legacy_property : NULL,
                       prop->info->parse ? qdev_set_legacy_property : NULL,
                       NULL,
                       prop, errp);
 
     g_free(type);
+    g_free(name);
+}
+
+/**
+ * @qdev_property_add_static - add a @Property to a device.
+ *
+ * Static properties access data in a struct.  The actual type of the
+ * property and the field depends on the property type.
+ */
+void qdev_property_add_static(DeviceState *dev, Property *prop,
+                              Error **errp)
+{
+    qdev_property_add(dev, prop->name, prop->info->name,
+                      prop->info->get, prop->info->set,
+                      NULL,
+                      prop, errp);
 }
 
 DeviceState *qdev_get_root(void)
diff --git a/hw/qdev.h b/hw/qdev.h
index 8002644..3410e77 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -487,11 +487,10 @@  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!
+ * @qdev_property_add_static - add a @Property to a device referencing a
+ * field in a struct.
  */
-void qdev_property_add_legacy(DeviceState *dev, Property *prop, Error **errp);
+void qdev_property_add_static(DeviceState *dev, Property *prop, Error **errp);
 
 /**
  * @qdev_get_root - returns the root device of the composition tree