qom: allow object_class_foreach to take additional parameters to refine search

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
Anthony Liguori 2011-12-22 14:11:53 -06:00
parent 18b6dade8c
commit 93c511a1ad
2 changed files with 17 additions and 2 deletions

View File

@ -431,6 +431,7 @@ const char *object_class_get_name(ObjectClass *klass);
ObjectClass *object_class_by_name(const char *typename);
void object_class_foreach(void (*fn)(ObjectClass *klass, void *opaque),
const char *implements_type, bool include_abstract,
void *opaque);
#endif

View File

@ -467,6 +467,8 @@ ObjectClass *object_class_by_name(const char *typename)
typedef struct OCFData
{
void (*fn)(ObjectClass *klass, void *opaque);
const char *implements_type;
bool include_abstract;
void *opaque;
} OCFData;
@ -475,16 +477,28 @@ static void object_class_foreach_tramp(gpointer key, gpointer value,
{
OCFData *data = opaque;
TypeImpl *type = value;
ObjectClass *k;
type_class_init(type);
k = type->class;
data->fn(value, type->class);
if (!data->include_abstract && type->abstract) {
return;
}
if (data->implements_type &&
!object_class_dynamic_cast(k, data->implements_type)) {
return;
}
data->fn(k, data->opaque);
}
void object_class_foreach(void (*fn)(ObjectClass *klass, void *opaque),
const char *implements_type, bool include_abstract,
void *opaque)
{
OCFData data = { fn, opaque };
OCFData data = { fn, implements_type, include_abstract, opaque };
g_hash_table_foreach(type_table_get(), object_class_foreach_tramp, &data);
}