From 11e6498a4fa3b27ca34d2fcb76bd6365da9d5c1b Mon Sep 17 00:00:00 2001 From: Patrick Benavoli Date: Tue, 4 Oct 2011 15:32:57 +0200 Subject: parameter-framework: import/export XML BZ: 10948 - Max value handling on integers corrected - Left-justified Qn.m numbers - Corrections after code review: removed fixed numbers from the code and unified byte to bit conversions Change-Id: Iaf54e413201eae61013735580e046c5ab1874700 Signed-off-by: Patrick Benavoli Reviewed-on: http://android.intel.com:8080/22316 Reviewed-by: Centelles, Sylvain Tested-by: Barthes, FabienX Reviewed-by: buildbot Tested-by: buildbot Reviewed-on: http://android.intel.com:8080/26777 Reviewed-by: Barthes, FabienX --- parameter/FixedPointParameterType.cpp | 46 ++++++++++++++++------------------- 1 file changed, 21 insertions(+), 25 deletions(-) (limited to 'parameter/FixedPointParameterType.cpp') diff --git a/parameter/FixedPointParameterType.cpp b/parameter/FixedPointParameterType.cpp index 5b90f13..0c1cc07 100644 --- a/parameter/FixedPointParameterType.cpp +++ b/parameter/FixedPointParameterType.cpp @@ -128,19 +128,10 @@ bool CFixedPointParameterType::asInteger(const string& strValue, uint32_t& uiVal // Get data in integer form iData = strtol(strValue.c_str(), NULL, 0); - if (bValueProvidedAsHexa) { + if (bValueProvidedAsHexa && isEncodable(iData)) { - if (!isEncodable(iData, getUtilSizeInBits())) { - - // Illegal value provided - parameterAccessContext.setError(getOutOfRangeError(strValue, parameterAccessContext.valueSpaceIsRaw(), true)); - - return false; - } else { - - // Sign extend - signExtend(iData); - } + // Sign extend + signExtend(iData); } } else { @@ -148,6 +139,8 @@ bool CFixedPointParameterType::asInteger(const string& strValue, uint32_t& uiVal // Do the conversion iData = (int32_t)(dData * (1UL << _uiFractional) + 0.5F - (double)(dData < 0)); + // Left justify + iData <<= getSize() * 8 - getUtilSizeInBits(); } // Check integrity @@ -159,7 +152,7 @@ bool CFixedPointParameterType::asInteger(const string& strValue, uint32_t& uiVal return false; } - uiValue = (uint32_t)iData; + uiValue = iData; return true; } @@ -169,7 +162,7 @@ void CFixedPointParameterType::asString(const uint32_t& uiValue, string& strValu int32_t iData = uiValue; // Check consistency - assert(isEncodable(iData, getUtilSizeInBits())); + assert(isEncodable(iData)); // Sign extend signExtend(iData); @@ -183,13 +176,16 @@ void CFixedPointParameterType::asString(const uint32_t& uiValue, string& strValu // Hexa formatting? if (parameterAccessContext.outputRawFormatIsHex()) { - strStream << "0x" << hex << uppercase << setw(getSize()*2) << setfill('0') << uiValue; + strStream << "0x" << hex << uppercase << setw(getSize()*2) << setfill('0') << (uint32_t)iData; } else { strStream << iData; } } else { + // Unjustify + iData >>= getSize() * 8 - getUtilSizeInBits(); + double dData = (double)iData / (1UL << _uiFractional); strStream << dData; @@ -208,7 +204,7 @@ uint32_t CFixedPointParameterType::getUtilSizeInBits() const string CFixedPointParameterType::getOutOfRangeError(const string& strValue, bool bRawValueSpace, bool bHexaValue) const { // Min/Max computation - int32_t iMax = (1L << (getUtilSizeInBits() - 1)) - 1; + int32_t iMax = (1L << (getSize() * 8 - 1)) - 1; int32_t iMin = -iMax - 1; ostringstream strStream; @@ -244,17 +240,17 @@ string CFixedPointParameterType::getOutOfRangeError(const string& strValue, bool // Check data is consistent with available range, with respect to its sign bool CFixedPointParameterType::isConsistent(uint32_t uiData) const { - uint32_t uiShift = 32 - getUtilSizeInBits(); + uint32_t uiShift = getSize() * 8; - if (uiShift) { - - // Negative value? - bool bIsValueExpectedNegative = (uiData & (1 << (uiShift - 1))) != 0; - - // Check high bits are clean - return bIsValueExpectedNegative ? !(~uiData >> uiShift) : !(uiData >> uiShift); + if (uiShift == 8 * sizeof(uiData)) { + // Prevent inappropriate shifts + return true; } - return true; + // Negative value? + bool bIsValueExpectedNegative = (uiData & (1 << (uiShift - 1))) != 0; + + // Check high bits are clean + return bIsValueExpectedNegative ? !(~uiData >> uiShift) : !(uiData >> uiShift); } -- cgit v1.1