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>
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 @@
     _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 @@
     delete _pElementLibrarySet;
 
     // Tuning Mode Mutex
-    pthread_mutex_destroy(&_tuningModeMutex);
+    pthread_mutex_destroy(&_blackboardMutex);
 }
 
 string CParameterMgr::getKind() const
@@ -594,7 +595,7 @@
     CAutoLog autoLog(this, "Configuration application request");
 
     // Lock state
-    CAutoLock autoLock(&_tuningModeMutex);
+    CAutoLock autoLock(&_blackboardMutex);
 
     if (!_bTuningModeIsOn) {
 
@@ -611,16 +612,39 @@
 }
 
 // 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 @@
 {
     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::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 @@
 }
 
 // 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 @@
         return false;
     }
     // Lock state
-    CAutoLock autoLock(&_tuningModeMutex);
+    CAutoLock autoLock(&_blackboardMutex);
 
     // Warn domains about exiting tuning mode
     if (!bOn && _bTuningModeIsOn) {
@@ -1639,48 +1673,16 @@
     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