blob: 2882f675afa7a8eb401906d4454ba48851c70a0c [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
1641 // Access Value in the Configuration Blackboard
1642 if (!accessValue(parameterAccessContext, strPath, strValue, bSet, strError)) {
1643
1644 return false;
1645 }
1646
1647 /// If the Configuration is the last one applied, update the Main Blackboard as well
1648
1649 if (bIsLastApplied) {
1650
1651 // Define Main context
1652 parameterAccessContext.setParameterBlackboard(_pMainParameterBlackboard);
1653
Frédéric Boisnard150407c2013-03-15 14:46:23 +01001654 // Activate the auto synchronization with the hardware
1655 if (bSet) {
1656
1657 parameterAccessContext.setAutoSync(_bAutoSyncOn);
1658 }
1659
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001660 // Access Value in the Main Blackboard
1661 return accessValue(parameterAccessContext, strPath, strValue, bSet, strError);
1662 }
1663
1664 return true;
1665}
1666
Patrick Benavoli68a91282011-08-31 11:23:23 +02001667// User set/get parameters
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001668bool CParameterMgr::accessValue(CParameterAccessContext& parameterAccessContext, const string& strPath, string& strValue, bool bSet, string& strError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001669{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001670 // Lock state
1671 CAutoLock autoLock(&_blackboardMutex);
1672
1673 CPathNavigator pathNavigator(strPath);
1674
1675 // Nagivate through system class
1676 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001677
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +02001678 parameterAccessContext.setError(strError);
1679
Patrick Benavoli68a91282011-08-31 11:23:23 +02001680 return false;
1681 }
1682
Patrick Benavoli065264a2011-11-20 15:46:41 +01001683 // Do the get
1684 return getConstSystemClass()->accessValue(pathNavigator, strValue, bSet, parameterAccessContext);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001685}
1686
1687// Tuning mode
1688bool CParameterMgr::setTuningMode(bool bOn, string& strError)
1689{
1690 // Tuning allowed?
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001691 if (bOn && !getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001692
1693 strError = "Tuning prohibited";
1694
1695 return false;
1696 }
1697 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +01001698 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001699
1700 // Warn domains about exiting tuning mode
1701 if (!bOn && _bTuningModeIsOn) {
1702
1703 // Ensure application of currently selected configurations
Patrick Benavoli1387bda2011-08-31 11:23:24 +02001704 // Force-apply configurations
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01001705 doApplyConfigurations(true);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001706
Patrick Benavoli68a91282011-08-31 11:23:23 +02001707 // Turn auto sync back on
1708 _bAutoSyncOn = true;
1709 }
1710
1711 // Store
1712 _bTuningModeIsOn = bOn;
1713
Patrick Benavoli68a91282011-08-31 11:23:23 +02001714 return true;
1715}
1716
1717bool CParameterMgr::tuningModeOn() const
1718{
1719 return _bTuningModeIsOn;
1720}
1721
1722// Current value space for user set/get value interpretation
1723void CParameterMgr::setValueSpace(bool bIsRaw)
1724{
1725 _bValueSpaceIsRaw = bIsRaw;
1726}
1727
1728bool CParameterMgr::valueSpaceIsRaw()
1729{
1730 return _bValueSpaceIsRaw;
1731}
1732
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001733// Current Output Raw Format for user get value interpretation
1734void CParameterMgr::setOutputRawFormat(bool bIsHex)
1735{
1736 _bOutputRawFormatIsHex = bIsHex;
1737}
1738
1739bool CParameterMgr::outputRawFormatIsHex()
1740{
1741 return _bOutputRawFormatIsHex;
1742}
1743
Patrick Benavoli68a91282011-08-31 11:23:23 +02001744/// Sync
1745// Automatic hardware synchronization control (during tuning session)
1746bool CParameterMgr::setAutoSync(bool bAutoSyncOn, string& strError)
1747{
1748 // Check tuning mode
1749 if (!checkTuningModeOn(strError)) {
1750
1751 return false;
1752 }
1753 // Warn domains about turning auto sync back on
1754 if (bAutoSyncOn && !_bAutoSyncOn) {
1755
Patrick Benavoli592ae562011-09-05 16:53:58 +02001756 // Do the synchronization at system class level (could be optimized by keeping track of all modified parameters)
1757 if (!sync(strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001758
1759 return false;
1760 }
1761 }
1762
1763 // Set Auto sync
1764 _bAutoSyncOn = bAutoSyncOn;
1765
1766 return true;
1767}
1768
1769bool CParameterMgr::autoSyncOn() const
1770{
1771 return _bAutoSyncOn;
1772}
1773
1774// Manual hardware synchronization control (during tuning session)
1775bool CParameterMgr::sync(string& strError)
1776{
1777 // Check tuning mode
1778 if (!checkTuningModeOn(strError)) {
1779
1780 return false;
1781 }
1782 // Warn domains about turning auto sync back on
1783 if (_bAutoSyncOn) {
1784
1785 strError = "Feature unavailable when Auto Sync is on";
1786
1787 return false;
1788 }
1789
1790 // Get syncer set
1791 CSyncerSet syncerSet;
1792 // ... from system class
1793 getConstSystemClass()->fillSyncerSet(syncerSet);
Kevin Rocardace81f82012-12-11 16:19:17 +01001794
Patrick Benavoli68a91282011-08-31 11:23:23 +02001795 // Sync
Kevin Rocardace81f82012-12-11 16:19:17 +01001796 list<string> lstrError;
1797 if (! syncerSet.sync(*_pMainParameterBlackboard, false, &lstrError)){
1798
Frederic Boisnard390b36d2013-05-23 15:28:31 +02001799 CUtility::asString(lstrError, strError);
Kevin Rocardace81f82012-12-11 16:19:17 +01001800 return false;
1801 };
1802
1803 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001804}
1805
1806// Content dump
1807void CParameterMgr::logStructureContent(string& strContent) const
1808{
1809 string strError;
1810
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001811 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001812
1813 dumpContent(strContent, parameterAccessContext);
1814}
1815
1816// Configuration/Domains handling
1817bool CParameterMgr::createDomain(const string& strName, string& strError)
1818{
1819 // Check tuning mode
1820 if (!checkTuningModeOn(strError)) {
1821
1822 return false;
1823 }
1824
1825 // Delegate to configurable domains
1826 return getConfigurableDomains()->createDomain(strName, strError);
1827}
1828
1829bool CParameterMgr::deleteDomain(const string& strName, string& strError)
1830{
1831 // Check tuning mode
1832 if (!checkTuningModeOn(strError)) {
1833
1834 return false;
1835 }
1836
1837 // Delegate to configurable domains
1838 return getConfigurableDomains()->deleteDomain(strName, strError);
1839}
1840
Kevin Rocard170f0a42012-06-18 13:56:05 +02001841bool CParameterMgr::deleteAllDomains(string& strError)
1842{
1843 // Check tuning mode
1844 if (!checkTuningModeOn(strError)) {
1845
1846 return false;
1847 }
1848
1849 // Delegate to configurable domains
1850 getConfigurableDomains()->deleteAllDomains();
1851
1852 return true;
1853}
1854
Patrick Benavoli68a91282011-08-31 11:23:23 +02001855bool CParameterMgr::createConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1856{
1857 // Check tuning mode
1858 if (!checkTuningModeOn(strError)) {
1859
1860 return false;
1861 }
1862
1863 // Delegate to configurable domains
1864 return getConfigurableDomains()->createConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1865}
1866
1867bool CParameterMgr::deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1868{
1869 // Check tuning mode
1870 if (!checkTuningModeOn(strError)) {
1871
1872 return false;
1873 }
1874
1875 // Delegate to configurable domains
1876 return getConfigurableDomains()->deleteConfiguration(strDomain, strConfiguration, strError);
1877}
1878
Kevin Rocardace81f82012-12-11 16:19:17 +01001879bool CParameterMgr::restoreConfiguration(const string& strDomain, const string& strConfiguration, list<string>& lstrError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001880{
Kevin Rocardace81f82012-12-11 16:19:17 +01001881 string strError;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001882 // Check tuning mode
1883 if (!checkTuningModeOn(strError)) {
1884
Kevin Rocardace81f82012-12-11 16:19:17 +01001885 lstrError.push_back(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001886 return false;
1887 }
1888
1889 // Delegate to configurable domains
Kevin Rocardace81f82012-12-11 16:19:17 +01001890 return getConstConfigurableDomains()->restoreConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, lstrError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001891}
1892
1893bool CParameterMgr::saveConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1894{
1895 // Check tuning mode
1896 if (!checkTuningModeOn(strError)) {
1897
1898 return false;
1899 }
1900
1901 // Delegate to configurable domains
1902 return getConfigurableDomains()->saveConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1903}
1904
1905// Configurable element - domain association
1906bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1907{
1908 // Check tuning mode
1909 if (!checkTuningModeOn(strError)) {
1910
1911 return false;
1912 }
1913
1914 CElementLocator elementLocator(getSystemClass());
1915
1916 CElement* pLocatedElement = NULL;
1917
1918 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1919
1920 return false;
1921 }
1922
1923 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001924 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001925
1926 // Delegate
1927 return getConfigurableDomains()->addConfigurableElementToDomain(strDomain, pConfigurableElement, _pMainParameterBlackboard, strError);
1928}
1929
1930bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1931{
1932 // Check tuning mode
1933 if (!checkTuningModeOn(strError)) {
1934
1935 return false;
1936 }
1937
1938 CElementLocator elementLocator(getSystemClass());
1939
1940 CElement* pLocatedElement = NULL;
1941
1942 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1943
Patrick Benavoli63499d42011-10-24 18:50:03 +02001944 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001945 }
1946
1947 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001948 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001949
1950 // Delegate
1951 return getConfigurableDomains()->removeConfigurableElementFromDomain(strDomain, pConfigurableElement, strError);
1952}
1953
1954bool CParameterMgr::split(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1955{
1956 // Check tuning mode
1957 if (!checkTuningModeOn(strError)) {
1958
1959 return false;
1960 }
1961
1962 CElementLocator elementLocator(getSystemClass());
1963
1964 CElement* pLocatedElement = NULL;
1965
1966 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1967
Patrick Benavoli63499d42011-10-24 18:50:03 +02001968 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001969 }
1970
1971 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001972 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001973
1974 // Delegate
1975 return getConfigurableDomains()->split(strDomain, pConfigurableElement, strError);
1976}
1977
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001978bool CParameterMgr::importDomainsXml(const string& strXmlSource, bool bWithSettings,
1979 bool bFromFile, string& strError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001980{
1981 // Check tuning mode
1982 if (!checkTuningModeOn(strError)) {
1983
1984 return false;
1985 }
1986
1987 // check path is absolute
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001988 if (bFromFile && strXmlSource[0] != '/') {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001989
1990 strError = "Please provide absolute path";
1991
1992 return false;
1993 }
1994 // Root element
1995 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1996
1997 // Context
1998 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1999
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002000 // Selection criteria definition for rule creation
2001 xmlDomainSerializingContext.setSelectionCriteriaDefinition(
2002 getConstSelectionCriteria()->getSelectionCriteriaDefinition());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002003
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002004 // Init serializing context
2005 xmlDomainSerializingContext.set(
2006 _pElementLibrarySet->getElementLibrary(EParameterConfigurationLibrary),
2007 "", _strSchemaFolderLocation);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002008
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002009 // Get Schema file associated to root element
2010 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" +
2011 pConfigurableDomains->getKind() + ".xsd";
2012
2013 // Xml Source
2014 CXmlDocSource* pSource;
2015
2016 if (bFromFile) {
2017
2018 // when importing from a file strXmlSource is the file name
2019 pSource = new CXmlFileDocSource(strXmlSource, strXmlSchemaFilePath,
2020 pConfigurableDomains->getKind(),
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +02002021 pConfigurableDomains->getName(), "SystemClassName",
2022 _bValidateSchemasOnStart);
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002023
2024 } else {
2025
2026 // when importing from an xml string, strXmlSource contains the string
2027 pSource = new CXmlStringDocSource(strXmlSource, strXmlSchemaFilePath,
2028 pConfigurableDomains->getKind(),
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +02002029 pConfigurableDomains->getName(), "SystemClassName",
2030 _bValidateSchemasOnStart);
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002031
2032 }
2033 // Start clean
2034 pConfigurableDomains->clean();
2035
2036 // Use a doc sink that instantiate Configurable Domains from the given doc source
2037 CXmlMemoryDocSink memorySink(pConfigurableDomains);
2038
2039 bool bProcessSuccess = memorySink.process(*pSource, xmlDomainSerializingContext);
2040
2041 if (!bProcessSuccess) {
2042
2043 //Cleanup
2044 pConfigurableDomains->clean();
2045
2046 } else {
2047
2048 // Validate domains after XML import
2049 pConfigurableDomains->validate(_pMainParameterBlackboard);
2050
Patrick Benavoli68a91282011-08-31 11:23:23 +02002051 }
2052
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002053 delete pSource;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002054
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002055 return bProcessSuccess;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002056}
2057
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002058bool CParameterMgr::exportDomainsXml(string& strXmlDest, bool bWithSettings, bool bToFile,
2059 string& strError) const
Patrick Benavoli68a91282011-08-31 11:23:23 +02002060{
2061 // check path is absolute
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002062 if (bToFile && strXmlDest[0] != '/') {
Patrick Benavoli68a91282011-08-31 11:23:23 +02002063
2064 strError = "Please provide absolute path";
2065
2066 return false;
2067 }
2068
2069 // Root element
2070 const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains();
2071
2072 // Get Schema file associated to root element
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002073 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" +
2074 pConfigurableDomains->getKind() + ".xsd";
Patrick Benavoli68a91282011-08-31 11:23:23 +02002075
2076 // Context
2077 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
2078
2079 // Value space
2080 xmlDomainSerializingContext.setValueSpaceRaw(_bValueSpaceIsRaw);
2081
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02002082 // Output raw format
2083 xmlDomainSerializingContext.setOutputRawFormat(_bOutputRawFormatIsHex);
2084
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002085 // Use a doc source by loading data from instantiated Configurable Domains
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002086 CXmlMemoryDocSource memorySource(pConfigurableDomains, pConfigurableDomains->getKind(),
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +02002087 strXmlSchemaFilePath, "parameter-framework",
2088 getVersion(), _bValidateSchemasOnStart);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002089
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002090 // Xml Sink
2091 CXmlDocSink* pSink;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002092
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002093 if (bToFile) {
2094
2095 // Use a doc sink to write the doc data in a file
2096 pSink = new CXmlFileDocSink(strXmlDest);
2097
2098 } else {
2099
2100 // Use a doc sink to write the doc data in a string
2101 pSink = new CXmlStringDocSink(strXmlDest);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002102 }
2103
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002104 bool bProcessSuccess = pSink->process(memorySource, xmlDomainSerializingContext);
2105
2106 delete pSink;
2107 return bProcessSuccess;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002108}
2109
2110// Binary Import/Export
2111bool CParameterMgr::importDomainsBinary(const string& strFileName, string& strError)
2112{
2113 // Check tuning mode
2114 if (!checkTuningModeOn(strError)) {
2115
2116 return false;
2117 }
2118 // check path is absolute
2119 if (strFileName[0] != '/') {
2120
2121 strError = "Please provide absolute path";
2122
2123 return false;
2124 }
2125 // Root element
2126 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
2127
2128 // Serialize in
2129 return pConfigurableDomains->serializeSettings(strFileName, false, _uiStructureChecksum, strError);
2130}
2131
2132bool CParameterMgr::exportDomainsBinary(const string& strFileName, string& strError)
2133{
2134 // check path is absolute
2135 if (strFileName[0] != '/') {
2136
2137 strError = "Please provide absolute path";
2138
2139 return false;
2140 }
Patrick Benavoli68a91282011-08-31 11:23:23 +02002141
Patrick Benavoli68a91282011-08-31 11:23:23 +02002142 // Root element
2143 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
2144
2145 // Serialize out
2146 return pConfigurableDomains->serializeSettings(strFileName, true, _uiStructureChecksum, strError);
2147}
2148
2149// For tuning, check we're in tuning mode
2150bool CParameterMgr::checkTuningModeOn(string& strError) const
2151{
2152 // Tuning Mode on?
2153 if (!_bTuningModeIsOn) {
2154
2155 strError = "Tuning Mode must be on";
2156
2157 return false;
2158 }
2159 return true;
2160}
2161
Patrick Benavoli065264a2011-11-20 15:46:41 +01002162// Tuning mutex dynamic parameter handling
2163pthread_mutex_t* CParameterMgr::getBlackboardMutex()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002164{
Patrick Benavoli065264a2011-11-20 15:46:41 +01002165 return &_blackboardMutex;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002166}
2167
Patrick Benavoli065264a2011-11-20 15:46:41 +01002168// Blackboard reference (dynamic parameter handling)
2169CParameterBlackboard* CParameterMgr::getParameterBlackboard()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002170{
Patrick Benavoli065264a2011-11-20 15:46:41 +01002171 return _pMainParameterBlackboard;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002172}
2173
Patrick Benavoli68a91282011-08-31 11:23:23 +02002174// Dynamic creation library feeding
2175void CParameterMgr::feedElementLibraries()
2176{
2177 // Global Configuration handling
2178 CElementLibrary* pFrameworkConfigurationLibrary = new CElementLibrary;
2179
Kevin Rocarda7b69602013-08-07 16:15:33 +02002180 pFrameworkConfigurationLibrary->addElementBuilder("ParameterFrameworkConfiguration", new TElementBuilderTemplate<CParameterFrameworkConfiguration>());
2181 pFrameworkConfigurationLibrary->addElementBuilder("SubsystemPlugins", new TKindElementBuilderTemplate<CSubsystemPlugins>());
2182 pFrameworkConfigurationLibrary->addElementBuilder("Location", new TKindElementBuilderTemplate<CPluginLocation>());
2183 pFrameworkConfigurationLibrary->addElementBuilder("StructureDescriptionFileLocation", new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>());
2184 pFrameworkConfigurationLibrary->addElementBuilder("SettingsConfiguration", new TKindElementBuilderTemplate<CFrameworkConfigurationGroup>());
2185 pFrameworkConfigurationLibrary->addElementBuilder("ConfigurableDomainsFileLocation", new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>());
2186 pFrameworkConfigurationLibrary->addElementBuilder("BinarySettingsFileLocation", new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002187
2188 _pElementLibrarySet->addElementLibrary(pFrameworkConfigurationLibrary);
2189
2190 // Parameter creation
2191 CElementLibrary* pParameterCreationLibrary = new CElementLibrary;
2192
Kevin Rocarda7b69602013-08-07 16:15:33 +02002193 pParameterCreationLibrary->addElementBuilder("Subsystem", new CSubsystemElementBuilder(getSystemClass()->getSubsystemLibrary()));
2194 pParameterCreationLibrary->addElementBuilder("ComponentType", new TNamedElementBuilderTemplate<CComponentType>());
2195 pParameterCreationLibrary->addElementBuilder("Component", new TNamedElementBuilderTemplate<CComponentInstance>());
2196 pParameterCreationLibrary->addElementBuilder("BitParameter", new TNamedElementBuilderTemplate<CBitParameterType>());
2197 pParameterCreationLibrary->addElementBuilder("BitParameterBlock", new TNamedElementBuilderTemplate<CBitParameterBlockType>());
2198 pParameterCreationLibrary->addElementBuilder("StringParameter", new TNamedElementBuilderTemplate<CStringParameterType>());
2199 pParameterCreationLibrary->addElementBuilder("ParameterBlock", new TNamedElementBuilderTemplate<CParameterBlockType>());
2200 pParameterCreationLibrary->addElementBuilder("BooleanParameter", new TNamedElementBuilderTemplate<CBooleanParameterType>());
2201 pParameterCreationLibrary->addElementBuilder("IntegerParameter", new TNamedElementBuilderTemplate<CIntegerParameterType>());
2202 pParameterCreationLibrary->addElementBuilder("LinearAdaptation", new TElementBuilderTemplate<CLinearParameterAdaptation>());
2203 pParameterCreationLibrary->addElementBuilder("EnumParameter", new TNamedElementBuilderTemplate<CEnumParameterType>());
2204 pParameterCreationLibrary->addElementBuilder("ValuePair", new TElementBuilderTemplate<CEnumValuePair>());
2205 pParameterCreationLibrary->addElementBuilder("FixedPointParameter", new TNamedElementBuilderTemplate<CFixedPointParameterType>());
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +02002206 pParameterCreationLibrary->addElementBuilder("SubsystemInclude", new CFileIncluderElementBuilder(_bValidateSchemasOnStart));
Patrick Benavoli68a91282011-08-31 11:23:23 +02002207
2208 _pElementLibrarySet->addElementLibrary(pParameterCreationLibrary);
2209
2210 // Parameter Configuration Domains creation
2211 CElementLibrary* pParameterConfigurationLibrary = new CElementLibrary;
2212
Kevin Rocarda7b69602013-08-07 16:15:33 +02002213 pParameterConfigurationLibrary->addElementBuilder("ConfigurableDomain", new TNamedElementBuilderTemplate<CConfigurableDomain>());
2214 pParameterConfigurationLibrary->addElementBuilder("Configuration", new TNamedElementBuilderTemplate<CDomainConfiguration>());
2215 pParameterConfigurationLibrary->addElementBuilder("CompoundRule", new TElementBuilderTemplate<CCompoundRule>());
2216 pParameterConfigurationLibrary->addElementBuilder("SelectionCriterionRule", new TElementBuilderTemplate<CSelectionCriterionRule>());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002217
2218 _pElementLibrarySet->addElementLibrary(pParameterConfigurationLibrary);
2219}
2220
2221// Remote Processor Server connection handling
2222bool CParameterMgr::handleRemoteProcessingInterface(string& strError)
2223{
2224 CAutoLog autoLog(this, "Handling remote processing interface");
2225
2226 // Start server if tuning allowed
Patrick Benavoli95ac0342011-11-07 20:32:51 +01002227 if (getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02002228
Kevin Rocardace81f82012-12-11 16:19:17 +01002229 log_info("Loading remote processor library");
Patrick Benavoli68a91282011-08-31 11:23:23 +02002230
2231 // Load library
Renaud de Chivre1b8b3ca2013-12-13 15:09:44 +01002232 _handleLibRemoteProcessor = dlopen("libremote-processor.so", RTLD_NOW);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002233
Renaud de Chivre1b8b3ca2013-12-13 15:09:44 +01002234 if (!_handleLibRemoteProcessor) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02002235
2236 // Return error
2237 const char* pcError = dlerror();
2238
2239 if (pcError) {
2240
2241 strError = pcError;
2242 } else {
2243
2244 strError = "Unable to load libremote-processor.so library";
2245 }
2246
2247 return false;
2248 }
2249
Renaud de Chivre1b8b3ca2013-12-13 15:09:44 +01002250 CreateRemoteProcessorServer pfnCreateRemoteProcessorServer = (CreateRemoteProcessorServer)dlsym(_handleLibRemoteProcessor, "createRemoteProcessorServer");
Patrick Benavoli68a91282011-08-31 11:23:23 +02002251
2252 if (!pfnCreateRemoteProcessorServer) {
2253
2254 strError = "libremote-process.so does not contain createRemoteProcessorServer symbol.";
2255
2256 return false;
2257 }
2258
2259 // Create server
Patrick Benavoli95ac0342011-11-07 20:32:51 +01002260 _pRemoteProcessorServer = pfnCreateRemoteProcessorServer(getConstFrameworkConfiguration()->getServerPort(), _pCommandHandler);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002261
Kevin Rocardace81f82012-12-11 16:19:17 +01002262 log_info("Starting remote processor server on port %d", getConstFrameworkConfiguration()->getServerPort());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002263 // Start
2264 if (!_pRemoteProcessorServer->start()) {
2265
Frédéric Boisnard6c55e9a2014-01-10 18:46:33 +01002266 ostringstream oss;
2267 oss << "ParameterMgr: Unable to start remote processor server on port "
2268 << getConstFrameworkConfiguration()->getServerPort();
2269 strError = oss.str();
Patrick Benavoli68a91282011-08-31 11:23:23 +02002270
2271 return false;
2272 }
2273 }
2274
2275 return true;
2276}
2277
2278// Back synchronization
Kevin Rocardace81f82012-12-11 16:19:17 +01002279CBackSynchronizer* CParameterMgr::createBackSynchronizer() const
Patrick Benavoli68a91282011-08-31 11:23:23 +02002280{
2281#ifdef SIMULATION
2282 // In simulation, back synchronization of the blackboard won't probably work
2283 // We need to ensure though the blackboard is initialized with valid data
Kevin Rocardace81f82012-12-11 16:19:17 +01002284 return new CSimulatedBackSynchronizer(getConstSystemClass(), _pMainParameterBlackboard);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002285#else
2286 // Real back synchronizer from subsystems
Kevin Rocardace81f82012-12-11 16:19:17 +01002287 return new CHardwareBackSynchronizer(getConstSystemClass(), _pMainParameterBlackboard);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002288#endif
2289}
2290
2291// Children typwise access
2292CParameterFrameworkConfiguration* CParameterMgr::getFrameworkConfiguration()
2293{
2294 return static_cast<CParameterFrameworkConfiguration*>(getChild(EFrameworkConfiguration));
2295}
2296
2297const CParameterFrameworkConfiguration* CParameterMgr::getConstFrameworkConfiguration()
2298{
2299 return getFrameworkConfiguration();
2300}
2301
2302CSelectionCriteria* CParameterMgr::getSelectionCriteria()
2303{
2304 return static_cast<CSelectionCriteria*>(getChild(ESelectionCriteria));
2305}
2306
2307const CSelectionCriteria* CParameterMgr::getConstSelectionCriteria()
2308{
2309 return static_cast<const CSelectionCriteria*>(getChild(ESelectionCriteria));
2310}
2311
2312CSystemClass* CParameterMgr::getSystemClass()
2313{
2314 return static_cast<CSystemClass*>(getChild(ESystemClass));
2315}
2316
2317const CSystemClass* CParameterMgr::getConstSystemClass() const
2318{
2319 return static_cast<const CSystemClass*>(getChild(ESystemClass));
2320}
2321
2322// Configurable Domains
2323CConfigurableDomains* CParameterMgr::getConfigurableDomains()
2324{
2325 return static_cast<CConfigurableDomains*>(getChild(EConfigurableDomains));
2326}
2327
2328const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains()
2329{
2330 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
2331}
2332
2333const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains() const
2334{
2335 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
2336}
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002337
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01002338// Apply configurations
2339void CParameterMgr::doApplyConfigurations(bool bForce)
2340{
2341 CSyncerSet syncerSet;
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002342
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01002343 // Check subsystems that need resync
2344 getSystemClass()->checkForSubsystemsToResync(syncerSet);
2345
2346 // Ensure application of currently selected configurations
2347 getConfigurableDomains()->apply(_pMainParameterBlackboard, syncerSet, bForce);
2348
2349 // Reset the modified status of the current criteria to indicate that a new configuration has been applied
2350 getSelectionCriteria()->resetModifiedStatus();
2351}
2352
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002353bool CParameterMgr::getSystemClassXMLString(string& strResult)
2354{
2355 // Root element
2356 const CSystemClass* pSystemClass = getSystemClass();
2357
2358 string strError;
2359
2360 CXmlSerializingContext xmlSerializingContext(strError);
2361
2362 // Use a doc source by loading data from instantiated Configurable Domains
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +02002363 CXmlMemoryDocSource memorySource(pSystemClass, pSystemClass->getKind(),
2364 _bValidateSchemasOnStart);
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002365
2366 // Use a doc sink that write the doc data in a string
2367 CXmlStringDocSink stringSink(strResult);
2368
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002369 bool bProcessSuccess = stringSink.process(memorySource, xmlSerializingContext);
2370
2371 if (!bProcessSuccess) {
2372
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002373 strResult = strError;
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002374
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002375 }
2376
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002377 return bProcessSuccess;
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002378}