diff options
author | Anthony Liguori <aliguori@us.ibm.com> | 2011-12-22 14:11:53 -0600 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2012-02-03 10:41:05 -0600 |
commit | 93c511a1adad281492f18b13e164ae4ac790c052 (patch) | |
tree | 8e5b0e703ca231c19af54a2ae49d0d9fff95f420 /qom | |
parent | 18b6dade8c0799c48f5c5e124b8c407cd5e22e96 (diff) |
qom: allow object_class_foreach to take additional parameters to refine search
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'qom')
-rw-r--r-- | qom/object.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/qom/object.c b/qom/object.c index a12895fc99..3dabb1abb0 100644 --- a/qom/object.c +++ b/qom/object.c @@ -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); } |