From patchwork Sun Jan 8 15:14:49 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrzej zaborowski X-Patchwork-Id: 134958 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id AA508B6FA0 for ; Mon, 9 Jan 2012 13:13:31 +1100 (EST) Received: from localhost ([::1]:38988 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rk4jn-0005Ae-Jz for incoming@patchwork.ozlabs.org; Sun, 08 Jan 2012 21:13:27 -0500 Received: from eggs.gnu.org ([140.186.70.92]:44670) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rk4ji-0005AV-Bu for qemu-devel@nongnu.org; Sun, 08 Jan 2012 21:13:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rk4jh-0005vQ-BC for qemu-devel@nongnu.org; Sun, 08 Jan 2012 21:13:22 -0500 Received: from mail-ww0-f53.google.com ([74.125.82.53]:55774) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rk4jh-0005vL-2k for qemu-devel@nongnu.org; Sun, 08 Jan 2012 21:13:21 -0500 Received: by wgbdt10 with SMTP id dt10so1058525wgb.10 for ; Sun, 08 Jan 2012 18:13:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:subject:date:message-id:x-mailer; bh=+ivLdtt4D2bJBs6AY3d79EgoeL0kUK2yIKdHorz75IE=; b=KWnU4EIr+J1FyJvbp8S3T8myTpJ30ZiNgg2l6OP7PF9DNGM9iezY+UKHppTFAvcdZl cwsV4iUSMS27kJ+YZEDu+a/RWsdGTrJbLMkw5pnOOB0CYxussgAmfp/Bd7bfgW7mAFpO 8yMwT9EudboDsXb1HBPNfnsGWnS5QmZPeo/No= Received: by 10.180.88.169 with SMTP id bh9mr1583710wib.20.1326075200357; Sun, 08 Jan 2012 18:13:20 -0800 (PST) Received: from azaborow-mobl.ger.corp.intel.com (80.224.83.224.static.user.ono.com. [80.224.83.224]) by mx.google.com with ESMTPS id r1sm4867507wia.8.2012.01.08.18.13.18 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 08 Jan 2012 18:13:19 -0800 (PST) Received: by azaborow-mobl.ger.corp.intel.com (sSMTP sendmail emulation); Sun, 08 Jan 2012 16:14:49 +0100 From: Andrzej Zaborowski To: qemu-devel@nongnu.org Date: Sun, 8 Jan 2012 16:14:49 +0100 Message-Id: <1326035689-16242-1-git-send-email-balrogg@gmail.com> X-Mailer: git-send-email 1.7.1.86.g0e460.dirty X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 74.125.82.53 Subject: [Qemu-devel] [PATCH] Add tab-completion for device_add. 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 Signed-off-by: Andrzej Zaborowski --- 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 = qemu_strndup(str, strchr(str, ',') - str); + qdev_driver_prop_foreach(driver_prop_completion_it, + driver, (void *) (sep + 1)); + qemu_free(driver); + } else { + qdev_driver_foreach(driver_completion_it, (void *) str); + } + } + break; default: break; } + qemu_free(pkey); } cleanup: