From: Andrzej Zaborowski <balrogg@gmail.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] Add tab-completion for device_add.
Date: Sun, 8 Jan 2012 16:28:54 +0100 [thread overview]
Message-ID: <1326036534-18029-1-git-send-email-balrogg@gmail.com> (raw)
In-Reply-To: <yes>
Signed-off-by: Andrzej Zaborowski <andrew.zaborowski@intel.com>
---
There are other ways to do this, but adding an API for querying
available qdev drivers was the one that made most sense to me.
---
hw/qdev.c | 38 ++++++++++++++++++++++++++++++++++++++
hw/qdev.h | 7 +++++++
monitor.c | 41 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 86 insertions(+), 0 deletions(-)
diff --git a/hw/qdev.c b/hw/qdev.c
index d0cf66d..ba97312 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -1535,3 +1535,41 @@ void qdev_machine_init(void)
qdev_get_peripheral_anon();
qdev_get_peripheral();
}
+
+int qdev_driver_foreach(qdev_driver_foreach_func func, void *opaque)
+{
+ DeviceInfo *info;
+ int ret = 0;
+
+ for (info = device_info_list; info != NULL; info = info->next) {
+ ret |= (*func)(info, opaque);
+ }
+
+ return ret;
+}
+
+int qdev_driver_prop_foreach(qdev_driver_prop_foreach_func func,
+ const char *driver, void *opaque)
+{
+ DeviceInfo *info;
+ Property *prop;
+ int ret = 0;
+
+ info = qdev_find_info(NULL, driver);
+ if (!info) {
+ return -1;
+ }
+
+ for (prop = info->props; prop && prop->name; prop++) {
+ /*
+ * TODO Properties without a parser are just for dirty hacks.
+ * See comment in qdev_device_help.
+ */
+ if (!prop->info->parse) {
+ continue; /* no way to set it, don't show */
+ }
+ ret |= (*func)(prop, opaque);
+ }
+
+ return ret;
+}
diff --git a/hw/qdev.h b/hw/qdev.h
index 2abb767..b72a31a 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -624,4 +624,11 @@ char *qdev_get_type(DeviceState *dev, Error **errp);
*/
void qdev_machine_init(void);
+/* Driver querying */
+typedef int (*qdev_driver_foreach_func)(DeviceInfo *info, void *opaque);
+int qdev_driver_foreach(qdev_driver_foreach_func func, void *opaque);
+typedef int (*qdev_driver_prop_foreach_func)(Property *info, void *opaque);
+int qdev_driver_prop_foreach(qdev_driver_prop_foreach_func func,
+ const char *driver, void *opaque);
+
#endif
diff --git a/monitor.c b/monitor.c
index 7334401..3eab307 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4069,6 +4069,28 @@ static void block_completion_it(void *opaque, BlockDriverState *bs)
}
}
+static int driver_completion_it(DeviceInfo *info, void *opaque)
+{
+ const char *input = opaque;
+
+ if (input[0] == '\0' || !strncmp(info->name, input, strlen(input))) {
+ readline_add_completion(cur_mon->rs, info->name);
+ }
+
+ return 0;
+}
+
+static int driver_prop_completion_it(Property *prop, void *opaque)
+{
+ const char *input = opaque;
+
+ if (input[0] == '\0' || !strncmp(prop->name, input, strlen(input))) {
+ readline_add_completion(cur_mon->rs, prop->name);
+ }
+
+ return 0;
+}
+
/* NOTE: this parser is an approximate form of the real command parser */
static void parse_cmdline(const char *cmdline,
int *pnb_args, char **args)
@@ -4109,6 +4131,7 @@ static void monitor_find_completion(const char *cmdline)
const char *ptype, *str;
const mon_cmd_t *cmd;
const KeyDef *key;
+ char *pkey;
parse_cmdline(cmdline, &nb_args, args);
#ifdef DEBUG_COMPLETION
@@ -4147,6 +4170,7 @@ static void monitor_find_completion(const char *cmdline)
goto cleanup;
}
+ key_get_info(cmd->args_type, &pkey);
ptype = next_arg_type(cmd->args_type);
for(i = 0; i < nb_args - 2; i++) {
if (*ptype != '\0') {
@@ -4192,9 +4216,26 @@ static void monitor_find_completion(const char *cmdline)
}
}
break;
+ case 'O':
+ if (!strcmp(pkey, "device")) {
+ char *sep = strrchr(str, ',');
+
+ readline_set_completion_index(cur_mon->rs,
+ strlen(sep ? sep + 1 : str));
+ if (sep) {
+ char *driver = g_strndup(str, strchr(str, ',') - str);
+ qdev_driver_prop_foreach(driver_prop_completion_it,
+ driver, (void *) (sep + 1));
+ g_free(driver);
+ } else {
+ qdev_driver_foreach(driver_completion_it, (void *) str);
+ }
+ }
+ break;
default:
break;
}
+ g_free(pkey);
}
cleanup:
--
1.7.4.4
next parent reply other threads:[~2012-01-09 2:27 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <yes>
2012-01-08 15:28 ` Andrzej Zaborowski [this message]
2012-01-12 17:01 ` [Qemu-devel] [PATCH] Add tab-completion for device_add Anthony Liguori
2019-12-04 9:36 ` [PATCH] i386: pass CLZERO to guests with EPYC CPU model on AMD ZEN platform Ani Sinha
2019-12-16 9:31 ` Ani Sinha
2012-01-08 15:14 [Qemu-devel] [PATCH] Add tab-completion for device_add Andrzej Zaborowski
2012-01-09 2:19 ` andrzej zaborowski
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=1326036534-18029-1-git-send-email-balrogg@gmail.com \
--to=balrogg@gmail.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).