diff mbox series

[17/36] qdev: Separate generic and device-specific property registration

Message ID 20201029220246.472693-18-ehabkost@redhat.com
State New
Headers show
Series Make qdev static property API usable by any QOM type | expand

Commit Message

Eduardo Habkost Oct. 29, 2020, 10:02 p.m. UTC
qdev_class_add_property() and qdev_property_add_static() will
have code that's specific for device types.

object_class_property_add_static(),
object_class_add_static_props(), and object_property_add_static()
will be generic and part of the QOM static property API.

The declarations for the new functions are being added to
qdev-properties.h, but they will be moved to a QOM header later.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: Eduardo Habkost <ehabkost@redhat.com>
Cc: qemu-devel@nongnu.org
---
 hw/core/qdev-prop-internal.h | 11 +++++++++++
 include/hw/qdev-properties.h | 24 ++++++++++++++++++++++++
 hw/core/qdev-properties.c    | 36 ++++++++++++++++++++++++++++--------
 3 files changed, 63 insertions(+), 8 deletions(-)

Comments

Marc-André Lureau Oct. 30, 2020, 9:56 a.m. UTC | #1
Hi

On Fri, Oct 30, 2020 at 2:19 AM Eduardo Habkost <ehabkost@redhat.com> wrote:

> qdev_class_add_property() and qdev_property_add_static() will

> have code that's specific for device types.

>

> object_class_property_add_static(),

> object_class_add_static_props(), and object_property_add_static()

> will be generic and part of the QOM static property API.

>

> The declarations for the new functions are being added to

> qdev-properties.h, but they will be moved to a QOM header later.

>

>

Might be worth to mention that you also changed *property_add_static() to
return the ObjectProperty. Probably useful in a later patch.

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>


-- 
Marc-André Lureau
<div dir="ltr"><div dir="ltr">Hi<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Oct 30, 2020 at 2:19 AM Eduardo Habkost &lt;<a href="mailto:ehabkost@redhat.com">ehabkost@redhat.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">qdev_class_add_property() and qdev_property_add_static() will<br>
have code that&#39;s specific for device types.<br>
<br>
object_class_property_add_static(),<br>
object_class_add_static_props(), and object_property_add_static()<br>
will be generic and part of the QOM static property API.<br>
<br>
The declarations for the new functions are being added to<br>
qdev-properties.h, but they will be moved to a QOM header later.<br>
<br></blockquote><div><br></div><div>Might be worth to mention that you also changed *property_add_static() to return the ObjectProperty. Probably useful in a later patch.</div></div><div class="gmail_quote"><br></div><div class="gmail_quote">Reviewed-by: Marc-André Lureau &lt;<a href="mailto:marcandre.lureau@redhat.com">marcandre.lureau@redhat.com</a>&gt;</div><div><br></div><div>-- </div><div dir="ltr" class="gmail_signature">Marc-André Lureau<br></div></div>
diff mbox series

Patch

diff --git a/hw/core/qdev-prop-internal.h b/hw/core/qdev-prop-internal.h
index 9cf5cc1d51..858f844504 100644
--- a/hw/core/qdev-prop-internal.h
+++ b/hw/core/qdev-prop-internal.h
@@ -27,4 +27,15 @@  void qdev_propinfo_get_int32(Object *obj, Visitor *v, const char *name,
 void qdev_propinfo_get_size32(Object *obj, Visitor *v, const char *name,
                               void *opaque, Error **errp);
 
+/**
+ * object_property_add_static: Add a static property to an object instance
+ * @obj: object instance
+ * @prop: property definition
+ *
+ * This function should not be used in new code.  Please add class properties
+ * instead, using object_class_add_static_props().
+ */
+ObjectProperty *
+object_property_add_static(Object *obj, Property *prop);
+
 #endif
diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h
index 7f8e4daade..c94301c349 100644
--- a/include/hw/qdev-properties.h
+++ b/include/hw/qdev-properties.h
@@ -275,6 +275,30 @@  extern const PropertyInfo qdev_prop_pcie_link_width;
 #define DEFINE_PROP_END_OF_LIST()               \
     {}
 
+/**
+ * object_class_property_add_static: Add a static property to object class
+ * @oc: object class
+ * @prop: property definition
+ *
+ * Add a property to an object class based on the property definition
+ * at @prop.
+ *
+ * The property definition at @prop should be defined using the
+ * ``DEFINE_PROP`` family of macros.  *@prop must exist for the
+ * life time of @oc.
+ */
+ObjectProperty *
+object_class_property_add_static(ObjectClass *oc, Property *prop);
+
+/**
+ * object_class_add_static_props: Add multiple static properties to object class
+ * @oc: object class
+ * @props: property definition array, terminated by DEFINED_PROP_END_OF_LIST()
+ *
+ * Add properties from @props using object_class_property_add_static()
+ */
+void object_class_add_static_props(ObjectClass *oc, Property *props);
+
 /*
  * Set properties between creation and realization.
  *
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index ad685f371d..68b1666e14 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -885,9 +885,9 @@  const PropertyInfo qdev_prop_link = {
     .create = create_link_property,
 };
 
-void qdev_property_add_static(DeviceState *dev, Property *prop)
+ObjectProperty *
+object_property_add_static(Object *obj, Property *prop)
 {
-    Object *obj = OBJECT(dev);
     ObjectProperty *op;
 
     assert(!prop->info->create);
@@ -907,11 +907,13 @@  void qdev_property_add_static(DeviceState *dev, Property *prop)
             op->init(obj, op);
         }
     }
+
+    return op;
 }
 
-static void qdev_class_add_property(DeviceClass *klass, Property *prop)
+ObjectProperty *
+object_class_property_add_static(ObjectClass *oc, Property *prop)
 {
-    ObjectClass *oc = OBJECT_CLASS(klass);
     ObjectProperty *op;
 
     if (prop->info->create) {
@@ -931,6 +933,21 @@  static void qdev_class_add_property(DeviceClass *klass, Property *prop)
         object_class_property_set_description(oc, prop->name,
                                             prop->info->description);
     }
+    return op;
+}
+
+void object_class_add_static_props(ObjectClass *oc, Property *props)
+{
+    Property *prop;
+
+    for (prop = props; prop && prop->name; prop++) {
+        object_class_property_add_static(oc, prop);
+    }
+}
+
+void qdev_property_add_static(DeviceState *dev, Property *prop)
+{
+    object_property_add_static(OBJECT(dev), prop);
 }
 
 /**
@@ -979,16 +996,19 @@  static void qdev_class_add_legacy_property(DeviceClass *dc, Property *prop)
         NULL, NULL, prop);
 }
 
-void device_class_set_props(DeviceClass *dc, Property *props)
+static void qdev_class_add_legacy_properties(DeviceClass *dc, Property *props)
 {
     Property *prop;
-
-    dc->props_ = props;
     for (prop = props; prop && prop->name; prop++) {
         qdev_class_add_legacy_property(dc, prop);
-        qdev_class_add_property(dc, prop);
     }
 }
+void device_class_set_props(DeviceClass *dc, Property *props)
+{
+    dc->props_ = props;
+    qdev_class_add_legacy_properties(dc, props);
+    object_class_add_static_props(OBJECT_CLASS(dc), props);
+}
 
 void qdev_alias_all_properties(DeviceState *target, Object *source)
 {