qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [RFC 4/4] qom: Abolish class properties


From: David Gibson
Subject: [Qemu-devel] [RFC 4/4] qom: Abolish class properties
Date: Thu, 29 Sep 2016 10:16:45 +1000

QOM allows both object class properties as well as object instance
properties.  object class properties were never much used, and provide
no real benefit.  Note that it's only the *existence* of such
properties that's established on a per-class basis - the way the
accessors work, the property's *value* is still per-instance.

Generally it's just as easy to create an instance property for every
instance from the (per-class) instance_init hook as it is to create a
class property.

Therefore, remove all support for object class properties, simplifying
the QOM model a bit.

Signed-off-by: David Gibson <address@hidden>
---
 include/qom/object.h |  42 -----------
 qom/object.c         | 195 ---------------------------------------------------
 2 files changed, 237 deletions(-)

diff --git a/include/qom/object.h b/include/qom/object.h
index 5ecc2d1..8b4e96c 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -941,13 +941,6 @@ ObjectProperty *object_property_add(Object *obj, const 
char *name,
 
 void object_property_del(Object *obj, const char *name, Error **errp);
 
-ObjectProperty *object_class_property_add(ObjectClass *klass, const char *name,
-                                          const char *type,
-                                          ObjectPropertyAccessor *get,
-                                          ObjectPropertyAccessor *set,
-                                          ObjectPropertyRelease *release,
-                                          void *opaque, Error **errp);
-
 /**
  * object_property_find:
  * @obj: the object
@@ -958,8 +951,6 @@ ObjectProperty *object_class_property_add(ObjectClass 
*klass, const char *name,
  */
 ObjectProperty *object_property_find(Object *obj, const char *name,
                                      Error **errp);
-ObjectProperty *object_class_property_find(ObjectClass *klass, const char 
*name,
-                                           Error **errp);
 
 typedef struct ObjectPropertyIterator {
     ObjectClass *nextclass;
@@ -1375,12 +1366,6 @@ void object_property_add_str(Object *obj, const char 
*name,
                              void (*set)(Object *, const char *, Error **),
                              Error **errp);
 
-void object_class_property_add_str(ObjectClass *klass, const char *name,
-                                   char *(*get)(Object *, Error **),
-                                   void (*set)(Object *, const char *,
-                                               Error **),
-                                   Error **errp);
-
 /**
  * object_property_add_bool:
  * @obj: the object to add a property to
@@ -1397,11 +1382,6 @@ void object_property_add_bool(Object *obj, const char 
*name,
                               void (*set)(Object *, bool, Error **),
                               Error **errp);
 
-void object_class_property_add_bool(ObjectClass *klass, const char *name,
-                                    bool (*get)(Object *, Error **),
-                                    void (*set)(Object *, bool, Error **),
-                                    Error **errp);
-
 /**
  * object_property_add_enum:
  * @obj: the object to add a property to
@@ -1421,13 +1401,6 @@ void object_property_add_enum(Object *obj, const char 
*name,
                               void (*set)(Object *, int, Error **),
                               Error **errp);
 
-void object_class_property_add_enum(ObjectClass *klass, const char *name,
-                                    const char *typename,
-                                    const char * const *strings,
-                                    int (*get)(Object *, Error **),
-                                    void (*set)(Object *, int, Error **),
-                                    Error **errp);
-
 /**
  * object_property_add_tm:
  * @obj: the object to add a property to
@@ -1442,10 +1415,6 @@ void object_property_add_tm(Object *obj, const char 
*name,
                             void (*get)(Object *, struct tm *, Error **),
                             Error **errp);
 
-void object_class_property_add_tm(ObjectClass *klass, const char *name,
-                                  void (*get)(Object *, struct tm *, Error **),
-                                  Error **errp);
-
 /**
  * object_property_add_uint8_ptr:
  * @obj: the object to add a property to
@@ -1458,8 +1427,6 @@ void object_class_property_add_tm(ObjectClass *klass, 
const char *name,
  */
 void object_property_add_uint8_ptr(Object *obj, const char *name,
                                    const uint8_t *v, Error **errp);
-void object_class_property_add_uint8_ptr(ObjectClass *klass, const char *name,
-                                         const uint8_t *v, Error **errp);
 
 /**
  * object_property_add_uint16_ptr:
@@ -1473,8 +1440,6 @@ void object_class_property_add_uint8_ptr(ObjectClass 
*klass, const char *name,
  */
 void object_property_add_uint16_ptr(Object *obj, const char *name,
                                     const uint16_t *v, Error **errp);
-void object_class_property_add_uint16_ptr(ObjectClass *klass, const char *name,
-                                          const uint16_t *v, Error **errp);
 
 /**
  * object_property_add_uint32_ptr:
@@ -1488,8 +1453,6 @@ void object_class_property_add_uint16_ptr(ObjectClass 
*klass, const char *name,
  */
 void object_property_add_uint32_ptr(Object *obj, const char *name,
                                     const uint32_t *v, Error **errp);
-void object_class_property_add_uint32_ptr(ObjectClass *klass, const char *name,
-                                          const uint32_t *v, Error **errp);
 
 /**
  * object_property_add_uint64_ptr:
@@ -1503,8 +1466,6 @@ void object_class_property_add_uint32_ptr(ObjectClass 
*klass, const char *name,
  */
 void object_property_add_uint64_ptr(Object *obj, const char *name,
                                     const uint64_t *v, Error **Errp);
-void object_class_property_add_uint64_ptr(ObjectClass *klass, const char *name,
-                                          const uint64_t *v, Error **Errp);
 
 /**
  * object_property_add_alias:
@@ -1556,9 +1517,6 @@ void object_property_add_const_link(Object *obj, const 
char *name,
  */
 void object_property_set_description(Object *obj, const char *name,
                                      const char *description, Error **errp);
-void object_class_property_set_description(ObjectClass *klass, const char 
*name,
-                                           const char *description,
-                                           Error **errp);
 
 /**
  * object_child_foreach:
diff --git a/qom/object.c b/qom/object.c
index 8166b7d..5a00cf5 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -948,50 +948,10 @@ object_property_add(Object *obj, const char *name, const 
char *type,
     return prop;
 }
 
-ObjectProperty *
-object_class_property_add(ObjectClass *klass,
-                          const char *name,
-                          const char *type,
-                          ObjectPropertyAccessor *get,
-                          ObjectPropertyAccessor *set,
-                          ObjectPropertyRelease *release,
-                          void *opaque,
-                          Error **errp)
-{
-    ObjectProperty *prop;
-
-    if (object_class_property_find(klass, name, NULL) != NULL) {
-        error_setg(errp, "attempt to add duplicate property '%s'"
-                   " to object (type '%s')", name,
-                   object_class_get_name(klass));
-        return NULL;
-    }
-
-    prop = g_malloc0(sizeof(*prop));
-
-    prop->name = g_strdup(name);
-    prop->type = g_strdup(type);
-
-    prop->get = get;
-    prop->set = set;
-    prop->release = release;
-    prop->opaque = opaque;
-
-    g_hash_table_insert(klass->properties, g_strdup(name), prop);
-
-    return prop;
-}
-
 ObjectProperty *object_property_find(Object *obj, const char *name,
                                      Error **errp)
 {
     ObjectProperty *prop;
-    ObjectClass *klass = object_get_class(obj);
-
-    prop = object_class_property_find(klass, name, NULL);
-    if (prop) {
-        return prop;
-    }
 
     prop = g_hash_table_lookup(obj->properties, name);
     if (prop) {
@@ -1022,27 +982,6 @@ ObjectProperty 
*object_property_iter_next(ObjectPropertyIterator *iter)
     return val;
 }
 
-ObjectProperty *object_class_property_find(ObjectClass *klass, const char 
*name,
-                                           Error **errp)
-{
-    ObjectProperty *prop;
-    ObjectClass *parent_klass;
-
-    parent_klass = object_class_get_parent(klass);
-    if (parent_klass) {
-        prop = object_class_property_find(parent_klass, name, NULL);
-        if (prop) {
-            return prop;
-        }
-    }
-
-    prop = g_hash_table_lookup(klass->properties, name);
-    if (!prop) {
-        error_setg(errp, "Property '.%s' not found", name);
-    }
-    return prop;
-}
-
 void object_property_del(Object *obj, const char *name, Error **errp)
 {
     ObjectProperty *prop = g_hash_table_lookup(obj->properties, name);
@@ -1792,29 +1731,6 @@ void object_property_add_str(Object *obj, const char 
*name,
     }
 }
 
-void object_class_property_add_str(ObjectClass *klass, const char *name,
-                                   char *(*get)(Object *, Error **),
-                                   void (*set)(Object *, const char *,
-                                               Error **),
-                                   Error **errp)
-{
-    Error *local_err = NULL;
-    StringProperty *prop = g_malloc0(sizeof(*prop));
-
-    prop->get = get;
-    prop->set = set;
-
-    object_class_property_add(klass, name, "string",
-                              get ? property_get_str : NULL,
-                              set ? property_set_str : NULL,
-                              property_release_str,
-                              prop, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
-        g_free(prop);
-    }
-}
-
 typedef struct BoolProperty
 {
     bool (*get)(Object *, Error **);
@@ -1882,28 +1798,6 @@ void object_property_add_bool(Object *obj, const char 
*name,
     }
 }
 
-void object_class_property_add_bool(ObjectClass *klass, const char *name,
-                                    bool (*get)(Object *, Error **),
-                                    void (*set)(Object *, bool, Error **),
-                                    Error **errp)
-{
-    Error *local_err = NULL;
-    BoolProperty *prop = g_malloc0(sizeof(*prop));
-
-    prop->get = get;
-    prop->set = set;
-
-    object_class_property_add(klass, name, "bool",
-                              get ? property_get_bool : NULL,
-                              set ? property_set_bool : NULL,
-                              property_release_bool,
-                              prop, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
-        g_free(prop);
-    }
-}
-
 static void property_get_enum(Object *obj, Visitor *v, const char *name,
                               void *opaque, Error **errp)
 {
@@ -1967,31 +1861,6 @@ void object_property_add_enum(Object *obj, const char 
*name,
     }
 }
 
-void object_class_property_add_enum(ObjectClass *klass, const char *name,
-                                    const char *typename,
-                                    const char * const *strings,
-                                    int (*get)(Object *, Error **),
-                                    void (*set)(Object *, int, Error **),
-                                    Error **errp)
-{
-    Error *local_err = NULL;
-    EnumProperty *prop = g_malloc(sizeof(*prop));
-
-    prop->strings = strings;
-    prop->get = get;
-    prop->set = set;
-
-    object_class_property_add(klass, name, typename,
-                              get ? property_get_enum : NULL,
-                              set ? property_set_enum : NULL,
-                              property_release_enum,
-                              prop, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
-        g_free(prop);
-    }
-}
-
 typedef struct TMProperty {
     void (*get)(Object *, struct tm *, Error **);
 } TMProperty;
@@ -2070,25 +1939,6 @@ void object_property_add_tm(Object *obj, const char 
*name,
     }
 }
 
-void object_class_property_add_tm(ObjectClass *klass, const char *name,
-                                  void (*get)(Object *, struct tm *, Error **),
-                                  Error **errp)
-{
-    Error *local_err = NULL;
-    TMProperty *prop = g_malloc0(sizeof(*prop));
-
-    prop->get = get;
-
-    object_class_property_add(klass, name, "struct tm",
-                              get ? property_get_tm : NULL, NULL,
-                              property_release_tm,
-                              prop, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
-        g_free(prop);
-    }
-}
-
 static char *qdev_get_type(Object *obj, Error **errp)
 {
     return g_strdup(object_get_typename(obj));
@@ -2129,13 +1979,6 @@ void object_property_add_uint8_ptr(Object *obj, const 
char *name,
                         NULL, NULL, (void *)v, errp);
 }
 
-void object_class_property_add_uint8_ptr(ObjectClass *klass, const char *name,
-                                         const uint8_t *v, Error **errp)
-{
-    object_class_property_add(klass, name, "uint8", property_get_uint8_ptr,
-                              NULL, NULL, (void *)v, errp);
-}
-
 void object_property_add_uint16_ptr(Object *obj, const char *name,
                                     const uint16_t *v, Error **errp)
 {
@@ -2143,13 +1986,6 @@ void object_property_add_uint16_ptr(Object *obj, const 
char *name,
                         NULL, NULL, (void *)v, errp);
 }
 
-void object_class_property_add_uint16_ptr(ObjectClass *klass, const char *name,
-                                          const uint16_t *v, Error **errp)
-{
-    object_class_property_add(klass, name, "uint16", property_get_uint16_ptr,
-                              NULL, NULL, (void *)v, errp);
-}
-
 void object_property_add_uint32_ptr(Object *obj, const char *name,
                                     const uint32_t *v, Error **errp)
 {
@@ -2157,13 +1993,6 @@ void object_property_add_uint32_ptr(Object *obj, const 
char *name,
                         NULL, NULL, (void *)v, errp);
 }
 
-void object_class_property_add_uint32_ptr(ObjectClass *klass, const char *name,
-                                          const uint32_t *v, Error **errp)
-{
-    object_class_property_add(klass, name, "uint32", property_get_uint32_ptr,
-                              NULL, NULL, (void *)v, errp);
-}
-
 void object_property_add_uint64_ptr(Object *obj, const char *name,
                                     const uint64_t *v, Error **errp)
 {
@@ -2171,13 +2000,6 @@ void object_property_add_uint64_ptr(Object *obj, const 
char *name,
                         NULL, NULL, (void *)v, errp);
 }
 
-void object_class_property_add_uint64_ptr(ObjectClass *klass, const char *name,
-                                          const uint64_t *v, Error **errp)
-{
-    object_class_property_add(klass, name, "uint64", property_get_uint64_ptr,
-                              NULL, NULL, (void *)v, errp);
-}
-
 typedef struct {
     Object *target_obj;
     char *target_name;
@@ -2275,23 +2097,6 @@ void object_property_set_description(Object *obj, const 
char *name,
     op->description = g_strdup(description);
 }
 
-void object_class_property_set_description(ObjectClass *klass,
-                                           const char *name,
-                                           const char *description,
-                                           Error **errp)
-{
-    ObjectProperty *op;
-
-    op = g_hash_table_lookup(klass->properties, name);
-    if (!op) {
-        error_setg(errp, "Property '.%s' not found", name);
-        return;
-    }
-
-    g_free(op->description);
-    op->description = g_strdup(description);
-}
-
 static void object_instance_init(Object *obj)
 {
     object_property_add_str(obj, "type", qdev_get_type, NULL, NULL);
-- 
2.7.4




reply via email to

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