From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by dpdk.org (Postfix) with ESMTP id E85C27CC4 for ; Thu, 29 Mar 2018 23:24:26 +0200 (CEST) Received: by mail-wm0-f65.google.com with SMTP id r82so14019716wme.0 for ; Thu, 29 Mar 2018 14:24:26 -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=Oks/MFqFD90LwjvN0Er9r4BI6YBHYYcAxQNvDV6b6m656tXKFu7B2wZK5JoBAekNUu XhO/FmCDyvkjrR1tBUZNN6pLXgYPKRa7HlrNcG1Oo76dbejrb2bZLPOHcq6UhAfuVJu+ iiLco0WbUugYN7AW4GQTJq/YqAy0vDcaiHWDHBgnoG6GqZSJye/IVjjO8csVtYLVzifj F0tymIBw7PuQ011g0ByCtmZCthLLDc2Obw6jYTLnzAqkWUcglab2aD4JyqlzXzYKf6xl BojSaSeWZqOaT11L82hfXQuvtCWs5nnhkDJxdkQC5rDBmvt7XcxZ5RClAdQS2HdZHY9B puPA== 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=QkACc4rdbe9u8C9DwZYWyaZGiEwsmBmAfi59ixuVeKB+9hDHeFSz9l6icDEox5+8Gj LRFZj2F1R9PE2OZGvSatAQYYEPRTjZydC2eqPDJEYUfuh6/L1lSWnMxFqRcxXzUjhgyz l4EOQi7Y6mHd2JeTKEfpFSzmICDxBPgGdXoQobofAGHSVbt/QagNTkdVHDjfY5ovr8Tg XGygjK4nPjywxKjQJIooaZba7kujVR8U/YuK+2/prPo8zWaIHc9aqtW3eT8Kevre0p+m 7Zxi3yl9uR0vwdjUhAU3VwUs87aNKbNFB5dLU6y2p5DTwuGvxLNMpi+ZT81cXMnVv2+Y Zv1A== X-Gm-Message-State: ALQs6tCuA0gPTfBmkX7ZXiJMn4Sd8vQTc9Tr76tts7crTD5tNsDZ3FTy D/n9jnv8KsaTxXjkxm5IGEaHzTCa X-Google-Smtp-Source: AIpwx4/DBwhZXP0LBmpwigjfqB9rVTRZ37KYOfWDHBlSyI+JXp9d7l+8Wo7+69XpLSgSu8RK1mjpUA== X-Received: by 10.28.48.76 with SMTP id w73mr41502wmw.156.1522358666226; Thu, 29 Mar 2018 14:24:26 -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 m35sm11907457wrm.59.2018.03.29.14.24.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Mar 2018 14:24:25 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Thu, 29 Mar 2018 23:23:35 +0200 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v4 11/20] 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: Thu, 29 Mar 2018 21:24:27 -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