From: Marcel Apfelbaum <marcel.a@redhat.com>
To: qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, aliguori@us.ibm.com, afaerber@suse.de,
Marcel Apfelbaum <marcel.a@redhat.com>
Subject: [Qemu-devel] [RFC PATCH 1/2] qemu-help: Sort devices by logical functionality
Date: Thu, 18 Jul 2013 11:27:42 +0300 [thread overview]
Message-ID: <1374136063-24399-2-git-send-email-marcel.a@redhat.com> (raw)
In-Reply-To: <1374136063-24399-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.
Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
---
include/hw/qdev-core.h | 7 +++++++
qdev-monitor.c | 23 ++++++++++++++++++++++-
2 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index 7fbffcb..4f7a9b8 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -17,6 +17,12 @@ enum {
#define DEVICE_CLASS(klass) OBJECT_CLASS_CHECK(DeviceClass, (klass), TYPE_DEVICE)
#define DEVICE_GET_CLASS(obj) OBJECT_GET_CLASS(DeviceClass, (obj), TYPE_DEVICE)
+#define DEVICE_CATEGORY_STORAGE "storage"
+#define DEVICE_CATEGORY_NETWORK "network"
+#define DEVICE_CATEGORY_INPUT "input"
+#define DEVICE_CATEGORY_DISPLAY "display"
+#define DEVICE_CATEGORY_SOUND "sound"
+
typedef int (*qdev_initfn)(DeviceState *dev);
typedef int (*qdev_event)(DeviceState *dev);
typedef void (*qdev_resetfn)(DeviceState *dev);
@@ -81,6 +87,7 @@ typedef struct DeviceClass {
/*< public >*/
const char *fw_name;
+ const char *category;
const char *desc;
Property *props;
int no_user;
diff --git a/qdev-monitor.c b/qdev-monitor.c
index e54dbc2..1446b6e 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -93,6 +93,9 @@ 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->category) {
+ error_printf(", category \"%s\"", dc->category);
+ }
if (dc->desc) {
error_printf(", desc \"%s\"", dc->desc);
}
@@ -139,16 +142,34 @@ static const char *find_typename_by_alias(const char *alias)
return NULL;
}
+static gint qdev_device_compare(gconstpointer item1, gconstpointer item2)
+{
+ DeviceClass *dc1, *dc2;
+
+ dc1 = (DeviceClass *)object_class_dynamic_cast((ObjectClass *)item1,
+ TYPE_DEVICE);
+ dc2 = (DeviceClass *)object_class_dynamic_cast((ObjectClass *)item2,
+ TYPE_DEVICE);
+
+ return g_strcmp0(dc1->category, dc2->category);
+}
+
int qdev_device_help(QemuOpts *opts)
{
const char *driver;
Property *prop;
ObjectClass *klass;
+ GSList *list;
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);
+
+ list = object_class_get_list(TYPE_DEVICE, false);
+ list = g_slist_sort(list, qdev_device_compare);
+ g_slist_foreach(list, (GFunc)qdev_print_devinfo, &show_no_user);
+ g_slist_free(list);
+
return 1;
}
--
1.8.3.1
next prev parent reply other threads:[~2013-07-18 8:28 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-18 8:27 [Qemu-devel] [RFC PATCH 0/2] qemu-help: improve -device command line help Marcel Apfelbaum
2013-07-18 8:27 ` Marcel Apfelbaum [this message]
2013-07-18 14:12 ` [Qemu-devel] [RFC PATCH 1/2] qemu-help: Sort devices by logical functionality Michael S. Tsirkin
2013-07-18 14:28 ` Anthony Liguori
2013-07-18 14:42 ` Marcel Apfelbaum
2013-07-18 14:49 ` Paolo Bonzini
2013-07-18 14:58 ` Anthony Liguori
2013-07-18 15:23 ` Marcel Apfelbaum
2013-07-18 15:32 ` Paolo Bonzini
2013-07-21 8:03 ` Michael S. Tsirkin
2013-07-21 13:57 ` Ronen Hod
2013-07-18 8:27 ` [Qemu-devel] [RFC PATCH 2/2] devices: Associate devices to their logical category Marcel Apfelbaum
2013-07-18 13:56 ` [Qemu-devel] [RFC PATCH 0/2] qemu-help: improve -device command line help Paolo Bonzini
2013-07-18 14:02 ` Marcel Apfelbaum
2013-07-18 15:04 ` Eric Blake
2013-07-21 12:09 ` Andreas Färber
2013-07-21 12:49 ` Michael S. Tsirkin
2013-07-29 20:24 ` Anthony Liguori
-- strict thread matches above, loose matches on Subject: below --
2013-07-18 9:06 Marcel Apfelbaum
2013-07-18 9:06 ` [Qemu-devel] [RFC PATCH 1/2] qemu-help: Sort devices by logical functionality 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=1374136063-24399-2-git-send-email-marcel.a@redhat.com \
--to=marcel.a@redhat.com \
--cc=afaerber@suse.de \
--cc=aliguori@us.ibm.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).