From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id 01ABEC318 for ; Tue, 16 Feb 2016 21:49:22 +0100 (CET) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP; 16 Feb 2016 12:48:25 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,456,1449561600"; d="scan'208";a="916278289" Received: from irsmsx151.ger.corp.intel.com ([163.33.192.59]) by fmsmga002.fm.intel.com with ESMTP; 16 Feb 2016 12:48:24 -0800 Received: from irsmsx108.ger.corp.intel.com ([169.254.11.102]) by IRSMSX151.ger.corp.intel.com ([169.254.4.108]) with mapi id 14.03.0248.002; Tue, 16 Feb 2016 20:48:23 +0000 From: "Dumitrescu, Cristian" To: Rich Lane , "dev@dpdk.org" Thread-Topic: [PATCH v3] cfgfile: support looking up sections by index Thread-Index: AQHRZDcW9PuYuHpX3k+Fn3s8y33oSp8vKgaw Date: Tue, 16 Feb 2016 20:48:22 +0000 Message-ID: <3EB4FA525960D640B5BDFFD6A3D8912647951FD1@IRSMSX108.ger.corp.intel.com> References: <1453178510-113435-1-git-send-email-rlane@bigswitch.com> <1455131536-46285-1-git-send-email-rlane@bigswitch.com> In-Reply-To: <1455131536-46285-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: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiY2I0NGZmYmItMzUyMC00NTk4LTgyOGQtN2FmNzI1YTBiYTcxIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE1LjkuNi42IiwiVHJ1c3RlZExhYmVsSGFzaCI6IjNvNHdiYUdRVjVMeTFjcjRzekdWOEhMdmNNZlBpMkNhUmwzZWpramM0Tkk9In0= x-ctpclassification: CTP_IC x-originating-ip: [163.33.239.180] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH v3] 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Feb 2016 20:49:23 -0000 > -----Original Message----- > From: Rich Lane [mailto:rich.lane@bigswitch.com] > Sent: Wednesday, February 10, 2016 7:12 PM > To: dev@dpdk.org > Cc: Dumitrescu, Cristian ; Panu Matilainen > > Subject: [PATCH v3] cfgfile: support looking up sections by index >=20 > This is useful when sections have duplicate names. >=20 > Signed-off-by: Rich Lane > --- > v2->v3 > - Added check for index < 0. > v1->v2: > - Added new symbol to version script. >=20 > 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(+) >=20 > diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cf= gfile.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; > } >=20 > +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 >=3D cfg->num_sections) > + return -1; > + > + sect =3D cfg->sections[index]; > + 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..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); >=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 > +* @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, For the purpose of consistency, this function should provide back to the us= er the name of the section as an output parameter: char *name. This parameter should either be NULL (when user does not care about the sec= tion name) or pre-allocated by the user with at least CFG_NAME_LEN characte= rs. > + struct rte_cfgfile_entry *entries, > + int max_entries); > + Also the doxygen comment of the following existing functions should be upda= ted 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 { >=20 > local: *; > }; > + > +DPDK_2.3 { > + global: > + > + rte_cfgfile_section_entries_by_index; > +} DPDK_2.0; > -- > 1.9.1