From 46966e050fdd1ae48c7692ae9818762ba262e781 Mon Sep 17 00:00:00 2001 From: Renaud de Chivre Date: Mon, 2 Sep 2013 10:48:36 +0200 Subject: Handle key names in mapping context BZ: 126002 Mapping context only allows to retrieve a mapping value from its corresponding key ID. We also want to do the same using its key as a string. This patch adds key name handling in context mapping. It also adds an API to retieve a mapping value from its corresponding key name. Note: it also removes an unused argument from handleMappingContext function. Change-Id: I5a18ad624a69272ea2796090692f2bfa8b373a52 Signed-off-by: Renaud de Chivre Reviewed-on: http://android.intel.com:8080/131571 Tested-by: Dixon, CharlesX Reviewed-by: cactus Tested-by: cactus --- parameter/MappingContext.cpp | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'parameter/MappingContext.cpp') diff --git a/parameter/MappingContext.cpp b/parameter/MappingContext.cpp index dae71ee..727fadb 100644 --- a/parameter/MappingContext.cpp +++ b/parameter/MappingContext.cpp @@ -23,6 +23,7 @@ * UPDATED: 2011-07-27 */ #include "MappingContext.h" +#include #include #include @@ -66,15 +67,27 @@ CMappingContext& CMappingContext::operator=(const CMappingContext& right) } // Item access -bool CMappingContext::setItem(uint32_t uiItemType, const string* pStrItem) +bool CMappingContext::setItem(uint32_t uiItemType, const string* pStrKey, const string* pStrItem) { + uint32_t uiIndex; + // Do some checks + for (uiIndex = 0; uiIndex < _uiNbItemTypes; uiIndex++) { + + // Does key already exist ? + assert(_pstItemArray[uiIndex].strKey != pStrKey); + } + if (_pstItemArray[uiItemType].bSet) { // Already set! return false; } - // Get item value + + // Set item key + _pstItemArray[uiItemType].strKey = pStrKey; + + // Set item value _pstItemArray[uiItemType].strItem = pStrItem; // Now is set @@ -98,6 +111,22 @@ uint32_t CMappingContext::getItemAsInteger(uint32_t uiItemType) const return strtoul(_pstItemArray[uiItemType].strItem->c_str(), NULL, 0); } +const string* CMappingContext::getItem(const string& strKey) const +{ + uint32_t uiItemType; + + for (uiItemType = 0; uiItemType < _uiNbItemTypes; uiItemType++) { + + if (_pstItemArray[uiItemType].strKey != NULL && + strKey == *_pstItemArray[uiItemType].strKey) { + + return _pstItemArray[uiItemType].strItem; + } + } + + return NULL; +} + bool CMappingContext::iSet(uint32_t uiItemType) const { return _pstItemArray[uiItemType].bSet; -- cgit v1.1