parameter-framework: Changed criterion interface

BZ: 9561

- separated selection criterion change event indication form configuration application requests in different APIs
- added a way to retrieve selection criterion from its name
- updated version number 0.2.1

Change-Id: Icf4560fe67001655a171401f106296b9aa09afb3
Orig-Change-Id: I8dfb05ba1e704888c5c1ff9268a2a2e9a46af9bb
Signed-off-by: Patrick Benavoli <patrickx.benavoli@intel.com>
Reviewed-on: http://android.intel.com:8080/20208
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-connector-test/ExamplePlatform.cpp b/parameter-connector-test/ExamplePlatform.cpp
index 0e51cfb..5d60880 100644
--- a/parameter-connector-test/ExamplePlatform.cpp
+++ b/parameter-connector-test/ExamplePlatform.cpp
@@ -80,9 +80,6 @@
     _pMode = _pParameterMgrPlatformConnector->createSelectionCriterion("Mode", _pModeType);
     _pSelectedInputDevice = _pParameterMgrPlatformConnector->createSelectionCriterion("SelectedInputDevice", _pInputDeviceType);
     _pSelectedOutputDevice = _pParameterMgrPlatformConnector->createSelectionCriterion("SelectedOutputDevice", _pOutputDeviceType);
-
-    // Init state
-    setState(EInitState);
 }
 
 CExamplePlatform::~CExamplePlatform()
@@ -94,21 +91,26 @@
 // Start
 bool CExamplePlatform::start(string& strError)
 {
-    return _pParameterMgrPlatformConnector->start(strError);
+    if (!_pParameterMgrPlatformConnector->start(strError)) {
+
+        return false;
+    }
+    // Init state
+    return setState(EInitState, strError);
 }
 
 // State
-void CExamplePlatform::setState(CExamplePlatform::State eState)
+bool CExamplePlatform::setState(CExamplePlatform::State eState, string& strError)
 {
     switch(eState) {
     case EInitState:
-        _pMode->setCriterionState(0, false);
-        _pSelectedInputDevice->setCriterionState(0, false);
+        _pMode->setCriterionState(0);
+        _pSelectedInputDevice->setCriterionState(0);
         _pSelectedOutputDevice->setCriterionState(0x4);
         break;
     case EState1:
-        _pMode->setCriterionState(0, false);
-        _pSelectedInputDevice->setCriterionState(0, false);
+        _pMode->setCriterionState(0);
+        _pSelectedInputDevice->setCriterionState(0);
         // Select Headset
         _pSelectedOutputDevice->setCriterionState(0x1);
         break;
@@ -119,5 +121,6 @@
     default:
         break;
     }
+    return _pParameterMgrPlatformConnector->applyConfigurations(strError);
 }
 
diff --git a/parameter-connector-test/ExamplePlatform.h b/parameter-connector-test/ExamplePlatform.h
index bf821e8..1249c7f 100644
--- a/parameter-connector-test/ExamplePlatform.h
+++ b/parameter-connector-test/ExamplePlatform.h
@@ -58,7 +58,7 @@
     bool start(string& strError);
 
     // State
-    void setState(State eState);
+    bool setState(State eState, string& strError);
 
 private:
     // The connector
diff --git a/parameter/ParameterMgr.cpp b/parameter/ParameterMgr.cpp
index a8335c8..329ab37 100644
--- a/parameter/ParameterMgr.cpp
+++ b/parameter/ParameterMgr.cpp
@@ -305,9 +305,6 @@
         return false;
     }
 
-    // All is loaded, we're ready to observe selection criteria change events
-    getSelectionCriteria()->setObserver(this);
-
     // Start remote processor server if appropriate
     return handleRemoteProcessingInterface(strError);
 }
@@ -554,10 +551,17 @@
     return getSelectionCriteria()->createSelectionCriterion(strName, pSelectionCriterionType);
 }
 
-// Selection criteria changed event
-void CParameterMgr::selectionCriterionChanged(const CSelectionCriterion* pSelectionCriterion)
+// Selection criterion retrieval
+CSelectionCriterion* CParameterMgr::getSelectionCriterion(const string& strName)
 {
-    CAutoLog autoLog(this, "Selection criterion changed event: " + pSelectionCriterion->getFormattedDescription(false));
+    // Propagate
+    return getSelectionCriteria()->getSelectionCriterion(strName);
+}
+
+// Selection criteria changed event
+bool CParameterMgr::applyConfigurations(string& strError)
+{
+    CAutoLog autoLog(this, "Configuration application request");
 
     // Lock state
     CAutoLock autoLock(&_tuningModeMutex);
@@ -565,13 +569,15 @@
     if (!_bTuningModeIsOn) {
 
         // Apply configuration(s)
-        string strError;
-
         if (!getConfigurableDomains()->apply(_pMainParameterBlackboard, false, strError)) {
 
             log("Failed to apply configurations!");
+
+            return false;
         }
     }
+
+    return true;
 }
 
 // Command processing
diff --git a/parameter/ParameterMgr.h b/parameter/ParameterMgr.h
index 74440f8..4596843 100644
--- a/parameter/ParameterMgr.h
+++ b/parameter/ParameterMgr.h
@@ -36,7 +36,6 @@
 #include "SelectionCriterionType.h"
 #include "SelectionCriterion.h"
 #include "Element.h"
-#include "SelectionCriterionObserver.h"
 #include <map>
 #include <vector>
 
@@ -52,7 +51,7 @@
 class IRemoteProcessorServerInterface;
 class CBackSynchronizer;
 
-class CParameterMgr : private CElement, private IRemoteCommandHandler, private ISelectionCriterionObserver
+class CParameterMgr : private CElement, private IRemoteCommandHandler
 {
     enum ChildElement {
         EFrameworkConfiguration,
@@ -94,7 +93,7 @@
 
     // Version
     static const uint32_t guiEditionMajor = 0x0;
-    static const uint32_t guiEditionMinor = 0x1;
+    static const uint32_t guiEditionMinor = 0x2;
     static const uint32_t guiRevision = 0x1;
 public:
     // Logger interface
@@ -118,6 +117,11 @@
     // Selection Criteria
     CSelectionCriterionType* createSelectionCriterionType(bool bIsInclusive);
     CSelectionCriterion* createSelectionCriterion(const string& strName, const CSelectionCriterionType* pSelectionCriterionType);
+    // Selection criterion retrieval
+    CSelectionCriterion* getSelectionCriterion(const string& strName);
+
+    // Configuration application
+    bool applyConfigurations(string& strError);
 
     //////////// Tuning /////////////
     // Tuning mode
@@ -176,9 +180,6 @@
     virtual void nestLog() const;
     virtual void unnestLog() const;
 
-    // From ISelectionCriterionObserver: selection criteria changed event
-    virtual void selectionCriterionChanged(const CSelectionCriterion* pSelectionCriterion);
-
     // From IRemoteCommandHandler: return true on success, fill result in any cases
     virtual bool remoteCommandProcess(const IRemoteCommand& remoteCommand, string& strResult);
 
diff --git a/parameter/ParameterMgrPlatformConnector.cpp b/parameter/ParameterMgrPlatformConnector.cpp
index 9da41dd..7f570c5 100644
--- a/parameter/ParameterMgrPlatformConnector.cpp
+++ b/parameter/ParameterMgrPlatformConnector.cpp
@@ -54,6 +54,7 @@
     delete _pParameterMgrLogger;
 }
 
+// Selection Criteria interface. Beware returned objects are lent, clients shall not delete them!
 ISelectionCriterionTypeInterface* CParameterMgrPlatformConnector::createSelectionCriterionType(bool bIsInclusive)
 {
     assert(!_bStarted);
@@ -61,13 +62,27 @@
     return _pParameterMgr->createSelectionCriterionType(bIsInclusive);
 }
 
-ISelectionCriterionInterface* CParameterMgrPlatformConnector::createSelectionCriterion(const std::string& strName, const ISelectionCriterionTypeInterface* pSelectionCriterionType)
+ISelectionCriterionInterface* CParameterMgrPlatformConnector::createSelectionCriterion(const string& strName, const ISelectionCriterionTypeInterface* pSelectionCriterionType)
 {
     assert(!_bStarted);
 
     return _pParameterMgr->createSelectionCriterion(strName, static_cast<const CSelectionCriterionType*>(pSelectionCriterionType));
 }
 
+// Selection criterion retrieval
+ISelectionCriterionInterface* CParameterMgrPlatformConnector::getSelectionCriterion(const string& strName)
+{
+    return _pParameterMgr->getSelectionCriterion(strName);
+}
+
+// Configuration application
+bool CParameterMgrPlatformConnector::applyConfigurations(string& strError)
+{
+    assert(_bStarted);
+
+    return _pParameterMgr->applyConfigurations(strError);
+}
+
 // Logging
 void CParameterMgrPlatformConnector::setLogger(CParameterMgrPlatformConnector::ILogger* pLogger)
 {
@@ -75,7 +90,7 @@
 }
 
 // Start
-bool CParameterMgrPlatformConnector::start(std::string& strError)
+bool CParameterMgrPlatformConnector::start(string& strError)
 {
     // Create data structure
     if (!_pParameterMgr->load(strError)) {
@@ -88,11 +103,13 @@
         return false;
     }
 
+    _bStarted = true;
+
     return true;
 }
 
 // Private logging
-void CParameterMgrPlatformConnector::doLog(const std::string& strLog)
+void CParameterMgrPlatformConnector::doLog(const string& strLog)
 {
     if (_pLogger) {
 
diff --git a/parameter/ParameterMgrPlatformConnector.h b/parameter/ParameterMgrPlatformConnector.h
index 91679b7..91fa1b2 100644
--- a/parameter/ParameterMgrPlatformConnector.h
+++ b/parameter/ParameterMgrPlatformConnector.h
@@ -46,6 +46,11 @@
     // Should be called before start
     ISelectionCriterionTypeInterface* createSelectionCriterionType(bool bIsInclusive = false);
     ISelectionCriterionInterface* createSelectionCriterion(const std::string& strName, const ISelectionCriterionTypeInterface* pSelectionCriterionType);
+    // Selection criterion retrieval
+    ISelectionCriterionInterface* getSelectionCriterion(const std::string& strName);
+
+    // Configuration application
+    bool applyConfigurations(std::string& strError);
 
     // Logging
     // Should be called before start
diff --git a/parameter/SelectionCriteria.cpp b/parameter/SelectionCriteria.cpp
index 9377e31..d0b5766 100644
--- a/parameter/SelectionCriteria.cpp
+++ b/parameter/SelectionCriteria.cpp
@@ -56,11 +56,10 @@
     return getSelectionCriteriaDefinition()->createSelectionCriterion(strName, pSelectionCriterionType);
 }
 
-// Subscription
-void CSelectionCriteria::setObserver(ISelectionCriterionObserver* pSelectionCriterionObserver)
+// Selection criterion retrieval
+CSelectionCriterion* CSelectionCriteria::getSelectionCriterion(const string& strName)
 {
-    // Delegate
-    getSelectionCriteriaDefinition()->setObserver(pSelectionCriterionObserver);
+    return getSelectionCriteriaDefinition()->getSelectionCriterion(strName);
 }
 
 // List available criteria
diff --git a/parameter/SelectionCriteria.h b/parameter/SelectionCriteria.h
index 4751d59..37e4d65 100644
--- a/parameter/SelectionCriteria.h
+++ b/parameter/SelectionCriteria.h
@@ -50,13 +50,12 @@
     // Selection Criteria/Type creation
     CSelectionCriterionType* createSelectionCriterionType(bool bIsInclusive);
     CSelectionCriterion* createSelectionCriterion(const string& strName, const CSelectionCriterionType* pSelectionCriterionType);
+    // Selection criterion retrieval
+    CSelectionCriterion* getSelectionCriterion(const string& strName);
 
     // Selection Criterion definition
     const CSelectionCriteriaDefinition* getSelectionCriteriaDefinition() const;
 
-    // Subscription
-    void setObserver(ISelectionCriterionObserver* pSelectionCriterionObserver);
-
     // List available criteria
     void listSelectionCriteria(string& strResult, bool bWithTypeInfo) const;
 
diff --git a/parameter/SelectionCriteriaDefinition.cpp b/parameter/SelectionCriteriaDefinition.cpp
index e23f326..5a9855a 100644
--- a/parameter/SelectionCriteriaDefinition.cpp
+++ b/parameter/SelectionCriteriaDefinition.cpp
@@ -56,19 +56,9 @@
     return static_cast<const CSelectionCriterion*>(findChild(strName));
 }
 
-// Subscription
-void CSelectionCriteriaDefinition::setObserver(ISelectionCriterionObserver* pSelectionCriterionObserver)
+CSelectionCriterion* CSelectionCriteriaDefinition::getSelectionCriterion(const string& strName)
 {
-    // Propagate
-    uint32_t uiNbChildren = getNbChildren();
-    uint32_t uiChild;
-
-    for (uiChild = 0; uiChild < uiNbChildren; uiChild++) {
-
-        CSelectionCriterion* pSelectionCriterion = static_cast<CSelectionCriterion*>(getChild(uiChild));
-
-        pSelectionCriterion->setObserver(pSelectionCriterionObserver);
-    }
+    return static_cast<CSelectionCriterion*>(findChild(strName));
 }
 
 // List available criteria
diff --git a/parameter/SelectionCriteriaDefinition.h b/parameter/SelectionCriteriaDefinition.h
index e8487b5..a496e9b 100644
--- a/parameter/SelectionCriteriaDefinition.h
+++ b/parameter/SelectionCriteriaDefinition.h
@@ -45,9 +45,7 @@
 
     // Selection Criterion access
     const CSelectionCriterion* getSelectionCriterion(const string& strName) const;
-
-    // Subscription
-    void setObserver(ISelectionCriterionObserver* pSelectionCriterionObserver);
+    CSelectionCriterion* getSelectionCriterion(const string& strName);
 
     // List available criteria
     void listSelectionCriteria(string& strResult, bool bWithTypeInfo) const;
diff --git a/parameter/SelectionCriterion.cpp b/parameter/SelectionCriterion.cpp
index 9640b3b..d3e561b 100644
--- a/parameter/SelectionCriterion.cpp
+++ b/parameter/SelectionCriterion.cpp
@@ -29,10 +29,11 @@
  * </auto_header>
  */
 #include "SelectionCriterion.h"
+#include "AutoLog.h"
 
 #define base CElement
 
-CSelectionCriterion::CSelectionCriterion(const string& strName, const CSelectionCriterionType* pType) : base(strName), _iState(0), _pType(pType), _pObserver(NULL)
+CSelectionCriterion::CSelectionCriterion(const string& strName, const CSelectionCriterionType* pType) : base(strName), _iState(0), _pType(pType)
 {
 }
 
@@ -43,18 +44,14 @@
 
 /// From ISelectionCriterionInterface
 // State
-void CSelectionCriterion::setCriterionState(int iState, bool bUpdate)
+void CSelectionCriterion::setCriterionState(int iState)
 {
     // Check for a change
     if (_iState != iState) {
 
+        CAutoLog autoLog(this, "Selection criterion changed event: " + getFormattedDescription(false));
+
         _iState = iState;
-
-        // Update if required
-        if (bUpdate && _pObserver) {
-
-            _pObserver->selectionCriterionChanged(this);
-        }
     }
 }
 
@@ -75,12 +72,6 @@
     return _pType;
 }
 
-/// Observer
-void CSelectionCriterion::setObserver(ISelectionCriterionObserver* pSelectionCriterionObserver)
-{
-    _pObserver = pSelectionCriterionObserver;
-}
-
 /// Match methods
 bool CSelectionCriterion::is(int iState) const
 {
diff --git a/parameter/SelectionCriterion.h b/parameter/SelectionCriterion.h
index e7b44fe..53e2b17 100644
--- a/parameter/SelectionCriterion.h
+++ b/parameter/SelectionCriterion.h
@@ -32,7 +32,6 @@
 
 #include "Element.h"
 #include "SelectionCriterionType.h"
-#include "SelectionCriterionObserver.h"
 #include "SelectionCriterionInterface.h"
 
 #include <list>
@@ -46,16 +45,13 @@
 
     /// From ISelectionCriterionInterface
     // State
-    virtual void setCriterionState(int iState, bool bUpdate);
+    virtual void setCriterionState(int iState);
     virtual int getCriterionState() const;
     // Name
     virtual string getCriterionName() const;
     // Type
     virtual const ISelectionCriterionTypeInterface* getCriterionType() const;
 
-    /// Subscription
-    void setObserver(ISelectionCriterionObserver* pSelectionCriterionObserver);
-
     /// Match methods
     bool is(int iState) const;
     bool isNot(int iState) const;
@@ -72,7 +68,5 @@
     int _iState;
     // Type
     const CSelectionCriterionType* _pType;
-    // Observer
-    ISelectionCriterionObserver* _pObserver;
 };
 
diff --git a/parameter/SelectionCriterionInterface.h b/parameter/SelectionCriterionInterface.h
index 134de01..9162486 100644
--- a/parameter/SelectionCriterionInterface.h
+++ b/parameter/SelectionCriterionInterface.h
@@ -28,7 +28,7 @@
 class ISelectionCriterionInterface
 {
 public:
-    virtual void setCriterionState(int iState, bool bUpdate = true) = 0;
+    virtual void setCriterionState(int iState) = 0;
     virtual int getCriterionState() const = 0;
     virtual std::string getCriterionName() const = 0;
     virtual const ISelectionCriterionTypeInterface* getCriterionType() const = 0;
diff --git a/parameter/SelectionCriterionObserver.h b/parameter/SelectionCriterionObserver.h
deleted file mode 100644
index fd0ec7d..0000000
--- a/parameter/SelectionCriterionObserver.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/* <auto_header>
- * <FILENAME>
- * 
- * INTEL CONFIDENTIAL
- * Copyright © 2011 Intel 
- * Corporation All Rights Reserved.
- * 
- * The source code contained or described herein and all documents related to
- * the source code ("Material") are owned by Intel Corporation or its suppliers
- * or licensors. Title to the Material remains with Intel Corporation or its
- * suppliers and licensors. The Material contains trade secrets and proprietary
- * and confidential information of Intel or its suppliers and licensors. The
- * Material is protected by worldwide copyright and trade secret laws and
- * treaty provisions. No part of the Material may be used, copied, reproduced,
- * modified, published, uploaded, posted, transmitted, distributed, or
- * disclosed in any way without Intel’s prior express written permission.
- * 
- * No license under any patent, copyright, trade secret or other intellectual
- * property right is granted to or conferred upon you by disclosure or delivery
- * of the Materials, either expressly, by implication, inducement, estoppel or
- * otherwise. Any license under such intellectual property rights must be
- * express and approved by Intel in writing.
- * 
- *  AUTHOR: Patrick Benavoli (patrickx.benavoli@intel.com)
- * CREATED: 2011-06-01
- * UPDATED: 2011-07-27
- * 
- * 
- * </auto_header>
- */
-#pragma once
-
-class CSelectionCriterion;
-
-class ISelectionCriterionObserver
-{
-public:
-    virtual void selectionCriterionChanged(const CSelectionCriterion* pSelectionCriterion) = 0;
-};