From 065264a93ce9c63b6a5c95e985188ee33ba587d3 Mon Sep 17 00:00:00 2001 From: Patrick Benavoli Date: Sun, 20 Nov 2011 15:46:41 +0100 Subject: 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 Reviewed-on: http://android.intel.com:8080/25406 Reviewed-by: Barthes, FabienX Tested-by: Barthes, FabienX Reviewed-by: buildbot Tested-by: buildbot --- parameter/BitParameter.cpp | 79 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 74 insertions(+), 5 deletions(-) (limited to 'parameter/BitParameter.cpp') diff --git a/parameter/BitParameter.cpp b/parameter/BitParameter.cpp index d94ed9a..0aa99d7 100644 --- a/parameter/BitParameter.cpp +++ b/parameter/BitParameter.cpp @@ -60,9 +60,78 @@ uint32_t CBitParameter::getFootPrint() const return 0; } -// Actual parameter access +// Actual parameter access (tuning) bool CBitParameter::doSetValue(const string& strValue, uint32_t uiOffset, CParameterAccessContext& parameterAccessContext) const { + return doSet(strValue, uiOffset, parameterAccessContext); +} + +void CBitParameter::doGetValue(string& strValue, uint32_t uiOffset, CParameterAccessContext& parameterAccessContext) const +{ + doGet(strValue, uiOffset, parameterAccessContext); +} + +/// Value access +// Boolean access +bool CBitParameter::accessAsBoolean(bool& bValue, bool bSet, CParameterAccessContext& parameterAccessContext) const +{ + // Check boolean access validity here + if (static_cast(getTypeElement())->getBitSize() != 1) { + + parameterAccessContext.setError("Type mismatch"); + // Append parameter path to error + parameterAccessContext.appendToError(" " + getPath()); + + return false; + } + + // Rely on integer access + uint32_t uiValue; + + if (bSet) { + + uiValue = bValue; + } + + if (!accessAsInteger(uiValue, bSet, parameterAccessContext)) { + + return false; + } + + if (!bSet) { + + bValue = uiValue != 0; + } + + return true; +} + +// Integer Access +bool CBitParameter::accessAsInteger(uint32_t& uiValue, bool bSet, CParameterAccessContext& parameterAccessContext) const +{ + uint32_t uiOffset = getOffset(); + + if (bSet) { + + // Set and sync + if (!doSet(uiValue, uiOffset, parameterAccessContext) || !sync(parameterAccessContext)) { + + // Append parameter path to error + parameterAccessContext.appendToError(" " + getPath()); + + return false; + } + } else { + + // Convert + doGet(uiValue, uiOffset, parameterAccessContext); + } + return true; +} + +template +bool CBitParameter::doSet(type value, uint32_t uiOffset, CParameterAccessContext& parameterAccessContext) const +{ uint32_t uiData = 0; // Read/modify/write @@ -72,7 +141,7 @@ bool CBitParameter::doSetValue(const string& strValue, uint32_t uiOffset, CParam pBlackboard->readInteger(&uiData, getBelongingBlockSize(), uiOffset, parameterAccessContext.isBigEndianSubsystem()); // Convert - if (!static_cast(getTypeElement())->asInteger(strValue, uiData, parameterAccessContext)) { + if (!static_cast(getTypeElement())->toBlackboard(value, uiData, parameterAccessContext)) { return false; } @@ -82,7 +151,8 @@ bool CBitParameter::doSetValue(const string& strValue, uint32_t uiOffset, CParam return true; } -void CBitParameter::doGetValue(string& strValue, uint32_t uiOffset, CParameterAccessContext& parameterAccessContext) const +template +void CBitParameter::doGet(type& value, uint32_t uiOffset, CParameterAccessContext& parameterAccessContext) const { uint32_t uiData = 0; @@ -93,6 +163,5 @@ void CBitParameter::doGetValue(string& strValue, uint32_t uiOffset, CParameterAc pBlackboard->readInteger(&uiData, getBelongingBlockSize(), uiOffset, parameterAccessContext.isBigEndianSubsystem()); // Convert - static_cast(getTypeElement())->asString(uiData, strValue, parameterAccessContext); + static_cast(getTypeElement())->fromBlackboard(value, uiData, parameterAccessContext); } - -- cgit v1.1