From 6ba361d96bc2581667b3400f87ff89fae6449e1f Mon Sep 17 00:00:00 2001 From: Patrick Benavoli Date: Wed, 31 Aug 2011 11:23:24 +0200 Subject: parameter-framework: improvements and corrections BZ: 6721 - Bug correction concerning selection criteria display (inclusive type) - Adapted XML format to allow for only on parameter to be associated to a domain - Removed unused files in parameter project Change-Id: I9f42d08ff8cb60354714fe3d6b0f0b321ad0a7bf Orig-Change-Id: I837e553070f5acf2d275082c986ba29433493e31 Signed-off-by: Patrick Benavoli Reviewed-on: http://android.intel.com:8080/16878 Reviewed-by: Mahe, Erwan Tested-by: Barthes, FabienX Reviewed-by: buildbot Tested-by: buildbot --- parameter/ParameterType.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'parameter/ParameterType.cpp') diff --git a/parameter/ParameterType.cpp b/parameter/ParameterType.cpp index 9a23c40..054c5e8 100644 --- a/parameter/ParameterType.cpp +++ b/parameter/ParameterType.cpp @@ -95,3 +95,58 @@ CInstanceConfigurableElement* CParameterType::doInstantiate() const } } +// Sign extension +void CParameterType::signExtend(int32_t& iData) const +{ + uint32_t uiSizeInBits = _uiSize << 3; + uint32_t uiShift = 32 - uiSizeInBits; + + if (uiShift) { + + iData = (iData << uiShift) >> uiShift; + } +} + +// Check data has no bit set outside available range +bool CParameterType::isEncodable(uint32_t uiData) const +{ + uint32_t uiSizeInBits = _uiSize << 3; + uint32_t uiShift = 32 - uiSizeInBits; + + if (uiShift) { + + // Check high bits are clean + return !(uiData >> uiShift); + } + + return true; +} + +// Remove all bits set outside available range +uint32_t CParameterType::makeEncodable(uint32_t uiData) const +{ + uint32_t uiSizeInBits = _uiSize << 3; + + uint32_t uiMask = (1 << uiSizeInBits) - 1; + + return uiData & uiMask; +} + +// Check data is consistent with available range, with respect to its sign +bool CParameterType::isConsistent(uint32_t uiData, bool bSigned) const +{ + uint32_t uiSizeInBits = _uiSize << 3; + uint32_t uiShift = 32 - uiSizeInBits; + + if (uiShift) { + + // Negative value? + bool bIsValueExpectedNegative = bSigned && (uiData & (1 << (uiShift - 1))) != 0; + + // Check high bits are clean + return bIsValueExpectedNegative ? !(~uiData >> uiShift) : !(uiData >> uiShift); + } + + return true; +} + -- cgit v1.1