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 | |
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>
42 files changed, 1695 insertions, 325 deletions
@@ -2,3 +2,4 @@ *.win *.layout *.user +*.user.* diff --git a/parameter/Android.mk b/parameter/Android.mk index aba82af..267d916 100644 --- a/parameter/Android.mk +++ b/parameter/Android.mk @@ -9,7 +9,8 @@ LOCAL_COPY_HEADERS_TO := parameter LOCAL_COPY_HEADERS := \ ParameterMgrPlatformConnector.h \ SelectionCriterionTypeInterface.h \ - SelectionCriterionInterface.h + SelectionCriterionInterface.h \ + ParameterHandle.h LOCAL_SRC_FILES:= \ Subsystem.cpp \ @@ -87,7 +88,8 @@ LOCAL_SRC_FILES:= \ StringParameter.cpp \ EnumParameterType.cpp \ VirtualSubsystem.cpp \ - VirtualSyncer.cpp + VirtualSyncer.cpp \ + ParameterHandle.cpp LOCAL_MODULE:= libparameter diff --git a/parameter/ArrayParameter.cpp b/parameter/ArrayParameter.cpp index 3877e79..0021a20 100644 --- a/parameter/ArrayParameter.cpp +++ b/parameter/ArrayParameter.cpp @@ -35,6 +35,7 @@ #include "ParameterAccessContext.h" #include "ConfigurationAccessContext.h" #include "ParameterBlackboard.h" +#include <assert.h> #define base CParameter @@ -95,80 +96,91 @@ bool CArrayParameter::serializeXmlSettings(CXmlElement& xmlConfigurationSettings } // User set/get -bool CArrayParameter::setValue(CPathNavigator& pathNavigator, const string& strValue, CParameterAccessContext& parameterContext) const +bool CArrayParameter::accessValue(CPathNavigator& pathNavigator, string& strValue, bool bSet, CParameterAccessContext& parameterAccessContext) const { - uint32_t uiStartIndex; + uint32_t uiIndex; - if (!getIndex(pathNavigator, uiStartIndex, parameterContext)) { + if (!getIndex(pathNavigator, uiIndex, parameterAccessContext)) { return false; } - // Check for dynamic access - if (!checkForDynamicAccess(parameterContext)) { + if (bSet) { + // Set + if (uiIndex == (uint32_t)-1) { - return false; - } + // No index provided, start with 0 + uiIndex = 0; + } - if (uiStartIndex == (uint32_t)-1) { + // Actually set values + if (!setValues(uiIndex, 0, strValue, parameterAccessContext)) { - // No index provided, start with 0 - uiStartIndex = 0; - } + return false; + } - // Actually set values - if (!setValues(uiStartIndex, 0, strValue, parameterContext)) { + // Synchronize + if (parameterAccessContext.getAutoSync() && !sync(parameterAccessContext)) { - return false; - } + // Append parameter path to error + parameterAccessContext.appendToError(" " + getPath()); - // Synchronize - if (parameterContext.getAutoSync() && !sync(parameterContext)) { + return false; + } + } else { + // Get + if (uiIndex == (uint32_t)-1) { - // Append parameter path to error - parameterContext.appendToError(" " + getPath()); + // Whole array requested + getValues(0, strValue, parameterAccessContext); - return false; + } else { + // Scalar requested + doGetValue(strValue, getOffset() + uiIndex * getSize(), parameterAccessContext); + } } return true; } -bool CArrayParameter::getValue(CPathNavigator& pathNavigator, string& strValue, CParameterAccessContext& parameterContext) const +// Boolean +bool CArrayParameter::accessAsBooleanArray(vector<bool>& abValues, bool bSet, CParameterAccessContext& parameterAccessContext) const { - uint32_t uiIndex; - - if (!getIndex(pathNavigator, uiIndex, parameterContext)) { - - return false; - } - - // Check for dynamic access - if (!checkForDynamicAccess(parameterContext)) { - - return false; - } + return accessValues(abValues, bSet, parameterAccessContext); +} - if (uiIndex == (uint32_t)-1) { +// Integer +bool CArrayParameter::accessAsIntegerArray(vector<uint32_t>& auiValues, bool bSet, CParameterAccessContext& parameterAccessContext) const +{ + return accessValues(auiValues, bSet, parameterAccessContext); +} - // Whole array requested - getValues(0, strValue, parameterContext); +// Signed Integer Access +bool CArrayParameter::accessAsSignedIntegerArray(vector<int32_t>& aiValues, bool bSet, CParameterAccessContext& parameterAccessContext) const +{ + return accessValues(aiValues, bSet, parameterAccessContext); +} - } else { - // Scalar requested - doGetValue(strValue, getOffset() + uiIndex * getSize(), parameterContext); - } +// Double Access +bool CArrayParameter::accessAsDoubleArray(vector<double>& adValues, bool bSet, CParameterAccessContext& parameterAccessContext) const +{ + return accessValues(adValues, bSet, parameterAccessContext); +} - return true; +// String Access +bool CArrayParameter::accessAsStringArray(vector<string>& astrValues, bool bSet, CParameterAccessContext& parameterAccessContext) const +{ + return accessValues(astrValues, bSet, parameterAccessContext); } +// Dump void CArrayParameter::logValue(string& strValue, CErrorContext& errorContext) const { // Parameter context - CParameterAccessContext& parameterContext = static_cast<CParameterAccessContext&>(errorContext); + CParameterAccessContext& parameterAccessContext = static_cast<CParameterAccessContext&>(errorContext); // Dump values - getValues(0, strValue, parameterContext); + getValues(0, strValue, parameterAccessContext); } // Used for simulation and virtual subsystems @@ -197,7 +209,7 @@ void CArrayParameter::setDefaultValues(CParameterAccessContext& parameterAccessC } // Index from path -bool CArrayParameter::getIndex(CPathNavigator& pathNavigator, uint32_t& uiIndex, CParameterAccessContext& parameterContext) const +bool CArrayParameter::getIndex(CPathNavigator& pathNavigator, uint32_t& uiIndex, CParameterAccessContext& parameterAccessContext) const { uiIndex = (uint32_t)-1; @@ -212,7 +224,7 @@ bool CArrayParameter::getIndex(CPathNavigator& pathNavigator, uint32_t& uiIndex, if (!iss) { - parameterContext.setError("Expected numerical expression as last item in " + pathNavigator.getCurrentPath()); + parameterAccessContext.setError("Expected numerical expression as last item in " + pathNavigator.getCurrentPath()); return false; } @@ -222,7 +234,7 @@ bool CArrayParameter::getIndex(CPathNavigator& pathNavigator, uint32_t& uiIndex, oss << "Provided index out of range (max is " << getArrayLength() - 1 << ")"; - parameterContext.setError(oss.str()); + parameterAccessContext.setError(oss.str()); return false; } @@ -233,7 +245,7 @@ bool CArrayParameter::getIndex(CPathNavigator& pathNavigator, uint32_t& uiIndex, if (pStrChildName) { // Should be leaf element - parameterContext.setError("Path not found: " + pathNavigator.getCurrentPath()); + parameterAccessContext.setError("Path not found: " + pathNavigator.getCurrentPath()); return false; } @@ -243,7 +255,7 @@ bool CArrayParameter::getIndex(CPathNavigator& pathNavigator, uint32_t& uiIndex, } // Common set value processing -bool CArrayParameter::setValues(uint32_t uiStartIndex, uint32_t uiBaseOffset, const string& strValue, CParameterAccessContext& parameterContext) const +bool CArrayParameter::setValues(uint32_t uiStartIndex, uint32_t uiBaseOffset, const string& strValue, CParameterAccessContext& parameterAccessContext) const { // Deal with value(s) Tokenizer tok(strValue, DEFAULT_DELIMITER + ","); @@ -252,10 +264,10 @@ bool CArrayParameter::setValues(uint32_t uiStartIndex, uint32_t uiBaseOffset, co uint32_t uiNbValues = astrValues.size(); // Check number of provided values - if (uiNbValues + uiStartIndex > getArrayLength()) { + if (uiNbValues + uiStartIndex > getArrayLength()) { // Out of bounds - parameterContext.setError("Too many values provided"); + parameterAccessContext.setError("Too many values provided"); return false; } @@ -267,10 +279,10 @@ bool CArrayParameter::setValues(uint32_t uiStartIndex, uint32_t uiBaseOffset, co for (uiValueIndex = 0; uiValueIndex < uiNbValues; uiValueIndex++) { - if (!doSetValue(astrValues[uiValueIndex], uiOffset, parameterContext)) { + if (!doSetValue(astrValues[uiValueIndex], uiOffset, parameterAccessContext)) { // Append parameter path to error - parameterContext.appendToError(" " + getPath() + "/" + toString(uiValueIndex + uiStartIndex)); + parameterAccessContext.appendToError(" " + getPath() + "/" + toString(uiValueIndex + uiStartIndex)); return false; } @@ -281,7 +293,7 @@ bool CArrayParameter::setValues(uint32_t uiStartIndex, uint32_t uiBaseOffset, co } // Common get value processing -void CArrayParameter::getValues(uint32_t uiBaseOffset, string& strValues, CParameterAccessContext& parameterContext) const +void CArrayParameter::getValues(uint32_t uiBaseOffset, string& strValues, CParameterAccessContext& parameterAccessContext) const { uint32_t uiValueIndex; uint32_t uiSize = getSize(); @@ -295,7 +307,7 @@ void CArrayParameter::getValues(uint32_t uiBaseOffset, string& strValues, CParam for (uiValueIndex = 0; uiValueIndex < uiArrayLength; uiValueIndex++) { string strReadValue; - doGetValue(strReadValue, uiOffset, parameterContext); + doGetValue(strReadValue, uiOffset, parameterAccessContext); if (!bFirst) { @@ -310,3 +322,113 @@ void CArrayParameter::getValues(uint32_t uiBaseOffset, string& strValues, CParam uiOffset += uiSize; } } + +// Generic Access +template <typename type> +bool CArrayParameter::accessValues(vector<type>& values, bool bSet, CParameterAccessContext& parameterAccessContext) const +{ + bool bSuccess; + + if (bSet) { + + if (setValues(values, parameterAccessContext)) { + + // Synchronize + bSuccess = sync(parameterAccessContext); + } else { + + bSuccess = false; + } + } else { + + bSuccess = getValues(values, parameterAccessContext); + } + if (!bSuccess) { + + // Append parameter path to error + parameterAccessContext.appendToError(" " + getPath()); + } + return bSuccess; +} + +template <typename type> +bool CArrayParameter::setValues(const vector<type>& values, CParameterAccessContext& parameterAccessContext) const +{ + uint32_t uiNbValues = getArrayLength(); + uint32_t uiValueIndex; + uint32_t uiSize = getSize(); + uint32_t uiOffset = getOffset(); + + assert(values.size() == uiNbValues); + + // Process + for (uiValueIndex = 0; uiValueIndex < uiNbValues; uiValueIndex++) { + + if (!doSet(values[uiValueIndex], uiOffset, parameterAccessContext)) { + + return false; + } + + uiOffset += uiSize; + } + + return true; +} + +template <typename type> +bool CArrayParameter::getValues(vector<type>& values, CParameterAccessContext& parameterAccessContext) const +{ + uint32_t uiNbValues = getArrayLength(); + uint32_t uiValueIndex; + uint32_t uiSize = getSize(); + uint32_t uiOffset = getOffset(); + + values.clear(); + + for (uiValueIndex = 0; uiValueIndex < uiNbValues; uiValueIndex++) { + type readValue; + + if (!doGet(readValue, uiOffset, parameterAccessContext)) { + + return false; + } + + values.push_back(readValue); + + uiOffset += uiSize; + } + return true; +} + +template <typename type> +bool CArrayParameter::doSet(type value, uint32_t uiOffset, CParameterAccessContext& parameterAccessContext) const +{ + uint32_t uiData; + + if (!static_cast<const CParameterType*>(getTypeElement())->toBlackboard(value, uiData, parameterAccessContext)) { + + return false; + } + // Write blackboard + CParameterBlackboard* pBlackboard = parameterAccessContext.getParameterBlackboard(); + + // Beware this code works on little endian architectures only! + pBlackboard->writeInteger(&uiData, getSize(), uiOffset, parameterAccessContext.isBigEndianSubsystem()); + + return true; +} + +template <typename type> +bool CArrayParameter::doGet(type& value, uint32_t uiOffset, CParameterAccessContext& parameterAccessContext) const +{ + uint32_t uiData = 0; + + // Read blackboard + const CParameterBlackboard* pBlackboard = parameterAccessContext.getParameterBlackboard(); + + // Beware this code works on little endian architectures only! + pBlackboard->readInteger(&uiData, getSize(), uiOffset, parameterAccessContext.isBigEndianSubsystem()); + + return static_cast<const CParameterType*>(getTypeElement())->fromBlackboard(value, uiData, parameterAccessContext); +} + diff --git a/parameter/ArrayParameter.h b/parameter/ArrayParameter.h index 3816652..ea6950e 100644 --- a/parameter/ArrayParameter.h +++ b/parameter/ArrayParameter.h @@ -42,10 +42,22 @@ public: // XML configuration settings parsing virtual bool serializeXmlSettings(CXmlElement& xmlConfigurationSettingsElementContent, CConfigurationAccessContext& configurationAccessContext) const; + + // Value access + // Boolean + virtual bool accessAsBooleanArray(vector<bool>& abValues, bool bSet, CParameterAccessContext& parameterAccessContext) const; + // Integer + virtual bool accessAsIntegerArray(vector<uint32_t>& auiValues, bool bSet, CParameterAccessContext& parameterAccessContext) const; + // Signed Integer Access + virtual bool accessAsSignedIntegerArray(vector<int32_t>& aiValues, bool bSet, CParameterAccessContext& parameterAccessContext) const; + // Double Access + virtual bool accessAsDoubleArray(vector<double>& adValues, bool bSet, CParameterAccessContext& parameterAccessContext) const; + // String Access + virtual bool accessAsStringArray(vector<string>& astrValues, bool bSet, CParameterAccessContext& parameterAccessContext) const; + protected: // User set/get - virtual bool setValue(CPathNavigator& pathNavigator, const string& strValue, CParameterAccessContext& parameterContext) const; - virtual bool getValue(CPathNavigator& pathNavigator, string& strValue, CParameterAccessContext& parameterContext) const; + virtual bool accessValue(CPathNavigator& pathNavigator, string& strValue, bool bSet, CParameterAccessContext& parameterAccessContext) const; virtual void logValue(string& strValue, CErrorContext& errorContext) const; // Used for simulation and virtual subsystems virtual void setDefaultValues(CParameterAccessContext& parameterAccessContext) const; @@ -56,9 +68,22 @@ private: // Array length uint32_t getArrayLength() const; // Common set value processing - bool setValues(uint32_t uiStartIndex, uint32_t uiBaseOffset, const string& strValue, CParameterAccessContext& parameterContext) const; + bool setValues(uint32_t uiStartIndex, uint32_t uiBaseOffset, const string& strValue, CParameterAccessContext& parameterAccessContext) const; // Log / get values common - void getValues(uint32_t uiBaseOffset, string& strValues, CParameterAccessContext& parameterContext) const; + void getValues(uint32_t uiBaseOffset, string& strValues, CParameterAccessContext& parameterAccessContext) const; // Index retrieval from user set/get request - bool getIndex(CPathNavigator& pathNavigator, uint32_t& uiIndex, CParameterAccessContext& parameterContext) const; + bool getIndex(CPathNavigator& pathNavigator, uint32_t& uiIndex, CParameterAccessContext& parameterAccessContext) const; + + /// Value access + // Generic Access + template <typename type> + bool accessValues(vector<type>& values, bool bSet, CParameterAccessContext& parameterAccessContext) const; + template <typename type> + bool setValues(const vector<type>& values, CParameterAccessContext& parameterAccessContext) const; + template <typename type> + bool getValues(vector<type>& values, CParameterAccessContext& parameterAccessContext) const; + template <typename type> + bool doSet(type value, uint32_t uiOffset, CParameterAccessContext& parameterAccessContext) const; + template <typename type> + bool doGet(type& value, uint32_t uiOffset, CParameterAccessContext& parameterAccessContext) const; }; diff --git a/parameter/BaseParameter.cpp b/parameter/BaseParameter.cpp index b4b0780..73bcad9 100644 --- a/parameter/BaseParameter.cpp +++ b/parameter/BaseParameter.cpp @@ -33,6 +33,7 @@ #include "ParameterAccessContext.h" #include "ConfigurationAccessContext.h" #include "ParameterBlackboard.h" +#include <assert.h> #define base CInstanceConfigurableElement @@ -73,77 +74,153 @@ bool CBaseParameter::serializeXmlSettings(CXmlElement& xmlConfigurationSettingsE void CBaseParameter::logValue(string& strValue, CErrorContext& errorContext) const { // Parameter context - CParameterAccessContext& parameterContext = static_cast<CParameterAccessContext&>(errorContext); + CParameterAccessContext& parameterAccessContext = static_cast<CParameterAccessContext&>(errorContext); // Dump value - doGetValue(strValue, getOffset(), parameterContext); + doGetValue(strValue, getOffset(), parameterAccessContext); } -// Parameter Access -bool CBaseParameter::setValue(CPathNavigator& pathNavigator, const string& strValue, CParameterAccessContext& parameterContext) const +// Check element is a parameter +bool CBaseParameter::isParameter() const { - // Check path validity - if (!checkPathExhausted(pathNavigator, parameterContext)) { + return true; +} - return false; - } +/// Value access +// Boolean access +bool CBaseParameter::accessAsBoolean(bool& bValue, bool bSet, CParameterAccessContext& parameterAccessContext) const +{ + (void)bValue; + (void)bSet; - // Check for dynamic access - if (!checkForDynamicAccess(parameterContext)) { + parameterAccessContext.setError("Unsupported conversion"); - return false; - } + return false; +} - // Set Value - if (!doSetValue(strValue, getOffset(), parameterContext)) { +bool CBaseParameter::accessAsBooleanArray(vector<bool>& abValues, bool bSet, CParameterAccessContext& parameterAccessContext) const +{ + (void)abValues; + (void)bSet; - // Append parameter path to error - parameterContext.appendToError(" " + getPath()); + parameterAccessContext.setError("Unsupported conversion"); - return false; - } - // Synchronize - if (parameterContext.getAutoSync() && !sync(parameterContext)) { + return false; +} - // Append parameter path to error - parameterContext.appendToError(" " + getPath()); +// Integer Access +bool CBaseParameter::accessAsInteger(uint32_t& uiValue, bool bSet, CParameterAccessContext& parameterAccessContext) const +{ + (void)uiValue; + (void)bSet; - return false; - } - return true; + parameterAccessContext.setError("Unsupported conversion"); + + return false; } -bool CBaseParameter::getValue(CPathNavigator& pathNavigator, string& strValue, CParameterAccessContext& parameterContext) const +bool CBaseParameter::accessAsIntegerArray(vector<uint32_t>& auiValues, bool bSet, CParameterAccessContext& parameterAccessContext) const { - // Check path validity - if (!checkPathExhausted(pathNavigator, parameterContext)) { + (void)auiValues; + (void)bSet; - return false; - } + parameterAccessContext.setError("Unsupported conversion"); - // Check for dynamic access - if (!checkForDynamicAccess(parameterContext)) { + return false; +} - return false; - } +// Signed Integer Access +bool CBaseParameter::accessAsSignedInteger(int32_t& iValue, bool bSet, CParameterAccessContext& parameterAccessContext) const +{ + (void)iValue; + (void)bSet; + + parameterAccessContext.setError("Unsupported conversion"); + + return false; +} + +bool CBaseParameter::accessAsSignedIntegerArray(vector<int32_t>& aiValues, bool bSet, CParameterAccessContext& parameterAccessContext) const +{ + (void)aiValues; + (void)bSet; + + parameterAccessContext.setError("Unsupported conversion"); + + return false; +} + +// Double Access +bool CBaseParameter::accessAsDouble(double& dValue, bool bSet, CParameterAccessContext& parameterAccessContext) const +{ + (void)dValue; + (void)bSet; - // Get Value - doGetValue(strValue, getOffset(), parameterContext); + parameterAccessContext.setError("Unsupported conversion"); + + return false; +} + +bool CBaseParameter::accessAsDoubleArray(vector<double>& adValues, bool bSet, CParameterAccessContext& parameterAccessContext) const +{ + (void)adValues; + (void)bSet; + + parameterAccessContext.setError("Unsupported conversion"); + + return false; +} + +// String Access +bool CBaseParameter::accessAsString(string& strValue, bool bSet, CParameterAccessContext& parameterAccessContext) const +{ + if (bSet) { + + // Set Value + if (!doSetValue(strValue, getOffset(), parameterAccessContext)) { + + // Append parameter path to error + parameterAccessContext.appendToError(" " + getPath()); + + return false; + } + // Synchronize + if (parameterAccessContext.getAutoSync() && !sync(parameterAccessContext)) { + + // Append parameter path to error + parameterAccessContext.appendToError(" " + getPath()); + + return false; + } + + } else { + // Get Value + doGetValue(strValue, getOffset(), parameterAccessContext); + } return true; } -// Dynamic access checking -bool CBaseParameter::checkForDynamicAccess(CParameterAccessContext& parameterAccessContext) const +bool CBaseParameter::accessAsStringArray(vector<string>& astrValues, bool bSet, CParameterAccessContext& parameterAccessContext) const { - // Check for dynamic access - if (parameterAccessContext.isDynamicAccess() && !isRogue()) { + (void)astrValues; + (void)bSet; + (void)parameterAccessContext; + + // Generic string array access to scalar parameter must have been filtered out before + assert(0); + + return false; +} - // Parameter is not rogue - parameterAccessContext.setError("Parameter " + getPath() + " is not rogue"); +// Parameter Access +bool CBaseParameter::accessValue(CPathNavigator& pathNavigator, string& strValue, bool bSet, CParameterAccessContext& parameterAccessContext) const +{ + // Check path validity + if (!checkPathExhausted(pathNavigator, parameterAccessContext)) { return false; } - return true; + return accessAsString(strValue, bSet, parameterAccessContext); } diff --git a/parameter/BaseParameter.h b/parameter/BaseParameter.h index 2e3598d..c0db74f 100644 --- a/parameter/BaseParameter.h +++ b/parameter/BaseParameter.h @@ -31,6 +31,7 @@ #pragma once #include <stdint.h> +#include <vector> #include "InstanceConfigurableElement.h" @@ -44,16 +45,37 @@ public: // XML configuration settings parsing/composing virtual bool serializeXmlSettings(CXmlElement& xmlConfigurationSettingsElementContent, CConfigurationAccessContext& configurationAccessContext) const; + + // Check element is a parameter + virtual bool isParameter() const; + + /// Value access + // Boolean access + virtual bool accessAsBoolean(bool& bValue, bool bSet, CParameterAccessContext& parameterAccessContext) const; + virtual bool accessAsBooleanArray(vector<bool>& abValues, bool bSet, CParameterAccessContext& parameterAccessContext) const; + + // Integer Access + virtual bool accessAsInteger(uint32_t& uiValue, bool bSet, CParameterAccessContext& parameterAccessContext) const; + virtual bool accessAsIntegerArray(vector<uint32_t>& auiValues, bool bSet, CParameterAccessContext& parameterAccessContext) const; + + // Signed Integer Access + virtual bool accessAsSignedInteger(int32_t& iValue, bool bSet, CParameterAccessContext& parameterAccessContext) const; + virtual bool accessAsSignedIntegerArray(vector<int32_t>& aiValues, bool bSet, CParameterAccessContext& parameterAccessContext) const; + + // Double Access + virtual bool accessAsDouble(double& dValue, bool bSet, CParameterAccessContext& parameterAccessContext) const; + virtual bool accessAsDoubleArray(vector<double>& adValues, bool bSet, CParameterAccessContext& parameterAccessContext) const; + + // String Access + bool accessAsString(string& strValue, bool bSet, CParameterAccessContext& parameterAccessContext) const; + virtual bool accessAsStringArray(vector<string>& astrValues, bool bSet, CParameterAccessContext& parameterAccessContext) const; + protected: // Parameter Access - virtual bool setValue(CPathNavigator& pathNavigator, const string& strValue, CParameterAccessContext& parameterContext) const; - virtual bool getValue(CPathNavigator& pathNavigator, string& strValue, CParameterAccessContext& parameterContext) const; + virtual bool accessValue(CPathNavigator& pathNavigator, string& strValue, bool bSet, CParameterAccessContext& parameterAccessContext) const; virtual void logValue(string& strValue, CErrorContext& errorContext) const; // Actual value access (to be implemented by derived) virtual bool doSetValue(const string& strValue, uint32_t uiOffset, CParameterAccessContext& parameterAccessContext) const = 0; virtual void doGetValue(string& strValue, uint32_t uiOffset, CParameterAccessContext& parameterAccessContext) const = 0; - - // Dynamic access checking - bool checkForDynamicAccess(CParameterAccessContext& parameterAccessContext) const; }; 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<const CBitParameterType*>(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 <typename type> +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<const CBitParameterType*>(getTypeElement())->asInteger(strValue, uiData, parameterAccessContext)) { + if (!static_cast<const CBitParameterType*>(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 <typename type> +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<const CBitParameterType*>(getTypeElement())->asString(uiData, strValue, parameterAccessContext); + static_cast<const CBitParameterType*>(getTypeElement())->fromBlackboard(value, uiData, parameterAccessContext); } - diff --git a/parameter/BitParameter.h b/parameter/BitParameter.h index 5f62cf3..3391e27 100644 --- a/parameter/BitParameter.h +++ b/parameter/BitParameter.h @@ -44,11 +44,25 @@ public: // Type virtual Type getType() const; + + /// Value access + // Boolean access + virtual bool accessAsBoolean(bool& bValue, bool bSet, CParameterAccessContext& parameterAccessContext) const; + + // Integer Access + virtual bool accessAsInteger(uint32_t& uiValue, bool bSet, CParameterAccessContext& parameterAccessContext) const; private: // Size uint32_t getBelongingBlockSize() const; - // Actual Access + // String Access virtual bool doSetValue(const string& strValue, uint32_t uiOffset, CParameterAccessContext& parameterAccessContext) const; virtual void doGetValue(string& strValue, uint32_t uiOffset, CParameterAccessContext& parameterAccessContext) const; + + // Generic Access + template <typename type> + bool doSet(type value, uint32_t uiOffset, CParameterAccessContext& parameterAccessContext) const; + template <typename type> + void doGet(type& value, uint32_t uiOffset, CParameterAccessContext& parameterAccessContext) const; + }; diff --git a/parameter/BitParameterType.cpp b/parameter/BitParameterType.cpp index 31d1d77..30b0173 100644 --- a/parameter/BitParameterType.cpp +++ b/parameter/BitParameterType.cpp @@ -94,7 +94,7 @@ bool CBitParameterType::fromXml(const CXmlElement& xmlElement, CXmlSerializingCo } // Conversion -bool CBitParameterType::asInteger(const string& strValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const +bool CBitParameterType::toBlackboard(const string& strValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const { // Hexa bool bValueProvidedAsHexa = !strValue.compare(0, 2, "0x"); @@ -129,7 +129,7 @@ bool CBitParameterType::asInteger(const string& strValue, uint32_t& uiValue, CPa return true; } -void CBitParameterType::asString(const uint32_t& uiValue, string& strValue, CParameterAccessContext& parameterAccessContext) const +void CBitParameterType::fromBlackboard(string& strValue, const uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const { uint32_t uiConvertedValue = (uiValue & getMask()) >> _uiBitPos; @@ -147,6 +147,30 @@ void CBitParameterType::asString(const uint32_t& uiValue, string& strValue, CPar strValue = strStream.str(); } +// Value access +// Integer +bool CBitParameterType::toBlackboard(uint32_t uiUserValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const +{ + if (uiUserValue > getMaxValue()) { + + parameterAccessContext.setError("Value out of range"); + + return false; + } + + // Do bitwise RMW operation + uiValue = (uiValue & ~getMask()) | (uiUserValue << _uiBitPos); + + return true; +} + +void CBitParameterType::fromBlackboard(uint32_t& uiUserValue, uint32_t uiValue, CParameterAccessContext& parameterAccessContext) const +{ + (void)parameterAccessContext; + + uiUserValue = (uiValue & getMask()) >> _uiBitPos; +} + // Bit Size uint32_t CBitParameterType::getBitSize() const { diff --git a/parameter/BitParameterType.h b/parameter/BitParameterType.h index b8afeec..6cd86c4 100644 --- a/parameter/BitParameterType.h +++ b/parameter/BitParameterType.h @@ -44,9 +44,13 @@ public: // From IXmlSink virtual bool fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext); - // Conversion - bool asInteger(const string& strValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const; - void asString(const uint32_t& uiValue, string& strValue, CParameterAccessContext& parameterAccessContext) const; + /// Conversion + // String + bool toBlackboard(const string& strValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const; + void fromBlackboard(string& strValue, const uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const; + // Integer + bool toBlackboard(uint32_t uiUserValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const; + void fromBlackboard(uint32_t& uiUserValue, uint32_t uiValue, CParameterAccessContext& parameterAccessContext) const; // Bit Size uint32_t getBitSize() const; diff --git a/parameter/BooleanParameterType.cpp b/parameter/BooleanParameterType.cpp index 425596d..0e4c636 100644 --- a/parameter/BooleanParameterType.cpp +++ b/parameter/BooleanParameterType.cpp @@ -47,7 +47,8 @@ string CBooleanParameterType::getKind() const return "BooleanParameter"; } -bool CBooleanParameterType::asInteger(const string& strValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const +// Tuning interface +bool CBooleanParameterType::toBlackboard(const string& strValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const { if (strValue == "1" || strValue == "0x1") { @@ -76,7 +77,7 @@ bool CBooleanParameterType::asInteger(const string& strValue, uint32_t& uiValue, return true; } -void CBooleanParameterType::asString(const uint32_t& uiValue, string& strValue, CParameterAccessContext& parameterAccessContext) const +bool CBooleanParameterType::fromBlackboard(string& strValue, const uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const { if (parameterAccessContext.valueSpaceIsRaw() && parameterAccessContext.outputRawFormatIsHex()) { @@ -84,4 +85,47 @@ void CBooleanParameterType::asString(const uint32_t& uiValue, string& strValue, } strValue += uiValue ? "1" : "0"; + + return true; +} + +// Value access +bool CBooleanParameterType::toBlackboard(bool bUserValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const +{ + (void)parameterAccessContext; + + uiValue = bUserValue; + + return true; +} + +bool CBooleanParameterType::fromBlackboard(bool& bUserValue, uint32_t uiValue, CParameterAccessContext& parameterAccessContext) const +{ + (void)parameterAccessContext; + + bUserValue = uiValue != 0; + + return true; +} + +// Integer +bool CBooleanParameterType::toBlackboard(uint32_t uiUserValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const +{ + if (uiUserValue > 1) { + + parameterAccessContext.setError("Value out of range"); + } + + uiValue = uiUserValue; + + return true; +} + +bool CBooleanParameterType::fromBlackboard(uint32_t& uiUserValue, uint32_t uiValue, CParameterAccessContext& parameterAccessContext) const +{ + (void)parameterAccessContext; + + uiUserValue = uiValue != 0; + + return true; } diff --git a/parameter/BooleanParameterType.h b/parameter/BooleanParameterType.h index 1bf0a5a..97d670e 100644 --- a/parameter/BooleanParameterType.h +++ b/parameter/BooleanParameterType.h @@ -38,7 +38,17 @@ public: CBooleanParameterType(const string& strName); virtual ~CBooleanParameterType(); + // Kind virtual string getKind() const; - virtual bool asInteger(const string& strValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const; - virtual void asString(const uint32_t& uiValue, string& strValue, CParameterAccessContext& parameterAccessContext) const; + + /// Conversion + // String + virtual bool toBlackboard(const string& strValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const; + virtual bool fromBlackboard(string& strValue, const uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const; + // Boolean + virtual bool toBlackboard(bool bUserValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const; + virtual bool fromBlackboard(bool& bUserValue, uint32_t uiValue, CParameterAccessContext& parameterAccessContext) const; + // Integer + virtual bool toBlackboard(uint32_t uiUserValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const; + virtual bool fromBlackboard(uint32_t& uiUserValue, uint32_t uiValue, CParameterAccessContext& parameterAccessContext) const; }; diff --git a/parameter/ConfigurableDomain.cpp b/parameter/ConfigurableDomain.cpp index c9e3266..696bbd0 100644 --- a/parameter/ConfigurableDomain.cpp +++ b/parameter/ConfigurableDomain.cpp @@ -32,7 +32,6 @@ #include "DomainConfiguration.h" #include "ConfigurableElement.h" #include "ConfigurationAccessContext.h" -#include "Subsystem.h" #include "XmlDomainSerializingContext.h" #include <assert.h> @@ -243,17 +242,15 @@ bool CConfigurableDomain::parseConfigurableElements(const CXmlElement& xmlElemen string strConfigurableElementPath = xmlConfigurableElementElement.getAttributeString("Path"); CPathNavigator pathNavigator(strConfigurableElementPath); - - string* pStrChildName = pathNavigator.next(); + string strError; // Is there an element and does it match system class name? - if (!pStrChildName || *pStrChildName != pSystemClassElement->getName()) { + if (!pathNavigator.navigateThrough(pSystemClassElement->getName(), strError)) { - serializingContext.setError("Could not find configurable element of path " + strConfigurableElementPath + " from ConfigurableDomain description " + getName()); + serializingContext.setError("Could not find configurable element of path " + strConfigurableElementPath + " from ConfigurableDomain description " + getName() + " (" + strError + ")"); return false; } - // Browse system class for configurable element CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pSystemClassElement->findDescendant(pathNavigator)); @@ -264,7 +261,6 @@ bool CConfigurableDomain::parseConfigurableElements(const CXmlElement& xmlElemen return false; } // Add found element to domain - string strError; if (!addConfigurableElement(pConfigurableElement, NULL, strError)) { serializingContext.setError(strError); diff --git a/parameter/ConfigurableElement.cpp b/parameter/ConfigurableElement.cpp index c5d97f8..93acf3f 100644 --- a/parameter/ConfigurableElement.cpp +++ b/parameter/ConfigurableElement.cpp @@ -127,13 +127,13 @@ bool CConfigurableElement::serializeXmlSettings(CXmlElement& xmlConfigurationSet } // Parameter access -bool CConfigurableElement::setValue(CPathNavigator& pathNavigator, const string& strValue, CParameterAccessContext& parameterContext) const +bool CConfigurableElement::accessValue(CPathNavigator& pathNavigator, string& strValue, bool bSet, CParameterAccessContext& parameterAccessContext) const { string* pStrChildName = pathNavigator.next(); if (!pStrChildName) { - parameterContext.setError("Non settable element"); + parameterAccessContext.setError("Non accessible element"); return false; } @@ -142,35 +142,12 @@ bool CConfigurableElement::setValue(CPathNavigator& pathNavigator, const string& if (!pChild) { - parameterContext.setError("Path not found: " + pathNavigator.getCurrentPath()); + parameterAccessContext.setError("Path not found: " + pathNavigator.getCurrentPath()); return false; } - return pChild->setValue(pathNavigator, strValue, parameterContext); -} - -bool CConfigurableElement::getValue(CPathNavigator& pathNavigator, string& strValue, CParameterAccessContext& parameterContext) const -{ - string* pStrChildName = pathNavigator.next(); - - if (!pStrChildName) { - - parameterContext.setError("Non gettable element"); - - return false; - } - - const CConfigurableElement* pChild = static_cast<const CConfigurableElement*>(findChild(*pStrChildName)); - - if (!pChild) { - - parameterContext.setError("Path not found: " + pathNavigator.getCurrentPath()); - - return false; - } - - return pChild->getValue(pathNavigator, strValue, parameterContext); + return pChild->accessValue(pathNavigator, strValue, bSet, parameterAccessContext); } // Used for simulation and virtual subsystems @@ -489,6 +466,13 @@ const CSubsystem* CConfigurableElement::getBelongingSubsystem() const return static_cast<const CConfigurableElement*>(pParent)->getBelongingSubsystem(); } +// Check element is a parameter +bool CConfigurableElement::isParameter() const +{ + return false; +} + + // Check parent is still of current type (by structure knowledge) bool CConfigurableElement::isOfConfigurableElementType(const CElement* pParent) const { diff --git a/parameter/ConfigurableElement.h b/parameter/ConfigurableElement.h index 57eb3a5..41e33bf 100644 --- a/parameter/ConfigurableElement.h +++ b/parameter/ConfigurableElement.h @@ -85,9 +85,14 @@ public: // Footprint as string string getFootprintAsString() const; + // Belonging subsystem + virtual const CSubsystem* getBelongingSubsystem() const; + + // Check element is a parameter + virtual bool isParameter() const; + // Parameter access - virtual bool setValue(CPathNavigator& pathNavigator, const string& strValue, CParameterAccessContext& parameterContext) const; - virtual bool getValue(CPathNavigator& pathNavigator, string& strValue, CParameterAccessContext& parameterContext) const; + virtual bool accessValue(CPathNavigator& pathNavigator, string& strValue, bool bSet, CParameterAccessContext& parameterAccessContext) const; // Used for simulation and virtual subsystems virtual void setDefaultValues(CParameterAccessContext& parameterAccessContext) const; @@ -115,9 +120,6 @@ private: void getBelongingDomains(list<const CConfigurableDomain*>& configurableDomainList) const; void listDomains(const list<const CConfigurableDomain*>& configurableDomainList, string& strResult, bool bVertical) const; - // Belonging subsystem - virtual const CSubsystem* getBelongingSubsystem() const; - // Check parent is still of current type (by structure knowledge) bool isOfConfigurableElementType(const CElement* pParent) const; diff --git a/parameter/Element.cpp b/parameter/Element.cpp index 50c0774..4e939c0 100644 --- a/parameter/Element.cpp +++ b/parameter/Element.cpp @@ -212,7 +212,7 @@ bool CElement::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& se if (!pChild) { - elementSerializingContext.setError("XML Path not found: " + xmlElement.getPath()); + elementSerializingContext.setError("Unable to handle XML element: " + childElement.getPath()); return false; } diff --git a/parameter/ElementLocator.cpp b/parameter/ElementLocator.cpp index 71ed5ad..b70e23c 100644 --- a/parameter/ElementLocator.cpp +++ b/parameter/ElementLocator.cpp @@ -35,7 +35,6 @@ CElementLocator::CElementLocator(CElement* pSubRootElement, bool bStrict) : _pSu { } - // Locate element bool CElementLocator::locate(const string& strPath, CElement** ppElement, string& strError) { diff --git a/parameter/EnumParameterType.cpp b/parameter/EnumParameterType.cpp index f59c7ba..87cefcd 100644 --- a/parameter/EnumParameterType.cpp +++ b/parameter/EnumParameterType.cpp @@ -97,7 +97,8 @@ bool CEnumParameterType::fromXml(const CXmlElement& xmlElement, CXmlSerializingC return true; } -bool CEnumParameterType::asInteger(const string& strValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const +// Conversion (tuning) +bool CEnumParameterType::toBlackboard(const string& strValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const { int32_t iData; @@ -141,7 +142,7 @@ bool CEnumParameterType::asInteger(const string& strValue, uint32_t& uiValue, CP return true; } -void CEnumParameterType::asString(const uint32_t& uiValue, string& strValue, CParameterAccessContext& parameterAccessContext) const +bool CEnumParameterType::fromBlackboard(string& strValue, const uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const { // Take care of format if (parameterAccessContext.valueSpaceIsRaw()) { @@ -179,6 +180,35 @@ void CEnumParameterType::asString(const uint32_t& uiValue, string& strValue, CPa // Literal display requested (should succeed) getLiteral(iValue, strValue); } + return true; +} + +// Value access +bool CEnumParameterType::toBlackboard(int32_t iUserValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const +{ + if (!isValid(iUserValue)) { + + parameterAccessContext.setError("Invalid value"); + + return false; + } + uiValue = iUserValue; + + return true; +} + +bool CEnumParameterType::fromBlackboard(int32_t& iUserValue, uint32_t uiValue, CParameterAccessContext& parameterAccessContext) const +{ + (void)parameterAccessContext; + + int32_t iValue = uiValue; + + // Sign extend + signExtend(iValue); + + iUserValue = iValue; + + return true; } // Default value handling (simulation only) diff --git a/parameter/EnumParameterType.h b/parameter/EnumParameterType.h index f6d546f..9ef6343 100644 --- a/parameter/EnumParameterType.h +++ b/parameter/EnumParameterType.h @@ -51,9 +51,13 @@ public: // From IXmlSink virtual bool fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext); - // Conversion - virtual bool asInteger(const string& strValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const; - virtual void asString(const uint32_t& uiValue, string& strValue, CParameterAccessContext& parameterAccessContext) const; + /// Conversion + // String + virtual bool toBlackboard(const string& strValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const; + virtual bool fromBlackboard(string& strValue, const uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const; + // Integer + virtual bool toBlackboard(int32_t iUserValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const; + virtual bool fromBlackboard(int32_t& iUserValue, uint32_t uiValue, CParameterAccessContext& parameterAccessContext) const; // Default value handling (simulation only) virtual uint32_t getDefaultValue() const; 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); +} diff --git a/parameter/FixedPointParameterType.h b/parameter/FixedPointParameterType.h index d4e13d4..4dcf85f 100644 --- a/parameter/FixedPointParameterType.h +++ b/parameter/FixedPointParameterType.h @@ -44,9 +44,13 @@ public: // Value space handling for configuration import virtual void handleValueSpaceAttribute(CXmlElement& xmlConfigurableElementSettingsElement, CConfigurationAccessContext& configurationAccessContext) const; - // Conversion - virtual bool asInteger(const string& strValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const; - virtual void asString(const uint32_t& uiValue, string& strValue, CParameterAccessContext& parameterAccessContext) const; + /// Conversion + // String + virtual bool toBlackboard(const string& strValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const; + virtual bool fromBlackboard(string& strValue, const uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const; + // Double + virtual bool toBlackboard(double dUserValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const; + virtual bool fromBlackboard(double& dUserValue, uint32_t uiValue, CParameterAccessContext& parameterAccessContext) const; // Element properties virtual void showProperties(string& strResult) const; @@ -60,6 +64,9 @@ private: string getOutOfRangeError(const string& strValue, bool bRawValueSpace, bool bHexaValue) const; // Check data is consistent with available range, with respect to its sign bool isConsistent(uint32_t uiData) const; + // Data conversion + int32_t asInteger(double dValue) const; + double asDouble(int32_t iValue) const; // Integral part in Q notation uint32_t _uiIntegral; diff --git a/parameter/InstanceConfigurableElement.cpp b/parameter/InstanceConfigurableElement.cpp index 6d6526e..8720fef 100644 --- a/parameter/InstanceConfigurableElement.cpp +++ b/parameter/InstanceConfigurableElement.cpp @@ -112,6 +112,18 @@ void CInstanceConfigurableElement::showProperties(string& strResult) const _pTypeElement->showProperties(strResult); } +// Scalar or Array? +bool CInstanceConfigurableElement::isScalar() const +{ + return _pTypeElement->isScalar(); +} + +// Array Length +uint32_t CInstanceConfigurableElement::getArrayLength() const +{ + return _pTypeElement->getArrayLength(); +} + // Sync to HW void CInstanceConfigurableElement::setSyncer(ISyncer* pSyncer) { diff --git a/parameter/InstanceConfigurableElement.h b/parameter/InstanceConfigurableElement.h index 0604a69..a98c3b9 100644 --- a/parameter/InstanceConfigurableElement.h +++ b/parameter/InstanceConfigurableElement.h @@ -72,6 +72,12 @@ public: // Element properties virtual void showProperties(string& strResult) const; + + // Scalar or Array? + bool isScalar() const; + + // Array Length + uint32_t getArrayLength() const; protected: // Syncer virtual ISyncer* getSyncer() const; diff --git a/parameter/IntegerParameterType.cpp b/parameter/IntegerParameterType.cpp index cdbb7a5..71941c2 100644 --- a/parameter/IntegerParameterType.cpp +++ b/parameter/IntegerParameterType.cpp @@ -113,7 +113,7 @@ bool CIntegerParameterType::fromXml(const CXmlElement& xmlElement, CXmlSerializi _uiMax = xmlElement.getAttributeInteger("Max"); } else { - _uiMax = -1L >> (8 * sizeof(uint32_t) - uiSizeInBits); + _uiMax = (uint32_t)-1L >> (8 * sizeof(uint32_t) - uiSizeInBits); } } @@ -121,7 +121,8 @@ bool CIntegerParameterType::fromXml(const CXmlElement& xmlElement, CXmlSerializi return base::fromXml(xmlElement, serializingContext); } -bool CIntegerParameterType::asInteger(const string& strValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const +// Conversion (tuning) +bool CIntegerParameterType::toBlackboard(const string& strValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const { // Hexa bool bValueProvidedAsHexa = !strValue.compare(0, 2, "0x"); @@ -162,7 +163,7 @@ bool CIntegerParameterType::asInteger(const string& strValue, uint32_t& uiValue, return true; } -void CIntegerParameterType::asString(const uint32_t& uiValue, string& strValue, CParameterAccessContext& parameterAccessContext) const +bool CIntegerParameterType::fromBlackboard(string& strValue, const uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const { // Check consistency assert(isEncodable(uiValue)); @@ -192,6 +193,82 @@ void CIntegerParameterType::asString(const uint32_t& uiValue, string& strValue, } strValue = strStream.str(); + + return true; +} + +// Value access +// Integer +bool CIntegerParameterType::toBlackboard(uint32_t uiUserValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const +{ + if (_bSigned) { + + parameterAccessContext.setError("Parameter is signed"); + + return false; + } + if (uiUserValue < _uiMin || uiUserValue > _uiMax) { + + parameterAccessContext.setError("Value out of range"); + + return false; + } + // Do assign + uiValue = uiUserValue; + + return true; +} + +bool CIntegerParameterType::fromBlackboard(uint32_t& uiUserValue, uint32_t uiValue, CParameterAccessContext& parameterAccessContext) const +{ + if (_bSigned) { + + parameterAccessContext.setError("Parameter is signed"); + + return false; + } + uiUserValue = uiValue; + + return true; +} + +// Signed Integer +bool CIntegerParameterType::toBlackboard(int32_t iUserValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const +{ + if (!_bSigned) { + + parameterAccessContext.setError("Parameter is unsigned"); + + return false; + } + if (iUserValue < (int32_t)_uiMin || iUserValue > (int32_t)_uiMax) { + + parameterAccessContext.setError("Value out of range"); + + return false; + } + // Do assign + uiValue = iUserValue; + + return true; +} + +bool CIntegerParameterType::fromBlackboard(int32_t& iUserValue, uint32_t uiValue, CParameterAccessContext& parameterAccessContext) const +{ + if (!_bSigned) { + + parameterAccessContext.setError("Parameter is unsigned"); + + return false; + } + int32_t iValue = uiValue; + + // Sign extend + signExtend(iValue); + + iUserValue = iValue; + + return true; } // Default value handling (simulation only) diff --git a/parameter/IntegerParameterType.h b/parameter/IntegerParameterType.h index 50a7f91..ddd6e79 100644 --- a/parameter/IntegerParameterType.h +++ b/parameter/IntegerParameterType.h @@ -40,9 +40,16 @@ public: // From IXmlSink virtual bool fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext); - // Conversion - virtual bool asInteger(const string& strValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const; - virtual void asString(const uint32_t& uiValue, string& strValue, CParameterAccessContext& parameterAccessContext) const; + /// Conversion + // String + virtual bool toBlackboard(const string& strValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const; + virtual bool fromBlackboard(string& strValue, const uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const; + // Integer + virtual bool toBlackboard(uint32_t uiUserValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const; + virtual bool fromBlackboard(uint32_t& uiUserValue, uint32_t uiValue, CParameterAccessContext& parameterAccessContext) const; + // Signed Integer + virtual bool toBlackboard(int32_t iUserValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const; + virtual bool fromBlackboard(int32_t& iUserValue, uint32_t uiValue, CParameterAccessContext& parameterAccessContext) const; // Default value handling (simulation only) virtual uint32_t getDefaultValue() const; diff --git a/parameter/Parameter.cpp b/parameter/Parameter.cpp index 1770d9a..2fb6b70 100644 --- a/parameter/Parameter.cpp +++ b/parameter/Parameter.cpp @@ -55,7 +55,6 @@ bool CParameter::serializeXmlSettings(CXmlElement& xmlConfigurationSettingsEleme return base::serializeXmlSettings(xmlConfigurationSettingsElementContent, configurationAccessContext); } - // Value space handling for configuration import void CParameter::handleValueSpaceAttribute(CXmlElement& xmlConfigurableElementSettingsElement, CConfigurationAccessContext& configurationAccessContext) const { @@ -86,16 +85,79 @@ void CParameter::setDefaultValues(CParameterAccessContext& parameterAccessContex pBlackboard->writeInteger(&uiDefaultValue, getSize(), getOffset(), parameterAccessContext.isBigEndianSubsystem()); } -// Actual parameter access +/// Actual parameter access +// String access bool CParameter::doSetValue(const string& strValue, uint32_t uiOffset, CParameterAccessContext& parameterAccessContext) const { + return doSet(strValue, uiOffset, parameterAccessContext); +} + +void CParameter::doGetValue(string& strValue, uint32_t uiOffset, CParameterAccessContext& parameterAccessContext) const +{ + doGet(strValue, uiOffset, parameterAccessContext); +} + +// Boolean access +bool CParameter::accessAsBoolean(bool& bValue, bool bSet, CParameterAccessContext& parameterAccessContext) const +{ + return doAccess(bValue, bSet, parameterAccessContext); +} + +// Integer Access +bool CParameter::accessAsInteger(uint32_t& uiValue, bool bSet, CParameterAccessContext& parameterAccessContext) const +{ + return doAccess(uiValue, bSet, parameterAccessContext); +} + +// Signed Integer Access +bool CParameter::accessAsSignedInteger(int32_t& iValue, bool bSet, CParameterAccessContext& parameterAccessContext) const +{ + return doAccess(iValue, bSet, parameterAccessContext); +} + +// Double Access +bool CParameter::accessAsDouble(double& dValue, bool bSet, CParameterAccessContext& parameterAccessContext) const +{ + return doAccess(dValue, bSet, parameterAccessContext); +} + +// Generic Access +template <typename type> +bool CParameter::doAccess(type& value, bool bSet, CParameterAccessContext& parameterAccessContext) const +{ + bool bSuccess; + + if (bSet) { + + if (doSet(value, getOffset(), parameterAccessContext)) { + + // Synchronize + bSuccess = sync(parameterAccessContext); + } else { + + bSuccess = false; + } + } else { + + bSuccess = doGet(value, getOffset(), parameterAccessContext); + } + if (!bSuccess) { + + // Append parameter path to error + parameterAccessContext.appendToError(" " + getPath()); + } + return bSuccess; +} + +template <typename type> +bool CParameter::doSet(type value, uint32_t uiOffset, CParameterAccessContext& parameterAccessContext) const +{ uint32_t uiData; - if (!static_cast<const CParameterType*>(getTypeElement())->asInteger(strValue, uiData, parameterAccessContext)) { + if (!static_cast<const CParameterType*>(getTypeElement())->toBlackboard(value, uiData, parameterAccessContext)) { return false; } - // Write blackboard CParameterBlackboard* pBlackboard = parameterAccessContext.getParameterBlackboard(); @@ -105,7 +167,8 @@ bool CParameter::doSetValue(const string& strValue, uint32_t uiOffset, CParamete return true; } -void CParameter::doGetValue(string& strValue, uint32_t uiOffset, CParameterAccessContext& parameterAccessContext) const +template <typename type> +bool CParameter::doGet(type& value, uint32_t uiOffset, CParameterAccessContext& parameterAccessContext) const { uint32_t uiData = 0; @@ -115,6 +178,5 @@ void CParameter::doGetValue(string& strValue, uint32_t uiOffset, CParameterAcces // Beware this code works on little endian architectures only! pBlackboard->readInteger(&uiData, getSize(), uiOffset, parameterAccessContext.isBigEndianSubsystem()); - static_cast<const CParameterType*>(getTypeElement())->asString(uiData, strValue, parameterAccessContext); + return static_cast<const CParameterType*>(getTypeElement())->fromBlackboard(value, uiData, parameterAccessContext); } - diff --git a/parameter/Parameter.h b/parameter/Parameter.h index 175836c..25a7a5a 100644 --- a/parameter/Parameter.h +++ b/parameter/Parameter.h @@ -47,6 +47,18 @@ public: // XML configuration settings parsing/composing virtual bool serializeXmlSettings(CXmlElement& xmlConfigurationSettingsElementContent, CConfigurationAccessContext& configurationAccessContext) const; + + // Boolean access + virtual bool accessAsBoolean(bool& bValue, bool bSet, CParameterAccessContext& parameterAccessContext) const; + + // Integer Access + virtual bool accessAsInteger(uint32_t& uiValue, bool bSet, CParameterAccessContext& parameterAccessContext) const; + + // Signed Integer Access + virtual bool accessAsSignedInteger(int32_t& iValue, bool bSet, CParameterAccessContext& parameterAccessContext) const; + + // Double Access + virtual bool accessAsDouble(double& dValue, bool bSet, CParameterAccessContext& parameterAccessContext) const; protected: // Used for simulation and virtual subsystems virtual void setDefaultValues(CParameterAccessContext& parameterAccessContext) const; @@ -60,4 +72,12 @@ protected: // Size uint32_t getSize() const; +private: + // Generic Access + template <typename type> + bool doAccess(type& value, bool bSet, CParameterAccessContext& parameterAccessContext) const; + template <typename type> + bool doSet(type value, uint32_t uiOffset, CParameterAccessContext& parameterAccessContext) const; + template <typename type> + bool doGet(type& value, uint32_t uiOffset, CParameterAccessContext& parameterAccessContext) const; }; diff --git a/parameter/ParameterAccessContext.cpp b/parameter/ParameterAccessContext.cpp index 769565a..cc0506d 100644 --- a/parameter/ParameterAccessContext.cpp +++ b/parameter/ParameterAccessContext.cpp @@ -32,16 +32,22 @@ #define base CErrorContext -CParameterAccessContext::CParameterAccessContext(string& strError, CParameterBlackboard* pParameterBlackboard, bool bValueSpaceIsRaw, bool bOutputRawFormatIsHex) : - base(strError), _pParameterBlackboard(pParameterBlackboard), +CParameterAccessContext::CParameterAccessContext(string& strError, CParameterBlackboard* pParameterBlackboard, bool bValueSpaceIsRaw, bool bOutputRawFormatIsHex) + : base(strError), _pParameterBlackboard(pParameterBlackboard), _bValueSpaceIsRaw(bValueSpaceIsRaw), _bOutputRawFormatIsHex(bOutputRawFormatIsHex), - _bBigEndianSubsystem(false), _bAutoSync(true), _bDynamicAccess(false) + _bBigEndianSubsystem(false), _bAutoSync(true) { } -CParameterAccessContext::CParameterAccessContext(string& strError) : - base(strError), _pParameterBlackboard(NULL), _bValueSpaceIsRaw(false), - _bOutputRawFormatIsHex(false), _bBigEndianSubsystem(false), _bAutoSync(true), _bDynamicAccess(false) +CParameterAccessContext::CParameterAccessContext(string& strError, bool bBigEndianSubsystem, CParameterBlackboard* pParameterBlackboard) + : base(strError), _pParameterBlackboard(pParameterBlackboard), _bValueSpaceIsRaw(false), + _bOutputRawFormatIsHex(false), _bBigEndianSubsystem(bBigEndianSubsystem), _bAutoSync(true) +{ +} + +CParameterAccessContext::CParameterAccessContext(string& strError) + : base(strError), _pParameterBlackboard(NULL), _bValueSpaceIsRaw(false), + _bOutputRawFormatIsHex(false), _bBigEndianSubsystem(false), _bAutoSync(true) { } @@ -97,16 +103,5 @@ void CParameterAccessContext::setAutoSync(bool bAutoSync) bool CParameterAccessContext::getAutoSync() const { - return _bAutoSync || _bDynamicAccess; -} - -// Dynamic access -void CParameterAccessContext::setDynamicAccess(bool bDynamicAccess) -{ - _bDynamicAccess = bDynamicAccess; -} - -bool CParameterAccessContext::isDynamicAccess() const -{ - return _bDynamicAccess; + return _bAutoSync; } diff --git a/parameter/ParameterAccessContext.h b/parameter/ParameterAccessContext.h index 11c0fdc..cf4c5bc 100644 --- a/parameter/ParameterAccessContext.h +++ b/parameter/ParameterAccessContext.h @@ -38,6 +38,7 @@ class CParameterAccessContext : public CErrorContext { public: CParameterAccessContext(string& strError, CParameterBlackboard* pParameterBlackboard, bool bValueSpaceIsRaw, bool bOutputRawFormatIsHex = false); + CParameterAccessContext(string& strError, bool bBigEndianSubsystem, CParameterBlackboard* pParameterBlackboard); CParameterAccessContext(string& strError); // ParameterBlackboard @@ -60,10 +61,6 @@ public: void setAutoSync(bool bAutoSync); bool getAutoSync() const; - // Dynamic access - void setDynamicAccess(bool bDynamicAccess); - bool isDynamicAccess() const; - private: // Blackboard CParameterBlackboard* _pParameterBlackboard; @@ -75,7 +72,5 @@ private: bool _bBigEndianSubsystem; // Automatic synchronization to HW bool _bAutoSync; - // Dynamic access - bool _bDynamicAccess; }; diff --git a/parameter/ParameterHandle.cpp b/parameter/ParameterHandle.cpp new file mode 100644 index 0000000..85889a9 --- /dev/null +++ b/parameter/ParameterHandle.cpp @@ -0,0 +1,516 @@ +/* <auto_header> + * <FILENAME> + * + * INTEL CONFIDENTIAL + * Copyright © 2011 Intel + * Corporation All Rights Reserved. + * + * The source code contained or described herein and all documents related to + * the source code ("Material") are owned by Intel Corporation or its suppliers + * or licensors. Title to the Material remains with Intel Corporation or its + * suppliers and licensors. The Material contains trade secrets and proprietary + * and confidential information of Intel or its suppliers and licensors. The + * Material is protected by worldwide copyright and trade secret laws and + * treaty provisions. No part of the Material may be used, copied, reproduced, + * modified, published, uploaded, posted, transmitted, distributed, or + * disclosed in any way without Intel’s prior express written permission. + * + * No license under any patent, copyright, trade secret or other intellectual + * property right is granted to or conferred upon you by disclosure or delivery + * of the Materials, either expressly, by implication, inducement, estoppel or + * otherwise. Any license under such intellectual property rights must be + * express and approved by Intel in writing. + * + * AUTHOR: Patrick Benavoli (patrickx.benavoli@intel.com) + * CREATED: 2011-06-01 + * UPDATED: 2011-07-27 + * + * + * </auto_header> + */ +#include "ParameterHandle.h" +#include "ParameterAccessContext.h" +#include "BaseParameter.h" +#include "Subsystem.h" +#include <assert.h> +#include "ParameterMgr.h" +#include "AutoLock.h" + +CParameterHandle::CParameterHandle(const CBaseParameter* pParameter, CParameterMgr* pParameterMgr) + : _pBaseParameter(pParameter), _pParameterMgr(pParameterMgr), _bBigEndianSubsystem(pParameter->getBelongingSubsystem()->isBigEndian()) +{ +} + +// Parameter features +bool CParameterHandle::isRogue() const +{ + return _pBaseParameter->isRogue(); +} + +bool CParameterHandle::isArray() const +{ + return !_pBaseParameter->isScalar(); +} + +// Array Length +uint32_t CParameterHandle::getArrayLength() const +{ + return _pBaseParameter->getArrayLength(); +} + +// Parameter path +string CParameterHandle::getPath() const +{ + return _pBaseParameter->getPath(); +} + +// Parameter kind +string CParameterHandle::getKind() const +{ + return _pBaseParameter->getKind(); +} + +// Boolean access +bool CParameterHandle::setAsBoolean(bool bValue, string& strError) +{ + // Check operation validity + if (!checkAccessValidity(true, 0, strError)) { + + return false; + } + // Ensure we're safe against blackboard foreign access + CAutoLock autoLock(_pParameterMgr->getBlackboardMutex()); + + // When in tuning mode, silently skip the request + if (_pParameterMgr->tuningModeOn()) { + + return true; + } + + // Define access context + CParameterAccessContext parameterAccessContext(strError, _bBigEndianSubsystem, _pParameterMgr->getParameterBlackboard()); + + return _pBaseParameter->accessAsBoolean(bValue, true, parameterAccessContext); +} + +bool CParameterHandle::getAsBoolean(bool bValue, string& strError) const +{ + // Check operation validity + if (!checkAccessValidity(false, 0, strError)) { + + return false; + } + // Ensure we're safe against blackboard foreign access + CAutoLock autoLock(_pParameterMgr->getBlackboardMutex()); + + // Define access context + CParameterAccessContext parameterAccessContext(strError, _bBigEndianSubsystem, _pParameterMgr->getParameterBlackboard()); + + return _pBaseParameter->accessAsBoolean(bValue, false, parameterAccessContext); +} + +bool CParameterHandle::setAsBooleanArray(const vector<bool>& abValues, string& strError) +{ + // Check operation validity + if (!checkAccessValidity(true, abValues.size(), strError)) { + + return false; + } + // Ensure we're safe against blackboard foreign access + CAutoLock autoLock(_pParameterMgr->getBlackboardMutex()); + + // When in tuning mode, silently skip the request + if (_pParameterMgr->tuningModeOn()) { + + return true; + } + + // Define access context + CParameterAccessContext parameterAccessContext(strError, _bBigEndianSubsystem, _pParameterMgr->getParameterBlackboard()); + + // Copy values for type adaptation + vector<bool> abUserValues = abValues; + + return _pBaseParameter->accessAsBooleanArray(abUserValues, true, parameterAccessContext); +} + +bool CParameterHandle::getAsBooleanArray(vector<bool>& abValues, string& strError) const +{ + // Check operation validity + if (!checkAccessValidity(false, -1, strError)) { + + return false; + } + // Ensure we're safe against blackboard foreign access + CAutoLock autoLock(_pParameterMgr->getBlackboardMutex()); + + // Define access context + CParameterAccessContext parameterAccessContext(strError, _bBigEndianSubsystem, _pParameterMgr->getParameterBlackboard()); + + return _pBaseParameter->accessAsBooleanArray(abValues, false, parameterAccessContext); +} + +// Integer Access +bool CParameterHandle::setAsInteger(uint32_t uiValue, string& strError) +{ + // Check operation validity + if (!checkAccessValidity(true, 0, strError)) { + + return false; + } + // Ensure we're safe against blackboard foreign access + CAutoLock autoLock(_pParameterMgr->getBlackboardMutex()); + + // When in tuning mode, silently skip the request + if (_pParameterMgr->tuningModeOn()) { + + return true; + } + + // Define access context + CParameterAccessContext parameterAccessContext(strError, _bBigEndianSubsystem, _pParameterMgr->getParameterBlackboard()); + + return _pBaseParameter->accessAsInteger(uiValue, true, parameterAccessContext); +} + +bool CParameterHandle::getAsInteger(uint32_t& uiValue, string& strError) const +{ + // Check operation validity + if (!checkAccessValidity(false, 0, strError)) { + + return false; + } + // Ensure we're safe against blackboard foreign access + CAutoLock autoLock(_pParameterMgr->getBlackboardMutex()); + + // Define access context + CParameterAccessContext parameterAccessContext(strError, _bBigEndianSubsystem, _pParameterMgr->getParameterBlackboard()); + + return _pBaseParameter->accessAsInteger(uiValue, false, parameterAccessContext); +} + +bool CParameterHandle::setAsIntegerArray(const vector<uint32_t>& auiValues, string& strError) +{ + // Check operation validity + if (!checkAccessValidity(true, auiValues.size(), strError)) { + + return false; + } + // Ensure we're safe against blackboard foreign access + CAutoLock autoLock(_pParameterMgr->getBlackboardMutex()); + + // When in tuning mode, silently skip the request + if (_pParameterMgr->tuningModeOn()) { + + return true; + } + + // Define access context + CParameterAccessContext parameterAccessContext(strError, _bBigEndianSubsystem, _pParameterMgr->getParameterBlackboard()); + + // Copy values for type adaptation + vector<uint32_t> auiUserValues = auiValues; + + return _pBaseParameter->accessAsIntegerArray(auiUserValues, true, parameterAccessContext); +} + +bool CParameterHandle::getAsIntegerArray(vector<uint32_t>& auiValues, string& strError) const +{ + // Check operation validity + if (!checkAccessValidity(false, -1, strError)) { + + return false; + } + // Ensure we're safe against blackboard foreign access + CAutoLock autoLock(_pParameterMgr->getBlackboardMutex()); + + // Define access context + CParameterAccessContext parameterAccessContext(strError, _bBigEndianSubsystem, _pParameterMgr->getParameterBlackboard()); + + return _pBaseParameter->accessAsIntegerArray(auiValues, false, parameterAccessContext); +} + +// Signed Integer Access +bool CParameterHandle::setAsSignedInteger(int32_t iValue, string& strError) +{ + // Check operation validity + if (!checkAccessValidity(true, 0, strError)) { + + return false; + } + // Ensure we're safe against blackboard foreign access + CAutoLock autoLock(_pParameterMgr->getBlackboardMutex()); + + // When in tuning mode, silently skip the request + if (_pParameterMgr->tuningModeOn()) { + + return true; + } + + // Define access context + CParameterAccessContext parameterAccessContext(strError, _bBigEndianSubsystem, _pParameterMgr->getParameterBlackboard()); + + return _pBaseParameter->accessAsSignedInteger(iValue, true, parameterAccessContext); +} + +bool CParameterHandle::getAsSignedInteger(int32_t& iValue, string& strError) const +{ + // Check operation validity + if (!checkAccessValidity(false, 0, strError)) { + + return false; + } + // Ensure we're safe against blackboard foreign access + CAutoLock autoLock(_pParameterMgr->getBlackboardMutex()); + + // Define access context + CParameterAccessContext parameterAccessContext(strError, _bBigEndianSubsystem, _pParameterMgr->getParameterBlackboard()); + + return _pBaseParameter->accessAsSignedInteger(iValue, false, parameterAccessContext); +} + +bool CParameterHandle::setAsSignedIntegerArray(const vector<int32_t>& aiValues, string& strError) +{ + // Check operation validity + if (!checkAccessValidity(true, aiValues.size(), strError)) { + + return false; + } + // Ensure we're safe against blackboard foreign access + CAutoLock autoLock(_pParameterMgr->getBlackboardMutex()); + + // When in tuning mode, silently skip the request + if (_pParameterMgr->tuningModeOn()) { + + return true; + } + + // Define access context + CParameterAccessContext parameterAccessContext(strError, _bBigEndianSubsystem, _pParameterMgr->getParameterBlackboard()); + + // Copy values for type adaptation + vector<int32_t> aiUserValues = aiValues; + + return _pBaseParameter->accessAsSignedIntegerArray(aiUserValues, true, parameterAccessContext); +} + +bool CParameterHandle::getAsSignedIntegerArray(vector<int32_t>& aiValues, string& strError) const +{ + // Check operation validity + if (!checkAccessValidity(false, -1, strError)) { + + return false; + } + // Ensure we're safe against blackboard foreign access + CAutoLock autoLock(_pParameterMgr->getBlackboardMutex()); + + // Define access context + CParameterAccessContext parameterAccessContext(strError, _bBigEndianSubsystem, _pParameterMgr->getParameterBlackboard()); + + return _pBaseParameter->accessAsSignedIntegerArray(aiValues, false, parameterAccessContext); +} + +// Double Access +bool CParameterHandle::setAsDouble(double dValue, string& strError) +{ + // Check operation validity + if (!checkAccessValidity(true, 0, strError)) { + + return false; + } + // Ensure we're safe against blackboard foreign access + CAutoLock autoLock(_pParameterMgr->getBlackboardMutex()); + + // When in tuning mode, silently skip the request + if (_pParameterMgr->tuningModeOn()) { + + return true; + } + + // Define access context + CParameterAccessContext parameterAccessContext(strError, _bBigEndianSubsystem, _pParameterMgr->getParameterBlackboard()); + + return _pBaseParameter->accessAsDouble(dValue, true, parameterAccessContext); +} + +bool CParameterHandle::getAsDouble(double& dValue, string& strError) const +{ + // Check operation validity + if (!checkAccessValidity(false, 0, strError)) { + + return false; + } + // Ensure we're safe against blackboard foreign access + CAutoLock autoLock(_pParameterMgr->getBlackboardMutex()); + + // Define access context + CParameterAccessContext parameterAccessContext(strError, _bBigEndianSubsystem, _pParameterMgr->getParameterBlackboard()); + + return _pBaseParameter->accessAsDouble(dValue, false, parameterAccessContext); +} + +bool CParameterHandle::setAsDoubleArray(const vector<double>& adValues, string& strError) +{ + // Check operation validity + if (!checkAccessValidity(true, adValues.size(), strError)) { + + return false; + } + // Ensure we're safe against blackboard foreign access + CAutoLock autoLock(_pParameterMgr->getBlackboardMutex()); + + // When in tuning mode, silently skip the request + if (_pParameterMgr->tuningModeOn()) { + + return true; + } + + // Define access context + CParameterAccessContext parameterAccessContext(strError, _bBigEndianSubsystem, _pParameterMgr->getParameterBlackboard()); + + // Copy values for type adaptation + vector<double> adUserValues = adValues; + + return _pBaseParameter->accessAsDoubleArray(adUserValues, true, parameterAccessContext); +} + +bool CParameterHandle::getAsDoubleArray(vector<double>& adValues, string& strError) const +{ + // Check operation validity + if (!checkAccessValidity(false, -1, strError)) { + + return false; + } + // Ensure we're safe against blackboard foreign access + CAutoLock autoLock(_pParameterMgr->getBlackboardMutex()); + + // Define access context + CParameterAccessContext parameterAccessContext(strError, _bBigEndianSubsystem, _pParameterMgr->getParameterBlackboard()); + + return _pBaseParameter->accessAsDoubleArray(adValues, false, parameterAccessContext); +} + +// String Access +bool CParameterHandle::setAsString(const string& strValue, string& strError) +{ + // Check operation validity + if (!checkAccessValidity(true, 0, strError)) { + + return false; + } + // Ensure we're safe against blackboard foreign access + CAutoLock autoLock(_pParameterMgr->getBlackboardMutex()); + + // When in tuning mode, silently skip the request + if (_pParameterMgr->tuningModeOn()) { + + return true; + } + + // Define access context + CParameterAccessContext parameterAccessContext(strError, _bBigEndianSubsystem, _pParameterMgr->getParameterBlackboard()); + + // Copy value for type adaptation + string strUserValue = strValue; + + return _pBaseParameter->accessAsString(strUserValue, true, parameterAccessContext); +} + +bool CParameterHandle::getAsString(string& strValue, string& strError) const +{ + // Check operation validity + if (!checkAccessValidity(false, 0, strError)) { + + return false; + } + // Ensure we're safe against blackboard foreign access + CAutoLock autoLock(_pParameterMgr->getBlackboardMutex()); + + // Define access context + CParameterAccessContext parameterAccessContext(strError, _bBigEndianSubsystem, _pParameterMgr->getParameterBlackboard()); + + return _pBaseParameter->accessAsString(strValue, false, parameterAccessContext); +} + +bool CParameterHandle::setAsStringArray(const vector<string>& astrValues, string& strError) +{ + // Check operation validity + if (!checkAccessValidity(true, astrValues.size(), strError)) { + + return false; + } + // Ensure we're safe against blackboard foreign access + CAutoLock autoLock(_pParameterMgr->getBlackboardMutex()); + + // When in tuning mode, silently skip the request + if (_pParameterMgr->tuningModeOn()) { + + return true; + } + + // Define access context + CParameterAccessContext parameterAccessContext(strError, _bBigEndianSubsystem, _pParameterMgr->getParameterBlackboard()); + + // Copy values for type adaptation + vector<string> astrUserValues = astrValues; + + return _pBaseParameter->accessAsStringArray(astrUserValues, true, parameterAccessContext); +} + +bool CParameterHandle::getAsStringArray(vector<string>& astrValues, string& strError) const +{ + // Check operation validity + if (!checkAccessValidity(false, -1, strError)) { + + return false; + } + // Ensure we're safe against blackboard foreign access + CAutoLock autoLock(_pParameterMgr->getBlackboardMutex()); + + // Define access context + CParameterAccessContext parameterAccessContext(strError, _bBigEndianSubsystem, _pParameterMgr->getParameterBlackboard()); + + return _pBaseParameter->accessAsStringArray(astrValues, false, parameterAccessContext); +} + +// Access validity +bool CParameterHandle::checkAccessValidity(bool bSet, uint32_t uiArrayLength, string& strError) const +{ + if (bSet && !isRogue()) { + + strError = "Parameter is not rogue: "; + + strError += getPath(); + + return false; + } + + if (uiArrayLength && !isArray()) { + + strError = "Parameter is scalar: "; + + strError += getPath(); + + return false; + } + + if (!uiArrayLength && isArray()) { + + strError = "Parameter is an array: "; + + strError += getPath(); + + return false; + } + + if (bSet && uiArrayLength && (uiArrayLength != getArrayLength())) { + + strError = "Array length mismatch: "; + + strError += getPath(); + + return false; + } + + return true; +} diff --git a/parameter/ParameterHandle.h b/parameter/ParameterHandle.h new file mode 100644 index 0000000..0e6660f --- /dev/null +++ b/parameter/ParameterHandle.h @@ -0,0 +1,86 @@ +/* ParameterHandle.h + ** + ** Copyright © 2011 Intel + ** + ** Licensed under the Apache License, Version 2.0 (the "License"); + ** you may not use this file except in compliance with the License. + ** You may obtain a copy of the License at + ** + ** http://www.apache.org/licenses/LICENSE-2.0 + ** + ** Unless required by applicable law or agreed to in writing, software + ** distributed under the License is distributed on an "AS IS" BASIS, + ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ** See the License for the specific language governing permissions and + ** limitations under the License. + ** + ** AUTHOR: Patrick Benavoli (patrickx.benavoli@intel.com) + ** CREATED: 2011-06-01 + ** UPDATED: 2011-07-27 + ** + */ +#pragma once + +#include <stdint.h> +#include <string> +#include <vector> + +class CBaseParameter; +class CParameterMgr; + +class CParameterHandle +{ +public: + CParameterHandle(const CBaseParameter* pParameter, CParameterMgr* pParameterMgr); + + // Parameter features + bool isRogue() const; + bool isArray() const; + // Array Length + uint32_t getArrayLength() const; // Returns 0 for scalar + // Parameter path + std::string getPath() const; + // Parameter kind + std::string getKind() const; + + // Boolean access + bool setAsBoolean(bool bValue, std::string& strError); + bool getAsBoolean(bool bValue, std::string& strError) const; + bool setAsBooleanArray(const std::vector<bool>& abValues, std::string& strError); + bool getAsBooleanArray(std::vector<bool>& abValues, std::string& strError) const; + + // Integer Access + bool setAsInteger(uint32_t uiValue, std::string& strError); + bool getAsInteger(uint32_t& uiValue, std::string& strError) const; + bool setAsIntegerArray(const std::vector<uint32_t>& auiValues, std::string& strError); + bool getAsIntegerArray(std::vector<uint32_t>& auiValues, std::string& strError) const; + + // Signed Integer Access + bool setAsSignedInteger(int32_t iValue, std::string& strError); + bool getAsSignedInteger(int32_t& iValue, std::string& strError) const; + bool setAsSignedIntegerArray(const std::vector<int32_t>& aiValues, std::string& strError); + bool getAsSignedIntegerArray(std::vector<int32_t>& aiValues, std::string& strError) const; + + // Double Access + bool setAsDouble(double dValue, std::string& strError); + bool getAsDouble(double& dValue, std::string& strError) const; + bool setAsDoubleArray(const std::vector<double>& adValues, std::string& strError); + bool getAsDoubleArray(std::vector<double>& adValues, std::string& strError) const; + + // String Access + bool setAsString(const std::string& strValue, std::string& strError); + bool getAsString(std::string& strValue, std::string& strError) const; + bool setAsStringArray(const std::vector<std::string>& astrValues, std::string& strError); + bool getAsStringArray(std::vector<std::string>& astrValues, std::string& strError) const; + +private: + // Access validity + bool checkAccessValidity(bool bSet, uint32_t uiArrayLength, std::string& strError) const; + + // Accessed parameter instance + const CBaseParameter* _pBaseParameter; + // Parameter Mgr + CParameterMgr* _pParameterMgr; + // Subsystem endianness + bool _bBigEndianSubsystem; +}; diff --git a/parameter/ParameterMgr.cpp b/parameter/ParameterMgr.cpp index 102d28b..1e1a562 100644 --- a/parameter/ParameterMgr.cpp +++ b/parameter/ParameterMgr.cpp @@ -75,6 +75,7 @@ #include <strings.h> #include <dlfcn.h> #include <assert.h> +#include "ParameterHandle.h" #define base CElement @@ -182,8 +183,8 @@ CParameterMgr::CParameterMgr(const string& strConfigurationFilePath) : _uiLogDepth(0) { // Tuning Mode Mutex - bzero(&_tuningModeMutex, sizeof(_tuningModeMutex)); - pthread_mutex_init(&_tuningModeMutex, NULL); + bzero(&_blackboardMutex, sizeof(_blackboardMutex)); + pthread_mutex_init(&_blackboardMutex, NULL); // Deal with children addChild(new CParameterFrameworkConfiguration); @@ -229,7 +230,7 @@ CParameterMgr::~CParameterMgr() delete _pElementLibrarySet; // Tuning Mode Mutex - pthread_mutex_destroy(&_tuningModeMutex); + pthread_mutex_destroy(&_blackboardMutex); } string CParameterMgr::getKind() const @@ -594,7 +595,7 @@ bool CParameterMgr::applyConfigurations(string& strError) CAutoLog autoLog(this, "Configuration application request"); // Lock state - CAutoLock autoLock(&_tuningModeMutex); + CAutoLock autoLock(&_blackboardMutex); if (!_bTuningModeIsOn) { @@ -611,16 +612,39 @@ bool CParameterMgr::applyConfigurations(string& strError) } // Dynamic parameter handling -bool CParameterMgr::setValue(const string& strPath, const string& strValue, bool bRawValueSpace, string& strError) +CParameterHandle* CParameterMgr::createParameterHandle(const string& strPath, string& strError) { - // Delegate to low level functionality - return doSetValue(strPath, strValue, bRawValueSpace, true, strError); -} + CPathNavigator pathNavigator(strPath); -bool CParameterMgr::getValue(const string& strPath, string& strValue, bool bRawValueSpace, bool bHexOutputRawFormat, string& strError) const -{ - // Delegate to low level functionality - return doGetValue(strPath, strValue, bRawValueSpace, bHexOutputRawFormat, true, strError); + // Nagivate through system class + if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) { + + return false; + } + + // Find element + const CElement* pElement = getConstSystemClass()->findDescendant(pathNavigator); + + if (!pElement) { + + strError = "Path not found"; + + return false; + } + + // Check found element is a parameter + const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pElement); + + if (!pConfigurableElement->isParameter()) { + + // Element is not parameter + strError = "Not a parameter"; + + return false; + } + + // Convert as parameter and return new handle + return new CParameterHandle(static_cast<const CBaseParameter*>(pElement), this); } /////////////////// Remote command parsers @@ -1103,7 +1127,7 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getParameterCommman { string strValue; - if (!getValue(remoteCommand.getArgument(0), strValue, strResult)) { + if (!accessValue(remoteCommand.getArgument(0), strValue, false, strResult)) { return CCommandHandler::EFailed; } @@ -1115,7 +1139,15 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getParameterCommman CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) { - return setValue(remoteCommand.getArgument(0), remoteCommand.packArguments(1, remoteCommand.getArgumentCount() - 1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed; + // Check tuning mode + if (!checkTuningModeOn(strResult)) { + + return CCommandHandler::EFailed; + } + // Get value to set + string strValue = remoteCommand.packArguments(1, remoteCommand.getArgumentCount() - 1); + + return accessValue(remoteCommand.getArgument(0), strValue, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed; } CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listBelongingDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) @@ -1217,22 +1249,24 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importSettingsCommm } // User set/get parameters -bool CParameterMgr::setValue(const string& strPath, const string& strValue, string& strError) +bool CParameterMgr::accessValue(const string& strPath, string& strValue, bool bSet, string& strError) { - // Check tuning mode - if (!checkTuningModeOn(strError)) { + // Lock state + CAutoLock autoLock(&_blackboardMutex); + + CPathNavigator pathNavigator(strPath); + + // Nagivate through system class + if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) { return false; } - // Delegate to low level functionality - return doSetValue(strPath, strValue, _bValueSpaceIsRaw, false, strError); -} + // Define context + CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex); -bool CParameterMgr::getValue(const string& strPath, string& strValue, string& strError) const -{ - // Delegate to low level functionality - return doGetValue(strPath, strValue, _bValueSpaceIsRaw, _bOutputRawFormatIsHex, false, strError); + // Do the get + return getConstSystemClass()->accessValue(pathNavigator, strValue, bSet, parameterAccessContext); } // Tuning mode @@ -1246,7 +1280,7 @@ bool CParameterMgr::setTuningMode(bool bOn, string& strError) return false; } // Lock state - CAutoLock autoLock(&_tuningModeMutex); + CAutoLock autoLock(&_blackboardMutex); // Warn domains about exiting tuning mode if (!bOn && _bTuningModeIsOn) { @@ -1639,48 +1673,16 @@ bool CParameterMgr::checkTuningModeOn(string& strError) const return true; } -// Parameter access -bool CParameterMgr::doSetValue(const string& strPath, const string& strValue, bool bRawValueSpace, bool bDynamicAccess, string& strError) +// Tuning mutex dynamic parameter handling +pthread_mutex_t* CParameterMgr::getBlackboardMutex() { - CPathNavigator pathNavigator(strPath); - - // Nagivate through system class - if (!pathNavigator.navigateThrough(getSystemClass()->getName(), strError)) { - - return false; - } - - // Define context - CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, bRawValueSpace); - - // Set auto sync - parameterAccessContext.setAutoSync(_bAutoSyncOn); - - // Set dynamic access - parameterAccessContext.setDynamicAccess(bDynamicAccess); - - // Do the set - return getSystemClass()->setValue(pathNavigator, strValue, parameterAccessContext); + return &_blackboardMutex; } -bool CParameterMgr::doGetValue(const string& strPath, string& strValue, bool bRawValueSpace, bool bHexOutputRawFormat, bool bDynamicAccess, string& strError) const +// Blackboard reference (dynamic parameter handling) +CParameterBlackboard* CParameterMgr::getParameterBlackboard() { - CPathNavigator pathNavigator(strPath); - - // Nagivate through system class - if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) { - - return false; - } - - // Define context - CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, bRawValueSpace, bHexOutputRawFormat); - - // Set dynamic access - parameterAccessContext.setDynamicAccess(bDynamicAccess); - - // Do the get - return getConstSystemClass()->getValue(pathNavigator, strValue, parameterAccessContext); + return _pMainParameterBlackboard; } // Dynamic creation library feeding diff --git a/parameter/ParameterMgr.h b/parameter/ParameterMgr.h index c7bdcb6..08c777b 100644 --- a/parameter/ParameterMgr.h +++ b/parameter/ParameterMgr.h @@ -50,6 +50,7 @@ class CParameterBlackboard; class CConfigurableDomains; class IRemoteProcessorServerInterface; class CBackSynchronizer; +class CParameterHandle; class CParameterMgr : private CElement { @@ -64,9 +65,10 @@ class CParameterMgr : private CElement EParameterCreationLibrary, EParameterConfigurationLibrary }; - typedef TRemoteCommandHandlerTemplate<CParameterMgr> CCommandHandler; // Remote command parsers + typedef TRemoteCommandHandlerTemplate<CParameterMgr> CCommandHandler; + typedef CCommandHandler::CommandStatus (CParameterMgr::*RemoteCommandParser)(const IRemoteCommand& remoteCommand, string& strResult); // Parser descriptions @@ -79,9 +81,12 @@ class CParameterMgr : private CElement const char* _pcDescription; }; // Version - static const uint32_t guiEditionMajor = 0x1; - static const uint32_t guiEditionMinor = 0x1; + static const uint32_t guiEditionMajor = 0x2; + static const uint32_t guiEditionMinor = 0x0; static const uint32_t guiRevision = 0x0; + + // Parameter handle friendship + friend class CParameterHandle; public: // Logger interface class ILogger @@ -111,8 +116,7 @@ public: bool applyConfigurations(string& strError); // Dynamic parameter handling - bool setValue(const string& strPath, const string& strValue, bool bRawValueSpace, string& strError); - bool getValue(const string& strPath, string& strValue, bool bRawValueSpace, bool bHexOutputRawFormat, string& strError) const; + CParameterHandle* createParameterHandle(const string& strPath, string& strError); //////////// Tuning ///////////// // Tuning mode @@ -133,8 +137,7 @@ public: bool sync(string& strError); // User set/get parameters - bool setValue(const string& strPath, const string& strValue, string& strError); - bool getValue(const string& strPath, string& strValue, string& strError) const; + bool accessValue(const string& strPath, string& strValue, bool bSet, string& strError); ////////// Configuration/Domains handling ////////////// // Creation/Deletion @@ -242,8 +245,14 @@ private: // For tuning, check we're in tuning mode bool checkTuningModeOn(string& strError) const; + // Blackboard (dynamic parameter handling) + pthread_mutex_t* getBlackboardMutex(); + + // Blackboard reference (dynamic parameter handling) + CParameterBlackboard* getParameterBlackboard(); + // Parameter access - bool doSetValue(const string& strPath, const string& strValue, bool bRawValueSpace, bool bDynamicAccess, string& strError); + bool doSetValue(const string& strPath, const string& strValue, bool bRawValueSpace, bool bDynamicAccess, string& strError) const; bool doGetValue(const string& strPath, string& strValue, bool bRawValueSpace, bool bHexOutputRawFormat, bool bDynamicAccess, string& strError) const; // Framework global configuration loading @@ -328,8 +337,8 @@ private: // Maximum command usage length uint32_t _uiMaxCommandUsageLength; - // Tuning mode mutex - pthread_mutex_t _tuningModeMutex; + // Blackboard access mutex + pthread_mutex_t _blackboardMutex; // Logging ILogger* _pLogger; diff --git a/parameter/ParameterMgrPlatformConnector.cpp b/parameter/ParameterMgrPlatformConnector.cpp index 17d202c..d99568f 100644 --- a/parameter/ParameterMgrPlatformConnector.cpp +++ b/parameter/ParameterMgrPlatformConnector.cpp @@ -78,14 +78,11 @@ bool CParameterMgrPlatformConnector::applyConfigurations(string& strError) } // Dynamic parameter handling -bool CParameterMgrPlatformConnector::setValue(const string& strPath, const string& strValue, string& strError, bool bRawValueSpace) +CParameterHandle* CParameterMgrPlatformConnector::createParameterHandle(const string& strPath, string& strError) const { - return _pParameterMgr->setValue(strPath, strValue, bRawValueSpace, strError); -} + assert(_bStarted); -bool CParameterMgrPlatformConnector::getValue(const string& strPath, string& strValue, string& strError, bool bRawValueSpace, bool bHexOutputRawFormat) const -{ - return _pParameterMgr->getValue(strPath, strValue, bRawValueSpace, bHexOutputRawFormat, strError); + return _pParameterMgr->createParameterHandle(strPath, strError); } // Logging diff --git a/parameter/ParameterMgrPlatformConnector.h b/parameter/ParameterMgrPlatformConnector.h index 14e408c..e121290 100644 --- a/parameter/ParameterMgrPlatformConnector.h +++ b/parameter/ParameterMgrPlatformConnector.h @@ -23,6 +23,7 @@ #include "SelectionCriterionTypeInterface.h" #include "SelectionCriterionInterface.h" +#include "ParameterHandle.h" class CParameterMgr; class CParameterMgrLogger; @@ -60,8 +61,9 @@ public: bool applyConfigurations(std::string& strError); // Dynamic parameter handling - bool setValue(const std::string& strPath, const std::string& strValue, std::string& strError, bool bRawValueSpace = false); - bool getValue(const std::string& strPath, std::string& strValue, std::string& strError, bool bRawValueSpace = false, bool bHexOutputRawFormat = false) const; + // Returned objects are owned by clients + // Must be cassed after successfull start + CParameterHandle* createParameterHandle(const std::string& strPath, std::string& strError) const; private: // Private logging diff --git a/parameter/ParameterType.cpp b/parameter/ParameterType.cpp index b22cde4..ffa8d76 100644 --- a/parameter/ParameterType.cpp +++ b/parameter/ParameterType.cpp @@ -31,6 +31,7 @@ #include "ParameterType.h" #include "Parameter.h" #include "ArrayParameter.h" +#include "ParameterAccessContext.h" #define base CTypeElement @@ -150,3 +151,98 @@ uint32_t CParameterType::makeEncodable(uint32_t uiData) const return uiData & uiMask; } +// Conversions (dynamic access) +// Value access +// Boolean +bool CParameterType::toBlackboard(bool bUserValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const +{ + (void)bUserValue; + (void)uiValue; + (void)parameterAccessContext; + + parameterAccessContext.setError("Unsupported conversion"); + + return false; +} + +bool CParameterType::fromBlackboard(bool& bUserValue, uint32_t uiValue, CParameterAccessContext& parameterAccessContext) const +{ + (void)bUserValue; + (void)uiValue; + (void)parameterAccessContext; + + parameterAccessContext.setError("Unsupported conversion"); + + return false; +} + +// Integer +bool CParameterType::toBlackboard(uint32_t uiUserValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const +{ + (void)uiUserValue; + (void)uiValue; + (void)parameterAccessContext; + + parameterAccessContext.setError("Unsupported conversion"); + + return false; +} + +bool CParameterType::fromBlackboard(uint32_t& uiUserValue, uint32_t uiValue, CParameterAccessContext& parameterAccessContext) const +{ + (void)uiUserValue; + (void)uiValue; + (void)parameterAccessContext; + + parameterAccessContext.setError("Unsupported conversion"); + + return false; +} + +// Signed Integer +bool CParameterType::toBlackboard(int32_t iUserValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const +{ + (void)iUserValue; + (void)uiValue; + (void)parameterAccessContext; + + parameterAccessContext.setError("Unsupported conversion"); + + return false; +} + +bool CParameterType::fromBlackboard(int32_t& iUserValue, uint32_t uiValue, CParameterAccessContext& parameterAccessContext) const +{ + (void)iUserValue; + (void)uiValue; + (void)parameterAccessContext; + + parameterAccessContext.setError("Unsupported conversion"); + + return false; +} + +// Double +bool CParameterType::toBlackboard(double dUserValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const +{ + (void)dUserValue; + (void)uiValue; + (void)parameterAccessContext; + + parameterAccessContext.setError("Unsupported conversion"); + + return false; +} + +bool CParameterType::fromBlackboard(double& dUserValue, uint32_t uiValue, CParameterAccessContext& parameterAccessContext) const +{ + (void)dUserValue; + (void)uiValue; + (void)parameterAccessContext; + + parameterAccessContext.setError("Unsupported conversion"); + + return false; +} + + diff --git a/parameter/ParameterType.h b/parameter/ParameterType.h index e8e67a5..37ba869 100644 --- a/parameter/ParameterType.h +++ b/parameter/ParameterType.h @@ -52,9 +52,22 @@ public: // From IXmlSink virtual bool fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext); - // Conversion - virtual bool asInteger(const string& strValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const = 0; - virtual void asString(const uint32_t& uiValue, string& strValue, CParameterAccessContext& parameterAccessContext) const = 0; + /// Conversions + // String + virtual bool toBlackboard(const string& strValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const = 0; + virtual bool fromBlackboard(string& strValue, const uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const = 0; + // Boolean + virtual bool toBlackboard(bool bUserValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const; + virtual bool fromBlackboard(bool& bUserValue, uint32_t uiValue, CParameterAccessContext& parameterAccessContext) const; + // Integer + virtual bool toBlackboard(uint32_t uiUserValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const; + virtual bool fromBlackboard(uint32_t& uiUserValue, uint32_t uiValue, CParameterAccessContext& parameterAccessContext) const; + // Signed Integer + virtual bool toBlackboard(int32_t iUserValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const; + virtual bool fromBlackboard(int32_t& iUserValue, uint32_t uiValue, CParameterAccessContext& parameterAccessContext) const; + // Double + virtual bool toBlackboard(double dUserValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const; + virtual bool fromBlackboard(double& dUserValue, uint32_t uiValue, CParameterAccessContext& parameterAccessContext) const; // XML Serialization value space handling // Value space handling for configuration import/export diff --git a/parameter/StringParameter.cpp b/parameter/StringParameter.cpp index 5d01f76..c9d4329 100644 --- a/parameter/StringParameter.cpp +++ b/parameter/StringParameter.cpp @@ -65,7 +65,7 @@ void CStringParameter::setDefaultValues(CParameterAccessContext& parameterAccess pBlackboard->writeString("", getOffset()); } -// Actual parameter access +// Actual parameter access (tuning) bool CStringParameter::doSetValue(const string& strValue, uint32_t uiOffset, CParameterAccessContext& parameterAccessContext) const { if (strValue.length() >= getSize()) { @@ -94,4 +94,3 @@ void CStringParameter::doGetValue(string& strValue, uint32_t uiOffset, CParamete strValue = pcValue; } - diff --git a/parameter/StringParameter.h b/parameter/StringParameter.h index f536ceb..453085b 100644 --- a/parameter/StringParameter.h +++ b/parameter/StringParameter.h @@ -48,7 +48,7 @@ protected: // Used for simulation and virtual subsystems virtual void setDefaultValues(CParameterAccessContext& parameterAccessContext) const; - // Actual value access + // Actual value access (tuning) virtual bool doSetValue(const string& strValue, uint32_t uiOffset, CParameterAccessContext& parameterAccessContext) const; virtual void doGetValue(string& strValue, uint32_t uiOffset, CParameterAccessContext& parameterAccessContext) const; diff --git a/parameter/Subsystem.cpp b/parameter/Subsystem.cpp index 5f09d6c..59b95c3 100644 --- a/parameter/Subsystem.cpp +++ b/parameter/Subsystem.cpp @@ -156,28 +156,20 @@ bool CSubsystem::mapSubsystemElements(string& strError) } // Parameter access -bool CSubsystem::setValue(CPathNavigator& pathNavigator, const string& strValue, CParameterAccessContext& parameterContext) const +bool CSubsystem::accessValue(CPathNavigator& pathNavigator, string& strValue, bool bSet, CParameterAccessContext& parameterAccessContext) const { // Deal with Endianness - parameterContext.setBigEndianSubsystem(_bBigEndian); - - return base::setValue(pathNavigator, strValue, parameterContext); -} - -bool CSubsystem::getValue(CPathNavigator& pathNavigator, string& strValue, CParameterAccessContext& parameterContext) const -{ - // Deal with Endianness - parameterContext.setBigEndianSubsystem(_bBigEndian); + parameterAccessContext.setBigEndianSubsystem(_bBigEndian); - return base::getValue(pathNavigator, strValue, parameterContext); + return base::accessValue(pathNavigator, strValue, bSet, parameterAccessContext); } void CSubsystem::logValue(string& strValue, CErrorContext& errorContext) const { - CParameterAccessContext& parameterContext = static_cast<CParameterAccessContext&>(errorContext); + CParameterAccessContext& parameterAccessContext = static_cast<CParameterAccessContext&>(errorContext); // Deal with Endianness - parameterContext.setBigEndianSubsystem(_bBigEndian); + parameterAccessContext.setBigEndianSubsystem(_bBigEndian); return base::logValue(strValue, errorContext); } diff --git a/parameter/Subsystem.h b/parameter/Subsystem.h index 9be5de4..4ef56d1 100644 --- a/parameter/Subsystem.h +++ b/parameter/Subsystem.h @@ -62,8 +62,7 @@ public: virtual string getKind() const; protected: // Parameter access - virtual bool setValue(CPathNavigator& pathNavigator, const string& strValue, CParameterAccessContext& parameterContext) const; - virtual bool getValue(CPathNavigator& pathNavigator, string& strValue, CParameterAccessContext& parameterContext) const; + virtual bool accessValue(CPathNavigator& pathNavigator, string& strValue, bool bSet, CParameterAccessContext& parameterAccessContext) const; virtual void logValue(string& strValue, CErrorContext& errorContext) const; // Used for simulation and virtual subsystems virtual void setDefaultValues(CParameterAccessContext& parameterAccessContext) const; diff --git a/parameter/buildlog.txt b/parameter/buildlog.txt deleted file mode 100644 index df695c2..0000000 --- a/parameter/buildlog.txt +++ /dev/null @@ -1 +0,0 @@ -make: *** No rule to make target `mfld_cdk'. Stop. |