return sizeof(ObjectClass);
}
+static size_t type_object_get_size(TypeImpl *ti)
+{
+ if (ti->instance_size) {
+ return ti->instance_size;
+ }
+
+ if (type_has_parent(ti)) {
+ return type_object_get_size(type_get_parent(ti));
+ }
+
+ return 0;
+}
+
static void type_class_interface_init(TypeImpl *ti, InterfaceImpl *iface)
{
TypeInfo info = {
g_free(name);
}
-static void type_class_init(TypeImpl *ti)
+static void type_initialize(TypeImpl *ti)
{
size_t class_size = sizeof(ObjectClass);
int i;
}
ti->class_size = type_class_get_size(ti);
+ ti->instance_size = type_object_get_size(ti);
ti->class = g_malloc0(ti->class_size);
ti->class->type = ti;
if (type_has_parent(ti)) {
TypeImpl *parent = type_get_parent(ti);
- type_class_init(parent);
+ type_initialize(parent);
class_size = parent->class_size;
g_assert(parent->class_size <= ti->class_size);
Object *obj = data;
g_assert(type != NULL);
- g_assert(type->instance_size >= sizeof(Object));
+ type_initialize(type);
- type_class_init(type);
+ g_assert(type->instance_size >= sizeof(Object));
g_assert(type->abstract == false);
memset(obj, 0, type->instance_size);
ObjectProperty *prop;
QTAILQ_FOREACH(prop, &obj->properties, node) {
- if (!strstart(prop->type, "child<", NULL)) {
- continue;
- }
-
- if (prop->opaque == child) {
+ if (strstart(prop->type, "child<", NULL) && prop->opaque == child) {
object_property_del(obj, prop->name, errp);
+ break;
}
}
}
Object *obj;
g_assert(type != NULL);
+ type_initialize(type);
obj = g_malloc(type->instance_size);
object_initialize_with_type(obj, type);
return NULL;
}
- type_class_init(type);
+ type_initialize(type);
return type->class;
}
TypeImpl *type = value;
ObjectClass *k;
- type_class_init(type);
+ type_initialize(type);
k = type->class;
if (!data->include_abstract && type->abstract) {
g_hash_table_foreach(type_table_get(), object_class_foreach_tramp, &data);
}
+static void object_class_get_list_tramp(ObjectClass *klass, void *opaque)
+{
+ GSList **list = opaque;
+
+ *list = g_slist_prepend(*list, klass);
+}
+
+GSList *object_class_get_list(const char *implements_type,
+ bool include_abstract)
+{
+ GSList *list = NULL;
+
+ object_class_foreach(object_class_get_list_tramp,
+ implements_type, include_abstract, &list);
+ return list;
+}
+
void object_ref(Object *obj)
{
obj->ref++;
return newpath;
}
+Object *object_resolve_path_component(Object *parent, gchar *part)
+{
+ ObjectProperty *prop = object_property_find(parent, part);
+ if (prop == NULL) {
+ return NULL;
+ }
+
+ if (strstart(prop->type, "link<", NULL)) {
+ return *(Object **)prop->opaque;
+ } else if (strstart(prop->type, "child<", NULL)) {
+ return prop->opaque;
+ } else {
+ return NULL;
+ }
+}
+
static Object *object_resolve_abs_path(Object *parent,
gchar **parts,
const char *typename,
int index)
{
- ObjectProperty *prop;
Object *child;
if (parts[index] == NULL) {
return object_resolve_abs_path(parent, parts, typename, index + 1);
}
- prop = object_property_find(parent, parts[index]);
- if (prop == NULL) {
- return NULL;
- }
-
- child = NULL;
- if (strstart(prop->type, "link<", NULL)) {
- Object **pchild = prop->opaque;
- if (*pchild) {
- child = *pchild;
- }
- } else if (strstart(prop->type, "child<", NULL)) {
- child = prop->opaque;
- }
-
+ child = object_resolve_path_component(parent, parts[index]);
if (!child) {
return NULL;
}