Skip to content

Commit

Permalink
object: add class property initializer
Browse files Browse the repository at this point in the history
This callback is used to set default value in following patch "object:
add object_property_set_defaut_{bool,str,int,uint}()".

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20200110153039.1379601-7-marcandre.lureau@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
elmarco authored and bonzini committed Jan 24, 2020
1 parent ba806ff commit 2a1be4b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
16 changes: 14 additions & 2 deletions include/qom/object.h
Expand Up @@ -309,6 +309,8 @@ typedef struct InterfaceInfo InterfaceInfo;
*/


typedef struct ObjectProperty ObjectProperty;

/**
* ObjectPropertyAccessor:
* @obj: the object that owns the property
Expand Down Expand Up @@ -356,7 +358,16 @@ typedef void (ObjectPropertyRelease)(Object *obj,
const char *name,
void *opaque);

typedef struct ObjectProperty
/**
* ObjectPropertyInit:
* @obj: the object that owns the property
* @prop: the property to set
*
* Called when a property is initialized.
*/
typedef void (ObjectPropertyInit)(Object *obj, ObjectProperty *prop);

struct ObjectProperty
{
gchar *name;
gchar *type;
Expand All @@ -365,8 +376,9 @@ typedef struct ObjectProperty
ObjectPropertyAccessor *set;
ObjectPropertyResolve *resolve;
ObjectPropertyRelease *release;
ObjectPropertyInit *init;
void *opaque;
} ObjectProperty;
};

/**
* ObjectUnparent:
Expand Down
14 changes: 14 additions & 0 deletions qom/object.c
Expand Up @@ -478,6 +478,19 @@ void object_apply_compat_props(Object *obj)
}
}

static void object_class_property_init_all(Object *obj)
{
ObjectPropertyIterator iter;
ObjectProperty *prop;

object_class_property_iter_init(&iter, object_get_class(obj));
while ((prop = object_property_iter_next(&iter))) {
if (prop->init) {
prop->init(obj, prop);
}
}
}

static void object_initialize_with_type(void *data, size_t size, TypeImpl *type)
{
Object *obj = data;
Expand All @@ -491,6 +504,7 @@ static void object_initialize_with_type(void *data, size_t size, TypeImpl *type)
memset(obj, 0, type->instance_size);
obj->class = type->class;
object_ref(obj);
object_class_property_init_all(obj);
obj->properties = g_hash_table_new_full(g_str_hash, g_str_equal,
NULL, object_property_free);
object_init_with_type(obj, type);
Expand Down

0 comments on commit 2a1be4b

Please sign in to comment.