1 /*
2  * Copyright (c) 2011-2014, Intel Corporation
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice, this
9  * list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation and/or
13  * other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors
16  * may be used to endorse or promote products derived from this software without
17  * specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 #include "ParameterMgrPlatformConnector.h"
31 #include "ParameterMgr.h"
32 #include "ParameterMgrLogger.h"
33 #include <assert.h>
34 
35 using std::string;
36 
37 // Construction
CParameterMgrPlatformConnector(const string & strConfigurationFilePath)38 CParameterMgrPlatformConnector::CParameterMgrPlatformConnector(
39         const string& strConfigurationFilePath) :
40     _pParameterMgr(new CParameterMgr(strConfigurationFilePath)), _bStarted(false), _pLogger(NULL)
41 {
42     // Logging
43     _pParameterMgrLogger = new CParameterMgrLogger<CParameterMgrPlatformConnector>(*this);
44     _pParameterMgr->setLogger(_pParameterMgrLogger);
45 }
46 
~CParameterMgrPlatformConnector()47 CParameterMgrPlatformConnector::~CParameterMgrPlatformConnector()
48 {
49     delete _pParameterMgr;
50     delete _pParameterMgrLogger;
51 }
52 
53 // Selection Criteria interface. Beware returned objects are lent, clients shall not delete them!
createSelectionCriterionType(bool bIsInclusive)54 ISelectionCriterionTypeInterface* CParameterMgrPlatformConnector::createSelectionCriterionType(bool bIsInclusive)
55 {
56     assert(!_bStarted);
57 
58     return _pParameterMgr->createSelectionCriterionType(bIsInclusive);
59 }
60 
createSelectionCriterion(const string & strName,const ISelectionCriterionTypeInterface * pSelectionCriterionType)61 ISelectionCriterionInterface* CParameterMgrPlatformConnector::createSelectionCriterion(const string& strName, const ISelectionCriterionTypeInterface* pSelectionCriterionType)
62 {
63     assert(!_bStarted);
64 
65     return _pParameterMgr->createSelectionCriterion(strName, static_cast<const CSelectionCriterionType*>(pSelectionCriterionType));
66 }
67 
68 // Selection criterion retrieval
getSelectionCriterion(const string & strName) const69 ISelectionCriterionInterface* CParameterMgrPlatformConnector::getSelectionCriterion(const string& strName) const
70 {
71     return _pParameterMgr->getSelectionCriterion(strName);
72 }
73 
74 // Configuration application
applyConfigurations()75 void CParameterMgrPlatformConnector::applyConfigurations()
76 {
77     assert(_bStarted);
78 
79     _pParameterMgr->applyConfigurations();
80 }
81 
82 // Dynamic parameter handling
createParameterHandle(const string & strPath,string & strError) const83 CParameterHandle* CParameterMgrPlatformConnector::createParameterHandle(const string& strPath, string& strError) const
84 {
85     assert(_bStarted);
86 
87     return _pParameterMgr->createParameterHandle(strPath, strError);
88 }
89 
90 // Logging
setLogger(CParameterMgrPlatformConnector::ILogger * pLogger)91 void CParameterMgrPlatformConnector::setLogger(CParameterMgrPlatformConnector::ILogger* pLogger)
92 {
93     _pLogger = pLogger;
94 }
95 
getForceNoRemoteInterface() const96 bool CParameterMgrPlatformConnector::getForceNoRemoteInterface() const
97 {
98     return _pParameterMgr->getForceNoRemoteInterface();
99 }
100 
setForceNoRemoteInterface(bool bForceNoRemoteInterface)101 void CParameterMgrPlatformConnector::setForceNoRemoteInterface(bool bForceNoRemoteInterface)
102 {
103     _pParameterMgr->setForceNoRemoteInterface(bForceNoRemoteInterface);
104 }
105 
setFailureOnMissingSubsystem(bool bFail,string & strError)106 bool CParameterMgrPlatformConnector::setFailureOnMissingSubsystem(bool bFail, string &strError)
107 {
108     if (_bStarted) {
109 
110         strError = "Can not set missing subsystem policy while running";
111         return false;
112     }
113 
114     _pParameterMgr->setFailureOnMissingSubsystem(bFail);
115     return true;
116 }
117 
getFailureOnMissingSubsystem()118 bool CParameterMgrPlatformConnector::getFailureOnMissingSubsystem()
119 {
120     return _pParameterMgr->getFailureOnMissingSubsystem();
121 }
122 
setFailureOnFailedSettingsLoad(bool bFail,std::string & strError)123 bool CParameterMgrPlatformConnector::setFailureOnFailedSettingsLoad(
124         bool bFail, std::string& strError)
125 {
126     if (_bStarted) {
127 
128         strError = "Can not set failure on failed settings load policy while running";
129         return false;
130     }
131 
132     _pParameterMgr->setFailureOnFailedSettingsLoad(bFail);
133     return true;
134 }
135 
getFailureOnFailedSettingsLoad()136 bool CParameterMgrPlatformConnector::getFailureOnFailedSettingsLoad()
137 {
138     return _pParameterMgr->getFailureOnFailedSettingsLoad();
139 }
140 
getSchemaFolderLocation() const141 const string& CParameterMgrPlatformConnector::getSchemaFolderLocation() const
142 {
143     return _pParameterMgr->getSchemaFolderLocation();
144 }
145 
setSchemaFolderLocation(const string & strSchemaFolderLocation)146 void CParameterMgrPlatformConnector::setSchemaFolderLocation(const string& strSchemaFolderLocation)
147 {
148     _pParameterMgr->setSchemaFolderLocation(strSchemaFolderLocation);
149 }
150 
setValidateSchemasOnStart(bool bValidate,std::string & strError)151 bool CParameterMgrPlatformConnector::setValidateSchemasOnStart(
152     bool bValidate, std::string& strError)
153 {
154     if (_bStarted) {
155 
156         strError = "Can not enable xml validation after the start of the parameter-framework";
157         return false;
158     }
159 
160     _pParameterMgr->setValidateSchemasOnStart(bValidate);
161     return true;
162 }
163 
getValidateSchemasOnStart()164 bool CParameterMgrPlatformConnector::getValidateSchemasOnStart()
165 {
166     return _pParameterMgr->getValidateSchemasOnStart();
167 }
168 
169 // Start
start(string & strError)170 bool CParameterMgrPlatformConnector::start(string& strError)
171 {
172     // Create data structure
173     if (!_pParameterMgr->load(strError)) {
174 
175         return false;
176     }
177 
178     _bStarted = true;
179 
180     return true;
181 }
182 
183 // Started state
isStarted() const184 bool CParameterMgrPlatformConnector::isStarted() const
185 {
186     return _bStarted;
187 }
188 
189 // Private logging
doLog(bool bIsWarning,const string & strLog)190 void CParameterMgrPlatformConnector::doLog(bool bIsWarning, const string& strLog)
191 {
192     if (_pLogger) {
193 
194         _pLogger->log(bIsWarning, strLog);
195     }
196 }
197