blob: 9b01c851363819d04b723c3ea2cfbc803b2c839a [file] [log] [blame]
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +02001/*
David Wagnerb76c9d62014-02-05 18:30:24 +01002 * 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.
Patrick Benavoli68a91282011-08-31 11:23:23 +020029 */
30#include "ParameterMgr.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020031#include "XmlParameterSerializingContext.h"
32#include "XmlElementSerializingContext.h"
33#include "SystemClass.h"
34#include "ElementLibrarySet.h"
35#include "SubsystemLibrary.h"
36#include "NamedElementBuilderTemplate.h"
37#include "KindElementBuilderTemplate.h"
38#include "ElementBuilderTemplate.h"
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +020039#include "XmlFileIncluderElement.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020040#include "SelectionCriterionType.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020041#include "SubsystemElementBuilder.h"
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +020042#include "FileIncluderElementBuilder.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020043#include "SelectionCriteria.h"
44#include "ComponentType.h"
45#include "ComponentInstance.h"
46#include "ParameterBlockType.h"
47#include "BooleanParameterType.h"
48#include "IntegerParameterType.h"
49#include "FixedPointParameterType.h"
50#include "ParameterBlackboard.h"
51#include "Parameter.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020052#include "ParameterAccessContext.h"
53#include "XmlFileIncluderElement.h"
54#include "ParameterFrameworkConfiguration.h"
55#include "FrameworkConfigurationGroup.h"
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +010056#include "PluginLocation.h"
57#include "SubsystemPlugins.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020058#include "FrameworkConfigurationLocation.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020059#include "ConfigurableDomains.h"
60#include "ConfigurableDomain.h"
61#include "DomainConfiguration.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020062#include "XmlDomainSerializingContext.h"
David Wagner29fa61f2014-12-19 11:15:02 +010063#include "XmlDomainExportContext.h"
64#include "XmlDomainImportContext.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020065#include "BitParameterBlockType.h"
66#include "BitParameterType.h"
Patrick Benavoli1352ae52011-10-21 16:48:04 +020067#include "StringParameterType.h"
Patrick Benavoli9fc3c0d2011-10-27 14:27:27 +020068#include "EnumParameterType.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020069#include "RemoteProcessorServerInterface.h"
70#include "ElementLocator.h"
71#include "AutoLog.h"
72#include "CompoundRule.h"
73#include "SelectionCriterionRule.h"
74#include "SimulatedBackSynchronizer.h"
75#include "HardwareBackSynchronizer.h"
Patrick Benavoli1387bda2011-08-31 11:23:24 +020076#include "AutoLock.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020077#include <strings.h>
78#include <dlfcn.h>
79#include <assert.h>
Patrick Benavoli065264a2011-11-20 15:46:41 +010080#include "ParameterHandle.h"
Patrick Benavoliee65e6d2011-11-20 18:52:24 +010081#include "LinearParameterAdaptation.h"
Patrick Benavoli68808c62012-02-02 17:12:41 +010082#include "EnumValuePair.h"
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +020083#include "Subsystem.h"
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020084#include "XmlFileDocSink.h"
85#include "XmlFileDocSource.h"
86#include "XmlStringDocSink.h"
Georges-Henri Baroncec86c12012-09-04 17:30:28 +020087#include "XmlStringDocSource.h"
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020088#include "XmlMemoryDocSink.h"
89#include "XmlMemoryDocSource.h"
Kevin Rocardace81f82012-12-11 16:19:17 +010090#include "Utility.h"
Frédéric Boisnard6c55e9a2014-01-10 18:46:33 +010091#include <sstream>
Patrick Benavoli68a91282011-08-31 11:23:23 +020092
93#define base CElement
94
Sebastien Gonzalved9526492014-02-20 22:28:03 +010095using std::string;
96using std::list;
97using std::vector;
98using std::ostringstream;
99
Patrick Benavoli68a91282011-08-31 11:23:23 +0200100// Used for remote processor server creation
101typedef IRemoteProcessorServerInterface* (*CreateRemoteProcessorServer)(uint16_t uiPort, IRemoteCommandHandler* pCommandHandler);
102
103// Global configuration file name (fixed)
104const char* gacParameterFrameworkConfigurationFileName = "ParameterFrameworkConfiguration.xml";
105const char* gacSystemSchemasSubFolder = "Schemas";
106
107// Config File System looks normally like this:
108// ---------------------------------------------
Kevin Rocard03b73842014-10-01 18:20:41 +0200109//|-- <ParameterFrameworkConfiguration>.xml
110//|-- Schemas
111//| `-- *.xsd
112//|-- Settings
113//| `-- <SystemClassName folder>*
114//| |-- <ConfigurableDomains>.xml
115//| `-- <Settings>.bin?
116//`-- Structure
117// `-- <SystemClassName folder>*
118// |-- <SystemClassName>Class.xml
119// `-- <Subsystem>.xml*
Patrick Benavoli68a91282011-08-31 11:23:23 +0200120// --------------------------------------------
121
122
123// Remote command parser array
Patrick Benavoli592ae562011-09-05 16:53:58 +0200124const CParameterMgr::SRemoteCommandParserItem CParameterMgr::gastRemoteCommandParserItems[] = {
Kevin Rocard3949b342013-05-24 18:43:53 +0200125
Patrick Benavoli592ae562011-09-05 16:53:58 +0200126 /// Version
Kevin Rocard3949b342013-05-24 18:43:53 +0200127 { "version", &CParameterMgr::versionCommandProcess, 0,
128 "", "Show version" },
129
Patrick Benavoli68a91282011-08-31 11:23:23 +0200130 /// Status
Kevin Rocard3949b342013-05-24 18:43:53 +0200131 { "status", &CParameterMgr::statusCommandProcess, 0, "",
132 "Show current status" },
133
Patrick Benavoli68a91282011-08-31 11:23:23 +0200134 /// Tuning Mode
Kevin Rocard3949b342013-05-24 18:43:53 +0200135 { "setTuningMode", &CParameterMgr::setTuningModeCommmandProcess, 1,
136 "on|off*", "Turn on or off Tuning Mode" },
137 { "getTuningMode", &CParameterMgr::getTuningModeCommmandProcess, 0,
138 "", "Show Tuning Mode" },
139
Patrick Benavoli68a91282011-08-31 11:23:23 +0200140 /// Value Space
Kevin Rocard3949b342013-05-24 18:43:53 +0200141 { "setValueSpace", &CParameterMgr::setValueSpaceCommmandProcess, 1,
142 "raw|real*", "Assigns Value Space used for parameter value interpretation" },
143 { "getValueSpace", &CParameterMgr::getValueSpaceCommmandProcess, 0,
144 "", "Show Value Space" },
145
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200146 /// Output Raw Format
Kevin Rocard3949b342013-05-24 18:43:53 +0200147 { "setOutputRawFormat", &CParameterMgr::setOutputRawFormatCommmandProcess, 1,
148 "dec*|hex", "Assigns format used to output parameter values when in raw Value Space" },
149 { "getOutputRawFormat", &CParameterMgr::getOutputRawFormatCommmandProcess, 0,
150 "", "Show Output Raw Format" },
151
Patrick Benavoli68a91282011-08-31 11:23:23 +0200152 /// Sync
Kevin Rocard3949b342013-05-24 18:43:53 +0200153 { "setAutoSync", &CParameterMgr::setAutoSyncCommmandProcess, 1,
154 "on*|off", "Turn on or off automatic synchronization to hardware while in Tuning Mode" },
155 { "getAutoSync", &CParameterMgr::getAutoSyncCommmandProcess, 0,
156 "", "Show Auto Sync state" },
157 { "sync", &CParameterMgr::syncCommmandProcess, 0,
158 "", "Synchronize current settings to hardware while in Tuning Mode and Auto Sync off" },
159
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200160 /// Criteria
Kevin Rocard3949b342013-05-24 18:43:53 +0200161 { "listCriteria", &CParameterMgr::listCriteriaCommmandProcess, 0,
162 "[csv]", "List selection criteria" },
163
Patrick Benavoli68a91282011-08-31 11:23:23 +0200164 /// Domains
Kevin Rocard3949b342013-05-24 18:43:53 +0200165 { "listDomains", &CParameterMgr::listDomainsCommmandProcess, 0,
166 "", "List configurable domains" },
167 { "dumpDomains", &CParameterMgr::dumpDomainsCommmandProcess, 0,
168 "", "Show all domains and configurations, including applicability conditions" },
169 { "createDomain", &CParameterMgr::createDomainCommmandProcess, 1,
170 "<domain>", "Create new configurable domain" },
171 { "deleteDomain", &CParameterMgr::deleteDomainCommmandProcess, 1,
172 "<domain>", "Delete configurable domain" },
173 { "deleteAllDomains", &CParameterMgr::deleteAllDomainsCommmandProcess, 0,
174 "", "Delete all configurable domains" },
175 { "renameDomain", &CParameterMgr::renameDomainCommmandProcess, 2,
176 "<domain> <new name>", "Rename configurable domain" },
177 { "setSequenceAwareness", &CParameterMgr::setSequenceAwarenessCommmandProcess, 1,
178 "<domain> true|false*", "Set configurable domain sequence awareness" },
179 { "getSequenceAwareness", &CParameterMgr::getSequenceAwarenessCommmandProcess, 1,
180 "<domain>", "Get configurable domain sequence awareness" },
181 { "listDomainElements", &CParameterMgr::listDomainElementsCommmandProcess, 1,
182 "<domain>", "List elements associated to configurable domain" },
183 { "addElement", &CParameterMgr::addElementCommmandProcess, 2,
184 "<domain> <elem path>", "Associate element at given path to configurable domain" },
185 { "removeElement", &CParameterMgr::removeElementCommmandProcess, 2,
186 "<domain> <elem path>", "Dissociate element at given path from configurable domain" },
187 { "splitDomain", &CParameterMgr::splitDomainCommmandProcess, 2,
188 "<domain> <elem path>", "Split configurable domain at given associated element path" },
189
Patrick Benavoli68a91282011-08-31 11:23:23 +0200190 /// Configurations
Kevin Rocard3949b342013-05-24 18:43:53 +0200191 { "listConfigurations", &CParameterMgr::listConfigurationsCommmandProcess, 1,
192 "<domain>", "List domain configurations" },
193 { "createConfiguration", &CParameterMgr::createConfigurationCommmandProcess, 2,
194 "<domain> <configuration>", "Create new domain configuration" },
195 { "deleteConfiguration", &CParameterMgr::deleteConfigurationCommmandProcess, 2,
196 "<domain> <configuration>", "Delete domain configuration" },
197 { "renameConfiguration", &CParameterMgr::renameConfigurationCommmandProcess, 3,
198 "<domain> <configuration> <new name>", "Rename domain configuration" },
199 { "saveConfiguration", &CParameterMgr::saveConfigurationCommmandProcess, 2,
200 "<domain> <configuration>", "Save current settings into configuration" },
201 { "restoreConfiguration", &CParameterMgr::restoreConfigurationCommmandProcess, 2,
202 "<domain> <configuration>", "Restore current settings from configuration" },
203 { "setElementSequence", &CParameterMgr::setElementSequenceCommmandProcess, 3,
204 "<domain> <configuration> <elem path list>",
205 "Set element application order for configuration" },
206 { "getElementSequence", &CParameterMgr::getElementSequenceCommmandProcess, 2,
207 "<domain> <configuration>", "Get element application order for configuration" },
208 { "setRule", &CParameterMgr::setRuleCommmandProcess, 3,
209 "<domain> <configuration> <rule>", "Set configuration application rule" },
210 { "clearRule", &CParameterMgr::clearRuleCommmandProcess, 2,
211 "<domain> <configuration>", "Clear configuration application rule" },
212 { "getRule", &CParameterMgr::getRuleCommmandProcess, 2,
213 "<domain> <configuration>", "Get configuration application rule" },
214
Patrick Benavoli68a91282011-08-31 11:23:23 +0200215 /// Elements/Parameters
Kevin Rocard3949b342013-05-24 18:43:53 +0200216 { "listElements", &CParameterMgr::listElementsCommmandProcess, 1,
217 "<elem path>|/", "List elements under element at given path or root" },
218 { "listParameters", &CParameterMgr::listParametersCommmandProcess, 1,
219 "<elem path>|/", "List parameters under element at given path or root" },
220 { "dumpElement", &CParameterMgr::dumpElementCommmandProcess, 1,
221 "<elem path>", "Dump structure and content of element at given path" },
222 { "getElementSize", &CParameterMgr::getElementSizeCommmandProcess, 1,
223 "<elem path>", "Show size of element at given path" },
224 { "showProperties", &CParameterMgr::showPropertiesCommmandProcess, 1,
225 "<elem path>", "Show properties of element at given path" },
226 { "getParameter", &CParameterMgr::getParameterCommmandProcess, 1,
227 "<param path>", "Get value for parameter at given path" },
228 { "setParameter", &CParameterMgr::setParameterCommmandProcess, 2,
229 "<param path> <value>", "Set value for parameter at given path" },
230 { "listBelongingDomains", &CParameterMgr::listBelongingDomainsCommmandProcess, 1,
231 "<elem path>", "List domain(s) element at given path belongs to" },
232 { "listAssociatedDomains", &CParameterMgr::listAssociatedDomainsCommmandProcess, 1,
233 "<elem path>", "List domain(s) element at given path is associated to" },
234 { "getConfigurationParameter", &CParameterMgr::getConfigurationParameterCommmandProcess, 3,
235 "<domain> <configuration> <param path>",
236 "Get value for parameter at given path from configuration" },
237 { "setConfigurationParameter", &CParameterMgr::setConfigurationParameterCommmandProcess, 4,
238 "<domain> <configuration> <param path> <value>",
239 "Set value for parameter at given path to configuration" },
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200240 { "showMapping", &CParameterMgr::showMappingCommmandProcess, 1,
241 "<elem path>", "Show mapping for an element at given path" },
Kevin Rocard3949b342013-05-24 18:43:53 +0200242
Patrick Benavoli68a91282011-08-31 11:23:23 +0200243 /// Browse
Kevin Rocard3949b342013-05-24 18:43:53 +0200244 { "listAssociatedElements", &CParameterMgr::listAssociatedElementsCommmandProcess, 0,
245 "", "List element sub-trees associated to at least one configurable domain" },
246 { "listConflictingElements", &CParameterMgr::listConflictingElementsCommmandProcess, 0,
247 "", "List element sub-trees contained in more than one configurable domain" },
248 { "listRogueElements", &CParameterMgr::listRogueElementsCommmandProcess, 0,
249 "", "List element sub-trees owned by no configurable domain" },
250
Patrick Benavoli68a91282011-08-31 11:23:23 +0200251 /// Settings Import/Export
Kevin Rocard3949b342013-05-24 18:43:53 +0200252 { "exportDomainsXML", &CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess, 1,
253 "<file path> ", "Export domains to XML file" },
254 { "importDomainsXML", &CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess, 1,
255 "<file path>", "Import domains from XML file" },
256 { "exportDomainsWithSettingsXML",
257 &CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess, 1,
258 "<file path> ", "Export domains including settings to XML file" },
259 { "importDomainsWithSettingsXML",
260 &CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess, 1,
261 "<file path>", "Import domains including settings from XML file" },
262 { "exportSettings", &CParameterMgr::exportSettingsCommmandProcess, 1,
263 "<file path>", "Export settings to binary file" },
264 { "importSettings", &CParameterMgr::importSettingsCommmandProcess, 1,
265 "<file path>", "Import settings from binary file" },
Georges-Henri Baroncec86c12012-09-04 17:30:28 +0200266 { "getDomainsWithSettingsXML",
267 &CParameterMgr::getConfigurableDomainsWithSettingsXMLCommmandProcess, 0,
Kevin Rocard3949b342013-05-24 18:43:53 +0200268 "", "Print domains including settings as XML" },
David Wagnered744eb2014-12-04 18:38:52 +0100269 { "getDomainWithSettingsXML",
270 &CParameterMgr::getConfigurableDomainWithSettingsXMLCommmandProcess, 1,
271 "<domain>", "Print the given domain including settings as XML" },
Georges-Henri Baroncec86c12012-09-04 17:30:28 +0200272 { "setDomainsWithSettingsXML",
273 &CParameterMgr::setConfigurableDomainsWithSettingsXMLCommmandProcess, 1,
274 "<xml configurable domains>", "Import domains including settings from XML string" },
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200275 /// Structure Export
Kevin Rocard3949b342013-05-24 18:43:53 +0200276 { "getSystemClassXML", &CParameterMgr::getSystemClassXMLCommmandProcess, 0 ,
Kevin Rocardc0211572013-06-18 11:34:53 +0200277 "", "Print parameter structure as XML" },
278 /// Deprecated Commands
279 { "getDomainsXML",
280 &CParameterMgr::getConfigurableDomainsWithSettingsXMLCommmandProcess, 0,
281 "", "DEPRECATED COMMAND, please use getDomainsWithSettingsXML" },
Georges-Henri Baroncec86c12012-09-04 17:30:28 +0200282
Patrick Benavoli68a91282011-08-31 11:23:23 +0200283};
Kevin Rocard3949b342013-05-24 18:43:53 +0200284
Patrick Benavoli68a91282011-08-31 11:23:23 +0200285// Remote command parsers array Size
Patrick Benavoli592ae562011-09-05 16:53:58 +0200286const uint32_t CParameterMgr::guiNbRemoteCommandParserItems = sizeof(gastRemoteCommandParserItems) / sizeof(gastRemoteCommandParserItems[0]);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200287
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100288CParameterMgr::CParameterMgr(const string& strConfigurationFilePath) :
Patrick Benavoli68a91282011-08-31 11:23:23 +0200289 _bTuningModeIsOn(false),
290 _bValueSpaceIsRaw(false),
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200291 _bOutputRawFormatIsHex(false),
Patrick Benavoli68a91282011-08-31 11:23:23 +0200292 _bAutoSyncOn(true),
293 _pMainParameterBlackboard(new CParameterBlackboard),
294 _pElementLibrarySet(new CElementLibrarySet),
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100295 _strXmlConfigurationFilePath(strConfigurationFilePath),
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100296 _pSubsystemPlugins(NULL),
Renaud de Chivre1b8b3ca2013-12-13 15:09:44 +0100297 _handleLibRemoteProcessor(NULL),
Patrick Benavoli68a91282011-08-31 11:23:23 +0200298 _uiStructureChecksum(0),
299 _pRemoteProcessorServer(NULL),
300 _uiMaxCommandUsageLength(0),
301 _pLogger(NULL),
Kevin Rocardecf93102013-07-10 18:28:10 +0200302 _uiLogDepth(0),
Kevin Rocardd6909eb2013-07-18 09:13:51 +0200303 _bFailOnMissingSubsystem(true),
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +0200304 _bFailOnFailedSettingsLoad(true),
305 _bValidateSchemasOnStart(false)
306
Patrick Benavoli68a91282011-08-31 11:23:23 +0200307{
308 // Tuning Mode Mutex
Patrick Benavoli065264a2011-11-20 15:46:41 +0100309 bzero(&_blackboardMutex, sizeof(_blackboardMutex));
310 pthread_mutex_init(&_blackboardMutex, NULL);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200311
312 // Deal with children
313 addChild(new CParameterFrameworkConfiguration);
314 addChild(new CSelectionCriteria);
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100315 addChild(new CSystemClass);
316 addChild(new CConfigurableDomains);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200317
Patrick Benavoli63499d42011-10-24 18:50:03 +0200318 _pCommandHandler = new CCommandHandler(this);
319
320 // Add command parsers
321 uint32_t uiRemoteCommandParserItem;
322
323 for (uiRemoteCommandParserItem = 0; uiRemoteCommandParserItem < guiNbRemoteCommandParserItems; uiRemoteCommandParserItem++) {
324
325 const SRemoteCommandParserItem* pRemoteCommandParserItem = &gastRemoteCommandParserItems[uiRemoteCommandParserItem];
326
327 _pCommandHandler->addCommandParser(pRemoteCommandParserItem->_pcCommandName,
328 pRemoteCommandParserItem->_pfnParser,
329 pRemoteCommandParserItem->_uiMinArgumentCount,
330 pRemoteCommandParserItem->_pcHelp,
331 pRemoteCommandParserItem->_pcDescription);
332 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100333
334 // Configuration file folder
335 uint32_t uiSlashPos = _strXmlConfigurationFilePath.rfind('/', -1);
336
337 assert(uiSlashPos != (uint32_t)-1);
338
339 _strXmlConfigurationFolderPath = _strXmlConfigurationFilePath.substr(0, uiSlashPos);
340
341 // Schema absolute folder location
342 _strSchemaFolderLocation = _strXmlConfigurationFolderPath + "/" + gacSystemSchemasSubFolder;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200343}
344
345CParameterMgr::~CParameterMgr()
346{
347 // Children
348 delete _pRemoteProcessorServer;
Frederic Boisnard31242302012-04-26 17:07:34 +0200349 delete _pCommandHandler;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200350 delete _pMainParameterBlackboard;
351 delete _pElementLibrarySet;
352
Renaud de Chivre1b8b3ca2013-12-13 15:09:44 +0100353 // Close remote processor library
354 if (_handleLibRemoteProcessor != NULL) {
355 dlclose(_handleLibRemoteProcessor);
356 }
357
Patrick Benavoli68a91282011-08-31 11:23:23 +0200358 // Tuning Mode Mutex
Patrick Benavoli065264a2011-11-20 15:46:41 +0100359 pthread_mutex_destroy(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200360}
361
362string CParameterMgr::getKind() const
363{
364 return "ParameterMgr";
365}
366
367// Logging
368void CParameterMgr::setLogger(CParameterMgr::ILogger* pLogger)
369{
370 _pLogger = pLogger;
371}
372
373// Logging
Kevin Rocardace81f82012-12-11 16:19:17 +0100374void CParameterMgr::doLog(bool bIsWarning, const string& strLog) const
Patrick Benavoli68a91282011-08-31 11:23:23 +0200375{
376 if (_pLogger) {
377
378 // Nest
379 string strIndent;
380
381 // Level
382 uint32_t uiNbIndents = _uiLogDepth;
383
384 while (uiNbIndents--) {
385
386 strIndent += " ";
387 }
388
389 // Log
Kevin Rocardace81f82012-12-11 16:19:17 +0100390 _pLogger->log(bIsWarning, strIndent + strLog);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200391 }
392}
393
394void CParameterMgr::nestLog() const
395{
Patrick Benavoli592ae562011-09-05 16:53:58 +0200396 _uiLogDepth++;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200397}
398
399void CParameterMgr::unnestLog() const
400{
Patrick Benavoli592ae562011-09-05 16:53:58 +0200401 _uiLogDepth--;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200402}
403
Patrick Benavoli63499d42011-10-24 18:50:03 +0200404// Version
405string CParameterMgr::getVersion() const
406{
407 string strVersion;
408
409 // Major
410 strVersion = toString(guiEditionMajor) + ".";
411 // Minor
412 strVersion += toString(guiEditionMinor) + ".";
413 // Revision
414 strVersion += toString(guiRevision);
415
416 return strVersion;
417}
418
Patrick Benavoli68a91282011-08-31 11:23:23 +0200419bool CParameterMgr::load(string& strError)
420{
421 CAutoLog autoLog(this, "Loading");
422
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +0200423 feedElementLibraries();
424
Patrick Benavoli68a91282011-08-31 11:23:23 +0200425 // Load Framework configuration
426 if (!loadFrameworkConfiguration(strError)) {
427
428 return false;
429 }
430
431 // Load subsystems
Kevin Rocardecf93102013-07-10 18:28:10 +0200432 if (!getSystemClass()->loadSubsystems(strError,
433 _pSubsystemPlugins, !_bFailOnMissingSubsystem)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200434
435 return false;
436 }
437
438 // Load structure
439 if (!loadStructure(strError)) {
440
441 return false;
442 }
443
444 // Load settings
445 if (!loadSettings(strError)) {
446
447 return false;
448 }
449
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200450 // Back synchronization for areas in parameter blackboard not covered by any domain
Kevin Rocardace81f82012-12-11 16:19:17 +0100451 CBackSynchronizer* pBackSynchronizer = createBackSynchronizer();
Patrick Benavoli68a91282011-08-31 11:23:23 +0200452
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200453 // Back-synchronize
Kevin Rocard57096bd2012-11-30 11:24:20 +0100454 {
455 CAutoLog autoLog(this, "Main blackboard back synchronization");
456
Kevin Rocard5d6e05a2013-01-21 15:57:45 +0100457 pBackSynchronizer->sync();
Kevin Rocard57096bd2012-11-30 11:24:20 +0100458
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200459 // Get rid of back synchronizer
460 delete pBackSynchronizer;
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200461 }
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200462
463 // We're done loading the settings and back synchronizing
464 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
465
466 // We need to ensure all domains are valid
467 pConfigurableDomains->validate(_pMainParameterBlackboard);
468
Kevin Rocard7f265822012-12-07 18:51:22 +0100469 // Log selection criterion states
470 {
471 CAutoLog autoLog(this, "Criterion states");
472
473 const CSelectionCriteria* selectionCriteria = getConstSelectionCriteria();
474
475 list<string> lstrSelectionCriteron;
476 selectionCriteria->listSelectionCriteria(lstrSelectionCriteron, true, false);
477
Kevin Rocard36299362013-02-04 14:57:47 +0100478 log_table(false, lstrSelectionCriteron);
Kevin Rocard7f265822012-12-07 18:51:22 +0100479 }
480
Kevin Rocard2fbe6e82013-03-26 17:09:29 +0100481 // Subsystem can not ask for resync as they have not been synced yet
482 getSystemClass()->cleanSubsystemsNeedToResync();
483
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100484 // At initialization, check subsystems that need resync
485 doApplyConfigurations(true);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200486
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200487 // Start remote processor server if appropriate
488 return handleRemoteProcessingInterface(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200489}
490
491bool CParameterMgr::loadFrameworkConfiguration(string& strError)
492{
493 CAutoLog autoLog(this, "Loading framework configuration");
494
Patrick Benavoli68a91282011-08-31 11:23:23 +0200495 // Parse Structure XML file
496 CXmlElementSerializingContext elementSerializingContext(strError);
497
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100498 if (!xmlParse(elementSerializingContext, getFrameworkConfiguration(), _strXmlConfigurationFilePath, _strXmlConfigurationFolderPath, EFrameworkConfigurationLibrary)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200499
500 return false;
501 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100502 // Set class name to system class and configurable domains
503 getSystemClass()->setName(getConstFrameworkConfiguration()->getSystemClassName());
504 getConfigurableDomains()->setName(getConstFrameworkConfiguration()->getSystemClassName());
505
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100506 // Get subsystem plugins elements
507 _pSubsystemPlugins = static_cast<const CSubsystemPlugins*>(getConstFrameworkConfiguration()->findChild("SubsystemPlugins"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200508
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100509 if (!_pSubsystemPlugins) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200510
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100511 strError = "Parameter Framework Configuration: couldn't find SubsystemPlugins element";
Patrick Benavoli68a91282011-08-31 11:23:23 +0200512
513 return false;
514 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200515
Patrick Benavoli68a91282011-08-31 11:23:23 +0200516 // Log tuning availability
Kevin Rocardace81f82012-12-11 16:19:17 +0100517 log_info("Tuning %s", getConstFrameworkConfiguration()->isTuningAllowed() ? "allowed" : "prohibited");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200518
519 return true;
520}
521
522bool CParameterMgr::loadStructure(string& strError)
523{
524 // Retrieve system to load structure to
525 CSystemClass* pSystemClass = getSystemClass();
526
Kevin Rocarde25ee792013-04-22 17:46:28 +0200527 log_info("Loading " + pSystemClass->getName() + " system class structure");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200528
529 // Get structure description element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100530 const CFrameworkConfigurationLocation* pStructureDescriptionFileLocation = static_cast<const CFrameworkConfigurationLocation*>(getConstFrameworkConfiguration()->findChildOfKind("StructureDescriptionFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200531
532 if (!pStructureDescriptionFileLocation) {
533
534 strError = "No StructureDescriptionFileLocation element found for SystemClass " + pSystemClass->getName();
535
536 return false;
537 }
538
539 // Get Xml structure folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100540 string strXmlStructureFolder = pStructureDescriptionFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200541
542 // Get Xml structure file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100543 string strXmlStructureFilePath = pStructureDescriptionFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200544
545 // Parse Structure XML file
546 CXmlParameterSerializingContext parameterBuildContext(strError);
547
Kevin Rocard57096bd2012-11-30 11:24:20 +0100548 CAutoLog autolog(pSystemClass, "Importing system structure from file " + strXmlStructureFilePath);
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200549
Patrick Benavoli68a91282011-08-31 11:23:23 +0200550 if (!xmlParse(parameterBuildContext, pSystemClass, strXmlStructureFilePath, strXmlStructureFolder, EParameterCreationLibrary)) {
551
552 return false;
553 }
554
555 // Initialize offsets
556 pSystemClass->setOffset(0);
557
558 // Initialize main blackboard's size
559 _pMainParameterBlackboard->setSize(pSystemClass->getFootPrint());
560
561 return true;
562}
563
564bool CParameterMgr::loadSettings(string& strError)
565{
Kevin Rocardd6909eb2013-07-18 09:13:51 +0200566 string strLoadError;
567 bool success = loadSettingsFromConfigFile(strLoadError);
568
569 if (!success && !_bFailOnFailedSettingsLoad) {
570 // Load can not fail, ie continue but log the load errors
571 log_info(strLoadError);
572 log_info("Failed to load settings, continue without domains.");
573 success = true;
574 }
575
576 if (!success) {
577 // Propagate the litteral error only if the function fails
578 strError = strLoadError;
579 return false;
580 }
581
582 return true;
583}
584
585bool CParameterMgr::loadSettingsFromConfigFile(string& strError)
586{
Patrick Benavoli68a91282011-08-31 11:23:23 +0200587 CAutoLog autoLog(this, "Loading settings");
588
589 // Get settings configuration element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100590 const CFrameworkConfigurationGroup* pParameterConfigurationGroup = static_cast<const CFrameworkConfigurationGroup*>(getConstFrameworkConfiguration()->findChildOfKind("SettingsConfiguration"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200591
592 if (!pParameterConfigurationGroup) {
593
594 // No settings to load
595
596 return true;
597 }
598 // Get binary settings file location
599 const CFrameworkConfigurationLocation* pBinarySettingsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("BinarySettingsFileLocation"));
600
601 string strXmlBinarySettingsFilePath;
602
603 if (pBinarySettingsFileLocation) {
604
605 // Get Xml binary settings file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100606 strXmlBinarySettingsFilePath = pBinarySettingsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200607 }
608
609 // Get configurable domains element
610 const CFrameworkConfigurationLocation* pConfigurableDomainsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("ConfigurableDomainsFileLocation"));
611
612 if (!pConfigurableDomainsFileLocation) {
613
614 strError = "No ConfigurableDomainsFileLocation element found for SystemClass " + getSystemClass()->getName();
615
616 return false;
Kevin Rocardd6909eb2013-07-18 09:13:51 +0200617 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200618 // Get destination root element
619 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
620
621 // Get Xml configuration domains file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100622 string strXmlConfigurationDomainsFilePath = pConfigurableDomainsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200623
624 // Get Xml configuration domains folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100625 string strXmlConfigurationDomainsFolder = pConfigurableDomainsFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200626
627 // Parse configuration domains XML file (ask to read settings from XML file if they are not provided as binary)
David Wagnerd8a53102014-12-10 14:49:23 +0100628 CXmlDomainImportContext xmlDomainImportContext(strError, !pBinarySettingsFileLocation,
629 *getSystemClass());
Patrick Benavoli68a91282011-08-31 11:23:23 +0200630
631 // Selection criteria definition for rule creation
David Wagner29fa61f2014-12-19 11:15:02 +0100632 xmlDomainImportContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
Patrick Benavoli68a91282011-08-31 11:23:23 +0200633
Patrick Benavoli63499d42011-10-24 18:50:03 +0200634 // Auto validation of configurations if no binary settings provided
David Wagner29fa61f2014-12-19 11:15:02 +0100635 xmlDomainImportContext.setAutoValidationRequired(!pBinarySettingsFileLocation);
Patrick Benavoli63499d42011-10-24 18:50:03 +0200636
Kevin Rocardace81f82012-12-11 16:19:17 +0100637 log_info("Importing configurable domains from file %s %s settings", strXmlConfigurationDomainsFilePath.c_str(), pBinarySettingsFileLocation ? "without" : "with");
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200638
Patrick Benavoli68a91282011-08-31 11:23:23 +0200639 // Do parse
David Wagner29fa61f2014-12-19 11:15:02 +0100640 if (!xmlParse(xmlDomainImportContext, pConfigurableDomains, strXmlConfigurationDomainsFilePath, strXmlConfigurationDomainsFolder, EParameterConfigurationLibrary, "SystemClassName")) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200641
642 return false;
643 }
644 // We have loaded the whole system structure, compute checksum
645 const CSystemClass* pSystemClass = getConstSystemClass();
646 _uiStructureChecksum = pSystemClass->computeStructureChecksum() + getConfigurableDomains()->computeStructureChecksum() + getSelectionCriteria()->computeStructureChecksum();
647
648 // Load binary settings if any provided
649 if (pBinarySettingsFileLocation && !pConfigurableDomains->serializeSettings(strXmlBinarySettingsFilePath, false, _uiStructureChecksum, strError)) {
650
651 return false;
652 }
653
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200654 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200655}
656
657// XML parsing
658bool CParameterMgr::xmlParse(CXmlElementSerializingContext& elementSerializingContext, CElement* pRootElement, const string& strXmlFilePath, const string& strXmlFolder, CParameterMgr::ElementLibrary eElementLibrary, const string& strNameAttrituteName)
659{
660 // Init serializing context
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +0200661 elementSerializingContext.set(_pElementLibrarySet->getElementLibrary(
662 eElementLibrary), strXmlFolder, _strSchemaFolderLocation);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200663
664 // Get Schema file associated to root element
665 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pRootElement->getKind() + ".xsd";
666
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +0200667 CXmlFileDocSource fileDocSource(strXmlFilePath, strXmlSchemaFilePath,
668 pRootElement->getKind(),
669 pRootElement->getName(), strNameAttrituteName,
670 _bValidateSchemasOnStart);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200671
672 // Start clean
673 pRootElement->clean();
674
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200675 CXmlMemoryDocSink memorySink(pRootElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200676
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200677 if (!memorySink.process(fileDocSource, elementSerializingContext)) {
678 //Cleanup
Patrick Benavoli68a91282011-08-31 11:23:23 +0200679 pRootElement->clean();
680
681 return false;
682 }
683
Patrick Benavoli68a91282011-08-31 11:23:23 +0200684 return true;
685}
686
687// Init
688bool CParameterMgr::init(string& strError)
689{
690 return base::init(strError);
691}
692
693// Selection criteria interface
694CSelectionCriterionType* CParameterMgr::createSelectionCriterionType(bool bIsInclusive)
695{
696 // Propagate
697 return getSelectionCriteria()->createSelectionCriterionType(bIsInclusive);
698}
699
700CSelectionCriterion* CParameterMgr::createSelectionCriterion(const string& strName, const CSelectionCriterionType* pSelectionCriterionType)
701{
702 // Propagate
703 return getSelectionCriteria()->createSelectionCriterion(strName, pSelectionCriterionType);
704}
705
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200706// Selection criterion retrieval
707CSelectionCriterion* CParameterMgr::getSelectionCriterion(const string& strName)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200708{
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200709 // Propagate
710 return getSelectionCriteria()->getSelectionCriterion(strName);
711}
712
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100713// Configuration application
Kevin Rocardace81f82012-12-11 16:19:17 +0100714void CParameterMgr::applyConfigurations()
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200715{
716 CAutoLog autoLog(this, "Configuration application request");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200717
718 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +0100719 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200720
721 if (!_bTuningModeIsOn) {
722
723 // Apply configuration(s)
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100724 doApplyConfigurations(false);
Frédéric Boisnarddaaa63c2012-08-27 15:48:15 +0200725 } else {
726
Kevin Rocardace81f82012-12-11 16:19:17 +0100727 log_warning("Configurations were not applied because the TuningMode is on");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200728 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200729}
730
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200731// Get the configurableElement corresponding to the given path
732const CConfigurableElement* CParameterMgr::getConfigurableElement(const string& strPath,
733 string& strError) const
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200734{
Patrick Benavoli065264a2011-11-20 15:46:41 +0100735 CPathNavigator pathNavigator(strPath);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200736
Patrick Benavoli065264a2011-11-20 15:46:41 +0100737 // Nagivate through system class
738 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
739
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100740 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100741 }
742
743 // Find element
744 const CElement* pElement = getConstSystemClass()->findDescendant(pathNavigator);
745
746 if (!pElement) {
747
Kevin Rocard4c3f8d82013-11-21 12:16:28 +0100748 strError = "Path not found: " + strPath;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100749
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100750 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100751 }
752
753 // Check found element is a parameter
754 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pElement);
755
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200756 return pConfigurableElement;
757}
758
759// Dynamic parameter handling
760CParameterHandle* CParameterMgr::createParameterHandle(const string& strPath, string& strError)
761{
762 const CConfigurableElement* pConfigurableElement = getConfigurableElement(strPath, strError);
763
764 if (!pConfigurableElement) {
765
766 // Element not found
Kevin Rocard4c3f8d82013-11-21 12:16:28 +0100767 strError = "Element not found: " + strPath;
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200768 return NULL;
769 }
770
Patrick Benavoli065264a2011-11-20 15:46:41 +0100771 if (!pConfigurableElement->isParameter()) {
772
773 // Element is not parameter
Kevin Rocard4c3f8d82013-11-21 12:16:28 +0100774 strError = "Not a parameter: " + strPath;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100775
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100776 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100777 }
778
779 // Convert as parameter and return new handle
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200780 return new CParameterHandle(static_cast<const CBaseParameter*>(pConfigurableElement), this);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200781}
782
Kevin Rocardecf93102013-07-10 18:28:10 +0200783void CParameterMgr::setFailureOnMissingSubsystem(bool bFail)
784{
785 _bFailOnMissingSubsystem = bFail;
786}
787
788bool CParameterMgr::getFailureOnMissingSubsystem() const
789{
790 return _bFailOnMissingSubsystem;
791}
Kevin Rocardd6909eb2013-07-18 09:13:51 +0200792
793void CParameterMgr::setFailureOnFailedSettingsLoad(bool bFail)
794{
795 _bFailOnFailedSettingsLoad = bFail;
796}
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +0200797
Kevin Rocardd6909eb2013-07-18 09:13:51 +0200798bool CParameterMgr::getFailureOnFailedSettingsLoad()
799{
800 return _bFailOnFailedSettingsLoad;
801}
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +0200802
803void CParameterMgr::setValidateSchemasOnStart(bool bValidate)
804{
805 _bValidateSchemasOnStart = bValidate;
806}
807
808bool CParameterMgr::getValidateSchemasOnStart() const
809{
810 return _bValidateSchemasOnStart;
811}
812
Patrick Benavoli68a91282011-08-31 11:23:23 +0200813/////////////////// Remote command parsers
Patrick Benavoli592ae562011-09-05 16:53:58 +0200814/// Version
Patrick Benavoli63499d42011-10-24 18:50:03 +0200815CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::versionCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli592ae562011-09-05 16:53:58 +0200816{
817 (void)remoteCommand;
818
Patrick Benavoli63499d42011-10-24 18:50:03 +0200819 // Show version
820 strResult = getVersion();
Patrick Benavoli592ae562011-09-05 16:53:58 +0200821
Patrick Benavoli63499d42011-10-24 18:50:03 +0200822 return CCommandHandler::ESucceeded;
Patrick Benavoli592ae562011-09-05 16:53:58 +0200823}
824
Patrick Benavoli68a91282011-08-31 11:23:23 +0200825/// Status
Patrick Benavoli63499d42011-10-24 18:50:03 +0200826CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::statusCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200827{
828 (void)remoteCommand;
829 // System class
830 const CSystemClass* pSystemClass = getSystemClass();
831
Patrick Benavoli68a91282011-08-31 11:23:23 +0200832 // Show status
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200833 /// General section
834 appendTitle(strResult, "General:");
835 // System class
Patrick Benavoli68a91282011-08-31 11:23:23 +0200836 strResult += "System Class: ";
837 strResult += pSystemClass->getName();
838 strResult += "\n";
839
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200840 // Tuning mode
Patrick Benavoli68a91282011-08-31 11:23:23 +0200841 strResult += "Tuning Mode: ";
842 strResult += tuningModeOn() ? "on" : "off";
843 strResult += "\n";
844
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200845 // Value space
Patrick Benavoli68a91282011-08-31 11:23:23 +0200846 strResult += "Value Space: ";
847 strResult += valueSpaceIsRaw() ? "raw" : "real";
848 strResult += "\n";
849
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200850 // Output raw format
851 strResult += "Output Raw Format: ";
852 strResult += outputRawFormatIsHex() ? "hex" : "dec";
853 strResult += "\n";
854
855 // Auto Sync
Patrick Benavoli68a91282011-08-31 11:23:23 +0200856 strResult += "Auto Sync: ";
857 strResult += autoSyncOn() ? "on" : "off";
858 strResult += "\n";
859
860 /// Subsystem list
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200861 appendTitle(strResult, "Subsystems:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200862 string strSubsystemList;
863 pSystemClass->listChildrenPaths(strSubsystemList);
864 strResult += strSubsystemList;
865
866 /// Last applied configurations
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200867 appendTitle(strResult, "Last Applied [Pending] Configurations:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200868 string strLastAppliedConfigurations;
869 getConfigurableDomains()->listLastAppliedConfigurations(strLastAppliedConfigurations);
870 strResult += strLastAppliedConfigurations;
871
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200872 /// Criteria states
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200873 appendTitle(strResult, "Selection Criteria:");
Kevin Rocard7f265822012-12-07 18:51:22 +0100874 list<string> lstrSelectionCriteria;
875 getSelectionCriteria()->listSelectionCriteria(lstrSelectionCriteria, false, true);
876 // Concatenate the criterion list as the command result
Frederic Boisnard390b36d2013-05-23 15:28:31 +0200877 string strCriteriaStates;
878 CUtility::asString(lstrSelectionCriteria, strCriteriaStates);
879 strResult += strCriteriaStates;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200880
Patrick Benavoli63499d42011-10-24 18:50:03 +0200881 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200882}
883
884/// Tuning Mode
Patrick Benavoli63499d42011-10-24 18:50:03 +0200885CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200886{
887 if (remoteCommand.getArgument(0) == "on") {
888
889 if (setTuningMode(true, strResult)) {
890
Patrick Benavoli63499d42011-10-24 18:50:03 +0200891 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200892 }
893 } else if (remoteCommand.getArgument(0) == "off") {
894
895 if (setTuningMode(false, strResult)) {
896
Patrick Benavoli63499d42011-10-24 18:50:03 +0200897 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200898 }
899 } else {
900 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200901 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200902 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200903 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200904}
905
Patrick Benavoli63499d42011-10-24 18:50:03 +0200906CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200907{
908 (void)remoteCommand;
909
910 strResult = tuningModeOn() ? "on" : "off";
911
Patrick Benavoli63499d42011-10-24 18:50:03 +0200912 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200913}
914
915/// Value Space
Patrick Benavoli63499d42011-10-24 18:50:03 +0200916CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200917{
918 (void)strResult;
919
920 if (remoteCommand.getArgument(0) == "raw") {
921
922 setValueSpace(true);
923
Patrick Benavoli63499d42011-10-24 18:50:03 +0200924 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200925
926 } else if (remoteCommand.getArgument(0) == "real") {
927
928 setValueSpace(false);
929
Patrick Benavoli63499d42011-10-24 18:50:03 +0200930 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200931
932 } else {
933 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200934 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200935 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200936 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200937}
938
Patrick Benavoli63499d42011-10-24 18:50:03 +0200939CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200940{
941 (void)remoteCommand;
942
943 strResult = valueSpaceIsRaw() ? "raw" : "real";
944
Patrick Benavoli63499d42011-10-24 18:50:03 +0200945 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200946}
947
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200948/// Output Raw Format
Patrick Benavoli63499d42011-10-24 18:50:03 +0200949CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200950{
951 (void)strResult;
952
953 if (remoteCommand.getArgument(0) == "hex") {
954
955 setOutputRawFormat(true);
956
Patrick Benavoli63499d42011-10-24 18:50:03 +0200957 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200958
959 } else if (remoteCommand.getArgument(0) == "dec") {
960
961 setOutputRawFormat(false);
962
Patrick Benavoli63499d42011-10-24 18:50:03 +0200963 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200964
965 } else {
966 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200967 return CCommandHandler::EShowUsage;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200968 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200969 return CCommandHandler::EFailed;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200970}
971
Patrick Benavoli63499d42011-10-24 18:50:03 +0200972CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200973{
974 (void)remoteCommand;
975
976 strResult = outputRawFormatIsHex() ? "hex" : "dec";
977
Patrick Benavoli63499d42011-10-24 18:50:03 +0200978 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200979}
980
Patrick Benavoli68a91282011-08-31 11:23:23 +0200981/// Sync
Patrick Benavoli63499d42011-10-24 18:50:03 +0200982CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200983{
984 if (remoteCommand.getArgument(0) == "on") {
985
986 if (setAutoSync(true, strResult)) {
987
Patrick Benavoli63499d42011-10-24 18:50:03 +0200988 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200989 }
990 } else if (remoteCommand.getArgument(0) == "off") {
991
992 if (setAutoSync(false, strResult)) {
993
Patrick Benavoli63499d42011-10-24 18:50:03 +0200994 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200995 }
996 } else {
997 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200998 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200999 }
Patrick Benavoli63499d42011-10-24 18:50:03 +02001000 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001001}
1002
Patrick Benavoli63499d42011-10-24 18:50:03 +02001003CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001004{
1005 (void)remoteCommand;
1006
1007 strResult = autoSyncOn() ? "on" : "off";
1008
Patrick Benavoli63499d42011-10-24 18:50:03 +02001009 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001010}
1011
Patrick Benavoli63499d42011-10-24 18:50:03 +02001012CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::syncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001013{
1014 (void)remoteCommand;
1015
Patrick Benavoli63499d42011-10-24 18:50:03 +02001016 return sync(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001017}
1018
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001019/// Criteria
Patrick Benavoli63499d42011-10-24 18:50:03 +02001020CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listCriteriaCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001021{
1022 (void)remoteCommand;
1023
Kevin Rocard4eae8272013-04-18 19:12:46 +02001024 bool humanReadable = true;
Kevin Rocard7f265822012-12-07 18:51:22 +01001025
Kevin Rocard4eae8272013-04-18 19:12:46 +02001026 // Look for optional arguments
1027 if (remoteCommand.getArgumentCount() >= 1) {
1028
1029 // If csv is provided, format the criterion list in Commas Separated Value pairs
1030 if (remoteCommand.getArgument(0) == "csv") {
1031 humanReadable = false;
1032 } else {
1033 return CCommandHandler::EShowUsage;
1034 }
1035 }
1036
1037 list<string> lstrResult;
1038 getSelectionCriteria()->listSelectionCriteria(lstrResult, true, humanReadable);
Kevin Rocard7f265822012-12-07 18:51:22 +01001039
1040 // Concatenate the criterion list as the command result
Frederic Boisnard390b36d2013-05-23 15:28:31 +02001041 CUtility::asString(lstrResult, strResult);
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001042
Patrick Benavoli63499d42011-10-24 18:50:03 +02001043 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001044}
Patrick Benavoli68a91282011-08-31 11:23:23 +02001045
1046/// Domains
Patrick Benavoli63499d42011-10-24 18:50:03 +02001047CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001048{
1049 (void)remoteCommand;
1050
Patrick Benavoli63499d42011-10-24 18:50:03 +02001051 getConfigurableDomains()->listDomains(strResult);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001052
Patrick Benavoli63499d42011-10-24 18:50:03 +02001053 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001054}
1055
Patrick Benavoli63499d42011-10-24 18:50:03 +02001056CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001057{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001058 return createDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001059}
1060
Patrick Benavoli63499d42011-10-24 18:50:03 +02001061CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001062{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001063 return deleteDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001064}
1065
Kevin Rocard170f0a42012-06-18 13:56:05 +02001066CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteAllDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1067{
1068 (void)remoteCommand;
1069
1070 return deleteAllDomains(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1071}
1072
Patrick Benavoli63499d42011-10-24 18:50:03 +02001073CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001074{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001075 return getConfigurableDomains()->renameDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001076}
1077
Patrick Benavoli63499d42011-10-24 18:50:03 +02001078CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001079{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001080 // Check tuning mode
1081 if (!checkTuningModeOn(strResult)) {
1082
1083 return CCommandHandler::EFailed;
1084 }
1085
1086 // Set property
1087 bool bSequenceAware;
1088
1089 if (remoteCommand.getArgument(1) == "true") {
1090
1091 bSequenceAware = true;
1092
1093 } else if (remoteCommand.getArgument(1) == "false") {
1094
1095 bSequenceAware = false;
1096
1097 } else {
1098 // Show usage
1099 return CCommandHandler::EShowUsage;
1100 }
1101
1102 return getConfigurableDomains()->setSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001103}
1104
Patrick Benavoli63499d42011-10-24 18:50:03 +02001105CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001106{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001107 // Get property
1108 bool bSequenceAware;
1109
1110 if (!getConfigurableDomains()->getSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult)) {
1111
1112 return CCommandHandler::EFailed;
1113 }
1114
1115 strResult = bSequenceAware ? "true" : "false";
1116
1117 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001118}
1119
Patrick Benavoli63499d42011-10-24 18:50:03 +02001120CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001121{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001122 return getConfigurableDomains()->listDomainElements(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001123}
1124
Patrick Benavoli63499d42011-10-24 18:50:03 +02001125CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::addElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001126{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001127 return addConfigurableElementToDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1128}
1129
1130CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::removeElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1131{
1132 return removeConfigurableElementFromDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1133}
1134
1135CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::splitDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1136{
1137 return split(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001138}
1139
1140/// Configurations
Patrick Benavoli63499d42011-10-24 18:50:03 +02001141CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConfigurationsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001142{
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001143 return getConstConfigurableDomains()->listConfigurations(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
1144}
1145
1146CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1147{
1148 (void)remoteCommand;
1149
1150 // Dummy error context
1151 string strError;
1152 CErrorContext errorContext(strError);
1153
1154 // Dump
1155 getConstConfigurableDomains()->dumpContent(strResult, errorContext);
1156
1157 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001158}
1159
Patrick Benavoli63499d42011-10-24 18:50:03 +02001160CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001161{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001162 return createConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001163}
1164
Patrick Benavoli63499d42011-10-24 18:50:03 +02001165CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001166{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001167 return deleteConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001168}
1169
Patrick Benavoli63499d42011-10-24 18:50:03 +02001170CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001171{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001172 return getConfigurableDomains()->renameConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001173}
1174
Patrick Benavoli63499d42011-10-24 18:50:03 +02001175CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::saveConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001176{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001177 return saveConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001178}
1179
Patrick Benavoli63499d42011-10-24 18:50:03 +02001180CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::restoreConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001181{
Kevin Rocardace81f82012-12-11 16:19:17 +01001182 list<string> lstrResult;
1183 if (!restoreConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), lstrResult)) {
1184 //Concatenate the error list as the command result
Frederic Boisnard390b36d2013-05-23 15:28:31 +02001185 CUtility::asString(lstrResult, strResult);
Kevin Rocardace81f82012-12-11 16:19:17 +01001186
1187 return CCommandHandler::EFailed;
1188 }
1189 return CCommandHandler::EDone;
Patrick Benavoli63499d42011-10-24 18:50:03 +02001190}
1191
1192CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1193{
1194 // Check tuning mode
1195 if (!checkTuningModeOn(strResult)) {
1196
1197 return CCommandHandler::EFailed;
1198 }
1199
1200 // Build configurable element path list
Sebastien Gonzalved9526492014-02-20 22:28:03 +01001201 std::vector<string> astrNewElementSequence;
Patrick Benavoli63499d42011-10-24 18:50:03 +02001202
1203 uint32_t uiArgument;
1204
1205 for (uiArgument = 2; uiArgument < remoteCommand.getArgumentCount(); uiArgument++) {
1206
1207 astrNewElementSequence.push_back(remoteCommand.getArgument(uiArgument));
1208 }
1209
1210 // Delegate to configurable domains
1211 return getConfigurableDomains()->setElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), astrNewElementSequence, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1212}
1213
1214CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1215{
1216 // Delegate to configurable domains
1217 return getConfigurableDomains()->getElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001218}
1219
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001220CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1221{
1222 // Delegate to configurable domains
1223 return getConfigurableDomains()->setApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.packArguments(2, remoteCommand.getArgumentCount() - 2), getConstSelectionCriteria()->getSelectionCriteriaDefinition(), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1224}
1225
1226CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::clearRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1227{
1228 // Delegate to configurable domains
1229 return getConfigurableDomains()->clearApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1230}
1231
1232CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1233{
1234 // Delegate to configurable domains
1235 return getConfigurableDomains()->getApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
1236}
1237
Patrick Benavoli68a91282011-08-31 11:23:23 +02001238/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001239CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001240{
1241 CElementLocator elementLocator(getSystemClass(), false);
1242
1243 CElement* pLocatedElement = NULL;
1244
1245 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1246
Patrick Benavoli63499d42011-10-24 18:50:03 +02001247 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001248 }
1249
1250 strResult = string("\n");
1251
1252 if (!pLocatedElement) {
1253
1254 // List from root folder
1255
1256 // Return system class qualified name
1257 pLocatedElement = getSystemClass();
1258 }
1259
1260 // Return sub-elements
1261 strResult += pLocatedElement->listQualifiedPaths(false);
1262
Patrick Benavoli63499d42011-10-24 18:50:03 +02001263 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001264}
1265
1266/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001267CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listParametersCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001268{
1269 CElementLocator elementLocator(getSystemClass(), false);
1270
1271 CElement* pLocatedElement = NULL;
1272
1273 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1274
Patrick Benavoli63499d42011-10-24 18:50:03 +02001275 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001276 }
1277
1278 strResult = string("\n");
1279
1280 if (!pLocatedElement) {
1281
1282 // List from root folder
1283
1284 // Return system class qualified name
1285 pLocatedElement = getSystemClass();
1286 }
1287
1288 // Return sub-elements
1289 strResult += pLocatedElement->listQualifiedPaths(true);
1290
Patrick Benavoli63499d42011-10-24 18:50:03 +02001291 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001292}
1293
Patrick Benavoli63499d42011-10-24 18:50:03 +02001294CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001295{
1296 CElementLocator elementLocator(getSystemClass());
1297
1298 CElement* pLocatedElement = NULL;
1299
1300 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1301
Patrick Benavoli63499d42011-10-24 18:50:03 +02001302 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001303 }
1304
1305 string strError;
1306
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001307 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001308
1309 // Dump elements
1310 pLocatedElement->dumpContent(strResult, parameterAccessContext);
1311
Patrick Benavoli63499d42011-10-24 18:50:03 +02001312 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001313}
1314
Patrick Benavoli63499d42011-10-24 18:50:03 +02001315CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSizeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001316{
1317 CElementLocator elementLocator(getSystemClass());
1318
1319 CElement* pLocatedElement = NULL;
1320
1321 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1322
Patrick Benavoli63499d42011-10-24 18:50:03 +02001323 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001324 }
1325
1326 // Converted to actual sizable element
1327 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1328
1329 // Get size as string
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001330 strResult = pConfigurableElement->getFootprintAsString();
Patrick Benavoli68a91282011-08-31 11:23:23 +02001331
Patrick Benavoli63499d42011-10-24 18:50:03 +02001332 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001333}
1334
Patrick Benavoli63499d42011-10-24 18:50:03 +02001335CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showPropertiesCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001336{
1337 CElementLocator elementLocator(getSystemClass());
1338
1339 CElement* pLocatedElement = NULL;
1340
1341 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1342
Patrick Benavoli63499d42011-10-24 18:50:03 +02001343 return CCommandHandler::EFailed;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001344 }
1345
1346 // Convert element
1347 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1348
1349 // Return element properties
1350 pConfigurableElement->showProperties(strResult);
1351
Patrick Benavoli63499d42011-10-24 18:50:03 +02001352 return CCommandHandler::ESucceeded;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001353}
1354
Patrick Benavoli63499d42011-10-24 18:50:03 +02001355CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001356{
1357 string strValue;
1358
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001359 if (!accessParameterValue(remoteCommand.getArgument(0), strValue, false, strResult)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001360
Patrick Benavoli63499d42011-10-24 18:50:03 +02001361 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001362 }
1363 // Succeeded
1364 strResult = strValue;
1365
Patrick Benavoli63499d42011-10-24 18:50:03 +02001366 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001367}
1368
Patrick Benavoli63499d42011-10-24 18:50:03 +02001369CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001370{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001371 // Check tuning mode
1372 if (!checkTuningModeOn(strResult)) {
1373
1374 return CCommandHandler::EFailed;
1375 }
1376 // Get value to set
1377 string strValue = remoteCommand.packArguments(1, remoteCommand.getArgumentCount() - 1);
1378
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001379 return accessParameterValue(remoteCommand.getArgument(0), strValue, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001380}
1381
Patrick Benavoli63499d42011-10-24 18:50:03 +02001382CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listBelongingDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001383{
1384 CElementLocator elementLocator(getSystemClass());
1385
1386 CElement* pLocatedElement = NULL;
1387
1388 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1389
Patrick Benavoli63499d42011-10-24 18:50:03 +02001390 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001391 }
1392
1393 // Convert element
1394 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1395
1396 // Return element belonging domains
1397 pConfigurableElement->listBelongingDomains(strResult);
1398
Patrick Benavoli63499d42011-10-24 18:50:03 +02001399 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001400}
1401
Patrick Benavoli63499d42011-10-24 18:50:03 +02001402CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001403{
1404 CElementLocator elementLocator(getSystemClass());
1405
1406 CElement* pLocatedElement = NULL;
1407
1408 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1409
Patrick Benavoli63499d42011-10-24 18:50:03 +02001410 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001411 }
1412
1413 // Convert element
1414 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1415
1416 // Return element belonging domains
1417 pConfigurableElement->listAssociatedDomains(strResult);
1418
Patrick Benavoli63499d42011-10-24 18:50:03 +02001419 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001420}
1421
Patrick Benavoli63499d42011-10-24 18:50:03 +02001422CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001423{
1424 (void)remoteCommand;
1425
1426 getConfigurableDomains()->listAssociatedElements(strResult);
1427
Patrick Benavoli63499d42011-10-24 18:50:03 +02001428 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001429}
1430
Patrick Benavoli63499d42011-10-24 18:50:03 +02001431CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConflictingElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001432{
1433 (void)remoteCommand;
1434
1435 getConfigurableDomains()->listConflictingElements(strResult);
1436
Patrick Benavoli63499d42011-10-24 18:50:03 +02001437 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001438}
1439
Patrick Benavoli63499d42011-10-24 18:50:03 +02001440CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listRogueElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001441{
1442 (void)remoteCommand;
1443
1444 getSystemClass()->listRogueElements(strResult);
1445
Patrick Benavoli63499d42011-10-24 18:50:03 +02001446 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001447}
1448
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001449CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getConfigurationParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1450{
1451 string strOutputValue;
1452 string strError;
1453
1454 if (!accessConfigurationValue(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), strOutputValue, false, strError)) {
1455
1456 strResult = strError;
1457 return CCommandHandler::EFailed;
1458 }
1459 // Succeeded
1460 strResult = strOutputValue;
1461
1462 return CCommandHandler::ESucceeded;
1463}
1464
1465CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setConfigurationParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1466{
1467 // Get value to set
1468 string strValue = remoteCommand.packArguments(3, remoteCommand.getArgumentCount() - 3);
1469
1470 bool bSuccess = accessConfigurationValue(remoteCommand.getArgument(0),
1471 remoteCommand.getArgument(1),
1472 remoteCommand.getArgument(2),
1473 strValue, true, strResult);
1474
1475 return bSuccess ? CCommandHandler::EDone : CCommandHandler::EFailed;
1476}
1477
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +02001478CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showMappingCommmandProcess(
1479 const IRemoteCommand& remoteCommand,
1480 string& strResult)
1481{
1482 if (!getParameterMapping(remoteCommand.getArgument(0), strResult)) {
1483
1484 return CCommandHandler::EFailed;
1485 }
1486
1487 return CCommandHandler::ESucceeded;
1488}
1489
Patrick Benavoli68a91282011-08-31 11:23:23 +02001490/// Settings Import/Export
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001491CParameterMgr::CCommandHandler::CommandStatus
1492 CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess(
1493 const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001494{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001495 string strFileName = remoteCommand.getArgument(0);
1496 return exportDomainsXml(strFileName, false, true, strResult) ?
1497 CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001498}
1499
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001500CParameterMgr::CCommandHandler::CommandStatus
1501 CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess(
1502 const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001503{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001504 return importDomainsXml(remoteCommand.getArgument(0), false, true, strResult) ?
1505 CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001506}
1507
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001508CParameterMgr::CCommandHandler::CommandStatus
1509 CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess(
1510 const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001511{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001512 string strFileName = remoteCommand.getArgument(0);
1513 return exportDomainsXml(strFileName, true, true, strResult) ?
1514 CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001515}
1516
Patrick Benavoli63499d42011-10-24 18:50:03 +02001517CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001518{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001519 return importDomainsXml(remoteCommand.getArgument(0), true, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001520}
1521
Patrick Benavoli63499d42011-10-24 18:50:03 +02001522CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001523{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001524 return exportDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001525}
1526
Patrick Benavoli63499d42011-10-24 18:50:03 +02001527CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001528{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001529 return importDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001530}
1531
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001532CParameterMgr::CCommandHandler::CommandStatus
1533 CParameterMgr::getConfigurableDomainsWithSettingsXMLCommmandProcess(
1534 const IRemoteCommand& remoteCommand, string& strResult)
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001535{
1536 (void)remoteCommand;
1537
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001538 if (!exportDomainsXml(strResult, true, false, strResult)) {
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001539
1540 return CCommandHandler::EFailed;
1541 }
1542 // Succeeded
1543 return CCommandHandler::ESucceeded;
1544}
1545
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001546CParameterMgr::CCommandHandler::CommandStatus
David Wagnered744eb2014-12-04 18:38:52 +01001547 CParameterMgr::getConfigurableDomainWithSettingsXMLCommmandProcess(
1548 const IRemoteCommand& remoteCommand, string& strResult)
1549{
1550 string strDomainName = remoteCommand.getArgument(0);
1551
1552 return exportSingleDomainXml(strResult, strDomainName, true, false, strResult) ?
1553 CCommandHandler::ESucceeded : CCommandHandler::EFailed;
1554}
1555
1556CParameterMgr::CCommandHandler::CommandStatus
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001557 CParameterMgr::setConfigurableDomainsWithSettingsXMLCommmandProcess(
1558 const IRemoteCommand& remoteCommand, string& strResult)
1559{
1560 return importDomainsXml(remoteCommand.getArgument(0), true, false, strResult) ?
1561 CCommandHandler::EDone : CCommandHandler::EFailed;
1562}
1563
1564CParameterMgr::CCommandHandler::CommandStatus
1565 CParameterMgr::getSystemClassXMLCommmandProcess(
1566 const IRemoteCommand& remoteCommand, string& strResult)
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001567{
1568 (void)remoteCommand;
1569
1570 if (!getSystemClassXMLString(strResult)) {
1571
1572 return CCommandHandler::EFailed;
1573 }
1574 // Succeeded
1575 return CCommandHandler::ESucceeded;
1576}
1577
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001578// User set/get parameters in main BlackBoard
1579bool CParameterMgr::accessParameterValue(const string& strPath, string& strValue, bool bSet, string& strError)
1580{
1581 // Define context
1582 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
1583
Frédéric Boisnard150407c2013-03-15 14:46:23 +01001584 // Activate the auto synchronization with the hardware
1585 if (bSet) {
1586
1587 parameterAccessContext.setAutoSync(_bAutoSyncOn);
1588 }
1589
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001590 return accessValue(parameterAccessContext, strPath, strValue, bSet, strError);
1591}
1592
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +02001593// User get parameter mapping
1594bool CParameterMgr::getParameterMapping(const string& strPath, string& strResult) const
1595{
1596 CPathNavigator pathNavigator(strPath);
1597
1598 // Nagivate through system class
1599 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strResult)) {
1600
1601 return false;
1602 }
1603
1604 // Get the ConfigurableElement corresponding to strPath
1605 const CConfigurableElement* pConfigurableElement = getConfigurableElement(strPath, strResult);
1606 if (!pConfigurableElement) {
1607
1608 return false;
1609 }
1610
1611 // Find the list of the ancestors of the current ConfigurableElement that have a mapping
1612 list<const CConfigurableElement*> configurableElementPath;
1613 pConfigurableElement->getListOfElementsWithMapping(configurableElementPath);
1614
1615 // Get the Subsystem containing the ConfigurableElement
1616 const CSubsystem* pSubsystem = pConfigurableElement->getBelongingSubsystem();
1617 if (!pSubsystem) {
1618
1619 strResult = "Unable to find the Subsystem containing the parameter";
1620 return false;
1621 }
1622
1623 // Fetch the mapping corresponding to the ConfigurableElement
1624 strResult = pSubsystem->getMapping(configurableElementPath);
1625
1626 return true;
1627}
1628
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001629// User set/get parameters in specific Configuration BlackBoard
1630bool CParameterMgr::accessConfigurationValue(const string& strDomain, const string& strConfiguration, const string& strPath, string& strValue, bool bSet, string& strError)
1631{
1632 CElementLocator elementLocator(getSystemClass());
1633
1634 CElement* pLocatedElement = NULL;
1635
1636 if (!elementLocator.locate(strPath, &pLocatedElement, strError)) {
1637
1638 return false;
1639 }
1640
1641 // Convert element
1642 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1643
1644 // Get the Configuration blackboard and the Base Offset of the configurable element in this blackboard
1645 uint32_t uiBaseOffset;
1646 bool bIsLastApplied;
1647
1648 CParameterBlackboard* pConfigurationBlackboard = getConstConfigurableDomains()->findConfigurationBlackboard(strDomain, strConfiguration, pConfigurableElement, uiBaseOffset, bIsLastApplied, strError);
1649
1650 if (!pConfigurationBlackboard) {
1651
1652 return false;
1653 }
1654
1655 log_info("Element %s in Domain %s, offset: %d, base offset: %d", strPath.c_str(), strDomain.c_str(), pConfigurableElement->getOffset(), uiBaseOffset);
1656
1657 /// Update the Configuration Blackboard
1658
Frédéric Boisnard150407c2013-03-15 14:46:23 +01001659 // Define Configuration context using Base Offset and keep Auto Sync off to prevent access to HW
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001660 CParameterAccessContext parameterAccessContext(strError, pConfigurationBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex, uiBaseOffset);
1661
Frédéric Boisnardda8298c2014-05-23 19:05:31 +02001662 // Deactivate the auto synchronization with the hardware during the Configuration Blackboard
1663 // access (only Main Blackboard shall be synchronized, Configurations Blackboards are copied
1664 // into the Main Blackboard each time a configuration is restored but they are not synchronized
1665 // directly).
1666 if (bSet) {
1667
1668 parameterAccessContext.setAutoSync(false);
1669 }
1670
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001671 // Access Value in the Configuration Blackboard
1672 if (!accessValue(parameterAccessContext, strPath, strValue, bSet, strError)) {
1673
1674 return false;
1675 }
1676
1677 /// If the Configuration is the last one applied, update the Main Blackboard as well
1678
1679 if (bIsLastApplied) {
1680
1681 // Define Main context
1682 parameterAccessContext.setParameterBlackboard(_pMainParameterBlackboard);
1683
Frédéric Boisnard150407c2013-03-15 14:46:23 +01001684 // Activate the auto synchronization with the hardware
1685 if (bSet) {
1686
1687 parameterAccessContext.setAutoSync(_bAutoSyncOn);
1688 }
1689
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001690 // Access Value in the Main Blackboard
1691 return accessValue(parameterAccessContext, strPath, strValue, bSet, strError);
1692 }
1693
1694 return true;
1695}
1696
Patrick Benavoli68a91282011-08-31 11:23:23 +02001697// User set/get parameters
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001698bool CParameterMgr::accessValue(CParameterAccessContext& parameterAccessContext, const string& strPath, string& strValue, bool bSet, string& strError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001699{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001700 // Lock state
1701 CAutoLock autoLock(&_blackboardMutex);
1702
1703 CPathNavigator pathNavigator(strPath);
1704
1705 // Nagivate through system class
1706 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001707
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +02001708 parameterAccessContext.setError(strError);
1709
Patrick Benavoli68a91282011-08-31 11:23:23 +02001710 return false;
1711 }
1712
Patrick Benavoli065264a2011-11-20 15:46:41 +01001713 // Do the get
1714 return getConstSystemClass()->accessValue(pathNavigator, strValue, bSet, parameterAccessContext);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001715}
1716
1717// Tuning mode
1718bool CParameterMgr::setTuningMode(bool bOn, string& strError)
1719{
1720 // Tuning allowed?
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001721 if (bOn && !getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001722
1723 strError = "Tuning prohibited";
1724
1725 return false;
1726 }
1727 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +01001728 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001729
1730 // Warn domains about exiting tuning mode
1731 if (!bOn && _bTuningModeIsOn) {
1732
1733 // Ensure application of currently selected configurations
Patrick Benavoli1387bda2011-08-31 11:23:24 +02001734 // Force-apply configurations
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01001735 doApplyConfigurations(true);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001736
Patrick Benavoli68a91282011-08-31 11:23:23 +02001737 // Turn auto sync back on
1738 _bAutoSyncOn = true;
1739 }
1740
1741 // Store
1742 _bTuningModeIsOn = bOn;
1743
Patrick Benavoli68a91282011-08-31 11:23:23 +02001744 return true;
1745}
1746
1747bool CParameterMgr::tuningModeOn() const
1748{
1749 return _bTuningModeIsOn;
1750}
1751
1752// Current value space for user set/get value interpretation
1753void CParameterMgr::setValueSpace(bool bIsRaw)
1754{
1755 _bValueSpaceIsRaw = bIsRaw;
1756}
1757
1758bool CParameterMgr::valueSpaceIsRaw()
1759{
1760 return _bValueSpaceIsRaw;
1761}
1762
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001763// Current Output Raw Format for user get value interpretation
1764void CParameterMgr::setOutputRawFormat(bool bIsHex)
1765{
1766 _bOutputRawFormatIsHex = bIsHex;
1767}
1768
1769bool CParameterMgr::outputRawFormatIsHex()
1770{
1771 return _bOutputRawFormatIsHex;
1772}
1773
Patrick Benavoli68a91282011-08-31 11:23:23 +02001774/// Sync
1775// Automatic hardware synchronization control (during tuning session)
1776bool CParameterMgr::setAutoSync(bool bAutoSyncOn, string& strError)
1777{
1778 // Check tuning mode
1779 if (!checkTuningModeOn(strError)) {
1780
1781 return false;
1782 }
1783 // Warn domains about turning auto sync back on
1784 if (bAutoSyncOn && !_bAutoSyncOn) {
1785
Patrick Benavoli592ae562011-09-05 16:53:58 +02001786 // Do the synchronization at system class level (could be optimized by keeping track of all modified parameters)
1787 if (!sync(strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001788
1789 return false;
1790 }
1791 }
1792
1793 // Set Auto sync
1794 _bAutoSyncOn = bAutoSyncOn;
1795
1796 return true;
1797}
1798
1799bool CParameterMgr::autoSyncOn() const
1800{
1801 return _bAutoSyncOn;
1802}
1803
1804// Manual hardware synchronization control (during tuning session)
1805bool CParameterMgr::sync(string& strError)
1806{
1807 // Check tuning mode
1808 if (!checkTuningModeOn(strError)) {
1809
1810 return false;
1811 }
1812 // Warn domains about turning auto sync back on
1813 if (_bAutoSyncOn) {
1814
1815 strError = "Feature unavailable when Auto Sync is on";
1816
1817 return false;
1818 }
1819
1820 // Get syncer set
1821 CSyncerSet syncerSet;
1822 // ... from system class
1823 getConstSystemClass()->fillSyncerSet(syncerSet);
Kevin Rocardace81f82012-12-11 16:19:17 +01001824
Patrick Benavoli68a91282011-08-31 11:23:23 +02001825 // Sync
Kevin Rocardace81f82012-12-11 16:19:17 +01001826 list<string> lstrError;
1827 if (! syncerSet.sync(*_pMainParameterBlackboard, false, &lstrError)){
1828
Frederic Boisnard390b36d2013-05-23 15:28:31 +02001829 CUtility::asString(lstrError, strError);
Kevin Rocardace81f82012-12-11 16:19:17 +01001830 return false;
1831 };
1832
1833 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001834}
1835
1836// Content dump
1837void CParameterMgr::logStructureContent(string& strContent) const
1838{
1839 string strError;
1840
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001841 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001842
1843 dumpContent(strContent, parameterAccessContext);
1844}
1845
1846// Configuration/Domains handling
1847bool CParameterMgr::createDomain(const string& strName, string& strError)
1848{
1849 // Check tuning mode
1850 if (!checkTuningModeOn(strError)) {
1851
1852 return false;
1853 }
1854
1855 // Delegate to configurable domains
1856 return getConfigurableDomains()->createDomain(strName, strError);
1857}
1858
1859bool CParameterMgr::deleteDomain(const string& strName, string& strError)
1860{
1861 // Check tuning mode
1862 if (!checkTuningModeOn(strError)) {
1863
1864 return false;
1865 }
1866
1867 // Delegate to configurable domains
1868 return getConfigurableDomains()->deleteDomain(strName, strError);
1869}
1870
Kevin Rocard170f0a42012-06-18 13:56:05 +02001871bool CParameterMgr::deleteAllDomains(string& strError)
1872{
1873 // Check tuning mode
1874 if (!checkTuningModeOn(strError)) {
1875
1876 return false;
1877 }
1878
1879 // Delegate to configurable domains
1880 getConfigurableDomains()->deleteAllDomains();
1881
1882 return true;
1883}
1884
Patrick Benavoli68a91282011-08-31 11:23:23 +02001885bool CParameterMgr::createConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1886{
1887 // Check tuning mode
1888 if (!checkTuningModeOn(strError)) {
1889
1890 return false;
1891 }
1892
1893 // Delegate to configurable domains
1894 return getConfigurableDomains()->createConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1895}
1896
1897bool CParameterMgr::deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1898{
1899 // Check tuning mode
1900 if (!checkTuningModeOn(strError)) {
1901
1902 return false;
1903 }
1904
1905 // Delegate to configurable domains
1906 return getConfigurableDomains()->deleteConfiguration(strDomain, strConfiguration, strError);
1907}
1908
Kevin Rocardace81f82012-12-11 16:19:17 +01001909bool CParameterMgr::restoreConfiguration(const string& strDomain, const string& strConfiguration, list<string>& lstrError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001910{
Kevin Rocardace81f82012-12-11 16:19:17 +01001911 string strError;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001912 // Check tuning mode
1913 if (!checkTuningModeOn(strError)) {
1914
Kevin Rocardace81f82012-12-11 16:19:17 +01001915 lstrError.push_back(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001916 return false;
1917 }
1918
1919 // Delegate to configurable domains
Kevin Rocardace81f82012-12-11 16:19:17 +01001920 return getConstConfigurableDomains()->restoreConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, lstrError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001921}
1922
1923bool CParameterMgr::saveConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1924{
1925 // Check tuning mode
1926 if (!checkTuningModeOn(strError)) {
1927
1928 return false;
1929 }
1930
1931 // Delegate to configurable domains
1932 return getConfigurableDomains()->saveConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1933}
1934
1935// Configurable element - domain association
1936bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1937{
1938 // Check tuning mode
1939 if (!checkTuningModeOn(strError)) {
1940
1941 return false;
1942 }
1943
1944 CElementLocator elementLocator(getSystemClass());
1945
1946 CElement* pLocatedElement = NULL;
1947
1948 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1949
1950 return false;
1951 }
1952
1953 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001954 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001955
1956 // Delegate
1957 return getConfigurableDomains()->addConfigurableElementToDomain(strDomain, pConfigurableElement, _pMainParameterBlackboard, strError);
1958}
1959
1960bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1961{
1962 // Check tuning mode
1963 if (!checkTuningModeOn(strError)) {
1964
1965 return false;
1966 }
1967
1968 CElementLocator elementLocator(getSystemClass());
1969
1970 CElement* pLocatedElement = NULL;
1971
1972 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1973
Patrick Benavoli63499d42011-10-24 18:50:03 +02001974 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001975 }
1976
1977 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001978 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001979
1980 // Delegate
1981 return getConfigurableDomains()->removeConfigurableElementFromDomain(strDomain, pConfigurableElement, strError);
1982}
1983
1984bool CParameterMgr::split(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1985{
1986 // Check tuning mode
1987 if (!checkTuningModeOn(strError)) {
1988
1989 return false;
1990 }
1991
1992 CElementLocator elementLocator(getSystemClass());
1993
1994 CElement* pLocatedElement = NULL;
1995
1996 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1997
Patrick Benavoli63499d42011-10-24 18:50:03 +02001998 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001999 }
2000
2001 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04002002 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002003
2004 // Delegate
2005 return getConfigurableDomains()->split(strDomain, pConfigurableElement, strError);
2006}
2007
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002008bool CParameterMgr::importDomainsXml(const string& strXmlSource, bool bWithSettings,
2009 bool bFromFile, string& strError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02002010{
2011 // Check tuning mode
2012 if (!checkTuningModeOn(strError)) {
2013
2014 return false;
2015 }
2016
2017 // check path is absolute
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002018 if (bFromFile && strXmlSource[0] != '/') {
Patrick Benavoli68a91282011-08-31 11:23:23 +02002019
2020 strError = "Please provide absolute path";
2021
2022 return false;
2023 }
2024 // Root element
2025 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
2026
2027 // Context
David Wagnerd8a53102014-12-10 14:49:23 +01002028 CXmlDomainImportContext xmlDomainImportContext(strError, bWithSettings, *getSystemClass());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002029
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002030 // Selection criteria definition for rule creation
David Wagner29fa61f2014-12-19 11:15:02 +01002031 xmlDomainImportContext.setSelectionCriteriaDefinition(
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002032 getConstSelectionCriteria()->getSelectionCriteriaDefinition());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002033
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002034 // Init serializing context
David Wagner29fa61f2014-12-19 11:15:02 +01002035 xmlDomainImportContext.set(
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002036 _pElementLibrarySet->getElementLibrary(EParameterConfigurationLibrary),
2037 "", _strSchemaFolderLocation);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002038
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002039 // Get Schema file associated to root element
2040 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" +
2041 pConfigurableDomains->getKind() + ".xsd";
2042
2043 // Xml Source
2044 CXmlDocSource* pSource;
2045
2046 if (bFromFile) {
2047
2048 // when importing from a file strXmlSource is the file name
2049 pSource = new CXmlFileDocSource(strXmlSource, strXmlSchemaFilePath,
2050 pConfigurableDomains->getKind(),
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +02002051 pConfigurableDomains->getName(), "SystemClassName",
2052 _bValidateSchemasOnStart);
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002053
2054 } else {
2055
2056 // when importing from an xml string, strXmlSource contains the string
2057 pSource = new CXmlStringDocSource(strXmlSource, strXmlSchemaFilePath,
2058 pConfigurableDomains->getKind(),
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +02002059 pConfigurableDomains->getName(), "SystemClassName",
2060 _bValidateSchemasOnStart);
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002061
2062 }
2063 // Start clean
2064 pConfigurableDomains->clean();
2065
2066 // Use a doc sink that instantiate Configurable Domains from the given doc source
2067 CXmlMemoryDocSink memorySink(pConfigurableDomains);
2068
David Wagner29fa61f2014-12-19 11:15:02 +01002069 bool bProcessSuccess = memorySink.process(*pSource, xmlDomainImportContext);
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002070
2071 if (!bProcessSuccess) {
2072
2073 //Cleanup
2074 pConfigurableDomains->clean();
2075
2076 } else {
2077
2078 // Validate domains after XML import
2079 pConfigurableDomains->validate(_pMainParameterBlackboard);
2080
Patrick Benavoli68a91282011-08-31 11:23:23 +02002081 }
2082
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002083 delete pSource;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002084
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002085 return bProcessSuccess;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002086}
2087
David Wagnered744eb2014-12-04 18:38:52 +01002088bool CParameterMgr::serializeElement(string& strXmlDest,
2089 CXmlSerializingContext& xmlSerializingContext, bool bToFile,
2090 const CElement& element, string& strError) const
Patrick Benavoli68a91282011-08-31 11:23:23 +02002091{
2092 // check path is absolute
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002093 if (bToFile && strXmlDest[0] != '/') {
Patrick Benavoli68a91282011-08-31 11:23:23 +02002094
2095 strError = "Please provide absolute path";
2096
2097 return false;
2098 }
2099
Patrick Benavoli68a91282011-08-31 11:23:23 +02002100 // Get Schema file associated to root element
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002101 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" +
David Wagnered744eb2014-12-04 18:38:52 +01002102 element.getKind() + ".xsd";
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02002103
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002104 // Use a doc source by loading data from instantiated Configurable Domains
David Wagnered744eb2014-12-04 18:38:52 +01002105 CXmlMemoryDocSource memorySource(&element, element.getKind(),
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +02002106 strXmlSchemaFilePath, "parameter-framework",
2107 getVersion(), _bValidateSchemasOnStart);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002108
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002109 // Xml Sink
2110 CXmlDocSink* pSink;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002111
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002112 if (bToFile) {
2113
2114 // Use a doc sink to write the doc data in a file
2115 pSink = new CXmlFileDocSink(strXmlDest);
2116
2117 } else {
2118
2119 // Use a doc sink to write the doc data in a string
David Wagnered744eb2014-12-04 18:38:52 +01002120 // TODO: use a stream rather than a string
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002121 pSink = new CXmlStringDocSink(strXmlDest);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002122 }
2123
David Wagnered744eb2014-12-04 18:38:52 +01002124 bool bProcessSuccess = pSink->process(memorySource, xmlSerializingContext);
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002125
2126 delete pSink;
2127 return bProcessSuccess;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002128}
2129
David Wagnered744eb2014-12-04 18:38:52 +01002130bool CParameterMgr::exportDomainsXml(string& strXmlDest, bool bWithSettings, bool bToFile,
2131 string& strError) const
2132{
2133 const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains();
2134
2135 CXmlDomainExportContext xmlDomainExportContext(strError, bWithSettings);
2136
2137 xmlDomainExportContext.setValueSpaceRaw(_bValueSpaceIsRaw);
2138
2139 xmlDomainExportContext.setOutputRawFormat(_bOutputRawFormatIsHex);
2140
2141
2142 return serializeElement(strXmlDest, xmlDomainExportContext, bToFile,
2143 *pConfigurableDomains, strError);
2144}
2145
2146bool CParameterMgr::exportSingleDomainXml(string& strXmlDest, const string& strDomainName,
2147 bool bWithSettings, bool bToFile, string& strError) const
2148{
2149 const CConfigurableDomains* pAllDomains = getConstConfigurableDomains();
2150
2151 // Element to be serialized
2152 const CConfigurableDomain* pRequestedDomain =
2153 pAllDomains->findConfigurableDomain(strDomainName, strError);
2154
2155 if (!pRequestedDomain) {
2156 return false;
2157 }
2158
2159 CXmlDomainExportContext xmlDomainExportContext(strError, bWithSettings);
2160
2161 xmlDomainExportContext.setValueSpaceRaw(_bValueSpaceIsRaw);
2162
2163 xmlDomainExportContext.setOutputRawFormat(_bOutputRawFormatIsHex);
2164
2165 return serializeElement(strXmlDest, xmlDomainExportContext, bToFile,
2166 *pRequestedDomain, strError);
2167}
2168
Patrick Benavoli68a91282011-08-31 11:23:23 +02002169// Binary Import/Export
2170bool CParameterMgr::importDomainsBinary(const string& strFileName, string& strError)
2171{
2172 // Check tuning mode
2173 if (!checkTuningModeOn(strError)) {
2174
2175 return false;
2176 }
2177 // check path is absolute
2178 if (strFileName[0] != '/') {
2179
2180 strError = "Please provide absolute path";
2181
2182 return false;
2183 }
2184 // Root element
2185 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
2186
2187 // Serialize in
2188 return pConfigurableDomains->serializeSettings(strFileName, false, _uiStructureChecksum, strError);
2189}
2190
2191bool CParameterMgr::exportDomainsBinary(const string& strFileName, string& strError)
2192{
2193 // check path is absolute
2194 if (strFileName[0] != '/') {
2195
2196 strError = "Please provide absolute path";
2197
2198 return false;
2199 }
Patrick Benavoli68a91282011-08-31 11:23:23 +02002200
Patrick Benavoli68a91282011-08-31 11:23:23 +02002201 // Root element
2202 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
2203
2204 // Serialize out
2205 return pConfigurableDomains->serializeSettings(strFileName, true, _uiStructureChecksum, strError);
2206}
2207
2208// For tuning, check we're in tuning mode
2209bool CParameterMgr::checkTuningModeOn(string& strError) const
2210{
2211 // Tuning Mode on?
2212 if (!_bTuningModeIsOn) {
2213
2214 strError = "Tuning Mode must be on";
2215
2216 return false;
2217 }
2218 return true;
2219}
2220
Patrick Benavoli065264a2011-11-20 15:46:41 +01002221// Tuning mutex dynamic parameter handling
2222pthread_mutex_t* CParameterMgr::getBlackboardMutex()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002223{
Patrick Benavoli065264a2011-11-20 15:46:41 +01002224 return &_blackboardMutex;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002225}
2226
Patrick Benavoli065264a2011-11-20 15:46:41 +01002227// Blackboard reference (dynamic parameter handling)
2228CParameterBlackboard* CParameterMgr::getParameterBlackboard()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002229{
Patrick Benavoli065264a2011-11-20 15:46:41 +01002230 return _pMainParameterBlackboard;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002231}
2232
Patrick Benavoli68a91282011-08-31 11:23:23 +02002233// Dynamic creation library feeding
2234void CParameterMgr::feedElementLibraries()
2235{
2236 // Global Configuration handling
2237 CElementLibrary* pFrameworkConfigurationLibrary = new CElementLibrary;
2238
Kevin Rocarda7b69602013-08-07 16:15:33 +02002239 pFrameworkConfigurationLibrary->addElementBuilder("ParameterFrameworkConfiguration", new TElementBuilderTemplate<CParameterFrameworkConfiguration>());
2240 pFrameworkConfigurationLibrary->addElementBuilder("SubsystemPlugins", new TKindElementBuilderTemplate<CSubsystemPlugins>());
2241 pFrameworkConfigurationLibrary->addElementBuilder("Location", new TKindElementBuilderTemplate<CPluginLocation>());
2242 pFrameworkConfigurationLibrary->addElementBuilder("StructureDescriptionFileLocation", new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>());
2243 pFrameworkConfigurationLibrary->addElementBuilder("SettingsConfiguration", new TKindElementBuilderTemplate<CFrameworkConfigurationGroup>());
2244 pFrameworkConfigurationLibrary->addElementBuilder("ConfigurableDomainsFileLocation", new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>());
2245 pFrameworkConfigurationLibrary->addElementBuilder("BinarySettingsFileLocation", new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002246
2247 _pElementLibrarySet->addElementLibrary(pFrameworkConfigurationLibrary);
2248
2249 // Parameter creation
2250 CElementLibrary* pParameterCreationLibrary = new CElementLibrary;
2251
Kevin Rocarda7b69602013-08-07 16:15:33 +02002252 pParameterCreationLibrary->addElementBuilder("Subsystem", new CSubsystemElementBuilder(getSystemClass()->getSubsystemLibrary()));
2253 pParameterCreationLibrary->addElementBuilder("ComponentType", new TNamedElementBuilderTemplate<CComponentType>());
2254 pParameterCreationLibrary->addElementBuilder("Component", new TNamedElementBuilderTemplate<CComponentInstance>());
2255 pParameterCreationLibrary->addElementBuilder("BitParameter", new TNamedElementBuilderTemplate<CBitParameterType>());
2256 pParameterCreationLibrary->addElementBuilder("BitParameterBlock", new TNamedElementBuilderTemplate<CBitParameterBlockType>());
2257 pParameterCreationLibrary->addElementBuilder("StringParameter", new TNamedElementBuilderTemplate<CStringParameterType>());
2258 pParameterCreationLibrary->addElementBuilder("ParameterBlock", new TNamedElementBuilderTemplate<CParameterBlockType>());
2259 pParameterCreationLibrary->addElementBuilder("BooleanParameter", new TNamedElementBuilderTemplate<CBooleanParameterType>());
2260 pParameterCreationLibrary->addElementBuilder("IntegerParameter", new TNamedElementBuilderTemplate<CIntegerParameterType>());
2261 pParameterCreationLibrary->addElementBuilder("LinearAdaptation", new TElementBuilderTemplate<CLinearParameterAdaptation>());
2262 pParameterCreationLibrary->addElementBuilder("EnumParameter", new TNamedElementBuilderTemplate<CEnumParameterType>());
2263 pParameterCreationLibrary->addElementBuilder("ValuePair", new TElementBuilderTemplate<CEnumValuePair>());
2264 pParameterCreationLibrary->addElementBuilder("FixedPointParameter", new TNamedElementBuilderTemplate<CFixedPointParameterType>());
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +02002265 pParameterCreationLibrary->addElementBuilder("SubsystemInclude", new CFileIncluderElementBuilder(_bValidateSchemasOnStart));
Patrick Benavoli68a91282011-08-31 11:23:23 +02002266
2267 _pElementLibrarySet->addElementLibrary(pParameterCreationLibrary);
2268
2269 // Parameter Configuration Domains creation
2270 CElementLibrary* pParameterConfigurationLibrary = new CElementLibrary;
2271
Kevin Rocarda7b69602013-08-07 16:15:33 +02002272 pParameterConfigurationLibrary->addElementBuilder("ConfigurableDomain", new TNamedElementBuilderTemplate<CConfigurableDomain>());
2273 pParameterConfigurationLibrary->addElementBuilder("Configuration", new TNamedElementBuilderTemplate<CDomainConfiguration>());
2274 pParameterConfigurationLibrary->addElementBuilder("CompoundRule", new TElementBuilderTemplate<CCompoundRule>());
2275 pParameterConfigurationLibrary->addElementBuilder("SelectionCriterionRule", new TElementBuilderTemplate<CSelectionCriterionRule>());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002276
2277 _pElementLibrarySet->addElementLibrary(pParameterConfigurationLibrary);
2278}
2279
2280// Remote Processor Server connection handling
2281bool CParameterMgr::handleRemoteProcessingInterface(string& strError)
2282{
2283 CAutoLog autoLog(this, "Handling remote processing interface");
2284
2285 // Start server if tuning allowed
Patrick Benavoli95ac0342011-11-07 20:32:51 +01002286 if (getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02002287
Kevin Rocardace81f82012-12-11 16:19:17 +01002288 log_info("Loading remote processor library");
Patrick Benavoli68a91282011-08-31 11:23:23 +02002289
2290 // Load library
Renaud de Chivre1b8b3ca2013-12-13 15:09:44 +01002291 _handleLibRemoteProcessor = dlopen("libremote-processor.so", RTLD_NOW);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002292
Renaud de Chivre1b8b3ca2013-12-13 15:09:44 +01002293 if (!_handleLibRemoteProcessor) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02002294
2295 // Return error
2296 const char* pcError = dlerror();
2297
2298 if (pcError) {
2299
2300 strError = pcError;
2301 } else {
2302
2303 strError = "Unable to load libremote-processor.so library";
2304 }
2305
2306 return false;
2307 }
2308
Renaud de Chivre1b8b3ca2013-12-13 15:09:44 +01002309 CreateRemoteProcessorServer pfnCreateRemoteProcessorServer = (CreateRemoteProcessorServer)dlsym(_handleLibRemoteProcessor, "createRemoteProcessorServer");
Patrick Benavoli68a91282011-08-31 11:23:23 +02002310
2311 if (!pfnCreateRemoteProcessorServer) {
2312
2313 strError = "libremote-process.so does not contain createRemoteProcessorServer symbol.";
2314
2315 return false;
2316 }
2317
2318 // Create server
Patrick Benavoli95ac0342011-11-07 20:32:51 +01002319 _pRemoteProcessorServer = pfnCreateRemoteProcessorServer(getConstFrameworkConfiguration()->getServerPort(), _pCommandHandler);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002320
Kevin Rocardace81f82012-12-11 16:19:17 +01002321 log_info("Starting remote processor server on port %d", getConstFrameworkConfiguration()->getServerPort());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002322 // Start
2323 if (!_pRemoteProcessorServer->start()) {
2324
Frédéric Boisnard6c55e9a2014-01-10 18:46:33 +01002325 ostringstream oss;
2326 oss << "ParameterMgr: Unable to start remote processor server on port "
2327 << getConstFrameworkConfiguration()->getServerPort();
2328 strError = oss.str();
Patrick Benavoli68a91282011-08-31 11:23:23 +02002329
2330 return false;
2331 }
2332 }
2333
2334 return true;
2335}
2336
2337// Back synchronization
Kevin Rocardace81f82012-12-11 16:19:17 +01002338CBackSynchronizer* CParameterMgr::createBackSynchronizer() const
Patrick Benavoli68a91282011-08-31 11:23:23 +02002339{
2340#ifdef SIMULATION
2341 // In simulation, back synchronization of the blackboard won't probably work
2342 // We need to ensure though the blackboard is initialized with valid data
Kevin Rocardace81f82012-12-11 16:19:17 +01002343 return new CSimulatedBackSynchronizer(getConstSystemClass(), _pMainParameterBlackboard);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002344#else
2345 // Real back synchronizer from subsystems
Kevin Rocardace81f82012-12-11 16:19:17 +01002346 return new CHardwareBackSynchronizer(getConstSystemClass(), _pMainParameterBlackboard);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002347#endif
2348}
2349
2350// Children typwise access
2351CParameterFrameworkConfiguration* CParameterMgr::getFrameworkConfiguration()
2352{
2353 return static_cast<CParameterFrameworkConfiguration*>(getChild(EFrameworkConfiguration));
2354}
2355
2356const CParameterFrameworkConfiguration* CParameterMgr::getConstFrameworkConfiguration()
2357{
2358 return getFrameworkConfiguration();
2359}
2360
2361CSelectionCriteria* CParameterMgr::getSelectionCriteria()
2362{
2363 return static_cast<CSelectionCriteria*>(getChild(ESelectionCriteria));
2364}
2365
2366const CSelectionCriteria* CParameterMgr::getConstSelectionCriteria()
2367{
2368 return static_cast<const CSelectionCriteria*>(getChild(ESelectionCriteria));
2369}
2370
2371CSystemClass* CParameterMgr::getSystemClass()
2372{
2373 return static_cast<CSystemClass*>(getChild(ESystemClass));
2374}
2375
2376const CSystemClass* CParameterMgr::getConstSystemClass() const
2377{
2378 return static_cast<const CSystemClass*>(getChild(ESystemClass));
2379}
2380
2381// Configurable Domains
2382CConfigurableDomains* CParameterMgr::getConfigurableDomains()
2383{
2384 return static_cast<CConfigurableDomains*>(getChild(EConfigurableDomains));
2385}
2386
2387const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains()
2388{
2389 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
2390}
2391
2392const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains() const
2393{
2394 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
2395}
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002396
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01002397// Apply configurations
2398void CParameterMgr::doApplyConfigurations(bool bForce)
2399{
2400 CSyncerSet syncerSet;
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002401
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01002402 // Check subsystems that need resync
2403 getSystemClass()->checkForSubsystemsToResync(syncerSet);
2404
2405 // Ensure application of currently selected configurations
2406 getConfigurableDomains()->apply(_pMainParameterBlackboard, syncerSet, bForce);
2407
2408 // Reset the modified status of the current criteria to indicate that a new configuration has been applied
2409 getSelectionCriteria()->resetModifiedStatus();
2410}
2411
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002412bool CParameterMgr::getSystemClassXMLString(string& strResult)
2413{
2414 // Root element
2415 const CSystemClass* pSystemClass = getSystemClass();
2416
2417 string strError;
2418
2419 CXmlSerializingContext xmlSerializingContext(strError);
2420
2421 // Use a doc source by loading data from instantiated Configurable Domains
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +02002422 CXmlMemoryDocSource memorySource(pSystemClass, pSystemClass->getKind(),
2423 _bValidateSchemasOnStart);
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002424
2425 // Use a doc sink that write the doc data in a string
2426 CXmlStringDocSink stringSink(strResult);
2427
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002428 bool bProcessSuccess = stringSink.process(memorySource, xmlSerializingContext);
2429
2430 if (!bProcessSuccess) {
2431
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002432 strResult = strError;
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002433
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002434 }
2435
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002436 return bProcessSuccess;
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002437}