diff options
author | Patrick Benavoli <patrickx.benavoli@intel.com> | 2011-11-25 22:36:41 +0100 |
---|---|---|
committer | David Wagner <david.wagner@intel.com> | 2014-02-10 17:15:01 +0100 |
commit | 79f16cc91351951a39ad3019a7dc9e4dea532551 (patch) | |
tree | 1b249c2733e743d7172422e17a26bab3d1fc66b3 | |
parent | 9bed7cea60c371df60ab53c2e7ade186f04266f3 (diff) | |
download | external_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>
-rw-r--r-- | Schemas/Parameter.xsd | 1 | ||||
-rw-r--r-- | parameter/BitParameterType.cpp | 40 | ||||
-rw-r--r-- | parameter/BitParameterType.h | 6 | ||||
-rw-r--r-- | parameter/ParameterMgr.cpp | 6 |
4 files changed, 41 insertions, 12 deletions
diff --git a/Schemas/Parameter.xsd b/Schemas/Parameter.xsd index 10d506a..098ee26 100644 --- a/Schemas/Parameter.xsd +++ b/Schemas/Parameter.xsd @@ -116,6 +116,7 @@ </xs:restriction>
</xs:simpleType>
</xs:attribute>
+ <xs:attribute name="Max" type="xs:integer" use="optional"/>
</xs:complexType>
<xs:element name="BitParameterBlock">
<xs:complexType>
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 diff --git a/parameter/BitParameterType.h b/parameter/BitParameterType.h index 6cd86c4..ebfec7e 100644 --- a/parameter/BitParameterType.h +++ b/parameter/BitParameterType.h @@ -63,8 +63,8 @@ public: private: // Instantiation virtual CInstanceConfigurableElement* doInstantiate() const; - // Max value - uint32_t getMaxValue() const; + // Max encodable value + uint32_t getMaxEncodableValue() const; // Biwise mask uint32_t getMask() const; // Check data has no bit set outside available range @@ -74,4 +74,6 @@ private: uint32_t _uiBitPos; // Size in bits uint32_t _uiBitSize; + // Max value + uint32_t _uiMax; }; diff --git a/parameter/ParameterMgr.cpp b/parameter/ParameterMgr.cpp index f1dd9eb..66c8d9e 100644 --- a/parameter/ParameterMgr.cpp +++ b/parameter/ParameterMgr.cpp @@ -620,7 +620,7 @@ CParameterHandle* CParameterMgr::createParameterHandle(const string& strPath, st // Nagivate through system class if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) { - return false; + return NULL; } // Find element @@ -630,7 +630,7 @@ CParameterHandle* CParameterMgr::createParameterHandle(const string& strPath, st strError = "Path not found"; - return false; + return NULL; } // Check found element is a parameter @@ -641,7 +641,7 @@ CParameterHandle* CParameterMgr::createParameterHandle(const string& strPath, st // Element is not parameter strError = "Not a parameter"; - return false; + return NULL; } // Convert as parameter and return new handle |