diff options
author | Patrick Benavoli <patrickx.benavoli@intel.com> | 2011-11-20 15:46:41 +0100 |
---|---|---|
committer | David Wagner <david.wagner@intel.com> | 2014-02-10 17:15:00 +0100 |
commit | 065264a93ce9c63b6a5c95e985188ee33ba587d3 (patch) | |
tree | 01897cd4ed658e6a41f21061146098d0385734fd /parameter/FixedPointParameterType.cpp | |
parent | 6ccab9d382c08323fb1f000d859a696f05719c92 (diff) | |
download | external_parameter-framework-065264a93ce9c63b6a5c95e985188ee33ba587d3.zip external_parameter-framework-065264a93ce9c63b6a5c95e985188ee33ba587d3.tar.gz external_parameter-framework-065264a93ce9c63b6a5c95e985188ee33ba587d3.tar.bz2 |
PFW: Type safe dynamic parameter access
BZ: 15065
Replaced high level string based parameter access interface with typed ones.
Now hosting platforms that want to control parameters must instantiate a
CParameterHandle object out of the desired parameter path.
CParameterHandle object may be used to access any kind of parameters, whatever
its internal type, whether it's an array or not.
Note that non rogue parameters offer a read access only. Any attempt to write
them will fail.
CParameterHandle objects offer the following kind of parameter accessing
interfaces:
- Boolean
- Integer (signed or unsigned)
- Double
- String
Note that those interfaces are available for scalar as well as for array
parameters.
Not all parameter types support all access kinds. Naturally, array parameters
are only accessed via array interfaces while scalar parameters are managed
through scalar interfaces.
Here's a list of parameter types that may be controlled through each kind of
access interface:
- Boolean access: boolean, bit (bit size must be one);
- Integer access: integer (sign must match), boolean (unsigned access only,
value <= 1), enumerations;
- Double access: for now only fixed points (soon integers will support them
also through platform adaptation objects)
- String access: all parameter types
In addition, cleaned up parameter access related code so as to make it more
generic and reusable.
Changed version to 2.0.0
Change-Id: Ib80868cdb773e90962e48f1f38d2ff0029189815
Signed-off-by: Patrick Benavoli <patrickx.benavoli@intel.com>
Reviewed-on: http://android.intel.com:8080/25406
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/FixedPointParameterType.cpp')
-rw-r--r-- | parameter/FixedPointParameterType.cpp | 74 |
1 files changed, 62 insertions, 12 deletions
diff --git a/parameter/FixedPointParameterType.cpp b/parameter/FixedPointParameterType.cpp index a12004d..3f57d77 100644 --- a/parameter/FixedPointParameterType.cpp +++ b/parameter/FixedPointParameterType.cpp @@ -108,7 +108,7 @@ bool CFixedPointParameterType::fromXml(const CXmlElement& xmlElement, CXmlSerial return base::fromXml(xmlElement, serializingContext); } -bool CFixedPointParameterType::asInteger(const string& strValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const +bool CFixedPointParameterType::toBlackboard(const string& strValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const { // Hexa bool bValueProvidedAsHexa = !strValue.compare(0, 2, "0x"); @@ -138,9 +138,7 @@ bool CFixedPointParameterType::asInteger(const string& strValue, uint32_t& uiVal double dData = strtod(strValue.c_str(), NULL); // Do the conversion - iData = (int32_t)(dData * (1UL << _uiFractional) + 0.5F - (double)(dData < 0)); - // Left justify - iData <<= getSize() * 8 - getUtilSizeInBits(); + iData = asInteger(dData); } // Check integrity @@ -157,7 +155,7 @@ bool CFixedPointParameterType::asInteger(const string& strValue, uint32_t& uiVal return true; } -void CFixedPointParameterType::asString(const uint32_t& uiValue, string& strValue, CParameterAccessContext& parameterAccessContext) const +bool CFixedPointParameterType::fromBlackboard(string& strValue, const uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const { int32_t iData = uiValue; @@ -183,18 +181,52 @@ void CFixedPointParameterType::asString(const uint32_t& uiValue, string& strValu } } else { - // Sign extend - signExtend(iData); - - // Unjustify - iData >>= getSize() * 8 - getUtilSizeInBits(); - - double dData = (double)iData / (1UL << _uiFractional); + // Conversion + double dData = asDouble(iData); strStream << dData; } strValue = strStream.str(); + + return true; +} + +// Value access +bool CFixedPointParameterType::toBlackboard(double dUserValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const +{ + // Do the conversion + int32_t iData = asInteger(dUserValue); + + // Check integrity + if (!isConsistent(iData)) { + + // Illegal value provided + parameterAccessContext.setError("Value out of range"); + + return false; + } + + uiValue = iData; + + return true; +} + +bool CFixedPointParameterType::fromBlackboard(double& dUserValue, uint32_t uiValue, CParameterAccessContext& parameterAccessContext) const +{ + (void)parameterAccessContext; + + int32_t iData = uiValue; + + // Check consistency + assert(isEncodable(iData)); + + // Sign extend + signExtend(iData); + + dUserValue = asDouble(iData); + + return true; } // Util size @@ -257,3 +289,21 @@ bool CFixedPointParameterType::isConsistent(uint32_t uiData) const return bIsValueExpectedNegative ? !(~uiData >> uiShift) : !(uiData >> uiShift); } +// Data conversion +int32_t CFixedPointParameterType::asInteger(double dValue) const +{ + // Do the conversion + int32_t iData = (int32_t)(dValue * (1UL << _uiFractional) + 0.5F - (double)(dValue < 0)); + // Left justify + iData <<= getSize() * 8 - getUtilSizeInBits(); + + return iData; +} + +double CFixedPointParameterType::asDouble(int32_t iValue) const +{ + // Unjustify + iValue >>= getSize() * 8 - getUtilSizeInBits(); + // Convert + return (double)iValue / (1UL << _uiFractional); +} |