diff mbox series

[11/24] tmp421: Register properties as class properties

Message ID 20200921221045.699690-12-ehabkost@redhat.com
State Accepted
Commit 0b43b6e53493d980008869f817a216ccb2078c06
Headers show
Series qom: Convert some properties to class properties | expand

Commit Message

Eduardo Habkost Sept. 21, 2020, 10:10 p.m. UTC
Class properties make QOM introspection simpler and easier, as
they don't require an object to be instantiated.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Cc: qemu-devel@nongnu.org
---
 hw/misc/tmp421.c | 30 +++++++++++++-----------------
 1 file changed, 13 insertions(+), 17 deletions(-)

Comments

Igor Mammedov Oct. 23, 2020, 6:21 p.m. UTC | #1
On Mon, 21 Sep 2020 18:10:32 -0400
Eduardo Habkost <ehabkost@redhat.com> wrote:

> Class properties make QOM introspection simpler and easier, as

> they don't require an object to be instantiated.

> 

> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>


Reviewed-by: Igor Mammedov <imammedo@redhat.com>


> ---

> Cc: qemu-devel@nongnu.org

> ---

>  hw/misc/tmp421.c | 30 +++++++++++++-----------------

>  1 file changed, 13 insertions(+), 17 deletions(-)

> 

> diff --git a/hw/misc/tmp421.c b/hw/misc/tmp421.c

> index 212d6e0e831..1c19a3a9713 100644

> --- a/hw/misc/tmp421.c

> +++ b/hw/misc/tmp421.c

> @@ -340,22 +340,6 @@ static void tmp421_realize(DeviceState *dev, Error **errp)

>      tmp421_reset(&s->i2c);

>  }

>  

> -static void tmp421_initfn(Object *obj)

> -{

> -    object_property_add(obj, "temperature0", "int",

> -                        tmp421_get_temperature,

> -                        tmp421_set_temperature, NULL, NULL);

> -    object_property_add(obj, "temperature1", "int",

> -                        tmp421_get_temperature,

> -                        tmp421_set_temperature, NULL, NULL);

> -    object_property_add(obj, "temperature2", "int",

> -                        tmp421_get_temperature,

> -                        tmp421_set_temperature, NULL, NULL);

> -    object_property_add(obj, "temperature3", "int",

> -                        tmp421_get_temperature,

> -                        tmp421_set_temperature, NULL, NULL);

> -}

> -

>  static void tmp421_class_init(ObjectClass *klass, void *data)

>  {

>      DeviceClass *dc = DEVICE_CLASS(klass);

> @@ -368,6 +352,19 @@ static void tmp421_class_init(ObjectClass *klass, void *data)

>      k->send = tmp421_tx;

>      dc->vmsd = &vmstate_tmp421;

>      sc->dev = (DeviceInfo *) data;

> +

> +    object_class_property_add(klass, "temperature0", "int",

> +                              tmp421_get_temperature,

> +                              tmp421_set_temperature, NULL, NULL);

> +    object_class_property_add(klass, "temperature1", "int",

> +                              tmp421_get_temperature,

> +                              tmp421_set_temperature, NULL, NULL);

> +    object_class_property_add(klass, "temperature2", "int",

> +                              tmp421_get_temperature,

> +                              tmp421_set_temperature, NULL, NULL);

> +    object_class_property_add(klass, "temperature3", "int",

> +                              tmp421_get_temperature,

> +                              tmp421_set_temperature, NULL, NULL);

>  }

>  

>  static const TypeInfo tmp421_info = {

> @@ -375,7 +372,6 @@ static const TypeInfo tmp421_info = {

>      .parent        = TYPE_I2C_SLAVE,

>      .instance_size = sizeof(TMP421State),

>      .class_size    = sizeof(TMP421Class),

> -    .instance_init = tmp421_initfn,

>      .abstract      = true,

>  };

>
diff mbox series

Patch

diff --git a/hw/misc/tmp421.c b/hw/misc/tmp421.c
index 212d6e0e831..1c19a3a9713 100644
--- a/hw/misc/tmp421.c
+++ b/hw/misc/tmp421.c
@@ -340,22 +340,6 @@  static void tmp421_realize(DeviceState *dev, Error **errp)
     tmp421_reset(&s->i2c);
 }
 
-static void tmp421_initfn(Object *obj)
-{
-    object_property_add(obj, "temperature0", "int",
-                        tmp421_get_temperature,
-                        tmp421_set_temperature, NULL, NULL);
-    object_property_add(obj, "temperature1", "int",
-                        tmp421_get_temperature,
-                        tmp421_set_temperature, NULL, NULL);
-    object_property_add(obj, "temperature2", "int",
-                        tmp421_get_temperature,
-                        tmp421_set_temperature, NULL, NULL);
-    object_property_add(obj, "temperature3", "int",
-                        tmp421_get_temperature,
-                        tmp421_set_temperature, NULL, NULL);
-}
-
 static void tmp421_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -368,6 +352,19 @@  static void tmp421_class_init(ObjectClass *klass, void *data)
     k->send = tmp421_tx;
     dc->vmsd = &vmstate_tmp421;
     sc->dev = (DeviceInfo *) data;
+
+    object_class_property_add(klass, "temperature0", "int",
+                              tmp421_get_temperature,
+                              tmp421_set_temperature, NULL, NULL);
+    object_class_property_add(klass, "temperature1", "int",
+                              tmp421_get_temperature,
+                              tmp421_set_temperature, NULL, NULL);
+    object_class_property_add(klass, "temperature2", "int",
+                              tmp421_get_temperature,
+                              tmp421_set_temperature, NULL, NULL);
+    object_class_property_add(klass, "temperature3", "int",
+                              tmp421_get_temperature,
+                              tmp421_set_temperature, NULL, NULL);
 }
 
 static const TypeInfo tmp421_info = {
@@ -375,7 +372,6 @@  static const TypeInfo tmp421_info = {
     .parent        = TYPE_I2C_SLAVE,
     .instance_size = sizeof(TMP421State),
     .class_size    = sizeof(TMP421Class),
-    .instance_init = tmp421_initfn,
     .abstract      = true,
 };