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 <renaud.de.chivre@intel.com>
Reviewed-on: http://android.intel.com:8080/131571
Tested-by: Dixon, CharlesX <charlesx.dixon@intel.com>
Reviewed-by: cactus <cactus@intel.com>
Tested-by: cactus <cactus@intel.com>
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 <assert.h>
#include <string.h>
#include <stdlib.h>
@@ -66,15 +67,27 @@
}
// 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 @@
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;