1 /*
2 * Copyright (c) 2011-2015, 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 : _pParameterMgrLogger(new CParameterMgrLogger<CParameterMgrPlatformConnector>(*this)),
41 _pParameterMgr(new CParameterMgr(strConfigurationFilePath, *_pParameterMgrLogger)),
42 _bStarted(false), _pLogger(NULL)
43 {
44 }
45
~CParameterMgrPlatformConnector()46 CParameterMgrPlatformConnector::~CParameterMgrPlatformConnector()
47 {
48 delete _pParameterMgr;
49 delete _pParameterMgrLogger;
50 }
51
52 // Selection Criteria interface. Beware returned objects are lent, clients shall not delete them!
createSelectionCriterionType(bool bIsInclusive)53 ISelectionCriterionTypeInterface *CParameterMgrPlatformConnector::createSelectionCriterionType(
54 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(
62 const string &strName, const ISelectionCriterionTypeInterface *pSelectionCriterionType)
63 {
64 assert(!_bStarted);
65
66 return _pParameterMgr->createSelectionCriterion(
67 strName, static_cast<const CSelectionCriterionType *>(pSelectionCriterionType));
68 }
69
70 // Selection criterion retrieval
getSelectionCriterion(const string & strName) const71 ISelectionCriterionInterface *CParameterMgrPlatformConnector::getSelectionCriterion(
72 const string &strName) const
73 {
74 return _pParameterMgr->getSelectionCriterion(strName);
75 }
76
77 // Configuration application
applyConfigurations()78 void CParameterMgrPlatformConnector::applyConfigurations()
79 {
80 assert(_bStarted);
81
82 _pParameterMgr->applyConfigurations();
83 }
84
85 // Dynamic parameter handling
createParameterHandle(const string & strPath,string & strError) const86 CParameterHandle *CParameterMgrPlatformConnector::createParameterHandle(const string &strPath,
87 string &strError) const
88 {
89 assert(_bStarted);
90
91 return _pParameterMgr->createParameterHandle(strPath, strError);
92 }
93
createElementHandle(const string & strPath,string & strError) const94 ElementHandle *CParameterMgrPlatformConnector::createElementHandle(const string &strPath,
95 string &strError) const
96 {
97 return _pParameterMgr->createElementHandle(strPath, strError);
98 }
99
100 // Logging
setLogger(CParameterMgrPlatformConnector::ILogger * pLogger)101 void CParameterMgrPlatformConnector::setLogger(CParameterMgrPlatformConnector::ILogger *pLogger)
102 {
103 _pLogger = pLogger;
104 }
105
getForceNoRemoteInterface() const106 bool CParameterMgrPlatformConnector::getForceNoRemoteInterface() const
107 {
108 return _pParameterMgr->getForceNoRemoteInterface();
109 }
110
setForceNoRemoteInterface(bool bForceNoRemoteInterface)111 void CParameterMgrPlatformConnector::setForceNoRemoteInterface(bool bForceNoRemoteInterface)
112 {
113 _pParameterMgr->setForceNoRemoteInterface(bForceNoRemoteInterface);
114 }
115
setFailureOnMissingSubsystem(bool bFail,string & strError)116 bool CParameterMgrPlatformConnector::setFailureOnMissingSubsystem(bool bFail, string &strError)
117 {
118 if (_bStarted) {
119
120 strError = "Can not set missing subsystem policy while running";
121 return false;
122 }
123
124 _pParameterMgr->setFailureOnMissingSubsystem(bFail);
125 return true;
126 }
127
getFailureOnMissingSubsystem() const128 bool CParameterMgrPlatformConnector::getFailureOnMissingSubsystem() const
129 {
130 return _pParameterMgr->getFailureOnMissingSubsystem();
131 }
132
setFailureOnFailedSettingsLoad(bool bFail,std::string & strError)133 bool CParameterMgrPlatformConnector::setFailureOnFailedSettingsLoad(bool bFail,
134 std::string &strError)
135 {
136 if (_bStarted) {
137
138 strError = "Can not set failure on failed settings load policy while running";
139 return false;
140 }
141
142 _pParameterMgr->setFailureOnFailedSettingsLoad(bFail);
143 return true;
144 }
145
getFailureOnFailedSettingsLoad() const146 bool CParameterMgrPlatformConnector::getFailureOnFailedSettingsLoad() const
147 {
148 return _pParameterMgr->getFailureOnFailedSettingsLoad();
149 }
150
getSchemaUri() const151 const string &CParameterMgrPlatformConnector::getSchemaUri() const
152 {
153 return _pParameterMgr->getSchemaUri();
154 }
155
setSchemaUri(const string & schemaUri)156 void CParameterMgrPlatformConnector::setSchemaUri(const string &schemaUri)
157 {
158 _pParameterMgr->setSchemaUri(schemaUri);
159 }
160
setValidateSchemasOnStart(bool bValidate,std::string & strError)161 bool CParameterMgrPlatformConnector::setValidateSchemasOnStart(bool bValidate,
162 std::string &strError)
163 {
164 if (_bStarted) {
165
166 strError = "Can not enable xml validation after the start of the parameter-framework";
167 return false;
168 }
169
170 _pParameterMgr->setValidateSchemasOnStart(bValidate);
171 return true;
172 }
173
getValidateSchemasOnStart() const174 bool CParameterMgrPlatformConnector::getValidateSchemasOnStart() const
175 {
176 return _pParameterMgr->getValidateSchemasOnStart();
177 }
178
179 // Start
start(string & strError)180 bool CParameterMgrPlatformConnector::start(string &strError)
181 {
182 // Create data structure
183 if (!_pParameterMgr->load(strError)) {
184
185 return false;
186 }
187
188 _bStarted = true;
189
190 return true;
191 }
192
193 // Started state
isStarted() const194 bool CParameterMgrPlatformConnector::isStarted() const
195 {
196 return _bStarted;
197 }
198
199 // Private logging
info(const string & log)200 void CParameterMgrPlatformConnector::info(const string &log)
201 {
202 if (_pLogger) {
203
204 _pLogger->info(log);
205 }
206 }
207
warning(const string & log)208 void CParameterMgrPlatformConnector::warning(const string &log)
209 {
210 if (_pLogger) {
211
212 _pLogger->warning(log);
213 }
214 }
215