PFW: Log criterion state at PFW start

BZ: 77959

The PFW will log criterion patch state at start before appling
configuration.

Change-Id: I4ac3676b9ba685c1e226a8495ffdbe98f0c08219
Signed-off-by: Kevin Rocard <kevinx.rocard@intel.com>
Reviewed-on: http://android.intel.com:8080/79965
Reviewed-by: De Chivre, Renaud <renaud.de.chivre@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/Element.cpp b/parameter/Element.cpp
index de4a8a9..06c3df2 100644
--- a/parameter/Element.cpp
+++ b/parameter/Element.cpp
@@ -23,13 +23,13 @@
  * UPDATED: 2011-07-27
  */
 #include "Element.h"
+#include "XmlElementSerializingContext.h"
+#include "ElementLibrary.h"
+#include "ErrorContext.h"
 #include <assert.h>
 #include <stdio.h>
 #include <stdarg.h>
 #include <sstream>
-#include "XmlElementSerializingContext.h"
-#include "ElementLibrary.h"
-#include "ErrorContext.h"
 
 CElement::CElement(const string& strName) : _strName(strName), _pParent(NULL)
 {
diff --git a/parameter/ParameterMgr.cpp b/parameter/ParameterMgr.cpp
index 4116dbe..484687a 100644
--- a/parameter/ParameterMgr.cpp
+++ b/parameter/ParameterMgr.cpp
@@ -355,6 +355,21 @@
     // We need to ensure all domains are valid
     pConfigurableDomains->validate(_pMainParameterBlackboard);
 
+    // Log selection criterion states
+    {
+        CAutoLog autoLog(this, "Criterion states");
+
+        const CSelectionCriteria* selectionCriteria = getConstSelectionCriteria();
+
+        list<string> lstrSelectionCriteron;
+        selectionCriteria->listSelectionCriteria(lstrSelectionCriteron, true, false);
+
+        string strSelectionCriteron;
+        CUtility::concatenate(lstrSelectionCriteron, strSelectionCriteron);
+
+        log_info("%s", strSelectionCriteron.c_str());
+    }
+
     // At initialization, check subsystems that need resync
     doApplyConfigurations(true);
 
@@ -673,9 +688,10 @@
 
     /// Criteria states
     appendTitle(strResult, "Selection Criteria:");
-    string strSelectionCriteria;
-    getSelectionCriteria()->listSelectionCriteria(strSelectionCriteria, false);
-    strResult += strSelectionCriteria;
+    list<string> lstrSelectionCriteria;
+    getSelectionCriteria()->listSelectionCriteria(lstrSelectionCriteria, false, true);
+    // Concatenate the criterion list as the command result
+    CUtility::concatenate(lstrSelectionCriteria, strResult);
 
     return CCommandHandler::ESucceeded;
 }
@@ -820,7 +836,12 @@
 {
     (void)remoteCommand;
 
-    getSelectionCriteria()->listSelectionCriteria(strResult, true);
+    list<string> lstrResult;
+
+    getSelectionCriteria()->listSelectionCriteria(lstrResult, true, true);
+
+    // Concatenate the criterion list as the command result
+    CUtility::concatenate(lstrResult, strResult);
 
     return CCommandHandler::ESucceeded;
 }
diff --git a/parameter/SelectionCriteria.cpp b/parameter/SelectionCriteria.cpp
index f75ec35..4b3132e 100644
--- a/parameter/SelectionCriteria.cpp
+++ b/parameter/SelectionCriteria.cpp
@@ -57,9 +57,9 @@
 }
 
 // List available criteria
-void CSelectionCriteria::listSelectionCriteria(string& strResult, bool bWithTypeInfo) const
+void CSelectionCriteria::listSelectionCriteria(list<string>& lstrResult, bool bWithTypeInfo, bool bHumanReadable) const
 {
-    getSelectionCriteriaDefinition()->listSelectionCriteria(strResult, bWithTypeInfo);
+    getSelectionCriteriaDefinition()->listSelectionCriteria(lstrResult, bWithTypeInfo, bHumanReadable);
 }
 
 // Reset the modified status of the children
diff --git a/parameter/SelectionCriteria.h b/parameter/SelectionCriteria.h
index dd274d0..9d34b5b 100644
--- a/parameter/SelectionCriteria.h
+++ b/parameter/SelectionCriteria.h
@@ -24,6 +24,7 @@
  */
 #pragma once
 
+#include <list>
 #include "Element.h"
 #include "SelectionCriterionType.h"
 #include "SelectionCriterion.h"
@@ -51,7 +52,7 @@
     const CSelectionCriteriaDefinition* getSelectionCriteriaDefinition() const;
 
     // List available criteria
-    void listSelectionCriteria(string& strResult, bool bWithTypeInfo) const;
+    void listSelectionCriteria(list<string>& strResult, bool bWithTypeInfo, bool bHumanReadable) const;
 
     // Base
     virtual string getKind() const;
diff --git a/parameter/SelectionCriteriaDefinition.cpp b/parameter/SelectionCriteriaDefinition.cpp
index fafb53a..d7a879d 100644
--- a/parameter/SelectionCriteriaDefinition.cpp
+++ b/parameter/SelectionCriteriaDefinition.cpp
@@ -62,7 +62,7 @@
 }
 
 // List available criteria
-void CSelectionCriteriaDefinition::listSelectionCriteria(string& strResult, bool bWithTypeInfo) const
+void CSelectionCriteriaDefinition::listSelectionCriteria(list<string>& lstrResult, bool bWithTypeInfo, bool bHumanReadable) const
 {
     // Propagate
     uint32_t uiNbChildren = getNbChildren();
@@ -72,7 +72,7 @@
 
         const CSelectionCriterion* pSelectionCriterion = static_cast<const CSelectionCriterion*>(getChild(uiChild));
 
-        strResult += pSelectionCriterion->getFormattedDescription(bWithTypeInfo) + "\n";
+        lstrResult.push_back(pSelectionCriterion->getFormattedDescription(bWithTypeInfo, bHumanReadable));
     }
 }
 
diff --git a/parameter/SelectionCriteriaDefinition.h b/parameter/SelectionCriteriaDefinition.h
index 337f7c3..cae4e18 100644
--- a/parameter/SelectionCriteriaDefinition.h
+++ b/parameter/SelectionCriteriaDefinition.h
@@ -42,7 +42,7 @@
     CSelectionCriterion* getSelectionCriterion(const string& strName);
 
     // List available criteria
-    void listSelectionCriteria(string& strResult, bool bWithTypeInfo) const;
+    void listSelectionCriteria(list<string>& lstrResult, bool bWithTypeInfo, bool bHumanReadable) const;
 
     // Base
     virtual string getKind() const;
diff --git a/parameter/SelectionCriterion.cpp b/parameter/SelectionCriterion.cpp
index 77bca4d..908aaf6 100644
--- a/parameter/SelectionCriterion.cpp
+++ b/parameter/SelectionCriterion.cpp
@@ -55,7 +55,7 @@
 
         _iState = iState;
 
-        log_info("Selection criterion changed event: %s", getFormattedDescription(false).c_str());
+        log_info("Selection criterion changed event: %s", getFormattedDescription(false, false).c_str());
 
         // Check if the previous criterion value has been taken into account (i.e. at least one Configuration was applied
         // since the last criterion change)
@@ -108,35 +108,56 @@
 }
 
 /// User request
-string CSelectionCriterion::getFormattedDescription(bool bWithTypeInfo) const
+string CSelectionCriterion::getFormattedDescription(bool bWithTypeInfo, bool bHumanReadable) const
 {
     string strFormattedDescription;
 
-    if (bWithTypeInfo) {
+    if (bHumanReadable) {
 
-        // Display type info
-        appendTitle(strFormattedDescription, getName() + ":");
+        if (bWithTypeInfo) {
 
-        // States
-        strFormattedDescription += "Possible states ";
+            // Display type info
+            appendTitle(strFormattedDescription, getName() + ":");
 
-        // Type Kind
-        strFormattedDescription += "(";
-        strFormattedDescription += _pType->isTypeInclusive() ? "Inclusive" : "Exclusive";
-        strFormattedDescription += "): ";
+            // States
+            strFormattedDescription += "Possible states ";
 
-        // States
-        strFormattedDescription += _pType->listPossibleValues() + "\n";
+            // Type Kind
+            strFormattedDescription += "(";
+            strFormattedDescription += _pType->isTypeInclusive() ? "Inclusive" : "Exclusive";
+            strFormattedDescription += "): ";
+
+            // States
+            strFormattedDescription += _pType->listPossibleValues() + "\n";
+
+            // Current State
+            strFormattedDescription += "Current state";
+        } else {
+            // Name only
+            strFormattedDescription = getName();
+        }
 
         // Current State
-        strFormattedDescription += "Current state";
+        strFormattedDescription += " = " + _pType->getFormattedState(_iState);
     } else {
-        // Name only
-        strFormattedDescription = getName();
+        // Name
+        strFormattedDescription = "Criterion name: " + getName();
+
+        if (bWithTypeInfo) {
+            // Type Kind
+            strFormattedDescription += ", type kind: ";
+            strFormattedDescription +=  _pType->isTypeInclusive() ? "inclusive" : "exclusive";
+        }
+
+        // Current State
+        strFormattedDescription += ", current state: " +
+                                   _pType->getFormattedState(_iState);
+
+         if (bWithTypeInfo) {
+            // States
+            strFormattedDescription += ", states: " +
+                                       _pType->listPossibleValues();
+        }
     }
-
-    // Current State
-    strFormattedDescription += " = " + _pType->getFormattedState(_iState);
-
     return strFormattedDescription;
 }
diff --git a/parameter/SelectionCriterion.h b/parameter/SelectionCriterion.h
index cf66c45..fe79359 100644
--- a/parameter/SelectionCriterion.h
+++ b/parameter/SelectionCriterion.h
@@ -56,7 +56,7 @@
     bool excludes(int iState) const;
 
     /// User request
-    string getFormattedDescription(bool bWithTypeInfo) const;
+    string getFormattedDescription(bool bWithTypeInfo, bool bHumanReadable) const;
 
     /// From CElement
     virtual string getKind() const;