From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) by dpdk.org (Postfix) with ESMTP id 204421C161 for ; Fri, 13 Apr 2018 15:23:13 +0200 (CEST) Received: by mail-wm0-f68.google.com with SMTP id i3so4154835wmf.3 for ; Fri, 13 Apr 2018 06:23:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=y8qr/vLSXkYz29nKLmInF6P56peAaXHB7YSHhJOGLE4=; b=2SuJ93JOQ3dc/8WprOX+hLO2NX5Cv9M8c4S1gdknj2AQxjAvUBb7iwsi0RFQ6VpgGa WgH4fydrcB4YDHz57uuba6Pn9H6Ih3npPvUe7dsDaIOuUtBy/NNYLIEtrZat7UbsAXhw YU2oqSB4RhRQtfuRFvzmWUFZVGJgvghvDvsafpGrUJgGpMym9/U+0YxgZmLpqzSD6Bet EhehNYD9BCBmiYm9VUD5YpQN0oxIvI7iImOGJt9vl7fz5KzBrUGVr2tqkbXzrBoZ0Cr6 BgwBdgE9iRawf+QRaY6nw84mY8cZ2o15uaVyye0nSfKPq85X9a+TmT5ph8cGV4yMWWZ0 mxCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=y8qr/vLSXkYz29nKLmInF6P56peAaXHB7YSHhJOGLE4=; b=BwYJlhf7QHHR8jJzHjzYfbfr8VRjGBE6gmfVS8Om7Sditfbl133tqhliA9tKGkNbtI j5IWM1bREpEmujHQUuv4Gm3sIBuVo01FTTR2TqgImcYnyEB2prBqqZ+2cdHp507TtbaO tkz9ZELCwo5UpF7LrvxHBOm4Q5eHNcU+L+Z+D88ZhUBTlPYb65brdG9n7qECI8FhPtcI Wfh8mCC/oCImgjcQvqRTmxJUmpNikYHX9I2+BKxHZt+28ph6zlBQGl4YQDevN4yJc14S uPTsGUqTpOIPzROaGGeW0k4QxCkFOWXpgFcHyi65ydcxOemuMOva5nM9BZPlEXUzSdEb ncKg== X-Gm-Message-State: ALQs6tDyNUCR4lB0EBRsgIqAGD2o7hURtmv14Wb0iLFyomgi99LVX0pU 5xF00u7UP0LpOLzu+4VDIwtYiee9 X-Google-Smtp-Source: AIpwx4+cctr6Z0xw+gtXH0fRqJiWwOCnmtzkryooQQDHya4/UIhg05CSG92/wucqucGL+OD7sBD6WQ== X-Received: by 10.28.12.17 with SMTP id 17mr3527284wmm.75.1523625792320; Fri, 13 Apr 2018 06:23:12 -0700 (PDT) Received: from bidouze.dev.6wind.com. (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id r200sm2377244wmb.9.2018.04.13.06.23.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Apr 2018 06:23:11 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Fri, 13 Apr 2018 15:22:27 +0200 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v6 12/22] kvargs: add generic string matching callback X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Apr 2018 13:23:13 -0000 This function can be used as a callback to rte_kvargs_process. This should reduce code duplication. Signed-off-by: Gaetan Rivet --- lib/Makefile | 1 + lib/librte_kvargs/rte_kvargs.c | 10 ++++++++++ lib/librte_kvargs/rte_kvargs.h | 28 ++++++++++++++++++++++++++++ lib/librte_kvargs/rte_kvargs_version.map | 7 +++++++ 4 files changed, 46 insertions(+) diff --git a/lib/Makefile b/lib/Makefile index 1b17526f7..4206485d3 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -5,6 +5,7 @@ include $(RTE_SDK)/mk/rte.vars.mk DIRS-y += librte_compat DIRS-$(CONFIG_RTE_LIBRTE_KVARGS) += librte_kvargs +DEPDIRS-librte_kvargs := librte_compat DIRS-$(CONFIG_RTE_LIBRTE_EAL) += librte_eal DEPDIRS-librte_eal := librte_kvargs DIRS-$(CONFIG_RTE_LIBRTE_PCI) += librte_pci diff --git a/lib/librte_kvargs/rte_kvargs.c b/lib/librte_kvargs/rte_kvargs.c index 0a1abf579..6ee04cbb9 100644 --- a/lib/librte_kvargs/rte_kvargs.c +++ b/lib/librte_kvargs/rte_kvargs.c @@ -180,3 +180,13 @@ rte_kvargs_parse(const char *args, const char * const valid_keys[]) return kvlist; } + +__rte_experimental +int +rte_kvargs_strcmp(const char *key __rte_unused, + const char *value, void *opaque) +{ + const char *str = opaque; + + return -strcmp(str, value); +} diff --git a/lib/librte_kvargs/rte_kvargs.h b/lib/librte_kvargs/rte_kvargs.h index 51b8120b8..c07c6fea5 100644 --- a/lib/librte_kvargs/rte_kvargs.h +++ b/lib/librte_kvargs/rte_kvargs.h @@ -25,6 +25,8 @@ extern "C" { #endif +#include + /** Maximum number of key/value associations */ #define RTE_KVARGS_MAX 32 @@ -121,6 +123,32 @@ int rte_kvargs_process(const struct rte_kvargs *kvlist, unsigned rte_kvargs_count(const struct rte_kvargs *kvlist, const char *key_match); +/** + * Generic kvarg handler for string comparison. + * + * This function can be used for a generic string comparison processing + * on a list of kvargs. + * + * @param key + * kvarg pair key. + * + * @param value + * kvarg pair value. + * + * @param opaque + * Opaque pointer to a string. + * + * @return + * 0 if the strings match. + * !0 otherwise or on error. + * + * Unless strcmp, comparison ordering is not kept. + * In order for rte_kvargs_process to stop processing on match error, + * a negative value is returned even if strcmp had returned a positive one. + */ +__rte_experimental +int rte_kvargs_strcmp(const char *key, const char *value, void *opaque); + #ifdef __cplusplus } #endif diff --git a/lib/librte_kvargs/rte_kvargs_version.map b/lib/librte_kvargs/rte_kvargs_version.map index 2030ec46c..e2f663a88 100644 --- a/lib/librte_kvargs/rte_kvargs_version.map +++ b/lib/librte_kvargs/rte_kvargs_version.map @@ -8,3 +8,10 @@ DPDK_2.0 { local: *; }; + +EXPERIMENTAL { + global: + + rte_kvargs_strcmp; + +} DPDK_2.0; -- 2.11.0