]> git.proxmox.com Git - mirror_qemu.git/commitdiff
qom: Introduce object_class_get_list()
authorAndreas Färber <afaerber@suse.de>
Sat, 25 Feb 2012 22:07:34 +0000 (23:07 +0100)
committerAnthony Liguori <aliguori@us.ibm.com>
Wed, 14 Mar 2012 20:30:39 +0000 (15:30 -0500)
This function allows to obtain a singly-linked list of classes, which
can be sorted by the caller.

Signed-off-by: Andreas Färber <afaerber@suse.de>
Cc: Anthony Liguori <anthony@codemonkey.ws>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
include/qemu/object.h
qom/object.c

index ec2d2943c2c1e8e203ff65b600b6ff8f7494b22e..e8fc1268b368458519f82153e61c55dff6e800e1 100644 (file)
@@ -560,6 +560,17 @@ 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);
+
+/**
+ * object_class_get_list:
+ * @implements_type: The type to filter for, including its derivatives.
+ * @include_abstract: Whether to include abstract classes.
+ *
+ * Returns: A singly-linked list of the classes in reverse hashtable order.
+ */
+GSList *object_class_get_list(const char *implements_type,
+                              bool include_abstract);
+
 /**
  * object_ref:
  * @obj: the object
index 664708da86f2f207aff35c23008e9e1309f09d4d..9cd9506eb527deb9dd29ad18b44fa70630fb93a4 100644 (file)
@@ -584,6 +584,23 @@ void object_class_foreach(void (*fn)(ObjectClass *klass, void *opaque),
     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++;