diff options
author | Patrick Benavoli <patrickx.benavoli@intel.com> | 2012-02-02 17:12:41 +0100 |
---|---|---|
committer | David Wagner <david.wagner@intel.com> | 2014-02-10 17:15:02 +0100 |
commit | 68808c650fc95660c9eb0d8f0bf97701b8076eb8 (patch) | |
tree | 57fa617254a8895609a9c17608141b83f263bc2d /parameter/EnumParameterType.cpp | |
parent | 0bd50546a8d06a6865d32c695adf8893fa71250a (diff) | |
download | external_parameter-framework-68808c650fc95660c9eb0d8f0bf97701b8076eb8.zip external_parameter-framework-68808c650fc95660c9eb0d8f0bf97701b8076eb8.tar.gz external_parameter-framework-68808c650fc95660c9eb0d8f0bf97701b8076eb8.tar.bz2 |
PFW: Enum parameter mapping
BZ: 22125
Enum parameter types are now fully parsed as any other types, which allow
Mapping attributes to be correctly interpreted.
Now inner structure of enum parameter types is based on automatically
created objects: ValuePair
Slight adaptation of to ICS environment in Android.mk files and
XmlComposer (time.h).
More explicit error statement issued in case of plugin load failure in
SystemClass.cpp.
Added a log for Alsa mixer elements accesses.
Change-Id: Ia71fd854e639a288c5dae79260b1e2a0eb1a7ac2
Signed-off-by: Patrick Benavoli <patrickx.benavoli@intel.com>
Reviewed-on: http://android.intel.com:8080/33756
Reviewed-by: Barthes, FabienX <fabienx.barthes@intel.com>
Tested-by: Barthes, FabienX <fabienx.barthes@intel.com>
Reviewed-by: buildbot <buildbot@intel.com>
Tested-by: buildbot <buildbot@intel.com>
Diffstat (limited to 'parameter/EnumParameterType.cpp')
-rw-r--r-- | parameter/EnumParameterType.cpp | 82 |
1 files changed, 44 insertions, 38 deletions
diff --git a/parameter/EnumParameterType.cpp b/parameter/EnumParameterType.cpp index 87cefcd..60c937c 100644 --- a/parameter/EnumParameterType.cpp +++ b/parameter/EnumParameterType.cpp @@ -35,6 +35,7 @@ #include <ctype.h> #include <assert.h> #include "ParameterAccessContext.h" +#include "EnumValuePair.h" #define base CParameterType @@ -47,6 +48,11 @@ string CEnumParameterType::getKind() const return "EnumParameter"; } +bool CEnumParameterType::childrenAreDynamic() const +{ + return true; +} + // Element properties void CEnumParameterType::showProperties(string& strResult) const { @@ -55,14 +61,17 @@ void CEnumParameterType::showProperties(string& strResult) const strResult += "Value Pairs:\n"; // Show all value pairs - ValuePairListIterator it; + uint32_t uiChild; + uint32_t uiNbChildren = getNbChildren(); + + for (uiChild = 0; uiChild < uiNbChildren; uiChild++) { - for (it = _valuePairList.begin(); it != _valuePairList.end(); ++it) { + const CEnumValuePair* pValuePair = static_cast<const CEnumValuePair*>(getChild(uiChild)); strResult += "\tLiteral: \""; - strResult += it->_strLiteral; + strResult += pValuePair->getName(); strResult += "\", Numerical: "; - strResult += toString(it->_iNumerical); + strResult += pValuePair->getNumericalAsString(); strResult += "\n"; } } @@ -75,26 +84,8 @@ bool CEnumParameterType::fromXml(const CXmlElement& xmlElement, CXmlSerializingC // Size setSize(uiSizeInBits / 8); - // Get value pairs - CXmlElement::CChildIterator it(xmlElement); - - CXmlElement xmlValuePairElement; - - while (it.next(xmlValuePairElement)) { - - _valuePairList.push_back(SValuePair(xmlValuePairElement.getAttributeString("Literal"), xmlValuePairElement.getAttributeSignedInteger("Numerical"))); - } - - // Check value pair list - if (_valuePairList.empty()) { - - serializingContext.setError("No Value pairs provided for element " + xmlElement.getPath()); - - return false; - } - - // Don't dig - return true; + // Base + return base::fromXml(xmlElement, serializingContext); } // Conversion (tuning) @@ -214,10 +205,13 @@ bool CEnumParameterType::fromBlackboard(int32_t& iUserValue, uint32_t uiValue, C // Default value handling (simulation only) uint32_t CEnumParameterType::getDefaultValue() const { - assert(!_valuePairList.empty()); + if (!getNbChildren()) { + + return 0; + } - // Return first item - return _valuePairList.front()._iNumerical; + // Return first available numerical + return static_cast<const CEnumValuePair*>(getChild(0))->getNumerical(); } // Check string is a number @@ -231,47 +225,59 @@ bool CEnumParameterType::isNumber(const string& strValue) // Literal - numerical conversions bool CEnumParameterType::getLiteral(int32_t iNumerical, string& strLiteral) const { - ValuePairListIterator it; + uint32_t uiChild; + uint32_t uiNbChildren = getNbChildren(); - for (it = _valuePairList.begin(); it != _valuePairList.end(); ++it) { + for (uiChild = 0; uiChild < uiNbChildren; uiChild++) { - if (it->_iNumerical == iNumerical) { + const CEnumValuePair* pValuePair = static_cast<const CEnumValuePair*>(getChild(uiChild)); - strLiteral = it->_strLiteral; + if (pValuePair->getNumerical() == iNumerical) { + + strLiteral = pValuePair->getName(); return true; } } + return false; } bool CEnumParameterType::getNumerical(const string& strLiteral, int32_t& iNumerical) const { - ValuePairListIterator it; + uint32_t uiChild; + uint32_t uiNbChildren = getNbChildren(); + + for (uiChild = 0; uiChild < uiNbChildren; uiChild++) { - for (it = _valuePairList.begin(); it != _valuePairList.end(); ++it) { + const CEnumValuePair* pValuePair = static_cast<const CEnumValuePair*>(getChild(uiChild)); - if (it->_strLiteral == strLiteral) { + if (pValuePair->getName() == strLiteral) { - iNumerical = it->_iNumerical; + iNumerical = pValuePair->getNumerical(); return true; } } + return false; } // Numerical validity bool CEnumParameterType::isValid(int32_t iNumerical) const { - ValuePairListIterator it; + uint32_t uiChild; + uint32_t uiNbChildren = getNbChildren(); + + for (uiChild = 0; uiChild < uiNbChildren; uiChild++) { - for (it = _valuePairList.begin(); it != _valuePairList.end(); ++it) { + const CEnumValuePair* pValuePair = static_cast<const CEnumValuePair*>(getChild(uiChild)); - if (it->_iNumerical == iNumerical) { + if (pValuePair->getNumerical() == iNumerical) { return true; } } + return false; } |