blob: 8a6adf0534f741fb7ee664e151bc753366be4d02 [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 Wagnerd8a53102014-12-10 14:49:23 +0100625 CXmlDomainImportContext xmlDomainImportContext(strError, !pBinarySettingsFileLocation,
626 *getSystemClass());
Patrick Benavoli68a91282011-08-31 11:23:23 +0200627
628 // Selection criteria definition for rule creation
David Wagner29fa61f2014-12-19 11:15:02 +0100629 xmlDomainImportContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
Patrick Benavoli68a91282011-08-31 11:23:23 +0200630
Patrick Benavoli63499d42011-10-24 18:50:03 +0200631 // Auto validation of configurations if no binary settings provided
David Wagner29fa61f2014-12-19 11:15:02 +0100632 xmlDomainImportContext.setAutoValidationRequired(!pBinarySettingsFileLocation);
Patrick Benavoli63499d42011-10-24 18:50:03 +0200633
Kevin Rocardace81f82012-12-11 16:19:17 +0100634 log_info("Importing configurable domains from file %s %s settings", strXmlConfigurationDomainsFilePath.c_str(), pBinarySettingsFileLocation ? "without" : "with");
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200635
Patrick Benavoli68a91282011-08-31 11:23:23 +0200636 // Do parse
David Wagner29fa61f2014-12-19 11:15:02 +0100637 if (!xmlParse(xmlDomainImportContext, pConfigurableDomains, strXmlConfigurationDomainsFilePath, strXmlConfigurationDomainsFolder, EParameterConfigurationLibrary, "SystemClassName")) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200638
639 return false;
640 }
641 // We have loaded the whole system structure, compute checksum
642 const CSystemClass* pSystemClass = getConstSystemClass();
643 _uiStructureChecksum = pSystemClass->computeStructureChecksum() + getConfigurableDomains()->computeStructureChecksum() + getSelectionCriteria()->computeStructureChecksum();
644
645 // Load binary settings if any provided
646 if (pBinarySettingsFileLocation && !pConfigurableDomains->serializeSettings(strXmlBinarySettingsFilePath, false, _uiStructureChecksum, strError)) {
647
648 return false;
649 }
650
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200651 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200652}
653
654// XML parsing
655bool CParameterMgr::xmlParse(CXmlElementSerializingContext& elementSerializingContext, CElement* pRootElement, const string& strXmlFilePath, const string& strXmlFolder, CParameterMgr::ElementLibrary eElementLibrary, const string& strNameAttrituteName)
656{
657 // Init serializing context
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +0200658 elementSerializingContext.set(_pElementLibrarySet->getElementLibrary(
659 eElementLibrary), strXmlFolder, _strSchemaFolderLocation);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200660
661 // Get Schema file associated to root element
662 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pRootElement->getKind() + ".xsd";
663
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +0200664 CXmlFileDocSource fileDocSource(strXmlFilePath, strXmlSchemaFilePath,
665 pRootElement->getKind(),
666 pRootElement->getName(), strNameAttrituteName,
667 _bValidateSchemasOnStart);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200668
669 // Start clean
670 pRootElement->clean();
671
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200672 CXmlMemoryDocSink memorySink(pRootElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200673
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200674 if (!memorySink.process(fileDocSource, elementSerializingContext)) {
675 //Cleanup
Patrick Benavoli68a91282011-08-31 11:23:23 +0200676 pRootElement->clean();
677
678 return false;
679 }
680
Patrick Benavoli68a91282011-08-31 11:23:23 +0200681 return true;
682}
683
684// Init
685bool CParameterMgr::init(string& strError)
686{
687 return base::init(strError);
688}
689
690// Selection criteria interface
691CSelectionCriterionType* CParameterMgr::createSelectionCriterionType(bool bIsInclusive)
692{
693 // Propagate
694 return getSelectionCriteria()->createSelectionCriterionType(bIsInclusive);
695}
696
697CSelectionCriterion* CParameterMgr::createSelectionCriterion(const string& strName, const CSelectionCriterionType* pSelectionCriterionType)
698{
699 // Propagate
700 return getSelectionCriteria()->createSelectionCriterion(strName, pSelectionCriterionType);
701}
702
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200703// Selection criterion retrieval
704CSelectionCriterion* CParameterMgr::getSelectionCriterion(const string& strName)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200705{
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200706 // Propagate
707 return getSelectionCriteria()->getSelectionCriterion(strName);
708}
709
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100710// Configuration application
Kevin Rocardace81f82012-12-11 16:19:17 +0100711void CParameterMgr::applyConfigurations()
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200712{
713 CAutoLog autoLog(this, "Configuration application request");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200714
715 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +0100716 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200717
718 if (!_bTuningModeIsOn) {
719
720 // Apply configuration(s)
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100721 doApplyConfigurations(false);
Frédéric Boisnarddaaa63c2012-08-27 15:48:15 +0200722 } else {
723
Kevin Rocardace81f82012-12-11 16:19:17 +0100724 log_warning("Configurations were not applied because the TuningMode is on");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200725 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200726}
727
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200728// Get the configurableElement corresponding to the given path
729const CConfigurableElement* CParameterMgr::getConfigurableElement(const string& strPath,
730 string& strError) const
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200731{
Patrick Benavoli065264a2011-11-20 15:46:41 +0100732 CPathNavigator pathNavigator(strPath);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200733
Patrick Benavoli065264a2011-11-20 15:46:41 +0100734 // Nagivate through system class
735 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
736
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100737 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100738 }
739
740 // Find element
741 const CElement* pElement = getConstSystemClass()->findDescendant(pathNavigator);
742
743 if (!pElement) {
744
Kevin Rocard4c3f8d82013-11-21 12:16:28 +0100745 strError = "Path not found: " + strPath;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100746
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100747 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100748 }
749
750 // Check found element is a parameter
751 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pElement);
752
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200753 return pConfigurableElement;
754}
755
756// Dynamic parameter handling
757CParameterHandle* CParameterMgr::createParameterHandle(const string& strPath, string& strError)
758{
759 const CConfigurableElement* pConfigurableElement = getConfigurableElement(strPath, strError);
760
761 if (!pConfigurableElement) {
762
763 // Element not found
Kevin Rocard4c3f8d82013-11-21 12:16:28 +0100764 strError = "Element not found: " + strPath;
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200765 return NULL;
766 }
767
Patrick Benavoli065264a2011-11-20 15:46:41 +0100768 if (!pConfigurableElement->isParameter()) {
769
770 // Element is not parameter
Kevin Rocard4c3f8d82013-11-21 12:16:28 +0100771 strError = "Not a parameter: " + strPath;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100772
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100773 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100774 }
775
776 // Convert as parameter and return new handle
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200777 return new CParameterHandle(static_cast<const CBaseParameter*>(pConfigurableElement), this);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200778}
779
Kevin Rocardecf93102013-07-10 18:28:10 +0200780void CParameterMgr::setFailureOnMissingSubsystem(bool bFail)
781{
782 _bFailOnMissingSubsystem = bFail;
783}
784
785bool CParameterMgr::getFailureOnMissingSubsystem() const
786{
787 return _bFailOnMissingSubsystem;
788}
Kevin Rocardd6909eb2013-07-18 09:13:51 +0200789
790void CParameterMgr::setFailureOnFailedSettingsLoad(bool bFail)
791{
792 _bFailOnFailedSettingsLoad = bFail;
793}
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +0200794
Kevin Rocardd6909eb2013-07-18 09:13:51 +0200795bool CParameterMgr::getFailureOnFailedSettingsLoad()
796{
797 return _bFailOnFailedSettingsLoad;
798}
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +0200799
800void CParameterMgr::setValidateSchemasOnStart(bool bValidate)
801{
802 _bValidateSchemasOnStart = bValidate;
803}
804
805bool CParameterMgr::getValidateSchemasOnStart() const
806{
807 return _bValidateSchemasOnStart;
808}
809
Patrick Benavoli68a91282011-08-31 11:23:23 +0200810/////////////////// Remote command parsers
Patrick Benavoli592ae562011-09-05 16:53:58 +0200811/// Version
Patrick Benavoli63499d42011-10-24 18:50:03 +0200812CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::versionCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli592ae562011-09-05 16:53:58 +0200813{
814 (void)remoteCommand;
815
Patrick Benavoli63499d42011-10-24 18:50:03 +0200816 // Show version
817 strResult = getVersion();
Patrick Benavoli592ae562011-09-05 16:53:58 +0200818
Patrick Benavoli63499d42011-10-24 18:50:03 +0200819 return CCommandHandler::ESucceeded;
Patrick Benavoli592ae562011-09-05 16:53:58 +0200820}
821
Patrick Benavoli68a91282011-08-31 11:23:23 +0200822/// Status
Patrick Benavoli63499d42011-10-24 18:50:03 +0200823CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::statusCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200824{
825 (void)remoteCommand;
826 // System class
827 const CSystemClass* pSystemClass = getSystemClass();
828
Patrick Benavoli68a91282011-08-31 11:23:23 +0200829 // Show status
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200830 /// General section
831 appendTitle(strResult, "General:");
832 // System class
Patrick Benavoli68a91282011-08-31 11:23:23 +0200833 strResult += "System Class: ";
834 strResult += pSystemClass->getName();
835 strResult += "\n";
836
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200837 // Tuning mode
Patrick Benavoli68a91282011-08-31 11:23:23 +0200838 strResult += "Tuning Mode: ";
839 strResult += tuningModeOn() ? "on" : "off";
840 strResult += "\n";
841
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200842 // Value space
Patrick Benavoli68a91282011-08-31 11:23:23 +0200843 strResult += "Value Space: ";
844 strResult += valueSpaceIsRaw() ? "raw" : "real";
845 strResult += "\n";
846
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200847 // Output raw format
848 strResult += "Output Raw Format: ";
849 strResult += outputRawFormatIsHex() ? "hex" : "dec";
850 strResult += "\n";
851
852 // Auto Sync
Patrick Benavoli68a91282011-08-31 11:23:23 +0200853 strResult += "Auto Sync: ";
854 strResult += autoSyncOn() ? "on" : "off";
855 strResult += "\n";
856
857 /// Subsystem list
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200858 appendTitle(strResult, "Subsystems:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200859 string strSubsystemList;
860 pSystemClass->listChildrenPaths(strSubsystemList);
861 strResult += strSubsystemList;
862
863 /// Last applied configurations
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200864 appendTitle(strResult, "Last Applied [Pending] Configurations:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200865 string strLastAppliedConfigurations;
866 getConfigurableDomains()->listLastAppliedConfigurations(strLastAppliedConfigurations);
867 strResult += strLastAppliedConfigurations;
868
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200869 /// Criteria states
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200870 appendTitle(strResult, "Selection Criteria:");
Kevin Rocard7f265822012-12-07 18:51:22 +0100871 list<string> lstrSelectionCriteria;
872 getSelectionCriteria()->listSelectionCriteria(lstrSelectionCriteria, false, true);
873 // Concatenate the criterion list as the command result
Frederic Boisnard390b36d2013-05-23 15:28:31 +0200874 string strCriteriaStates;
875 CUtility::asString(lstrSelectionCriteria, strCriteriaStates);
876 strResult += strCriteriaStates;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200877
Patrick Benavoli63499d42011-10-24 18:50:03 +0200878 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200879}
880
881/// Tuning Mode
Patrick Benavoli63499d42011-10-24 18:50:03 +0200882CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200883{
884 if (remoteCommand.getArgument(0) == "on") {
885
886 if (setTuningMode(true, strResult)) {
887
Patrick Benavoli63499d42011-10-24 18:50:03 +0200888 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200889 }
890 } else if (remoteCommand.getArgument(0) == "off") {
891
892 if (setTuningMode(false, strResult)) {
893
Patrick Benavoli63499d42011-10-24 18:50:03 +0200894 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200895 }
896 } else {
897 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200898 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200899 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200900 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200901}
902
Patrick Benavoli63499d42011-10-24 18:50:03 +0200903CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200904{
905 (void)remoteCommand;
906
907 strResult = tuningModeOn() ? "on" : "off";
908
Patrick Benavoli63499d42011-10-24 18:50:03 +0200909 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200910}
911
912/// Value Space
Patrick Benavoli63499d42011-10-24 18:50:03 +0200913CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200914{
915 (void)strResult;
916
917 if (remoteCommand.getArgument(0) == "raw") {
918
919 setValueSpace(true);
920
Patrick Benavoli63499d42011-10-24 18:50:03 +0200921 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200922
923 } else if (remoteCommand.getArgument(0) == "real") {
924
925 setValueSpace(false);
926
Patrick Benavoli63499d42011-10-24 18:50:03 +0200927 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200928
929 } else {
930 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200931 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200932 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200933 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200934}
935
Patrick Benavoli63499d42011-10-24 18:50:03 +0200936CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200937{
938 (void)remoteCommand;
939
940 strResult = valueSpaceIsRaw() ? "raw" : "real";
941
Patrick Benavoli63499d42011-10-24 18:50:03 +0200942 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200943}
944
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200945/// Output Raw Format
Patrick Benavoli63499d42011-10-24 18:50:03 +0200946CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200947{
948 (void)strResult;
949
950 if (remoteCommand.getArgument(0) == "hex") {
951
952 setOutputRawFormat(true);
953
Patrick Benavoli63499d42011-10-24 18:50:03 +0200954 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200955
956 } else if (remoteCommand.getArgument(0) == "dec") {
957
958 setOutputRawFormat(false);
959
Patrick Benavoli63499d42011-10-24 18:50:03 +0200960 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200961
962 } else {
963 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200964 return CCommandHandler::EShowUsage;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200965 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200966 return CCommandHandler::EFailed;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200967}
968
Patrick Benavoli63499d42011-10-24 18:50:03 +0200969CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200970{
971 (void)remoteCommand;
972
973 strResult = outputRawFormatIsHex() ? "hex" : "dec";
974
Patrick Benavoli63499d42011-10-24 18:50:03 +0200975 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200976}
977
Patrick Benavoli68a91282011-08-31 11:23:23 +0200978/// Sync
Patrick Benavoli63499d42011-10-24 18:50:03 +0200979CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200980{
981 if (remoteCommand.getArgument(0) == "on") {
982
983 if (setAutoSync(true, strResult)) {
984
Patrick Benavoli63499d42011-10-24 18:50:03 +0200985 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200986 }
987 } else if (remoteCommand.getArgument(0) == "off") {
988
989 if (setAutoSync(false, strResult)) {
990
Patrick Benavoli63499d42011-10-24 18:50:03 +0200991 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200992 }
993 } else {
994 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200995 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200996 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200997 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200998}
999
Patrick Benavoli63499d42011-10-24 18:50:03 +02001000CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001001{
1002 (void)remoteCommand;
1003
1004 strResult = autoSyncOn() ? "on" : "off";
1005
Patrick Benavoli63499d42011-10-24 18:50:03 +02001006 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001007}
1008
Patrick Benavoli63499d42011-10-24 18:50:03 +02001009CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::syncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001010{
1011 (void)remoteCommand;
1012
Patrick Benavoli63499d42011-10-24 18:50:03 +02001013 return sync(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001014}
1015
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001016/// Criteria
Patrick Benavoli63499d42011-10-24 18:50:03 +02001017CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listCriteriaCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001018{
1019 (void)remoteCommand;
1020
Kevin Rocard4eae8272013-04-18 19:12:46 +02001021 bool humanReadable = true;
Kevin Rocard7f265822012-12-07 18:51:22 +01001022
Kevin Rocard4eae8272013-04-18 19:12:46 +02001023 // Look for optional arguments
1024 if (remoteCommand.getArgumentCount() >= 1) {
1025
1026 // If csv is provided, format the criterion list in Commas Separated Value pairs
1027 if (remoteCommand.getArgument(0) == "csv") {
1028 humanReadable = false;
1029 } else {
1030 return CCommandHandler::EShowUsage;
1031 }
1032 }
1033
1034 list<string> lstrResult;
1035 getSelectionCriteria()->listSelectionCriteria(lstrResult, true, humanReadable);
Kevin Rocard7f265822012-12-07 18:51:22 +01001036
1037 // Concatenate the criterion list as the command result
Frederic Boisnard390b36d2013-05-23 15:28:31 +02001038 CUtility::asString(lstrResult, strResult);
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001039
Patrick Benavoli63499d42011-10-24 18:50:03 +02001040 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001041}
Patrick Benavoli68a91282011-08-31 11:23:23 +02001042
1043/// Domains
Patrick Benavoli63499d42011-10-24 18:50:03 +02001044CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001045{
1046 (void)remoteCommand;
1047
Patrick Benavoli63499d42011-10-24 18:50:03 +02001048 getConfigurableDomains()->listDomains(strResult);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001049
Patrick Benavoli63499d42011-10-24 18:50:03 +02001050 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001051}
1052
Patrick Benavoli63499d42011-10-24 18:50:03 +02001053CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001054{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001055 return createDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001056}
1057
Patrick Benavoli63499d42011-10-24 18:50:03 +02001058CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001059{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001060 return deleteDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001061}
1062
Kevin Rocard170f0a42012-06-18 13:56:05 +02001063CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteAllDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1064{
1065 (void)remoteCommand;
1066
1067 return deleteAllDomains(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1068}
1069
Patrick Benavoli63499d42011-10-24 18:50:03 +02001070CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001071{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001072 return getConfigurableDomains()->renameDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001073}
1074
Patrick Benavoli63499d42011-10-24 18:50:03 +02001075CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001076{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001077 // Check tuning mode
1078 if (!checkTuningModeOn(strResult)) {
1079
1080 return CCommandHandler::EFailed;
1081 }
1082
1083 // Set property
1084 bool bSequenceAware;
1085
1086 if (remoteCommand.getArgument(1) == "true") {
1087
1088 bSequenceAware = true;
1089
1090 } else if (remoteCommand.getArgument(1) == "false") {
1091
1092 bSequenceAware = false;
1093
1094 } else {
1095 // Show usage
1096 return CCommandHandler::EShowUsage;
1097 }
1098
1099 return getConfigurableDomains()->setSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001100}
1101
Patrick Benavoli63499d42011-10-24 18:50:03 +02001102CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001103{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001104 // Get property
1105 bool bSequenceAware;
1106
1107 if (!getConfigurableDomains()->getSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult)) {
1108
1109 return CCommandHandler::EFailed;
1110 }
1111
1112 strResult = bSequenceAware ? "true" : "false";
1113
1114 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001115}
1116
Patrick Benavoli63499d42011-10-24 18:50:03 +02001117CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001118{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001119 return getConfigurableDomains()->listDomainElements(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001120}
1121
Patrick Benavoli63499d42011-10-24 18:50:03 +02001122CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::addElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001123{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001124 return addConfigurableElementToDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1125}
1126
1127CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::removeElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1128{
1129 return removeConfigurableElementFromDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1130}
1131
1132CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::splitDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1133{
1134 return split(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001135}
1136
1137/// Configurations
Patrick Benavoli63499d42011-10-24 18:50:03 +02001138CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConfigurationsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001139{
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001140 return getConstConfigurableDomains()->listConfigurations(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
1141}
1142
1143CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1144{
1145 (void)remoteCommand;
1146
1147 // Dummy error context
1148 string strError;
1149 CErrorContext errorContext(strError);
1150
1151 // Dump
1152 getConstConfigurableDomains()->dumpContent(strResult, errorContext);
1153
1154 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001155}
1156
Patrick Benavoli63499d42011-10-24 18:50:03 +02001157CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001158{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001159 return createConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001160}
1161
Patrick Benavoli63499d42011-10-24 18:50:03 +02001162CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001163{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001164 return deleteConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001165}
1166
Patrick Benavoli63499d42011-10-24 18:50:03 +02001167CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001168{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001169 return getConfigurableDomains()->renameConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001170}
1171
Patrick Benavoli63499d42011-10-24 18:50:03 +02001172CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::saveConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001173{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001174 return saveConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001175}
1176
Patrick Benavoli63499d42011-10-24 18:50:03 +02001177CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::restoreConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001178{
Kevin Rocardace81f82012-12-11 16:19:17 +01001179 list<string> lstrResult;
1180 if (!restoreConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), lstrResult)) {
1181 //Concatenate the error list as the command result
Frederic Boisnard390b36d2013-05-23 15:28:31 +02001182 CUtility::asString(lstrResult, strResult);
Kevin Rocardace81f82012-12-11 16:19:17 +01001183
1184 return CCommandHandler::EFailed;
1185 }
1186 return CCommandHandler::EDone;
Patrick Benavoli63499d42011-10-24 18:50:03 +02001187}
1188
1189CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1190{
1191 // Check tuning mode
1192 if (!checkTuningModeOn(strResult)) {
1193
1194 return CCommandHandler::EFailed;
1195 }
1196
1197 // Build configurable element path list
Sebastien Gonzalved9526492014-02-20 22:28:03 +01001198 std::vector<string> astrNewElementSequence;
Patrick Benavoli63499d42011-10-24 18:50:03 +02001199
1200 uint32_t uiArgument;
1201
1202 for (uiArgument = 2; uiArgument < remoteCommand.getArgumentCount(); uiArgument++) {
1203
1204 astrNewElementSequence.push_back(remoteCommand.getArgument(uiArgument));
1205 }
1206
1207 // Delegate to configurable domains
1208 return getConfigurableDomains()->setElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), astrNewElementSequence, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1209}
1210
1211CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1212{
1213 // Delegate to configurable domains
1214 return getConfigurableDomains()->getElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001215}
1216
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001217CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1218{
1219 // Delegate to configurable domains
1220 return getConfigurableDomains()->setApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.packArguments(2, remoteCommand.getArgumentCount() - 2), getConstSelectionCriteria()->getSelectionCriteriaDefinition(), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1221}
1222
1223CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::clearRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1224{
1225 // Delegate to configurable domains
1226 return getConfigurableDomains()->clearApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1227}
1228
1229CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1230{
1231 // Delegate to configurable domains
1232 return getConfigurableDomains()->getApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
1233}
1234
Patrick Benavoli68a91282011-08-31 11:23:23 +02001235/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001236CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001237{
1238 CElementLocator elementLocator(getSystemClass(), false);
1239
1240 CElement* pLocatedElement = NULL;
1241
1242 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1243
Patrick Benavoli63499d42011-10-24 18:50:03 +02001244 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001245 }
1246
1247 strResult = string("\n");
1248
1249 if (!pLocatedElement) {
1250
1251 // List from root folder
1252
1253 // Return system class qualified name
1254 pLocatedElement = getSystemClass();
1255 }
1256
1257 // Return sub-elements
1258 strResult += pLocatedElement->listQualifiedPaths(false);
1259
Patrick Benavoli63499d42011-10-24 18:50:03 +02001260 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001261}
1262
1263/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001264CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listParametersCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001265{
1266 CElementLocator elementLocator(getSystemClass(), false);
1267
1268 CElement* pLocatedElement = NULL;
1269
1270 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1271
Patrick Benavoli63499d42011-10-24 18:50:03 +02001272 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001273 }
1274
1275 strResult = string("\n");
1276
1277 if (!pLocatedElement) {
1278
1279 // List from root folder
1280
1281 // Return system class qualified name
1282 pLocatedElement = getSystemClass();
1283 }
1284
1285 // Return sub-elements
1286 strResult += pLocatedElement->listQualifiedPaths(true);
1287
Patrick Benavoli63499d42011-10-24 18:50:03 +02001288 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001289}
1290
Patrick Benavoli63499d42011-10-24 18:50:03 +02001291CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001292{
1293 CElementLocator elementLocator(getSystemClass());
1294
1295 CElement* pLocatedElement = NULL;
1296
1297 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1298
Patrick Benavoli63499d42011-10-24 18:50:03 +02001299 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001300 }
1301
1302 string strError;
1303
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001304 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001305
1306 // Dump elements
1307 pLocatedElement->dumpContent(strResult, parameterAccessContext);
1308
Patrick Benavoli63499d42011-10-24 18:50:03 +02001309 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001310}
1311
Patrick Benavoli63499d42011-10-24 18:50:03 +02001312CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSizeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001313{
1314 CElementLocator elementLocator(getSystemClass());
1315
1316 CElement* pLocatedElement = NULL;
1317
1318 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1319
Patrick Benavoli63499d42011-10-24 18:50:03 +02001320 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001321 }
1322
1323 // Converted to actual sizable element
1324 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1325
1326 // Get size as string
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001327 strResult = pConfigurableElement->getFootprintAsString();
Patrick Benavoli68a91282011-08-31 11:23:23 +02001328
Patrick Benavoli63499d42011-10-24 18:50:03 +02001329 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001330}
1331
Patrick Benavoli63499d42011-10-24 18:50:03 +02001332CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showPropertiesCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001333{
1334 CElementLocator elementLocator(getSystemClass());
1335
1336 CElement* pLocatedElement = NULL;
1337
1338 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1339
Patrick Benavoli63499d42011-10-24 18:50:03 +02001340 return CCommandHandler::EFailed;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001341 }
1342
1343 // Convert element
1344 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1345
1346 // Return element properties
1347 pConfigurableElement->showProperties(strResult);
1348
Patrick Benavoli63499d42011-10-24 18:50:03 +02001349 return CCommandHandler::ESucceeded;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001350}
1351
Patrick Benavoli63499d42011-10-24 18:50:03 +02001352CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001353{
1354 string strValue;
1355
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001356 if (!accessParameterValue(remoteCommand.getArgument(0), strValue, false, strResult)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001357
Patrick Benavoli63499d42011-10-24 18:50:03 +02001358 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001359 }
1360 // Succeeded
1361 strResult = strValue;
1362
Patrick Benavoli63499d42011-10-24 18:50:03 +02001363 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001364}
1365
Patrick Benavoli63499d42011-10-24 18:50:03 +02001366CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001367{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001368 // Check tuning mode
1369 if (!checkTuningModeOn(strResult)) {
1370
1371 return CCommandHandler::EFailed;
1372 }
1373 // Get value to set
1374 string strValue = remoteCommand.packArguments(1, remoteCommand.getArgumentCount() - 1);
1375
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001376 return accessParameterValue(remoteCommand.getArgument(0), strValue, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001377}
1378
Patrick Benavoli63499d42011-10-24 18:50:03 +02001379CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listBelongingDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001380{
1381 CElementLocator elementLocator(getSystemClass());
1382
1383 CElement* pLocatedElement = NULL;
1384
1385 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1386
Patrick Benavoli63499d42011-10-24 18:50:03 +02001387 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001388 }
1389
1390 // Convert element
1391 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1392
1393 // Return element belonging domains
1394 pConfigurableElement->listBelongingDomains(strResult);
1395
Patrick Benavoli63499d42011-10-24 18:50:03 +02001396 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001397}
1398
Patrick Benavoli63499d42011-10-24 18:50:03 +02001399CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001400{
1401 CElementLocator elementLocator(getSystemClass());
1402
1403 CElement* pLocatedElement = NULL;
1404
1405 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1406
Patrick Benavoli63499d42011-10-24 18:50:03 +02001407 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001408 }
1409
1410 // Convert element
1411 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1412
1413 // Return element belonging domains
1414 pConfigurableElement->listAssociatedDomains(strResult);
1415
Patrick Benavoli63499d42011-10-24 18:50:03 +02001416 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001417}
1418
Patrick Benavoli63499d42011-10-24 18:50:03 +02001419CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001420{
1421 (void)remoteCommand;
1422
1423 getConfigurableDomains()->listAssociatedElements(strResult);
1424
Patrick Benavoli63499d42011-10-24 18:50:03 +02001425 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001426}
1427
Patrick Benavoli63499d42011-10-24 18:50:03 +02001428CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConflictingElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001429{
1430 (void)remoteCommand;
1431
1432 getConfigurableDomains()->listConflictingElements(strResult);
1433
Patrick Benavoli63499d42011-10-24 18:50:03 +02001434 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001435}
1436
Patrick Benavoli63499d42011-10-24 18:50:03 +02001437CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listRogueElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001438{
1439 (void)remoteCommand;
1440
1441 getSystemClass()->listRogueElements(strResult);
1442
Patrick Benavoli63499d42011-10-24 18:50:03 +02001443 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001444}
1445
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001446CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getConfigurationParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1447{
1448 string strOutputValue;
1449 string strError;
1450
1451 if (!accessConfigurationValue(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), strOutputValue, false, strError)) {
1452
1453 strResult = strError;
1454 return CCommandHandler::EFailed;
1455 }
1456 // Succeeded
1457 strResult = strOutputValue;
1458
1459 return CCommandHandler::ESucceeded;
1460}
1461
1462CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setConfigurationParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1463{
1464 // Get value to set
1465 string strValue = remoteCommand.packArguments(3, remoteCommand.getArgumentCount() - 3);
1466
1467 bool bSuccess = accessConfigurationValue(remoteCommand.getArgument(0),
1468 remoteCommand.getArgument(1),
1469 remoteCommand.getArgument(2),
1470 strValue, true, strResult);
1471
1472 return bSuccess ? CCommandHandler::EDone : CCommandHandler::EFailed;
1473}
1474
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +02001475CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showMappingCommmandProcess(
1476 const IRemoteCommand& remoteCommand,
1477 string& strResult)
1478{
1479 if (!getParameterMapping(remoteCommand.getArgument(0), strResult)) {
1480
1481 return CCommandHandler::EFailed;
1482 }
1483
1484 return CCommandHandler::ESucceeded;
1485}
1486
Patrick Benavoli68a91282011-08-31 11:23:23 +02001487/// Settings Import/Export
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001488CParameterMgr::CCommandHandler::CommandStatus
1489 CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess(
1490 const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001491{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001492 string strFileName = remoteCommand.getArgument(0);
1493 return exportDomainsXml(strFileName, false, true, strResult) ?
1494 CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001495}
1496
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001497CParameterMgr::CCommandHandler::CommandStatus
1498 CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess(
1499 const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001500{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001501 return importDomainsXml(remoteCommand.getArgument(0), false, true, strResult) ?
1502 CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001503}
1504
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001505CParameterMgr::CCommandHandler::CommandStatus
1506 CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess(
1507 const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001508{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001509 string strFileName = remoteCommand.getArgument(0);
1510 return exportDomainsXml(strFileName, true, true, strResult) ?
1511 CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001512}
1513
Patrick Benavoli63499d42011-10-24 18:50:03 +02001514CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001515{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001516 return importDomainsXml(remoteCommand.getArgument(0), true, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001517}
1518
Patrick Benavoli63499d42011-10-24 18:50:03 +02001519CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001520{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001521 return exportDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001522}
1523
Patrick Benavoli63499d42011-10-24 18:50:03 +02001524CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001525{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001526 return importDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001527}
1528
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001529CParameterMgr::CCommandHandler::CommandStatus
1530 CParameterMgr::getConfigurableDomainsWithSettingsXMLCommmandProcess(
1531 const IRemoteCommand& remoteCommand, string& strResult)
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001532{
1533 (void)remoteCommand;
1534
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001535 if (!exportDomainsXml(strResult, true, false, strResult)) {
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001536
1537 return CCommandHandler::EFailed;
1538 }
1539 // Succeeded
1540 return CCommandHandler::ESucceeded;
1541}
1542
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001543CParameterMgr::CCommandHandler::CommandStatus
1544 CParameterMgr::setConfigurableDomainsWithSettingsXMLCommmandProcess(
1545 const IRemoteCommand& remoteCommand, string& strResult)
1546{
1547 return importDomainsXml(remoteCommand.getArgument(0), true, false, strResult) ?
1548 CCommandHandler::EDone : CCommandHandler::EFailed;
1549}
1550
1551CParameterMgr::CCommandHandler::CommandStatus
1552 CParameterMgr::getSystemClassXMLCommmandProcess(
1553 const IRemoteCommand& remoteCommand, string& strResult)
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001554{
1555 (void)remoteCommand;
1556
1557 if (!getSystemClassXMLString(strResult)) {
1558
1559 return CCommandHandler::EFailed;
1560 }
1561 // Succeeded
1562 return CCommandHandler::ESucceeded;
1563}
1564
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001565// User set/get parameters in main BlackBoard
1566bool CParameterMgr::accessParameterValue(const string& strPath, string& strValue, bool bSet, string& strError)
1567{
1568 // Define context
1569 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
1570
Frédéric Boisnard150407c2013-03-15 14:46:23 +01001571 // Activate the auto synchronization with the hardware
1572 if (bSet) {
1573
1574 parameterAccessContext.setAutoSync(_bAutoSyncOn);
1575 }
1576
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001577 return accessValue(parameterAccessContext, strPath, strValue, bSet, strError);
1578}
1579
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +02001580// User get parameter mapping
1581bool CParameterMgr::getParameterMapping(const string& strPath, string& strResult) const
1582{
1583 CPathNavigator pathNavigator(strPath);
1584
1585 // Nagivate through system class
1586 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strResult)) {
1587
1588 return false;
1589 }
1590
1591 // Get the ConfigurableElement corresponding to strPath
1592 const CConfigurableElement* pConfigurableElement = getConfigurableElement(strPath, strResult);
1593 if (!pConfigurableElement) {
1594
1595 return false;
1596 }
1597
1598 // Find the list of the ancestors of the current ConfigurableElement that have a mapping
1599 list<const CConfigurableElement*> configurableElementPath;
1600 pConfigurableElement->getListOfElementsWithMapping(configurableElementPath);
1601
1602 // Get the Subsystem containing the ConfigurableElement
1603 const CSubsystem* pSubsystem = pConfigurableElement->getBelongingSubsystem();
1604 if (!pSubsystem) {
1605
1606 strResult = "Unable to find the Subsystem containing the parameter";
1607 return false;
1608 }
1609
1610 // Fetch the mapping corresponding to the ConfigurableElement
1611 strResult = pSubsystem->getMapping(configurableElementPath);
1612
1613 return true;
1614}
1615
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001616// User set/get parameters in specific Configuration BlackBoard
1617bool CParameterMgr::accessConfigurationValue(const string& strDomain, const string& strConfiguration, const string& strPath, string& strValue, bool bSet, string& strError)
1618{
1619 CElementLocator elementLocator(getSystemClass());
1620
1621 CElement* pLocatedElement = NULL;
1622
1623 if (!elementLocator.locate(strPath, &pLocatedElement, strError)) {
1624
1625 return false;
1626 }
1627
1628 // Convert element
1629 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1630
1631 // Get the Configuration blackboard and the Base Offset of the configurable element in this blackboard
1632 uint32_t uiBaseOffset;
1633 bool bIsLastApplied;
1634
1635 CParameterBlackboard* pConfigurationBlackboard = getConstConfigurableDomains()->findConfigurationBlackboard(strDomain, strConfiguration, pConfigurableElement, uiBaseOffset, bIsLastApplied, strError);
1636
1637 if (!pConfigurationBlackboard) {
1638
1639 return false;
1640 }
1641
1642 log_info("Element %s in Domain %s, offset: %d, base offset: %d", strPath.c_str(), strDomain.c_str(), pConfigurableElement->getOffset(), uiBaseOffset);
1643
1644 /// Update the Configuration Blackboard
1645
Frédéric Boisnard150407c2013-03-15 14:46:23 +01001646 // 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 +01001647 CParameterAccessContext parameterAccessContext(strError, pConfigurationBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex, uiBaseOffset);
1648
Frédéric Boisnardda8298c2014-05-23 19:05:31 +02001649 // Deactivate the auto synchronization with the hardware during the Configuration Blackboard
1650 // access (only Main Blackboard shall be synchronized, Configurations Blackboards are copied
1651 // into the Main Blackboard each time a configuration is restored but they are not synchronized
1652 // directly).
1653 if (bSet) {
1654
1655 parameterAccessContext.setAutoSync(false);
1656 }
1657
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001658 // Access Value in the Configuration Blackboard
1659 if (!accessValue(parameterAccessContext, strPath, strValue, bSet, strError)) {
1660
1661 return false;
1662 }
1663
1664 /// If the Configuration is the last one applied, update the Main Blackboard as well
1665
1666 if (bIsLastApplied) {
1667
1668 // Define Main context
1669 parameterAccessContext.setParameterBlackboard(_pMainParameterBlackboard);
1670
Frédéric Boisnard150407c2013-03-15 14:46:23 +01001671 // Activate the auto synchronization with the hardware
1672 if (bSet) {
1673
1674 parameterAccessContext.setAutoSync(_bAutoSyncOn);
1675 }
1676
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001677 // Access Value in the Main Blackboard
1678 return accessValue(parameterAccessContext, strPath, strValue, bSet, strError);
1679 }
1680
1681 return true;
1682}
1683
Patrick Benavoli68a91282011-08-31 11:23:23 +02001684// User set/get parameters
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001685bool CParameterMgr::accessValue(CParameterAccessContext& parameterAccessContext, const string& strPath, string& strValue, bool bSet, string& strError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001686{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001687 // Lock state
1688 CAutoLock autoLock(&_blackboardMutex);
1689
1690 CPathNavigator pathNavigator(strPath);
1691
1692 // Nagivate through system class
1693 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001694
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +02001695 parameterAccessContext.setError(strError);
1696
Patrick Benavoli68a91282011-08-31 11:23:23 +02001697 return false;
1698 }
1699
Patrick Benavoli065264a2011-11-20 15:46:41 +01001700 // Do the get
1701 return getConstSystemClass()->accessValue(pathNavigator, strValue, bSet, parameterAccessContext);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001702}
1703
1704// Tuning mode
1705bool CParameterMgr::setTuningMode(bool bOn, string& strError)
1706{
1707 // Tuning allowed?
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001708 if (bOn && !getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001709
1710 strError = "Tuning prohibited";
1711
1712 return false;
1713 }
1714 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +01001715 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001716
1717 // Warn domains about exiting tuning mode
1718 if (!bOn && _bTuningModeIsOn) {
1719
1720 // Ensure application of currently selected configurations
Patrick Benavoli1387bda2011-08-31 11:23:24 +02001721 // Force-apply configurations
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01001722 doApplyConfigurations(true);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001723
Patrick Benavoli68a91282011-08-31 11:23:23 +02001724 // Turn auto sync back on
1725 _bAutoSyncOn = true;
1726 }
1727
1728 // Store
1729 _bTuningModeIsOn = bOn;
1730
Patrick Benavoli68a91282011-08-31 11:23:23 +02001731 return true;
1732}
1733
1734bool CParameterMgr::tuningModeOn() const
1735{
1736 return _bTuningModeIsOn;
1737}
1738
1739// Current value space for user set/get value interpretation
1740void CParameterMgr::setValueSpace(bool bIsRaw)
1741{
1742 _bValueSpaceIsRaw = bIsRaw;
1743}
1744
1745bool CParameterMgr::valueSpaceIsRaw()
1746{
1747 return _bValueSpaceIsRaw;
1748}
1749
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001750// Current Output Raw Format for user get value interpretation
1751void CParameterMgr::setOutputRawFormat(bool bIsHex)
1752{
1753 _bOutputRawFormatIsHex = bIsHex;
1754}
1755
1756bool CParameterMgr::outputRawFormatIsHex()
1757{
1758 return _bOutputRawFormatIsHex;
1759}
1760
Patrick Benavoli68a91282011-08-31 11:23:23 +02001761/// Sync
1762// Automatic hardware synchronization control (during tuning session)
1763bool CParameterMgr::setAutoSync(bool bAutoSyncOn, string& strError)
1764{
1765 // Check tuning mode
1766 if (!checkTuningModeOn(strError)) {
1767
1768 return false;
1769 }
1770 // Warn domains about turning auto sync back on
1771 if (bAutoSyncOn && !_bAutoSyncOn) {
1772
Patrick Benavoli592ae562011-09-05 16:53:58 +02001773 // Do the synchronization at system class level (could be optimized by keeping track of all modified parameters)
1774 if (!sync(strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001775
1776 return false;
1777 }
1778 }
1779
1780 // Set Auto sync
1781 _bAutoSyncOn = bAutoSyncOn;
1782
1783 return true;
1784}
1785
1786bool CParameterMgr::autoSyncOn() const
1787{
1788 return _bAutoSyncOn;
1789}
1790
1791// Manual hardware synchronization control (during tuning session)
1792bool CParameterMgr::sync(string& strError)
1793{
1794 // Check tuning mode
1795 if (!checkTuningModeOn(strError)) {
1796
1797 return false;
1798 }
1799 // Warn domains about turning auto sync back on
1800 if (_bAutoSyncOn) {
1801
1802 strError = "Feature unavailable when Auto Sync is on";
1803
1804 return false;
1805 }
1806
1807 // Get syncer set
1808 CSyncerSet syncerSet;
1809 // ... from system class
1810 getConstSystemClass()->fillSyncerSet(syncerSet);
Kevin Rocardace81f82012-12-11 16:19:17 +01001811
Patrick Benavoli68a91282011-08-31 11:23:23 +02001812 // Sync
Kevin Rocardace81f82012-12-11 16:19:17 +01001813 list<string> lstrError;
1814 if (! syncerSet.sync(*_pMainParameterBlackboard, false, &lstrError)){
1815
Frederic Boisnard390b36d2013-05-23 15:28:31 +02001816 CUtility::asString(lstrError, strError);
Kevin Rocardace81f82012-12-11 16:19:17 +01001817 return false;
1818 };
1819
1820 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001821}
1822
1823// Content dump
1824void CParameterMgr::logStructureContent(string& strContent) const
1825{
1826 string strError;
1827
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001828 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001829
1830 dumpContent(strContent, parameterAccessContext);
1831}
1832
1833// Configuration/Domains handling
1834bool CParameterMgr::createDomain(const string& strName, string& strError)
1835{
1836 // Check tuning mode
1837 if (!checkTuningModeOn(strError)) {
1838
1839 return false;
1840 }
1841
1842 // Delegate to configurable domains
1843 return getConfigurableDomains()->createDomain(strName, strError);
1844}
1845
1846bool CParameterMgr::deleteDomain(const string& strName, string& strError)
1847{
1848 // Check tuning mode
1849 if (!checkTuningModeOn(strError)) {
1850
1851 return false;
1852 }
1853
1854 // Delegate to configurable domains
1855 return getConfigurableDomains()->deleteDomain(strName, strError);
1856}
1857
Kevin Rocard170f0a42012-06-18 13:56:05 +02001858bool CParameterMgr::deleteAllDomains(string& strError)
1859{
1860 // Check tuning mode
1861 if (!checkTuningModeOn(strError)) {
1862
1863 return false;
1864 }
1865
1866 // Delegate to configurable domains
1867 getConfigurableDomains()->deleteAllDomains();
1868
1869 return true;
1870}
1871
Patrick Benavoli68a91282011-08-31 11:23:23 +02001872bool CParameterMgr::createConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1873{
1874 // Check tuning mode
1875 if (!checkTuningModeOn(strError)) {
1876
1877 return false;
1878 }
1879
1880 // Delegate to configurable domains
1881 return getConfigurableDomains()->createConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1882}
1883
1884bool CParameterMgr::deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1885{
1886 // Check tuning mode
1887 if (!checkTuningModeOn(strError)) {
1888
1889 return false;
1890 }
1891
1892 // Delegate to configurable domains
1893 return getConfigurableDomains()->deleteConfiguration(strDomain, strConfiguration, strError);
1894}
1895
Kevin Rocardace81f82012-12-11 16:19:17 +01001896bool CParameterMgr::restoreConfiguration(const string& strDomain, const string& strConfiguration, list<string>& lstrError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001897{
Kevin Rocardace81f82012-12-11 16:19:17 +01001898 string strError;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001899 // Check tuning mode
1900 if (!checkTuningModeOn(strError)) {
1901
Kevin Rocardace81f82012-12-11 16:19:17 +01001902 lstrError.push_back(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001903 return false;
1904 }
1905
1906 // Delegate to configurable domains
Kevin Rocardace81f82012-12-11 16:19:17 +01001907 return getConstConfigurableDomains()->restoreConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, lstrError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001908}
1909
1910bool CParameterMgr::saveConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1911{
1912 // Check tuning mode
1913 if (!checkTuningModeOn(strError)) {
1914
1915 return false;
1916 }
1917
1918 // Delegate to configurable domains
1919 return getConfigurableDomains()->saveConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1920}
1921
1922// Configurable element - domain association
1923bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1924{
1925 // Check tuning mode
1926 if (!checkTuningModeOn(strError)) {
1927
1928 return false;
1929 }
1930
1931 CElementLocator elementLocator(getSystemClass());
1932
1933 CElement* pLocatedElement = NULL;
1934
1935 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1936
1937 return false;
1938 }
1939
1940 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001941 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001942
1943 // Delegate
1944 return getConfigurableDomains()->addConfigurableElementToDomain(strDomain, pConfigurableElement, _pMainParameterBlackboard, strError);
1945}
1946
1947bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1948{
1949 // Check tuning mode
1950 if (!checkTuningModeOn(strError)) {
1951
1952 return false;
1953 }
1954
1955 CElementLocator elementLocator(getSystemClass());
1956
1957 CElement* pLocatedElement = NULL;
1958
1959 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1960
Patrick Benavoli63499d42011-10-24 18:50:03 +02001961 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001962 }
1963
1964 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001965 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001966
1967 // Delegate
1968 return getConfigurableDomains()->removeConfigurableElementFromDomain(strDomain, pConfigurableElement, strError);
1969}
1970
1971bool CParameterMgr::split(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1972{
1973 // Check tuning mode
1974 if (!checkTuningModeOn(strError)) {
1975
1976 return false;
1977 }
1978
1979 CElementLocator elementLocator(getSystemClass());
1980
1981 CElement* pLocatedElement = NULL;
1982
1983 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1984
Patrick Benavoli63499d42011-10-24 18:50:03 +02001985 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001986 }
1987
1988 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001989 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001990
1991 // Delegate
1992 return getConfigurableDomains()->split(strDomain, pConfigurableElement, strError);
1993}
1994
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001995bool CParameterMgr::importDomainsXml(const string& strXmlSource, bool bWithSettings,
1996 bool bFromFile, string& strError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001997{
1998 // Check tuning mode
1999 if (!checkTuningModeOn(strError)) {
2000
2001 return false;
2002 }
2003
2004 // check path is absolute
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002005 if (bFromFile && strXmlSource[0] != '/') {
Patrick Benavoli68a91282011-08-31 11:23:23 +02002006
2007 strError = "Please provide absolute path";
2008
2009 return false;
2010 }
2011 // Root element
2012 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
2013
2014 // Context
David Wagnerd8a53102014-12-10 14:49:23 +01002015 CXmlDomainImportContext xmlDomainImportContext(strError, bWithSettings, *getSystemClass());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002016
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002017 // Selection criteria definition for rule creation
David Wagner29fa61f2014-12-19 11:15:02 +01002018 xmlDomainImportContext.setSelectionCriteriaDefinition(
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002019 getConstSelectionCriteria()->getSelectionCriteriaDefinition());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002020
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002021 // Init serializing context
David Wagner29fa61f2014-12-19 11:15:02 +01002022 xmlDomainImportContext.set(
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002023 _pElementLibrarySet->getElementLibrary(EParameterConfigurationLibrary),
2024 "", _strSchemaFolderLocation);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002025
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002026 // Get Schema file associated to root element
2027 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" +
2028 pConfigurableDomains->getKind() + ".xsd";
2029
2030 // Xml Source
2031 CXmlDocSource* pSource;
2032
2033 if (bFromFile) {
2034
2035 // when importing from a file strXmlSource is the file name
2036 pSource = new CXmlFileDocSource(strXmlSource, strXmlSchemaFilePath,
2037 pConfigurableDomains->getKind(),
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +02002038 pConfigurableDomains->getName(), "SystemClassName",
2039 _bValidateSchemasOnStart);
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002040
2041 } else {
2042
2043 // when importing from an xml string, strXmlSource contains the string
2044 pSource = new CXmlStringDocSource(strXmlSource, strXmlSchemaFilePath,
2045 pConfigurableDomains->getKind(),
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +02002046 pConfigurableDomains->getName(), "SystemClassName",
2047 _bValidateSchemasOnStart);
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002048
2049 }
2050 // Start clean
2051 pConfigurableDomains->clean();
2052
2053 // Use a doc sink that instantiate Configurable Domains from the given doc source
2054 CXmlMemoryDocSink memorySink(pConfigurableDomains);
2055
David Wagner29fa61f2014-12-19 11:15:02 +01002056 bool bProcessSuccess = memorySink.process(*pSource, xmlDomainImportContext);
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002057
2058 if (!bProcessSuccess) {
2059
2060 //Cleanup
2061 pConfigurableDomains->clean();
2062
2063 } else {
2064
2065 // Validate domains after XML import
2066 pConfigurableDomains->validate(_pMainParameterBlackboard);
2067
Patrick Benavoli68a91282011-08-31 11:23:23 +02002068 }
2069
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002070 delete pSource;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002071
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002072 return bProcessSuccess;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002073}
2074
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002075bool CParameterMgr::exportDomainsXml(string& strXmlDest, bool bWithSettings, bool bToFile,
2076 string& strError) const
Patrick Benavoli68a91282011-08-31 11:23:23 +02002077{
2078 // check path is absolute
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002079 if (bToFile && strXmlDest[0] != '/') {
Patrick Benavoli68a91282011-08-31 11:23:23 +02002080
2081 strError = "Please provide absolute path";
2082
2083 return false;
2084 }
2085
2086 // Root element
2087 const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains();
2088
2089 // Get Schema file associated to root element
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002090 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" +
2091 pConfigurableDomains->getKind() + ".xsd";
Patrick Benavoli68a91282011-08-31 11:23:23 +02002092
2093 // Context
David Wagner29fa61f2014-12-19 11:15:02 +01002094 CXmlDomainExportContext xmlDomainExportContext(strError, bWithSettings);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002095
2096 // Value space
David Wagner29fa61f2014-12-19 11:15:02 +01002097 xmlDomainExportContext.setValueSpaceRaw(_bValueSpaceIsRaw);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002098
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02002099 // Output raw format
David Wagner29fa61f2014-12-19 11:15:02 +01002100 xmlDomainExportContext.setOutputRawFormat(_bOutputRawFormatIsHex);
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02002101
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002102 // Use a doc source by loading data from instantiated Configurable Domains
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002103 CXmlMemoryDocSource memorySource(pConfigurableDomains, pConfigurableDomains->getKind(),
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +02002104 strXmlSchemaFilePath, "parameter-framework",
2105 getVersion(), _bValidateSchemasOnStart);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002106
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002107 // Xml Sink
2108 CXmlDocSink* pSink;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002109
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002110 if (bToFile) {
2111
2112 // Use a doc sink to write the doc data in a file
2113 pSink = new CXmlFileDocSink(strXmlDest);
2114
2115 } else {
2116
2117 // Use a doc sink to write the doc data in a string
2118 pSink = new CXmlStringDocSink(strXmlDest);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002119 }
2120
David Wagner29fa61f2014-12-19 11:15:02 +01002121 bool bProcessSuccess = pSink->process(memorySource, xmlDomainExportContext);
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002122
2123 delete pSink;
2124 return bProcessSuccess;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002125}
2126
2127// Binary Import/Export
2128bool CParameterMgr::importDomainsBinary(const string& strFileName, string& strError)
2129{
2130 // Check tuning mode
2131 if (!checkTuningModeOn(strError)) {
2132
2133 return false;
2134 }
2135 // check path is absolute
2136 if (strFileName[0] != '/') {
2137
2138 strError = "Please provide absolute path";
2139
2140 return false;
2141 }
2142 // Root element
2143 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
2144
2145 // Serialize in
2146 return pConfigurableDomains->serializeSettings(strFileName, false, _uiStructureChecksum, strError);
2147}
2148
2149bool CParameterMgr::exportDomainsBinary(const string& strFileName, string& strError)
2150{
2151 // check path is absolute
2152 if (strFileName[0] != '/') {
2153
2154 strError = "Please provide absolute path";
2155
2156 return false;
2157 }
Patrick Benavoli68a91282011-08-31 11:23:23 +02002158
Patrick Benavoli68a91282011-08-31 11:23:23 +02002159 // Root element
2160 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
2161
2162 // Serialize out
2163 return pConfigurableDomains->serializeSettings(strFileName, true, _uiStructureChecksum, strError);
2164}
2165
2166// For tuning, check we're in tuning mode
2167bool CParameterMgr::checkTuningModeOn(string& strError) const
2168{
2169 // Tuning Mode on?
2170 if (!_bTuningModeIsOn) {
2171
2172 strError = "Tuning Mode must be on";
2173
2174 return false;
2175 }
2176 return true;
2177}
2178
Patrick Benavoli065264a2011-11-20 15:46:41 +01002179// Tuning mutex dynamic parameter handling
2180pthread_mutex_t* CParameterMgr::getBlackboardMutex()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002181{
Patrick Benavoli065264a2011-11-20 15:46:41 +01002182 return &_blackboardMutex;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002183}
2184
Patrick Benavoli065264a2011-11-20 15:46:41 +01002185// Blackboard reference (dynamic parameter handling)
2186CParameterBlackboard* CParameterMgr::getParameterBlackboard()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002187{
Patrick Benavoli065264a2011-11-20 15:46:41 +01002188 return _pMainParameterBlackboard;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002189}
2190
Patrick Benavoli68a91282011-08-31 11:23:23 +02002191// Dynamic creation library feeding
2192void CParameterMgr::feedElementLibraries()
2193{
2194 // Global Configuration handling
2195 CElementLibrary* pFrameworkConfigurationLibrary = new CElementLibrary;
2196
Kevin Rocarda7b69602013-08-07 16:15:33 +02002197 pFrameworkConfigurationLibrary->addElementBuilder("ParameterFrameworkConfiguration", new TElementBuilderTemplate<CParameterFrameworkConfiguration>());
2198 pFrameworkConfigurationLibrary->addElementBuilder("SubsystemPlugins", new TKindElementBuilderTemplate<CSubsystemPlugins>());
2199 pFrameworkConfigurationLibrary->addElementBuilder("Location", new TKindElementBuilderTemplate<CPluginLocation>());
2200 pFrameworkConfigurationLibrary->addElementBuilder("StructureDescriptionFileLocation", new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>());
2201 pFrameworkConfigurationLibrary->addElementBuilder("SettingsConfiguration", new TKindElementBuilderTemplate<CFrameworkConfigurationGroup>());
2202 pFrameworkConfigurationLibrary->addElementBuilder("ConfigurableDomainsFileLocation", new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>());
2203 pFrameworkConfigurationLibrary->addElementBuilder("BinarySettingsFileLocation", new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002204
2205 _pElementLibrarySet->addElementLibrary(pFrameworkConfigurationLibrary);
2206
2207 // Parameter creation
2208 CElementLibrary* pParameterCreationLibrary = new CElementLibrary;
2209
Kevin Rocarda7b69602013-08-07 16:15:33 +02002210 pParameterCreationLibrary->addElementBuilder("Subsystem", new CSubsystemElementBuilder(getSystemClass()->getSubsystemLibrary()));
2211 pParameterCreationLibrary->addElementBuilder("ComponentType", new TNamedElementBuilderTemplate<CComponentType>());
2212 pParameterCreationLibrary->addElementBuilder("Component", new TNamedElementBuilderTemplate<CComponentInstance>());
2213 pParameterCreationLibrary->addElementBuilder("BitParameter", new TNamedElementBuilderTemplate<CBitParameterType>());
2214 pParameterCreationLibrary->addElementBuilder("BitParameterBlock", new TNamedElementBuilderTemplate<CBitParameterBlockType>());
2215 pParameterCreationLibrary->addElementBuilder("StringParameter", new TNamedElementBuilderTemplate<CStringParameterType>());
2216 pParameterCreationLibrary->addElementBuilder("ParameterBlock", new TNamedElementBuilderTemplate<CParameterBlockType>());
2217 pParameterCreationLibrary->addElementBuilder("BooleanParameter", new TNamedElementBuilderTemplate<CBooleanParameterType>());
2218 pParameterCreationLibrary->addElementBuilder("IntegerParameter", new TNamedElementBuilderTemplate<CIntegerParameterType>());
2219 pParameterCreationLibrary->addElementBuilder("LinearAdaptation", new TElementBuilderTemplate<CLinearParameterAdaptation>());
2220 pParameterCreationLibrary->addElementBuilder("EnumParameter", new TNamedElementBuilderTemplate<CEnumParameterType>());
2221 pParameterCreationLibrary->addElementBuilder("ValuePair", new TElementBuilderTemplate<CEnumValuePair>());
2222 pParameterCreationLibrary->addElementBuilder("FixedPointParameter", new TNamedElementBuilderTemplate<CFixedPointParameterType>());
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +02002223 pParameterCreationLibrary->addElementBuilder("SubsystemInclude", new CFileIncluderElementBuilder(_bValidateSchemasOnStart));
Patrick Benavoli68a91282011-08-31 11:23:23 +02002224
2225 _pElementLibrarySet->addElementLibrary(pParameterCreationLibrary);
2226
2227 // Parameter Configuration Domains creation
2228 CElementLibrary* pParameterConfigurationLibrary = new CElementLibrary;
2229
Kevin Rocarda7b69602013-08-07 16:15:33 +02002230 pParameterConfigurationLibrary->addElementBuilder("ConfigurableDomain", new TNamedElementBuilderTemplate<CConfigurableDomain>());
2231 pParameterConfigurationLibrary->addElementBuilder("Configuration", new TNamedElementBuilderTemplate<CDomainConfiguration>());
2232 pParameterConfigurationLibrary->addElementBuilder("CompoundRule", new TElementBuilderTemplate<CCompoundRule>());
2233 pParameterConfigurationLibrary->addElementBuilder("SelectionCriterionRule", new TElementBuilderTemplate<CSelectionCriterionRule>());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002234
2235 _pElementLibrarySet->addElementLibrary(pParameterConfigurationLibrary);
2236}
2237
2238// Remote Processor Server connection handling
2239bool CParameterMgr::handleRemoteProcessingInterface(string& strError)
2240{
2241 CAutoLog autoLog(this, "Handling remote processing interface");
2242
2243 // Start server if tuning allowed
Patrick Benavoli95ac0342011-11-07 20:32:51 +01002244 if (getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02002245
Kevin Rocardace81f82012-12-11 16:19:17 +01002246 log_info("Loading remote processor library");
Patrick Benavoli68a91282011-08-31 11:23:23 +02002247
2248 // Load library
Renaud de Chivre1b8b3ca2013-12-13 15:09:44 +01002249 _handleLibRemoteProcessor = dlopen("libremote-processor.so", RTLD_NOW);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002250
Renaud de Chivre1b8b3ca2013-12-13 15:09:44 +01002251 if (!_handleLibRemoteProcessor) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02002252
2253 // Return error
2254 const char* pcError = dlerror();
2255
2256 if (pcError) {
2257
2258 strError = pcError;
2259 } else {
2260
2261 strError = "Unable to load libremote-processor.so library";
2262 }
2263
2264 return false;
2265 }
2266
Renaud de Chivre1b8b3ca2013-12-13 15:09:44 +01002267 CreateRemoteProcessorServer pfnCreateRemoteProcessorServer = (CreateRemoteProcessorServer)dlsym(_handleLibRemoteProcessor, "createRemoteProcessorServer");
Patrick Benavoli68a91282011-08-31 11:23:23 +02002268
2269 if (!pfnCreateRemoteProcessorServer) {
2270
2271 strError = "libremote-process.so does not contain createRemoteProcessorServer symbol.";
2272
2273 return false;
2274 }
2275
2276 // Create server
Patrick Benavoli95ac0342011-11-07 20:32:51 +01002277 _pRemoteProcessorServer = pfnCreateRemoteProcessorServer(getConstFrameworkConfiguration()->getServerPort(), _pCommandHandler);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002278
Kevin Rocardace81f82012-12-11 16:19:17 +01002279 log_info("Starting remote processor server on port %d", getConstFrameworkConfiguration()->getServerPort());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002280 // Start
2281 if (!_pRemoteProcessorServer->start()) {
2282
Frédéric Boisnard6c55e9a2014-01-10 18:46:33 +01002283 ostringstream oss;
2284 oss << "ParameterMgr: Unable to start remote processor server on port "
2285 << getConstFrameworkConfiguration()->getServerPort();
2286 strError = oss.str();
Patrick Benavoli68a91282011-08-31 11:23:23 +02002287
2288 return false;
2289 }
2290 }
2291
2292 return true;
2293}
2294
2295// Back synchronization
Kevin Rocardace81f82012-12-11 16:19:17 +01002296CBackSynchronizer* CParameterMgr::createBackSynchronizer() const
Patrick Benavoli68a91282011-08-31 11:23:23 +02002297{
2298#ifdef SIMULATION
2299 // In simulation, back synchronization of the blackboard won't probably work
2300 // We need to ensure though the blackboard is initialized with valid data
Kevin Rocardace81f82012-12-11 16:19:17 +01002301 return new CSimulatedBackSynchronizer(getConstSystemClass(), _pMainParameterBlackboard);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002302#else
2303 // Real back synchronizer from subsystems
Kevin Rocardace81f82012-12-11 16:19:17 +01002304 return new CHardwareBackSynchronizer(getConstSystemClass(), _pMainParameterBlackboard);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002305#endif
2306}
2307
2308// Children typwise access
2309CParameterFrameworkConfiguration* CParameterMgr::getFrameworkConfiguration()
2310{
2311 return static_cast<CParameterFrameworkConfiguration*>(getChild(EFrameworkConfiguration));
2312}
2313
2314const CParameterFrameworkConfiguration* CParameterMgr::getConstFrameworkConfiguration()
2315{
2316 return getFrameworkConfiguration();
2317}
2318
2319CSelectionCriteria* CParameterMgr::getSelectionCriteria()
2320{
2321 return static_cast<CSelectionCriteria*>(getChild(ESelectionCriteria));
2322}
2323
2324const CSelectionCriteria* CParameterMgr::getConstSelectionCriteria()
2325{
2326 return static_cast<const CSelectionCriteria*>(getChild(ESelectionCriteria));
2327}
2328
2329CSystemClass* CParameterMgr::getSystemClass()
2330{
2331 return static_cast<CSystemClass*>(getChild(ESystemClass));
2332}
2333
2334const CSystemClass* CParameterMgr::getConstSystemClass() const
2335{
2336 return static_cast<const CSystemClass*>(getChild(ESystemClass));
2337}
2338
2339// Configurable Domains
2340CConfigurableDomains* CParameterMgr::getConfigurableDomains()
2341{
2342 return static_cast<CConfigurableDomains*>(getChild(EConfigurableDomains));
2343}
2344
2345const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains()
2346{
2347 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
2348}
2349
2350const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains() const
2351{
2352 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
2353}
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002354
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01002355// Apply configurations
2356void CParameterMgr::doApplyConfigurations(bool bForce)
2357{
2358 CSyncerSet syncerSet;
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002359
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01002360 // Check subsystems that need resync
2361 getSystemClass()->checkForSubsystemsToResync(syncerSet);
2362
2363 // Ensure application of currently selected configurations
2364 getConfigurableDomains()->apply(_pMainParameterBlackboard, syncerSet, bForce);
2365
2366 // Reset the modified status of the current criteria to indicate that a new configuration has been applied
2367 getSelectionCriteria()->resetModifiedStatus();
2368}
2369
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002370bool CParameterMgr::getSystemClassXMLString(string& strResult)
2371{
2372 // Root element
2373 const CSystemClass* pSystemClass = getSystemClass();
2374
2375 string strError;
2376
2377 CXmlSerializingContext xmlSerializingContext(strError);
2378
2379 // Use a doc source by loading data from instantiated Configurable Domains
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +02002380 CXmlMemoryDocSource memorySource(pSystemClass, pSystemClass->getKind(),
2381 _bValidateSchemasOnStart);
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002382
2383 // Use a doc sink that write the doc data in a string
2384 CXmlStringDocSink stringSink(strResult);
2385
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002386 bool bProcessSuccess = stringSink.process(memorySource, xmlSerializingContext);
2387
2388 if (!bProcessSuccess) {
2389
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002390 strResult = strError;
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002391
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002392 }
2393
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002394 return bProcessSuccess;
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002395}