Skip to contentSkip to conversation

qom: Sorted class enumeration

RFC New Andreas Färber 2 participants 3 messages Feb 22, 2012

lore
Share & tools
lore
#0 lore raw

Hello,

For listing registered CPU classes I needed a way to sort classes in a custom (i.e., non-hashtable) order. I found it easiest to sort the classes using the existing foreach infrastructure, on the go via GLib's binary tree.

Patch is still missing documentation, but do you think this is the right direction, Anthony?

I've been wondering if it might make sense to replace the current filtering mechanism (abstract and type) with another callback function or whether that would be overkill - currently the only other filtering I needed to do was to ignore the "host" CPU class, which can be done by simple if in the callback.

Regards,
Andreas

Andreas Färber (1):
qom: Introduce object_class_foreach_ordered()

 include/qemu/object.h |    6 ++++++
 qom/object.c          |   43 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 0 deletions(-)
Signature · 1 line
1.7.7
#1 lore raw

RFC PATCH 1/1 qom: Introduce object_class_foreach_ordered()

This functions allows to walk the classes in a custom order rather than in hashtable order.

Cc Anthony Liguori <[email protected]>
Cc Peter Maydell <[email protected]>
---
 include/qemu/object.h |    6 ++++++
 qom/object.c          |   43 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 0 deletions(-)
include/qemu/object.h +6 -0
index 5179c0c..ab3597a 100644
@@ -560,6 +560,12 @@ 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);
+
+void object_class_foreach_ordered(void (*fn)(ObjectClass *klass, void *opaque),
+                                  const char *implements_type,
+                                  bool include_abstract, void *opaque,
+                                  GCompareFunc compfn);
+
 /**
  * object_ref:
  * @obj: the object
qom/object.c +43 -0

49 lines not on this page · raw message

Signature · 1 line
1.7.7
#2 lore raw
In reply to Andreas Färber
Quoted 8 lines · Andreas Färber

Hello,

For listing registered CPU classes I needed a way to sort classes in a custom (i.e., non-hashtable) order. I found it easiest to sort the classes using the existing foreach infrastructure, on the go via GLib's binary tree.

Patch is still missing documentation, but do you think this is the right direction, Anthony?

I think it might be better to have an object_class_search() function that acts like object_class_foreach() but returns a GSList. You can then call g_list_sort() on the resulting data structure.

Quoted 4 lines

I've been wondering if it might make sense to replace the current filtering mechanism (abstract and type) with another callback function or whether that would be overkill - currently the only other filtering I needed to do was to ignore the "host" CPU class, which can be done by simple if in the callback.

I'd prefer not to do callbacks because this interface gets exposed via QMP and callbacks can't be modeled via QMP.

Regards,

Anthony Liguori

Quoted 11 lines

Regards,
Andreas

Andreas Färber (1):
qom: Introduce object_class_foreach_ordered()

  include/qemu/object.h |    6 ++++++
  qom/object.c          |   43 +++++++++++++++++++++++++++++++++++++++++++
  2 files changed, 49 insertions(+), 0 deletions(-)