PFW: Dynamic parameter access

BZ: 13272

Added dynamic parameter setting / getting interface for hosting platforms
This new API allows:
	- getting any parameter
	- setting any parameter as long as it is rogue (attached to no domains)
Passed parameter values are in the form of strings.

Change-Id: I01a34597fcb4dafb225519cbc01dfffb22b5d52a
Signed-off-by: Patrick Benavoli <patrickx.benavoli@intel.com>
Reviewed-on: http://android.intel.com:8080/22629
Reviewed-by: Centelles, Sylvain <sylvain.centelles@intel.com>
Tested-by: Barthes, FabienX <fabienx.barthes@intel.com>
Reviewed-by: buildbot <buildbot@intel.com>
Tested-by: buildbot <buildbot@intel.com>
Reviewed-on: http://android.intel.com:8080/26781
Reviewed-by: Barthes, FabienX <fabienx.barthes@intel.com>
diff --git a/parameter/ArrayParameter.cpp b/parameter/ArrayParameter.cpp
index e8d351d..e777c61 100644
--- a/parameter/ArrayParameter.cpp
+++ b/parameter/ArrayParameter.cpp
@@ -104,6 +104,12 @@
         return false;
     }
 
+    // Check for dynamic access
+    if (!checkForDynamicAccess(parameterContext)) {
+
+        return false;
+    }
+
     if (uiStartIndex == (uint32_t)-1) {
 
         // No index provided, start with 0
@@ -136,6 +142,13 @@
 
         return false;
     }
+
+    // Check for dynamic access
+    if (!checkForDynamicAccess(parameterContext)) {
+
+        return false;
+    }
+
     if (uiIndex == (uint32_t)-1) {
 
         // Whole array requested
@@ -275,6 +288,8 @@
     uint32_t uiOffset = getOffset() - uiBaseOffset;
     uint32_t uiArrayLength = getArrayLength();
 
+    strValues.clear();
+
     bool bFirst = true;
 
     for (uiValueIndex = 0; uiValueIndex < uiArrayLength; uiValueIndex++) {
diff --git a/parameter/BaseParameter.cpp b/parameter/BaseParameter.cpp
index 67349d4..b4b0780 100644
--- a/parameter/BaseParameter.cpp
+++ b/parameter/BaseParameter.cpp
@@ -88,6 +88,12 @@
         return false;
     }
 
+    // Check for dynamic access
+    if (!checkForDynamicAccess(parameterContext)) {
+
+        return false;
+    }
+
     // Set Value
     if (!doSetValue(strValue, getOffset(), parameterContext)) {
 
@@ -115,8 +121,29 @@
         return false;
     }
 
+    // Check for dynamic access
+    if (!checkForDynamicAccess(parameterContext)) {
+
+        return false;
+    }
+
     // Get Value
     doGetValue(strValue, getOffset(), parameterContext);
 
     return true;
 }
+
+// Dynamic access checking
+bool CBaseParameter::checkForDynamicAccess(CParameterAccessContext& parameterAccessContext) const
+{
+    // Check for dynamic access
+    if (parameterAccessContext.isDynamicAccess() && !isRogue()) {
+
+        // Parameter is not rogue
+        parameterAccessContext.setError("Parameter " + getPath() + " is not rogue");
+
+        return false;
+    }
+
+    return true;
+}
diff --git a/parameter/BaseParameter.h b/parameter/BaseParameter.h
index e8f82ed..2e3598d 100644
--- a/parameter/BaseParameter.h
+++ b/parameter/BaseParameter.h
@@ -53,4 +53,7 @@
     // 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/ConfigurableElement.cpp b/parameter/ConfigurableElement.cpp
index f439ebf..b11b84f 100644
--- a/parameter/ConfigurableElement.cpp
+++ b/parameter/ConfigurableElement.cpp
@@ -353,6 +353,12 @@
     }
 }
 
+// Belonging to no domains
+bool CConfigurableElement::isRogue() const
+{
+    return !getBelongingDomainCount();
+}
+
 // Footprint as string
 string CConfigurableElement::getFootprintAsString() const
 {
diff --git a/parameter/ConfigurableElement.h b/parameter/ConfigurableElement.h
index 1f5498c..61a8bda 100644
--- a/parameter/ConfigurableElement.h
+++ b/parameter/ConfigurableElement.h
@@ -79,6 +79,9 @@
     // Elements with no domains
     void listRogueElements(string& strResult) const;
 
+    // Belonging to no domains
+    bool isRogue() const;
+
     // Footprint as string
     string getFootprintAsString() const;
 
diff --git a/parameter/DomainConfiguration.cpp b/parameter/DomainConfiguration.cpp
index a5ac27c..b30c8e3 100644
--- a/parameter/DomainConfiguration.cpp
+++ b/parameter/DomainConfiguration.cpp
@@ -439,20 +439,7 @@
 // AreaConfiguration retrieval from present area configurations
 CAreaConfiguration* CDomainConfiguration::findAreaConfiguration(const string& strConfigurableElementPath) const
 {
-    AreaConfigurationListIterator it;
-
-    for (it = _areaConfigurationList.begin(); it != _areaConfigurationList.end(); ++it) {
-
-        CAreaConfiguration* pAreaConfiguration = *it;
-
-        if (pAreaConfiguration->getConfigurableElement()->getPath() == strConfigurableElementPath) {
-
-            return pAreaConfiguration;
-        }
-    }
-
-    // Not found
-    return NULL;
+    return findAreaConfiguration(strConfigurableElementPath, _areaConfigurationList);
 }
 
 // AreaConfiguration retrieval from given area configuration list
diff --git a/parameter/ParameterAccessContext.cpp b/parameter/ParameterAccessContext.cpp
index e296d23..769565a 100644
--- a/parameter/ParameterAccessContext.cpp
+++ b/parameter/ParameterAccessContext.cpp
@@ -35,13 +35,13 @@
 CParameterAccessContext::CParameterAccessContext(string& strError, CParameterBlackboard* pParameterBlackboard, bool bValueSpaceIsRaw, bool bOutputRawFormatIsHex) :
     base(strError), _pParameterBlackboard(pParameterBlackboard),
     _bValueSpaceIsRaw(bValueSpaceIsRaw), _bOutputRawFormatIsHex(bOutputRawFormatIsHex),
-    _bBigEndianSubsystem(false), _bAutoSync(true)
+    _bBigEndianSubsystem(false), _bAutoSync(true), _bDynamicAccess(false)
 {
 }
 
 CParameterAccessContext::CParameterAccessContext(string& strError) :
     base(strError), _pParameterBlackboard(NULL), _bValueSpaceIsRaw(false),
-    _bOutputRawFormatIsHex(false), _bBigEndianSubsystem(false), _bAutoSync(true)
+    _bOutputRawFormatIsHex(false), _bBigEndianSubsystem(false), _bAutoSync(true), _bDynamicAccess(false)
 {
 }
 
@@ -97,5 +97,16 @@
 
 bool CParameterAccessContext::getAutoSync() const
 {
-    return _bAutoSync;
+    return _bAutoSync || _bDynamicAccess;
+}
+
+// Dynamic access
+void CParameterAccessContext::setDynamicAccess(bool bDynamicAccess)
+{
+    _bDynamicAccess = bDynamicAccess;
+}
+
+bool CParameterAccessContext::isDynamicAccess() const
+{
+    return _bDynamicAccess;
 }
diff --git a/parameter/ParameterAccessContext.h b/parameter/ParameterAccessContext.h
index cfdca7f..af6f1b7 100644
--- a/parameter/ParameterAccessContext.h
+++ b/parameter/ParameterAccessContext.h
@@ -60,6 +60,10 @@
     void setAutoSync(bool bAutoSync);
     bool getAutoSync() const;
 
+    // Dynamic access
+    void setDynamicAccess(bool bDynamicAccess);
+    bool isDynamicAccess() const;
+
 private:
     // Blackboard
     CParameterBlackboard* _pParameterBlackboard;
@@ -71,5 +75,7 @@
     bool _bBigEndianSubsystem;
     // Automatic synchronization to HW
     bool _bAutoSync;
+    // Dynamic access
+    bool _bDynamicAccess;
 };
 
diff --git a/parameter/ParameterMgr.cpp b/parameter/ParameterMgr.cpp
index 0fcd4e2..768a5c5 100644
--- a/parameter/ParameterMgr.cpp
+++ b/parameter/ParameterMgr.cpp
@@ -617,6 +617,19 @@
     return true;
 }
 
+// Dynamic parameter handling
+bool CParameterMgr::setValue(const string& strPath, const string& strValue, bool bRawValueSpace, string& strError)
+{
+    // Delegate to low level functionality
+    return doSetValue(strPath, strValue, bRawValueSpace, true, strError);
+}
+
+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);
+}
+
 /////////////////// Remote command parsers
 /// Version
 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::versionCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
@@ -1219,73 +1232,14 @@
         return false;
     }
 
-    CPathNavigator pathNavigator(strPath);
-
-    if (!pathNavigator.isPathValid()) {
-
-        strError = "Path not well formed";
-
-        return false;
-    }
-
-    string* pStrChildName = pathNavigator.next();
-
-    if (!pStrChildName) {
-
-        strError = "Non settable element";
-
-        return false;
-    }
-
-    if (*pStrChildName != getSystemClass()->getName()) {
-
-        strError = "Path not found";
-
-        return false;
-    }
-
-    // Define context
-    CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
-
-    // Set auto sync
-    parameterAccessContext.setAutoSync(_bAutoSyncOn);
-
-    // Do the set
-    return getSystemClass()->setValue(pathNavigator, strValue, parameterAccessContext);
+    // Delegate to low level functionality
+    return doSetValue(strPath, strValue, _bValueSpaceIsRaw, false, strError);
 }
 
 bool CParameterMgr::getValue(const string& strPath, string& strValue, string& strError) const
 {
-    CPathNavigator pathNavigator(strPath);
-
-    if (!pathNavigator.isPathValid()) {
-
-        strError = "Path not well formed";
-
-        return false;
-    }
-
-    string* pStrChildName = pathNavigator.next();
-
-    if (!pStrChildName) {
-
-        strError = "Non settable element";
-
-        return false;
-    }
-
-    if (*pStrChildName != getConstSystemClass()->getName()) {
-
-        strError = "Path not found";
-
-        return false;
-    }
-
-    // Define context
-    CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
-
-    // Do the get
-    return getConstSystemClass()->getValue(pathNavigator, strValue, parameterAccessContext);
+    // Delegate to low level functionality
+    return doGetValue(strPath, strValue, _bValueSpaceIsRaw, _bOutputRawFormatIsHex, false, strError);
 }
 
 // Tuning mode
@@ -1692,6 +1646,84 @@
     return true;
 }
 
+// Parameter access
+bool CParameterMgr::doSetValue(const string& strPath, const string& strValue, bool bRawValueSpace, bool bDynamicAccess, string& strError)
+{
+    CPathNavigator pathNavigator(strPath);
+
+    if (!pathNavigator.isPathValid()) {
+
+        strError = "Path not well formed";
+
+        return false;
+    }
+
+    string* pStrChildName = pathNavigator.next();
+
+    if (!pStrChildName) {
+
+        strError = "Non settable element";
+
+        return false;
+    }
+
+    if (*pStrChildName != getSystemClass()->getName()) {
+
+        strError = "Path not found";
+
+        return false;
+    }
+
+    // Define context
+    CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, bRawValueSpace, false);
+
+    // Set auto sync
+    parameterAccessContext.setAutoSync(_bAutoSyncOn);
+
+    // Set dynamic access
+    parameterAccessContext.setDynamicAccess(bDynamicAccess);
+
+    // Do the set
+    return getSystemClass()->setValue(pathNavigator, strValue, parameterAccessContext);
+}
+
+bool CParameterMgr::doGetValue(const string& strPath, string& strValue, bool bRawValueSpace, bool bHexOutputRawFormat, bool bDynamicAccess, string& strError) const
+{
+    CPathNavigator pathNavigator(strPath);
+
+    if (!pathNavigator.isPathValid()) {
+
+        strError = "Path not well formed";
+
+        return false;
+    }
+
+    string* pStrChildName = pathNavigator.next();
+
+    if (!pStrChildName) {
+
+        strError = "Non settable element";
+
+        return false;
+    }
+
+    if (*pStrChildName != getConstSystemClass()->getName()) {
+
+        strError = "Path not found";
+
+        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);
+}
+
 // Dynamic creation library feeding
 void CParameterMgr::feedElementLibraries()
 {
diff --git a/parameter/ParameterMgr.h b/parameter/ParameterMgr.h
index ef2bd90..857034a 100644
--- a/parameter/ParameterMgr.h
+++ b/parameter/ParameterMgr.h
@@ -110,6 +110,10 @@
     // Configuration application
     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;
+
     //////////// Tuning /////////////
     // Tuning mode
     bool setTuningMode(bool bOn, string& strError);
@@ -238,6 +242,10 @@
     // For tuning, check we're in tuning mode
     bool checkTuningModeOn(string& strError) const;
 
+    // Parameter access
+    bool doSetValue(const string& strPath, const string& strValue, bool bRawValueSpace, bool bDynamicAccess, string& strError);
+    bool doGetValue(const string& strPath, string& strValue, bool bRawValueSpace, bool bHexOutputRawFormat, bool bDynamicAccess, string& strError) const;
+
     // Framework global configuration loading
     bool loadFrameworkConfiguration(string& strError);
 
diff --git a/parameter/ParameterMgrPlatformConnector.cpp b/parameter/ParameterMgrPlatformConnector.cpp
index ae6c038..6fe5c65 100644
--- a/parameter/ParameterMgrPlatformConnector.cpp
+++ b/parameter/ParameterMgrPlatformConnector.cpp
@@ -34,7 +34,7 @@
 #include <assert.h>
 
 #ifdef SIMULATION
-const char* gpcParameterFrameworkConfigurationFolderPath = "/home/pat/Documents/gingerbread3/hardware/intel/PRIVATE/parameter-framework/XML";
+const char* gpcParameterFrameworkConfigurationFolderPath = "/home/pat/Documents/gingerbread2/hardware/intel/PRIVATE/parameter-framework/XML";
 #else
 const char* gpcParameterFrameworkConfigurationFolderPath = "/etc/parameter-framework";
 #endif
@@ -83,6 +83,17 @@
     return _pParameterMgr->applyConfigurations(strError);
 }
 
+// Dynamic parameter handling
+bool CParameterMgrPlatformConnector::setValue(const string& strPath, const string& strValue, string& strError, bool bRawValueSpace)
+{
+    return _pParameterMgr->setValue(strPath, strValue, bRawValueSpace, strError);
+}
+
+bool CParameterMgrPlatformConnector::getValue(const string& strPath, string& strValue, string& strError, bool bRawValueSpace, bool bHexOutputRawFormat) const
+{
+    return _pParameterMgr->getValue(strPath, strValue, bRawValueSpace, bHexOutputRawFormat, strError);
+}
+
 // Logging
 void CParameterMgrPlatformConnector::setLogger(CParameterMgrPlatformConnector::ILogger* pLogger)
 {
diff --git a/parameter/ParameterMgrPlatformConnector.h b/parameter/ParameterMgrPlatformConnector.h
index 43a5c95..518fd92 100644
--- a/parameter/ParameterMgrPlatformConnector.h
+++ b/parameter/ParameterMgrPlatformConnector.h
@@ -49,9 +49,6 @@
     // Selection criterion retrieval
     ISelectionCriterionInterface* getSelectionCriterion(const std::string& strName);
 
-    // Configuration application
-    bool applyConfigurations(std::string& strError);
-
     // Logging
     // Should be called before start
     void setLogger(ILogger* pLogger);
@@ -59,6 +56,13 @@
     // Start
     bool start(std::string& strError);
 
+    // Configuration application
+    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;
+
 private:
     // Private logging
     void doLog(const std::string& strLog);