From: Marcel Apfelbaum <marcel.a@redhat.com>
To: qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, aliguori@us.ibm.com,
Marcel Apfelbaum <marcel.a@redhat.com>,
afaerber@suse.de, mst@redhat.com
Subject: [Qemu-devel] [PATCH v2 2/3] qemu-help: Sort devices by logical functionality
Date: Mon, 29 Jul 2013 10:07:34 +0300 [thread overview]
Message-ID: <1375081655-28541-3-git-send-email-marcel.a@redhat.com> (raw)
In-Reply-To: <1375081655-28541-1-git-send-email-marcel.a@redhat.com>
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 <marcel.a@redhat.com>
---
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;
}
--
1.8.3.1
next prev parent reply other threads:[~2013-07-29 7:08 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-29 7:07 [Qemu-devel] [PATCH v2 0/3] qemu-help: improve -device command line help Marcel Apfelbaum
2013-07-29 7:07 ` [Qemu-devel] [PATCH v2 1/3] hw: import bitmap operations in qdev-core header Marcel Apfelbaum
2013-07-29 7:42 ` Michael S. Tsirkin
2013-07-29 8:01 ` Marcel Apfelbaum
2013-07-29 7:07 ` Marcel Apfelbaum [this message]
2013-07-29 8:04 ` [Qemu-devel] [PATCH v2 2/3] qemu-help: Sort devices by logical functionality Michael S. Tsirkin
2013-07-29 8:14 ` Marcel Apfelbaum
2013-07-29 8:20 ` Michael S. Tsirkin
2013-07-29 9:09 ` Marcel Apfelbaum
2013-07-29 9:22 ` Michael S. Tsirkin
2013-07-29 9:26 ` Marcel Apfelbaum
2013-07-29 7:07 ` [Qemu-devel] [PATCH v2 3/3] devices: Associate devices to their logical category Marcel Apfelbaum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1375081655-28541-3-git-send-email-marcel.a@redhat.com \
--to=marcel.a@redhat.com \
--cc=afaerber@suse.de \
--cc=aliguori@us.ibm.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).