From 7fce1e3c41213f0c4ea971b0e87a7cc34b5b5181 Mon Sep 17 00:00:00 2001 From: Guillaume Denneulin Date: Fri, 17 Feb 2012 17:34:47 +0100 Subject: Handle amend of mapping values at PFW level BZ: 24271 Amend mechanism can be used by various plugins, right now it is implemented in alsa one. Move this implementation in the PFW for all plugin to benefit from this mechanism. Change-Id: I3f193a732b00586c52303390f353fea00f4ce8ec Signed-off-by: Guillaume Denneulin Reviewed-on: http://android.intel.com:8080/35905 Reviewed-by: Barthes, FabienX Tested-by: Barthes, FabienX Reviewed-by: buildbot Tested-by: buildbot --- parameter/SubsystemObject.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'parameter/SubsystemObject.cpp') diff --git a/parameter/SubsystemObject.cpp b/parameter/SubsystemObject.cpp index ce6275b..5d92127 100644 --- a/parameter/SubsystemObject.cpp +++ b/parameter/SubsystemObject.cpp @@ -31,6 +31,7 @@ #include "SubsystemObject.h" #include "InstanceConfigurableElement.h" #include "ParameterBlackboard.h" +#include "MappingContext.h" #include #include #include @@ -176,3 +177,38 @@ void CSubsystemObject::log(const string& strMessage, ...) const _pInstanceConfigurableElement->log(acBuffer); } + +// Amendment +string CSubsystemObject::formatMappingValue(const string& strMappingValue, uint32_t uiFirstAmendKey, uint32_t uiNbAmendKeys, const CMappingContext& context) +{ + string strFormattedValue = strMappingValue; + // Search for amendment (only one supported for now) + size_t uiPercentPos = strFormattedValue.find('%', 0); + + // Amendment limited to one digit (values from 1 to 9) + assert((uiNbAmendKeys > 0) && (uiNbAmendKeys <= 9)); + + // Check we found one and that there's room for value + if (uiPercentPos != string::npos && uiPercentPos < strFormattedValue.size() - 1) { + + // Get Amend number + uint32_t uiAmendNumber = strFormattedValue[uiPercentPos + 1] - '0'; + + // Valid? + if (uiAmendNumber && uiAmendNumber <= uiNbAmendKeys) { + + uint32_t uiAmendType = uiFirstAmendKey + uiAmendNumber - 1; + + // Set? + if (context.iSet(uiAmendType)) { + + // Get Amend value + string strAmendValue = context.getItem(uiAmendType); + + // Make the amendment + strFormattedValue = strFormattedValue.substr(0, uiPercentPos) + strAmendValue + strFormattedValue.substr(uiPercentPos + 2, strFormattedValue.size() - uiPercentPos - 2); + } + } + } + return strFormattedValue; +} -- cgit v1.1