summaryrefslogtreecommitdiffstats
path: root/parameter/BaseParameter.cpp
diff options
context:
space:
mode:
authorPatrick Benavoli <patrickx.benavoli@intel.com>2011-11-20 15:46:41 +0100
committerDavid Wagner <david.wagner@intel.com>2014-02-10 17:15:00 +0100
commit065264a93ce9c63b6a5c95e985188ee33ba587d3 (patch)
tree01897cd4ed658e6a41f21061146098d0385734fd /parameter/BaseParameter.cpp
parent6ccab9d382c08323fb1f000d859a696f05719c92 (diff)
downloadexternal_parameter-framework-065264a93ce9c63b6a5c95e985188ee33ba587d3.zip
external_parameter-framework-065264a93ce9c63b6a5c95e985188ee33ba587d3.tar.gz
external_parameter-framework-065264a93ce9c63b6a5c95e985188ee33ba587d3.tar.bz2
PFW: Type safe dynamic parameter access
BZ: 15065 Replaced high level string based parameter access interface with typed ones. Now hosting platforms that want to control parameters must instantiate a CParameterHandle object out of the desired parameter path. CParameterHandle object may be used to access any kind of parameters, whatever its internal type, whether it's an array or not. Note that non rogue parameters offer a read access only. Any attempt to write them will fail. CParameterHandle objects offer the following kind of parameter accessing interfaces: - Boolean - Integer (signed or unsigned) - Double - String Note that those interfaces are available for scalar as well as for array parameters. Not all parameter types support all access kinds. Naturally, array parameters are only accessed via array interfaces while scalar parameters are managed through scalar interfaces. Here's a list of parameter types that may be controlled through each kind of access interface: - Boolean access: boolean, bit (bit size must be one); - Integer access: integer (sign must match), boolean (unsigned access only, value <= 1), enumerations; - Double access: for now only fixed points (soon integers will support them also through platform adaptation objects) - String access: all parameter types In addition, cleaned up parameter access related code so as to make it more generic and reusable. Changed version to 2.0.0 Change-Id: Ib80868cdb773e90962e48f1f38d2ff0029189815 Signed-off-by: Patrick Benavoli <patrickx.benavoli@intel.com> Reviewed-on: http://android.intel.com:8080/25406 Reviewed-by: Barthes, FabienX <fabienx.barthes@intel.com> Tested-by: Barthes, FabienX <fabienx.barthes@intel.com> Reviewed-by: buildbot <buildbot@intel.com> Tested-by: buildbot <buildbot@intel.com>
Diffstat (limited to 'parameter/BaseParameter.cpp')
-rw-r--r--parameter/BaseParameter.cpp163
1 files changed, 120 insertions, 43 deletions
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);
}