Restore autosync of string parameter

BZ: 183857

Sync for String parameter accessed from parameter handle API
does not work.

This patch allows synchronisation for string parameter accessed
from parameter handle APIs.

Change-Id: If738402f4c0fcb0bb51bd2515e46f3ac36a361dd
Signed-off-by: Francois Gaffie <francois.gaffie@intel.com>
Signed-off-by: Mattijs Korpershoek <mattijsx.korpershoek@intel.com>
diff --git a/parameter/ArrayParameter.cpp b/parameter/ArrayParameter.cpp
index dedb5da..47000a7 100644
--- a/parameter/ArrayParameter.cpp
+++ b/parameter/ArrayParameter.cpp
@@ -119,11 +119,10 @@
         }
 
         // Synchronize
-        if (parameterAccessContext.getAutoSync() && !sync(parameterAccessContext)) {
+        if (!sync(parameterAccessContext)) {
 
             // Append parameter path to error
             parameterAccessContext.appendToError(" " + getPath());
-
             return false;
         }
     } else {
@@ -326,28 +325,31 @@
 template <typename type>
 bool CArrayParameter::accessValues(vector<type>& values, bool bSet, CParameterAccessContext& parameterAccessContext) const
 {
-    bool bSuccess;
-
     if (bSet) {
 
-        if  (setValues(values, parameterAccessContext)) {
+        // Set Value
+        if (!setValues(values, parameterAccessContext)) {
 
-            // Synchronize
-            bSuccess = sync(parameterAccessContext);
-        } else {
+            // Append parameter path to error
+            parameterAccessContext.appendToError(" " + getPath());
+            return false;
+        }
+        if (!sync(parameterAccessContext)) {
 
-            bSuccess = false;
+            // Append parameter path to error
+            parameterAccessContext.appendToError(" " + getPath());
+            return false;
         }
     } else {
+        // Get Value
+        if (!getValues(values, parameterAccessContext)) {
 
-        bSuccess = getValues(values, parameterAccessContext);
+            // Append parameter path to error
+            parameterAccessContext.appendToError(" " + getPath());
+            return false;
+        }
     }
-    if (!bSuccess) {
-
-        // Append parameter path to error
-        parameterAccessContext.appendToError(" " + getPath());
-    }
-    return bSuccess;
+    return true;
 }
 
 template <typename type>
diff --git a/parameter/BaseParameter.cpp b/parameter/BaseParameter.cpp
index 65fa8bc..3c49471 100644
--- a/parameter/BaseParameter.cpp
+++ b/parameter/BaseParameter.cpp
@@ -51,7 +51,6 @@
 
             // Append parameter path to error
             configurationAccessContext.appendToError(" " + getPath());
-
             return false;
         }
     } else {
@@ -180,15 +179,13 @@
 
             // Append parameter path to error
             parameterAccessContext.appendToError(" " + getPath());
-
             return false;
         }
         // Synchronize
-        if (parameterAccessContext.getAutoSync() && !sync(parameterAccessContext)) {
+        if (!sync(parameterAccessContext)) {
 
             // Append parameter path to error
             parameterAccessContext.appendToError(" " + getPath());
-
             return false;
         }
 
diff --git a/parameter/BitParameter.cpp b/parameter/BitParameter.cpp
index aed9459..2077cde 100644
--- a/parameter/BitParameter.cpp
+++ b/parameter/BitParameter.cpp
@@ -113,12 +113,17 @@
 
     if (bSet) {
 
-        // Set and sync
-        if (!doSet(uiValue, uiOffset, parameterAccessContext) || !sync(parameterAccessContext)) {
+        // Set Value
+        if (!doSet(uiValue, uiOffset, parameterAccessContext)) {
 
             // Append parameter path to error
             parameterAccessContext.appendToError(" " + getPath());
+            return false;
+        }
+        // Synchronize
+        if (!sync(parameterAccessContext)) {
 
+            parameterAccessContext.appendToError(" " + getPath());
             return false;
         }
     } else {
diff --git a/parameter/InstanceConfigurableElement.cpp b/parameter/InstanceConfigurableElement.cpp
index d0e1971..003a606 100644
--- a/parameter/InstanceConfigurableElement.cpp
+++ b/parameter/InstanceConfigurableElement.cpp
@@ -175,9 +175,14 @@
     }
 }
 
-// Sync
 bool CInstanceConfigurableElement::sync(CParameterAccessContext& parameterAccessContext) const
 {
+    if (!parameterAccessContext.getAutoSync()) {
+
+        // AutoSync is disabled, do not perform the sync.
+        // This is not an error, but the expected behavior so return true anyway.
+        return true;
+    }
     ISyncer* pSyncer = getSyncer();
 
     if (!pSyncer) {
@@ -211,4 +216,3 @@
     }
     return true;
 }
-
diff --git a/parameter/InstanceConfigurableElement.h b/parameter/InstanceConfigurableElement.h
index 78b348c..39a0d94 100644
--- a/parameter/InstanceConfigurableElement.h
+++ b/parameter/InstanceConfigurableElement.h
@@ -104,8 +104,18 @@
     virtual ISyncer* getSyncer() const;
     // Syncer set (descendant)
     virtual void fillSyncerSetFromDescendant(CSyncerSet& syncerSet) const;
-    // Sync
+
+    /**
+     * Performs the sync if the AutoSync is enabled.
+     * If AutoSync is disabled, any call to sync will returns true, even if synchronization has not
+     * been done. It will happen when the AutoSync will be switched back on.
+     *
+     * @param[in:out] parameterAccessContext Parameter access context object
+     *
+     * @return true if the synchronization succeded or if the AutoSync is off, false otherwise.
+     */
     bool sync(CParameterAccessContext& parameterAccessContext) const;
+
     // Check parameter access path well formed for leaf elements
     static bool checkPathExhausted(CPathNavigator& pathNavigator, CErrorContext& errorContext);
 private:
diff --git a/parameter/Parameter.cpp b/parameter/Parameter.cpp
index 631710d..75433dd 100644
--- a/parameter/Parameter.cpp
+++ b/parameter/Parameter.cpp
@@ -122,30 +122,36 @@
 
 // Generic Access
 template <typename type>
-bool CParameter::doAccess(type& value, bool bSet, CParameterAccessContext& parameterAccessContext) const
+bool CParameter::doAccess(type& value, bool bSet,
+                          CParameterAccessContext& parameterAccessContext) const
 {
-    bool bSuccess;
-
     if (bSet) {
+        // set value
+        if (!doSet(value, getOffset() - parameterAccessContext.getBaseOffset(),
+                   parameterAccessContext)) {
 
-        if  (doSet(value, getOffset() - parameterAccessContext.getBaseOffset(), parameterAccessContext)) {
+            // Append parameter path to error
+            parameterAccessContext.appendToError(" " + getPath());
+            return false;
 
-            // Synchronize
-            bSuccess = sync(parameterAccessContext);
-        } else {
+        }
+        // Synchronize
+        if (!sync(parameterAccessContext)){
 
-            bSuccess = false;
+            parameterAccessContext.appendToError(" " + getPath());
+            return false;
         }
     } else {
+        // get value
+        if (!doGet(value, getOffset() - parameterAccessContext.getBaseOffset(),
+                   parameterAccessContext)) {
 
-        bSuccess = doGet(value, getOffset() - parameterAccessContext.getBaseOffset(), parameterAccessContext);
+            // Append parameter path to error
+            parameterAccessContext.appendToError(" " + getPath());
+            return false;
+        }
     }
-    if (!bSuccess) {
-
-        // Append parameter path to error
-        parameterAccessContext.appendToError(" " + getPath());
-    }
-    return bSuccess;
+    return true;
 }
 
 template <typename type>
diff --git a/parameter/ParameterAccessContext.cpp b/parameter/ParameterAccessContext.cpp
index b48e7c5..579f6bf 100644
--- a/parameter/ParameterAccessContext.cpp
+++ b/parameter/ParameterAccessContext.cpp
@@ -38,7 +38,7 @@
                                                  uint32_t uiBaseOffset)
     : base(strError), _pParameterBlackboard(pParameterBlackboard),
     _bValueSpaceIsRaw(bValueSpaceIsRaw), _bOutputRawFormatIsHex(bOutputRawFormatIsHex),
-    _bBigEndianSubsystem(false), _bAutoSync(false), _uiBaseOffset(uiBaseOffset)
+    _bBigEndianSubsystem(false), _bAutoSync(true), _uiBaseOffset(uiBaseOffset)
 {
 }
 
@@ -47,14 +47,14 @@
                                                  CParameterBlackboard* pParameterBlackboard,
                                                  uint32_t uiBaseOffset)
     : base(strError), _pParameterBlackboard(pParameterBlackboard), _bValueSpaceIsRaw(false),
-    _bOutputRawFormatIsHex(false), _bBigEndianSubsystem(bBigEndianSubsystem), _bAutoSync(false),
+    _bOutputRawFormatIsHex(false), _bBigEndianSubsystem(bBigEndianSubsystem), _bAutoSync(true),
     _uiBaseOffset(uiBaseOffset)
 {
 }
 
 CParameterAccessContext::CParameterAccessContext(string& strError)
     : base(strError), _pParameterBlackboard(NULL), _bValueSpaceIsRaw(false),
-    _bOutputRawFormatIsHex(false), _bBigEndianSubsystem(false), _bAutoSync(false), _uiBaseOffset(0)
+    _bOutputRawFormatIsHex(false), _bBigEndianSubsystem(false), _bAutoSync(true), _uiBaseOffset(0)
 {
 }