From patchwork Sat Feb 25 22:07:34 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 143076 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C43FBB6FB9 for ; Sun, 26 Feb 2012 09:08:00 +1100 (EST) Received: from localhost ([::1]:46025 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S1PmX-00049X-HY for incoming@patchwork.ozlabs.org; Sat, 25 Feb 2012 17:07:57 -0500 Received: from eggs.gnu.org ([208.118.235.92]:55421) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S1PmN-00048i-Gp for qemu-devel@nongnu.org; Sat, 25 Feb 2012 17:07:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S1PmI-0001AZ-3p for qemu-devel@nongnu.org; Sat, 25 Feb 2012 17:07:47 -0500 Received: from cantor2.suse.de ([195.135.220.15]:51726 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S1PmH-0001AJ-QP for qemu-devel@nongnu.org; Sat, 25 Feb 2012 17:07:42 -0500 Received: from relay1.suse.de (unknown [195.135.220.254]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id A5E12970AD; Sat, 25 Feb 2012 23:07:40 +0100 (CET) From: =?UTF-8?q?Andreas=20F=C3=A4rber?= To: qemu-devel@nongnu.org Date: Sat, 25 Feb 2012 23:07:34 +0100 Message-Id: <1330207654-25841-1-git-send-email-afaerber@suse.de> X-Mailer: git-send-email 1.7.7 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 X-Received-From: 195.135.220.15 Cc: =?UTF-8?q?Andreas=20F=C3=A4rber?= , Anthony Liguori Subject: [Qemu-devel] [PATCH v2] qom: Introduce object_class_get_list() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This function allows to obtain a singly-linked list of classes, which can be sorted by the caller. Signed-off-by: Andreas Färber Cc: 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++;