blob: 84a3fd4c28bb0d3415885695cd0517545bef50fe [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>
David Wagnerfd211972014-12-10 15:01:22 +010092#include <memory>
Patrick Benavoli68a91282011-08-31 11:23:23 +020093
94#define base CElement
95
Sebastien Gonzalved9526492014-02-20 22:28:03 +010096using std::string;
97using std::list;
98using std::vector;
99using std::ostringstream;
100
Patrick Benavoli68a91282011-08-31 11:23:23 +0200101// Used for remote processor server creation
102typedef IRemoteProcessorServerInterface* (*CreateRemoteProcessorServer)(uint16_t uiPort, IRemoteCommandHandler* pCommandHandler);
103
104// Global configuration file name (fixed)
105const char* gacParameterFrameworkConfigurationFileName = "ParameterFrameworkConfiguration.xml";
106const char* gacSystemSchemasSubFolder = "Schemas";
107
108// Config File System looks normally like this:
109// ---------------------------------------------
Kevin Rocard03b73842014-10-01 18:20:41 +0200110//|-- <ParameterFrameworkConfiguration>.xml
111//|-- Schemas
112//| `-- *.xsd
113//|-- Settings
114//| `-- <SystemClassName folder>*
115//| |-- <ConfigurableDomains>.xml
116//| `-- <Settings>.bin?
117//`-- Structure
118// `-- <SystemClassName folder>*
119// |-- <SystemClassName>Class.xml
120// `-- <Subsystem>.xml*
Patrick Benavoli68a91282011-08-31 11:23:23 +0200121// --------------------------------------------
122
123
124// Remote command parser array
Patrick Benavoli592ae562011-09-05 16:53:58 +0200125const CParameterMgr::SRemoteCommandParserItem CParameterMgr::gastRemoteCommandParserItems[] = {
Kevin Rocard3949b342013-05-24 18:43:53 +0200126
Patrick Benavoli592ae562011-09-05 16:53:58 +0200127 /// Version
Kevin Rocard3949b342013-05-24 18:43:53 +0200128 { "version", &CParameterMgr::versionCommandProcess, 0,
129 "", "Show version" },
130
Patrick Benavoli68a91282011-08-31 11:23:23 +0200131 /// Status
Kevin Rocard3949b342013-05-24 18:43:53 +0200132 { "status", &CParameterMgr::statusCommandProcess, 0, "",
133 "Show current status" },
134
Patrick Benavoli68a91282011-08-31 11:23:23 +0200135 /// Tuning Mode
Kevin Rocard3949b342013-05-24 18:43:53 +0200136 { "setTuningMode", &CParameterMgr::setTuningModeCommmandProcess, 1,
137 "on|off*", "Turn on or off Tuning Mode" },
138 { "getTuningMode", &CParameterMgr::getTuningModeCommmandProcess, 0,
139 "", "Show Tuning Mode" },
140
Patrick Benavoli68a91282011-08-31 11:23:23 +0200141 /// Value Space
Kevin Rocard3949b342013-05-24 18:43:53 +0200142 { "setValueSpace", &CParameterMgr::setValueSpaceCommmandProcess, 1,
143 "raw|real*", "Assigns Value Space used for parameter value interpretation" },
144 { "getValueSpace", &CParameterMgr::getValueSpaceCommmandProcess, 0,
145 "", "Show Value Space" },
146
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200147 /// Output Raw Format
Kevin Rocard3949b342013-05-24 18:43:53 +0200148 { "setOutputRawFormat", &CParameterMgr::setOutputRawFormatCommmandProcess, 1,
149 "dec*|hex", "Assigns format used to output parameter values when in raw Value Space" },
150 { "getOutputRawFormat", &CParameterMgr::getOutputRawFormatCommmandProcess, 0,
151 "", "Show Output Raw Format" },
152
Patrick Benavoli68a91282011-08-31 11:23:23 +0200153 /// Sync
Kevin Rocard3949b342013-05-24 18:43:53 +0200154 { "setAutoSync", &CParameterMgr::setAutoSyncCommmandProcess, 1,
155 "on*|off", "Turn on or off automatic synchronization to hardware while in Tuning Mode" },
156 { "getAutoSync", &CParameterMgr::getAutoSyncCommmandProcess, 0,
157 "", "Show Auto Sync state" },
158 { "sync", &CParameterMgr::syncCommmandProcess, 0,
159 "", "Synchronize current settings to hardware while in Tuning Mode and Auto Sync off" },
160
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200161 /// Criteria
Kevin Rocard3949b342013-05-24 18:43:53 +0200162 { "listCriteria", &CParameterMgr::listCriteriaCommmandProcess, 0,
163 "[csv]", "List selection criteria" },
164
Patrick Benavoli68a91282011-08-31 11:23:23 +0200165 /// Domains
Kevin Rocard3949b342013-05-24 18:43:53 +0200166 { "listDomains", &CParameterMgr::listDomainsCommmandProcess, 0,
167 "", "List configurable domains" },
168 { "dumpDomains", &CParameterMgr::dumpDomainsCommmandProcess, 0,
169 "", "Show all domains and configurations, including applicability conditions" },
170 { "createDomain", &CParameterMgr::createDomainCommmandProcess, 1,
171 "<domain>", "Create new configurable domain" },
172 { "deleteDomain", &CParameterMgr::deleteDomainCommmandProcess, 1,
173 "<domain>", "Delete configurable domain" },
174 { "deleteAllDomains", &CParameterMgr::deleteAllDomainsCommmandProcess, 0,
175 "", "Delete all configurable domains" },
176 { "renameDomain", &CParameterMgr::renameDomainCommmandProcess, 2,
177 "<domain> <new name>", "Rename configurable domain" },
178 { "setSequenceAwareness", &CParameterMgr::setSequenceAwarenessCommmandProcess, 1,
179 "<domain> true|false*", "Set configurable domain sequence awareness" },
180 { "getSequenceAwareness", &CParameterMgr::getSequenceAwarenessCommmandProcess, 1,
181 "<domain>", "Get configurable domain sequence awareness" },
182 { "listDomainElements", &CParameterMgr::listDomainElementsCommmandProcess, 1,
183 "<domain>", "List elements associated to configurable domain" },
184 { "addElement", &CParameterMgr::addElementCommmandProcess, 2,
185 "<domain> <elem path>", "Associate element at given path to configurable domain" },
186 { "removeElement", &CParameterMgr::removeElementCommmandProcess, 2,
187 "<domain> <elem path>", "Dissociate element at given path from configurable domain" },
188 { "splitDomain", &CParameterMgr::splitDomainCommmandProcess, 2,
189 "<domain> <elem path>", "Split configurable domain at given associated element path" },
190
Patrick Benavoli68a91282011-08-31 11:23:23 +0200191 /// Configurations
Kevin Rocard3949b342013-05-24 18:43:53 +0200192 { "listConfigurations", &CParameterMgr::listConfigurationsCommmandProcess, 1,
193 "<domain>", "List domain configurations" },
194 { "createConfiguration", &CParameterMgr::createConfigurationCommmandProcess, 2,
195 "<domain> <configuration>", "Create new domain configuration" },
196 { "deleteConfiguration", &CParameterMgr::deleteConfigurationCommmandProcess, 2,
197 "<domain> <configuration>", "Delete domain configuration" },
198 { "renameConfiguration", &CParameterMgr::renameConfigurationCommmandProcess, 3,
199 "<domain> <configuration> <new name>", "Rename domain configuration" },
200 { "saveConfiguration", &CParameterMgr::saveConfigurationCommmandProcess, 2,
201 "<domain> <configuration>", "Save current settings into configuration" },
202 { "restoreConfiguration", &CParameterMgr::restoreConfigurationCommmandProcess, 2,
203 "<domain> <configuration>", "Restore current settings from configuration" },
204 { "setElementSequence", &CParameterMgr::setElementSequenceCommmandProcess, 3,
205 "<domain> <configuration> <elem path list>",
206 "Set element application order for configuration" },
207 { "getElementSequence", &CParameterMgr::getElementSequenceCommmandProcess, 2,
208 "<domain> <configuration>", "Get element application order for configuration" },
209 { "setRule", &CParameterMgr::setRuleCommmandProcess, 3,
210 "<domain> <configuration> <rule>", "Set configuration application rule" },
211 { "clearRule", &CParameterMgr::clearRuleCommmandProcess, 2,
212 "<domain> <configuration>", "Clear configuration application rule" },
213 { "getRule", &CParameterMgr::getRuleCommmandProcess, 2,
214 "<domain> <configuration>", "Get configuration application rule" },
215
Patrick Benavoli68a91282011-08-31 11:23:23 +0200216 /// Elements/Parameters
Kevin Rocard3949b342013-05-24 18:43:53 +0200217 { "listElements", &CParameterMgr::listElementsCommmandProcess, 1,
218 "<elem path>|/", "List elements under element at given path or root" },
219 { "listParameters", &CParameterMgr::listParametersCommmandProcess, 1,
220 "<elem path>|/", "List parameters under element at given path or root" },
221 { "dumpElement", &CParameterMgr::dumpElementCommmandProcess, 1,
222 "<elem path>", "Dump structure and content of element at given path" },
223 { "getElementSize", &CParameterMgr::getElementSizeCommmandProcess, 1,
224 "<elem path>", "Show size of element at given path" },
225 { "showProperties", &CParameterMgr::showPropertiesCommmandProcess, 1,
226 "<elem path>", "Show properties of element at given path" },
227 { "getParameter", &CParameterMgr::getParameterCommmandProcess, 1,
228 "<param path>", "Get value for parameter at given path" },
229 { "setParameter", &CParameterMgr::setParameterCommmandProcess, 2,
230 "<param path> <value>", "Set value for parameter at given path" },
231 { "listBelongingDomains", &CParameterMgr::listBelongingDomainsCommmandProcess, 1,
232 "<elem path>", "List domain(s) element at given path belongs to" },
233 { "listAssociatedDomains", &CParameterMgr::listAssociatedDomainsCommmandProcess, 1,
234 "<elem path>", "List domain(s) element at given path is associated to" },
235 { "getConfigurationParameter", &CParameterMgr::getConfigurationParameterCommmandProcess, 3,
236 "<domain> <configuration> <param path>",
237 "Get value for parameter at given path from configuration" },
238 { "setConfigurationParameter", &CParameterMgr::setConfigurationParameterCommmandProcess, 4,
239 "<domain> <configuration> <param path> <value>",
240 "Set value for parameter at given path to configuration" },
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200241 { "showMapping", &CParameterMgr::showMappingCommmandProcess, 1,
242 "<elem path>", "Show mapping for an element at given path" },
Kevin Rocard3949b342013-05-24 18:43:53 +0200243
Patrick Benavoli68a91282011-08-31 11:23:23 +0200244 /// Browse
Kevin Rocard3949b342013-05-24 18:43:53 +0200245 { "listAssociatedElements", &CParameterMgr::listAssociatedElementsCommmandProcess, 0,
246 "", "List element sub-trees associated to at least one configurable domain" },
247 { "listConflictingElements", &CParameterMgr::listConflictingElementsCommmandProcess, 0,
248 "", "List element sub-trees contained in more than one configurable domain" },
249 { "listRogueElements", &CParameterMgr::listRogueElementsCommmandProcess, 0,
250 "", "List element sub-trees owned by no configurable domain" },
251
Patrick Benavoli68a91282011-08-31 11:23:23 +0200252 /// Settings Import/Export
Kevin Rocard3949b342013-05-24 18:43:53 +0200253 { "exportDomainsXML", &CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess, 1,
254 "<file path> ", "Export domains to XML file" },
255 { "importDomainsXML", &CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess, 1,
256 "<file path>", "Import domains from XML file" },
257 { "exportDomainsWithSettingsXML",
258 &CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess, 1,
259 "<file path> ", "Export domains including settings to XML file" },
260 { "importDomainsWithSettingsXML",
261 &CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess, 1,
262 "<file path>", "Import domains including settings from XML file" },
David Wagnerfd211972014-12-10 15:01:22 +0100263 { "importDomainWithSettingsXML",
264 &CParameterMgr::importConfigurableDomainWithSettingsFromXMLCommmandProcess, 1,
265 "<file path> [overwrite]", "Import a single domain including settings from XML file."
266 " Does not overwrite an existing domain unless 'overwrite' is passed as second"
267 " argument" },
Kevin Rocard3949b342013-05-24 18:43:53 +0200268 { "exportSettings", &CParameterMgr::exportSettingsCommmandProcess, 1,
269 "<file path>", "Export settings to binary file" },
270 { "importSettings", &CParameterMgr::importSettingsCommmandProcess, 1,
271 "<file path>", "Import settings from binary file" },
Georges-Henri Baroncec86c12012-09-04 17:30:28 +0200272 { "getDomainsWithSettingsXML",
273 &CParameterMgr::getConfigurableDomainsWithSettingsXMLCommmandProcess, 0,
Kevin Rocard3949b342013-05-24 18:43:53 +0200274 "", "Print domains including settings as XML" },
David Wagnered744eb2014-12-04 18:38:52 +0100275 { "getDomainWithSettingsXML",
276 &CParameterMgr::getConfigurableDomainWithSettingsXMLCommmandProcess, 1,
277 "<domain>", "Print the given domain including settings as XML" },
Georges-Henri Baroncec86c12012-09-04 17:30:28 +0200278 { "setDomainsWithSettingsXML",
279 &CParameterMgr::setConfigurableDomainsWithSettingsXMLCommmandProcess, 1,
280 "<xml configurable domains>", "Import domains including settings from XML string" },
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200281 /// Structure Export
Kevin Rocard3949b342013-05-24 18:43:53 +0200282 { "getSystemClassXML", &CParameterMgr::getSystemClassXMLCommmandProcess, 0 ,
Kevin Rocardc0211572013-06-18 11:34:53 +0200283 "", "Print parameter structure as XML" },
284 /// Deprecated Commands
285 { "getDomainsXML",
286 &CParameterMgr::getConfigurableDomainsWithSettingsXMLCommmandProcess, 0,
287 "", "DEPRECATED COMMAND, please use getDomainsWithSettingsXML" },
Georges-Henri Baroncec86c12012-09-04 17:30:28 +0200288
Patrick Benavoli68a91282011-08-31 11:23:23 +0200289};
Kevin Rocard3949b342013-05-24 18:43:53 +0200290
Patrick Benavoli68a91282011-08-31 11:23:23 +0200291// Remote command parsers array Size
Patrick Benavoli592ae562011-09-05 16:53:58 +0200292const uint32_t CParameterMgr::guiNbRemoteCommandParserItems = sizeof(gastRemoteCommandParserItems) / sizeof(gastRemoteCommandParserItems[0]);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200293
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100294CParameterMgr::CParameterMgr(const string& strConfigurationFilePath) :
Patrick Benavoli68a91282011-08-31 11:23:23 +0200295 _bTuningModeIsOn(false),
296 _bValueSpaceIsRaw(false),
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200297 _bOutputRawFormatIsHex(false),
Patrick Benavoli68a91282011-08-31 11:23:23 +0200298 _bAutoSyncOn(true),
299 _pMainParameterBlackboard(new CParameterBlackboard),
300 _pElementLibrarySet(new CElementLibrarySet),
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100301 _strXmlConfigurationFilePath(strConfigurationFilePath),
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100302 _pSubsystemPlugins(NULL),
Renaud de Chivre1b8b3ca2013-12-13 15:09:44 +0100303 _handleLibRemoteProcessor(NULL),
Patrick Benavoli68a91282011-08-31 11:23:23 +0200304 _uiStructureChecksum(0),
305 _pRemoteProcessorServer(NULL),
306 _uiMaxCommandUsageLength(0),
307 _pLogger(NULL),
Kevin Rocardecf93102013-07-10 18:28:10 +0200308 _uiLogDepth(0),
Kevin Rocardd6909eb2013-07-18 09:13:51 +0200309 _bFailOnMissingSubsystem(true),
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +0200310 _bFailOnFailedSettingsLoad(true),
311 _bValidateSchemasOnStart(false)
312
Patrick Benavoli68a91282011-08-31 11:23:23 +0200313{
314 // Tuning Mode Mutex
Patrick Benavoli065264a2011-11-20 15:46:41 +0100315 bzero(&_blackboardMutex, sizeof(_blackboardMutex));
316 pthread_mutex_init(&_blackboardMutex, NULL);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200317
318 // Deal with children
319 addChild(new CParameterFrameworkConfiguration);
320 addChild(new CSelectionCriteria);
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100321 addChild(new CSystemClass);
322 addChild(new CConfigurableDomains);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200323
Patrick Benavoli63499d42011-10-24 18:50:03 +0200324 _pCommandHandler = new CCommandHandler(this);
325
326 // Add command parsers
327 uint32_t uiRemoteCommandParserItem;
328
329 for (uiRemoteCommandParserItem = 0; uiRemoteCommandParserItem < guiNbRemoteCommandParserItems; uiRemoteCommandParserItem++) {
330
331 const SRemoteCommandParserItem* pRemoteCommandParserItem = &gastRemoteCommandParserItems[uiRemoteCommandParserItem];
332
333 _pCommandHandler->addCommandParser(pRemoteCommandParserItem->_pcCommandName,
334 pRemoteCommandParserItem->_pfnParser,
335 pRemoteCommandParserItem->_uiMinArgumentCount,
336 pRemoteCommandParserItem->_pcHelp,
337 pRemoteCommandParserItem->_pcDescription);
338 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100339
340 // Configuration file folder
341 uint32_t uiSlashPos = _strXmlConfigurationFilePath.rfind('/', -1);
342
343 assert(uiSlashPos != (uint32_t)-1);
344
345 _strXmlConfigurationFolderPath = _strXmlConfigurationFilePath.substr(0, uiSlashPos);
346
347 // Schema absolute folder location
348 _strSchemaFolderLocation = _strXmlConfigurationFolderPath + "/" + gacSystemSchemasSubFolder;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200349}
350
351CParameterMgr::~CParameterMgr()
352{
353 // Children
354 delete _pRemoteProcessorServer;
Frederic Boisnard31242302012-04-26 17:07:34 +0200355 delete _pCommandHandler;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200356 delete _pMainParameterBlackboard;
357 delete _pElementLibrarySet;
358
Renaud de Chivre1b8b3ca2013-12-13 15:09:44 +0100359 // Close remote processor library
360 if (_handleLibRemoteProcessor != NULL) {
361 dlclose(_handleLibRemoteProcessor);
362 }
363
Patrick Benavoli68a91282011-08-31 11:23:23 +0200364 // Tuning Mode Mutex
Patrick Benavoli065264a2011-11-20 15:46:41 +0100365 pthread_mutex_destroy(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200366}
367
368string CParameterMgr::getKind() const
369{
370 return "ParameterMgr";
371}
372
373// Logging
374void CParameterMgr::setLogger(CParameterMgr::ILogger* pLogger)
375{
376 _pLogger = pLogger;
377}
378
379// Logging
Kevin Rocardace81f82012-12-11 16:19:17 +0100380void CParameterMgr::doLog(bool bIsWarning, const string& strLog) const
Patrick Benavoli68a91282011-08-31 11:23:23 +0200381{
382 if (_pLogger) {
383
384 // Nest
385 string strIndent;
386
387 // Level
388 uint32_t uiNbIndents = _uiLogDepth;
389
390 while (uiNbIndents--) {
391
392 strIndent += " ";
393 }
394
395 // Log
Kevin Rocardace81f82012-12-11 16:19:17 +0100396 _pLogger->log(bIsWarning, strIndent + strLog);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200397 }
398}
399
400void CParameterMgr::nestLog() const
401{
Patrick Benavoli592ae562011-09-05 16:53:58 +0200402 _uiLogDepth++;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200403}
404
405void CParameterMgr::unnestLog() const
406{
Patrick Benavoli592ae562011-09-05 16:53:58 +0200407 _uiLogDepth--;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200408}
409
Patrick Benavoli63499d42011-10-24 18:50:03 +0200410// Version
411string CParameterMgr::getVersion() const
412{
413 string strVersion;
414
415 // Major
416 strVersion = toString(guiEditionMajor) + ".";
417 // Minor
418 strVersion += toString(guiEditionMinor) + ".";
419 // Revision
420 strVersion += toString(guiRevision);
421
422 return strVersion;
423}
424
Patrick Benavoli68a91282011-08-31 11:23:23 +0200425bool CParameterMgr::load(string& strError)
426{
427 CAutoLog autoLog(this, "Loading");
428
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +0200429 feedElementLibraries();
430
Patrick Benavoli68a91282011-08-31 11:23:23 +0200431 // Load Framework configuration
432 if (!loadFrameworkConfiguration(strError)) {
433
434 return false;
435 }
436
437 // Load subsystems
Kevin Rocardecf93102013-07-10 18:28:10 +0200438 if (!getSystemClass()->loadSubsystems(strError,
439 _pSubsystemPlugins, !_bFailOnMissingSubsystem)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200440
441 return false;
442 }
443
444 // Load structure
445 if (!loadStructure(strError)) {
446
447 return false;
448 }
449
450 // Load settings
451 if (!loadSettings(strError)) {
452
453 return false;
454 }
455
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200456 // Back synchronization for areas in parameter blackboard not covered by any domain
Kevin Rocardace81f82012-12-11 16:19:17 +0100457 CBackSynchronizer* pBackSynchronizer = createBackSynchronizer();
Patrick Benavoli68a91282011-08-31 11:23:23 +0200458
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200459 // Back-synchronize
Kevin Rocard57096bd2012-11-30 11:24:20 +0100460 {
461 CAutoLog autoLog(this, "Main blackboard back synchronization");
462
Kevin Rocard5d6e05a2013-01-21 15:57:45 +0100463 pBackSynchronizer->sync();
Kevin Rocard57096bd2012-11-30 11:24:20 +0100464
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200465 // Get rid of back synchronizer
466 delete pBackSynchronizer;
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200467 }
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200468
469 // We're done loading the settings and back synchronizing
470 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
471
472 // We need to ensure all domains are valid
473 pConfigurableDomains->validate(_pMainParameterBlackboard);
474
Kevin Rocard7f265822012-12-07 18:51:22 +0100475 // Log selection criterion states
476 {
477 CAutoLog autoLog(this, "Criterion states");
478
479 const CSelectionCriteria* selectionCriteria = getConstSelectionCriteria();
480
481 list<string> lstrSelectionCriteron;
482 selectionCriteria->listSelectionCriteria(lstrSelectionCriteron, true, false);
483
Kevin Rocard36299362013-02-04 14:57:47 +0100484 log_table(false, lstrSelectionCriteron);
Kevin Rocard7f265822012-12-07 18:51:22 +0100485 }
486
Kevin Rocard2fbe6e82013-03-26 17:09:29 +0100487 // Subsystem can not ask for resync as they have not been synced yet
488 getSystemClass()->cleanSubsystemsNeedToResync();
489
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100490 // At initialization, check subsystems that need resync
491 doApplyConfigurations(true);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200492
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200493 // Start remote processor server if appropriate
494 return handleRemoteProcessingInterface(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200495}
496
497bool CParameterMgr::loadFrameworkConfiguration(string& strError)
498{
499 CAutoLog autoLog(this, "Loading framework configuration");
500
Patrick Benavoli68a91282011-08-31 11:23:23 +0200501 // Parse Structure XML file
502 CXmlElementSerializingContext elementSerializingContext(strError);
503
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100504 if (!xmlParse(elementSerializingContext, getFrameworkConfiguration(), _strXmlConfigurationFilePath, _strXmlConfigurationFolderPath, EFrameworkConfigurationLibrary)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200505
506 return false;
507 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100508 // Set class name to system class and configurable domains
509 getSystemClass()->setName(getConstFrameworkConfiguration()->getSystemClassName());
510 getConfigurableDomains()->setName(getConstFrameworkConfiguration()->getSystemClassName());
511
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100512 // Get subsystem plugins elements
513 _pSubsystemPlugins = static_cast<const CSubsystemPlugins*>(getConstFrameworkConfiguration()->findChild("SubsystemPlugins"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200514
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100515 if (!_pSubsystemPlugins) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200516
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100517 strError = "Parameter Framework Configuration: couldn't find SubsystemPlugins element";
Patrick Benavoli68a91282011-08-31 11:23:23 +0200518
519 return false;
520 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200521
Patrick Benavoli68a91282011-08-31 11:23:23 +0200522 // Log tuning availability
Kevin Rocardace81f82012-12-11 16:19:17 +0100523 log_info("Tuning %s", getConstFrameworkConfiguration()->isTuningAllowed() ? "allowed" : "prohibited");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200524
525 return true;
526}
527
528bool CParameterMgr::loadStructure(string& strError)
529{
530 // Retrieve system to load structure to
531 CSystemClass* pSystemClass = getSystemClass();
532
Kevin Rocarde25ee792013-04-22 17:46:28 +0200533 log_info("Loading " + pSystemClass->getName() + " system class structure");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200534
535 // Get structure description element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100536 const CFrameworkConfigurationLocation* pStructureDescriptionFileLocation = static_cast<const CFrameworkConfigurationLocation*>(getConstFrameworkConfiguration()->findChildOfKind("StructureDescriptionFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200537
538 if (!pStructureDescriptionFileLocation) {
539
540 strError = "No StructureDescriptionFileLocation element found for SystemClass " + pSystemClass->getName();
541
542 return false;
543 }
544
545 // Get Xml structure folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100546 string strXmlStructureFolder = pStructureDescriptionFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200547
548 // Get Xml structure file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100549 string strXmlStructureFilePath = pStructureDescriptionFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200550
551 // Parse Structure XML file
552 CXmlParameterSerializingContext parameterBuildContext(strError);
553
Kevin Rocard57096bd2012-11-30 11:24:20 +0100554 CAutoLog autolog(pSystemClass, "Importing system structure from file " + strXmlStructureFilePath);
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200555
Patrick Benavoli68a91282011-08-31 11:23:23 +0200556 if (!xmlParse(parameterBuildContext, pSystemClass, strXmlStructureFilePath, strXmlStructureFolder, EParameterCreationLibrary)) {
557
558 return false;
559 }
560
561 // Initialize offsets
562 pSystemClass->setOffset(0);
563
564 // Initialize main blackboard's size
565 _pMainParameterBlackboard->setSize(pSystemClass->getFootPrint());
566
567 return true;
568}
569
570bool CParameterMgr::loadSettings(string& strError)
571{
Kevin Rocardd6909eb2013-07-18 09:13:51 +0200572 string strLoadError;
573 bool success = loadSettingsFromConfigFile(strLoadError);
574
575 if (!success && !_bFailOnFailedSettingsLoad) {
576 // Load can not fail, ie continue but log the load errors
577 log_info(strLoadError);
578 log_info("Failed to load settings, continue without domains.");
579 success = true;
580 }
581
582 if (!success) {
583 // Propagate the litteral error only if the function fails
584 strError = strLoadError;
585 return false;
586 }
587
588 return true;
589}
590
591bool CParameterMgr::loadSettingsFromConfigFile(string& strError)
592{
Patrick Benavoli68a91282011-08-31 11:23:23 +0200593 CAutoLog autoLog(this, "Loading settings");
594
595 // Get settings configuration element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100596 const CFrameworkConfigurationGroup* pParameterConfigurationGroup = static_cast<const CFrameworkConfigurationGroup*>(getConstFrameworkConfiguration()->findChildOfKind("SettingsConfiguration"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200597
598 if (!pParameterConfigurationGroup) {
599
600 // No settings to load
601
602 return true;
603 }
604 // Get binary settings file location
605 const CFrameworkConfigurationLocation* pBinarySettingsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("BinarySettingsFileLocation"));
606
607 string strXmlBinarySettingsFilePath;
608
609 if (pBinarySettingsFileLocation) {
610
611 // Get Xml binary settings file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100612 strXmlBinarySettingsFilePath = pBinarySettingsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200613 }
614
615 // Get configurable domains element
616 const CFrameworkConfigurationLocation* pConfigurableDomainsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("ConfigurableDomainsFileLocation"));
617
618 if (!pConfigurableDomainsFileLocation) {
619
620 strError = "No ConfigurableDomainsFileLocation element found for SystemClass " + getSystemClass()->getName();
621
622 return false;
Kevin Rocardd6909eb2013-07-18 09:13:51 +0200623 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200624 // Get destination root element
625 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
626
627 // Get Xml configuration domains file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100628 string strXmlConfigurationDomainsFilePath = pConfigurableDomainsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200629
630 // Get Xml configuration domains folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100631 string strXmlConfigurationDomainsFolder = pConfigurableDomainsFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200632
633 // 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 +0100634 CXmlDomainImportContext xmlDomainImportContext(strError, !pBinarySettingsFileLocation,
635 *getSystemClass());
Patrick Benavoli68a91282011-08-31 11:23:23 +0200636
637 // Selection criteria definition for rule creation
David Wagner29fa61f2014-12-19 11:15:02 +0100638 xmlDomainImportContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
Patrick Benavoli68a91282011-08-31 11:23:23 +0200639
Patrick Benavoli63499d42011-10-24 18:50:03 +0200640 // Auto validation of configurations if no binary settings provided
David Wagner29fa61f2014-12-19 11:15:02 +0100641 xmlDomainImportContext.setAutoValidationRequired(!pBinarySettingsFileLocation);
Patrick Benavoli63499d42011-10-24 18:50:03 +0200642
Kevin Rocardace81f82012-12-11 16:19:17 +0100643 log_info("Importing configurable domains from file %s %s settings", strXmlConfigurationDomainsFilePath.c_str(), pBinarySettingsFileLocation ? "without" : "with");
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200644
Patrick Benavoli68a91282011-08-31 11:23:23 +0200645 // Do parse
David Wagner29fa61f2014-12-19 11:15:02 +0100646 if (!xmlParse(xmlDomainImportContext, pConfigurableDomains, strXmlConfigurationDomainsFilePath, strXmlConfigurationDomainsFolder, EParameterConfigurationLibrary, "SystemClassName")) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200647
648 return false;
649 }
650 // We have loaded the whole system structure, compute checksum
651 const CSystemClass* pSystemClass = getConstSystemClass();
652 _uiStructureChecksum = pSystemClass->computeStructureChecksum() + getConfigurableDomains()->computeStructureChecksum() + getSelectionCriteria()->computeStructureChecksum();
653
654 // Load binary settings if any provided
655 if (pBinarySettingsFileLocation && !pConfigurableDomains->serializeSettings(strXmlBinarySettingsFilePath, false, _uiStructureChecksum, strError)) {
656
657 return false;
658 }
659
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200660 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200661}
662
David Wagnerfd211972014-12-10 15:01:22 +0100663bool CParameterMgr::importDomainFromFile(const string& strXmlFilePath, bool bOverwrite,
664 string& strError)
665{
666 CXmlDomainImportContext xmlDomainImportContext(strError, true, *getSystemClass());
667
668 // Selection criteria definition for rule creation
669 xmlDomainImportContext.setSelectionCriteriaDefinition(
670 getConstSelectionCriteria()->getSelectionCriteriaDefinition());
671
672 // Auto validation of configurations
673 xmlDomainImportContext.setAutoValidationRequired(true);
674
675 // We initialize the domain with an empty name but since we have set the isDomainStandalone
676 // context, the name will be retrieved during de-serialization
677 std::auto_ptr<CConfigurableDomain> standaloneDomain(new CConfigurableDomain());
678 bool bSuccess = xmlParse(xmlDomainImportContext, standaloneDomain.get(),
679 strXmlFilePath, "", EParameterConfigurationLibrary, "");
680
681 if (!bSuccess) {
682 return false;
683 }
684
685 bSuccess = getConfigurableDomains()->addDomain(*standaloneDomain, bOverwrite, strError);
686 if (!bSuccess) {
687 return false;
688 }
689
690 // ownership has been transfered to the ConfigurableDomains object
691 standaloneDomain.release();
692 return true;
693}
694
Patrick Benavoli68a91282011-08-31 11:23:23 +0200695// XML parsing
696bool CParameterMgr::xmlParse(CXmlElementSerializingContext& elementSerializingContext, CElement* pRootElement, const string& strXmlFilePath, const string& strXmlFolder, CParameterMgr::ElementLibrary eElementLibrary, const string& strNameAttrituteName)
697{
698 // Init serializing context
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +0200699 elementSerializingContext.set(_pElementLibrarySet->getElementLibrary(
700 eElementLibrary), strXmlFolder, _strSchemaFolderLocation);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200701
702 // Get Schema file associated to root element
703 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pRootElement->getKind() + ".xsd";
704
David Wagnerfd211972014-12-10 15:01:22 +0100705 std::auto_ptr<CXmlFileDocSource> fileDocSource(NULL);
706
707 if (strNameAttrituteName.empty()) {
708 fileDocSource.reset(new CXmlFileDocSource(strXmlFilePath, strXmlSchemaFilePath,
709 pRootElement->getKind(),
710 _bValidateSchemasOnStart));
711 } else {
712 fileDocSource.reset(new CXmlFileDocSource(strXmlFilePath, strXmlSchemaFilePath,
713 pRootElement->getKind(),
714 pRootElement->getName(), strNameAttrituteName,
715 _bValidateSchemasOnStart));
716 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200717
718 // Start clean
719 pRootElement->clean();
720
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200721 CXmlMemoryDocSink memorySink(pRootElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200722
David Wagnerfd211972014-12-10 15:01:22 +0100723 if (!memorySink.process(*fileDocSource, elementSerializingContext)) {
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200724 //Cleanup
Patrick Benavoli68a91282011-08-31 11:23:23 +0200725 pRootElement->clean();
726
727 return false;
728 }
729
Patrick Benavoli68a91282011-08-31 11:23:23 +0200730 return true;
731}
732
733// Init
734bool CParameterMgr::init(string& strError)
735{
736 return base::init(strError);
737}
738
739// Selection criteria interface
740CSelectionCriterionType* CParameterMgr::createSelectionCriterionType(bool bIsInclusive)
741{
742 // Propagate
743 return getSelectionCriteria()->createSelectionCriterionType(bIsInclusive);
744}
745
746CSelectionCriterion* CParameterMgr::createSelectionCriterion(const string& strName, const CSelectionCriterionType* pSelectionCriterionType)
747{
748 // Propagate
749 return getSelectionCriteria()->createSelectionCriterion(strName, pSelectionCriterionType);
750}
751
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200752// Selection criterion retrieval
753CSelectionCriterion* CParameterMgr::getSelectionCriterion(const string& strName)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200754{
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200755 // Propagate
756 return getSelectionCriteria()->getSelectionCriterion(strName);
757}
758
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100759// Configuration application
Kevin Rocardace81f82012-12-11 16:19:17 +0100760void CParameterMgr::applyConfigurations()
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200761{
762 CAutoLog autoLog(this, "Configuration application request");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200763
764 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +0100765 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200766
767 if (!_bTuningModeIsOn) {
768
769 // Apply configuration(s)
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100770 doApplyConfigurations(false);
Frédéric Boisnarddaaa63c2012-08-27 15:48:15 +0200771 } else {
772
Kevin Rocardace81f82012-12-11 16:19:17 +0100773 log_warning("Configurations were not applied because the TuningMode is on");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200774 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200775}
776
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200777// Get the configurableElement corresponding to the given path
778const CConfigurableElement* CParameterMgr::getConfigurableElement(const string& strPath,
779 string& strError) const
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200780{
Patrick Benavoli065264a2011-11-20 15:46:41 +0100781 CPathNavigator pathNavigator(strPath);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200782
Patrick Benavoli065264a2011-11-20 15:46:41 +0100783 // Nagivate through system class
784 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
785
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100786 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100787 }
788
789 // Find element
790 const CElement* pElement = getConstSystemClass()->findDescendant(pathNavigator);
791
792 if (!pElement) {
793
Kevin Rocard4c3f8d82013-11-21 12:16:28 +0100794 strError = "Path not found: " + strPath;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100795
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100796 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100797 }
798
799 // Check found element is a parameter
800 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pElement);
801
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200802 return pConfigurableElement;
803}
804
805// Dynamic parameter handling
806CParameterHandle* CParameterMgr::createParameterHandle(const string& strPath, string& strError)
807{
808 const CConfigurableElement* pConfigurableElement = getConfigurableElement(strPath, strError);
809
810 if (!pConfigurableElement) {
811
812 // Element not found
Kevin Rocard4c3f8d82013-11-21 12:16:28 +0100813 strError = "Element not found: " + strPath;
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200814 return NULL;
815 }
816
Patrick Benavoli065264a2011-11-20 15:46:41 +0100817 if (!pConfigurableElement->isParameter()) {
818
819 // Element is not parameter
Kevin Rocard4c3f8d82013-11-21 12:16:28 +0100820 strError = "Not a parameter: " + strPath;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100821
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100822 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100823 }
824
825 // Convert as parameter and return new handle
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200826 return new CParameterHandle(static_cast<const CBaseParameter*>(pConfigurableElement), this);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200827}
828
Kevin Rocardecf93102013-07-10 18:28:10 +0200829void CParameterMgr::setFailureOnMissingSubsystem(bool bFail)
830{
831 _bFailOnMissingSubsystem = bFail;
832}
833
834bool CParameterMgr::getFailureOnMissingSubsystem() const
835{
836 return _bFailOnMissingSubsystem;
837}
Kevin Rocardd6909eb2013-07-18 09:13:51 +0200838
839void CParameterMgr::setFailureOnFailedSettingsLoad(bool bFail)
840{
841 _bFailOnFailedSettingsLoad = bFail;
842}
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +0200843
Kevin Rocardd6909eb2013-07-18 09:13:51 +0200844bool CParameterMgr::getFailureOnFailedSettingsLoad()
845{
846 return _bFailOnFailedSettingsLoad;
847}
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +0200848
849void CParameterMgr::setValidateSchemasOnStart(bool bValidate)
850{
851 _bValidateSchemasOnStart = bValidate;
852}
853
854bool CParameterMgr::getValidateSchemasOnStart() const
855{
856 return _bValidateSchemasOnStart;
857}
858
Patrick Benavoli68a91282011-08-31 11:23:23 +0200859/////////////////// Remote command parsers
Patrick Benavoli592ae562011-09-05 16:53:58 +0200860/// Version
Patrick Benavoli63499d42011-10-24 18:50:03 +0200861CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::versionCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli592ae562011-09-05 16:53:58 +0200862{
863 (void)remoteCommand;
864
Patrick Benavoli63499d42011-10-24 18:50:03 +0200865 // Show version
866 strResult = getVersion();
Patrick Benavoli592ae562011-09-05 16:53:58 +0200867
Patrick Benavoli63499d42011-10-24 18:50:03 +0200868 return CCommandHandler::ESucceeded;
Patrick Benavoli592ae562011-09-05 16:53:58 +0200869}
870
Patrick Benavoli68a91282011-08-31 11:23:23 +0200871/// Status
Patrick Benavoli63499d42011-10-24 18:50:03 +0200872CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::statusCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200873{
874 (void)remoteCommand;
875 // System class
876 const CSystemClass* pSystemClass = getSystemClass();
877
Patrick Benavoli68a91282011-08-31 11:23:23 +0200878 // Show status
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200879 /// General section
880 appendTitle(strResult, "General:");
881 // System class
Patrick Benavoli68a91282011-08-31 11:23:23 +0200882 strResult += "System Class: ";
883 strResult += pSystemClass->getName();
884 strResult += "\n";
885
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200886 // Tuning mode
Patrick Benavoli68a91282011-08-31 11:23:23 +0200887 strResult += "Tuning Mode: ";
888 strResult += tuningModeOn() ? "on" : "off";
889 strResult += "\n";
890
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200891 // Value space
Patrick Benavoli68a91282011-08-31 11:23:23 +0200892 strResult += "Value Space: ";
893 strResult += valueSpaceIsRaw() ? "raw" : "real";
894 strResult += "\n";
895
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200896 // Output raw format
897 strResult += "Output Raw Format: ";
898 strResult += outputRawFormatIsHex() ? "hex" : "dec";
899 strResult += "\n";
900
901 // Auto Sync
Patrick Benavoli68a91282011-08-31 11:23:23 +0200902 strResult += "Auto Sync: ";
903 strResult += autoSyncOn() ? "on" : "off";
904 strResult += "\n";
905
906 /// Subsystem list
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200907 appendTitle(strResult, "Subsystems:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200908 string strSubsystemList;
909 pSystemClass->listChildrenPaths(strSubsystemList);
910 strResult += strSubsystemList;
911
912 /// Last applied configurations
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200913 appendTitle(strResult, "Last Applied [Pending] Configurations:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200914 string strLastAppliedConfigurations;
915 getConfigurableDomains()->listLastAppliedConfigurations(strLastAppliedConfigurations);
916 strResult += strLastAppliedConfigurations;
917
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200918 /// Criteria states
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200919 appendTitle(strResult, "Selection Criteria:");
Kevin Rocard7f265822012-12-07 18:51:22 +0100920 list<string> lstrSelectionCriteria;
921 getSelectionCriteria()->listSelectionCriteria(lstrSelectionCriteria, false, true);
922 // Concatenate the criterion list as the command result
Frederic Boisnard390b36d2013-05-23 15:28:31 +0200923 string strCriteriaStates;
924 CUtility::asString(lstrSelectionCriteria, strCriteriaStates);
925 strResult += strCriteriaStates;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200926
Patrick Benavoli63499d42011-10-24 18:50:03 +0200927 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200928}
929
930/// Tuning Mode
Patrick Benavoli63499d42011-10-24 18:50:03 +0200931CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200932{
933 if (remoteCommand.getArgument(0) == "on") {
934
935 if (setTuningMode(true, strResult)) {
936
Patrick Benavoli63499d42011-10-24 18:50:03 +0200937 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200938 }
939 } else if (remoteCommand.getArgument(0) == "off") {
940
941 if (setTuningMode(false, strResult)) {
942
Patrick Benavoli63499d42011-10-24 18:50:03 +0200943 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200944 }
945 } else {
946 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200947 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200948 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200949 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200950}
951
Patrick Benavoli63499d42011-10-24 18:50:03 +0200952CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200953{
954 (void)remoteCommand;
955
956 strResult = tuningModeOn() ? "on" : "off";
957
Patrick Benavoli63499d42011-10-24 18:50:03 +0200958 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200959}
960
961/// Value Space
Patrick Benavoli63499d42011-10-24 18:50:03 +0200962CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200963{
964 (void)strResult;
965
966 if (remoteCommand.getArgument(0) == "raw") {
967
968 setValueSpace(true);
969
Patrick Benavoli63499d42011-10-24 18:50:03 +0200970 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200971
972 } else if (remoteCommand.getArgument(0) == "real") {
973
974 setValueSpace(false);
975
Patrick Benavoli63499d42011-10-24 18:50:03 +0200976 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200977
978 } else {
979 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200980 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200981 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200982 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200983}
984
Patrick Benavoli63499d42011-10-24 18:50:03 +0200985CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200986{
987 (void)remoteCommand;
988
989 strResult = valueSpaceIsRaw() ? "raw" : "real";
990
Patrick Benavoli63499d42011-10-24 18:50:03 +0200991 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200992}
993
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200994/// Output Raw Format
Patrick Benavoli63499d42011-10-24 18:50:03 +0200995CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200996{
997 (void)strResult;
998
999 if (remoteCommand.getArgument(0) == "hex") {
1000
1001 setOutputRawFormat(true);
1002
Patrick Benavoli63499d42011-10-24 18:50:03 +02001003 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001004
1005 } else if (remoteCommand.getArgument(0) == "dec") {
1006
1007 setOutputRawFormat(false);
1008
Patrick Benavoli63499d42011-10-24 18:50:03 +02001009 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001010
1011 } else {
1012 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +02001013 return CCommandHandler::EShowUsage;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001014 }
Patrick Benavoli63499d42011-10-24 18:50:03 +02001015 return CCommandHandler::EFailed;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001016}
1017
Patrick Benavoli63499d42011-10-24 18:50:03 +02001018CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001019{
1020 (void)remoteCommand;
1021
1022 strResult = outputRawFormatIsHex() ? "hex" : "dec";
1023
Patrick Benavoli63499d42011-10-24 18:50:03 +02001024 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001025}
1026
Patrick Benavoli68a91282011-08-31 11:23:23 +02001027/// Sync
Patrick Benavoli63499d42011-10-24 18:50:03 +02001028CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001029{
1030 if (remoteCommand.getArgument(0) == "on") {
1031
1032 if (setAutoSync(true, strResult)) {
1033
Patrick Benavoli63499d42011-10-24 18:50:03 +02001034 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001035 }
1036 } else if (remoteCommand.getArgument(0) == "off") {
1037
1038 if (setAutoSync(false, strResult)) {
1039
Patrick Benavoli63499d42011-10-24 18:50:03 +02001040 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001041 }
1042 } else {
1043 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +02001044 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001045 }
Patrick Benavoli63499d42011-10-24 18:50:03 +02001046 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001047}
1048
Patrick Benavoli63499d42011-10-24 18:50:03 +02001049CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001050{
1051 (void)remoteCommand;
1052
1053 strResult = autoSyncOn() ? "on" : "off";
1054
Patrick Benavoli63499d42011-10-24 18:50:03 +02001055 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001056}
1057
Patrick Benavoli63499d42011-10-24 18:50:03 +02001058CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::syncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001059{
1060 (void)remoteCommand;
1061
Patrick Benavoli63499d42011-10-24 18:50:03 +02001062 return sync(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001063}
1064
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001065/// Criteria
Patrick Benavoli63499d42011-10-24 18:50:03 +02001066CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listCriteriaCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001067{
1068 (void)remoteCommand;
1069
Kevin Rocard4eae8272013-04-18 19:12:46 +02001070 bool humanReadable = true;
Kevin Rocard7f265822012-12-07 18:51:22 +01001071
Kevin Rocard4eae8272013-04-18 19:12:46 +02001072 // Look for optional arguments
1073 if (remoteCommand.getArgumentCount() >= 1) {
1074
1075 // If csv is provided, format the criterion list in Commas Separated Value pairs
1076 if (remoteCommand.getArgument(0) == "csv") {
1077 humanReadable = false;
1078 } else {
1079 return CCommandHandler::EShowUsage;
1080 }
1081 }
1082
1083 list<string> lstrResult;
1084 getSelectionCriteria()->listSelectionCriteria(lstrResult, true, humanReadable);
Kevin Rocard7f265822012-12-07 18:51:22 +01001085
1086 // Concatenate the criterion list as the command result
Frederic Boisnard390b36d2013-05-23 15:28:31 +02001087 CUtility::asString(lstrResult, strResult);
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001088
Patrick Benavoli63499d42011-10-24 18:50:03 +02001089 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001090}
Patrick Benavoli68a91282011-08-31 11:23:23 +02001091
1092/// Domains
Patrick Benavoli63499d42011-10-24 18:50:03 +02001093CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001094{
1095 (void)remoteCommand;
1096
Patrick Benavoli63499d42011-10-24 18:50:03 +02001097 getConfigurableDomains()->listDomains(strResult);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001098
Patrick Benavoli63499d42011-10-24 18:50:03 +02001099 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001100}
1101
Patrick Benavoli63499d42011-10-24 18:50:03 +02001102CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001103{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001104 return createDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001105}
1106
Patrick Benavoli63499d42011-10-24 18:50:03 +02001107CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001108{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001109 return deleteDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001110}
1111
Kevin Rocard170f0a42012-06-18 13:56:05 +02001112CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteAllDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1113{
1114 (void)remoteCommand;
1115
1116 return deleteAllDomains(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1117}
1118
Patrick Benavoli63499d42011-10-24 18:50:03 +02001119CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001120{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001121 return getConfigurableDomains()->renameDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001122}
1123
Patrick Benavoli63499d42011-10-24 18:50:03 +02001124CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001125{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001126 // Check tuning mode
1127 if (!checkTuningModeOn(strResult)) {
1128
1129 return CCommandHandler::EFailed;
1130 }
1131
1132 // Set property
1133 bool bSequenceAware;
1134
1135 if (remoteCommand.getArgument(1) == "true") {
1136
1137 bSequenceAware = true;
1138
1139 } else if (remoteCommand.getArgument(1) == "false") {
1140
1141 bSequenceAware = false;
1142
1143 } else {
1144 // Show usage
1145 return CCommandHandler::EShowUsage;
1146 }
1147
1148 return getConfigurableDomains()->setSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001149}
1150
Patrick Benavoli63499d42011-10-24 18:50:03 +02001151CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001152{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001153 // Get property
1154 bool bSequenceAware;
1155
1156 if (!getConfigurableDomains()->getSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult)) {
1157
1158 return CCommandHandler::EFailed;
1159 }
1160
1161 strResult = bSequenceAware ? "true" : "false";
1162
1163 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001164}
1165
Patrick Benavoli63499d42011-10-24 18:50:03 +02001166CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001167{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001168 return getConfigurableDomains()->listDomainElements(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001169}
1170
Patrick Benavoli63499d42011-10-24 18:50:03 +02001171CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::addElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001172{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001173 return addConfigurableElementToDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1174}
1175
1176CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::removeElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1177{
1178 return removeConfigurableElementFromDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1179}
1180
1181CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::splitDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1182{
1183 return split(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001184}
1185
1186/// Configurations
Patrick Benavoli63499d42011-10-24 18:50:03 +02001187CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConfigurationsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001188{
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001189 return getConstConfigurableDomains()->listConfigurations(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
1190}
1191
1192CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1193{
1194 (void)remoteCommand;
1195
1196 // Dummy error context
1197 string strError;
1198 CErrorContext errorContext(strError);
1199
1200 // Dump
1201 getConstConfigurableDomains()->dumpContent(strResult, errorContext);
1202
1203 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001204}
1205
Patrick Benavoli63499d42011-10-24 18:50:03 +02001206CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001207{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001208 return createConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001209}
1210
Patrick Benavoli63499d42011-10-24 18:50:03 +02001211CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001212{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001213 return deleteConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001214}
1215
Patrick Benavoli63499d42011-10-24 18:50:03 +02001216CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001217{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001218 return getConfigurableDomains()->renameConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001219}
1220
Patrick Benavoli63499d42011-10-24 18:50:03 +02001221CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::saveConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001222{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001223 return saveConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001224}
1225
Patrick Benavoli63499d42011-10-24 18:50:03 +02001226CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::restoreConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001227{
Kevin Rocardace81f82012-12-11 16:19:17 +01001228 list<string> lstrResult;
1229 if (!restoreConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), lstrResult)) {
1230 //Concatenate the error list as the command result
Frederic Boisnard390b36d2013-05-23 15:28:31 +02001231 CUtility::asString(lstrResult, strResult);
Kevin Rocardace81f82012-12-11 16:19:17 +01001232
1233 return CCommandHandler::EFailed;
1234 }
1235 return CCommandHandler::EDone;
Patrick Benavoli63499d42011-10-24 18:50:03 +02001236}
1237
1238CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1239{
1240 // Check tuning mode
1241 if (!checkTuningModeOn(strResult)) {
1242
1243 return CCommandHandler::EFailed;
1244 }
1245
1246 // Build configurable element path list
Sebastien Gonzalved9526492014-02-20 22:28:03 +01001247 std::vector<string> astrNewElementSequence;
Patrick Benavoli63499d42011-10-24 18:50:03 +02001248
1249 uint32_t uiArgument;
1250
1251 for (uiArgument = 2; uiArgument < remoteCommand.getArgumentCount(); uiArgument++) {
1252
1253 astrNewElementSequence.push_back(remoteCommand.getArgument(uiArgument));
1254 }
1255
1256 // Delegate to configurable domains
1257 return getConfigurableDomains()->setElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), astrNewElementSequence, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1258}
1259
1260CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1261{
1262 // Delegate to configurable domains
1263 return getConfigurableDomains()->getElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001264}
1265
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001266CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1267{
1268 // Delegate to configurable domains
1269 return getConfigurableDomains()->setApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.packArguments(2, remoteCommand.getArgumentCount() - 2), getConstSelectionCriteria()->getSelectionCriteriaDefinition(), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1270}
1271
1272CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::clearRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1273{
1274 // Delegate to configurable domains
1275 return getConfigurableDomains()->clearApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1276}
1277
1278CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1279{
1280 // Delegate to configurable domains
1281 return getConfigurableDomains()->getApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
1282}
1283
Patrick Benavoli68a91282011-08-31 11:23:23 +02001284/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001285CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001286{
1287 CElementLocator elementLocator(getSystemClass(), false);
1288
1289 CElement* pLocatedElement = NULL;
1290
1291 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1292
Patrick Benavoli63499d42011-10-24 18:50:03 +02001293 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001294 }
1295
1296 strResult = string("\n");
1297
1298 if (!pLocatedElement) {
1299
1300 // List from root folder
1301
1302 // Return system class qualified name
1303 pLocatedElement = getSystemClass();
1304 }
1305
1306 // Return sub-elements
1307 strResult += pLocatedElement->listQualifiedPaths(false);
1308
Patrick Benavoli63499d42011-10-24 18:50:03 +02001309 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001310}
1311
1312/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001313CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listParametersCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001314{
1315 CElementLocator elementLocator(getSystemClass(), false);
1316
1317 CElement* pLocatedElement = NULL;
1318
1319 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1320
Patrick Benavoli63499d42011-10-24 18:50:03 +02001321 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001322 }
1323
1324 strResult = string("\n");
1325
1326 if (!pLocatedElement) {
1327
1328 // List from root folder
1329
1330 // Return system class qualified name
1331 pLocatedElement = getSystemClass();
1332 }
1333
1334 // Return sub-elements
1335 strResult += pLocatedElement->listQualifiedPaths(true);
1336
Patrick Benavoli63499d42011-10-24 18:50:03 +02001337 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001338}
1339
Patrick Benavoli63499d42011-10-24 18:50:03 +02001340CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001341{
1342 CElementLocator elementLocator(getSystemClass());
1343
1344 CElement* pLocatedElement = NULL;
1345
1346 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1347
Patrick Benavoli63499d42011-10-24 18:50:03 +02001348 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001349 }
1350
1351 string strError;
1352
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001353 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001354
1355 // Dump elements
1356 pLocatedElement->dumpContent(strResult, parameterAccessContext);
1357
Patrick Benavoli63499d42011-10-24 18:50:03 +02001358 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001359}
1360
Patrick Benavoli63499d42011-10-24 18:50:03 +02001361CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSizeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001362{
1363 CElementLocator elementLocator(getSystemClass());
1364
1365 CElement* pLocatedElement = NULL;
1366
1367 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1368
Patrick Benavoli63499d42011-10-24 18:50:03 +02001369 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001370 }
1371
1372 // Converted to actual sizable element
1373 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1374
1375 // Get size as string
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001376 strResult = pConfigurableElement->getFootprintAsString();
Patrick Benavoli68a91282011-08-31 11:23:23 +02001377
Patrick Benavoli63499d42011-10-24 18:50:03 +02001378 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001379}
1380
Patrick Benavoli63499d42011-10-24 18:50:03 +02001381CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showPropertiesCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001382{
1383 CElementLocator elementLocator(getSystemClass());
1384
1385 CElement* pLocatedElement = NULL;
1386
1387 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1388
Patrick Benavoli63499d42011-10-24 18:50:03 +02001389 return CCommandHandler::EFailed;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001390 }
1391
1392 // Convert element
1393 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1394
1395 // Return element properties
1396 pConfigurableElement->showProperties(strResult);
1397
Patrick Benavoli63499d42011-10-24 18:50:03 +02001398 return CCommandHandler::ESucceeded;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001399}
1400
Patrick Benavoli63499d42011-10-24 18:50:03 +02001401CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001402{
1403 string strValue;
1404
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001405 if (!accessParameterValue(remoteCommand.getArgument(0), strValue, false, strResult)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001406
Patrick Benavoli63499d42011-10-24 18:50:03 +02001407 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001408 }
1409 // Succeeded
1410 strResult = strValue;
1411
Patrick Benavoli63499d42011-10-24 18:50:03 +02001412 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001413}
1414
Patrick Benavoli63499d42011-10-24 18:50:03 +02001415CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001416{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001417 // Check tuning mode
1418 if (!checkTuningModeOn(strResult)) {
1419
1420 return CCommandHandler::EFailed;
1421 }
1422 // Get value to set
1423 string strValue = remoteCommand.packArguments(1, remoteCommand.getArgumentCount() - 1);
1424
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001425 return accessParameterValue(remoteCommand.getArgument(0), strValue, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001426}
1427
Patrick Benavoli63499d42011-10-24 18:50:03 +02001428CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listBelongingDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001429{
1430 CElementLocator elementLocator(getSystemClass());
1431
1432 CElement* pLocatedElement = NULL;
1433
1434 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1435
Patrick Benavoli63499d42011-10-24 18:50:03 +02001436 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001437 }
1438
1439 // Convert element
1440 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1441
1442 // Return element belonging domains
1443 pConfigurableElement->listBelongingDomains(strResult);
1444
Patrick Benavoli63499d42011-10-24 18:50:03 +02001445 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001446}
1447
Patrick Benavoli63499d42011-10-24 18:50:03 +02001448CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001449{
1450 CElementLocator elementLocator(getSystemClass());
1451
1452 CElement* pLocatedElement = NULL;
1453
1454 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1455
Patrick Benavoli63499d42011-10-24 18:50:03 +02001456 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001457 }
1458
1459 // Convert element
1460 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1461
1462 // Return element belonging domains
1463 pConfigurableElement->listAssociatedDomains(strResult);
1464
Patrick Benavoli63499d42011-10-24 18:50:03 +02001465 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001466}
1467
Patrick Benavoli63499d42011-10-24 18:50:03 +02001468CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001469{
1470 (void)remoteCommand;
1471
1472 getConfigurableDomains()->listAssociatedElements(strResult);
1473
Patrick Benavoli63499d42011-10-24 18:50:03 +02001474 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001475}
1476
Patrick Benavoli63499d42011-10-24 18:50:03 +02001477CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConflictingElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001478{
1479 (void)remoteCommand;
1480
1481 getConfigurableDomains()->listConflictingElements(strResult);
1482
Patrick Benavoli63499d42011-10-24 18:50:03 +02001483 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001484}
1485
Patrick Benavoli63499d42011-10-24 18:50:03 +02001486CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listRogueElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001487{
1488 (void)remoteCommand;
1489
1490 getSystemClass()->listRogueElements(strResult);
1491
Patrick Benavoli63499d42011-10-24 18:50:03 +02001492 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001493}
1494
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001495CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getConfigurationParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1496{
1497 string strOutputValue;
1498 string strError;
1499
1500 if (!accessConfigurationValue(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), strOutputValue, false, strError)) {
1501
1502 strResult = strError;
1503 return CCommandHandler::EFailed;
1504 }
1505 // Succeeded
1506 strResult = strOutputValue;
1507
1508 return CCommandHandler::ESucceeded;
1509}
1510
1511CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setConfigurationParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1512{
1513 // Get value to set
1514 string strValue = remoteCommand.packArguments(3, remoteCommand.getArgumentCount() - 3);
1515
1516 bool bSuccess = accessConfigurationValue(remoteCommand.getArgument(0),
1517 remoteCommand.getArgument(1),
1518 remoteCommand.getArgument(2),
1519 strValue, true, strResult);
1520
1521 return bSuccess ? CCommandHandler::EDone : CCommandHandler::EFailed;
1522}
1523
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +02001524CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showMappingCommmandProcess(
1525 const IRemoteCommand& remoteCommand,
1526 string& strResult)
1527{
1528 if (!getParameterMapping(remoteCommand.getArgument(0), strResult)) {
1529
1530 return CCommandHandler::EFailed;
1531 }
1532
1533 return CCommandHandler::ESucceeded;
1534}
1535
Patrick Benavoli68a91282011-08-31 11:23:23 +02001536/// Settings Import/Export
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001537CParameterMgr::CCommandHandler::CommandStatus
1538 CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess(
1539 const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001540{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001541 string strFileName = remoteCommand.getArgument(0);
1542 return exportDomainsXml(strFileName, false, true, strResult) ?
1543 CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001544}
1545
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001546CParameterMgr::CCommandHandler::CommandStatus
1547 CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess(
1548 const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001549{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001550 return importDomainsXml(remoteCommand.getArgument(0), false, true, strResult) ?
1551 CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001552}
1553
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001554CParameterMgr::CCommandHandler::CommandStatus
1555 CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess(
1556 const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001557{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001558 string strFileName = remoteCommand.getArgument(0);
1559 return exportDomainsXml(strFileName, true, true, strResult) ?
1560 CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001561}
1562
Patrick Benavoli63499d42011-10-24 18:50:03 +02001563CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001564{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001565 return importDomainsXml(remoteCommand.getArgument(0), true, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001566}
1567
David Wagnerfd211972014-12-10 15:01:22 +01001568CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainWithSettingsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1569{
1570 bool bOverwrite = false;
1571
1572 // Look for optional arguments
1573 if (remoteCommand.getArgumentCount() > 1) {
1574
1575 if (remoteCommand.getArgument(1) == "overwrite") {
1576
1577 bOverwrite = true;
1578 } else {
1579 // Show usage
1580 return CCommandHandler::EShowUsage;
1581 }
1582 }
1583
1584 return importSingleDomainXml(remoteCommand.getArgument(0), bOverwrite, strResult) ?
1585 CCommandHandler::EDone : CCommandHandler::EFailed;
1586}
1587
Patrick Benavoli63499d42011-10-24 18:50:03 +02001588CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001589{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001590 return exportDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001591}
1592
Patrick Benavoli63499d42011-10-24 18:50:03 +02001593CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001594{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001595 return importDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001596}
1597
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001598CParameterMgr::CCommandHandler::CommandStatus
1599 CParameterMgr::getConfigurableDomainsWithSettingsXMLCommmandProcess(
1600 const IRemoteCommand& remoteCommand, string& strResult)
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001601{
1602 (void)remoteCommand;
1603
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001604 if (!exportDomainsXml(strResult, true, false, strResult)) {
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001605
1606 return CCommandHandler::EFailed;
1607 }
1608 // Succeeded
1609 return CCommandHandler::ESucceeded;
1610}
1611
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001612CParameterMgr::CCommandHandler::CommandStatus
David Wagnered744eb2014-12-04 18:38:52 +01001613 CParameterMgr::getConfigurableDomainWithSettingsXMLCommmandProcess(
1614 const IRemoteCommand& remoteCommand, string& strResult)
1615{
1616 string strDomainName = remoteCommand.getArgument(0);
1617
1618 return exportSingleDomainXml(strResult, strDomainName, true, false, strResult) ?
1619 CCommandHandler::ESucceeded : CCommandHandler::EFailed;
1620}
1621
1622CParameterMgr::CCommandHandler::CommandStatus
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001623 CParameterMgr::setConfigurableDomainsWithSettingsXMLCommmandProcess(
1624 const IRemoteCommand& remoteCommand, string& strResult)
1625{
1626 return importDomainsXml(remoteCommand.getArgument(0), true, false, strResult) ?
1627 CCommandHandler::EDone : CCommandHandler::EFailed;
1628}
1629
1630CParameterMgr::CCommandHandler::CommandStatus
1631 CParameterMgr::getSystemClassXMLCommmandProcess(
1632 const IRemoteCommand& remoteCommand, string& strResult)
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001633{
1634 (void)remoteCommand;
1635
1636 if (!getSystemClassXMLString(strResult)) {
1637
1638 return CCommandHandler::EFailed;
1639 }
1640 // Succeeded
1641 return CCommandHandler::ESucceeded;
1642}
1643
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001644// User set/get parameters in main BlackBoard
1645bool CParameterMgr::accessParameterValue(const string& strPath, string& strValue, bool bSet, string& strError)
1646{
1647 // Define context
1648 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
1649
Frédéric Boisnard150407c2013-03-15 14:46:23 +01001650 // Activate the auto synchronization with the hardware
1651 if (bSet) {
1652
1653 parameterAccessContext.setAutoSync(_bAutoSyncOn);
1654 }
1655
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001656 return accessValue(parameterAccessContext, strPath, strValue, bSet, strError);
1657}
1658
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +02001659// User get parameter mapping
1660bool CParameterMgr::getParameterMapping(const string& strPath, string& strResult) const
1661{
1662 CPathNavigator pathNavigator(strPath);
1663
1664 // Nagivate through system class
1665 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strResult)) {
1666
1667 return false;
1668 }
1669
1670 // Get the ConfigurableElement corresponding to strPath
1671 const CConfigurableElement* pConfigurableElement = getConfigurableElement(strPath, strResult);
1672 if (!pConfigurableElement) {
1673
1674 return false;
1675 }
1676
1677 // Find the list of the ancestors of the current ConfigurableElement that have a mapping
1678 list<const CConfigurableElement*> configurableElementPath;
1679 pConfigurableElement->getListOfElementsWithMapping(configurableElementPath);
1680
1681 // Get the Subsystem containing the ConfigurableElement
1682 const CSubsystem* pSubsystem = pConfigurableElement->getBelongingSubsystem();
1683 if (!pSubsystem) {
1684
1685 strResult = "Unable to find the Subsystem containing the parameter";
1686 return false;
1687 }
1688
1689 // Fetch the mapping corresponding to the ConfigurableElement
1690 strResult = pSubsystem->getMapping(configurableElementPath);
1691
1692 return true;
1693}
1694
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001695// User set/get parameters in specific Configuration BlackBoard
1696bool CParameterMgr::accessConfigurationValue(const string& strDomain, const string& strConfiguration, const string& strPath, string& strValue, bool bSet, string& strError)
1697{
1698 CElementLocator elementLocator(getSystemClass());
1699
1700 CElement* pLocatedElement = NULL;
1701
1702 if (!elementLocator.locate(strPath, &pLocatedElement, strError)) {
1703
1704 return false;
1705 }
1706
1707 // Convert element
1708 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1709
1710 // Get the Configuration blackboard and the Base Offset of the configurable element in this blackboard
1711 uint32_t uiBaseOffset;
1712 bool bIsLastApplied;
1713
1714 CParameterBlackboard* pConfigurationBlackboard = getConstConfigurableDomains()->findConfigurationBlackboard(strDomain, strConfiguration, pConfigurableElement, uiBaseOffset, bIsLastApplied, strError);
1715
1716 if (!pConfigurationBlackboard) {
1717
1718 return false;
1719 }
1720
1721 log_info("Element %s in Domain %s, offset: %d, base offset: %d", strPath.c_str(), strDomain.c_str(), pConfigurableElement->getOffset(), uiBaseOffset);
1722
1723 /// Update the Configuration Blackboard
1724
Frédéric Boisnard150407c2013-03-15 14:46:23 +01001725 // 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 +01001726 CParameterAccessContext parameterAccessContext(strError, pConfigurationBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex, uiBaseOffset);
1727
Frédéric Boisnardda8298c2014-05-23 19:05:31 +02001728 // Deactivate the auto synchronization with the hardware during the Configuration Blackboard
1729 // access (only Main Blackboard shall be synchronized, Configurations Blackboards are copied
1730 // into the Main Blackboard each time a configuration is restored but they are not synchronized
1731 // directly).
1732 if (bSet) {
1733
1734 parameterAccessContext.setAutoSync(false);
1735 }
1736
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001737 // Access Value in the Configuration Blackboard
1738 if (!accessValue(parameterAccessContext, strPath, strValue, bSet, strError)) {
1739
1740 return false;
1741 }
1742
1743 /// If the Configuration is the last one applied, update the Main Blackboard as well
1744
1745 if (bIsLastApplied) {
1746
1747 // Define Main context
1748 parameterAccessContext.setParameterBlackboard(_pMainParameterBlackboard);
1749
Frédéric Boisnard150407c2013-03-15 14:46:23 +01001750 // Activate the auto synchronization with the hardware
1751 if (bSet) {
1752
1753 parameterAccessContext.setAutoSync(_bAutoSyncOn);
1754 }
1755
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001756 // Access Value in the Main Blackboard
1757 return accessValue(parameterAccessContext, strPath, strValue, bSet, strError);
1758 }
1759
1760 return true;
1761}
1762
Patrick Benavoli68a91282011-08-31 11:23:23 +02001763// User set/get parameters
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001764bool CParameterMgr::accessValue(CParameterAccessContext& parameterAccessContext, const string& strPath, string& strValue, bool bSet, string& strError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001765{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001766 // Lock state
1767 CAutoLock autoLock(&_blackboardMutex);
1768
1769 CPathNavigator pathNavigator(strPath);
1770
1771 // Nagivate through system class
1772 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001773
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +02001774 parameterAccessContext.setError(strError);
1775
Patrick Benavoli68a91282011-08-31 11:23:23 +02001776 return false;
1777 }
1778
Patrick Benavoli065264a2011-11-20 15:46:41 +01001779 // Do the get
1780 return getConstSystemClass()->accessValue(pathNavigator, strValue, bSet, parameterAccessContext);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001781}
1782
1783// Tuning mode
1784bool CParameterMgr::setTuningMode(bool bOn, string& strError)
1785{
1786 // Tuning allowed?
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001787 if (bOn && !getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001788
1789 strError = "Tuning prohibited";
1790
1791 return false;
1792 }
1793 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +01001794 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001795
1796 // Warn domains about exiting tuning mode
1797 if (!bOn && _bTuningModeIsOn) {
1798
1799 // Ensure application of currently selected configurations
Patrick Benavoli1387bda2011-08-31 11:23:24 +02001800 // Force-apply configurations
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01001801 doApplyConfigurations(true);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001802
Patrick Benavoli68a91282011-08-31 11:23:23 +02001803 // Turn auto sync back on
1804 _bAutoSyncOn = true;
1805 }
1806
1807 // Store
1808 _bTuningModeIsOn = bOn;
1809
Patrick Benavoli68a91282011-08-31 11:23:23 +02001810 return true;
1811}
1812
1813bool CParameterMgr::tuningModeOn() const
1814{
1815 return _bTuningModeIsOn;
1816}
1817
1818// Current value space for user set/get value interpretation
1819void CParameterMgr::setValueSpace(bool bIsRaw)
1820{
1821 _bValueSpaceIsRaw = bIsRaw;
1822}
1823
1824bool CParameterMgr::valueSpaceIsRaw()
1825{
1826 return _bValueSpaceIsRaw;
1827}
1828
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001829// Current Output Raw Format for user get value interpretation
1830void CParameterMgr::setOutputRawFormat(bool bIsHex)
1831{
1832 _bOutputRawFormatIsHex = bIsHex;
1833}
1834
1835bool CParameterMgr::outputRawFormatIsHex()
1836{
1837 return _bOutputRawFormatIsHex;
1838}
1839
Patrick Benavoli68a91282011-08-31 11:23:23 +02001840/// Sync
1841// Automatic hardware synchronization control (during tuning session)
1842bool CParameterMgr::setAutoSync(bool bAutoSyncOn, string& strError)
1843{
1844 // Check tuning mode
1845 if (!checkTuningModeOn(strError)) {
1846
1847 return false;
1848 }
1849 // Warn domains about turning auto sync back on
1850 if (bAutoSyncOn && !_bAutoSyncOn) {
1851
Patrick Benavoli592ae562011-09-05 16:53:58 +02001852 // Do the synchronization at system class level (could be optimized by keeping track of all modified parameters)
1853 if (!sync(strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001854
1855 return false;
1856 }
1857 }
1858
1859 // Set Auto sync
1860 _bAutoSyncOn = bAutoSyncOn;
1861
1862 return true;
1863}
1864
1865bool CParameterMgr::autoSyncOn() const
1866{
1867 return _bAutoSyncOn;
1868}
1869
1870// Manual hardware synchronization control (during tuning session)
1871bool CParameterMgr::sync(string& strError)
1872{
1873 // Check tuning mode
1874 if (!checkTuningModeOn(strError)) {
1875
1876 return false;
1877 }
1878 // Warn domains about turning auto sync back on
1879 if (_bAutoSyncOn) {
1880
1881 strError = "Feature unavailable when Auto Sync is on";
1882
1883 return false;
1884 }
1885
1886 // Get syncer set
1887 CSyncerSet syncerSet;
1888 // ... from system class
1889 getConstSystemClass()->fillSyncerSet(syncerSet);
Kevin Rocardace81f82012-12-11 16:19:17 +01001890
Patrick Benavoli68a91282011-08-31 11:23:23 +02001891 // Sync
Kevin Rocardace81f82012-12-11 16:19:17 +01001892 list<string> lstrError;
1893 if (! syncerSet.sync(*_pMainParameterBlackboard, false, &lstrError)){
1894
Frederic Boisnard390b36d2013-05-23 15:28:31 +02001895 CUtility::asString(lstrError, strError);
Kevin Rocardace81f82012-12-11 16:19:17 +01001896 return false;
1897 };
1898
1899 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001900}
1901
1902// Content dump
1903void CParameterMgr::logStructureContent(string& strContent) const
1904{
1905 string strError;
1906
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001907 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001908
1909 dumpContent(strContent, parameterAccessContext);
1910}
1911
1912// Configuration/Domains handling
1913bool CParameterMgr::createDomain(const string& strName, string& strError)
1914{
1915 // Check tuning mode
1916 if (!checkTuningModeOn(strError)) {
1917
1918 return false;
1919 }
1920
1921 // Delegate to configurable domains
1922 return getConfigurableDomains()->createDomain(strName, strError);
1923}
1924
1925bool CParameterMgr::deleteDomain(const string& strName, string& strError)
1926{
1927 // Check tuning mode
1928 if (!checkTuningModeOn(strError)) {
1929
1930 return false;
1931 }
1932
1933 // Delegate to configurable domains
1934 return getConfigurableDomains()->deleteDomain(strName, strError);
1935}
1936
Kevin Rocard170f0a42012-06-18 13:56:05 +02001937bool CParameterMgr::deleteAllDomains(string& strError)
1938{
1939 // Check tuning mode
1940 if (!checkTuningModeOn(strError)) {
1941
1942 return false;
1943 }
1944
1945 // Delegate to configurable domains
1946 getConfigurableDomains()->deleteAllDomains();
1947
1948 return true;
1949}
1950
Patrick Benavoli68a91282011-08-31 11:23:23 +02001951bool CParameterMgr::createConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1952{
1953 // Check tuning mode
1954 if (!checkTuningModeOn(strError)) {
1955
1956 return false;
1957 }
1958
1959 // Delegate to configurable domains
1960 return getConfigurableDomains()->createConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1961}
1962
1963bool CParameterMgr::deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1964{
1965 // Check tuning mode
1966 if (!checkTuningModeOn(strError)) {
1967
1968 return false;
1969 }
1970
1971 // Delegate to configurable domains
1972 return getConfigurableDomains()->deleteConfiguration(strDomain, strConfiguration, strError);
1973}
1974
Kevin Rocardace81f82012-12-11 16:19:17 +01001975bool CParameterMgr::restoreConfiguration(const string& strDomain, const string& strConfiguration, list<string>& lstrError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001976{
Kevin Rocardace81f82012-12-11 16:19:17 +01001977 string strError;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001978 // Check tuning mode
1979 if (!checkTuningModeOn(strError)) {
1980
Kevin Rocardace81f82012-12-11 16:19:17 +01001981 lstrError.push_back(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001982 return false;
1983 }
1984
1985 // Delegate to configurable domains
Kevin Rocardace81f82012-12-11 16:19:17 +01001986 return getConstConfigurableDomains()->restoreConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, lstrError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001987}
1988
1989bool CParameterMgr::saveConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1990{
1991 // Check tuning mode
1992 if (!checkTuningModeOn(strError)) {
1993
1994 return false;
1995 }
1996
1997 // Delegate to configurable domains
1998 return getConfigurableDomains()->saveConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1999}
2000
2001// Configurable element - domain association
2002bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
2003{
2004 // Check tuning mode
2005 if (!checkTuningModeOn(strError)) {
2006
2007 return false;
2008 }
2009
2010 CElementLocator elementLocator(getSystemClass());
2011
2012 CElement* pLocatedElement = NULL;
2013
2014 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
2015
2016 return false;
2017 }
2018
2019 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04002020 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002021
2022 // Delegate
2023 return getConfigurableDomains()->addConfigurableElementToDomain(strDomain, pConfigurableElement, _pMainParameterBlackboard, strError);
2024}
2025
2026bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
2027{
2028 // Check tuning mode
2029 if (!checkTuningModeOn(strError)) {
2030
2031 return false;
2032 }
2033
2034 CElementLocator elementLocator(getSystemClass());
2035
2036 CElement* pLocatedElement = NULL;
2037
2038 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
2039
Patrick Benavoli63499d42011-10-24 18:50:03 +02002040 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002041 }
2042
2043 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04002044 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002045
2046 // Delegate
2047 return getConfigurableDomains()->removeConfigurableElementFromDomain(strDomain, pConfigurableElement, strError);
2048}
2049
2050bool CParameterMgr::split(const string& strDomain, const string& strConfigurableElementPath, string& strError)
2051{
2052 // Check tuning mode
2053 if (!checkTuningModeOn(strError)) {
2054
2055 return false;
2056 }
2057
2058 CElementLocator elementLocator(getSystemClass());
2059
2060 CElement* pLocatedElement = NULL;
2061
2062 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
2063
Patrick Benavoli63499d42011-10-24 18:50:03 +02002064 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002065 }
2066
2067 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04002068 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002069
2070 // Delegate
2071 return getConfigurableDomains()->split(strDomain, pConfigurableElement, strError);
2072}
2073
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002074bool CParameterMgr::importDomainsXml(const string& strXmlSource, bool bWithSettings,
2075 bool bFromFile, string& strError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02002076{
2077 // Check tuning mode
2078 if (!checkTuningModeOn(strError)) {
2079
2080 return false;
2081 }
2082
2083 // check path is absolute
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002084 if (bFromFile && strXmlSource[0] != '/') {
Patrick Benavoli68a91282011-08-31 11:23:23 +02002085
2086 strError = "Please provide absolute path";
2087
2088 return false;
2089 }
2090 // Root element
2091 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
2092
2093 // Context
David Wagnerd8a53102014-12-10 14:49:23 +01002094 CXmlDomainImportContext xmlDomainImportContext(strError, bWithSettings, *getSystemClass());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002095
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002096 // Selection criteria definition for rule creation
David Wagner29fa61f2014-12-19 11:15:02 +01002097 xmlDomainImportContext.setSelectionCriteriaDefinition(
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002098 getConstSelectionCriteria()->getSelectionCriteriaDefinition());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002099
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002100 // Init serializing context
David Wagner29fa61f2014-12-19 11:15:02 +01002101 xmlDomainImportContext.set(
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002102 _pElementLibrarySet->getElementLibrary(EParameterConfigurationLibrary),
2103 "", _strSchemaFolderLocation);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002104
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002105 // Get Schema file associated to root element
2106 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" +
2107 pConfigurableDomains->getKind() + ".xsd";
2108
2109 // Xml Source
2110 CXmlDocSource* pSource;
2111
2112 if (bFromFile) {
2113
2114 // when importing from a file strXmlSource is the file name
2115 pSource = new CXmlFileDocSource(strXmlSource, strXmlSchemaFilePath,
2116 pConfigurableDomains->getKind(),
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +02002117 pConfigurableDomains->getName(), "SystemClassName",
2118 _bValidateSchemasOnStart);
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002119
2120 } else {
2121
2122 // when importing from an xml string, strXmlSource contains the string
2123 pSource = new CXmlStringDocSource(strXmlSource, strXmlSchemaFilePath,
2124 pConfigurableDomains->getKind(),
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +02002125 pConfigurableDomains->getName(), "SystemClassName",
2126 _bValidateSchemasOnStart);
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002127
2128 }
2129 // Start clean
2130 pConfigurableDomains->clean();
2131
2132 // Use a doc sink that instantiate Configurable Domains from the given doc source
2133 CXmlMemoryDocSink memorySink(pConfigurableDomains);
2134
David Wagner29fa61f2014-12-19 11:15:02 +01002135 bool bProcessSuccess = memorySink.process(*pSource, xmlDomainImportContext);
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002136
2137 if (!bProcessSuccess) {
2138
2139 //Cleanup
2140 pConfigurableDomains->clean();
2141
2142 } else {
2143
2144 // Validate domains after XML import
2145 pConfigurableDomains->validate(_pMainParameterBlackboard);
2146
Patrick Benavoli68a91282011-08-31 11:23:23 +02002147 }
2148
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002149 delete pSource;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002150
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002151 return bProcessSuccess;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002152}
2153
David Wagnerfd211972014-12-10 15:01:22 +01002154bool CParameterMgr::importSingleDomainXml(const string& strXmlSource, bool bOverwrite,
2155 string& strError)
2156{
2157 if (!checkTuningModeOn(strError)) {
2158
2159 return false;
2160 }
2161
2162 // check path is absolute
2163 if (strXmlSource[0] != '/') {
2164
2165 strError = "Please provide absolute path";
2166
2167 return false;
2168 }
2169
2170 return importDomainFromFile(strXmlSource, bOverwrite, strError);
2171}
2172
David Wagnered744eb2014-12-04 18:38:52 +01002173bool CParameterMgr::serializeElement(string& strXmlDest,
2174 CXmlSerializingContext& xmlSerializingContext, bool bToFile,
2175 const CElement& element, string& strError) const
Patrick Benavoli68a91282011-08-31 11:23:23 +02002176{
2177 // check path is absolute
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002178 if (bToFile && strXmlDest[0] != '/') {
Patrick Benavoli68a91282011-08-31 11:23:23 +02002179
2180 strError = "Please provide absolute path";
2181
2182 return false;
2183 }
2184
Patrick Benavoli68a91282011-08-31 11:23:23 +02002185 // Get Schema file associated to root element
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002186 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" +
David Wagnered744eb2014-12-04 18:38:52 +01002187 element.getKind() + ".xsd";
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02002188
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002189 // Use a doc source by loading data from instantiated Configurable Domains
David Wagnered744eb2014-12-04 18:38:52 +01002190 CXmlMemoryDocSource memorySource(&element, element.getKind(),
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +02002191 strXmlSchemaFilePath, "parameter-framework",
2192 getVersion(), _bValidateSchemasOnStart);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002193
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002194 // Xml Sink
2195 CXmlDocSink* pSink;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002196
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002197 if (bToFile) {
2198
2199 // Use a doc sink to write the doc data in a file
2200 pSink = new CXmlFileDocSink(strXmlDest);
2201
2202 } else {
2203
2204 // Use a doc sink to write the doc data in a string
David Wagnered744eb2014-12-04 18:38:52 +01002205 // TODO: use a stream rather than a string
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002206 pSink = new CXmlStringDocSink(strXmlDest);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002207 }
2208
David Wagnered744eb2014-12-04 18:38:52 +01002209 bool bProcessSuccess = pSink->process(memorySource, xmlSerializingContext);
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002210
2211 delete pSink;
2212 return bProcessSuccess;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002213}
2214
David Wagnered744eb2014-12-04 18:38:52 +01002215bool CParameterMgr::exportDomainsXml(string& strXmlDest, bool bWithSettings, bool bToFile,
2216 string& strError) const
2217{
2218 const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains();
2219
2220 CXmlDomainExportContext xmlDomainExportContext(strError, bWithSettings);
2221
2222 xmlDomainExportContext.setValueSpaceRaw(_bValueSpaceIsRaw);
2223
2224 xmlDomainExportContext.setOutputRawFormat(_bOutputRawFormatIsHex);
2225
2226
2227 return serializeElement(strXmlDest, xmlDomainExportContext, bToFile,
2228 *pConfigurableDomains, strError);
2229}
2230
2231bool CParameterMgr::exportSingleDomainXml(string& strXmlDest, const string& strDomainName,
2232 bool bWithSettings, bool bToFile, string& strError) const
2233{
2234 const CConfigurableDomains* pAllDomains = getConstConfigurableDomains();
2235
2236 // Element to be serialized
2237 const CConfigurableDomain* pRequestedDomain =
2238 pAllDomains->findConfigurableDomain(strDomainName, strError);
2239
2240 if (!pRequestedDomain) {
2241 return false;
2242 }
2243
2244 CXmlDomainExportContext xmlDomainExportContext(strError, bWithSettings);
2245
2246 xmlDomainExportContext.setValueSpaceRaw(_bValueSpaceIsRaw);
2247
2248 xmlDomainExportContext.setOutputRawFormat(_bOutputRawFormatIsHex);
2249
2250 return serializeElement(strXmlDest, xmlDomainExportContext, bToFile,
2251 *pRequestedDomain, strError);
2252}
2253
Patrick Benavoli68a91282011-08-31 11:23:23 +02002254// Binary Import/Export
2255bool CParameterMgr::importDomainsBinary(const string& strFileName, string& strError)
2256{
2257 // Check tuning mode
2258 if (!checkTuningModeOn(strError)) {
2259
2260 return false;
2261 }
2262 // check path is absolute
2263 if (strFileName[0] != '/') {
2264
2265 strError = "Please provide absolute path";
2266
2267 return false;
2268 }
2269 // Root element
2270 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
2271
2272 // Serialize in
2273 return pConfigurableDomains->serializeSettings(strFileName, false, _uiStructureChecksum, strError);
2274}
2275
2276bool CParameterMgr::exportDomainsBinary(const string& strFileName, string& strError)
2277{
2278 // check path is absolute
2279 if (strFileName[0] != '/') {
2280
2281 strError = "Please provide absolute path";
2282
2283 return false;
2284 }
Patrick Benavoli68a91282011-08-31 11:23:23 +02002285
Patrick Benavoli68a91282011-08-31 11:23:23 +02002286 // Root element
2287 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
2288
2289 // Serialize out
2290 return pConfigurableDomains->serializeSettings(strFileName, true, _uiStructureChecksum, strError);
2291}
2292
2293// For tuning, check we're in tuning mode
2294bool CParameterMgr::checkTuningModeOn(string& strError) const
2295{
2296 // Tuning Mode on?
2297 if (!_bTuningModeIsOn) {
2298
2299 strError = "Tuning Mode must be on";
2300
2301 return false;
2302 }
2303 return true;
2304}
2305
Patrick Benavoli065264a2011-11-20 15:46:41 +01002306// Tuning mutex dynamic parameter handling
2307pthread_mutex_t* CParameterMgr::getBlackboardMutex()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002308{
Patrick Benavoli065264a2011-11-20 15:46:41 +01002309 return &_blackboardMutex;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002310}
2311
Patrick Benavoli065264a2011-11-20 15:46:41 +01002312// Blackboard reference (dynamic parameter handling)
2313CParameterBlackboard* CParameterMgr::getParameterBlackboard()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002314{
Patrick Benavoli065264a2011-11-20 15:46:41 +01002315 return _pMainParameterBlackboard;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002316}
2317
Patrick Benavoli68a91282011-08-31 11:23:23 +02002318// Dynamic creation library feeding
2319void CParameterMgr::feedElementLibraries()
2320{
2321 // Global Configuration handling
2322 CElementLibrary* pFrameworkConfigurationLibrary = new CElementLibrary;
2323
Kevin Rocarda7b69602013-08-07 16:15:33 +02002324 pFrameworkConfigurationLibrary->addElementBuilder("ParameterFrameworkConfiguration", new TElementBuilderTemplate<CParameterFrameworkConfiguration>());
2325 pFrameworkConfigurationLibrary->addElementBuilder("SubsystemPlugins", new TKindElementBuilderTemplate<CSubsystemPlugins>());
2326 pFrameworkConfigurationLibrary->addElementBuilder("Location", new TKindElementBuilderTemplate<CPluginLocation>());
2327 pFrameworkConfigurationLibrary->addElementBuilder("StructureDescriptionFileLocation", new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>());
2328 pFrameworkConfigurationLibrary->addElementBuilder("SettingsConfiguration", new TKindElementBuilderTemplate<CFrameworkConfigurationGroup>());
2329 pFrameworkConfigurationLibrary->addElementBuilder("ConfigurableDomainsFileLocation", new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>());
2330 pFrameworkConfigurationLibrary->addElementBuilder("BinarySettingsFileLocation", new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002331
2332 _pElementLibrarySet->addElementLibrary(pFrameworkConfigurationLibrary);
2333
2334 // Parameter creation
2335 CElementLibrary* pParameterCreationLibrary = new CElementLibrary;
2336
Kevin Rocarda7b69602013-08-07 16:15:33 +02002337 pParameterCreationLibrary->addElementBuilder("Subsystem", new CSubsystemElementBuilder(getSystemClass()->getSubsystemLibrary()));
2338 pParameterCreationLibrary->addElementBuilder("ComponentType", new TNamedElementBuilderTemplate<CComponentType>());
2339 pParameterCreationLibrary->addElementBuilder("Component", new TNamedElementBuilderTemplate<CComponentInstance>());
2340 pParameterCreationLibrary->addElementBuilder("BitParameter", new TNamedElementBuilderTemplate<CBitParameterType>());
2341 pParameterCreationLibrary->addElementBuilder("BitParameterBlock", new TNamedElementBuilderTemplate<CBitParameterBlockType>());
2342 pParameterCreationLibrary->addElementBuilder("StringParameter", new TNamedElementBuilderTemplate<CStringParameterType>());
2343 pParameterCreationLibrary->addElementBuilder("ParameterBlock", new TNamedElementBuilderTemplate<CParameterBlockType>());
2344 pParameterCreationLibrary->addElementBuilder("BooleanParameter", new TNamedElementBuilderTemplate<CBooleanParameterType>());
2345 pParameterCreationLibrary->addElementBuilder("IntegerParameter", new TNamedElementBuilderTemplate<CIntegerParameterType>());
2346 pParameterCreationLibrary->addElementBuilder("LinearAdaptation", new TElementBuilderTemplate<CLinearParameterAdaptation>());
2347 pParameterCreationLibrary->addElementBuilder("EnumParameter", new TNamedElementBuilderTemplate<CEnumParameterType>());
2348 pParameterCreationLibrary->addElementBuilder("ValuePair", new TElementBuilderTemplate<CEnumValuePair>());
2349 pParameterCreationLibrary->addElementBuilder("FixedPointParameter", new TNamedElementBuilderTemplate<CFixedPointParameterType>());
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +02002350 pParameterCreationLibrary->addElementBuilder("SubsystemInclude", new CFileIncluderElementBuilder(_bValidateSchemasOnStart));
Patrick Benavoli68a91282011-08-31 11:23:23 +02002351
2352 _pElementLibrarySet->addElementLibrary(pParameterCreationLibrary);
2353
2354 // Parameter Configuration Domains creation
2355 CElementLibrary* pParameterConfigurationLibrary = new CElementLibrary;
2356
David Wagnerfd211972014-12-10 15:01:22 +01002357 pParameterConfigurationLibrary->addElementBuilder("ConfigurableDomain", new TElementBuilderTemplate<CConfigurableDomain>());
Kevin Rocarda7b69602013-08-07 16:15:33 +02002358 pParameterConfigurationLibrary->addElementBuilder("Configuration", new TNamedElementBuilderTemplate<CDomainConfiguration>());
2359 pParameterConfigurationLibrary->addElementBuilder("CompoundRule", new TElementBuilderTemplate<CCompoundRule>());
2360 pParameterConfigurationLibrary->addElementBuilder("SelectionCriterionRule", new TElementBuilderTemplate<CSelectionCriterionRule>());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002361
2362 _pElementLibrarySet->addElementLibrary(pParameterConfigurationLibrary);
2363}
2364
2365// Remote Processor Server connection handling
2366bool CParameterMgr::handleRemoteProcessingInterface(string& strError)
2367{
2368 CAutoLog autoLog(this, "Handling remote processing interface");
2369
2370 // Start server if tuning allowed
Patrick Benavoli95ac0342011-11-07 20:32:51 +01002371 if (getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02002372
Kevin Rocardace81f82012-12-11 16:19:17 +01002373 log_info("Loading remote processor library");
Patrick Benavoli68a91282011-08-31 11:23:23 +02002374
2375 // Load library
Renaud de Chivre1b8b3ca2013-12-13 15:09:44 +01002376 _handleLibRemoteProcessor = dlopen("libremote-processor.so", RTLD_NOW);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002377
Renaud de Chivre1b8b3ca2013-12-13 15:09:44 +01002378 if (!_handleLibRemoteProcessor) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02002379
2380 // Return error
2381 const char* pcError = dlerror();
2382
2383 if (pcError) {
2384
2385 strError = pcError;
2386 } else {
2387
2388 strError = "Unable to load libremote-processor.so library";
2389 }
2390
2391 return false;
2392 }
2393
Renaud de Chivre1b8b3ca2013-12-13 15:09:44 +01002394 CreateRemoteProcessorServer pfnCreateRemoteProcessorServer = (CreateRemoteProcessorServer)dlsym(_handleLibRemoteProcessor, "createRemoteProcessorServer");
Patrick Benavoli68a91282011-08-31 11:23:23 +02002395
2396 if (!pfnCreateRemoteProcessorServer) {
2397
2398 strError = "libremote-process.so does not contain createRemoteProcessorServer symbol.";
2399
2400 return false;
2401 }
2402
2403 // Create server
Patrick Benavoli95ac0342011-11-07 20:32:51 +01002404 _pRemoteProcessorServer = pfnCreateRemoteProcessorServer(getConstFrameworkConfiguration()->getServerPort(), _pCommandHandler);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002405
Kevin Rocardace81f82012-12-11 16:19:17 +01002406 log_info("Starting remote processor server on port %d", getConstFrameworkConfiguration()->getServerPort());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002407 // Start
2408 if (!_pRemoteProcessorServer->start()) {
2409
Frédéric Boisnard6c55e9a2014-01-10 18:46:33 +01002410 ostringstream oss;
2411 oss << "ParameterMgr: Unable to start remote processor server on port "
2412 << getConstFrameworkConfiguration()->getServerPort();
2413 strError = oss.str();
Patrick Benavoli68a91282011-08-31 11:23:23 +02002414
2415 return false;
2416 }
2417 }
2418
2419 return true;
2420}
2421
2422// Back synchronization
Kevin Rocardace81f82012-12-11 16:19:17 +01002423CBackSynchronizer* CParameterMgr::createBackSynchronizer() const
Patrick Benavoli68a91282011-08-31 11:23:23 +02002424{
2425#ifdef SIMULATION
2426 // In simulation, back synchronization of the blackboard won't probably work
2427 // We need to ensure though the blackboard is initialized with valid data
Kevin Rocardace81f82012-12-11 16:19:17 +01002428 return new CSimulatedBackSynchronizer(getConstSystemClass(), _pMainParameterBlackboard);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002429#else
2430 // Real back synchronizer from subsystems
Kevin Rocardace81f82012-12-11 16:19:17 +01002431 return new CHardwareBackSynchronizer(getConstSystemClass(), _pMainParameterBlackboard);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002432#endif
2433}
2434
2435// Children typwise access
2436CParameterFrameworkConfiguration* CParameterMgr::getFrameworkConfiguration()
2437{
2438 return static_cast<CParameterFrameworkConfiguration*>(getChild(EFrameworkConfiguration));
2439}
2440
2441const CParameterFrameworkConfiguration* CParameterMgr::getConstFrameworkConfiguration()
2442{
2443 return getFrameworkConfiguration();
2444}
2445
2446CSelectionCriteria* CParameterMgr::getSelectionCriteria()
2447{
2448 return static_cast<CSelectionCriteria*>(getChild(ESelectionCriteria));
2449}
2450
2451const CSelectionCriteria* CParameterMgr::getConstSelectionCriteria()
2452{
2453 return static_cast<const CSelectionCriteria*>(getChild(ESelectionCriteria));
2454}
2455
2456CSystemClass* CParameterMgr::getSystemClass()
2457{
2458 return static_cast<CSystemClass*>(getChild(ESystemClass));
2459}
2460
2461const CSystemClass* CParameterMgr::getConstSystemClass() const
2462{
2463 return static_cast<const CSystemClass*>(getChild(ESystemClass));
2464}
2465
2466// Configurable Domains
2467CConfigurableDomains* CParameterMgr::getConfigurableDomains()
2468{
2469 return static_cast<CConfigurableDomains*>(getChild(EConfigurableDomains));
2470}
2471
2472const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains()
2473{
2474 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
2475}
2476
2477const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains() const
2478{
2479 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
2480}
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002481
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01002482// Apply configurations
2483void CParameterMgr::doApplyConfigurations(bool bForce)
2484{
2485 CSyncerSet syncerSet;
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002486
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01002487 // Check subsystems that need resync
2488 getSystemClass()->checkForSubsystemsToResync(syncerSet);
2489
2490 // Ensure application of currently selected configurations
2491 getConfigurableDomains()->apply(_pMainParameterBlackboard, syncerSet, bForce);
2492
2493 // Reset the modified status of the current criteria to indicate that a new configuration has been applied
2494 getSelectionCriteria()->resetModifiedStatus();
2495}
2496
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002497bool CParameterMgr::getSystemClassXMLString(string& strResult)
2498{
2499 // Root element
2500 const CSystemClass* pSystemClass = getSystemClass();
2501
2502 string strError;
2503
2504 CXmlSerializingContext xmlSerializingContext(strError);
2505
2506 // Use a doc source by loading data from instantiated Configurable Domains
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +02002507 CXmlMemoryDocSource memorySource(pSystemClass, pSystemClass->getKind(),
2508 _bValidateSchemasOnStart);
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002509
2510 // Use a doc sink that write the doc data in a string
2511 CXmlStringDocSink stringSink(strResult);
2512
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002513 bool bProcessSuccess = stringSink.process(memorySource, xmlSerializingContext);
2514
2515 if (!bProcessSuccess) {
2516
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002517 strResult = strError;
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002518
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002519 }
2520
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002521 return bProcessSuccess;
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002522}