[v3,3/5] kvargs: add get by key function
Checks
Commit Message
Adds a new function to get value of a specific key from kvargs list.
Signed-off-by: Xueming Li <xuemingl@nvidia.com>
---
lib/librte_kvargs/rte_kvargs.c | 20 ++++++++++++++++++++
lib/librte_kvargs/rte_kvargs.h | 21 +++++++++++++++++++++
lib/librte_kvargs/version.map | 1 +
3 files changed, 42 insertions(+)
Comments
On 30/03/2021 13:15, Xueming Li wrote:
> Adds a new function to get value of a specific key from kvargs list.
>
> Signed-off-by: Xueming Li <xuemingl@nvidia.com>
> ---
> lib/librte_kvargs/rte_kvargs.c | 20 ++++++++++++++++++++
> lib/librte_kvargs/rte_kvargs.h | 21 +++++++++++++++++++++
> lib/librte_kvargs/version.map | 1 +
> 3 files changed, 42 insertions(+)
>
[SNIP]
> diff --git a/lib/librte_kvargs/version.map b/lib/librte_kvargs/version.map
> index ed375bf4a3..e2bf792c60 100644
> --- a/lib/librte_kvargs/version.map
> +++ b/lib/librte_kvargs/version.map
> @@ -12,6 +12,7 @@ DPDK_21 {
> EXPERIMENTAL {
> global:
>
Please separate rte_kvargs_get from the other symbols.
And add #21.05 in front, so we know when the symbol got added.
> + rte_kvargs_get;
> rte_kvargs_parse_delim;
> rte_kvargs_strcmp;
>
>
>-----Original Message-----
>From: Kinsella, Ray <mdr@ashroe.eu>
>Sent: Thursday, April 1, 2021 5:06 PM
>To: Xueming(Steven) Li <xuemingl@nvidia.com>; NBU-Contact-Thomas Monjalon <thomas@monjalon.net>; Gaetan Rivet
><gaetanr@nvidia.com>
>Cc: dev@dpdk.org; Asaf Penso <asafp@nvidia.com>; Olivier Matz <olivier.matz@6wind.com>; Neil Horman
><nhorman@tuxdriver.com>
>Subject: Re: [PATCH v3 3/5] kvargs: add get by key function
>
>
>
>On 30/03/2021 13:15, Xueming Li wrote:
>> Adds a new function to get value of a specific key from kvargs list.
>>
>> Signed-off-by: Xueming Li <xuemingl@nvidia.com>
>> ---
>> lib/librte_kvargs/rte_kvargs.c | 20 ++++++++++++++++++++
>> lib/librte_kvargs/rte_kvargs.h | 21 +++++++++++++++++++++
>> lib/librte_kvargs/version.map | 1 +
>> 3 files changed, 42 insertions(+)
>>
>
>[SNIP]
>
>> diff --git a/lib/librte_kvargs/version.map
>> b/lib/librte_kvargs/version.map index ed375bf4a3..e2bf792c60 100644
>> --- a/lib/librte_kvargs/version.map
>> +++ b/lib/librte_kvargs/version.map
>> @@ -12,6 +12,7 @@ DPDK_21 {
>> EXPERIMENTAL {
>> global:
>>
>Please separate rte_kvargs_get from the other symbols.
>And add #21.05 in front, so we know when the symbol got added.
Good point, thanks
>
>> + rte_kvargs_get;
>> rte_kvargs_parse_delim;
>> rte_kvargs_strcmp;
>>
>>
@@ -203,6 +203,26 @@ rte_kvargs_free(struct rte_kvargs *kvlist)
free(kvlist);
}
+/* Lookup a value in an rte_kvargs list by its key. */
+const char *
+rte_kvargs_get(const struct rte_kvargs *kvlist, const char *key)
+{
+ unsigned int i;
+
+ if (!kvlist)
+ return NULL;
+ for (i = 0; i < kvlist->count; ++i) {
+ /* Allows key to be NULL. */
+ if (!key && !kvlist->pairs[i].key)
+ return kvlist->pairs[i].value;
+ if (!key || !kvlist->pairs[i].key)
+ continue;
+ if (!strcmp(kvlist->pairs[i].key, key))
+ return kvlist->pairs[i].value;
+ }
+ return NULL;
+}
+
/*
* Parse the arguments "key=value,key=value,..." string and return
* an allocated structure that contains a key/value list. Also
@@ -114,6 +114,27 @@ struct rte_kvargs *rte_kvargs_parse_delim(const char *args,
*/
void rte_kvargs_free(struct rte_kvargs *kvlist);
+/**
+ * Get the value associated with a given key.
+ *
+ * If the key is NULL, the first value from the list is returned.
+ * If multiple key matches, the value of the first one is returned.
+ *
+ * The memory returned is allocated as part of the rte_kvargs structure,
+ * it must never be modified.
+ *
+ * @param kvlist
+ * A list of rte_kvargs pair of 'key=value'.
+ * @param key
+ * The matching key.
+
+ * @return
+ * NULL if no key matches the input, a value associated with a matching
+ * key otherwise.
+ */
+__rte_experimental
+const char *rte_kvargs_get(const struct rte_kvargs *kvlist, const char *key);
+
/**
* Call a handler function for each key/value matching the key
*
@@ -12,6 +12,7 @@ DPDK_21 {
EXPERIMENTAL {
global:
+ rte_kvargs_get;
rte_kvargs_parse_delim;
rte_kvargs_strcmp;