From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <cristian.dumitrescu@intel.com>
Received: from mga03.intel.com (mga03.intel.com [134.134.136.65])
 by dpdk.org (Postfix) with ESMTP id 648C2694A
 for <dev@dpdk.org>; Tue, 23 Feb 2016 01:12:51 +0100 (CET)
Received: from orsmga001.jf.intel.com ([10.7.209.18])
 by orsmga103.jf.intel.com with ESMTP; 22 Feb 2016 16:12:47 -0800
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.22,487,1449561600"; d="scan'208";a="892161754"
Received: from irsmsx152.ger.corp.intel.com ([163.33.192.66])
 by orsmga001.jf.intel.com with ESMTP; 22 Feb 2016 16:12:47 -0800
Received: from irsmsx108.ger.corp.intel.com ([169.254.11.102]) by
 IRSMSX152.ger.corp.intel.com ([169.254.6.200]) with mapi id 14.03.0248.002;
 Tue, 23 Feb 2016 00:12:45 +0000
From: "Dumitrescu, Cristian" <cristian.dumitrescu@intel.com>
To: Rich Lane <rich.lane@bigswitch.com>, "dev@dpdk.org" <dev@dpdk.org>
Thread-Topic: [PATCH v5] cfgfile: support looking up sections by index
Thread-Index: AQHRba/uveW8ppPpxkqPTtGXymj+6J84wb2Q
Date: Tue, 23 Feb 2016 00:12:45 +0000
Message-ID: <3EB4FA525960D640B5BDFFD6A3D89126479546A2@IRSMSX108.ger.corp.intel.com>
References: <1455663517-55095-1-git-send-email-rlane@bigswitch.com>
 <1456173039-23175-1-git-send-email-rlane@bigswitch.com>
In-Reply-To: <1456173039-23175-1-git-send-email-rlane@bigswitch.com>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiZGY1MjMwYTAtZTc5Zi00NGVmLWIwMGEtY2U3YTE1OGE4YmZhIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE1LjkuNi42IiwiVHJ1c3RlZExhYmVsSGFzaCI6IjJrM3JmWFZzRkgwZUNpSU5aVGxEWmlpbFN2MUIzWWRGWG9sTFwvWHZRTWNZPSJ9
x-ctpclassification: CTP_IC
x-originating-ip: [163.33.239.182]
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
Subject: Re: [dpdk-dev] [PATCH v5] cfgfile: support looking up sections by
	index
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: patches and discussions about DPDK <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Tue, 23 Feb 2016 00:12:51 -0000



> -----Original Message-----
> From: Rich Lane [mailto:rich.lane@bigswitch.com]
> Sent: Monday, February 22, 2016 8:31 PM
> To: dev@dpdk.org
> Cc: Dumitrescu, Cristian <cristian.dumitrescu@intel.com>; Panu Matilainen
> <pmatilai@redhat.com>
> Subject: [PATCH v5] cfgfile: support looking up sections by index
>=20
> This is useful when sections have duplicate names.
>=20
> Signed-off-by: Rich Lane <rlane@bigswitch.com>
> ---
> v4->v5:
> - Reordered sectionname argument.
> v3->v4:
> - Added section name return value.
> - Updated API docs for other functions.
> v2->v3
> - Added check for index < 0.
> v1->v2:
> - Added new symbol to version script.
>=20
>  lib/librte_cfgfile/rte_cfgfile.c           | 18 ++++++++++++++
>  lib/librte_cfgfile/rte_cfgfile.h           | 39
> ++++++++++++++++++++++++++++++
>  lib/librte_cfgfile/rte_cfgfile_version.map |  6 +++++
>  3 files changed, 63 insertions(+)
>=20
> diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cf=
gfile.c
> index 1cd523f..75625a2 100644
> --- a/lib/librte_cfgfile/rte_cfgfile.c
> +++ b/lib/librte_cfgfile/rte_cfgfile.c
> @@ -333,6 +333,24 @@ rte_cfgfile_section_entries(struct rte_cfgfile *cfg,
> const char *sectionname,
>  	return i;
>  }
>=20
> +int
> +rte_cfgfile_section_entries_by_index(struct rte_cfgfile *cfg, int index,
> +		char *sectionname,
> +		struct rte_cfgfile_entry *entries, int max_entries)
> +{
> +	int i;
> +	const struct rte_cfgfile_section *sect;
> +
> +	if (index < 0 || index >=3D cfg->num_sections)
> +		return -1;
> +
> +	sect =3D cfg->sections[index];
> +	snprintf(sectionname, CFG_NAME_LEN, "%s", sect->name);
> +	for (i =3D 0; i < max_entries && i < sect->num_entries; i++)
> +		entries[i] =3D *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_cf=
gfile.h
> index d443782..689fd66 100644
> --- a/lib/librte_cfgfile/rte_cfgfile.h
> +++ b/lib/librte_cfgfile/rte_cfgfile.h
> @@ -126,6 +126,9 @@ int rte_cfgfile_has_section(struct rte_cfgfile *cfg,
> const char *sectionname);
>  /**
>  * Get number of entries in given config file section
>  *
> +* If multiple sections have the given name this function operates on the
> +* first one.
> +*
>  * @param cfg
>  *   Config file
>  * @param sectionname
> @@ -138,6 +141,9 @@ int rte_cfgfile_section_num_entries(struct rte_cfgfil=
e
> *cfg,
>=20
>  /** Get section entries as key-value pairs
>  *
> +* If multiple sections have the given name this function operates on the
> +* first one.
> +*
>  * @param cfg
>  *   Config file
>  * @param sectionname
> @@ -155,8 +161,38 @@ int rte_cfgfile_section_entries(struct rte_cfgfile
> *cfg,
>  	struct rte_cfgfile_entry *entries,
>  	int max_entries);
>=20
> +/** 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 sectio=
n
> +*   entries are stored as key-value pair after successful invocation
> +* @param max_entries
> +*   Maximum number of section entries to be stored in entries array

The description for sectionname should also be moved after the description =
of index parameter to match the argument order. We're nearly there :)

> +* @param sectionname
> +*   Pre-allocated string of at least CFG_NAME_LEN characters where the
> +*   section name is stored after successful invocation.
> +* @return
> +*   Number of entries populated on success, negative error code otherwis=
e
> +*/
> +int rte_cfgfile_section_entries_by_index(struct rte_cfgfile *cfg,
> +	int index,
> +	char *sectionname,
> +	struct rte_cfgfile_entry *entries,
> +	int max_entries);
> +
>  /** Get value of the named entry in named config file section
>  *
> +* If multiple sections have the given name this function operates on the
> +* first one.
> +*
>  * @param cfg
>  *   Config file
>  * @param sectionname
> @@ -172,6 +208,9 @@ const char *rte_cfgfile_get_entry(struct rte_cfgfile
> *cfg,
>=20
>  /** Check if given entry exists in named config file section
>  *
> +* If multiple sections have the given name this function operates on the
> +* first one.
> +*
>  * @param cfg
>  *   Config file
>  * @param sectionname
> 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 {
>=20
>  	local: *;
>  };
> +
> +DPDK_2.3 {
> +	global:
> +
> +	rte_cfgfile_section_entries_by_index;
> +} DPDK_2.0;
> --
> 1.9.1