qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 13/36] qdev: Wrap getters and setters in separate helpers


From: Eduardo Habkost
Subject: [PATCH 13/36] qdev: Wrap getters and setters in separate helpers
Date: Thu, 29 Oct 2020 18:02:23 -0400

We'll add extra code to the qdev property getters and setters, so
add wrapper functions where additional actions can be performed.

The new functions have a "static_prop_" prefix instead of "qdev_"
because the code will eventually be moved outside
qdev-properties.c, to common QOM code.

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-properties.c | 44 +++++++++++++++++++++++++++++++++++----
 1 file changed, 40 insertions(+), 4 deletions(-)

diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index 5e010afdb8..aab9e65e97 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -45,6 +45,40 @@ void *qdev_get_prop_ptr(Object *obj, Property *prop)
     return ptr;
 }
 
+static void static_prop_get(Object *obj, Visitor *v, const char *name,
+                            void *opaque, Error **errp)
+{
+    Property *prop = opaque;
+    return prop->info->get(obj, v, name, opaque, errp);
+}
+
+/**
+ * static_prop_getter: Return getter function to be used for property
+ *
+ * Return value can be NULL if @info has no getter function.
+ */
+static ObjectPropertyAccessor *static_prop_getter(const PropertyInfo *info)
+{
+    return info->get ? static_prop_get : NULL;
+}
+
+static void static_prop_set(Object *obj, Visitor *v, const char *name,
+                            void *opaque, Error **errp)
+{
+    Property *prop = opaque;
+    return prop->info->set(obj, v, name, opaque, errp);
+}
+
+/**
+ * static_prop_setter: Return setter function to be used for property
+ *
+ * Return value can be NULL if @info has not setter function.
+ */
+static ObjectPropertyAccessor *static_prop_setter(const PropertyInfo *info)
+{
+    return info->set ? static_prop_set : NULL;
+}
+
 void qdev_propinfo_get_enum(Object *obj, Visitor *v, const char *name,
                             void *opaque, Error **errp)
 {
@@ -687,8 +721,8 @@ static void set_prop_arraylen(Object *obj, Visitor *v, 
const char *name,
         assert(qdev_get_prop_ptr(obj, &arrayprop->prop) == eltptr);
         object_property_add(obj, propname,
                             arrayprop->prop.info->name,
-                            arrayprop->prop.info->get,
-                            arrayprop->prop.info->set,
+                            static_prop_getter(arrayprop->prop.info),
+                            static_prop_setter(arrayprop->prop.info),
                             array_element_release,
                             arrayprop);
     }
@@ -929,7 +963,8 @@ void qdev_property_add_static(DeviceState *dev, Property 
*prop)
     assert(!prop->info->create);
 
     op = object_property_add(obj, prop->name, prop->info->name,
-                             prop->info->get, prop->info->set,
+                             static_prop_getter(prop->info),
+                             static_prop_setter(prop->info),
                              prop->info->release,
                              prop);
 
@@ -955,7 +990,8 @@ static void qdev_class_add_property(DeviceClass *klass, 
Property *prop)
 
         op = object_class_property_add(oc,
                                        prop->name, prop->info->name,
-                                       prop->info->get, prop->info->set,
+                                       static_prop_getter(prop->info),
+                                       static_prop_setter(prop->info),
                                        prop->info->release,
                                        prop);
         if (prop->set_default) {
-- 
2.28.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]