qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v2] qom: Introduce object_class_get_list()


From: Anthony Liguori
Subject: Re: [Qemu-devel] [PATCH v2] qom: Introduce object_class_get_list()
Date: Wed, 14 Mar 2012 16:18:49 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2

On 02/25/2012 04:07 PM, Andreas Färber wrote:
This function allows to obtain a singly-linked list of classes, which
can be sorted by the caller.

Signed-off-by: Andreas Färber<address@hidden>
Cc: Anthony Liguori<address@hidden>

Applied.  Thanks.

Regards,

Anthony Liguori

---
  v1 ->  v2:
  * Instead of object_class_foreach() using a GCompareFunc with a GTree 
internally,
    return a GSList so that the caller can sort herself (suggested by Anthony).
  * Add documentation.

  include/qemu/object.h |   11 +++++++++++
  qom/object.c          |   17 +++++++++++++++++
  2 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/include/qemu/object.h b/include/qemu/object.h
index 69e4b7b..ddc3b81 100644
--- a/include/qemu/object.h
+++ b/include/qemu/object.h
@@ -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
diff --git a/qom/object.c b/qom/object.c
index aa037d2..eef0b22 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -572,6 +572,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++;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]