From patchwork Mon Jul 29 07:07:34 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcel Apfelbaum X-Patchwork-Id: 262694 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 60A3D2C0098 for ; Mon, 29 Jul 2013 17:09:10 +1000 (EST) Received: from localhost ([::1]:55030 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V3hZq-0002Bz-1R for incoming@patchwork.ozlabs.org; Mon, 29 Jul 2013 03:09:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59856) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V3hZA-00027Y-TS for qemu-devel@nongnu.org; Mon, 29 Jul 2013 03:08:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V3hZ4-0004qx-AL for qemu-devel@nongnu.org; Mon, 29 Jul 2013 03:08:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:4141) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V3hZ4-0004qr-3i for qemu-devel@nongnu.org; Mon, 29 Jul 2013 03:08:18 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r6T78Hll008942 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 29 Jul 2013 03:08:17 -0400 Received: from localhost.localdomain.com (vpn-201-135.tlv.redhat.com [10.35.201.135]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r6T789gl025920; Mon, 29 Jul 2013 03:08:15 -0400 From: Marcel Apfelbaum To: qemu-devel@nongnu.org Date: Mon, 29 Jul 2013 10:07:34 +0300 Message-Id: <1375081655-28541-3-git-send-email-marcel.a@redhat.com> In-Reply-To: <1375081655-28541-1-git-send-email-marcel.a@redhat.com> References: <1375081655-28541-1-git-send-email-marcel.a@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: pbonzini@redhat.com, aliguori@us.ibm.com, Marcel Apfelbaum , afaerber@suse.de, mst@redhat.com Subject: [Qemu-devel] [PATCH v2 2/3] qemu-help: Sort devices by logical functionality 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 Categorize devices that appear as output to "-device ?" command by logical functionality. Sort the devices by logical categories before showing them to user. The sort is done by functionality rather than alphabetical. Signed-off-by: Marcel Apfelbaum --- Changes from v1: Addressed Michael Tsirkin review: Used bitmap operations on categories Moved category names into the header file include/hw/qdev-core.h | 33 +++++++++++++++++++++++++++++++++ qdev-monitor.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 79 insertions(+), 4 deletions(-) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index e8b89b1..80b06ac 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -18,6 +18,38 @@ enum { #define DEVICE_CLASS(klass) OBJECT_CLASS_CHECK(DeviceClass, (klass), TYPE_DEVICE) #define DEVICE_GET_CLASS(obj) OBJECT_GET_CLASS(DeviceClass, (obj), TYPE_DEVICE) +typedef enum DeviceCategory { + DEVICE_CATEGORY_ASSEMBLY, + DEVICE_CATEGORY_MANAGEMENT, + DEVICE_CATEGORY_STORAGE, + DEVICE_CATEGORY_NETWORK, + DEVICE_CATEGORY_INPUT, + DEVICE_CATEGORY_DISPLAY, + DEVICE_CATEGORY_SOUND, + DEVICE_CATEGORY_MISC, + DEVICE_CATEGORY_MAX +} DeviceCategory; + +static inline const char *qdev_category_get_name(DeviceCategory category) +{ + /* Category names corresponding to DeviceCategory values + * The array elements must be in the same order as they + * appear in DeviceCategory enum. + */ + static const char *category_names[] = { + "Assembly", + "Management", + "Storage", + "Network", + "Input", + "Display", + "Sound", + "Misc", + }; + + return category_names[category]; +} + typedef int (*qdev_initfn)(DeviceState *dev); typedef int (*qdev_event)(DeviceState *dev); typedef void (*qdev_resetfn)(DeviceState *dev); @@ -81,6 +113,7 @@ typedef struct DeviceClass { ObjectClass parent_class; /*< public >*/ + DECLARE_BITMAP(categories, 20); const char *fw_name; const char *desc; Property *props; diff --git a/qdev-monitor.c b/qdev-monitor.c index e54dbc2..c3a3550 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -75,14 +75,21 @@ static bool qdev_class_has_alias(DeviceClass *dc) return (qdev_class_get_alias(dc) != NULL); } +typedef struct PrintDevInfoData { + bool show_no_user; + DeviceCategory category; +} PrintDevInfoData ; + static void qdev_print_devinfo(ObjectClass *klass, void *opaque) { DeviceClass *dc; - bool *show_no_user = opaque; + PrintDevInfoData *data = opaque; + DeviceCategory category; + category = data ? data->category : DEVICE_CATEGORY_MAX; dc = (DeviceClass *)object_class_dynamic_cast(klass, TYPE_DEVICE); - if (!dc || (show_no_user && !*show_no_user && dc->no_user)) { + if (!dc || (data && !data->show_no_user && dc->no_user)) { return; } @@ -93,6 +100,18 @@ static void qdev_print_devinfo(ObjectClass *klass, void *opaque) if (qdev_class_has_alias(dc)) { error_printf(", alias \"%s\"", qdev_class_get_alias(dc)); } + if (dc->categories) { + if (test_bit(category, dc->categories)) { + error_printf(", category \"%s\"", qdev_category_get_name(category)); + } else { + error_printf(", categories"); + for (category = 0; category < DEVICE_CATEGORY_MAX; ++category) { + if (test_bit(category, dc->categories)) { + error_printf(" \"%s\"", qdev_category_get_name(category)); + } + } + } + } if (dc->desc) { error_printf(", desc \"%s\"", dc->desc); } @@ -139,6 +158,23 @@ static const char *find_typename_by_alias(const char *alias) return NULL; } +static GSList *qdev_get_devices_by_category(DeviceCategory category) +{ + DeviceClass *dc; + GSList *list, *curr, *ret_list = NULL; + + list = object_class_get_list(TYPE_DEVICE, false); + for (curr = list; curr; curr = g_slist_next(curr)) { + dc = (DeviceClass *)object_class_dynamic_cast(curr->data, TYPE_DEVICE); + if (test_bit(category, dc->categories)) { + ret_list = g_slist_append(ret_list, dc); + } + } + g_slist_free(list); + + return ret_list; +} + int qdev_device_help(QemuOpts *opts) { const char *driver; @@ -147,8 +183,14 @@ int qdev_device_help(QemuOpts *opts) driver = qemu_opt_get(opts, "driver"); if (driver && is_help_option(driver)) { - bool show_no_user = false; - object_class_foreach(qdev_print_devinfo, TYPE_DEVICE, false, &show_no_user); + DeviceCategory category; + for (category = 0; category < DEVICE_CATEGORY_MAX; ++category) { + PrintDevInfoData data = { false, category }; + GSList *list = qdev_get_devices_by_category(category); + g_slist_foreach(list, (GFunc)qdev_print_devinfo, &data); + g_slist_free(list); + } + return 1; }