From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47089) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UzpBu-0001yR-B2 for qemu-devel@nongnu.org; Thu, 18 Jul 2013 10:28:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UzpBt-0000n2-0x for qemu-devel@nongnu.org; Thu, 18 Jul 2013 10:28:22 -0400 Received: from e9.ny.us.ibm.com ([32.97.182.139]:37107) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UzpBs-0000lN-TN for qemu-devel@nongnu.org; Thu, 18 Jul 2013 10:28:20 -0400 Received: from /spool/local by e9.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 18 Jul 2013 10:28:07 -0400 Received: from d01relay06.pok.ibm.com (d01relay06.pok.ibm.com [9.56.227.116]) by d01dlp03.pok.ibm.com (Postfix) with ESMTP id 562D7C90044 for ; Thu, 18 Jul 2013 10:28:04 -0400 (EDT) Received: from d01av05.pok.ibm.com (d01av05.pok.ibm.com [9.56.224.195]) by d01relay06.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r6IES5Dl30015732 for ; Thu, 18 Jul 2013 10:28:05 -0400 Received: from d01av05.pok.ibm.com (loopback [127.0.0.1]) by d01av05.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r6IES5b5013131 for ; Thu, 18 Jul 2013 10:28:05 -0400 From: Anthony Liguori In-Reply-To: <1374136063-24399-2-git-send-email-marcel.a@redhat.com> References: <1374136063-24399-1-git-send-email-marcel.a@redhat.com> <1374136063-24399-2-git-send-email-marcel.a@redhat.com> Date: Thu, 18 Jul 2013 09:28:00 -0500 Message-ID: <87ppugdjtb.fsf@codemonkey.ws> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: Re: [Qemu-devel] [RFC PATCH 1/2] qemu-help: Sort devices by logical functionality List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Marcel Apfelbaum , qemu-devel@nongnu.org Cc: pbonzini@redhat.com, afaerber@suse.de Marcel Apfelbaum writes: > 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 > Reviewed-by: Kevin Wolf > --- > 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" > + Looks reasonable, but please make this a bitmap. There are cases, particularly if we start modeling multifunction PCI cards as a single device, where a single device can support multiple types of functionality. Regards, Anthony Liguori > 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