blob: 32082b30250648756c8b8445614b0ee4ffb6bd21 [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"
63#include "BitParameterBlockType.h"
64#include "BitParameterType.h"
Patrick Benavoli1352ae52011-10-21 16:48:04 +020065#include "StringParameterType.h"
Patrick Benavoli9fc3c0d2011-10-27 14:27:27 +020066#include "EnumParameterType.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020067#include "RemoteProcessorServerInterface.h"
68#include "ElementLocator.h"
69#include "AutoLog.h"
70#include "CompoundRule.h"
71#include "SelectionCriterionRule.h"
72#include "SimulatedBackSynchronizer.h"
73#include "HardwareBackSynchronizer.h"
Patrick Benavoli1387bda2011-08-31 11:23:24 +020074#include "AutoLock.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020075#include <strings.h>
76#include <dlfcn.h>
77#include <assert.h>
Patrick Benavoli065264a2011-11-20 15:46:41 +010078#include "ParameterHandle.h"
Patrick Benavoliee65e6d2011-11-20 18:52:24 +010079#include "LinearParameterAdaptation.h"
Patrick Benavoli68808c62012-02-02 17:12:41 +010080#include "EnumValuePair.h"
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +020081#include "Subsystem.h"
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020082#include "XmlFileDocSink.h"
83#include "XmlFileDocSource.h"
84#include "XmlStringDocSink.h"
Georges-Henri Baroncec86c12012-09-04 17:30:28 +020085#include "XmlStringDocSource.h"
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020086#include "XmlMemoryDocSink.h"
87#include "XmlMemoryDocSource.h"
Kevin Rocardace81f82012-12-11 16:19:17 +010088#include "Utility.h"
Frédéric Boisnard6c55e9a2014-01-10 18:46:33 +010089#include <sstream>
Patrick Benavoli68a91282011-08-31 11:23:23 +020090
91#define base CElement
92
93// Used for remote processor server creation
94typedef IRemoteProcessorServerInterface* (*CreateRemoteProcessorServer)(uint16_t uiPort, IRemoteCommandHandler* pCommandHandler);
95
96// Global configuration file name (fixed)
97const char* gacParameterFrameworkConfigurationFileName = "ParameterFrameworkConfiguration.xml";
98const char* gacSystemSchemasSubFolder = "Schemas";
99
100// Config File System looks normally like this:
101// ---------------------------------------------
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100102//├── <ParameterFrameworkConfiguration>.xml
Patrick Benavoli68a91282011-08-31 11:23:23 +0200103//├── Schemas
104//│ └── *.xsd
105//├── Settings
106//│ └── <SystemClassName folder>*
107//│ ├── <ConfigurableDomains>.xml
108//│ └── <Settings>.bin?
109//└── Structure
110// └── <SystemClassName folder>*
111// ├── <SystemClassName>Class.xml
112// └── <Subsystem>.xml*
113// --------------------------------------------
114
115
116// Remote command parser array
Patrick Benavoli592ae562011-09-05 16:53:58 +0200117const CParameterMgr::SRemoteCommandParserItem CParameterMgr::gastRemoteCommandParserItems[] = {
Kevin Rocard3949b342013-05-24 18:43:53 +0200118
Patrick Benavoli592ae562011-09-05 16:53:58 +0200119 /// Version
Kevin Rocard3949b342013-05-24 18:43:53 +0200120 { "version", &CParameterMgr::versionCommandProcess, 0,
121 "", "Show version" },
122
Patrick Benavoli68a91282011-08-31 11:23:23 +0200123 /// Status
Kevin Rocard3949b342013-05-24 18:43:53 +0200124 { "status", &CParameterMgr::statusCommandProcess, 0, "",
125 "Show current status" },
126
Patrick Benavoli68a91282011-08-31 11:23:23 +0200127 /// Tuning Mode
Kevin Rocard3949b342013-05-24 18:43:53 +0200128 { "setTuningMode", &CParameterMgr::setTuningModeCommmandProcess, 1,
129 "on|off*", "Turn on or off Tuning Mode" },
130 { "getTuningMode", &CParameterMgr::getTuningModeCommmandProcess, 0,
131 "", "Show Tuning Mode" },
132
Patrick Benavoli68a91282011-08-31 11:23:23 +0200133 /// Value Space
Kevin Rocard3949b342013-05-24 18:43:53 +0200134 { "setValueSpace", &CParameterMgr::setValueSpaceCommmandProcess, 1,
135 "raw|real*", "Assigns Value Space used for parameter value interpretation" },
136 { "getValueSpace", &CParameterMgr::getValueSpaceCommmandProcess, 0,
137 "", "Show Value Space" },
138
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200139 /// Output Raw Format
Kevin Rocard3949b342013-05-24 18:43:53 +0200140 { "setOutputRawFormat", &CParameterMgr::setOutputRawFormatCommmandProcess, 1,
141 "dec*|hex", "Assigns format used to output parameter values when in raw Value Space" },
142 { "getOutputRawFormat", &CParameterMgr::getOutputRawFormatCommmandProcess, 0,
143 "", "Show Output Raw Format" },
144
Patrick Benavoli68a91282011-08-31 11:23:23 +0200145 /// Sync
Kevin Rocard3949b342013-05-24 18:43:53 +0200146 { "setAutoSync", &CParameterMgr::setAutoSyncCommmandProcess, 1,
147 "on*|off", "Turn on or off automatic synchronization to hardware while in Tuning Mode" },
148 { "getAutoSync", &CParameterMgr::getAutoSyncCommmandProcess, 0,
149 "", "Show Auto Sync state" },
150 { "sync", &CParameterMgr::syncCommmandProcess, 0,
151 "", "Synchronize current settings to hardware while in Tuning Mode and Auto Sync off" },
152
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200153 /// Criteria
Kevin Rocard3949b342013-05-24 18:43:53 +0200154 { "listCriteria", &CParameterMgr::listCriteriaCommmandProcess, 0,
155 "[csv]", "List selection criteria" },
156
Patrick Benavoli68a91282011-08-31 11:23:23 +0200157 /// Domains
Kevin Rocard3949b342013-05-24 18:43:53 +0200158 { "listDomains", &CParameterMgr::listDomainsCommmandProcess, 0,
159 "", "List configurable domains" },
160 { "dumpDomains", &CParameterMgr::dumpDomainsCommmandProcess, 0,
161 "", "Show all domains and configurations, including applicability conditions" },
162 { "createDomain", &CParameterMgr::createDomainCommmandProcess, 1,
163 "<domain>", "Create new configurable domain" },
164 { "deleteDomain", &CParameterMgr::deleteDomainCommmandProcess, 1,
165 "<domain>", "Delete configurable domain" },
166 { "deleteAllDomains", &CParameterMgr::deleteAllDomainsCommmandProcess, 0,
167 "", "Delete all configurable domains" },
168 { "renameDomain", &CParameterMgr::renameDomainCommmandProcess, 2,
169 "<domain> <new name>", "Rename configurable domain" },
170 { "setSequenceAwareness", &CParameterMgr::setSequenceAwarenessCommmandProcess, 1,
171 "<domain> true|false*", "Set configurable domain sequence awareness" },
172 { "getSequenceAwareness", &CParameterMgr::getSequenceAwarenessCommmandProcess, 1,
173 "<domain>", "Get configurable domain sequence awareness" },
174 { "listDomainElements", &CParameterMgr::listDomainElementsCommmandProcess, 1,
175 "<domain>", "List elements associated to configurable domain" },
176 { "addElement", &CParameterMgr::addElementCommmandProcess, 2,
177 "<domain> <elem path>", "Associate element at given path to configurable domain" },
178 { "removeElement", &CParameterMgr::removeElementCommmandProcess, 2,
179 "<domain> <elem path>", "Dissociate element at given path from configurable domain" },
180 { "splitDomain", &CParameterMgr::splitDomainCommmandProcess, 2,
181 "<domain> <elem path>", "Split configurable domain at given associated element path" },
182
Patrick Benavoli68a91282011-08-31 11:23:23 +0200183 /// Configurations
Kevin Rocard3949b342013-05-24 18:43:53 +0200184 { "listConfigurations", &CParameterMgr::listConfigurationsCommmandProcess, 1,
185 "<domain>", "List domain configurations" },
186 { "createConfiguration", &CParameterMgr::createConfigurationCommmandProcess, 2,
187 "<domain> <configuration>", "Create new domain configuration" },
188 { "deleteConfiguration", &CParameterMgr::deleteConfigurationCommmandProcess, 2,
189 "<domain> <configuration>", "Delete domain configuration" },
190 { "renameConfiguration", &CParameterMgr::renameConfigurationCommmandProcess, 3,
191 "<domain> <configuration> <new name>", "Rename domain configuration" },
192 { "saveConfiguration", &CParameterMgr::saveConfigurationCommmandProcess, 2,
193 "<domain> <configuration>", "Save current settings into configuration" },
194 { "restoreConfiguration", &CParameterMgr::restoreConfigurationCommmandProcess, 2,
195 "<domain> <configuration>", "Restore current settings from configuration" },
196 { "setElementSequence", &CParameterMgr::setElementSequenceCommmandProcess, 3,
197 "<domain> <configuration> <elem path list>",
198 "Set element application order for configuration" },
199 { "getElementSequence", &CParameterMgr::getElementSequenceCommmandProcess, 2,
200 "<domain> <configuration>", "Get element application order for configuration" },
201 { "setRule", &CParameterMgr::setRuleCommmandProcess, 3,
202 "<domain> <configuration> <rule>", "Set configuration application rule" },
203 { "clearRule", &CParameterMgr::clearRuleCommmandProcess, 2,
204 "<domain> <configuration>", "Clear configuration application rule" },
205 { "getRule", &CParameterMgr::getRuleCommmandProcess, 2,
206 "<domain> <configuration>", "Get configuration application rule" },
207
Patrick Benavoli68a91282011-08-31 11:23:23 +0200208 /// Elements/Parameters
Kevin Rocard3949b342013-05-24 18:43:53 +0200209 { "listElements", &CParameterMgr::listElementsCommmandProcess, 1,
210 "<elem path>|/", "List elements under element at given path or root" },
211 { "listParameters", &CParameterMgr::listParametersCommmandProcess, 1,
212 "<elem path>|/", "List parameters under element at given path or root" },
213 { "dumpElement", &CParameterMgr::dumpElementCommmandProcess, 1,
214 "<elem path>", "Dump structure and content of element at given path" },
215 { "getElementSize", &CParameterMgr::getElementSizeCommmandProcess, 1,
216 "<elem path>", "Show size of element at given path" },
217 { "showProperties", &CParameterMgr::showPropertiesCommmandProcess, 1,
218 "<elem path>", "Show properties of element at given path" },
219 { "getParameter", &CParameterMgr::getParameterCommmandProcess, 1,
220 "<param path>", "Get value for parameter at given path" },
221 { "setParameter", &CParameterMgr::setParameterCommmandProcess, 2,
222 "<param path> <value>", "Set value for parameter at given path" },
223 { "listBelongingDomains", &CParameterMgr::listBelongingDomainsCommmandProcess, 1,
224 "<elem path>", "List domain(s) element at given path belongs to" },
225 { "listAssociatedDomains", &CParameterMgr::listAssociatedDomainsCommmandProcess, 1,
226 "<elem path>", "List domain(s) element at given path is associated to" },
227 { "getConfigurationParameter", &CParameterMgr::getConfigurationParameterCommmandProcess, 3,
228 "<domain> <configuration> <param path>",
229 "Get value for parameter at given path from configuration" },
230 { "setConfigurationParameter", &CParameterMgr::setConfigurationParameterCommmandProcess, 4,
231 "<domain> <configuration> <param path> <value>",
232 "Set value for parameter at given path to configuration" },
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200233 { "showMapping", &CParameterMgr::showMappingCommmandProcess, 1,
234 "<elem path>", "Show mapping for an element at given path" },
Kevin Rocard3949b342013-05-24 18:43:53 +0200235
Patrick Benavoli68a91282011-08-31 11:23:23 +0200236 /// Browse
Kevin Rocard3949b342013-05-24 18:43:53 +0200237 { "listAssociatedElements", &CParameterMgr::listAssociatedElementsCommmandProcess, 0,
238 "", "List element sub-trees associated to at least one configurable domain" },
239 { "listConflictingElements", &CParameterMgr::listConflictingElementsCommmandProcess, 0,
240 "", "List element sub-trees contained in more than one configurable domain" },
241 { "listRogueElements", &CParameterMgr::listRogueElementsCommmandProcess, 0,
242 "", "List element sub-trees owned by no configurable domain" },
243
Patrick Benavoli68a91282011-08-31 11:23:23 +0200244 /// Settings Import/Export
Kevin Rocard3949b342013-05-24 18:43:53 +0200245 { "exportDomainsXML", &CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess, 1,
246 "<file path> ", "Export domains to XML file" },
247 { "importDomainsXML", &CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess, 1,
248 "<file path>", "Import domains from XML file" },
249 { "exportDomainsWithSettingsXML",
250 &CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess, 1,
251 "<file path> ", "Export domains including settings to XML file" },
252 { "importDomainsWithSettingsXML",
253 &CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess, 1,
254 "<file path>", "Import domains including settings from XML file" },
255 { "exportSettings", &CParameterMgr::exportSettingsCommmandProcess, 1,
256 "<file path>", "Export settings to binary file" },
257 { "importSettings", &CParameterMgr::importSettingsCommmandProcess, 1,
258 "<file path>", "Import settings from binary file" },
Georges-Henri Baroncec86c12012-09-04 17:30:28 +0200259 { "getDomainsWithSettingsXML",
260 &CParameterMgr::getConfigurableDomainsWithSettingsXMLCommmandProcess, 0,
Kevin Rocard3949b342013-05-24 18:43:53 +0200261 "", "Print domains including settings as XML" },
Georges-Henri Baroncec86c12012-09-04 17:30:28 +0200262 { "setDomainsWithSettingsXML",
263 &CParameterMgr::setConfigurableDomainsWithSettingsXMLCommmandProcess, 1,
264 "<xml configurable domains>", "Import domains including settings from XML string" },
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200265 /// Structure Export
Kevin Rocard3949b342013-05-24 18:43:53 +0200266 { "getSystemClassXML", &CParameterMgr::getSystemClassXMLCommmandProcess, 0 ,
Kevin Rocardc0211572013-06-18 11:34:53 +0200267 "", "Print parameter structure as XML" },
268 /// Deprecated Commands
269 { "getDomainsXML",
270 &CParameterMgr::getConfigurableDomainsWithSettingsXMLCommmandProcess, 0,
271 "", "DEPRECATED COMMAND, please use getDomainsWithSettingsXML" },
Georges-Henri Baroncec86c12012-09-04 17:30:28 +0200272
Patrick Benavoli68a91282011-08-31 11:23:23 +0200273};
Kevin Rocard3949b342013-05-24 18:43:53 +0200274
Patrick Benavoli68a91282011-08-31 11:23:23 +0200275// Remote command parsers array Size
Patrick Benavoli592ae562011-09-05 16:53:58 +0200276const uint32_t CParameterMgr::guiNbRemoteCommandParserItems = sizeof(gastRemoteCommandParserItems) / sizeof(gastRemoteCommandParserItems[0]);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200277
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100278CParameterMgr::CParameterMgr(const string& strConfigurationFilePath) :
Patrick Benavoli68a91282011-08-31 11:23:23 +0200279 _bTuningModeIsOn(false),
280 _bValueSpaceIsRaw(false),
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200281 _bOutputRawFormatIsHex(false),
Patrick Benavoli68a91282011-08-31 11:23:23 +0200282 _bAutoSyncOn(true),
283 _pMainParameterBlackboard(new CParameterBlackboard),
284 _pElementLibrarySet(new CElementLibrarySet),
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100285 _strXmlConfigurationFilePath(strConfigurationFilePath),
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100286 _pSubsystemPlugins(NULL),
Renaud de Chivre1b8b3ca2013-12-13 15:09:44 +0100287 _handleLibRemoteProcessor(NULL),
Patrick Benavoli68a91282011-08-31 11:23:23 +0200288 _uiStructureChecksum(0),
289 _pRemoteProcessorServer(NULL),
290 _uiMaxCommandUsageLength(0),
291 _pLogger(NULL),
Kevin Rocardecf93102013-07-10 18:28:10 +0200292 _uiLogDepth(0),
Kevin Rocardd6909eb2013-07-18 09:13:51 +0200293 _bFailOnMissingSubsystem(true),
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +0200294 _bFailOnFailedSettingsLoad(true),
295 _bValidateSchemasOnStart(false)
296
Patrick Benavoli68a91282011-08-31 11:23:23 +0200297{
298 // Tuning Mode Mutex
Patrick Benavoli065264a2011-11-20 15:46:41 +0100299 bzero(&_blackboardMutex, sizeof(_blackboardMutex));
300 pthread_mutex_init(&_blackboardMutex, NULL);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200301
302 // Deal with children
303 addChild(new CParameterFrameworkConfiguration);
304 addChild(new CSelectionCriteria);
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100305 addChild(new CSystemClass);
306 addChild(new CConfigurableDomains);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200307
Patrick Benavoli63499d42011-10-24 18:50:03 +0200308 _pCommandHandler = new CCommandHandler(this);
309
310 // Add command parsers
311 uint32_t uiRemoteCommandParserItem;
312
313 for (uiRemoteCommandParserItem = 0; uiRemoteCommandParserItem < guiNbRemoteCommandParserItems; uiRemoteCommandParserItem++) {
314
315 const SRemoteCommandParserItem* pRemoteCommandParserItem = &gastRemoteCommandParserItems[uiRemoteCommandParserItem];
316
317 _pCommandHandler->addCommandParser(pRemoteCommandParserItem->_pcCommandName,
318 pRemoteCommandParserItem->_pfnParser,
319 pRemoteCommandParserItem->_uiMinArgumentCount,
320 pRemoteCommandParserItem->_pcHelp,
321 pRemoteCommandParserItem->_pcDescription);
322 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100323
324 // Configuration file folder
325 uint32_t uiSlashPos = _strXmlConfigurationFilePath.rfind('/', -1);
326
327 assert(uiSlashPos != (uint32_t)-1);
328
329 _strXmlConfigurationFolderPath = _strXmlConfigurationFilePath.substr(0, uiSlashPos);
330
331 // Schema absolute folder location
332 _strSchemaFolderLocation = _strXmlConfigurationFolderPath + "/" + gacSystemSchemasSubFolder;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200333}
334
335CParameterMgr::~CParameterMgr()
336{
337 // Children
338 delete _pRemoteProcessorServer;
Frederic Boisnard31242302012-04-26 17:07:34 +0200339 delete _pCommandHandler;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200340 delete _pMainParameterBlackboard;
341 delete _pElementLibrarySet;
342
Renaud de Chivre1b8b3ca2013-12-13 15:09:44 +0100343 // Close remote processor library
344 if (_handleLibRemoteProcessor != NULL) {
345 dlclose(_handleLibRemoteProcessor);
346 }
347
Patrick Benavoli68a91282011-08-31 11:23:23 +0200348 // Tuning Mode Mutex
Patrick Benavoli065264a2011-11-20 15:46:41 +0100349 pthread_mutex_destroy(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200350}
351
352string CParameterMgr::getKind() const
353{
354 return "ParameterMgr";
355}
356
357// Logging
358void CParameterMgr::setLogger(CParameterMgr::ILogger* pLogger)
359{
360 _pLogger = pLogger;
361}
362
363// Logging
Kevin Rocardace81f82012-12-11 16:19:17 +0100364void CParameterMgr::doLog(bool bIsWarning, const string& strLog) const
Patrick Benavoli68a91282011-08-31 11:23:23 +0200365{
366 if (_pLogger) {
367
368 // Nest
369 string strIndent;
370
371 // Level
372 uint32_t uiNbIndents = _uiLogDepth;
373
374 while (uiNbIndents--) {
375
376 strIndent += " ";
377 }
378
379 // Log
Kevin Rocardace81f82012-12-11 16:19:17 +0100380 _pLogger->log(bIsWarning, strIndent + strLog);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200381 }
382}
383
384void CParameterMgr::nestLog() const
385{
Patrick Benavoli592ae562011-09-05 16:53:58 +0200386 _uiLogDepth++;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200387}
388
389void CParameterMgr::unnestLog() const
390{
Patrick Benavoli592ae562011-09-05 16:53:58 +0200391 _uiLogDepth--;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200392}
393
Patrick Benavoli63499d42011-10-24 18:50:03 +0200394// Version
395string CParameterMgr::getVersion() const
396{
397 string strVersion;
398
399 // Major
400 strVersion = toString(guiEditionMajor) + ".";
401 // Minor
402 strVersion += toString(guiEditionMinor) + ".";
403 // Revision
404 strVersion += toString(guiRevision);
405
406 return strVersion;
407}
408
Patrick Benavoli68a91282011-08-31 11:23:23 +0200409bool CParameterMgr::load(string& strError)
410{
411 CAutoLog autoLog(this, "Loading");
412
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +0200413 feedElementLibraries();
414
Patrick Benavoli68a91282011-08-31 11:23:23 +0200415 // Load Framework configuration
416 if (!loadFrameworkConfiguration(strError)) {
417
418 return false;
419 }
420
421 // Load subsystems
Kevin Rocardecf93102013-07-10 18:28:10 +0200422 if (!getSystemClass()->loadSubsystems(strError,
423 _pSubsystemPlugins, !_bFailOnMissingSubsystem)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200424
425 return false;
426 }
427
428 // Load structure
429 if (!loadStructure(strError)) {
430
431 return false;
432 }
433
434 // Load settings
435 if (!loadSettings(strError)) {
436
437 return false;
438 }
439
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200440 // Back synchronization for areas in parameter blackboard not covered by any domain
Kevin Rocardace81f82012-12-11 16:19:17 +0100441 CBackSynchronizer* pBackSynchronizer = createBackSynchronizer();
Patrick Benavoli68a91282011-08-31 11:23:23 +0200442
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200443 // Back-synchronize
Kevin Rocard57096bd2012-11-30 11:24:20 +0100444 {
445 CAutoLog autoLog(this, "Main blackboard back synchronization");
446
Kevin Rocard5d6e05a2013-01-21 15:57:45 +0100447 pBackSynchronizer->sync();
Kevin Rocard57096bd2012-11-30 11:24:20 +0100448
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200449 // Get rid of back synchronizer
450 delete pBackSynchronizer;
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200451 }
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200452
453 // We're done loading the settings and back synchronizing
454 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
455
456 // We need to ensure all domains are valid
457 pConfigurableDomains->validate(_pMainParameterBlackboard);
458
Kevin Rocard7f265822012-12-07 18:51:22 +0100459 // Log selection criterion states
460 {
461 CAutoLog autoLog(this, "Criterion states");
462
463 const CSelectionCriteria* selectionCriteria = getConstSelectionCriteria();
464
465 list<string> lstrSelectionCriteron;
466 selectionCriteria->listSelectionCriteria(lstrSelectionCriteron, true, false);
467
Kevin Rocard36299362013-02-04 14:57:47 +0100468 log_table(false, lstrSelectionCriteron);
Kevin Rocard7f265822012-12-07 18:51:22 +0100469 }
470
Kevin Rocard2fbe6e82013-03-26 17:09:29 +0100471 // Subsystem can not ask for resync as they have not been synced yet
472 getSystemClass()->cleanSubsystemsNeedToResync();
473
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100474 // At initialization, check subsystems that need resync
475 doApplyConfigurations(true);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200476
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200477 // Start remote processor server if appropriate
478 return handleRemoteProcessingInterface(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200479}
480
481bool CParameterMgr::loadFrameworkConfiguration(string& strError)
482{
483 CAutoLog autoLog(this, "Loading framework configuration");
484
Patrick Benavoli68a91282011-08-31 11:23:23 +0200485 // Parse Structure XML file
486 CXmlElementSerializingContext elementSerializingContext(strError);
487
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100488 if (!xmlParse(elementSerializingContext, getFrameworkConfiguration(), _strXmlConfigurationFilePath, _strXmlConfigurationFolderPath, EFrameworkConfigurationLibrary)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200489
490 return false;
491 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100492 // Set class name to system class and configurable domains
493 getSystemClass()->setName(getConstFrameworkConfiguration()->getSystemClassName());
494 getConfigurableDomains()->setName(getConstFrameworkConfiguration()->getSystemClassName());
495
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100496 // Get subsystem plugins elements
497 _pSubsystemPlugins = static_cast<const CSubsystemPlugins*>(getConstFrameworkConfiguration()->findChild("SubsystemPlugins"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200498
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100499 if (!_pSubsystemPlugins) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200500
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100501 strError = "Parameter Framework Configuration: couldn't find SubsystemPlugins element";
Patrick Benavoli68a91282011-08-31 11:23:23 +0200502
503 return false;
504 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200505
Patrick Benavoli68a91282011-08-31 11:23:23 +0200506 // Log tuning availability
Kevin Rocardace81f82012-12-11 16:19:17 +0100507 log_info("Tuning %s", getConstFrameworkConfiguration()->isTuningAllowed() ? "allowed" : "prohibited");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200508
509 return true;
510}
511
512bool CParameterMgr::loadStructure(string& strError)
513{
514 // Retrieve system to load structure to
515 CSystemClass* pSystemClass = getSystemClass();
516
Kevin Rocarde25ee792013-04-22 17:46:28 +0200517 log_info("Loading " + pSystemClass->getName() + " system class structure");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200518
519 // Get structure description element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100520 const CFrameworkConfigurationLocation* pStructureDescriptionFileLocation = static_cast<const CFrameworkConfigurationLocation*>(getConstFrameworkConfiguration()->findChildOfKind("StructureDescriptionFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200521
522 if (!pStructureDescriptionFileLocation) {
523
524 strError = "No StructureDescriptionFileLocation element found for SystemClass " + pSystemClass->getName();
525
526 return false;
527 }
528
529 // Get Xml structure folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100530 string strXmlStructureFolder = pStructureDescriptionFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200531
532 // Get Xml structure file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100533 string strXmlStructureFilePath = pStructureDescriptionFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200534
535 // Parse Structure XML file
536 CXmlParameterSerializingContext parameterBuildContext(strError);
537
Kevin Rocard57096bd2012-11-30 11:24:20 +0100538 CAutoLog autolog(pSystemClass, "Importing system structure from file " + strXmlStructureFilePath);
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200539
Patrick Benavoli68a91282011-08-31 11:23:23 +0200540 if (!xmlParse(parameterBuildContext, pSystemClass, strXmlStructureFilePath, strXmlStructureFolder, EParameterCreationLibrary)) {
541
542 return false;
543 }
544
545 // Initialize offsets
546 pSystemClass->setOffset(0);
547
548 // Initialize main blackboard's size
549 _pMainParameterBlackboard->setSize(pSystemClass->getFootPrint());
550
551 return true;
552}
553
554bool CParameterMgr::loadSettings(string& strError)
555{
Kevin Rocardd6909eb2013-07-18 09:13:51 +0200556 string strLoadError;
557 bool success = loadSettingsFromConfigFile(strLoadError);
558
559 if (!success && !_bFailOnFailedSettingsLoad) {
560 // Load can not fail, ie continue but log the load errors
561 log_info(strLoadError);
562 log_info("Failed to load settings, continue without domains.");
563 success = true;
564 }
565
566 if (!success) {
567 // Propagate the litteral error only if the function fails
568 strError = strLoadError;
569 return false;
570 }
571
572 return true;
573}
574
575bool CParameterMgr::loadSettingsFromConfigFile(string& strError)
576{
Patrick Benavoli68a91282011-08-31 11:23:23 +0200577 CAutoLog autoLog(this, "Loading settings");
578
579 // Get settings configuration element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100580 const CFrameworkConfigurationGroup* pParameterConfigurationGroup = static_cast<const CFrameworkConfigurationGroup*>(getConstFrameworkConfiguration()->findChildOfKind("SettingsConfiguration"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200581
582 if (!pParameterConfigurationGroup) {
583
584 // No settings to load
585
586 return true;
587 }
588 // Get binary settings file location
589 const CFrameworkConfigurationLocation* pBinarySettingsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("BinarySettingsFileLocation"));
590
591 string strXmlBinarySettingsFilePath;
592
593 if (pBinarySettingsFileLocation) {
594
595 // Get Xml binary settings file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100596 strXmlBinarySettingsFilePath = pBinarySettingsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200597 }
598
599 // Get configurable domains element
600 const CFrameworkConfigurationLocation* pConfigurableDomainsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("ConfigurableDomainsFileLocation"));
601
602 if (!pConfigurableDomainsFileLocation) {
603
604 strError = "No ConfigurableDomainsFileLocation element found for SystemClass " + getSystemClass()->getName();
605
606 return false;
Kevin Rocardd6909eb2013-07-18 09:13:51 +0200607 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200608 // Get destination root element
609 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
610
611 // Get Xml configuration domains file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100612 string strXmlConfigurationDomainsFilePath = pConfigurableDomainsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200613
614 // Get Xml configuration domains folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100615 string strXmlConfigurationDomainsFolder = pConfigurableDomainsFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200616
617 // Parse configuration domains XML file (ask to read settings from XML file if they are not provided as binary)
618 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, !pBinarySettingsFileLocation);
619
620 // Selection criteria definition for rule creation
621 xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
622
Patrick Benavoli63499d42011-10-24 18:50:03 +0200623 // Auto validation of configurations if no binary settings provided
624 xmlDomainSerializingContext.setAutoValidationRequired(!pBinarySettingsFileLocation);
625
Kevin Rocardace81f82012-12-11 16:19:17 +0100626 log_info("Importing configurable domains from file %s %s settings", strXmlConfigurationDomainsFilePath.c_str(), pBinarySettingsFileLocation ? "without" : "with");
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200627
Patrick Benavoli68a91282011-08-31 11:23:23 +0200628 // Do parse
629 if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strXmlConfigurationDomainsFilePath, strXmlConfigurationDomainsFolder, EParameterConfigurationLibrary, "SystemClassName")) {
630
631 return false;
632 }
633 // We have loaded the whole system structure, compute checksum
634 const CSystemClass* pSystemClass = getConstSystemClass();
635 _uiStructureChecksum = pSystemClass->computeStructureChecksum() + getConfigurableDomains()->computeStructureChecksum() + getSelectionCriteria()->computeStructureChecksum();
636
637 // Load binary settings if any provided
638 if (pBinarySettingsFileLocation && !pConfigurableDomains->serializeSettings(strXmlBinarySettingsFilePath, false, _uiStructureChecksum, strError)) {
639
640 return false;
641 }
642
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200643 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200644}
645
646// XML parsing
647bool CParameterMgr::xmlParse(CXmlElementSerializingContext& elementSerializingContext, CElement* pRootElement, const string& strXmlFilePath, const string& strXmlFolder, CParameterMgr::ElementLibrary eElementLibrary, const string& strNameAttrituteName)
648{
649 // Init serializing context
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +0200650 elementSerializingContext.set(_pElementLibrarySet->getElementLibrary(
651 eElementLibrary), strXmlFolder, _strSchemaFolderLocation);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200652
653 // Get Schema file associated to root element
654 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pRootElement->getKind() + ".xsd";
655
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +0200656 CXmlFileDocSource fileDocSource(strXmlFilePath, strXmlSchemaFilePath,
657 pRootElement->getKind(),
658 pRootElement->getName(), strNameAttrituteName,
659 _bValidateSchemasOnStart);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200660
661 // Start clean
662 pRootElement->clean();
663
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200664 CXmlMemoryDocSink memorySink(pRootElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200665
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200666 if (!memorySink.process(fileDocSource, elementSerializingContext)) {
667 //Cleanup
Patrick Benavoli68a91282011-08-31 11:23:23 +0200668 pRootElement->clean();
669
670 return false;
671 }
672
Patrick Benavoli68a91282011-08-31 11:23:23 +0200673 return true;
674}
675
676// Init
677bool CParameterMgr::init(string& strError)
678{
679 return base::init(strError);
680}
681
682// Selection criteria interface
683CSelectionCriterionType* CParameterMgr::createSelectionCriterionType(bool bIsInclusive)
684{
685 // Propagate
686 return getSelectionCriteria()->createSelectionCriterionType(bIsInclusive);
687}
688
689CSelectionCriterion* CParameterMgr::createSelectionCriterion(const string& strName, const CSelectionCriterionType* pSelectionCriterionType)
690{
691 // Propagate
692 return getSelectionCriteria()->createSelectionCriterion(strName, pSelectionCriterionType);
693}
694
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200695// Selection criterion retrieval
696CSelectionCriterion* CParameterMgr::getSelectionCriterion(const string& strName)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200697{
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200698 // Propagate
699 return getSelectionCriteria()->getSelectionCriterion(strName);
700}
701
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100702// Configuration application
Kevin Rocardace81f82012-12-11 16:19:17 +0100703void CParameterMgr::applyConfigurations()
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200704{
705 CAutoLog autoLog(this, "Configuration application request");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200706
707 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +0100708 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200709
710 if (!_bTuningModeIsOn) {
711
712 // Apply configuration(s)
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100713 doApplyConfigurations(false);
Frédéric Boisnarddaaa63c2012-08-27 15:48:15 +0200714 } else {
715
Kevin Rocardace81f82012-12-11 16:19:17 +0100716 log_warning("Configurations were not applied because the TuningMode is on");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200717 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200718}
719
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200720// Get the configurableElement corresponding to the given path
721const CConfigurableElement* CParameterMgr::getConfigurableElement(const string& strPath,
722 string& strError) const
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200723{
Patrick Benavoli065264a2011-11-20 15:46:41 +0100724 CPathNavigator pathNavigator(strPath);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200725
Patrick Benavoli065264a2011-11-20 15:46:41 +0100726 // Nagivate through system class
727 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
728
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100729 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100730 }
731
732 // Find element
733 const CElement* pElement = getConstSystemClass()->findDescendant(pathNavigator);
734
735 if (!pElement) {
736
Kevin Rocard4c3f8d82013-11-21 12:16:28 +0100737 strError = "Path not found: " + strPath;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100738
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100739 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100740 }
741
742 // Check found element is a parameter
743 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pElement);
744
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200745 return pConfigurableElement;
746}
747
748// Dynamic parameter handling
749CParameterHandle* CParameterMgr::createParameterHandle(const string& strPath, string& strError)
750{
751 const CConfigurableElement* pConfigurableElement = getConfigurableElement(strPath, strError);
752
753 if (!pConfigurableElement) {
754
755 // Element not found
Kevin Rocard4c3f8d82013-11-21 12:16:28 +0100756 strError = "Element not found: " + strPath;
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200757 return NULL;
758 }
759
Patrick Benavoli065264a2011-11-20 15:46:41 +0100760 if (!pConfigurableElement->isParameter()) {
761
762 // Element is not parameter
Kevin Rocard4c3f8d82013-11-21 12:16:28 +0100763 strError = "Not a parameter: " + strPath;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100764
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100765 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100766 }
767
768 // Convert as parameter and return new handle
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200769 return new CParameterHandle(static_cast<const CBaseParameter*>(pConfigurableElement), this);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200770}
771
Kevin Rocardecf93102013-07-10 18:28:10 +0200772void CParameterMgr::setFailureOnMissingSubsystem(bool bFail)
773{
774 _bFailOnMissingSubsystem = bFail;
775}
776
777bool CParameterMgr::getFailureOnMissingSubsystem() const
778{
779 return _bFailOnMissingSubsystem;
780}
Kevin Rocardd6909eb2013-07-18 09:13:51 +0200781
782void CParameterMgr::setFailureOnFailedSettingsLoad(bool bFail)
783{
784 _bFailOnFailedSettingsLoad = bFail;
785}
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +0200786
Kevin Rocardd6909eb2013-07-18 09:13:51 +0200787bool CParameterMgr::getFailureOnFailedSettingsLoad()
788{
789 return _bFailOnFailedSettingsLoad;
790}
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +0200791
792void CParameterMgr::setValidateSchemasOnStart(bool bValidate)
793{
794 _bValidateSchemasOnStart = bValidate;
795}
796
797bool CParameterMgr::getValidateSchemasOnStart() const
798{
799 return _bValidateSchemasOnStart;
800}
801
Patrick Benavoli68a91282011-08-31 11:23:23 +0200802/////////////////// Remote command parsers
Patrick Benavoli592ae562011-09-05 16:53:58 +0200803/// Version
Patrick Benavoli63499d42011-10-24 18:50:03 +0200804CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::versionCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli592ae562011-09-05 16:53:58 +0200805{
806 (void)remoteCommand;
807
Patrick Benavoli63499d42011-10-24 18:50:03 +0200808 // Show version
809 strResult = getVersion();
Patrick Benavoli592ae562011-09-05 16:53:58 +0200810
Patrick Benavoli63499d42011-10-24 18:50:03 +0200811 return CCommandHandler::ESucceeded;
Patrick Benavoli592ae562011-09-05 16:53:58 +0200812}
813
Patrick Benavoli68a91282011-08-31 11:23:23 +0200814/// Status
Patrick Benavoli63499d42011-10-24 18:50:03 +0200815CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::statusCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200816{
817 (void)remoteCommand;
818 // System class
819 const CSystemClass* pSystemClass = getSystemClass();
820
Patrick Benavoli68a91282011-08-31 11:23:23 +0200821 // Show status
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200822 /// General section
823 appendTitle(strResult, "General:");
824 // System class
Patrick Benavoli68a91282011-08-31 11:23:23 +0200825 strResult += "System Class: ";
826 strResult += pSystemClass->getName();
827 strResult += "\n";
828
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200829 // Tuning mode
Patrick Benavoli68a91282011-08-31 11:23:23 +0200830 strResult += "Tuning Mode: ";
831 strResult += tuningModeOn() ? "on" : "off";
832 strResult += "\n";
833
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200834 // Value space
Patrick Benavoli68a91282011-08-31 11:23:23 +0200835 strResult += "Value Space: ";
836 strResult += valueSpaceIsRaw() ? "raw" : "real";
837 strResult += "\n";
838
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200839 // Output raw format
840 strResult += "Output Raw Format: ";
841 strResult += outputRawFormatIsHex() ? "hex" : "dec";
842 strResult += "\n";
843
844 // Auto Sync
Patrick Benavoli68a91282011-08-31 11:23:23 +0200845 strResult += "Auto Sync: ";
846 strResult += autoSyncOn() ? "on" : "off";
847 strResult += "\n";
848
849 /// Subsystem list
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200850 appendTitle(strResult, "Subsystems:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200851 string strSubsystemList;
852 pSystemClass->listChildrenPaths(strSubsystemList);
853 strResult += strSubsystemList;
854
855 /// Last applied configurations
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200856 appendTitle(strResult, "Last Applied [Pending] Configurations:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200857 string strLastAppliedConfigurations;
858 getConfigurableDomains()->listLastAppliedConfigurations(strLastAppliedConfigurations);
859 strResult += strLastAppliedConfigurations;
860
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200861 /// Criteria states
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200862 appendTitle(strResult, "Selection Criteria:");
Kevin Rocard7f265822012-12-07 18:51:22 +0100863 list<string> lstrSelectionCriteria;
864 getSelectionCriteria()->listSelectionCriteria(lstrSelectionCriteria, false, true);
865 // Concatenate the criterion list as the command result
Frederic Boisnard390b36d2013-05-23 15:28:31 +0200866 string strCriteriaStates;
867 CUtility::asString(lstrSelectionCriteria, strCriteriaStates);
868 strResult += strCriteriaStates;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200869
Patrick Benavoli63499d42011-10-24 18:50:03 +0200870 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200871}
872
873/// Tuning Mode
Patrick Benavoli63499d42011-10-24 18:50:03 +0200874CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200875{
876 if (remoteCommand.getArgument(0) == "on") {
877
878 if (setTuningMode(true, strResult)) {
879
Patrick Benavoli63499d42011-10-24 18:50:03 +0200880 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200881 }
882 } else if (remoteCommand.getArgument(0) == "off") {
883
884 if (setTuningMode(false, strResult)) {
885
Patrick Benavoli63499d42011-10-24 18:50:03 +0200886 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200887 }
888 } else {
889 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200890 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200891 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200892 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200893}
894
Patrick Benavoli63499d42011-10-24 18:50:03 +0200895CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200896{
897 (void)remoteCommand;
898
899 strResult = tuningModeOn() ? "on" : "off";
900
Patrick Benavoli63499d42011-10-24 18:50:03 +0200901 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200902}
903
904/// Value Space
Patrick Benavoli63499d42011-10-24 18:50:03 +0200905CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200906{
907 (void)strResult;
908
909 if (remoteCommand.getArgument(0) == "raw") {
910
911 setValueSpace(true);
912
Patrick Benavoli63499d42011-10-24 18:50:03 +0200913 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200914
915 } else if (remoteCommand.getArgument(0) == "real") {
916
917 setValueSpace(false);
918
Patrick Benavoli63499d42011-10-24 18:50:03 +0200919 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200920
921 } else {
922 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200923 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200924 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200925 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200926}
927
Patrick Benavoli63499d42011-10-24 18:50:03 +0200928CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200929{
930 (void)remoteCommand;
931
932 strResult = valueSpaceIsRaw() ? "raw" : "real";
933
Patrick Benavoli63499d42011-10-24 18:50:03 +0200934 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200935}
936
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200937/// Output Raw Format
Patrick Benavoli63499d42011-10-24 18:50:03 +0200938CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200939{
940 (void)strResult;
941
942 if (remoteCommand.getArgument(0) == "hex") {
943
944 setOutputRawFormat(true);
945
Patrick Benavoli63499d42011-10-24 18:50:03 +0200946 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200947
948 } else if (remoteCommand.getArgument(0) == "dec") {
949
950 setOutputRawFormat(false);
951
Patrick Benavoli63499d42011-10-24 18:50:03 +0200952 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200953
954 } else {
955 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200956 return CCommandHandler::EShowUsage;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200957 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200958 return CCommandHandler::EFailed;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200959}
960
Patrick Benavoli63499d42011-10-24 18:50:03 +0200961CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200962{
963 (void)remoteCommand;
964
965 strResult = outputRawFormatIsHex() ? "hex" : "dec";
966
Patrick Benavoli63499d42011-10-24 18:50:03 +0200967 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200968}
969
Patrick Benavoli68a91282011-08-31 11:23:23 +0200970/// Sync
Patrick Benavoli63499d42011-10-24 18:50:03 +0200971CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200972{
973 if (remoteCommand.getArgument(0) == "on") {
974
975 if (setAutoSync(true, strResult)) {
976
Patrick Benavoli63499d42011-10-24 18:50:03 +0200977 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200978 }
979 } else if (remoteCommand.getArgument(0) == "off") {
980
981 if (setAutoSync(false, strResult)) {
982
Patrick Benavoli63499d42011-10-24 18:50:03 +0200983 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200984 }
985 } else {
986 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200987 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200988 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200989 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200990}
991
Patrick Benavoli63499d42011-10-24 18:50:03 +0200992CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200993{
994 (void)remoteCommand;
995
996 strResult = autoSyncOn() ? "on" : "off";
997
Patrick Benavoli63499d42011-10-24 18:50:03 +0200998 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200999}
1000
Patrick Benavoli63499d42011-10-24 18:50:03 +02001001CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::syncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001002{
1003 (void)remoteCommand;
1004
Patrick Benavoli63499d42011-10-24 18:50:03 +02001005 return sync(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001006}
1007
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001008/// Criteria
Patrick Benavoli63499d42011-10-24 18:50:03 +02001009CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listCriteriaCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001010{
1011 (void)remoteCommand;
1012
Kevin Rocard4eae8272013-04-18 19:12:46 +02001013 bool humanReadable = true;
Kevin Rocard7f265822012-12-07 18:51:22 +01001014
Kevin Rocard4eae8272013-04-18 19:12:46 +02001015 // Look for optional arguments
1016 if (remoteCommand.getArgumentCount() >= 1) {
1017
1018 // If csv is provided, format the criterion list in Commas Separated Value pairs
1019 if (remoteCommand.getArgument(0) == "csv") {
1020 humanReadable = false;
1021 } else {
1022 return CCommandHandler::EShowUsage;
1023 }
1024 }
1025
1026 list<string> lstrResult;
1027 getSelectionCriteria()->listSelectionCriteria(lstrResult, true, humanReadable);
Kevin Rocard7f265822012-12-07 18:51:22 +01001028
1029 // Concatenate the criterion list as the command result
Frederic Boisnard390b36d2013-05-23 15:28:31 +02001030 CUtility::asString(lstrResult, strResult);
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001031
Patrick Benavoli63499d42011-10-24 18:50:03 +02001032 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001033}
Patrick Benavoli68a91282011-08-31 11:23:23 +02001034
1035/// Domains
Patrick Benavoli63499d42011-10-24 18:50:03 +02001036CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001037{
1038 (void)remoteCommand;
1039
Patrick Benavoli63499d42011-10-24 18:50:03 +02001040 getConfigurableDomains()->listDomains(strResult);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001041
Patrick Benavoli63499d42011-10-24 18:50:03 +02001042 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001043}
1044
Patrick Benavoli63499d42011-10-24 18:50:03 +02001045CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001046{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001047 return createDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001048}
1049
Patrick Benavoli63499d42011-10-24 18:50:03 +02001050CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001051{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001052 return deleteDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001053}
1054
Kevin Rocard170f0a42012-06-18 13:56:05 +02001055CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteAllDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1056{
1057 (void)remoteCommand;
1058
1059 return deleteAllDomains(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1060}
1061
Patrick Benavoli63499d42011-10-24 18:50:03 +02001062CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001063{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001064 return getConfigurableDomains()->renameDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001065}
1066
Patrick Benavoli63499d42011-10-24 18:50:03 +02001067CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001068{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001069 // Check tuning mode
1070 if (!checkTuningModeOn(strResult)) {
1071
1072 return CCommandHandler::EFailed;
1073 }
1074
1075 // Set property
1076 bool bSequenceAware;
1077
1078 if (remoteCommand.getArgument(1) == "true") {
1079
1080 bSequenceAware = true;
1081
1082 } else if (remoteCommand.getArgument(1) == "false") {
1083
1084 bSequenceAware = false;
1085
1086 } else {
1087 // Show usage
1088 return CCommandHandler::EShowUsage;
1089 }
1090
1091 return getConfigurableDomains()->setSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001092}
1093
Patrick Benavoli63499d42011-10-24 18:50:03 +02001094CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001095{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001096 // Get property
1097 bool bSequenceAware;
1098
1099 if (!getConfigurableDomains()->getSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult)) {
1100
1101 return CCommandHandler::EFailed;
1102 }
1103
1104 strResult = bSequenceAware ? "true" : "false";
1105
1106 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001107}
1108
Patrick Benavoli63499d42011-10-24 18:50:03 +02001109CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001110{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001111 return getConfigurableDomains()->listDomainElements(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001112}
1113
Patrick Benavoli63499d42011-10-24 18:50:03 +02001114CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::addElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001115{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001116 return addConfigurableElementToDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1117}
1118
1119CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::removeElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1120{
1121 return removeConfigurableElementFromDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1122}
1123
1124CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::splitDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1125{
1126 return split(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001127}
1128
1129/// Configurations
Patrick Benavoli63499d42011-10-24 18:50:03 +02001130CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConfigurationsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001131{
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001132 return getConstConfigurableDomains()->listConfigurations(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
1133}
1134
1135CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1136{
1137 (void)remoteCommand;
1138
1139 // Dummy error context
1140 string strError;
1141 CErrorContext errorContext(strError);
1142
1143 // Dump
1144 getConstConfigurableDomains()->dumpContent(strResult, errorContext);
1145
1146 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001147}
1148
Patrick Benavoli63499d42011-10-24 18:50:03 +02001149CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001150{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001151 return createConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001152}
1153
Patrick Benavoli63499d42011-10-24 18:50:03 +02001154CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001155{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001156 return deleteConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001157}
1158
Patrick Benavoli63499d42011-10-24 18:50:03 +02001159CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001160{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001161 return getConfigurableDomains()->renameConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001162}
1163
Patrick Benavoli63499d42011-10-24 18:50:03 +02001164CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::saveConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001165{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001166 return saveConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001167}
1168
Patrick Benavoli63499d42011-10-24 18:50:03 +02001169CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::restoreConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001170{
Kevin Rocardace81f82012-12-11 16:19:17 +01001171 list<string> lstrResult;
1172 if (!restoreConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), lstrResult)) {
1173 //Concatenate the error list as the command result
Frederic Boisnard390b36d2013-05-23 15:28:31 +02001174 CUtility::asString(lstrResult, strResult);
Kevin Rocardace81f82012-12-11 16:19:17 +01001175
1176 return CCommandHandler::EFailed;
1177 }
1178 return CCommandHandler::EDone;
Patrick Benavoli63499d42011-10-24 18:50:03 +02001179}
1180
1181CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1182{
1183 // Check tuning mode
1184 if (!checkTuningModeOn(strResult)) {
1185
1186 return CCommandHandler::EFailed;
1187 }
1188
1189 // Build configurable element path list
1190 vector<string> astrNewElementSequence;
1191
1192 uint32_t uiArgument;
1193
1194 for (uiArgument = 2; uiArgument < remoteCommand.getArgumentCount(); uiArgument++) {
1195
1196 astrNewElementSequence.push_back(remoteCommand.getArgument(uiArgument));
1197 }
1198
1199 // Delegate to configurable domains
1200 return getConfigurableDomains()->setElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), astrNewElementSequence, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1201}
1202
1203CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1204{
1205 // Delegate to configurable domains
1206 return getConfigurableDomains()->getElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001207}
1208
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001209CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1210{
1211 // Delegate to configurable domains
1212 return getConfigurableDomains()->setApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.packArguments(2, remoteCommand.getArgumentCount() - 2), getConstSelectionCriteria()->getSelectionCriteriaDefinition(), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1213}
1214
1215CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::clearRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1216{
1217 // Delegate to configurable domains
1218 return getConfigurableDomains()->clearApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1219}
1220
1221CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1222{
1223 // Delegate to configurable domains
1224 return getConfigurableDomains()->getApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
1225}
1226
Patrick Benavoli68a91282011-08-31 11:23:23 +02001227/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001228CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001229{
1230 CElementLocator elementLocator(getSystemClass(), false);
1231
1232 CElement* pLocatedElement = NULL;
1233
1234 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1235
Patrick Benavoli63499d42011-10-24 18:50:03 +02001236 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001237 }
1238
1239 strResult = string("\n");
1240
1241 if (!pLocatedElement) {
1242
1243 // List from root folder
1244
1245 // Return system class qualified name
1246 pLocatedElement = getSystemClass();
1247 }
1248
1249 // Return sub-elements
1250 strResult += pLocatedElement->listQualifiedPaths(false);
1251
Patrick Benavoli63499d42011-10-24 18:50:03 +02001252 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001253}
1254
1255/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001256CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listParametersCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001257{
1258 CElementLocator elementLocator(getSystemClass(), false);
1259
1260 CElement* pLocatedElement = NULL;
1261
1262 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1263
Patrick Benavoli63499d42011-10-24 18:50:03 +02001264 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001265 }
1266
1267 strResult = string("\n");
1268
1269 if (!pLocatedElement) {
1270
1271 // List from root folder
1272
1273 // Return system class qualified name
1274 pLocatedElement = getSystemClass();
1275 }
1276
1277 // Return sub-elements
1278 strResult += pLocatedElement->listQualifiedPaths(true);
1279
Patrick Benavoli63499d42011-10-24 18:50:03 +02001280 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001281}
1282
Patrick Benavoli63499d42011-10-24 18:50:03 +02001283CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001284{
1285 CElementLocator elementLocator(getSystemClass());
1286
1287 CElement* pLocatedElement = NULL;
1288
1289 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1290
Patrick Benavoli63499d42011-10-24 18:50:03 +02001291 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001292 }
1293
1294 string strError;
1295
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001296 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001297
1298 // Dump elements
1299 pLocatedElement->dumpContent(strResult, parameterAccessContext);
1300
Patrick Benavoli63499d42011-10-24 18:50:03 +02001301 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001302}
1303
Patrick Benavoli63499d42011-10-24 18:50:03 +02001304CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSizeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001305{
1306 CElementLocator elementLocator(getSystemClass());
1307
1308 CElement* pLocatedElement = NULL;
1309
1310 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1311
Patrick Benavoli63499d42011-10-24 18:50:03 +02001312 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001313 }
1314
1315 // Converted to actual sizable element
1316 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1317
1318 // Get size as string
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001319 strResult = pConfigurableElement->getFootprintAsString();
Patrick Benavoli68a91282011-08-31 11:23:23 +02001320
Patrick Benavoli63499d42011-10-24 18:50:03 +02001321 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001322}
1323
Patrick Benavoli63499d42011-10-24 18:50:03 +02001324CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showPropertiesCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001325{
1326 CElementLocator elementLocator(getSystemClass());
1327
1328 CElement* pLocatedElement = NULL;
1329
1330 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1331
Patrick Benavoli63499d42011-10-24 18:50:03 +02001332 return CCommandHandler::EFailed;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001333 }
1334
1335 // Convert element
1336 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1337
1338 // Return element properties
1339 pConfigurableElement->showProperties(strResult);
1340
Patrick Benavoli63499d42011-10-24 18:50:03 +02001341 return CCommandHandler::ESucceeded;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001342}
1343
Patrick Benavoli63499d42011-10-24 18:50:03 +02001344CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001345{
1346 string strValue;
1347
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001348 if (!accessParameterValue(remoteCommand.getArgument(0), strValue, false, strResult)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001349
Patrick Benavoli63499d42011-10-24 18:50:03 +02001350 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001351 }
1352 // Succeeded
1353 strResult = strValue;
1354
Patrick Benavoli63499d42011-10-24 18:50:03 +02001355 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001356}
1357
Patrick Benavoli63499d42011-10-24 18:50:03 +02001358CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001359{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001360 // Check tuning mode
1361 if (!checkTuningModeOn(strResult)) {
1362
1363 return CCommandHandler::EFailed;
1364 }
1365 // Get value to set
1366 string strValue = remoteCommand.packArguments(1, remoteCommand.getArgumentCount() - 1);
1367
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001368 return accessParameterValue(remoteCommand.getArgument(0), strValue, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001369}
1370
Patrick Benavoli63499d42011-10-24 18:50:03 +02001371CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listBelongingDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001372{
1373 CElementLocator elementLocator(getSystemClass());
1374
1375 CElement* pLocatedElement = NULL;
1376
1377 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1378
Patrick Benavoli63499d42011-10-24 18:50:03 +02001379 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001380 }
1381
1382 // Convert element
1383 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1384
1385 // Return element belonging domains
1386 pConfigurableElement->listBelongingDomains(strResult);
1387
Patrick Benavoli63499d42011-10-24 18:50:03 +02001388 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001389}
1390
Patrick Benavoli63499d42011-10-24 18:50:03 +02001391CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001392{
1393 CElementLocator elementLocator(getSystemClass());
1394
1395 CElement* pLocatedElement = NULL;
1396
1397 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1398
Patrick Benavoli63499d42011-10-24 18:50:03 +02001399 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001400 }
1401
1402 // Convert element
1403 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1404
1405 // Return element belonging domains
1406 pConfigurableElement->listAssociatedDomains(strResult);
1407
Patrick Benavoli63499d42011-10-24 18:50:03 +02001408 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001409}
1410
Patrick Benavoli63499d42011-10-24 18:50:03 +02001411CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001412{
1413 (void)remoteCommand;
1414
1415 getConfigurableDomains()->listAssociatedElements(strResult);
1416
Patrick Benavoli63499d42011-10-24 18:50:03 +02001417 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001418}
1419
Patrick Benavoli63499d42011-10-24 18:50:03 +02001420CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConflictingElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001421{
1422 (void)remoteCommand;
1423
1424 getConfigurableDomains()->listConflictingElements(strResult);
1425
Patrick Benavoli63499d42011-10-24 18:50:03 +02001426 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001427}
1428
Patrick Benavoli63499d42011-10-24 18:50:03 +02001429CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listRogueElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001430{
1431 (void)remoteCommand;
1432
1433 getSystemClass()->listRogueElements(strResult);
1434
Patrick Benavoli63499d42011-10-24 18:50:03 +02001435 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001436}
1437
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001438CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getConfigurationParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1439{
1440 string strOutputValue;
1441 string strError;
1442
1443 if (!accessConfigurationValue(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), strOutputValue, false, strError)) {
1444
1445 strResult = strError;
1446 return CCommandHandler::EFailed;
1447 }
1448 // Succeeded
1449 strResult = strOutputValue;
1450
1451 return CCommandHandler::ESucceeded;
1452}
1453
1454CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setConfigurationParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1455{
1456 // Get value to set
1457 string strValue = remoteCommand.packArguments(3, remoteCommand.getArgumentCount() - 3);
1458
1459 bool bSuccess = accessConfigurationValue(remoteCommand.getArgument(0),
1460 remoteCommand.getArgument(1),
1461 remoteCommand.getArgument(2),
1462 strValue, true, strResult);
1463
1464 return bSuccess ? CCommandHandler::EDone : CCommandHandler::EFailed;
1465}
1466
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +02001467CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showMappingCommmandProcess(
1468 const IRemoteCommand& remoteCommand,
1469 string& strResult)
1470{
1471 if (!getParameterMapping(remoteCommand.getArgument(0), strResult)) {
1472
1473 return CCommandHandler::EFailed;
1474 }
1475
1476 return CCommandHandler::ESucceeded;
1477}
1478
Patrick Benavoli68a91282011-08-31 11:23:23 +02001479/// Settings Import/Export
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001480CParameterMgr::CCommandHandler::CommandStatus
1481 CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess(
1482 const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001483{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001484 string strFileName = remoteCommand.getArgument(0);
1485 return exportDomainsXml(strFileName, false, true, strResult) ?
1486 CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001487}
1488
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001489CParameterMgr::CCommandHandler::CommandStatus
1490 CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess(
1491 const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001492{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001493 return importDomainsXml(remoteCommand.getArgument(0), false, true, strResult) ?
1494 CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001495}
1496
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001497CParameterMgr::CCommandHandler::CommandStatus
1498 CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess(
1499 const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001500{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001501 string strFileName = remoteCommand.getArgument(0);
1502 return exportDomainsXml(strFileName, true, true, strResult) ?
1503 CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001504}
1505
Patrick Benavoli63499d42011-10-24 18:50:03 +02001506CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001507{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001508 return importDomainsXml(remoteCommand.getArgument(0), true, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001509}
1510
Patrick Benavoli63499d42011-10-24 18:50:03 +02001511CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001512{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001513 return exportDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001514}
1515
Patrick Benavoli63499d42011-10-24 18:50:03 +02001516CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001517{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001518 return importDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001519}
1520
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001521CParameterMgr::CCommandHandler::CommandStatus
1522 CParameterMgr::getConfigurableDomainsWithSettingsXMLCommmandProcess(
1523 const IRemoteCommand& remoteCommand, string& strResult)
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001524{
1525 (void)remoteCommand;
1526
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001527 if (!exportDomainsXml(strResult, true, false, strResult)) {
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001528
1529 return CCommandHandler::EFailed;
1530 }
1531 // Succeeded
1532 return CCommandHandler::ESucceeded;
1533}
1534
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001535CParameterMgr::CCommandHandler::CommandStatus
1536 CParameterMgr::setConfigurableDomainsWithSettingsXMLCommmandProcess(
1537 const IRemoteCommand& remoteCommand, string& strResult)
1538{
1539 return importDomainsXml(remoteCommand.getArgument(0), true, false, strResult) ?
1540 CCommandHandler::EDone : CCommandHandler::EFailed;
1541}
1542
1543CParameterMgr::CCommandHandler::CommandStatus
1544 CParameterMgr::getSystemClassXMLCommmandProcess(
1545 const IRemoteCommand& remoteCommand, string& strResult)
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001546{
1547 (void)remoteCommand;
1548
1549 if (!getSystemClassXMLString(strResult)) {
1550
1551 return CCommandHandler::EFailed;
1552 }
1553 // Succeeded
1554 return CCommandHandler::ESucceeded;
1555}
1556
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001557// User set/get parameters in main BlackBoard
1558bool CParameterMgr::accessParameterValue(const string& strPath, string& strValue, bool bSet, string& strError)
1559{
1560 // Define context
1561 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
1562
Frédéric Boisnard150407c2013-03-15 14:46:23 +01001563 // Activate the auto synchronization with the hardware
1564 if (bSet) {
1565
1566 parameterAccessContext.setAutoSync(_bAutoSyncOn);
1567 }
1568
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001569 return accessValue(parameterAccessContext, strPath, strValue, bSet, strError);
1570}
1571
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +02001572// User get parameter mapping
1573bool CParameterMgr::getParameterMapping(const string& strPath, string& strResult) const
1574{
1575 CPathNavigator pathNavigator(strPath);
1576
1577 // Nagivate through system class
1578 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strResult)) {
1579
1580 return false;
1581 }
1582
1583 // Get the ConfigurableElement corresponding to strPath
1584 const CConfigurableElement* pConfigurableElement = getConfigurableElement(strPath, strResult);
1585 if (!pConfigurableElement) {
1586
1587 return false;
1588 }
1589
1590 // Find the list of the ancestors of the current ConfigurableElement that have a mapping
1591 list<const CConfigurableElement*> configurableElementPath;
1592 pConfigurableElement->getListOfElementsWithMapping(configurableElementPath);
1593
1594 // Get the Subsystem containing the ConfigurableElement
1595 const CSubsystem* pSubsystem = pConfigurableElement->getBelongingSubsystem();
1596 if (!pSubsystem) {
1597
1598 strResult = "Unable to find the Subsystem containing the parameter";
1599 return false;
1600 }
1601
1602 // Fetch the mapping corresponding to the ConfigurableElement
1603 strResult = pSubsystem->getMapping(configurableElementPath);
1604
1605 return true;
1606}
1607
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001608// User set/get parameters in specific Configuration BlackBoard
1609bool CParameterMgr::accessConfigurationValue(const string& strDomain, const string& strConfiguration, const string& strPath, string& strValue, bool bSet, string& strError)
1610{
1611 CElementLocator elementLocator(getSystemClass());
1612
1613 CElement* pLocatedElement = NULL;
1614
1615 if (!elementLocator.locate(strPath, &pLocatedElement, strError)) {
1616
1617 return false;
1618 }
1619
1620 // Convert element
1621 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1622
1623 // Get the Configuration blackboard and the Base Offset of the configurable element in this blackboard
1624 uint32_t uiBaseOffset;
1625 bool bIsLastApplied;
1626
1627 CParameterBlackboard* pConfigurationBlackboard = getConstConfigurableDomains()->findConfigurationBlackboard(strDomain, strConfiguration, pConfigurableElement, uiBaseOffset, bIsLastApplied, strError);
1628
1629 if (!pConfigurationBlackboard) {
1630
1631 return false;
1632 }
1633
1634 log_info("Element %s in Domain %s, offset: %d, base offset: %d", strPath.c_str(), strDomain.c_str(), pConfigurableElement->getOffset(), uiBaseOffset);
1635
1636 /// Update the Configuration Blackboard
1637
Frédéric Boisnard150407c2013-03-15 14:46:23 +01001638 // 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 +01001639 CParameterAccessContext parameterAccessContext(strError, pConfigurationBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex, uiBaseOffset);
1640
Frédéric Boisnardda8298c2014-05-23 19:05:31 +02001641 // Deactivate the auto synchronization with the hardware during the Configuration Blackboard
1642 // access (only Main Blackboard shall be synchronized, Configurations Blackboards are copied
1643 // into the Main Blackboard each time a configuration is restored but they are not synchronized
1644 // directly).
1645 if (bSet) {
1646
1647 parameterAccessContext.setAutoSync(false);
1648 }
1649
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001650 // Access Value in the Configuration Blackboard
1651 if (!accessValue(parameterAccessContext, strPath, strValue, bSet, strError)) {
1652
1653 return false;
1654 }
1655
1656 /// If the Configuration is the last one applied, update the Main Blackboard as well
1657
1658 if (bIsLastApplied) {
1659
1660 // Define Main context
1661 parameterAccessContext.setParameterBlackboard(_pMainParameterBlackboard);
1662
Frédéric Boisnard150407c2013-03-15 14:46:23 +01001663 // Activate the auto synchronization with the hardware
1664 if (bSet) {
1665
1666 parameterAccessContext.setAutoSync(_bAutoSyncOn);
1667 }
1668
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001669 // Access Value in the Main Blackboard
1670 return accessValue(parameterAccessContext, strPath, strValue, bSet, strError);
1671 }
1672
1673 return true;
1674}
1675
Patrick Benavoli68a91282011-08-31 11:23:23 +02001676// User set/get parameters
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001677bool CParameterMgr::accessValue(CParameterAccessContext& parameterAccessContext, const string& strPath, string& strValue, bool bSet, string& strError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001678{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001679 // Lock state
1680 CAutoLock autoLock(&_blackboardMutex);
1681
1682 CPathNavigator pathNavigator(strPath);
1683
1684 // Nagivate through system class
1685 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001686
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +02001687 parameterAccessContext.setError(strError);
1688
Patrick Benavoli68a91282011-08-31 11:23:23 +02001689 return false;
1690 }
1691
Patrick Benavoli065264a2011-11-20 15:46:41 +01001692 // Do the get
1693 return getConstSystemClass()->accessValue(pathNavigator, strValue, bSet, parameterAccessContext);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001694}
1695
1696// Tuning mode
1697bool CParameterMgr::setTuningMode(bool bOn, string& strError)
1698{
1699 // Tuning allowed?
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001700 if (bOn && !getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001701
1702 strError = "Tuning prohibited";
1703
1704 return false;
1705 }
1706 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +01001707 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001708
1709 // Warn domains about exiting tuning mode
1710 if (!bOn && _bTuningModeIsOn) {
1711
1712 // Ensure application of currently selected configurations
Patrick Benavoli1387bda2011-08-31 11:23:24 +02001713 // Force-apply configurations
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01001714 doApplyConfigurations(true);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001715
Patrick Benavoli68a91282011-08-31 11:23:23 +02001716 // Turn auto sync back on
1717 _bAutoSyncOn = true;
1718 }
1719
1720 // Store
1721 _bTuningModeIsOn = bOn;
1722
Patrick Benavoli68a91282011-08-31 11:23:23 +02001723 return true;
1724}
1725
1726bool CParameterMgr::tuningModeOn() const
1727{
1728 return _bTuningModeIsOn;
1729}
1730
1731// Current value space for user set/get value interpretation
1732void CParameterMgr::setValueSpace(bool bIsRaw)
1733{
1734 _bValueSpaceIsRaw = bIsRaw;
1735}
1736
1737bool CParameterMgr::valueSpaceIsRaw()
1738{
1739 return _bValueSpaceIsRaw;
1740}
1741
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001742// Current Output Raw Format for user get value interpretation
1743void CParameterMgr::setOutputRawFormat(bool bIsHex)
1744{
1745 _bOutputRawFormatIsHex = bIsHex;
1746}
1747
1748bool CParameterMgr::outputRawFormatIsHex()
1749{
1750 return _bOutputRawFormatIsHex;
1751}
1752
Patrick Benavoli68a91282011-08-31 11:23:23 +02001753/// Sync
1754// Automatic hardware synchronization control (during tuning session)
1755bool CParameterMgr::setAutoSync(bool bAutoSyncOn, string& strError)
1756{
1757 // Check tuning mode
1758 if (!checkTuningModeOn(strError)) {
1759
1760 return false;
1761 }
1762 // Warn domains about turning auto sync back on
1763 if (bAutoSyncOn && !_bAutoSyncOn) {
1764
Patrick Benavoli592ae562011-09-05 16:53:58 +02001765 // Do the synchronization at system class level (could be optimized by keeping track of all modified parameters)
1766 if (!sync(strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001767
1768 return false;
1769 }
1770 }
1771
1772 // Set Auto sync
1773 _bAutoSyncOn = bAutoSyncOn;
1774
1775 return true;
1776}
1777
1778bool CParameterMgr::autoSyncOn() const
1779{
1780 return _bAutoSyncOn;
1781}
1782
1783// Manual hardware synchronization control (during tuning session)
1784bool CParameterMgr::sync(string& strError)
1785{
1786 // Check tuning mode
1787 if (!checkTuningModeOn(strError)) {
1788
1789 return false;
1790 }
1791 // Warn domains about turning auto sync back on
1792 if (_bAutoSyncOn) {
1793
1794 strError = "Feature unavailable when Auto Sync is on";
1795
1796 return false;
1797 }
1798
1799 // Get syncer set
1800 CSyncerSet syncerSet;
1801 // ... from system class
1802 getConstSystemClass()->fillSyncerSet(syncerSet);
Kevin Rocardace81f82012-12-11 16:19:17 +01001803
Patrick Benavoli68a91282011-08-31 11:23:23 +02001804 // Sync
Kevin Rocardace81f82012-12-11 16:19:17 +01001805 list<string> lstrError;
1806 if (! syncerSet.sync(*_pMainParameterBlackboard, false, &lstrError)){
1807
Frederic Boisnard390b36d2013-05-23 15:28:31 +02001808 CUtility::asString(lstrError, strError);
Kevin Rocardace81f82012-12-11 16:19:17 +01001809 return false;
1810 };
1811
1812 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001813}
1814
1815// Content dump
1816void CParameterMgr::logStructureContent(string& strContent) const
1817{
1818 string strError;
1819
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001820 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001821
1822 dumpContent(strContent, parameterAccessContext);
1823}
1824
1825// Configuration/Domains handling
1826bool CParameterMgr::createDomain(const string& strName, string& strError)
1827{
1828 // Check tuning mode
1829 if (!checkTuningModeOn(strError)) {
1830
1831 return false;
1832 }
1833
1834 // Delegate to configurable domains
1835 return getConfigurableDomains()->createDomain(strName, strError);
1836}
1837
1838bool CParameterMgr::deleteDomain(const string& strName, string& strError)
1839{
1840 // Check tuning mode
1841 if (!checkTuningModeOn(strError)) {
1842
1843 return false;
1844 }
1845
1846 // Delegate to configurable domains
1847 return getConfigurableDomains()->deleteDomain(strName, strError);
1848}
1849
Kevin Rocard170f0a42012-06-18 13:56:05 +02001850bool CParameterMgr::deleteAllDomains(string& strError)
1851{
1852 // Check tuning mode
1853 if (!checkTuningModeOn(strError)) {
1854
1855 return false;
1856 }
1857
1858 // Delegate to configurable domains
1859 getConfigurableDomains()->deleteAllDomains();
1860
1861 return true;
1862}
1863
Patrick Benavoli68a91282011-08-31 11:23:23 +02001864bool CParameterMgr::createConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1865{
1866 // Check tuning mode
1867 if (!checkTuningModeOn(strError)) {
1868
1869 return false;
1870 }
1871
1872 // Delegate to configurable domains
1873 return getConfigurableDomains()->createConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1874}
1875
1876bool CParameterMgr::deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1877{
1878 // Check tuning mode
1879 if (!checkTuningModeOn(strError)) {
1880
1881 return false;
1882 }
1883
1884 // Delegate to configurable domains
1885 return getConfigurableDomains()->deleteConfiguration(strDomain, strConfiguration, strError);
1886}
1887
Kevin Rocardace81f82012-12-11 16:19:17 +01001888bool CParameterMgr::restoreConfiguration(const string& strDomain, const string& strConfiguration, list<string>& lstrError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001889{
Kevin Rocardace81f82012-12-11 16:19:17 +01001890 string strError;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001891 // Check tuning mode
1892 if (!checkTuningModeOn(strError)) {
1893
Kevin Rocardace81f82012-12-11 16:19:17 +01001894 lstrError.push_back(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001895 return false;
1896 }
1897
1898 // Delegate to configurable domains
Kevin Rocardace81f82012-12-11 16:19:17 +01001899 return getConstConfigurableDomains()->restoreConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, lstrError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001900}
1901
1902bool CParameterMgr::saveConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1903{
1904 // Check tuning mode
1905 if (!checkTuningModeOn(strError)) {
1906
1907 return false;
1908 }
1909
1910 // Delegate to configurable domains
1911 return getConfigurableDomains()->saveConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1912}
1913
1914// Configurable element - domain association
1915bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1916{
1917 // Check tuning mode
1918 if (!checkTuningModeOn(strError)) {
1919
1920 return false;
1921 }
1922
1923 CElementLocator elementLocator(getSystemClass());
1924
1925 CElement* pLocatedElement = NULL;
1926
1927 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1928
1929 return false;
1930 }
1931
1932 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001933 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001934
1935 // Delegate
1936 return getConfigurableDomains()->addConfigurableElementToDomain(strDomain, pConfigurableElement, _pMainParameterBlackboard, strError);
1937}
1938
1939bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1940{
1941 // Check tuning mode
1942 if (!checkTuningModeOn(strError)) {
1943
1944 return false;
1945 }
1946
1947 CElementLocator elementLocator(getSystemClass());
1948
1949 CElement* pLocatedElement = NULL;
1950
1951 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1952
Patrick Benavoli63499d42011-10-24 18:50:03 +02001953 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001954 }
1955
1956 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001957 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001958
1959 // Delegate
1960 return getConfigurableDomains()->removeConfigurableElementFromDomain(strDomain, pConfigurableElement, strError);
1961}
1962
1963bool CParameterMgr::split(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1964{
1965 // Check tuning mode
1966 if (!checkTuningModeOn(strError)) {
1967
1968 return false;
1969 }
1970
1971 CElementLocator elementLocator(getSystemClass());
1972
1973 CElement* pLocatedElement = NULL;
1974
1975 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1976
Patrick Benavoli63499d42011-10-24 18:50:03 +02001977 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001978 }
1979
1980 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001981 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001982
1983 // Delegate
1984 return getConfigurableDomains()->split(strDomain, pConfigurableElement, strError);
1985}
1986
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001987bool CParameterMgr::importDomainsXml(const string& strXmlSource, bool bWithSettings,
1988 bool bFromFile, string& strError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001989{
1990 // Check tuning mode
1991 if (!checkTuningModeOn(strError)) {
1992
1993 return false;
1994 }
1995
1996 // check path is absolute
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001997 if (bFromFile && strXmlSource[0] != '/') {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001998
1999 strError = "Please provide absolute path";
2000
2001 return false;
2002 }
2003 // Root element
2004 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
2005
2006 // Context
2007 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
2008
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002009 // Selection criteria definition for rule creation
2010 xmlDomainSerializingContext.setSelectionCriteriaDefinition(
2011 getConstSelectionCriteria()->getSelectionCriteriaDefinition());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002012
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002013 // Init serializing context
2014 xmlDomainSerializingContext.set(
2015 _pElementLibrarySet->getElementLibrary(EParameterConfigurationLibrary),
2016 "", _strSchemaFolderLocation);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002017
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002018 // Get Schema file associated to root element
2019 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" +
2020 pConfigurableDomains->getKind() + ".xsd";
2021
2022 // Xml Source
2023 CXmlDocSource* pSource;
2024
2025 if (bFromFile) {
2026
2027 // when importing from a file strXmlSource is the file name
2028 pSource = new CXmlFileDocSource(strXmlSource, strXmlSchemaFilePath,
2029 pConfigurableDomains->getKind(),
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +02002030 pConfigurableDomains->getName(), "SystemClassName",
2031 _bValidateSchemasOnStart);
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002032
2033 } else {
2034
2035 // when importing from an xml string, strXmlSource contains the string
2036 pSource = new CXmlStringDocSource(strXmlSource, strXmlSchemaFilePath,
2037 pConfigurableDomains->getKind(),
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +02002038 pConfigurableDomains->getName(), "SystemClassName",
2039 _bValidateSchemasOnStart);
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002040
2041 }
2042 // Start clean
2043 pConfigurableDomains->clean();
2044
2045 // Use a doc sink that instantiate Configurable Domains from the given doc source
2046 CXmlMemoryDocSink memorySink(pConfigurableDomains);
2047
2048 bool bProcessSuccess = memorySink.process(*pSource, xmlDomainSerializingContext);
2049
2050 if (!bProcessSuccess) {
2051
2052 //Cleanup
2053 pConfigurableDomains->clean();
2054
2055 } else {
2056
2057 // Validate domains after XML import
2058 pConfigurableDomains->validate(_pMainParameterBlackboard);
2059
Patrick Benavoli68a91282011-08-31 11:23:23 +02002060 }
2061
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002062 delete pSource;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002063
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002064 return bProcessSuccess;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002065}
2066
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002067bool CParameterMgr::exportDomainsXml(string& strXmlDest, bool bWithSettings, bool bToFile,
2068 string& strError) const
Patrick Benavoli68a91282011-08-31 11:23:23 +02002069{
2070 // check path is absolute
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002071 if (bToFile && strXmlDest[0] != '/') {
Patrick Benavoli68a91282011-08-31 11:23:23 +02002072
2073 strError = "Please provide absolute path";
2074
2075 return false;
2076 }
2077
2078 // Root element
2079 const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains();
2080
2081 // Get Schema file associated to root element
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002082 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" +
2083 pConfigurableDomains->getKind() + ".xsd";
Patrick Benavoli68a91282011-08-31 11:23:23 +02002084
2085 // Context
2086 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
2087
2088 // Value space
2089 xmlDomainSerializingContext.setValueSpaceRaw(_bValueSpaceIsRaw);
2090
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02002091 // Output raw format
2092 xmlDomainSerializingContext.setOutputRawFormat(_bOutputRawFormatIsHex);
2093
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002094 // Use a doc source by loading data from instantiated Configurable Domains
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002095 CXmlMemoryDocSource memorySource(pConfigurableDomains, pConfigurableDomains->getKind(),
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +02002096 strXmlSchemaFilePath, "parameter-framework",
2097 getVersion(), _bValidateSchemasOnStart);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002098
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002099 // Xml Sink
2100 CXmlDocSink* pSink;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002101
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002102 if (bToFile) {
2103
2104 // Use a doc sink to write the doc data in a file
2105 pSink = new CXmlFileDocSink(strXmlDest);
2106
2107 } else {
2108
2109 // Use a doc sink to write the doc data in a string
2110 pSink = new CXmlStringDocSink(strXmlDest);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002111 }
2112
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002113 bool bProcessSuccess = pSink->process(memorySource, xmlDomainSerializingContext);
2114
2115 delete pSink;
2116 return bProcessSuccess;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002117}
2118
2119// Binary Import/Export
2120bool CParameterMgr::importDomainsBinary(const string& strFileName, string& strError)
2121{
2122 // Check tuning mode
2123 if (!checkTuningModeOn(strError)) {
2124
2125 return false;
2126 }
2127 // check path is absolute
2128 if (strFileName[0] != '/') {
2129
2130 strError = "Please provide absolute path";
2131
2132 return false;
2133 }
2134 // Root element
2135 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
2136
2137 // Serialize in
2138 return pConfigurableDomains->serializeSettings(strFileName, false, _uiStructureChecksum, strError);
2139}
2140
2141bool CParameterMgr::exportDomainsBinary(const string& strFileName, string& strError)
2142{
2143 // check path is absolute
2144 if (strFileName[0] != '/') {
2145
2146 strError = "Please provide absolute path";
2147
2148 return false;
2149 }
Patrick Benavoli68a91282011-08-31 11:23:23 +02002150
Patrick Benavoli68a91282011-08-31 11:23:23 +02002151 // Root element
2152 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
2153
2154 // Serialize out
2155 return pConfigurableDomains->serializeSettings(strFileName, true, _uiStructureChecksum, strError);
2156}
2157
2158// For tuning, check we're in tuning mode
2159bool CParameterMgr::checkTuningModeOn(string& strError) const
2160{
2161 // Tuning Mode on?
2162 if (!_bTuningModeIsOn) {
2163
2164 strError = "Tuning Mode must be on";
2165
2166 return false;
2167 }
2168 return true;
2169}
2170
Patrick Benavoli065264a2011-11-20 15:46:41 +01002171// Tuning mutex dynamic parameter handling
2172pthread_mutex_t* CParameterMgr::getBlackboardMutex()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002173{
Patrick Benavoli065264a2011-11-20 15:46:41 +01002174 return &_blackboardMutex;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002175}
2176
Patrick Benavoli065264a2011-11-20 15:46:41 +01002177// Blackboard reference (dynamic parameter handling)
2178CParameterBlackboard* CParameterMgr::getParameterBlackboard()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002179{
Patrick Benavoli065264a2011-11-20 15:46:41 +01002180 return _pMainParameterBlackboard;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002181}
2182
Patrick Benavoli68a91282011-08-31 11:23:23 +02002183// Dynamic creation library feeding
2184void CParameterMgr::feedElementLibraries()
2185{
2186 // Global Configuration handling
2187 CElementLibrary* pFrameworkConfigurationLibrary = new CElementLibrary;
2188
Kevin Rocarda7b69602013-08-07 16:15:33 +02002189 pFrameworkConfigurationLibrary->addElementBuilder("ParameterFrameworkConfiguration", new TElementBuilderTemplate<CParameterFrameworkConfiguration>());
2190 pFrameworkConfigurationLibrary->addElementBuilder("SubsystemPlugins", new TKindElementBuilderTemplate<CSubsystemPlugins>());
2191 pFrameworkConfigurationLibrary->addElementBuilder("Location", new TKindElementBuilderTemplate<CPluginLocation>());
2192 pFrameworkConfigurationLibrary->addElementBuilder("StructureDescriptionFileLocation", new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>());
2193 pFrameworkConfigurationLibrary->addElementBuilder("SettingsConfiguration", new TKindElementBuilderTemplate<CFrameworkConfigurationGroup>());
2194 pFrameworkConfigurationLibrary->addElementBuilder("ConfigurableDomainsFileLocation", new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>());
2195 pFrameworkConfigurationLibrary->addElementBuilder("BinarySettingsFileLocation", new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002196
2197 _pElementLibrarySet->addElementLibrary(pFrameworkConfigurationLibrary);
2198
2199 // Parameter creation
2200 CElementLibrary* pParameterCreationLibrary = new CElementLibrary;
2201
Kevin Rocarda7b69602013-08-07 16:15:33 +02002202 pParameterCreationLibrary->addElementBuilder("Subsystem", new CSubsystemElementBuilder(getSystemClass()->getSubsystemLibrary()));
2203 pParameterCreationLibrary->addElementBuilder("ComponentType", new TNamedElementBuilderTemplate<CComponentType>());
2204 pParameterCreationLibrary->addElementBuilder("Component", new TNamedElementBuilderTemplate<CComponentInstance>());
2205 pParameterCreationLibrary->addElementBuilder("BitParameter", new TNamedElementBuilderTemplate<CBitParameterType>());
2206 pParameterCreationLibrary->addElementBuilder("BitParameterBlock", new TNamedElementBuilderTemplate<CBitParameterBlockType>());
2207 pParameterCreationLibrary->addElementBuilder("StringParameter", new TNamedElementBuilderTemplate<CStringParameterType>());
2208 pParameterCreationLibrary->addElementBuilder("ParameterBlock", new TNamedElementBuilderTemplate<CParameterBlockType>());
2209 pParameterCreationLibrary->addElementBuilder("BooleanParameter", new TNamedElementBuilderTemplate<CBooleanParameterType>());
2210 pParameterCreationLibrary->addElementBuilder("IntegerParameter", new TNamedElementBuilderTemplate<CIntegerParameterType>());
2211 pParameterCreationLibrary->addElementBuilder("LinearAdaptation", new TElementBuilderTemplate<CLinearParameterAdaptation>());
2212 pParameterCreationLibrary->addElementBuilder("EnumParameter", new TNamedElementBuilderTemplate<CEnumParameterType>());
2213 pParameterCreationLibrary->addElementBuilder("ValuePair", new TElementBuilderTemplate<CEnumValuePair>());
2214 pParameterCreationLibrary->addElementBuilder("FixedPointParameter", new TNamedElementBuilderTemplate<CFixedPointParameterType>());
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +02002215 pParameterCreationLibrary->addElementBuilder("SubsystemInclude", new CFileIncluderElementBuilder(_bValidateSchemasOnStart));
Patrick Benavoli68a91282011-08-31 11:23:23 +02002216
2217 _pElementLibrarySet->addElementLibrary(pParameterCreationLibrary);
2218
2219 // Parameter Configuration Domains creation
2220 CElementLibrary* pParameterConfigurationLibrary = new CElementLibrary;
2221
Kevin Rocarda7b69602013-08-07 16:15:33 +02002222 pParameterConfigurationLibrary->addElementBuilder("ConfigurableDomain", new TNamedElementBuilderTemplate<CConfigurableDomain>());
2223 pParameterConfigurationLibrary->addElementBuilder("Configuration", new TNamedElementBuilderTemplate<CDomainConfiguration>());
2224 pParameterConfigurationLibrary->addElementBuilder("CompoundRule", new TElementBuilderTemplate<CCompoundRule>());
2225 pParameterConfigurationLibrary->addElementBuilder("SelectionCriterionRule", new TElementBuilderTemplate<CSelectionCriterionRule>());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002226
2227 _pElementLibrarySet->addElementLibrary(pParameterConfigurationLibrary);
2228}
2229
2230// Remote Processor Server connection handling
2231bool CParameterMgr::handleRemoteProcessingInterface(string& strError)
2232{
2233 CAutoLog autoLog(this, "Handling remote processing interface");
2234
2235 // Start server if tuning allowed
Patrick Benavoli95ac0342011-11-07 20:32:51 +01002236 if (getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02002237
Kevin Rocardace81f82012-12-11 16:19:17 +01002238 log_info("Loading remote processor library");
Patrick Benavoli68a91282011-08-31 11:23:23 +02002239
2240 // Load library
Renaud de Chivre1b8b3ca2013-12-13 15:09:44 +01002241 _handleLibRemoteProcessor = dlopen("libremote-processor.so", RTLD_NOW);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002242
Renaud de Chivre1b8b3ca2013-12-13 15:09:44 +01002243 if (!_handleLibRemoteProcessor) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02002244
2245 // Return error
2246 const char* pcError = dlerror();
2247
2248 if (pcError) {
2249
2250 strError = pcError;
2251 } else {
2252
2253 strError = "Unable to load libremote-processor.so library";
2254 }
2255
2256 return false;
2257 }
2258
Renaud de Chivre1b8b3ca2013-12-13 15:09:44 +01002259 CreateRemoteProcessorServer pfnCreateRemoteProcessorServer = (CreateRemoteProcessorServer)dlsym(_handleLibRemoteProcessor, "createRemoteProcessorServer");
Patrick Benavoli68a91282011-08-31 11:23:23 +02002260
2261 if (!pfnCreateRemoteProcessorServer) {
2262
2263 strError = "libremote-process.so does not contain createRemoteProcessorServer symbol.";
2264
2265 return false;
2266 }
2267
2268 // Create server
Patrick Benavoli95ac0342011-11-07 20:32:51 +01002269 _pRemoteProcessorServer = pfnCreateRemoteProcessorServer(getConstFrameworkConfiguration()->getServerPort(), _pCommandHandler);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002270
Kevin Rocardace81f82012-12-11 16:19:17 +01002271 log_info("Starting remote processor server on port %d", getConstFrameworkConfiguration()->getServerPort());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002272 // Start
2273 if (!_pRemoteProcessorServer->start()) {
2274
Frédéric Boisnard6c55e9a2014-01-10 18:46:33 +01002275 ostringstream oss;
2276 oss << "ParameterMgr: Unable to start remote processor server on port "
2277 << getConstFrameworkConfiguration()->getServerPort();
2278 strError = oss.str();
Patrick Benavoli68a91282011-08-31 11:23:23 +02002279
2280 return false;
2281 }
2282 }
2283
2284 return true;
2285}
2286
2287// Back synchronization
Kevin Rocardace81f82012-12-11 16:19:17 +01002288CBackSynchronizer* CParameterMgr::createBackSynchronizer() const
Patrick Benavoli68a91282011-08-31 11:23:23 +02002289{
2290#ifdef SIMULATION
2291 // In simulation, back synchronization of the blackboard won't probably work
2292 // We need to ensure though the blackboard is initialized with valid data
Kevin Rocardace81f82012-12-11 16:19:17 +01002293 return new CSimulatedBackSynchronizer(getConstSystemClass(), _pMainParameterBlackboard);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002294#else
2295 // Real back synchronizer from subsystems
Kevin Rocardace81f82012-12-11 16:19:17 +01002296 return new CHardwareBackSynchronizer(getConstSystemClass(), _pMainParameterBlackboard);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002297#endif
2298}
2299
2300// Children typwise access
2301CParameterFrameworkConfiguration* CParameterMgr::getFrameworkConfiguration()
2302{
2303 return static_cast<CParameterFrameworkConfiguration*>(getChild(EFrameworkConfiguration));
2304}
2305
2306const CParameterFrameworkConfiguration* CParameterMgr::getConstFrameworkConfiguration()
2307{
2308 return getFrameworkConfiguration();
2309}
2310
2311CSelectionCriteria* CParameterMgr::getSelectionCriteria()
2312{
2313 return static_cast<CSelectionCriteria*>(getChild(ESelectionCriteria));
2314}
2315
2316const CSelectionCriteria* CParameterMgr::getConstSelectionCriteria()
2317{
2318 return static_cast<const CSelectionCriteria*>(getChild(ESelectionCriteria));
2319}
2320
2321CSystemClass* CParameterMgr::getSystemClass()
2322{
2323 return static_cast<CSystemClass*>(getChild(ESystemClass));
2324}
2325
2326const CSystemClass* CParameterMgr::getConstSystemClass() const
2327{
2328 return static_cast<const CSystemClass*>(getChild(ESystemClass));
2329}
2330
2331// Configurable Domains
2332CConfigurableDomains* CParameterMgr::getConfigurableDomains()
2333{
2334 return static_cast<CConfigurableDomains*>(getChild(EConfigurableDomains));
2335}
2336
2337const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains()
2338{
2339 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
2340}
2341
2342const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains() const
2343{
2344 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
2345}
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002346
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01002347// Apply configurations
2348void CParameterMgr::doApplyConfigurations(bool bForce)
2349{
2350 CSyncerSet syncerSet;
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002351
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01002352 // Check subsystems that need resync
2353 getSystemClass()->checkForSubsystemsToResync(syncerSet);
2354
2355 // Ensure application of currently selected configurations
2356 getConfigurableDomains()->apply(_pMainParameterBlackboard, syncerSet, bForce);
2357
2358 // Reset the modified status of the current criteria to indicate that a new configuration has been applied
2359 getSelectionCriteria()->resetModifiedStatus();
2360}
2361
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002362bool CParameterMgr::getSystemClassXMLString(string& strResult)
2363{
2364 // Root element
2365 const CSystemClass* pSystemClass = getSystemClass();
2366
2367 string strError;
2368
2369 CXmlSerializingContext xmlSerializingContext(strError);
2370
2371 // Use a doc source by loading data from instantiated Configurable Domains
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +02002372 CXmlMemoryDocSource memorySource(pSystemClass, pSystemClass->getKind(),
2373 _bValidateSchemasOnStart);
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002374
2375 // Use a doc sink that write the doc data in a string
2376 CXmlStringDocSink stringSink(strResult);
2377
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002378 bool bProcessSuccess = stringSink.process(memorySource, xmlSerializingContext);
2379
2380 if (!bProcessSuccess) {
2381
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002382 strResult = strError;
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002383
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002384 }
2385
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002386 return bProcessSuccess;
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002387}