From patchwork Wed Jun 11 14:50:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 358732 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 11376140085 for ; Thu, 12 Jun 2014 00:59:20 +1000 (EST) Received: from localhost ([::1]:47031 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wujzh-0001in-CX for incoming@patchwork.ozlabs.org; Wed, 11 Jun 2014 10:59:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44937) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WujsC-0005u5-6e for qemu-devel@nongnu.org; Wed, 11 Jun 2014 10:51:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wujs3-0008CX-KC for qemu-devel@nongnu.org; Wed, 11 Jun 2014 10:51:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:18046) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wujs3-0008Bc-An for qemu-devel@nongnu.org; Wed, 11 Jun 2014 10:51:23 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s5BEpFWR028121 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Jun 2014 10:51:16 -0400 Received: from localhost (ovpn-113-65.phx2.redhat.com [10.3.113.65]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s5BEpFeu027600; Wed, 11 Jun 2014 10:51:15 -0400 From: Luiz Capitulino To: peter.maydell@linaro.org Date: Wed, 11 Jun 2014 10:50:59 -0400 Message-Id: <1402498262-20521-15-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1402498262-20521-1-git-send-email-lcapitulino@redhat.com> References: <1402498262-20521-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: qemu-devel@nongnu.org, anthony@codemonkey.ws Subject: [Qemu-devel] [PULL 14/17] monitor: Add host_net_remove arguments completion 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 From: Hani Benhabiles Relies on readline unique completion strings patch to make the added vlan/hub completion values unique, instead of using something like a hash table. Signed-off-by: Hani Benhabiles Reviewed-by: Stefan Hajnoczi Signed-off-by: Luiz Capitulino --- hmp-commands.hx | 1 + hmp.h | 2 ++ monitor.c | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/hmp-commands.hx b/hmp-commands.hx index aab9cf5..f99da0e 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1227,6 +1227,7 @@ ETEXI .params = "vlan_id name", .help = "remove host VLAN client", .mhandler.cmd = net_host_device_remove, + .command_completion = host_net_remove_completion, }, STEXI diff --git a/hmp.h b/hmp.h index 22ee836..a53ad51 100644 --- a/hmp.h +++ b/hmp.h @@ -110,5 +110,7 @@ void watchdog_action_completion(ReadLineState *rs, int nb_args, void migrate_set_capability_completion(ReadLineState *rs, int nb_args, const char *str); void host_net_add_completion(ReadLineState *rs, int nb_args, const char *str); +void host_net_remove_completion(ReadLineState *rs, int nb_args, + const char *str); #endif diff --git a/monitor.c b/monitor.c index 0189bf8..d6c4f85 100644 --- a/monitor.c +++ b/monitor.c @@ -4610,6 +4610,44 @@ void host_net_add_completion(ReadLineState *rs, int nb_args, const char *str) } } +void host_net_remove_completion(ReadLineState *rs, int nb_args, const char *str) +{ + NetClientState *ncs[255]; + int count, i, len; + + len = strlen(str); + readline_set_completion_index(rs, len); + if (nb_args == 2) { + count = qemu_find_net_clients_except(NULL, ncs, + NET_CLIENT_OPTIONS_KIND_NONE, 255); + for (i = 0; i < count; i++) { + int id; + char name[16]; + + if (net_hub_id_for_client(ncs[i], &id)) { + continue; + } + snprintf(name, sizeof(name), "%d", id); + if (!strncmp(str, name, len)) { + readline_add_completion(rs, name); + } + } + return; + } else if (nb_args == 3) { + count = qemu_find_net_clients_except(NULL, ncs, + NET_CLIENT_OPTIONS_KIND_NIC, 255); + for (i = 0; i < count; i++) { + const char *name; + + name = ncs[i]->name; + if (!strncmp(str, name, len)) { + readline_add_completion(rs, name); + } + } + return; + } +} + static void monitor_find_completion_by_table(Monitor *mon, const mon_cmd_t *cmd_table, char **args,