PFW: Add resync mechanism if a subsystem needs resync

BZ: 76267

In the case of a hw subsystems reset, it's possible that its
parameter managed by the PFW may not be aligned with the PFW
blackboard.
A re-synchronization mechanism is implemented to ensure that the
subsystem is re-synchronized on the next configurations application.

Change-Id: I032150955d25a7020cf494e69456897b4c157916
Signed-off-by: Guillaume Denneulin <guillaume.denneulin@intel.com>
Reviewed-on: http://android.intel.com:8080/83015
Reviewed-by: Rocard, KevinX <kevinx.rocard@intel.com>
Reviewed-by: Centelles, Sylvain <sylvain.centelles@intel.com>
Tested-by: Dixon, CharlesX <charlesx.dixon@intel.com>
Reviewed-by: cactus <cactus@intel.com>
Tested-by: cactus <cactus@intel.com>
diff --git a/parameter/SubsystemObject.cpp b/parameter/SubsystemObject.cpp
index 8c5c5e4..15bba6c 100644
--- a/parameter/SubsystemObject.cpp
+++ b/parameter/SubsystemObject.cpp
@@ -23,8 +23,10 @@
  * UPDATED: 2011-07-27
  */
 #include "SubsystemObject.h"
+#include "Subsystem.h"
 #include "InstanceConfigurableElement.h"
 #include "ParameterBlackboard.h"
+#include "ParameterAccessContext.h"
 #include "MappingContext.h"
 #include <assert.h>
 #include <stdlib.h>
@@ -74,6 +76,18 @@
     return ostr.str();
 }
 
+// Default back synchronization
+void CSubsystemObject::setDefaultValues(CParameterBlackboard& parameterBlackboard) const
+{
+    string strError;
+
+    // Create access context
+    CParameterAccessContext parameterAccessContext(strError, &parameterBlackboard, false);
+
+    // Just implement back synchronization with default values
+    _pInstanceConfigurableElement->setDefaultValues(parameterAccessContext);
+}
+
 // Synchronization
 bool CSubsystemObject::sync(CParameterBlackboard& parameterBlackboard, bool bBack, string& strError)
 {
@@ -86,29 +100,34 @@
     return true;
 #endif
 
-    // Synchronize to/from HW
-    if (bBack) {
+    // Retrieve subsystem
+    const CSubsystem* pSubsystem = _pInstanceConfigurableElement->getBelongingSubsystem();
 
-        // Read from HW
-        if (!accessHW(true, strError)) {
+    // Get it's health insdicator
+    bool bIsSubsystemAlive = pSubsystem->isAlive();
 
-            strError = "Unable to back synchronize configurable element " + _pInstanceConfigurableElement->getPath() + ": " + strError;
-            log_warning(strError);
+    // Check subsystem health
+    if (!bIsSubsystemAlive) {
 
-            return false;
-        }
-
-    } else {
-
-        // Send to HW
-        if (!accessHW(false, strError)) {
-
-            strError = "Unable to synchronize configurable element " + _pInstanceConfigurableElement->getPath() + ": " + strError;
-            log_warning(strError);
-
-            return false;
-        }
+        strError = "Susbsystem not alive";
     }
+
+    // Synchronize to/from HW
+    if (!bIsSubsystemAlive || !accessHW(bBack, strError)) {
+
+        strError = string("Unable to ") + (bBack ? "back" : "forward") + " synchronize configurable element " +
+                _pInstanceConfigurableElement->getPath() + ": " + strError;
+
+        log_warning(strError);
+
+        // Fall back to parameter default initialization
+        if (bBack) {
+
+           setDefaultValues(parameterBlackboard);
+        }
+        return false;
+    }
+
     return true;
 }