Am 01.05.2012 20:18, schrieb Anthony Liguori:
> This allows a base class to easily add properties.
> 
> Signed-off-by: Anthony Liguori <aligu...@us.ibm.com>

Implementation looks okay but /me not so happy with it: This conflicts
with the move of the qdev static property infrastructure from
DeviceState to Object.

Consider rebasing this onto part of Paolo's series and call it
object_add_properties?

Andreas

> ---
>  hw/qdev.c |   25 ++++++++++++-------------
>  hw/qdev.h |    2 ++
>  2 files changed, 14 insertions(+), 13 deletions(-)
> 
> diff --git a/hw/qdev.c b/hw/qdev.c
> index 6a8f6bd..e17a9ab 100644
> --- a/hw/qdev.c
> +++ b/hw/qdev.c
> @@ -76,22 +76,26 @@ bool qdev_exists(const char *name)
>  static void qdev_property_add_legacy(DeviceState *dev, Property *prop,
>                                       Error **errp);
>  
> -void qdev_set_parent_bus(DeviceState *dev, BusState *bus)
> +void qdev_add_properties(DeviceState *dev, Property *props)
>  {
>      Property *prop;
>  
> +    for (prop = props; prop && prop->name; prop++) {
> +        qdev_property_add_legacy(dev, prop, NULL);
> +        qdev_property_add_static(dev, prop, NULL);
> +    }
> +    qdev_prop_set_defaults(dev, props);
> +}
> +
> +void qdev_set_parent_bus(DeviceState *dev, BusState *bus)
> +{
>      if (qdev_hotplug) {
>          assert(bus->allow_hotplug);
>      }
>  
>      dev->parent_bus = bus;
>      QTAILQ_INSERT_HEAD(&bus->children, dev, sibling);
> -
> -    for (prop = qdev_get_bus_info(dev)->props; prop && prop->name; prop++) {
> -        qdev_property_add_legacy(dev, prop, NULL);
> -        qdev_property_add_static(dev, prop, NULL);
> -    }
> -    qdev_prop_set_defaults(dev, dev->parent_bus->info->props);
> +    qdev_add_properties(dev, dev->parent_bus->info->props);
>  }
>  
>  /* Create a new device.  This only initializes the device state structure
> @@ -633,13 +637,8 @@ static void device_initfn(Object *obj)
>      dev->instance_id_alias = -1;
>      dev->state = DEV_STATE_CREATED;
>  
> -    for (prop = qdev_get_props(dev); prop && prop->name; prop++) {
> -        qdev_property_add_legacy(dev, prop, NULL);
> -        qdev_property_add_static(dev, prop, NULL);
> -    }
> -
> +    qdev_add_properties(dev, qdev_get_props(dev));
>      object_property_add_str(OBJECT(dev), "type", qdev_get_type, NULL, NULL);
> -    qdev_prop_set_defaults(dev, qdev_get_props(dev));
>  }
>  
>  /* Unlink device from bus and free the structure.  */
> diff --git a/hw/qdev.h b/hw/qdev.h
> index 4e90119..ca8386a 100644
> --- a/hw/qdev.h
> +++ b/hw/qdev.h
> @@ -360,4 +360,6 @@ void qdev_set_parent_bus(DeviceState *dev, BusState *bus);
>  
>  extern int qdev_hotplug;
>  
> +void qdev_add_properties(DeviceState *dev, Property *props);
> +
>  #endif


-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg

Reply via email to