blob: 749aacd50b8eb2b1368a64a5012130d05f5da02d [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" },
Georges-Henri Baroncec86c12012-09-04 17:30:28 +0200269 { "setDomainsWithSettingsXML",
270 &CParameterMgr::setConfigurableDomainsWithSettingsXMLCommmandProcess, 1,
271 "<xml configurable domains>", "Import domains including settings from XML string" },
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200272 /// Structure Export
Kevin Rocard3949b342013-05-24 18:43:53 +0200273 { "getSystemClassXML", &CParameterMgr::getSystemClassXMLCommmandProcess, 0 ,
Kevin Rocardc0211572013-06-18 11:34:53 +0200274 "", "Print parameter structure as XML" },
275 /// Deprecated Commands
276 { "getDomainsXML",
277 &CParameterMgr::getConfigurableDomainsWithSettingsXMLCommmandProcess, 0,
278 "", "DEPRECATED COMMAND, please use getDomainsWithSettingsXML" },
Georges-Henri Baroncec86c12012-09-04 17:30:28 +0200279
Patrick Benavoli68a91282011-08-31 11:23:23 +0200280};
Kevin Rocard3949b342013-05-24 18:43:53 +0200281
Patrick Benavoli68a91282011-08-31 11:23:23 +0200282// Remote command parsers array Size
Patrick Benavoli592ae562011-09-05 16:53:58 +0200283const uint32_t CParameterMgr::guiNbRemoteCommandParserItems = sizeof(gastRemoteCommandParserItems) / sizeof(gastRemoteCommandParserItems[0]);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200284
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100285CParameterMgr::CParameterMgr(const string& strConfigurationFilePath) :
Patrick Benavoli68a91282011-08-31 11:23:23 +0200286 _bTuningModeIsOn(false),
287 _bValueSpaceIsRaw(false),
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200288 _bOutputRawFormatIsHex(false),
Patrick Benavoli68a91282011-08-31 11:23:23 +0200289 _bAutoSyncOn(true),
290 _pMainParameterBlackboard(new CParameterBlackboard),
291 _pElementLibrarySet(new CElementLibrarySet),
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100292 _strXmlConfigurationFilePath(strConfigurationFilePath),
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100293 _pSubsystemPlugins(NULL),
Renaud de Chivre1b8b3ca2013-12-13 15:09:44 +0100294 _handleLibRemoteProcessor(NULL),
Patrick Benavoli68a91282011-08-31 11:23:23 +0200295 _uiStructureChecksum(0),
296 _pRemoteProcessorServer(NULL),
297 _uiMaxCommandUsageLength(0),
298 _pLogger(NULL),
Kevin Rocardecf93102013-07-10 18:28:10 +0200299 _uiLogDepth(0),
Kevin Rocardd6909eb2013-07-18 09:13:51 +0200300 _bFailOnMissingSubsystem(true),
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +0200301 _bFailOnFailedSettingsLoad(true),
302 _bValidateSchemasOnStart(false)
303
Patrick Benavoli68a91282011-08-31 11:23:23 +0200304{
305 // Tuning Mode Mutex
Patrick Benavoli065264a2011-11-20 15:46:41 +0100306 bzero(&_blackboardMutex, sizeof(_blackboardMutex));
307 pthread_mutex_init(&_blackboardMutex, NULL);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200308
309 // Deal with children
310 addChild(new CParameterFrameworkConfiguration);
311 addChild(new CSelectionCriteria);
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100312 addChild(new CSystemClass);
313 addChild(new CConfigurableDomains);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200314
Patrick Benavoli63499d42011-10-24 18:50:03 +0200315 _pCommandHandler = new CCommandHandler(this);
316
317 // Add command parsers
318 uint32_t uiRemoteCommandParserItem;
319
320 for (uiRemoteCommandParserItem = 0; uiRemoteCommandParserItem < guiNbRemoteCommandParserItems; uiRemoteCommandParserItem++) {
321
322 const SRemoteCommandParserItem* pRemoteCommandParserItem = &gastRemoteCommandParserItems[uiRemoteCommandParserItem];
323
324 _pCommandHandler->addCommandParser(pRemoteCommandParserItem->_pcCommandName,
325 pRemoteCommandParserItem->_pfnParser,
326 pRemoteCommandParserItem->_uiMinArgumentCount,
327 pRemoteCommandParserItem->_pcHelp,
328 pRemoteCommandParserItem->_pcDescription);
329 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100330
331 // Configuration file folder
332 uint32_t uiSlashPos = _strXmlConfigurationFilePath.rfind('/', -1);
333
334 assert(uiSlashPos != (uint32_t)-1);
335
336 _strXmlConfigurationFolderPath = _strXmlConfigurationFilePath.substr(0, uiSlashPos);
337
338 // Schema absolute folder location
339 _strSchemaFolderLocation = _strXmlConfigurationFolderPath + "/" + gacSystemSchemasSubFolder;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200340}
341
342CParameterMgr::~CParameterMgr()
343{
344 // Children
345 delete _pRemoteProcessorServer;
Frederic Boisnard31242302012-04-26 17:07:34 +0200346 delete _pCommandHandler;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200347 delete _pMainParameterBlackboard;
348 delete _pElementLibrarySet;
349
Renaud de Chivre1b8b3ca2013-12-13 15:09:44 +0100350 // Close remote processor library
351 if (_handleLibRemoteProcessor != NULL) {
352 dlclose(_handleLibRemoteProcessor);
353 }
354
Patrick Benavoli68a91282011-08-31 11:23:23 +0200355 // Tuning Mode Mutex
Patrick Benavoli065264a2011-11-20 15:46:41 +0100356 pthread_mutex_destroy(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200357}
358
359string CParameterMgr::getKind() const
360{
361 return "ParameterMgr";
362}
363
364// Logging
365void CParameterMgr::setLogger(CParameterMgr::ILogger* pLogger)
366{
367 _pLogger = pLogger;
368}
369
370// Logging
Kevin Rocardace81f82012-12-11 16:19:17 +0100371void CParameterMgr::doLog(bool bIsWarning, const string& strLog) const
Patrick Benavoli68a91282011-08-31 11:23:23 +0200372{
373 if (_pLogger) {
374
375 // Nest
376 string strIndent;
377
378 // Level
379 uint32_t uiNbIndents = _uiLogDepth;
380
381 while (uiNbIndents--) {
382
383 strIndent += " ";
384 }
385
386 // Log
Kevin Rocardace81f82012-12-11 16:19:17 +0100387 _pLogger->log(bIsWarning, strIndent + strLog);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200388 }
389}
390
391void CParameterMgr::nestLog() const
392{
Patrick Benavoli592ae562011-09-05 16:53:58 +0200393 _uiLogDepth++;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200394}
395
396void CParameterMgr::unnestLog() const
397{
Patrick Benavoli592ae562011-09-05 16:53:58 +0200398 _uiLogDepth--;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200399}
400
Patrick Benavoli63499d42011-10-24 18:50:03 +0200401// Version
402string CParameterMgr::getVersion() const
403{
404 string strVersion;
405
406 // Major
407 strVersion = toString(guiEditionMajor) + ".";
408 // Minor
409 strVersion += toString(guiEditionMinor) + ".";
410 // Revision
411 strVersion += toString(guiRevision);
412
413 return strVersion;
414}
415
Patrick Benavoli68a91282011-08-31 11:23:23 +0200416bool CParameterMgr::load(string& strError)
417{
418 CAutoLog autoLog(this, "Loading");
419
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +0200420 feedElementLibraries();
421
Patrick Benavoli68a91282011-08-31 11:23:23 +0200422 // Load Framework configuration
423 if (!loadFrameworkConfiguration(strError)) {
424
425 return false;
426 }
427
428 // Load subsystems
Kevin Rocardecf93102013-07-10 18:28:10 +0200429 if (!getSystemClass()->loadSubsystems(strError,
430 _pSubsystemPlugins, !_bFailOnMissingSubsystem)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200431
432 return false;
433 }
434
435 // Load structure
436 if (!loadStructure(strError)) {
437
438 return false;
439 }
440
441 // Load settings
442 if (!loadSettings(strError)) {
443
444 return false;
445 }
446
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200447 // Back synchronization for areas in parameter blackboard not covered by any domain
Kevin Rocardace81f82012-12-11 16:19:17 +0100448 CBackSynchronizer* pBackSynchronizer = createBackSynchronizer();
Patrick Benavoli68a91282011-08-31 11:23:23 +0200449
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200450 // Back-synchronize
Kevin Rocard57096bd2012-11-30 11:24:20 +0100451 {
452 CAutoLog autoLog(this, "Main blackboard back synchronization");
453
Kevin Rocard5d6e05a2013-01-21 15:57:45 +0100454 pBackSynchronizer->sync();
Kevin Rocard57096bd2012-11-30 11:24:20 +0100455
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200456 // Get rid of back synchronizer
457 delete pBackSynchronizer;
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200458 }
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200459
460 // We're done loading the settings and back synchronizing
461 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
462
463 // We need to ensure all domains are valid
464 pConfigurableDomains->validate(_pMainParameterBlackboard);
465
Kevin Rocard7f265822012-12-07 18:51:22 +0100466 // Log selection criterion states
467 {
468 CAutoLog autoLog(this, "Criterion states");
469
470 const CSelectionCriteria* selectionCriteria = getConstSelectionCriteria();
471
472 list<string> lstrSelectionCriteron;
473 selectionCriteria->listSelectionCriteria(lstrSelectionCriteron, true, false);
474
Kevin Rocard36299362013-02-04 14:57:47 +0100475 log_table(false, lstrSelectionCriteron);
Kevin Rocard7f265822012-12-07 18:51:22 +0100476 }
477
Kevin Rocard2fbe6e82013-03-26 17:09:29 +0100478 // Subsystem can not ask for resync as they have not been synced yet
479 getSystemClass()->cleanSubsystemsNeedToResync();
480
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100481 // At initialization, check subsystems that need resync
482 doApplyConfigurations(true);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200483
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200484 // Start remote processor server if appropriate
485 return handleRemoteProcessingInterface(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200486}
487
488bool CParameterMgr::loadFrameworkConfiguration(string& strError)
489{
490 CAutoLog autoLog(this, "Loading framework configuration");
491
Patrick Benavoli68a91282011-08-31 11:23:23 +0200492 // Parse Structure XML file
493 CXmlElementSerializingContext elementSerializingContext(strError);
494
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100495 if (!xmlParse(elementSerializingContext, getFrameworkConfiguration(), _strXmlConfigurationFilePath, _strXmlConfigurationFolderPath, EFrameworkConfigurationLibrary)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200496
497 return false;
498 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100499 // Set class name to system class and configurable domains
500 getSystemClass()->setName(getConstFrameworkConfiguration()->getSystemClassName());
501 getConfigurableDomains()->setName(getConstFrameworkConfiguration()->getSystemClassName());
502
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100503 // Get subsystem plugins elements
504 _pSubsystemPlugins = static_cast<const CSubsystemPlugins*>(getConstFrameworkConfiguration()->findChild("SubsystemPlugins"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200505
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100506 if (!_pSubsystemPlugins) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200507
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100508 strError = "Parameter Framework Configuration: couldn't find SubsystemPlugins element";
Patrick Benavoli68a91282011-08-31 11:23:23 +0200509
510 return false;
511 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200512
Patrick Benavoli68a91282011-08-31 11:23:23 +0200513 // Log tuning availability
Kevin Rocardace81f82012-12-11 16:19:17 +0100514 log_info("Tuning %s", getConstFrameworkConfiguration()->isTuningAllowed() ? "allowed" : "prohibited");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200515
516 return true;
517}
518
519bool CParameterMgr::loadStructure(string& strError)
520{
521 // Retrieve system to load structure to
522 CSystemClass* pSystemClass = getSystemClass();
523
Kevin Rocarde25ee792013-04-22 17:46:28 +0200524 log_info("Loading " + pSystemClass->getName() + " system class structure");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200525
526 // Get structure description element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100527 const CFrameworkConfigurationLocation* pStructureDescriptionFileLocation = static_cast<const CFrameworkConfigurationLocation*>(getConstFrameworkConfiguration()->findChildOfKind("StructureDescriptionFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200528
529 if (!pStructureDescriptionFileLocation) {
530
531 strError = "No StructureDescriptionFileLocation element found for SystemClass " + pSystemClass->getName();
532
533 return false;
534 }
535
536 // Get Xml structure folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100537 string strXmlStructureFolder = pStructureDescriptionFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200538
539 // Get Xml structure file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100540 string strXmlStructureFilePath = pStructureDescriptionFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200541
542 // Parse Structure XML file
543 CXmlParameterSerializingContext parameterBuildContext(strError);
544
Kevin Rocard57096bd2012-11-30 11:24:20 +0100545 CAutoLog autolog(pSystemClass, "Importing system structure from file " + strXmlStructureFilePath);
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200546
Patrick Benavoli68a91282011-08-31 11:23:23 +0200547 if (!xmlParse(parameterBuildContext, pSystemClass, strXmlStructureFilePath, strXmlStructureFolder, EParameterCreationLibrary)) {
548
549 return false;
550 }
551
552 // Initialize offsets
553 pSystemClass->setOffset(0);
554
555 // Initialize main blackboard's size
556 _pMainParameterBlackboard->setSize(pSystemClass->getFootPrint());
557
558 return true;
559}
560
561bool CParameterMgr::loadSettings(string& strError)
562{
Kevin Rocardd6909eb2013-07-18 09:13:51 +0200563 string strLoadError;
564 bool success = loadSettingsFromConfigFile(strLoadError);
565
566 if (!success && !_bFailOnFailedSettingsLoad) {
567 // Load can not fail, ie continue but log the load errors
568 log_info(strLoadError);
569 log_info("Failed to load settings, continue without domains.");
570 success = true;
571 }
572
573 if (!success) {
574 // Propagate the litteral error only if the function fails
575 strError = strLoadError;
576 return false;
577 }
578
579 return true;
580}
581
582bool CParameterMgr::loadSettingsFromConfigFile(string& strError)
583{
Patrick Benavoli68a91282011-08-31 11:23:23 +0200584 CAutoLog autoLog(this, "Loading settings");
585
586 // Get settings configuration element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100587 const CFrameworkConfigurationGroup* pParameterConfigurationGroup = static_cast<const CFrameworkConfigurationGroup*>(getConstFrameworkConfiguration()->findChildOfKind("SettingsConfiguration"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200588
589 if (!pParameterConfigurationGroup) {
590
591 // No settings to load
592
593 return true;
594 }
595 // Get binary settings file location
596 const CFrameworkConfigurationLocation* pBinarySettingsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("BinarySettingsFileLocation"));
597
598 string strXmlBinarySettingsFilePath;
599
600 if (pBinarySettingsFileLocation) {
601
602 // Get Xml binary settings file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100603 strXmlBinarySettingsFilePath = pBinarySettingsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200604 }
605
606 // Get configurable domains element
607 const CFrameworkConfigurationLocation* pConfigurableDomainsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("ConfigurableDomainsFileLocation"));
608
609 if (!pConfigurableDomainsFileLocation) {
610
611 strError = "No ConfigurableDomainsFileLocation element found for SystemClass " + getSystemClass()->getName();
612
613 return false;
Kevin Rocardd6909eb2013-07-18 09:13:51 +0200614 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200615 // Get destination root element
616 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
617
618 // Get Xml configuration domains file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100619 string strXmlConfigurationDomainsFilePath = pConfigurableDomainsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200620
621 // Get Xml configuration domains folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100622 string strXmlConfigurationDomainsFolder = pConfigurableDomainsFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200623
624 // Parse configuration domains XML file (ask to read settings from XML file if they are not provided as binary)
David Wagner29fa61f2014-12-19 11:15:02 +0100625 CXmlDomainImportContext xmlDomainImportContext(strError, !pBinarySettingsFileLocation);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200626
627 // Selection criteria definition for rule creation
David Wagner29fa61f2014-12-19 11:15:02 +0100628 xmlDomainImportContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
Patrick Benavoli68a91282011-08-31 11:23:23 +0200629
Patrick Benavoli63499d42011-10-24 18:50:03 +0200630 // Auto validation of configurations if no binary settings provided
David Wagner29fa61f2014-12-19 11:15:02 +0100631 xmlDomainImportContext.setAutoValidationRequired(!pBinarySettingsFileLocation);
Patrick Benavoli63499d42011-10-24 18:50:03 +0200632
Kevin Rocardace81f82012-12-11 16:19:17 +0100633 log_info("Importing configurable domains from file %s %s settings", strXmlConfigurationDomainsFilePath.c_str(), pBinarySettingsFileLocation ? "without" : "with");
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200634
Patrick Benavoli68a91282011-08-31 11:23:23 +0200635 // Do parse
David Wagner29fa61f2014-12-19 11:15:02 +0100636 if (!xmlParse(xmlDomainImportContext, pConfigurableDomains, strXmlConfigurationDomainsFilePath, strXmlConfigurationDomainsFolder, EParameterConfigurationLibrary, "SystemClassName")) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200637
638 return false;
639 }
640 // We have loaded the whole system structure, compute checksum
641 const CSystemClass* pSystemClass = getConstSystemClass();
642 _uiStructureChecksum = pSystemClass->computeStructureChecksum() + getConfigurableDomains()->computeStructureChecksum() + getSelectionCriteria()->computeStructureChecksum();
643
644 // Load binary settings if any provided
645 if (pBinarySettingsFileLocation && !pConfigurableDomains->serializeSettings(strXmlBinarySettingsFilePath, false, _uiStructureChecksum, strError)) {
646
647 return false;
648 }
649
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200650 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200651}
652
653// XML parsing
654bool CParameterMgr::xmlParse(CXmlElementSerializingContext& elementSerializingContext, CElement* pRootElement, const string& strXmlFilePath, const string& strXmlFolder, CParameterMgr::ElementLibrary eElementLibrary, const string& strNameAttrituteName)
655{
656 // Init serializing context
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +0200657 elementSerializingContext.set(_pElementLibrarySet->getElementLibrary(
658 eElementLibrary), strXmlFolder, _strSchemaFolderLocation);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200659
660 // Get Schema file associated to root element
661 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pRootElement->getKind() + ".xsd";
662
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +0200663 CXmlFileDocSource fileDocSource(strXmlFilePath, strXmlSchemaFilePath,
664 pRootElement->getKind(),
665 pRootElement->getName(), strNameAttrituteName,
666 _bValidateSchemasOnStart);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200667
668 // Start clean
669 pRootElement->clean();
670
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200671 CXmlMemoryDocSink memorySink(pRootElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200672
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200673 if (!memorySink.process(fileDocSource, elementSerializingContext)) {
674 //Cleanup
Patrick Benavoli68a91282011-08-31 11:23:23 +0200675 pRootElement->clean();
676
677 return false;
678 }
679
Patrick Benavoli68a91282011-08-31 11:23:23 +0200680 return true;
681}
682
683// Init
684bool CParameterMgr::init(string& strError)
685{
686 return base::init(strError);
687}
688
689// Selection criteria interface
690CSelectionCriterionType* CParameterMgr::createSelectionCriterionType(bool bIsInclusive)
691{
692 // Propagate
693 return getSelectionCriteria()->createSelectionCriterionType(bIsInclusive);
694}
695
696CSelectionCriterion* CParameterMgr::createSelectionCriterion(const string& strName, const CSelectionCriterionType* pSelectionCriterionType)
697{
698 // Propagate
699 return getSelectionCriteria()->createSelectionCriterion(strName, pSelectionCriterionType);
700}
701
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200702// Selection criterion retrieval
703CSelectionCriterion* CParameterMgr::getSelectionCriterion(const string& strName)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200704{
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200705 // Propagate
706 return getSelectionCriteria()->getSelectionCriterion(strName);
707}
708
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100709// Configuration application
Kevin Rocardace81f82012-12-11 16:19:17 +0100710void CParameterMgr::applyConfigurations()
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200711{
712 CAutoLog autoLog(this, "Configuration application request");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200713
714 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +0100715 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200716
717 if (!_bTuningModeIsOn) {
718
719 // Apply configuration(s)
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100720 doApplyConfigurations(false);
Frédéric Boisnarddaaa63c2012-08-27 15:48:15 +0200721 } else {
722
Kevin Rocardace81f82012-12-11 16:19:17 +0100723 log_warning("Configurations were not applied because the TuningMode is on");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200724 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200725}
726
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200727// Get the configurableElement corresponding to the given path
728const CConfigurableElement* CParameterMgr::getConfigurableElement(const string& strPath,
729 string& strError) const
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200730{
Patrick Benavoli065264a2011-11-20 15:46:41 +0100731 CPathNavigator pathNavigator(strPath);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200732
Patrick Benavoli065264a2011-11-20 15:46:41 +0100733 // Nagivate through system class
734 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
735
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100736 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100737 }
738
739 // Find element
740 const CElement* pElement = getConstSystemClass()->findDescendant(pathNavigator);
741
742 if (!pElement) {
743
Kevin Rocard4c3f8d82013-11-21 12:16:28 +0100744 strError = "Path not found: " + strPath;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100745
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100746 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100747 }
748
749 // Check found element is a parameter
750 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pElement);
751
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200752 return pConfigurableElement;
753}
754
755// Dynamic parameter handling
756CParameterHandle* CParameterMgr::createParameterHandle(const string& strPath, string& strError)
757{
758 const CConfigurableElement* pConfigurableElement = getConfigurableElement(strPath, strError);
759
760 if (!pConfigurableElement) {
761
762 // Element not found
Kevin Rocard4c3f8d82013-11-21 12:16:28 +0100763 strError = "Element not found: " + strPath;
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200764 return NULL;
765 }
766
Patrick Benavoli065264a2011-11-20 15:46:41 +0100767 if (!pConfigurableElement->isParameter()) {
768
769 // Element is not parameter
Kevin Rocard4c3f8d82013-11-21 12:16:28 +0100770 strError = "Not a parameter: " + strPath;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100771
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100772 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100773 }
774
775 // Convert as parameter and return new handle
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200776 return new CParameterHandle(static_cast<const CBaseParameter*>(pConfigurableElement), this);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200777}
778
Kevin Rocardecf93102013-07-10 18:28:10 +0200779void CParameterMgr::setFailureOnMissingSubsystem(bool bFail)
780{
781 _bFailOnMissingSubsystem = bFail;
782}
783
784bool CParameterMgr::getFailureOnMissingSubsystem() const
785{
786 return _bFailOnMissingSubsystem;
787}
Kevin Rocardd6909eb2013-07-18 09:13:51 +0200788
789void CParameterMgr::setFailureOnFailedSettingsLoad(bool bFail)
790{
791 _bFailOnFailedSettingsLoad = bFail;
792}
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +0200793
Kevin Rocardd6909eb2013-07-18 09:13:51 +0200794bool CParameterMgr::getFailureOnFailedSettingsLoad()
795{
796 return _bFailOnFailedSettingsLoad;
797}
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +0200798
799void CParameterMgr::setValidateSchemasOnStart(bool bValidate)
800{
801 _bValidateSchemasOnStart = bValidate;
802}
803
804bool CParameterMgr::getValidateSchemasOnStart() const
805{
806 return _bValidateSchemasOnStart;
807}
808
Patrick Benavoli68a91282011-08-31 11:23:23 +0200809/////////////////// Remote command parsers
Patrick Benavoli592ae562011-09-05 16:53:58 +0200810/// Version
Patrick Benavoli63499d42011-10-24 18:50:03 +0200811CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::versionCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli592ae562011-09-05 16:53:58 +0200812{
813 (void)remoteCommand;
814
Patrick Benavoli63499d42011-10-24 18:50:03 +0200815 // Show version
816 strResult = getVersion();
Patrick Benavoli592ae562011-09-05 16:53:58 +0200817
Patrick Benavoli63499d42011-10-24 18:50:03 +0200818 return CCommandHandler::ESucceeded;
Patrick Benavoli592ae562011-09-05 16:53:58 +0200819}
820
Patrick Benavoli68a91282011-08-31 11:23:23 +0200821/// Status
Patrick Benavoli63499d42011-10-24 18:50:03 +0200822CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::statusCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200823{
824 (void)remoteCommand;
825 // System class
826 const CSystemClass* pSystemClass = getSystemClass();
827
Patrick Benavoli68a91282011-08-31 11:23:23 +0200828 // Show status
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200829 /// General section
830 appendTitle(strResult, "General:");
831 // System class
Patrick Benavoli68a91282011-08-31 11:23:23 +0200832 strResult += "System Class: ";
833 strResult += pSystemClass->getName();
834 strResult += "\n";
835
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200836 // Tuning mode
Patrick Benavoli68a91282011-08-31 11:23:23 +0200837 strResult += "Tuning Mode: ";
838 strResult += tuningModeOn() ? "on" : "off";
839 strResult += "\n";
840
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200841 // Value space
Patrick Benavoli68a91282011-08-31 11:23:23 +0200842 strResult += "Value Space: ";
843 strResult += valueSpaceIsRaw() ? "raw" : "real";
844 strResult += "\n";
845
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200846 // Output raw format
847 strResult += "Output Raw Format: ";
848 strResult += outputRawFormatIsHex() ? "hex" : "dec";
849 strResult += "\n";
850
851 // Auto Sync
Patrick Benavoli68a91282011-08-31 11:23:23 +0200852 strResult += "Auto Sync: ";
853 strResult += autoSyncOn() ? "on" : "off";
854 strResult += "\n";
855
856 /// Subsystem list
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200857 appendTitle(strResult, "Subsystems:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200858 string strSubsystemList;
859 pSystemClass->listChildrenPaths(strSubsystemList);
860 strResult += strSubsystemList;
861
862 /// Last applied configurations
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200863 appendTitle(strResult, "Last Applied [Pending] Configurations:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200864 string strLastAppliedConfigurations;
865 getConfigurableDomains()->listLastAppliedConfigurations(strLastAppliedConfigurations);
866 strResult += strLastAppliedConfigurations;
867
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200868 /// Criteria states
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200869 appendTitle(strResult, "Selection Criteria:");
Kevin Rocard7f265822012-12-07 18:51:22 +0100870 list<string> lstrSelectionCriteria;
871 getSelectionCriteria()->listSelectionCriteria(lstrSelectionCriteria, false, true);
872 // Concatenate the criterion list as the command result
Frederic Boisnard390b36d2013-05-23 15:28:31 +0200873 string strCriteriaStates;
874 CUtility::asString(lstrSelectionCriteria, strCriteriaStates);
875 strResult += strCriteriaStates;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200876
Patrick Benavoli63499d42011-10-24 18:50:03 +0200877 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200878}
879
880/// Tuning Mode
Patrick Benavoli63499d42011-10-24 18:50:03 +0200881CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200882{
883 if (remoteCommand.getArgument(0) == "on") {
884
885 if (setTuningMode(true, strResult)) {
886
Patrick Benavoli63499d42011-10-24 18:50:03 +0200887 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200888 }
889 } else if (remoteCommand.getArgument(0) == "off") {
890
891 if (setTuningMode(false, strResult)) {
892
Patrick Benavoli63499d42011-10-24 18:50:03 +0200893 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200894 }
895 } else {
896 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200897 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200898 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200899 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200900}
901
Patrick Benavoli63499d42011-10-24 18:50:03 +0200902CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200903{
904 (void)remoteCommand;
905
906 strResult = tuningModeOn() ? "on" : "off";
907
Patrick Benavoli63499d42011-10-24 18:50:03 +0200908 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200909}
910
911/// Value Space
Patrick Benavoli63499d42011-10-24 18:50:03 +0200912CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200913{
914 (void)strResult;
915
916 if (remoteCommand.getArgument(0) == "raw") {
917
918 setValueSpace(true);
919
Patrick Benavoli63499d42011-10-24 18:50:03 +0200920 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200921
922 } else if (remoteCommand.getArgument(0) == "real") {
923
924 setValueSpace(false);
925
Patrick Benavoli63499d42011-10-24 18:50:03 +0200926 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200927
928 } else {
929 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200930 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200931 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200932 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200933}
934
Patrick Benavoli63499d42011-10-24 18:50:03 +0200935CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200936{
937 (void)remoteCommand;
938
939 strResult = valueSpaceIsRaw() ? "raw" : "real";
940
Patrick Benavoli63499d42011-10-24 18:50:03 +0200941 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200942}
943
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200944/// Output Raw Format
Patrick Benavoli63499d42011-10-24 18:50:03 +0200945CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200946{
947 (void)strResult;
948
949 if (remoteCommand.getArgument(0) == "hex") {
950
951 setOutputRawFormat(true);
952
Patrick Benavoli63499d42011-10-24 18:50:03 +0200953 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200954
955 } else if (remoteCommand.getArgument(0) == "dec") {
956
957 setOutputRawFormat(false);
958
Patrick Benavoli63499d42011-10-24 18:50:03 +0200959 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200960
961 } else {
962 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200963 return CCommandHandler::EShowUsage;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200964 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200965 return CCommandHandler::EFailed;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200966}
967
Patrick Benavoli63499d42011-10-24 18:50:03 +0200968CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200969{
970 (void)remoteCommand;
971
972 strResult = outputRawFormatIsHex() ? "hex" : "dec";
973
Patrick Benavoli63499d42011-10-24 18:50:03 +0200974 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200975}
976
Patrick Benavoli68a91282011-08-31 11:23:23 +0200977/// Sync
Patrick Benavoli63499d42011-10-24 18:50:03 +0200978CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200979{
980 if (remoteCommand.getArgument(0) == "on") {
981
982 if (setAutoSync(true, strResult)) {
983
Patrick Benavoli63499d42011-10-24 18:50:03 +0200984 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200985 }
986 } else if (remoteCommand.getArgument(0) == "off") {
987
988 if (setAutoSync(false, strResult)) {
989
Patrick Benavoli63499d42011-10-24 18:50:03 +0200990 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200991 }
992 } else {
993 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200994 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200995 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200996 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200997}
998
Patrick Benavoli63499d42011-10-24 18:50:03 +0200999CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001000{
1001 (void)remoteCommand;
1002
1003 strResult = autoSyncOn() ? "on" : "off";
1004
Patrick Benavoli63499d42011-10-24 18:50:03 +02001005 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001006}
1007
Patrick Benavoli63499d42011-10-24 18:50:03 +02001008CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::syncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001009{
1010 (void)remoteCommand;
1011
Patrick Benavoli63499d42011-10-24 18:50:03 +02001012 return sync(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001013}
1014
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001015/// Criteria
Patrick Benavoli63499d42011-10-24 18:50:03 +02001016CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listCriteriaCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001017{
1018 (void)remoteCommand;
1019
Kevin Rocard4eae8272013-04-18 19:12:46 +02001020 bool humanReadable = true;
Kevin Rocard7f265822012-12-07 18:51:22 +01001021
Kevin Rocard4eae8272013-04-18 19:12:46 +02001022 // Look for optional arguments
1023 if (remoteCommand.getArgumentCount() >= 1) {
1024
1025 // If csv is provided, format the criterion list in Commas Separated Value pairs
1026 if (remoteCommand.getArgument(0) == "csv") {
1027 humanReadable = false;
1028 } else {
1029 return CCommandHandler::EShowUsage;
1030 }
1031 }
1032
1033 list<string> lstrResult;
1034 getSelectionCriteria()->listSelectionCriteria(lstrResult, true, humanReadable);
Kevin Rocard7f265822012-12-07 18:51:22 +01001035
1036 // Concatenate the criterion list as the command result
Frederic Boisnard390b36d2013-05-23 15:28:31 +02001037 CUtility::asString(lstrResult, strResult);
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001038
Patrick Benavoli63499d42011-10-24 18:50:03 +02001039 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001040}
Patrick Benavoli68a91282011-08-31 11:23:23 +02001041
1042/// Domains
Patrick Benavoli63499d42011-10-24 18:50:03 +02001043CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001044{
1045 (void)remoteCommand;
1046
Patrick Benavoli63499d42011-10-24 18:50:03 +02001047 getConfigurableDomains()->listDomains(strResult);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001048
Patrick Benavoli63499d42011-10-24 18:50:03 +02001049 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001050}
1051
Patrick Benavoli63499d42011-10-24 18:50:03 +02001052CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001053{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001054 return createDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001055}
1056
Patrick Benavoli63499d42011-10-24 18:50:03 +02001057CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001058{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001059 return deleteDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001060}
1061
Kevin Rocard170f0a42012-06-18 13:56:05 +02001062CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteAllDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1063{
1064 (void)remoteCommand;
1065
1066 return deleteAllDomains(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1067}
1068
Patrick Benavoli63499d42011-10-24 18:50:03 +02001069CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001070{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001071 return getConfigurableDomains()->renameDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001072}
1073
Patrick Benavoli63499d42011-10-24 18:50:03 +02001074CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001075{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001076 // Check tuning mode
1077 if (!checkTuningModeOn(strResult)) {
1078
1079 return CCommandHandler::EFailed;
1080 }
1081
1082 // Set property
1083 bool bSequenceAware;
1084
1085 if (remoteCommand.getArgument(1) == "true") {
1086
1087 bSequenceAware = true;
1088
1089 } else if (remoteCommand.getArgument(1) == "false") {
1090
1091 bSequenceAware = false;
1092
1093 } else {
1094 // Show usage
1095 return CCommandHandler::EShowUsage;
1096 }
1097
1098 return getConfigurableDomains()->setSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001099}
1100
Patrick Benavoli63499d42011-10-24 18:50:03 +02001101CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001102{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001103 // Get property
1104 bool bSequenceAware;
1105
1106 if (!getConfigurableDomains()->getSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult)) {
1107
1108 return CCommandHandler::EFailed;
1109 }
1110
1111 strResult = bSequenceAware ? "true" : "false";
1112
1113 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001114}
1115
Patrick Benavoli63499d42011-10-24 18:50:03 +02001116CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001117{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001118 return getConfigurableDomains()->listDomainElements(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001119}
1120
Patrick Benavoli63499d42011-10-24 18:50:03 +02001121CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::addElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001122{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001123 return addConfigurableElementToDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1124}
1125
1126CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::removeElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1127{
1128 return removeConfigurableElementFromDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1129}
1130
1131CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::splitDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1132{
1133 return split(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001134}
1135
1136/// Configurations
Patrick Benavoli63499d42011-10-24 18:50:03 +02001137CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConfigurationsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001138{
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001139 return getConstConfigurableDomains()->listConfigurations(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
1140}
1141
1142CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1143{
1144 (void)remoteCommand;
1145
1146 // Dummy error context
1147 string strError;
1148 CErrorContext errorContext(strError);
1149
1150 // Dump
1151 getConstConfigurableDomains()->dumpContent(strResult, errorContext);
1152
1153 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001154}
1155
Patrick Benavoli63499d42011-10-24 18:50:03 +02001156CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001157{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001158 return createConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001159}
1160
Patrick Benavoli63499d42011-10-24 18:50:03 +02001161CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001162{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001163 return deleteConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001164}
1165
Patrick Benavoli63499d42011-10-24 18:50:03 +02001166CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001167{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001168 return getConfigurableDomains()->renameConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001169}
1170
Patrick Benavoli63499d42011-10-24 18:50:03 +02001171CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::saveConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001172{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001173 return saveConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001174}
1175
Patrick Benavoli63499d42011-10-24 18:50:03 +02001176CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::restoreConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001177{
Kevin Rocardace81f82012-12-11 16:19:17 +01001178 list<string> lstrResult;
1179 if (!restoreConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), lstrResult)) {
1180 //Concatenate the error list as the command result
Frederic Boisnard390b36d2013-05-23 15:28:31 +02001181 CUtility::asString(lstrResult, strResult);
Kevin Rocardace81f82012-12-11 16:19:17 +01001182
1183 return CCommandHandler::EFailed;
1184 }
1185 return CCommandHandler::EDone;
Patrick Benavoli63499d42011-10-24 18:50:03 +02001186}
1187
1188CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1189{
1190 // Check tuning mode
1191 if (!checkTuningModeOn(strResult)) {
1192
1193 return CCommandHandler::EFailed;
1194 }
1195
1196 // Build configurable element path list
Sebastien Gonzalved9526492014-02-20 22:28:03 +01001197 std::vector<string> astrNewElementSequence;
Patrick Benavoli63499d42011-10-24 18:50:03 +02001198
1199 uint32_t uiArgument;
1200
1201 for (uiArgument = 2; uiArgument < remoteCommand.getArgumentCount(); uiArgument++) {
1202
1203 astrNewElementSequence.push_back(remoteCommand.getArgument(uiArgument));
1204 }
1205
1206 // Delegate to configurable domains
1207 return getConfigurableDomains()->setElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), astrNewElementSequence, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1208}
1209
1210CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1211{
1212 // Delegate to configurable domains
1213 return getConfigurableDomains()->getElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001214}
1215
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001216CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1217{
1218 // Delegate to configurable domains
1219 return getConfigurableDomains()->setApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.packArguments(2, remoteCommand.getArgumentCount() - 2), getConstSelectionCriteria()->getSelectionCriteriaDefinition(), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1220}
1221
1222CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::clearRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1223{
1224 // Delegate to configurable domains
1225 return getConfigurableDomains()->clearApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1226}
1227
1228CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1229{
1230 // Delegate to configurable domains
1231 return getConfigurableDomains()->getApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
1232}
1233
Patrick Benavoli68a91282011-08-31 11:23:23 +02001234/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001235CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001236{
1237 CElementLocator elementLocator(getSystemClass(), false);
1238
1239 CElement* pLocatedElement = NULL;
1240
1241 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1242
Patrick Benavoli63499d42011-10-24 18:50:03 +02001243 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001244 }
1245
1246 strResult = string("\n");
1247
1248 if (!pLocatedElement) {
1249
1250 // List from root folder
1251
1252 // Return system class qualified name
1253 pLocatedElement = getSystemClass();
1254 }
1255
1256 // Return sub-elements
1257 strResult += pLocatedElement->listQualifiedPaths(false);
1258
Patrick Benavoli63499d42011-10-24 18:50:03 +02001259 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001260}
1261
1262/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001263CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listParametersCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001264{
1265 CElementLocator elementLocator(getSystemClass(), false);
1266
1267 CElement* pLocatedElement = NULL;
1268
1269 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1270
Patrick Benavoli63499d42011-10-24 18:50:03 +02001271 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001272 }
1273
1274 strResult = string("\n");
1275
1276 if (!pLocatedElement) {
1277
1278 // List from root folder
1279
1280 // Return system class qualified name
1281 pLocatedElement = getSystemClass();
1282 }
1283
1284 // Return sub-elements
1285 strResult += pLocatedElement->listQualifiedPaths(true);
1286
Patrick Benavoli63499d42011-10-24 18:50:03 +02001287 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001288}
1289
Patrick Benavoli63499d42011-10-24 18:50:03 +02001290CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001291{
1292 CElementLocator elementLocator(getSystemClass());
1293
1294 CElement* pLocatedElement = NULL;
1295
1296 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1297
Patrick Benavoli63499d42011-10-24 18:50:03 +02001298 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001299 }
1300
1301 string strError;
1302
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001303 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001304
1305 // Dump elements
1306 pLocatedElement->dumpContent(strResult, parameterAccessContext);
1307
Patrick Benavoli63499d42011-10-24 18:50:03 +02001308 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001309}
1310
Patrick Benavoli63499d42011-10-24 18:50:03 +02001311CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSizeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001312{
1313 CElementLocator elementLocator(getSystemClass());
1314
1315 CElement* pLocatedElement = NULL;
1316
1317 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1318
Patrick Benavoli63499d42011-10-24 18:50:03 +02001319 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001320 }
1321
1322 // Converted to actual sizable element
1323 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1324
1325 // Get size as string
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001326 strResult = pConfigurableElement->getFootprintAsString();
Patrick Benavoli68a91282011-08-31 11:23:23 +02001327
Patrick Benavoli63499d42011-10-24 18:50:03 +02001328 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001329}
1330
Patrick Benavoli63499d42011-10-24 18:50:03 +02001331CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showPropertiesCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001332{
1333 CElementLocator elementLocator(getSystemClass());
1334
1335 CElement* pLocatedElement = NULL;
1336
1337 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1338
Patrick Benavoli63499d42011-10-24 18:50:03 +02001339 return CCommandHandler::EFailed;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001340 }
1341
1342 // Convert element
1343 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1344
1345 // Return element properties
1346 pConfigurableElement->showProperties(strResult);
1347
Patrick Benavoli63499d42011-10-24 18:50:03 +02001348 return CCommandHandler::ESucceeded;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001349}
1350
Patrick Benavoli63499d42011-10-24 18:50:03 +02001351CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001352{
1353 string strValue;
1354
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001355 if (!accessParameterValue(remoteCommand.getArgument(0), strValue, false, strResult)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001356
Patrick Benavoli63499d42011-10-24 18:50:03 +02001357 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001358 }
1359 // Succeeded
1360 strResult = strValue;
1361
Patrick Benavoli63499d42011-10-24 18:50:03 +02001362 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001363}
1364
Patrick Benavoli63499d42011-10-24 18:50:03 +02001365CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001366{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001367 // Check tuning mode
1368 if (!checkTuningModeOn(strResult)) {
1369
1370 return CCommandHandler::EFailed;
1371 }
1372 // Get value to set
1373 string strValue = remoteCommand.packArguments(1, remoteCommand.getArgumentCount() - 1);
1374
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001375 return accessParameterValue(remoteCommand.getArgument(0), strValue, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001376}
1377
Patrick Benavoli63499d42011-10-24 18:50:03 +02001378CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listBelongingDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001379{
1380 CElementLocator elementLocator(getSystemClass());
1381
1382 CElement* pLocatedElement = NULL;
1383
1384 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1385
Patrick Benavoli63499d42011-10-24 18:50:03 +02001386 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001387 }
1388
1389 // Convert element
1390 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1391
1392 // Return element belonging domains
1393 pConfigurableElement->listBelongingDomains(strResult);
1394
Patrick Benavoli63499d42011-10-24 18:50:03 +02001395 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001396}
1397
Patrick Benavoli63499d42011-10-24 18:50:03 +02001398CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001399{
1400 CElementLocator elementLocator(getSystemClass());
1401
1402 CElement* pLocatedElement = NULL;
1403
1404 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1405
Patrick Benavoli63499d42011-10-24 18:50:03 +02001406 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001407 }
1408
1409 // Convert element
1410 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1411
1412 // Return element belonging domains
1413 pConfigurableElement->listAssociatedDomains(strResult);
1414
Patrick Benavoli63499d42011-10-24 18:50:03 +02001415 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001416}
1417
Patrick Benavoli63499d42011-10-24 18:50:03 +02001418CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001419{
1420 (void)remoteCommand;
1421
1422 getConfigurableDomains()->listAssociatedElements(strResult);
1423
Patrick Benavoli63499d42011-10-24 18:50:03 +02001424 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001425}
1426
Patrick Benavoli63499d42011-10-24 18:50:03 +02001427CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConflictingElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001428{
1429 (void)remoteCommand;
1430
1431 getConfigurableDomains()->listConflictingElements(strResult);
1432
Patrick Benavoli63499d42011-10-24 18:50:03 +02001433 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001434}
1435
Patrick Benavoli63499d42011-10-24 18:50:03 +02001436CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listRogueElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001437{
1438 (void)remoteCommand;
1439
1440 getSystemClass()->listRogueElements(strResult);
1441
Patrick Benavoli63499d42011-10-24 18:50:03 +02001442 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001443}
1444
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001445CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getConfigurationParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1446{
1447 string strOutputValue;
1448 string strError;
1449
1450 if (!accessConfigurationValue(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), strOutputValue, false, strError)) {
1451
1452 strResult = strError;
1453 return CCommandHandler::EFailed;
1454 }
1455 // Succeeded
1456 strResult = strOutputValue;
1457
1458 return CCommandHandler::ESucceeded;
1459}
1460
1461CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setConfigurationParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1462{
1463 // Get value to set
1464 string strValue = remoteCommand.packArguments(3, remoteCommand.getArgumentCount() - 3);
1465
1466 bool bSuccess = accessConfigurationValue(remoteCommand.getArgument(0),
1467 remoteCommand.getArgument(1),
1468 remoteCommand.getArgument(2),
1469 strValue, true, strResult);
1470
1471 return bSuccess ? CCommandHandler::EDone : CCommandHandler::EFailed;
1472}
1473
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +02001474CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showMappingCommmandProcess(
1475 const IRemoteCommand& remoteCommand,
1476 string& strResult)
1477{
1478 if (!getParameterMapping(remoteCommand.getArgument(0), strResult)) {
1479
1480 return CCommandHandler::EFailed;
1481 }
1482
1483 return CCommandHandler::ESucceeded;
1484}
1485
Patrick Benavoli68a91282011-08-31 11:23:23 +02001486/// Settings Import/Export
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001487CParameterMgr::CCommandHandler::CommandStatus
1488 CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess(
1489 const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001490{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001491 string strFileName = remoteCommand.getArgument(0);
1492 return exportDomainsXml(strFileName, false, true, strResult) ?
1493 CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001494}
1495
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001496CParameterMgr::CCommandHandler::CommandStatus
1497 CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess(
1498 const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001499{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001500 return importDomainsXml(remoteCommand.getArgument(0), false, true, strResult) ?
1501 CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001502}
1503
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001504CParameterMgr::CCommandHandler::CommandStatus
1505 CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess(
1506 const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001507{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001508 string strFileName = remoteCommand.getArgument(0);
1509 return exportDomainsXml(strFileName, true, true, strResult) ?
1510 CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001511}
1512
Patrick Benavoli63499d42011-10-24 18:50:03 +02001513CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001514{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001515 return importDomainsXml(remoteCommand.getArgument(0), true, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001516}
1517
Patrick Benavoli63499d42011-10-24 18:50:03 +02001518CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001519{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001520 return exportDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001521}
1522
Patrick Benavoli63499d42011-10-24 18:50:03 +02001523CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001524{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001525 return importDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001526}
1527
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001528CParameterMgr::CCommandHandler::CommandStatus
1529 CParameterMgr::getConfigurableDomainsWithSettingsXMLCommmandProcess(
1530 const IRemoteCommand& remoteCommand, string& strResult)
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001531{
1532 (void)remoteCommand;
1533
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001534 if (!exportDomainsXml(strResult, true, false, strResult)) {
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001535
1536 return CCommandHandler::EFailed;
1537 }
1538 // Succeeded
1539 return CCommandHandler::ESucceeded;
1540}
1541
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001542CParameterMgr::CCommandHandler::CommandStatus
1543 CParameterMgr::setConfigurableDomainsWithSettingsXMLCommmandProcess(
1544 const IRemoteCommand& remoteCommand, string& strResult)
1545{
1546 return importDomainsXml(remoteCommand.getArgument(0), true, false, strResult) ?
1547 CCommandHandler::EDone : CCommandHandler::EFailed;
1548}
1549
1550CParameterMgr::CCommandHandler::CommandStatus
1551 CParameterMgr::getSystemClassXMLCommmandProcess(
1552 const IRemoteCommand& remoteCommand, string& strResult)
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001553{
1554 (void)remoteCommand;
1555
1556 if (!getSystemClassXMLString(strResult)) {
1557
1558 return CCommandHandler::EFailed;
1559 }
1560 // Succeeded
1561 return CCommandHandler::ESucceeded;
1562}
1563
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001564// User set/get parameters in main BlackBoard
1565bool CParameterMgr::accessParameterValue(const string& strPath, string& strValue, bool bSet, string& strError)
1566{
1567 // Define context
1568 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
1569
Frédéric Boisnard150407c2013-03-15 14:46:23 +01001570 // Activate the auto synchronization with the hardware
1571 if (bSet) {
1572
1573 parameterAccessContext.setAutoSync(_bAutoSyncOn);
1574 }
1575
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001576 return accessValue(parameterAccessContext, strPath, strValue, bSet, strError);
1577}
1578
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +02001579// User get parameter mapping
1580bool CParameterMgr::getParameterMapping(const string& strPath, string& strResult) const
1581{
1582 CPathNavigator pathNavigator(strPath);
1583
1584 // Nagivate through system class
1585 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strResult)) {
1586
1587 return false;
1588 }
1589
1590 // Get the ConfigurableElement corresponding to strPath
1591 const CConfigurableElement* pConfigurableElement = getConfigurableElement(strPath, strResult);
1592 if (!pConfigurableElement) {
1593
1594 return false;
1595 }
1596
1597 // Find the list of the ancestors of the current ConfigurableElement that have a mapping
1598 list<const CConfigurableElement*> configurableElementPath;
1599 pConfigurableElement->getListOfElementsWithMapping(configurableElementPath);
1600
1601 // Get the Subsystem containing the ConfigurableElement
1602 const CSubsystem* pSubsystem = pConfigurableElement->getBelongingSubsystem();
1603 if (!pSubsystem) {
1604
1605 strResult = "Unable to find the Subsystem containing the parameter";
1606 return false;
1607 }
1608
1609 // Fetch the mapping corresponding to the ConfigurableElement
1610 strResult = pSubsystem->getMapping(configurableElementPath);
1611
1612 return true;
1613}
1614
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001615// User set/get parameters in specific Configuration BlackBoard
1616bool CParameterMgr::accessConfigurationValue(const string& strDomain, const string& strConfiguration, const string& strPath, string& strValue, bool bSet, string& strError)
1617{
1618 CElementLocator elementLocator(getSystemClass());
1619
1620 CElement* pLocatedElement = NULL;
1621
1622 if (!elementLocator.locate(strPath, &pLocatedElement, strError)) {
1623
1624 return false;
1625 }
1626
1627 // Convert element
1628 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1629
1630 // Get the Configuration blackboard and the Base Offset of the configurable element in this blackboard
1631 uint32_t uiBaseOffset;
1632 bool bIsLastApplied;
1633
1634 CParameterBlackboard* pConfigurationBlackboard = getConstConfigurableDomains()->findConfigurationBlackboard(strDomain, strConfiguration, pConfigurableElement, uiBaseOffset, bIsLastApplied, strError);
1635
1636 if (!pConfigurationBlackboard) {
1637
1638 return false;
1639 }
1640
1641 log_info("Element %s in Domain %s, offset: %d, base offset: %d", strPath.c_str(), strDomain.c_str(), pConfigurableElement->getOffset(), uiBaseOffset);
1642
1643 /// Update the Configuration Blackboard
1644
Frédéric Boisnard150407c2013-03-15 14:46:23 +01001645 // 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 +01001646 CParameterAccessContext parameterAccessContext(strError, pConfigurationBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex, uiBaseOffset);
1647
Frédéric Boisnardda8298c2014-05-23 19:05:31 +02001648 // Deactivate the auto synchronization with the hardware during the Configuration Blackboard
1649 // access (only Main Blackboard shall be synchronized, Configurations Blackboards are copied
1650 // into the Main Blackboard each time a configuration is restored but they are not synchronized
1651 // directly).
1652 if (bSet) {
1653
1654 parameterAccessContext.setAutoSync(false);
1655 }
1656
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001657 // Access Value in the Configuration Blackboard
1658 if (!accessValue(parameterAccessContext, strPath, strValue, bSet, strError)) {
1659
1660 return false;
1661 }
1662
1663 /// If the Configuration is the last one applied, update the Main Blackboard as well
1664
1665 if (bIsLastApplied) {
1666
1667 // Define Main context
1668 parameterAccessContext.setParameterBlackboard(_pMainParameterBlackboard);
1669
Frédéric Boisnard150407c2013-03-15 14:46:23 +01001670 // Activate the auto synchronization with the hardware
1671 if (bSet) {
1672
1673 parameterAccessContext.setAutoSync(_bAutoSyncOn);
1674 }
1675
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001676 // Access Value in the Main Blackboard
1677 return accessValue(parameterAccessContext, strPath, strValue, bSet, strError);
1678 }
1679
1680 return true;
1681}
1682
Patrick Benavoli68a91282011-08-31 11:23:23 +02001683// User set/get parameters
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001684bool CParameterMgr::accessValue(CParameterAccessContext& parameterAccessContext, const string& strPath, string& strValue, bool bSet, string& strError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001685{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001686 // Lock state
1687 CAutoLock autoLock(&_blackboardMutex);
1688
1689 CPathNavigator pathNavigator(strPath);
1690
1691 // Nagivate through system class
1692 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001693
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +02001694 parameterAccessContext.setError(strError);
1695
Patrick Benavoli68a91282011-08-31 11:23:23 +02001696 return false;
1697 }
1698
Patrick Benavoli065264a2011-11-20 15:46:41 +01001699 // Do the get
1700 return getConstSystemClass()->accessValue(pathNavigator, strValue, bSet, parameterAccessContext);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001701}
1702
1703// Tuning mode
1704bool CParameterMgr::setTuningMode(bool bOn, string& strError)
1705{
1706 // Tuning allowed?
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001707 if (bOn && !getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001708
1709 strError = "Tuning prohibited";
1710
1711 return false;
1712 }
1713 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +01001714 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001715
1716 // Warn domains about exiting tuning mode
1717 if (!bOn && _bTuningModeIsOn) {
1718
1719 // Ensure application of currently selected configurations
Patrick Benavoli1387bda2011-08-31 11:23:24 +02001720 // Force-apply configurations
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01001721 doApplyConfigurations(true);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001722
Patrick Benavoli68a91282011-08-31 11:23:23 +02001723 // Turn auto sync back on
1724 _bAutoSyncOn = true;
1725 }
1726
1727 // Store
1728 _bTuningModeIsOn = bOn;
1729
Patrick Benavoli68a91282011-08-31 11:23:23 +02001730 return true;
1731}
1732
1733bool CParameterMgr::tuningModeOn() const
1734{
1735 return _bTuningModeIsOn;
1736}
1737
1738// Current value space for user set/get value interpretation
1739void CParameterMgr::setValueSpace(bool bIsRaw)
1740{
1741 _bValueSpaceIsRaw = bIsRaw;
1742}
1743
1744bool CParameterMgr::valueSpaceIsRaw()
1745{
1746 return _bValueSpaceIsRaw;
1747}
1748
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001749// Current Output Raw Format for user get value interpretation
1750void CParameterMgr::setOutputRawFormat(bool bIsHex)
1751{
1752 _bOutputRawFormatIsHex = bIsHex;
1753}
1754
1755bool CParameterMgr::outputRawFormatIsHex()
1756{
1757 return _bOutputRawFormatIsHex;
1758}
1759
Patrick Benavoli68a91282011-08-31 11:23:23 +02001760/// Sync
1761// Automatic hardware synchronization control (during tuning session)
1762bool CParameterMgr::setAutoSync(bool bAutoSyncOn, string& strError)
1763{
1764 // Check tuning mode
1765 if (!checkTuningModeOn(strError)) {
1766
1767 return false;
1768 }
1769 // Warn domains about turning auto sync back on
1770 if (bAutoSyncOn && !_bAutoSyncOn) {
1771
Patrick Benavoli592ae562011-09-05 16:53:58 +02001772 // Do the synchronization at system class level (could be optimized by keeping track of all modified parameters)
1773 if (!sync(strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001774
1775 return false;
1776 }
1777 }
1778
1779 // Set Auto sync
1780 _bAutoSyncOn = bAutoSyncOn;
1781
1782 return true;
1783}
1784
1785bool CParameterMgr::autoSyncOn() const
1786{
1787 return _bAutoSyncOn;
1788}
1789
1790// Manual hardware synchronization control (during tuning session)
1791bool CParameterMgr::sync(string& strError)
1792{
1793 // Check tuning mode
1794 if (!checkTuningModeOn(strError)) {
1795
1796 return false;
1797 }
1798 // Warn domains about turning auto sync back on
1799 if (_bAutoSyncOn) {
1800
1801 strError = "Feature unavailable when Auto Sync is on";
1802
1803 return false;
1804 }
1805
1806 // Get syncer set
1807 CSyncerSet syncerSet;
1808 // ... from system class
1809 getConstSystemClass()->fillSyncerSet(syncerSet);
Kevin Rocardace81f82012-12-11 16:19:17 +01001810
Patrick Benavoli68a91282011-08-31 11:23:23 +02001811 // Sync
Kevin Rocardace81f82012-12-11 16:19:17 +01001812 list<string> lstrError;
1813 if (! syncerSet.sync(*_pMainParameterBlackboard, false, &lstrError)){
1814
Frederic Boisnard390b36d2013-05-23 15:28:31 +02001815 CUtility::asString(lstrError, strError);
Kevin Rocardace81f82012-12-11 16:19:17 +01001816 return false;
1817 };
1818
1819 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001820}
1821
1822// Content dump
1823void CParameterMgr::logStructureContent(string& strContent) const
1824{
1825 string strError;
1826
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001827 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001828
1829 dumpContent(strContent, parameterAccessContext);
1830}
1831
1832// Configuration/Domains handling
1833bool CParameterMgr::createDomain(const string& strName, string& strError)
1834{
1835 // Check tuning mode
1836 if (!checkTuningModeOn(strError)) {
1837
1838 return false;
1839 }
1840
1841 // Delegate to configurable domains
1842 return getConfigurableDomains()->createDomain(strName, strError);
1843}
1844
1845bool CParameterMgr::deleteDomain(const string& strName, string& strError)
1846{
1847 // Check tuning mode
1848 if (!checkTuningModeOn(strError)) {
1849
1850 return false;
1851 }
1852
1853 // Delegate to configurable domains
1854 return getConfigurableDomains()->deleteDomain(strName, strError);
1855}
1856
Kevin Rocard170f0a42012-06-18 13:56:05 +02001857bool CParameterMgr::deleteAllDomains(string& strError)
1858{
1859 // Check tuning mode
1860 if (!checkTuningModeOn(strError)) {
1861
1862 return false;
1863 }
1864
1865 // Delegate to configurable domains
1866 getConfigurableDomains()->deleteAllDomains();
1867
1868 return true;
1869}
1870
Patrick Benavoli68a91282011-08-31 11:23:23 +02001871bool CParameterMgr::createConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1872{
1873 // Check tuning mode
1874 if (!checkTuningModeOn(strError)) {
1875
1876 return false;
1877 }
1878
1879 // Delegate to configurable domains
1880 return getConfigurableDomains()->createConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1881}
1882
1883bool CParameterMgr::deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1884{
1885 // Check tuning mode
1886 if (!checkTuningModeOn(strError)) {
1887
1888 return false;
1889 }
1890
1891 // Delegate to configurable domains
1892 return getConfigurableDomains()->deleteConfiguration(strDomain, strConfiguration, strError);
1893}
1894
Kevin Rocardace81f82012-12-11 16:19:17 +01001895bool CParameterMgr::restoreConfiguration(const string& strDomain, const string& strConfiguration, list<string>& lstrError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001896{
Kevin Rocardace81f82012-12-11 16:19:17 +01001897 string strError;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001898 // Check tuning mode
1899 if (!checkTuningModeOn(strError)) {
1900
Kevin Rocardace81f82012-12-11 16:19:17 +01001901 lstrError.push_back(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001902 return false;
1903 }
1904
1905 // Delegate to configurable domains
Kevin Rocardace81f82012-12-11 16:19:17 +01001906 return getConstConfigurableDomains()->restoreConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, lstrError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001907}
1908
1909bool CParameterMgr::saveConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1910{
1911 // Check tuning mode
1912 if (!checkTuningModeOn(strError)) {
1913
1914 return false;
1915 }
1916
1917 // Delegate to configurable domains
1918 return getConfigurableDomains()->saveConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1919}
1920
1921// Configurable element - domain association
1922bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1923{
1924 // Check tuning mode
1925 if (!checkTuningModeOn(strError)) {
1926
1927 return false;
1928 }
1929
1930 CElementLocator elementLocator(getSystemClass());
1931
1932 CElement* pLocatedElement = NULL;
1933
1934 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1935
1936 return false;
1937 }
1938
1939 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001940 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001941
1942 // Delegate
1943 return getConfigurableDomains()->addConfigurableElementToDomain(strDomain, pConfigurableElement, _pMainParameterBlackboard, strError);
1944}
1945
1946bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1947{
1948 // Check tuning mode
1949 if (!checkTuningModeOn(strError)) {
1950
1951 return false;
1952 }
1953
1954 CElementLocator elementLocator(getSystemClass());
1955
1956 CElement* pLocatedElement = NULL;
1957
1958 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1959
Patrick Benavoli63499d42011-10-24 18:50:03 +02001960 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001961 }
1962
1963 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001964 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001965
1966 // Delegate
1967 return getConfigurableDomains()->removeConfigurableElementFromDomain(strDomain, pConfigurableElement, strError);
1968}
1969
1970bool CParameterMgr::split(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1971{
1972 // Check tuning mode
1973 if (!checkTuningModeOn(strError)) {
1974
1975 return false;
1976 }
1977
1978 CElementLocator elementLocator(getSystemClass());
1979
1980 CElement* pLocatedElement = NULL;
1981
1982 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1983
Patrick Benavoli63499d42011-10-24 18:50:03 +02001984 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001985 }
1986
1987 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001988 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001989
1990 // Delegate
1991 return getConfigurableDomains()->split(strDomain, pConfigurableElement, strError);
1992}
1993
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001994bool CParameterMgr::importDomainsXml(const string& strXmlSource, bool bWithSettings,
1995 bool bFromFile, string& strError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001996{
1997 // Check tuning mode
1998 if (!checkTuningModeOn(strError)) {
1999
2000 return false;
2001 }
2002
2003 // check path is absolute
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002004 if (bFromFile && strXmlSource[0] != '/') {
Patrick Benavoli68a91282011-08-31 11:23:23 +02002005
2006 strError = "Please provide absolute path";
2007
2008 return false;
2009 }
2010 // Root element
2011 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
2012
2013 // Context
David Wagner29fa61f2014-12-19 11:15:02 +01002014 CXmlDomainImportContext xmlDomainImportContext(strError, bWithSettings);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002015
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002016 // Selection criteria definition for rule creation
David Wagner29fa61f2014-12-19 11:15:02 +01002017 xmlDomainImportContext.setSelectionCriteriaDefinition(
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002018 getConstSelectionCriteria()->getSelectionCriteriaDefinition());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002019
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002020 // Init serializing context
David Wagner29fa61f2014-12-19 11:15:02 +01002021 xmlDomainImportContext.set(
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002022 _pElementLibrarySet->getElementLibrary(EParameterConfigurationLibrary),
2023 "", _strSchemaFolderLocation);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002024
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002025 // Get Schema file associated to root element
2026 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" +
2027 pConfigurableDomains->getKind() + ".xsd";
2028
2029 // Xml Source
2030 CXmlDocSource* pSource;
2031
2032 if (bFromFile) {
2033
2034 // when importing from a file strXmlSource is the file name
2035 pSource = new CXmlFileDocSource(strXmlSource, strXmlSchemaFilePath,
2036 pConfigurableDomains->getKind(),
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +02002037 pConfigurableDomains->getName(), "SystemClassName",
2038 _bValidateSchemasOnStart);
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002039
2040 } else {
2041
2042 // when importing from an xml string, strXmlSource contains the string
2043 pSource = new CXmlStringDocSource(strXmlSource, strXmlSchemaFilePath,
2044 pConfigurableDomains->getKind(),
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +02002045 pConfigurableDomains->getName(), "SystemClassName",
2046 _bValidateSchemasOnStart);
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002047
2048 }
2049 // Start clean
2050 pConfigurableDomains->clean();
2051
2052 // Use a doc sink that instantiate Configurable Domains from the given doc source
2053 CXmlMemoryDocSink memorySink(pConfigurableDomains);
2054
David Wagner29fa61f2014-12-19 11:15:02 +01002055 bool bProcessSuccess = memorySink.process(*pSource, xmlDomainImportContext);
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002056
2057 if (!bProcessSuccess) {
2058
2059 //Cleanup
2060 pConfigurableDomains->clean();
2061
2062 } else {
2063
2064 // Validate domains after XML import
2065 pConfigurableDomains->validate(_pMainParameterBlackboard);
2066
Patrick Benavoli68a91282011-08-31 11:23:23 +02002067 }
2068
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002069 delete pSource;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002070
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002071 return bProcessSuccess;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002072}
2073
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002074bool CParameterMgr::exportDomainsXml(string& strXmlDest, bool bWithSettings, bool bToFile,
2075 string& strError) const
Patrick Benavoli68a91282011-08-31 11:23:23 +02002076{
2077 // check path is absolute
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002078 if (bToFile && strXmlDest[0] != '/') {
Patrick Benavoli68a91282011-08-31 11:23:23 +02002079
2080 strError = "Please provide absolute path";
2081
2082 return false;
2083 }
2084
2085 // Root element
2086 const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains();
2087
2088 // Get Schema file associated to root element
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002089 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" +
2090 pConfigurableDomains->getKind() + ".xsd";
Patrick Benavoli68a91282011-08-31 11:23:23 +02002091
2092 // Context
David Wagner29fa61f2014-12-19 11:15:02 +01002093 CXmlDomainExportContext xmlDomainExportContext(strError, bWithSettings);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002094
2095 // Value space
David Wagner29fa61f2014-12-19 11:15:02 +01002096 xmlDomainExportContext.setValueSpaceRaw(_bValueSpaceIsRaw);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002097
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02002098 // Output raw format
David Wagner29fa61f2014-12-19 11:15:02 +01002099 xmlDomainExportContext.setOutputRawFormat(_bOutputRawFormatIsHex);
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02002100
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002101 // Use a doc source by loading data from instantiated Configurable Domains
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002102 CXmlMemoryDocSource memorySource(pConfigurableDomains, pConfigurableDomains->getKind(),
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +02002103 strXmlSchemaFilePath, "parameter-framework",
2104 getVersion(), _bValidateSchemasOnStart);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002105
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002106 // Xml Sink
2107 CXmlDocSink* pSink;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002108
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002109 if (bToFile) {
2110
2111 // Use a doc sink to write the doc data in a file
2112 pSink = new CXmlFileDocSink(strXmlDest);
2113
2114 } else {
2115
2116 // Use a doc sink to write the doc data in a string
2117 pSink = new CXmlStringDocSink(strXmlDest);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002118 }
2119
David Wagner29fa61f2014-12-19 11:15:02 +01002120 bool bProcessSuccess = pSink->process(memorySource, xmlDomainExportContext);
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002121
2122 delete pSink;
2123 return bProcessSuccess;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002124}
2125
2126// Binary Import/Export
2127bool CParameterMgr::importDomainsBinary(const string& strFileName, string& strError)
2128{
2129 // Check tuning mode
2130 if (!checkTuningModeOn(strError)) {
2131
2132 return false;
2133 }
2134 // check path is absolute
2135 if (strFileName[0] != '/') {
2136
2137 strError = "Please provide absolute path";
2138
2139 return false;
2140 }
2141 // Root element
2142 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
2143
2144 // Serialize in
2145 return pConfigurableDomains->serializeSettings(strFileName, false, _uiStructureChecksum, strError);
2146}
2147
2148bool CParameterMgr::exportDomainsBinary(const string& strFileName, string& strError)
2149{
2150 // check path is absolute
2151 if (strFileName[0] != '/') {
2152
2153 strError = "Please provide absolute path";
2154
2155 return false;
2156 }
Patrick Benavoli68a91282011-08-31 11:23:23 +02002157
Patrick Benavoli68a91282011-08-31 11:23:23 +02002158 // Root element
2159 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
2160
2161 // Serialize out
2162 return pConfigurableDomains->serializeSettings(strFileName, true, _uiStructureChecksum, strError);
2163}
2164
2165// For tuning, check we're in tuning mode
2166bool CParameterMgr::checkTuningModeOn(string& strError) const
2167{
2168 // Tuning Mode on?
2169 if (!_bTuningModeIsOn) {
2170
2171 strError = "Tuning Mode must be on";
2172
2173 return false;
2174 }
2175 return true;
2176}
2177
Patrick Benavoli065264a2011-11-20 15:46:41 +01002178// Tuning mutex dynamic parameter handling
2179pthread_mutex_t* CParameterMgr::getBlackboardMutex()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002180{
Patrick Benavoli065264a2011-11-20 15:46:41 +01002181 return &_blackboardMutex;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002182}
2183
Patrick Benavoli065264a2011-11-20 15:46:41 +01002184// Blackboard reference (dynamic parameter handling)
2185CParameterBlackboard* CParameterMgr::getParameterBlackboard()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002186{
Patrick Benavoli065264a2011-11-20 15:46:41 +01002187 return _pMainParameterBlackboard;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002188}
2189
Patrick Benavoli68a91282011-08-31 11:23:23 +02002190// Dynamic creation library feeding
2191void CParameterMgr::feedElementLibraries()
2192{
2193 // Global Configuration handling
2194 CElementLibrary* pFrameworkConfigurationLibrary = new CElementLibrary;
2195
Kevin Rocarda7b69602013-08-07 16:15:33 +02002196 pFrameworkConfigurationLibrary->addElementBuilder("ParameterFrameworkConfiguration", new TElementBuilderTemplate<CParameterFrameworkConfiguration>());
2197 pFrameworkConfigurationLibrary->addElementBuilder("SubsystemPlugins", new TKindElementBuilderTemplate<CSubsystemPlugins>());
2198 pFrameworkConfigurationLibrary->addElementBuilder("Location", new TKindElementBuilderTemplate<CPluginLocation>());
2199 pFrameworkConfigurationLibrary->addElementBuilder("StructureDescriptionFileLocation", new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>());
2200 pFrameworkConfigurationLibrary->addElementBuilder("SettingsConfiguration", new TKindElementBuilderTemplate<CFrameworkConfigurationGroup>());
2201 pFrameworkConfigurationLibrary->addElementBuilder("ConfigurableDomainsFileLocation", new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>());
2202 pFrameworkConfigurationLibrary->addElementBuilder("BinarySettingsFileLocation", new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002203
2204 _pElementLibrarySet->addElementLibrary(pFrameworkConfigurationLibrary);
2205
2206 // Parameter creation
2207 CElementLibrary* pParameterCreationLibrary = new CElementLibrary;
2208
Kevin Rocarda7b69602013-08-07 16:15:33 +02002209 pParameterCreationLibrary->addElementBuilder("Subsystem", new CSubsystemElementBuilder(getSystemClass()->getSubsystemLibrary()));
2210 pParameterCreationLibrary->addElementBuilder("ComponentType", new TNamedElementBuilderTemplate<CComponentType>());
2211 pParameterCreationLibrary->addElementBuilder("Component", new TNamedElementBuilderTemplate<CComponentInstance>());
2212 pParameterCreationLibrary->addElementBuilder("BitParameter", new TNamedElementBuilderTemplate<CBitParameterType>());
2213 pParameterCreationLibrary->addElementBuilder("BitParameterBlock", new TNamedElementBuilderTemplate<CBitParameterBlockType>());
2214 pParameterCreationLibrary->addElementBuilder("StringParameter", new TNamedElementBuilderTemplate<CStringParameterType>());
2215 pParameterCreationLibrary->addElementBuilder("ParameterBlock", new TNamedElementBuilderTemplate<CParameterBlockType>());
2216 pParameterCreationLibrary->addElementBuilder("BooleanParameter", new TNamedElementBuilderTemplate<CBooleanParameterType>());
2217 pParameterCreationLibrary->addElementBuilder("IntegerParameter", new TNamedElementBuilderTemplate<CIntegerParameterType>());
2218 pParameterCreationLibrary->addElementBuilder("LinearAdaptation", new TElementBuilderTemplate<CLinearParameterAdaptation>());
2219 pParameterCreationLibrary->addElementBuilder("EnumParameter", new TNamedElementBuilderTemplate<CEnumParameterType>());
2220 pParameterCreationLibrary->addElementBuilder("ValuePair", new TElementBuilderTemplate<CEnumValuePair>());
2221 pParameterCreationLibrary->addElementBuilder("FixedPointParameter", new TNamedElementBuilderTemplate<CFixedPointParameterType>());
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +02002222 pParameterCreationLibrary->addElementBuilder("SubsystemInclude", new CFileIncluderElementBuilder(_bValidateSchemasOnStart));
Patrick Benavoli68a91282011-08-31 11:23:23 +02002223
2224 _pElementLibrarySet->addElementLibrary(pParameterCreationLibrary);
2225
2226 // Parameter Configuration Domains creation
2227 CElementLibrary* pParameterConfigurationLibrary = new CElementLibrary;
2228
Kevin Rocarda7b69602013-08-07 16:15:33 +02002229 pParameterConfigurationLibrary->addElementBuilder("ConfigurableDomain", new TNamedElementBuilderTemplate<CConfigurableDomain>());
2230 pParameterConfigurationLibrary->addElementBuilder("Configuration", new TNamedElementBuilderTemplate<CDomainConfiguration>());
2231 pParameterConfigurationLibrary->addElementBuilder("CompoundRule", new TElementBuilderTemplate<CCompoundRule>());
2232 pParameterConfigurationLibrary->addElementBuilder("SelectionCriterionRule", new TElementBuilderTemplate<CSelectionCriterionRule>());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002233
2234 _pElementLibrarySet->addElementLibrary(pParameterConfigurationLibrary);
2235}
2236
2237// Remote Processor Server connection handling
2238bool CParameterMgr::handleRemoteProcessingInterface(string& strError)
2239{
2240 CAutoLog autoLog(this, "Handling remote processing interface");
2241
2242 // Start server if tuning allowed
Patrick Benavoli95ac0342011-11-07 20:32:51 +01002243 if (getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02002244
Kevin Rocardace81f82012-12-11 16:19:17 +01002245 log_info("Loading remote processor library");
Patrick Benavoli68a91282011-08-31 11:23:23 +02002246
2247 // Load library
Renaud de Chivre1b8b3ca2013-12-13 15:09:44 +01002248 _handleLibRemoteProcessor = dlopen("libremote-processor.so", RTLD_NOW);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002249
Renaud de Chivre1b8b3ca2013-12-13 15:09:44 +01002250 if (!_handleLibRemoteProcessor) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02002251
2252 // Return error
2253 const char* pcError = dlerror();
2254
2255 if (pcError) {
2256
2257 strError = pcError;
2258 } else {
2259
2260 strError = "Unable to load libremote-processor.so library";
2261 }
2262
2263 return false;
2264 }
2265
Renaud de Chivre1b8b3ca2013-12-13 15:09:44 +01002266 CreateRemoteProcessorServer pfnCreateRemoteProcessorServer = (CreateRemoteProcessorServer)dlsym(_handleLibRemoteProcessor, "createRemoteProcessorServer");
Patrick Benavoli68a91282011-08-31 11:23:23 +02002267
2268 if (!pfnCreateRemoteProcessorServer) {
2269
2270 strError = "libremote-process.so does not contain createRemoteProcessorServer symbol.";
2271
2272 return false;
2273 }
2274
2275 // Create server
Patrick Benavoli95ac0342011-11-07 20:32:51 +01002276 _pRemoteProcessorServer = pfnCreateRemoteProcessorServer(getConstFrameworkConfiguration()->getServerPort(), _pCommandHandler);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002277
Kevin Rocardace81f82012-12-11 16:19:17 +01002278 log_info("Starting remote processor server on port %d", getConstFrameworkConfiguration()->getServerPort());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002279 // Start
2280 if (!_pRemoteProcessorServer->start()) {
2281
Frédéric Boisnard6c55e9a2014-01-10 18:46:33 +01002282 ostringstream oss;
2283 oss << "ParameterMgr: Unable to start remote processor server on port "
2284 << getConstFrameworkConfiguration()->getServerPort();
2285 strError = oss.str();
Patrick Benavoli68a91282011-08-31 11:23:23 +02002286
2287 return false;
2288 }
2289 }
2290
2291 return true;
2292}
2293
2294// Back synchronization
Kevin Rocardace81f82012-12-11 16:19:17 +01002295CBackSynchronizer* CParameterMgr::createBackSynchronizer() const
Patrick Benavoli68a91282011-08-31 11:23:23 +02002296{
2297#ifdef SIMULATION
2298 // In simulation, back synchronization of the blackboard won't probably work
2299 // We need to ensure though the blackboard is initialized with valid data
Kevin Rocardace81f82012-12-11 16:19:17 +01002300 return new CSimulatedBackSynchronizer(getConstSystemClass(), _pMainParameterBlackboard);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002301#else
2302 // Real back synchronizer from subsystems
Kevin Rocardace81f82012-12-11 16:19:17 +01002303 return new CHardwareBackSynchronizer(getConstSystemClass(), _pMainParameterBlackboard);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002304#endif
2305}
2306
2307// Children typwise access
2308CParameterFrameworkConfiguration* CParameterMgr::getFrameworkConfiguration()
2309{
2310 return static_cast<CParameterFrameworkConfiguration*>(getChild(EFrameworkConfiguration));
2311}
2312
2313const CParameterFrameworkConfiguration* CParameterMgr::getConstFrameworkConfiguration()
2314{
2315 return getFrameworkConfiguration();
2316}
2317
2318CSelectionCriteria* CParameterMgr::getSelectionCriteria()
2319{
2320 return static_cast<CSelectionCriteria*>(getChild(ESelectionCriteria));
2321}
2322
2323const CSelectionCriteria* CParameterMgr::getConstSelectionCriteria()
2324{
2325 return static_cast<const CSelectionCriteria*>(getChild(ESelectionCriteria));
2326}
2327
2328CSystemClass* CParameterMgr::getSystemClass()
2329{
2330 return static_cast<CSystemClass*>(getChild(ESystemClass));
2331}
2332
2333const CSystemClass* CParameterMgr::getConstSystemClass() const
2334{
2335 return static_cast<const CSystemClass*>(getChild(ESystemClass));
2336}
2337
2338// Configurable Domains
2339CConfigurableDomains* CParameterMgr::getConfigurableDomains()
2340{
2341 return static_cast<CConfigurableDomains*>(getChild(EConfigurableDomains));
2342}
2343
2344const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains()
2345{
2346 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
2347}
2348
2349const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains() const
2350{
2351 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
2352}
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002353
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01002354// Apply configurations
2355void CParameterMgr::doApplyConfigurations(bool bForce)
2356{
2357 CSyncerSet syncerSet;
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002358
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01002359 // Check subsystems that need resync
2360 getSystemClass()->checkForSubsystemsToResync(syncerSet);
2361
2362 // Ensure application of currently selected configurations
2363 getConfigurableDomains()->apply(_pMainParameterBlackboard, syncerSet, bForce);
2364
2365 // Reset the modified status of the current criteria to indicate that a new configuration has been applied
2366 getSelectionCriteria()->resetModifiedStatus();
2367}
2368
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002369bool CParameterMgr::getSystemClassXMLString(string& strResult)
2370{
2371 // Root element
2372 const CSystemClass* pSystemClass = getSystemClass();
2373
2374 string strError;
2375
2376 CXmlSerializingContext xmlSerializingContext(strError);
2377
2378 // Use a doc source by loading data from instantiated Configurable Domains
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +02002379 CXmlMemoryDocSource memorySource(pSystemClass, pSystemClass->getKind(),
2380 _bValidateSchemasOnStart);
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002381
2382 // Use a doc sink that write the doc data in a string
2383 CXmlStringDocSink stringSink(strResult);
2384
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002385 bool bProcessSuccess = stringSink.process(memorySource, xmlSerializingContext);
2386
2387 if (!bProcessSuccess) {
2388
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002389 strResult = strError;
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002390
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002391 }
2392
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002393 return bProcessSuccess;
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002394}