From patchwork Sun Mar 30 10:58:37 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hani Benhabiles X-Patchwork-Id: 335100 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 CB7B71400C3 for ; Sun, 30 Mar 2014 22:15:39 +1100 (EST) Received: from localhost ([::1]:43753 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WUDWO-0005vH-VM for incoming@patchwork.ozlabs.org; Sun, 30 Mar 2014 07:03:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34725) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WUDSS-00007n-5p for qemu-devel@nongnu.org; Sun, 30 Mar 2014 06:59:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WUDSM-0003ZW-5U for qemu-devel@nongnu.org; Sun, 30 Mar 2014 06:59:20 -0400 Received: from mail-ee0-x22d.google.com ([2a00:1450:4013:c00::22d]:48924) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WUDSL-0003ZM-V7 for qemu-devel@nongnu.org; Sun, 30 Mar 2014 06:59:14 -0400 Received: by mail-ee0-f45.google.com with SMTP id d17so5668431eek.32 for ; Sun, 30 Mar 2014 03:59:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6AVfkNXAOjYkc65ZWDUxOMHwX+EHKGVlaLqKdoZrlpc=; b=DMCvOmJELImGGQ78vZcLwFO6UlDMp5Ju/wGRBBxwlQuWbQxr5i2rASTiD2N8KyDAAE 0K8Ug/n4OAV5beUR0OOounMwEdEXhVoTQunpiRDEF/NppJ5hrf9AgS5De/7rSTLpXF+Y E81TJOOkpbrz4tdzqmpYWevZy1bLsZ7cz8h843eCnOXMa2S5OXGVOBP5RboJjOK++dm4 flVaO4brz/331wHcydSkca1xtbcZ2S21bvSG1/hr2J3JU8Q6Shnbnn1aQ+QdeL1oIf8i vC2wF2UehV4+oFeobkhbfZ3KKgjK6YHf372TDcGTV+KFecMmcXb9vAFb3A7f4Dk1JMhr tXGg== X-Received: by 10.15.54.6 with SMTP id s6mr23888990eew.4.1396177153145; Sun, 30 Mar 2014 03:59:13 -0700 (PDT) Received: from localhost.localdomain ([41.109.152.17]) by mx.google.com with ESMTPSA id y51sm25023258eeu.0.2014.03.30.03.59.11 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 30 Mar 2014 03:59:12 -0700 (PDT) From: Hani Benhabiles To: qemu-devel@nongnu.org Date: Sun, 30 Mar 2014 11:58:37 +0100 Message-Id: <1396177119-24955-16-git-send-email-kroosec@gmail.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1396177119-24955-1-git-send-email-kroosec@gmail.com> References: <1396177119-24955-1-git-send-email-kroosec@gmail.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4013:c00::22d Cc: kwolf@redhat.com, aliguori@amazon.com, lcapitulino@redhat.com, stefanha@redhat.com, imammedo@redhat.com Subject: [Qemu-devel] [PATCH v2 15/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 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 --- 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 9da5866..b41a6d6 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1219,6 +1219,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 c82fd87..12f0364 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 4c20bc5..9781ee2 100644 --- a/monitor.c +++ b/monitor.c @@ -4619,6 +4619,44 @@ void host_net_add_completion(ReadLineState *rs, int nb_args, const char *str) add_completion_option(rs, str, "bridge"); } +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,