[dpdk-dev] [PATCH v3] cfgfile: support looking up sections by index

Dumitrescu, Cristian cristian.dumitrescu at intel.com
Tue Feb 16 21:48:22 CET 2016



> -----Original Message-----
> From: Rich Lane [mailto:rich.lane at bigswitch.com]
> Sent: Wednesday, February 10, 2016 7:12 PM
> To: dev at dpdk.org
> Cc: Dumitrescu, Cristian <cristian.dumitrescu at intel.com>; Panu Matilainen
> <pmatilai at redhat.com>
> Subject: [PATCH v3] cfgfile: support looking up sections by index
> 
> This is useful when sections have duplicate names.
> 
> Signed-off-by: Rich Lane <rlane at bigswitch.com>
> ---
> v2->v3
> - Added check for index < 0.
> v1->v2:
> - Added new symbol to version script.
> 
>  lib/librte_cfgfile/rte_cfgfile.c           | 16 ++++++++++++++++
>  lib/librte_cfgfile/rte_cfgfile.h           | 23 +++++++++++++++++++++++
>  lib/librte_cfgfile/rte_cfgfile_version.map |  6 ++++++
>  3 files changed, 45 insertions(+)
> 
> diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c
> index a677dad..eba0713 100644
> --- a/lib/librte_cfgfile/rte_cfgfile.c
> +++ b/lib/librte_cfgfile/rte_cfgfile.c
> @@ -333,6 +333,22 @@ rte_cfgfile_section_entries(struct rte_cfgfile *cfg,
> const char *sectionname,
>  	return i;
>  }
> 
> +int
> +rte_cfgfile_section_entries_by_index(struct rte_cfgfile *cfg, int index,
> +		struct rte_cfgfile_entry *entries, int max_entries)
> +{
> +	int i;
> +	const struct rte_cfgfile_section *sect;
> +
> +	if (index < 0 || index >= cfg->num_sections)
> +		return -1;
> +
> +	sect = cfg->sections[index];
> +	for (i = 0; i < max_entries && i < sect->num_entries; i++)
> +		entries[i] = *sect->entries[i];
> +	return i;
> +}
> +
>  const char *
>  rte_cfgfile_get_entry(struct rte_cfgfile *cfg, const char *sectionname,
>  		const char *entryname)
> diff --git a/lib/librte_cfgfile/rte_cfgfile.h b/lib/librte_cfgfile/rte_cfgfile.h
> index d443782..8e69971 100644
> --- a/lib/librte_cfgfile/rte_cfgfile.h
> +++ b/lib/librte_cfgfile/rte_cfgfile.h
> @@ -155,6 +155,29 @@ int rte_cfgfile_section_entries(struct rte_cfgfile
> *cfg,
>  	struct rte_cfgfile_entry *entries,
>  	int max_entries);
> 
> +/** Get section entries as key-value pairs
> +*
> +* The index of a section is the same as the index of its name in the
> +* result of rte_cfgfile_sections. This API can be used when there are
> +* multiple sections with the same name.
> +*
> +* @param cfg
> +*   Config file
> +* @param index
> +*   Section index
> +* @param entries
> +*   Pre-allocated array of at least max_entries entries where the section
> +*   entries are stored as key-value pair after successful invocation
> +* @param max_entries
> +*   Maximum number of section entries to be stored in entries array
> +* @return
> +*   Number of entries populated on success, negative error code otherwise
> +*/
> +int rte_cfgfile_section_entries_by_index(struct rte_cfgfile *cfg,
> +	int index,

For the purpose of consistency, this function should provide back to the user the name of the section as an output parameter: char *name.
This parameter should either be NULL (when user does not care about the section name) or pre-allocated by the user with at least CFG_NAME_LEN characters.

> +	struct rte_cfgfile_entry *entries,
> +	int max_entries);
> +

Also the doxygen comment of the following existing functions should be updated to state that, in the case multiple sections with the same name exist, these functions are working with the first section with this name:
- rte_cfgfile_section_num_entries()
- rte_cfgfile_section_entries()
- rte_cfgfile_get_entry()
- rte_cfgfile_has_entry()

>  /** Get value of the named entry in named config file section
>  *
>  * @param cfg
> diff --git a/lib/librte_cfgfile/rte_cfgfile_version.map
> b/lib/librte_cfgfile/rte_cfgfile_version.map
> index bf6c6fd..f6a27a9 100644
> --- a/lib/librte_cfgfile/rte_cfgfile_version.map
> +++ b/lib/librte_cfgfile/rte_cfgfile_version.map
> @@ -13,3 +13,9 @@ DPDK_2.0 {
> 
>  	local: *;
>  };
> +
> +DPDK_2.3 {
> +	global:
> +
> +	rte_cfgfile_section_entries_by_index;
> +} DPDK_2.0;
> --
> 1.9.1



More information about the dev mailing list