aboutsummaryrefslogtreecommitdiffstats
path: root/parameter/BitParameterType.cpp
diff options
context:
space:
mode:
authorPatrick Benavoli <patrickx.benavoli@intel.com>2011-11-25 22:36:41 +0100
committerDavid Wagner <david.wagner@intel.com>2014-02-10 17:15:01 +0100
commit79f16cc91351951a39ad3019a7dc9e4dea532551 (patch)
tree1b249c2733e743d7172422e17a26bab3d1fc66b3 /parameter/BitParameterType.cpp
parent9bed7cea60c371df60ab53c2e7ade186f04266f3 (diff)
downloadexternal_parameter-framework-79f16cc91351951a39ad3019a7dc9e4dea532551.zip
external_parameter-framework-79f16cc91351951a39ad3019a7dc9e4dea532551.tar.gz
external_parameter-framework-79f16cc91351951a39ad3019a7dc9e4dea532551.tar.bz2
PFW: Max value on bit parameters
BZ: 15708 Added Max attribute on bit parameter types. Max attribute, as the parameter itself is unsigned and can't exceed the maximum encodable value decided by the parameter's bit size. In addition, fixed a small mistake in CParameterMgr::createParameterHandle where now NULL is properly returned in case of failure instead of "false". Change-Id: Ifb0af6b4d43dc2c0ddb4e0e038b1ce226772d71f Signed-off-by: Patrick Benavoli <patrickx.benavoli@intel.com> Reviewed-on: http://android.intel.com:8080/26098 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/BitParameterType.cpp')
-rw-r--r--parameter/BitParameterType.cpp40
1 files changed, 33 insertions, 7 deletions
diff --git a/parameter/BitParameterType.cpp b/parameter/BitParameterType.cpp
index 30b0173..9a09a59 100644
--- a/parameter/BitParameterType.cpp
+++ b/parameter/BitParameterType.cpp
@@ -37,7 +37,7 @@
#define base CTypeElement
-CBitParameterType::CBitParameterType(const string& strName) : base(strName), _uiBitPos(0), _uiBitSize(0)
+CBitParameterType::CBitParameterType(const string& strName) : base(strName), _uiBitPos(0), _uiBitSize(0), _uiMax(uint32_t(-1))
{
}
@@ -61,6 +61,11 @@ void CBitParameterType::showProperties(string& strResult) const
strResult += "Bit size: ";
strResult += toString(_uiBitSize);
strResult += "\n";
+
+ // Max
+ strResult += "Max: ";
+ strResult += toString(_uiMax);
+ strResult += "\n";
}
// From IXmlSink
@@ -89,6 +94,27 @@ bool CBitParameterType::fromXml(const CXmlElement& xmlElement, CXmlSerializingCo
return false;
}
+ // Max
+ if (xmlElement.hasAttribute("Max")) {
+
+ _uiMax = xmlElement.getAttributeInteger("Max");
+
+ if (_uiMax > getMaxEncodableValue()) {
+
+ // Max value exceeded
+ ostringstream strStream;
+
+ strStream << "Max attribute inconsistent with maximum encodable size (" << getMaxEncodableValue() << ") for " + getKind();
+
+ serializingContext.setError(strStream.str());
+
+ return false;
+ }
+ } else {
+
+ _uiMax = getMaxEncodableValue();
+ }
+
// Base
return base::fromXml(xmlElement, serializingContext);
}
@@ -102,7 +128,7 @@ bool CBitParameterType::toBlackboard(const string& strValue, uint32_t& uiValue,
// Get value
uint32_t uiConvertedValue = strtoul(strValue.c_str(), NULL, 0);
- if (uiConvertedValue > getMaxValue()) {
+ if (uiConvertedValue > _uiMax) {
// Range exceeded
ostringstream strStream;
@@ -116,7 +142,7 @@ bool CBitParameterType::toBlackboard(const string& strValue, uint32_t& uiValue,
strStream << "0, ";
}
- strStream << getMaxValue() << "] for " + getKind();
+ strStream << _uiMax << "] for " + getKind();
parameterAccessContext.setError(strStream.str());
@@ -151,7 +177,7 @@ void CBitParameterType::fromBlackboard(string& strValue, const uint32_t& uiValue
// Integer
bool CBitParameterType::toBlackboard(uint32_t uiUserValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const
{
- if (uiUserValue > getMaxValue()) {
+ if (uiUserValue > _uiMax) {
parameterAccessContext.setError("Value out of range");
@@ -183,15 +209,15 @@ CInstanceConfigurableElement* CBitParameterType::doInstantiate() const
}
// Max value
-uint32_t CBitParameterType::getMaxValue() const
+uint32_t CBitParameterType::getMaxEncodableValue() const
{
- return (1 << _uiBitSize) - 1;
+ return (uint32_t)-1L >> (8 * sizeof(uint32_t) - _uiBitSize);
}
// Biwise mask
uint32_t CBitParameterType::getMask() const
{
- return getMaxValue() << _uiBitPos;
+ return getMaxEncodableValue() << _uiBitPos;
}
// Check data has no bit set outside available range