blob: f2d30e2bc0b8a9a31952c2f5ef4e8aadff9a0132 [file] [log] [blame]
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +02001 /*
Patrick Benavoli68a91282011-08-31 11:23:23 +02002 * INTEL CONFIDENTIAL
3 * Copyright © 2011 Intel
4 * Corporation All Rights Reserved.
5 *
6 * The source code contained or described herein and all documents related to
7 * the source code ("Material") are owned by Intel Corporation or its suppliers
8 * or licensors. Title to the Material remains with Intel Corporation or its
9 * suppliers and licensors. The Material contains trade secrets and proprietary
10 * and confidential information of Intel or its suppliers and licensors. The
11 * Material is protected by worldwide copyright and trade secret laws and
12 * treaty provisions. No part of the Material may be used, copied, reproduced,
13 * modified, published, uploaded, posted, transmitted, distributed, or
14 * disclosed in any way without Intel’s prior express written permission.
15 *
16 * No license under any patent, copyright, trade secret or other intellectual
17 * property right is granted to or conferred upon you by disclosure or delivery
18 * of the Materials, either expressly, by implication, inducement, estoppel or
19 * otherwise. Any license under such intellectual property rights must be
20 * express and approved by Intel in writing.
21 *
Patrick Benavoli68a91282011-08-31 11:23:23 +020022 * CREATED: 2011-06-01
23 * UPDATED: 2011-07-27
Patrick Benavoli68a91282011-08-31 11:23:23 +020024 */
25#include "ParameterMgr.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020026#include "XmlParameterSerializingContext.h"
27#include "XmlElementSerializingContext.h"
28#include "SystemClass.h"
29#include "ElementLibrarySet.h"
30#include "SubsystemLibrary.h"
31#include "NamedElementBuilderTemplate.h"
32#include "KindElementBuilderTemplate.h"
33#include "ElementBuilderTemplate.h"
34#include "SelectionCriterionType.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020035#include "SubsystemElementBuilder.h"
36#include "SelectionCriteria.h"
37#include "ComponentType.h"
38#include "ComponentInstance.h"
39#include "ParameterBlockType.h"
40#include "BooleanParameterType.h"
41#include "IntegerParameterType.h"
42#include "FixedPointParameterType.h"
43#include "ParameterBlackboard.h"
44#include "Parameter.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020045#include "ParameterAccessContext.h"
46#include "XmlFileIncluderElement.h"
47#include "ParameterFrameworkConfiguration.h"
48#include "FrameworkConfigurationGroup.h"
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +010049#include "PluginLocation.h"
50#include "SubsystemPlugins.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020051#include "FrameworkConfigurationLocation.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020052#include "ConfigurableDomains.h"
53#include "ConfigurableDomain.h"
54#include "DomainConfiguration.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020055#include "XmlDomainSerializingContext.h"
56#include "BitParameterBlockType.h"
57#include "BitParameterType.h"
Patrick Benavoli1352ae52011-10-21 16:48:04 +020058#include "StringParameterType.h"
Patrick Benavoli9fc3c0d2011-10-27 14:27:27 +020059#include "EnumParameterType.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020060#include "RemoteProcessorServerInterface.h"
61#include "ElementLocator.h"
62#include "AutoLog.h"
63#include "CompoundRule.h"
64#include "SelectionCriterionRule.h"
65#include "SimulatedBackSynchronizer.h"
66#include "HardwareBackSynchronizer.h"
Patrick Benavoli1387bda2011-08-31 11:23:24 +020067#include "AutoLock.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020068#include <strings.h>
69#include <dlfcn.h>
70#include <assert.h>
Patrick Benavoli065264a2011-11-20 15:46:41 +010071#include "ParameterHandle.h"
Patrick Benavoliee65e6d2011-11-20 18:52:24 +010072#include "LinearParameterAdaptation.h"
Patrick Benavoli68808c62012-02-02 17:12:41 +010073#include "EnumValuePair.h"
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +020074#include "Subsystem.h"
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020075#include "XmlFileDocSink.h"
76#include "XmlFileDocSource.h"
77#include "XmlStringDocSink.h"
Georges-Henri Baroncec86c12012-09-04 17:30:28 +020078#include "XmlStringDocSource.h"
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020079#include "XmlMemoryDocSink.h"
80#include "XmlMemoryDocSource.h"
Kevin Rocardace81f82012-12-11 16:19:17 +010081#include "Utility.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020082
83#define base CElement
84
85// Used for remote processor server creation
86typedef IRemoteProcessorServerInterface* (*CreateRemoteProcessorServer)(uint16_t uiPort, IRemoteCommandHandler* pCommandHandler);
87
88// Global configuration file name (fixed)
89const char* gacParameterFrameworkConfigurationFileName = "ParameterFrameworkConfiguration.xml";
90const char* gacSystemSchemasSubFolder = "Schemas";
91
92// Config File System looks normally like this:
93// ---------------------------------------------
Patrick Benavoli95ac0342011-11-07 20:32:51 +010094//├── <ParameterFrameworkConfiguration>.xml
Patrick Benavoli68a91282011-08-31 11:23:23 +020095//├── Schemas
96//│ └── *.xsd
97//├── Settings
98//│ └── <SystemClassName folder>*
99//│ ├── <ConfigurableDomains>.xml
100//│ └── <Settings>.bin?
101//└── Structure
102// └── <SystemClassName folder>*
103// ├── <SystemClassName>Class.xml
104// └── <Subsystem>.xml*
105// --------------------------------------------
106
107
108// Remote command parser array
Patrick Benavoli592ae562011-09-05 16:53:58 +0200109const CParameterMgr::SRemoteCommandParserItem CParameterMgr::gastRemoteCommandParserItems[] = {
Kevin Rocard3949b342013-05-24 18:43:53 +0200110
Patrick Benavoli592ae562011-09-05 16:53:58 +0200111 /// Version
Kevin Rocard3949b342013-05-24 18:43:53 +0200112 { "version", &CParameterMgr::versionCommandProcess, 0,
113 "", "Show version" },
114
Patrick Benavoli68a91282011-08-31 11:23:23 +0200115 /// Status
Kevin Rocard3949b342013-05-24 18:43:53 +0200116 { "status", &CParameterMgr::statusCommandProcess, 0, "",
117 "Show current status" },
118
Patrick Benavoli68a91282011-08-31 11:23:23 +0200119 /// Tuning Mode
Kevin Rocard3949b342013-05-24 18:43:53 +0200120 { "setTuningMode", &CParameterMgr::setTuningModeCommmandProcess, 1,
121 "on|off*", "Turn on or off Tuning Mode" },
122 { "getTuningMode", &CParameterMgr::getTuningModeCommmandProcess, 0,
123 "", "Show Tuning Mode" },
124
Patrick Benavoli68a91282011-08-31 11:23:23 +0200125 /// Value Space
Kevin Rocard3949b342013-05-24 18:43:53 +0200126 { "setValueSpace", &CParameterMgr::setValueSpaceCommmandProcess, 1,
127 "raw|real*", "Assigns Value Space used for parameter value interpretation" },
128 { "getValueSpace", &CParameterMgr::getValueSpaceCommmandProcess, 0,
129 "", "Show Value Space" },
130
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200131 /// Output Raw Format
Kevin Rocard3949b342013-05-24 18:43:53 +0200132 { "setOutputRawFormat", &CParameterMgr::setOutputRawFormatCommmandProcess, 1,
133 "dec*|hex", "Assigns format used to output parameter values when in raw Value Space" },
134 { "getOutputRawFormat", &CParameterMgr::getOutputRawFormatCommmandProcess, 0,
135 "", "Show Output Raw Format" },
136
Patrick Benavoli68a91282011-08-31 11:23:23 +0200137 /// Sync
Kevin Rocard3949b342013-05-24 18:43:53 +0200138 { "setAutoSync", &CParameterMgr::setAutoSyncCommmandProcess, 1,
139 "on*|off", "Turn on or off automatic synchronization to hardware while in Tuning Mode" },
140 { "getAutoSync", &CParameterMgr::getAutoSyncCommmandProcess, 0,
141 "", "Show Auto Sync state" },
142 { "sync", &CParameterMgr::syncCommmandProcess, 0,
143 "", "Synchronize current settings to hardware while in Tuning Mode and Auto Sync off" },
144
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200145 /// Criteria
Kevin Rocard3949b342013-05-24 18:43:53 +0200146 { "listCriteria", &CParameterMgr::listCriteriaCommmandProcess, 0,
147 "[csv]", "List selection criteria" },
148
Patrick Benavoli68a91282011-08-31 11:23:23 +0200149 /// Domains
Kevin Rocard3949b342013-05-24 18:43:53 +0200150 { "listDomains", &CParameterMgr::listDomainsCommmandProcess, 0,
151 "", "List configurable domains" },
152 { "dumpDomains", &CParameterMgr::dumpDomainsCommmandProcess, 0,
153 "", "Show all domains and configurations, including applicability conditions" },
154 { "createDomain", &CParameterMgr::createDomainCommmandProcess, 1,
155 "<domain>", "Create new configurable domain" },
156 { "deleteDomain", &CParameterMgr::deleteDomainCommmandProcess, 1,
157 "<domain>", "Delete configurable domain" },
158 { "deleteAllDomains", &CParameterMgr::deleteAllDomainsCommmandProcess, 0,
159 "", "Delete all configurable domains" },
160 { "renameDomain", &CParameterMgr::renameDomainCommmandProcess, 2,
161 "<domain> <new name>", "Rename configurable domain" },
162 { "setSequenceAwareness", &CParameterMgr::setSequenceAwarenessCommmandProcess, 1,
163 "<domain> true|false*", "Set configurable domain sequence awareness" },
164 { "getSequenceAwareness", &CParameterMgr::getSequenceAwarenessCommmandProcess, 1,
165 "<domain>", "Get configurable domain sequence awareness" },
166 { "listDomainElements", &CParameterMgr::listDomainElementsCommmandProcess, 1,
167 "<domain>", "List elements associated to configurable domain" },
168 { "addElement", &CParameterMgr::addElementCommmandProcess, 2,
169 "<domain> <elem path>", "Associate element at given path to configurable domain" },
170 { "removeElement", &CParameterMgr::removeElementCommmandProcess, 2,
171 "<domain> <elem path>", "Dissociate element at given path from configurable domain" },
172 { "splitDomain", &CParameterMgr::splitDomainCommmandProcess, 2,
173 "<domain> <elem path>", "Split configurable domain at given associated element path" },
174
Patrick Benavoli68a91282011-08-31 11:23:23 +0200175 /// Configurations
Kevin Rocard3949b342013-05-24 18:43:53 +0200176 { "listConfigurations", &CParameterMgr::listConfigurationsCommmandProcess, 1,
177 "<domain>", "List domain configurations" },
178 { "createConfiguration", &CParameterMgr::createConfigurationCommmandProcess, 2,
179 "<domain> <configuration>", "Create new domain configuration" },
180 { "deleteConfiguration", &CParameterMgr::deleteConfigurationCommmandProcess, 2,
181 "<domain> <configuration>", "Delete domain configuration" },
182 { "renameConfiguration", &CParameterMgr::renameConfigurationCommmandProcess, 3,
183 "<domain> <configuration> <new name>", "Rename domain configuration" },
184 { "saveConfiguration", &CParameterMgr::saveConfigurationCommmandProcess, 2,
185 "<domain> <configuration>", "Save current settings into configuration" },
186 { "restoreConfiguration", &CParameterMgr::restoreConfigurationCommmandProcess, 2,
187 "<domain> <configuration>", "Restore current settings from configuration" },
188 { "setElementSequence", &CParameterMgr::setElementSequenceCommmandProcess, 3,
189 "<domain> <configuration> <elem path list>",
190 "Set element application order for configuration" },
191 { "getElementSequence", &CParameterMgr::getElementSequenceCommmandProcess, 2,
192 "<domain> <configuration>", "Get element application order for configuration" },
193 { "setRule", &CParameterMgr::setRuleCommmandProcess, 3,
194 "<domain> <configuration> <rule>", "Set configuration application rule" },
195 { "clearRule", &CParameterMgr::clearRuleCommmandProcess, 2,
196 "<domain> <configuration>", "Clear configuration application rule" },
197 { "getRule", &CParameterMgr::getRuleCommmandProcess, 2,
198 "<domain> <configuration>", "Get configuration application rule" },
199
Patrick Benavoli68a91282011-08-31 11:23:23 +0200200 /// Elements/Parameters
Kevin Rocard3949b342013-05-24 18:43:53 +0200201 { "listElements", &CParameterMgr::listElementsCommmandProcess, 1,
202 "<elem path>|/", "List elements under element at given path or root" },
203 { "listParameters", &CParameterMgr::listParametersCommmandProcess, 1,
204 "<elem path>|/", "List parameters under element at given path or root" },
205 { "dumpElement", &CParameterMgr::dumpElementCommmandProcess, 1,
206 "<elem path>", "Dump structure and content of element at given path" },
207 { "getElementSize", &CParameterMgr::getElementSizeCommmandProcess, 1,
208 "<elem path>", "Show size of element at given path" },
209 { "showProperties", &CParameterMgr::showPropertiesCommmandProcess, 1,
210 "<elem path>", "Show properties of element at given path" },
211 { "getParameter", &CParameterMgr::getParameterCommmandProcess, 1,
212 "<param path>", "Get value for parameter at given path" },
213 { "setParameter", &CParameterMgr::setParameterCommmandProcess, 2,
214 "<param path> <value>", "Set value for parameter at given path" },
215 { "listBelongingDomains", &CParameterMgr::listBelongingDomainsCommmandProcess, 1,
216 "<elem path>", "List domain(s) element at given path belongs to" },
217 { "listAssociatedDomains", &CParameterMgr::listAssociatedDomainsCommmandProcess, 1,
218 "<elem path>", "List domain(s) element at given path is associated to" },
219 { "getConfigurationParameter", &CParameterMgr::getConfigurationParameterCommmandProcess, 3,
220 "<domain> <configuration> <param path>",
221 "Get value for parameter at given path from configuration" },
222 { "setConfigurationParameter", &CParameterMgr::setConfigurationParameterCommmandProcess, 4,
223 "<domain> <configuration> <param path> <value>",
224 "Set value for parameter at given path to configuration" },
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200225 { "showMapping", &CParameterMgr::showMappingCommmandProcess, 1,
226 "<elem path>", "Show mapping for an element at given path" },
Kevin Rocard3949b342013-05-24 18:43:53 +0200227
Patrick Benavoli68a91282011-08-31 11:23:23 +0200228 /// Browse
Kevin Rocard3949b342013-05-24 18:43:53 +0200229 { "listAssociatedElements", &CParameterMgr::listAssociatedElementsCommmandProcess, 0,
230 "", "List element sub-trees associated to at least one configurable domain" },
231 { "listConflictingElements", &CParameterMgr::listConflictingElementsCommmandProcess, 0,
232 "", "List element sub-trees contained in more than one configurable domain" },
233 { "listRogueElements", &CParameterMgr::listRogueElementsCommmandProcess, 0,
234 "", "List element sub-trees owned by no configurable domain" },
235
Patrick Benavoli68a91282011-08-31 11:23:23 +0200236 /// Settings Import/Export
Kevin Rocard3949b342013-05-24 18:43:53 +0200237 { "exportDomainsXML", &CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess, 1,
238 "<file path> ", "Export domains to XML file" },
239 { "importDomainsXML", &CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess, 1,
240 "<file path>", "Import domains from XML file" },
241 { "exportDomainsWithSettingsXML",
242 &CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess, 1,
243 "<file path> ", "Export domains including settings to XML file" },
244 { "importDomainsWithSettingsXML",
245 &CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess, 1,
246 "<file path>", "Import domains including settings from XML file" },
247 { "exportSettings", &CParameterMgr::exportSettingsCommmandProcess, 1,
248 "<file path>", "Export settings to binary file" },
249 { "importSettings", &CParameterMgr::importSettingsCommmandProcess, 1,
250 "<file path>", "Import settings from binary file" },
Georges-Henri Baroncec86c12012-09-04 17:30:28 +0200251 { "getDomainsWithSettingsXML",
252 &CParameterMgr::getConfigurableDomainsWithSettingsXMLCommmandProcess, 0,
Kevin Rocard3949b342013-05-24 18:43:53 +0200253 "", "Print domains including settings as XML" },
Georges-Henri Baroncec86c12012-09-04 17:30:28 +0200254 { "setDomainsWithSettingsXML",
255 &CParameterMgr::setConfigurableDomainsWithSettingsXMLCommmandProcess, 1,
256 "<xml configurable domains>", "Import domains including settings from XML string" },
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200257 /// Structure Export
Kevin Rocard3949b342013-05-24 18:43:53 +0200258 { "getSystemClassXML", &CParameterMgr::getSystemClassXMLCommmandProcess, 0 ,
Kevin Rocardc0211572013-06-18 11:34:53 +0200259 "", "Print parameter structure as XML" },
260 /// Deprecated Commands
261 { "getDomainsXML",
262 &CParameterMgr::getConfigurableDomainsWithSettingsXMLCommmandProcess, 0,
263 "", "DEPRECATED COMMAND, please use getDomainsWithSettingsXML" },
Georges-Henri Baroncec86c12012-09-04 17:30:28 +0200264
Patrick Benavoli68a91282011-08-31 11:23:23 +0200265};
Kevin Rocard3949b342013-05-24 18:43:53 +0200266
Patrick Benavoli68a91282011-08-31 11:23:23 +0200267// Remote command parsers array Size
Patrick Benavoli592ae562011-09-05 16:53:58 +0200268const uint32_t CParameterMgr::guiNbRemoteCommandParserItems = sizeof(gastRemoteCommandParserItems) / sizeof(gastRemoteCommandParserItems[0]);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200269
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100270CParameterMgr::CParameterMgr(const string& strConfigurationFilePath) :
Patrick Benavoli68a91282011-08-31 11:23:23 +0200271 _bTuningModeIsOn(false),
272 _bValueSpaceIsRaw(false),
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200273 _bOutputRawFormatIsHex(false),
Patrick Benavoli68a91282011-08-31 11:23:23 +0200274 _bAutoSyncOn(true),
275 _pMainParameterBlackboard(new CParameterBlackboard),
276 _pElementLibrarySet(new CElementLibrarySet),
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100277 _strXmlConfigurationFilePath(strConfigurationFilePath),
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100278 _pSubsystemPlugins(NULL),
Patrick Benavoli68a91282011-08-31 11:23:23 +0200279 _uiStructureChecksum(0),
280 _pRemoteProcessorServer(NULL),
281 _uiMaxCommandUsageLength(0),
282 _pLogger(NULL),
283 _uiLogDepth(0)
284{
285 // Tuning Mode Mutex
Patrick Benavoli065264a2011-11-20 15:46:41 +0100286 bzero(&_blackboardMutex, sizeof(_blackboardMutex));
287 pthread_mutex_init(&_blackboardMutex, NULL);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200288
289 // Deal with children
290 addChild(new CParameterFrameworkConfiguration);
291 addChild(new CSelectionCriteria);
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100292 addChild(new CSystemClass);
293 addChild(new CConfigurableDomains);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200294
295 // Feed element library
296 feedElementLibraries();
Patrick Benavoli63499d42011-10-24 18:50:03 +0200297
298 _pCommandHandler = new CCommandHandler(this);
299
300 // Add command parsers
301 uint32_t uiRemoteCommandParserItem;
302
303 for (uiRemoteCommandParserItem = 0; uiRemoteCommandParserItem < guiNbRemoteCommandParserItems; uiRemoteCommandParserItem++) {
304
305 const SRemoteCommandParserItem* pRemoteCommandParserItem = &gastRemoteCommandParserItems[uiRemoteCommandParserItem];
306
307 _pCommandHandler->addCommandParser(pRemoteCommandParserItem->_pcCommandName,
308 pRemoteCommandParserItem->_pfnParser,
309 pRemoteCommandParserItem->_uiMinArgumentCount,
310 pRemoteCommandParserItem->_pcHelp,
311 pRemoteCommandParserItem->_pcDescription);
312 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100313
314 // Configuration file folder
315 uint32_t uiSlashPos = _strXmlConfigurationFilePath.rfind('/', -1);
316
317 assert(uiSlashPos != (uint32_t)-1);
318
319 _strXmlConfigurationFolderPath = _strXmlConfigurationFilePath.substr(0, uiSlashPos);
320
321 // Schema absolute folder location
322 _strSchemaFolderLocation = _strXmlConfigurationFolderPath + "/" + gacSystemSchemasSubFolder;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200323}
324
325CParameterMgr::~CParameterMgr()
326{
327 // Children
328 delete _pRemoteProcessorServer;
Frederic Boisnard31242302012-04-26 17:07:34 +0200329 delete _pCommandHandler;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200330 delete _pMainParameterBlackboard;
331 delete _pElementLibrarySet;
332
333 // Tuning Mode Mutex
Patrick Benavoli065264a2011-11-20 15:46:41 +0100334 pthread_mutex_destroy(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200335}
336
337string CParameterMgr::getKind() const
338{
339 return "ParameterMgr";
340}
341
342// Logging
343void CParameterMgr::setLogger(CParameterMgr::ILogger* pLogger)
344{
345 _pLogger = pLogger;
346}
347
348// Logging
Kevin Rocardace81f82012-12-11 16:19:17 +0100349void CParameterMgr::doLog(bool bIsWarning, const string& strLog) const
Patrick Benavoli68a91282011-08-31 11:23:23 +0200350{
351 if (_pLogger) {
352
353 // Nest
354 string strIndent;
355
356 // Level
357 uint32_t uiNbIndents = _uiLogDepth;
358
359 while (uiNbIndents--) {
360
361 strIndent += " ";
362 }
363
364 // Log
Kevin Rocardace81f82012-12-11 16:19:17 +0100365 _pLogger->log(bIsWarning, strIndent + strLog);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200366 }
367}
368
369void CParameterMgr::nestLog() const
370{
Patrick Benavoli592ae562011-09-05 16:53:58 +0200371 _uiLogDepth++;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200372}
373
374void CParameterMgr::unnestLog() const
375{
Patrick Benavoli592ae562011-09-05 16:53:58 +0200376 _uiLogDepth--;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200377}
378
Patrick Benavoli63499d42011-10-24 18:50:03 +0200379// Version
380string CParameterMgr::getVersion() const
381{
382 string strVersion;
383
384 // Major
385 strVersion = toString(guiEditionMajor) + ".";
386 // Minor
387 strVersion += toString(guiEditionMinor) + ".";
388 // Revision
389 strVersion += toString(guiRevision);
390
391 return strVersion;
392}
393
Patrick Benavoli68a91282011-08-31 11:23:23 +0200394bool CParameterMgr::load(string& strError)
395{
396 CAutoLog autoLog(this, "Loading");
397
398 // Load Framework configuration
399 if (!loadFrameworkConfiguration(strError)) {
400
401 return false;
402 }
403
404 // Load subsystems
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100405 if (!getSystemClass()->loadSubsystems(strError, _pSubsystemPlugins)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200406
407 return false;
408 }
409
410 // Load structure
411 if (!loadStructure(strError)) {
412
413 return false;
414 }
415
416 // Load settings
417 if (!loadSettings(strError)) {
418
419 return false;
420 }
421
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200422 // Back synchronization for areas in parameter blackboard not covered by any domain
Kevin Rocardace81f82012-12-11 16:19:17 +0100423 CBackSynchronizer* pBackSynchronizer = createBackSynchronizer();
Patrick Benavoli68a91282011-08-31 11:23:23 +0200424
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200425 // Back-synchronize
Kevin Rocard57096bd2012-11-30 11:24:20 +0100426 {
427 CAutoLog autoLog(this, "Main blackboard back synchronization");
428
Kevin Rocard5d6e05a2013-01-21 15:57:45 +0100429 pBackSynchronizer->sync();
Kevin Rocard57096bd2012-11-30 11:24:20 +0100430
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200431 // Get rid of back synchronizer
432 delete pBackSynchronizer;
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200433 }
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200434
435 // We're done loading the settings and back synchronizing
436 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
437
438 // We need to ensure all domains are valid
439 pConfigurableDomains->validate(_pMainParameterBlackboard);
440
Kevin Rocard7f265822012-12-07 18:51:22 +0100441 // Log selection criterion states
442 {
443 CAutoLog autoLog(this, "Criterion states");
444
445 const CSelectionCriteria* selectionCriteria = getConstSelectionCriteria();
446
447 list<string> lstrSelectionCriteron;
448 selectionCriteria->listSelectionCriteria(lstrSelectionCriteron, true, false);
449
Kevin Rocard36299362013-02-04 14:57:47 +0100450 log_table(false, lstrSelectionCriteron);
Kevin Rocard7f265822012-12-07 18:51:22 +0100451 }
452
Kevin Rocard2fbe6e82013-03-26 17:09:29 +0100453 // Subsystem can not ask for resync as they have not been synced yet
454 getSystemClass()->cleanSubsystemsNeedToResync();
455
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100456 // At initialization, check subsystems that need resync
457 doApplyConfigurations(true);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200458
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200459 // Start remote processor server if appropriate
460 return handleRemoteProcessingInterface(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200461}
462
463bool CParameterMgr::loadFrameworkConfiguration(string& strError)
464{
465 CAutoLog autoLog(this, "Loading framework configuration");
466
Patrick Benavoli68a91282011-08-31 11:23:23 +0200467 // Parse Structure XML file
468 CXmlElementSerializingContext elementSerializingContext(strError);
469
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100470 if (!xmlParse(elementSerializingContext, getFrameworkConfiguration(), _strXmlConfigurationFilePath, _strXmlConfigurationFolderPath, EFrameworkConfigurationLibrary)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200471
472 return false;
473 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100474 // Set class name to system class and configurable domains
475 getSystemClass()->setName(getConstFrameworkConfiguration()->getSystemClassName());
476 getConfigurableDomains()->setName(getConstFrameworkConfiguration()->getSystemClassName());
477
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100478 // Get subsystem plugins elements
479 _pSubsystemPlugins = static_cast<const CSubsystemPlugins*>(getConstFrameworkConfiguration()->findChild("SubsystemPlugins"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200480
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100481 if (!_pSubsystemPlugins) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200482
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100483 strError = "Parameter Framework Configuration: couldn't find SubsystemPlugins element";
Patrick Benavoli68a91282011-08-31 11:23:23 +0200484
485 return false;
486 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200487
Patrick Benavoli68a91282011-08-31 11:23:23 +0200488 // Log tuning availability
Kevin Rocardace81f82012-12-11 16:19:17 +0100489 log_info("Tuning %s", getConstFrameworkConfiguration()->isTuningAllowed() ? "allowed" : "prohibited");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200490
491 return true;
492}
493
494bool CParameterMgr::loadStructure(string& strError)
495{
496 // Retrieve system to load structure to
497 CSystemClass* pSystemClass = getSystemClass();
498
Kevin Rocarde25ee792013-04-22 17:46:28 +0200499 log_info("Loading " + pSystemClass->getName() + " system class structure");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200500
501 // Get structure description element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100502 const CFrameworkConfigurationLocation* pStructureDescriptionFileLocation = static_cast<const CFrameworkConfigurationLocation*>(getConstFrameworkConfiguration()->findChildOfKind("StructureDescriptionFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200503
504 if (!pStructureDescriptionFileLocation) {
505
506 strError = "No StructureDescriptionFileLocation element found for SystemClass " + pSystemClass->getName();
507
508 return false;
509 }
510
511 // Get Xml structure folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100512 string strXmlStructureFolder = pStructureDescriptionFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200513
514 // Get Xml structure file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100515 string strXmlStructureFilePath = pStructureDescriptionFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200516
517 // Parse Structure XML file
518 CXmlParameterSerializingContext parameterBuildContext(strError);
519
Kevin Rocard57096bd2012-11-30 11:24:20 +0100520 CAutoLog autolog(pSystemClass, "Importing system structure from file " + strXmlStructureFilePath);
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200521
Patrick Benavoli68a91282011-08-31 11:23:23 +0200522 if (!xmlParse(parameterBuildContext, pSystemClass, strXmlStructureFilePath, strXmlStructureFolder, EParameterCreationLibrary)) {
523
524 return false;
525 }
526
527 // Initialize offsets
528 pSystemClass->setOffset(0);
529
530 // Initialize main blackboard's size
531 _pMainParameterBlackboard->setSize(pSystemClass->getFootPrint());
532
533 return true;
534}
535
536bool CParameterMgr::loadSettings(string& strError)
537{
538 CAutoLog autoLog(this, "Loading settings");
539
540 // Get settings configuration element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100541 const CFrameworkConfigurationGroup* pParameterConfigurationGroup = static_cast<const CFrameworkConfigurationGroup*>(getConstFrameworkConfiguration()->findChildOfKind("SettingsConfiguration"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200542
543 if (!pParameterConfigurationGroup) {
544
545 // No settings to load
546
547 return true;
548 }
549 // Get binary settings file location
550 const CFrameworkConfigurationLocation* pBinarySettingsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("BinarySettingsFileLocation"));
551
552 string strXmlBinarySettingsFilePath;
553
554 if (pBinarySettingsFileLocation) {
555
556 // Get Xml binary settings file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100557 strXmlBinarySettingsFilePath = pBinarySettingsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200558 }
559
560 // Get configurable domains element
561 const CFrameworkConfigurationLocation* pConfigurableDomainsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("ConfigurableDomainsFileLocation"));
562
563 if (!pConfigurableDomainsFileLocation) {
564
565 strError = "No ConfigurableDomainsFileLocation element found for SystemClass " + getSystemClass()->getName();
566
567 return false;
568 }
569 // Get destination root element
570 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
571
572 // Get Xml configuration domains file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100573 string strXmlConfigurationDomainsFilePath = pConfigurableDomainsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200574
575 // Get Xml configuration domains folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100576 string strXmlConfigurationDomainsFolder = pConfigurableDomainsFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200577
578 // Parse configuration domains XML file (ask to read settings from XML file if they are not provided as binary)
579 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, !pBinarySettingsFileLocation);
580
581 // Selection criteria definition for rule creation
582 xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
583
Patrick Benavoli63499d42011-10-24 18:50:03 +0200584 // Auto validation of configurations if no binary settings provided
585 xmlDomainSerializingContext.setAutoValidationRequired(!pBinarySettingsFileLocation);
586
Kevin Rocardace81f82012-12-11 16:19:17 +0100587 log_info("Importing configurable domains from file %s %s settings", strXmlConfigurationDomainsFilePath.c_str(), pBinarySettingsFileLocation ? "without" : "with");
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200588
Patrick Benavoli68a91282011-08-31 11:23:23 +0200589 // Do parse
590 if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strXmlConfigurationDomainsFilePath, strXmlConfigurationDomainsFolder, EParameterConfigurationLibrary, "SystemClassName")) {
591
592 return false;
593 }
594 // We have loaded the whole system structure, compute checksum
595 const CSystemClass* pSystemClass = getConstSystemClass();
596 _uiStructureChecksum = pSystemClass->computeStructureChecksum() + getConfigurableDomains()->computeStructureChecksum() + getSelectionCriteria()->computeStructureChecksum();
597
598 // Load binary settings if any provided
599 if (pBinarySettingsFileLocation && !pConfigurableDomains->serializeSettings(strXmlBinarySettingsFilePath, false, _uiStructureChecksum, strError)) {
600
601 return false;
602 }
603
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200604 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200605}
606
607// XML parsing
608bool CParameterMgr::xmlParse(CXmlElementSerializingContext& elementSerializingContext, CElement* pRootElement, const string& strXmlFilePath, const string& strXmlFolder, CParameterMgr::ElementLibrary eElementLibrary, const string& strNameAttrituteName)
609{
610 // Init serializing context
611 elementSerializingContext.set(_pElementLibrarySet->getElementLibrary(eElementLibrary), strXmlFolder, _strSchemaFolderLocation);
612
613 // Get Schema file associated to root element
614 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pRootElement->getKind() + ".xsd";
615
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200616 CXmlFileDocSource fileDocSource(strXmlFilePath, strXmlSchemaFilePath, pRootElement->getKind(), pRootElement->getName(), strNameAttrituteName);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200617
618 // Start clean
619 pRootElement->clean();
620
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200621 CXmlMemoryDocSink memorySink(pRootElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200622
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200623 if (!memorySink.process(fileDocSource, elementSerializingContext)) {
624 //Cleanup
Patrick Benavoli68a91282011-08-31 11:23:23 +0200625 pRootElement->clean();
626
627 return false;
628 }
629
Patrick Benavoli68a91282011-08-31 11:23:23 +0200630 return true;
631}
632
633// Init
634bool CParameterMgr::init(string& strError)
635{
636 return base::init(strError);
637}
638
639// Selection criteria interface
640CSelectionCriterionType* CParameterMgr::createSelectionCriterionType(bool bIsInclusive)
641{
642 // Propagate
643 return getSelectionCriteria()->createSelectionCriterionType(bIsInclusive);
644}
645
646CSelectionCriterion* CParameterMgr::createSelectionCriterion(const string& strName, const CSelectionCriterionType* pSelectionCriterionType)
647{
648 // Propagate
649 return getSelectionCriteria()->createSelectionCriterion(strName, pSelectionCriterionType);
650}
651
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200652// Selection criterion retrieval
653CSelectionCriterion* CParameterMgr::getSelectionCriterion(const string& strName)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200654{
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200655 // Propagate
656 return getSelectionCriteria()->getSelectionCriterion(strName);
657}
658
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100659// Configuration application
Kevin Rocardace81f82012-12-11 16:19:17 +0100660void CParameterMgr::applyConfigurations()
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200661{
662 CAutoLog autoLog(this, "Configuration application request");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200663
664 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +0100665 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200666
667 if (!_bTuningModeIsOn) {
668
669 // Apply configuration(s)
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100670 doApplyConfigurations(false);
Frédéric Boisnarddaaa63c2012-08-27 15:48:15 +0200671 } else {
672
Kevin Rocardace81f82012-12-11 16:19:17 +0100673 log_warning("Configurations were not applied because the TuningMode is on");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200674 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200675}
676
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200677// Get the configurableElement corresponding to the given path
678const CConfigurableElement* CParameterMgr::getConfigurableElement(const string& strPath,
679 string& strError) const
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200680{
Patrick Benavoli065264a2011-11-20 15:46:41 +0100681 CPathNavigator pathNavigator(strPath);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200682
Patrick Benavoli065264a2011-11-20 15:46:41 +0100683 // Nagivate through system class
684 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
685
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100686 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100687 }
688
689 // Find element
690 const CElement* pElement = getConstSystemClass()->findDescendant(pathNavigator);
691
692 if (!pElement) {
693
694 strError = "Path not found";
695
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100696 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100697 }
698
699 // Check found element is a parameter
700 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pElement);
701
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200702 return pConfigurableElement;
703}
704
705// Dynamic parameter handling
706CParameterHandle* CParameterMgr::createParameterHandle(const string& strPath, string& strError)
707{
708 const CConfigurableElement* pConfigurableElement = getConfigurableElement(strPath, strError);
709
710 if (!pConfigurableElement) {
711
712 // Element not found
713 strError = "Element not found";
714 return NULL;
715 }
716
Patrick Benavoli065264a2011-11-20 15:46:41 +0100717 if (!pConfigurableElement->isParameter()) {
718
719 // Element is not parameter
720 strError = "Not a parameter";
721
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100722 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100723 }
724
725 // Convert as parameter and return new handle
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200726 return new CParameterHandle(static_cast<const CBaseParameter*>(pConfigurableElement), this);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200727}
728
Patrick Benavoli68a91282011-08-31 11:23:23 +0200729/////////////////// Remote command parsers
Patrick Benavoli592ae562011-09-05 16:53:58 +0200730/// Version
Patrick Benavoli63499d42011-10-24 18:50:03 +0200731CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::versionCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli592ae562011-09-05 16:53:58 +0200732{
733 (void)remoteCommand;
734
Patrick Benavoli63499d42011-10-24 18:50:03 +0200735 // Show version
736 strResult = getVersion();
Patrick Benavoli592ae562011-09-05 16:53:58 +0200737
Patrick Benavoli63499d42011-10-24 18:50:03 +0200738 return CCommandHandler::ESucceeded;
Patrick Benavoli592ae562011-09-05 16:53:58 +0200739}
740
Patrick Benavoli68a91282011-08-31 11:23:23 +0200741/// Status
Patrick Benavoli63499d42011-10-24 18:50:03 +0200742CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::statusCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200743{
744 (void)remoteCommand;
745 // System class
746 const CSystemClass* pSystemClass = getSystemClass();
747
Patrick Benavoli68a91282011-08-31 11:23:23 +0200748 // Show status
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200749 /// General section
750 appendTitle(strResult, "General:");
751 // System class
Patrick Benavoli68a91282011-08-31 11:23:23 +0200752 strResult += "System Class: ";
753 strResult += pSystemClass->getName();
754 strResult += "\n";
755
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200756 // Tuning mode
Patrick Benavoli68a91282011-08-31 11:23:23 +0200757 strResult += "Tuning Mode: ";
758 strResult += tuningModeOn() ? "on" : "off";
759 strResult += "\n";
760
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200761 // Value space
Patrick Benavoli68a91282011-08-31 11:23:23 +0200762 strResult += "Value Space: ";
763 strResult += valueSpaceIsRaw() ? "raw" : "real";
764 strResult += "\n";
765
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200766 // Output raw format
767 strResult += "Output Raw Format: ";
768 strResult += outputRawFormatIsHex() ? "hex" : "dec";
769 strResult += "\n";
770
771 // Auto Sync
Patrick Benavoli68a91282011-08-31 11:23:23 +0200772 strResult += "Auto Sync: ";
773 strResult += autoSyncOn() ? "on" : "off";
774 strResult += "\n";
775
776 /// Subsystem list
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200777 appendTitle(strResult, "Subsystems:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200778 string strSubsystemList;
779 pSystemClass->listChildrenPaths(strSubsystemList);
780 strResult += strSubsystemList;
781
782 /// Last applied configurations
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200783 appendTitle(strResult, "Last Applied [Pending] Configurations:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200784 string strLastAppliedConfigurations;
785 getConfigurableDomains()->listLastAppliedConfigurations(strLastAppliedConfigurations);
786 strResult += strLastAppliedConfigurations;
787
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200788 /// Criteria states
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200789 appendTitle(strResult, "Selection Criteria:");
Kevin Rocard7f265822012-12-07 18:51:22 +0100790 list<string> lstrSelectionCriteria;
791 getSelectionCriteria()->listSelectionCriteria(lstrSelectionCriteria, false, true);
792 // Concatenate the criterion list as the command result
Frederic Boisnard390b36d2013-05-23 15:28:31 +0200793 string strCriteriaStates;
794 CUtility::asString(lstrSelectionCriteria, strCriteriaStates);
795 strResult += strCriteriaStates;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200796
Patrick Benavoli63499d42011-10-24 18:50:03 +0200797 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200798}
799
800/// Tuning Mode
Patrick Benavoli63499d42011-10-24 18:50:03 +0200801CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200802{
803 if (remoteCommand.getArgument(0) == "on") {
804
805 if (setTuningMode(true, strResult)) {
806
Patrick Benavoli63499d42011-10-24 18:50:03 +0200807 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200808 }
809 } else if (remoteCommand.getArgument(0) == "off") {
810
811 if (setTuningMode(false, strResult)) {
812
Patrick Benavoli63499d42011-10-24 18:50:03 +0200813 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200814 }
815 } else {
816 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200817 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200818 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200819 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200820}
821
Patrick Benavoli63499d42011-10-24 18:50:03 +0200822CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200823{
824 (void)remoteCommand;
825
826 strResult = tuningModeOn() ? "on" : "off";
827
Patrick Benavoli63499d42011-10-24 18:50:03 +0200828 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200829}
830
831/// Value Space
Patrick Benavoli63499d42011-10-24 18:50:03 +0200832CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200833{
834 (void)strResult;
835
836 if (remoteCommand.getArgument(0) == "raw") {
837
838 setValueSpace(true);
839
Patrick Benavoli63499d42011-10-24 18:50:03 +0200840 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200841
842 } else if (remoteCommand.getArgument(0) == "real") {
843
844 setValueSpace(false);
845
Patrick Benavoli63499d42011-10-24 18:50:03 +0200846 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200847
848 } else {
849 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200850 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200851 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200852 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200853}
854
Patrick Benavoli63499d42011-10-24 18:50:03 +0200855CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200856{
857 (void)remoteCommand;
858
859 strResult = valueSpaceIsRaw() ? "raw" : "real";
860
Patrick Benavoli63499d42011-10-24 18:50:03 +0200861 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200862}
863
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200864/// Output Raw Format
Patrick Benavoli63499d42011-10-24 18:50:03 +0200865CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200866{
867 (void)strResult;
868
869 if (remoteCommand.getArgument(0) == "hex") {
870
871 setOutputRawFormat(true);
872
Patrick Benavoli63499d42011-10-24 18:50:03 +0200873 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200874
875 } else if (remoteCommand.getArgument(0) == "dec") {
876
877 setOutputRawFormat(false);
878
Patrick Benavoli63499d42011-10-24 18:50:03 +0200879 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200880
881 } else {
882 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200883 return CCommandHandler::EShowUsage;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200884 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200885 return CCommandHandler::EFailed;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200886}
887
Patrick Benavoli63499d42011-10-24 18:50:03 +0200888CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200889{
890 (void)remoteCommand;
891
892 strResult = outputRawFormatIsHex() ? "hex" : "dec";
893
Patrick Benavoli63499d42011-10-24 18:50:03 +0200894 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200895}
896
Patrick Benavoli68a91282011-08-31 11:23:23 +0200897/// Sync
Patrick Benavoli63499d42011-10-24 18:50:03 +0200898CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200899{
900 if (remoteCommand.getArgument(0) == "on") {
901
902 if (setAutoSync(true, strResult)) {
903
Patrick Benavoli63499d42011-10-24 18:50:03 +0200904 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200905 }
906 } else if (remoteCommand.getArgument(0) == "off") {
907
908 if (setAutoSync(false, strResult)) {
909
Patrick Benavoli63499d42011-10-24 18:50:03 +0200910 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200911 }
912 } else {
913 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200914 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200915 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200916 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200917}
918
Patrick Benavoli63499d42011-10-24 18:50:03 +0200919CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200920{
921 (void)remoteCommand;
922
923 strResult = autoSyncOn() ? "on" : "off";
924
Patrick Benavoli63499d42011-10-24 18:50:03 +0200925 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200926}
927
Patrick Benavoli63499d42011-10-24 18:50:03 +0200928CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::syncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200929{
930 (void)remoteCommand;
931
Patrick Benavoli63499d42011-10-24 18:50:03 +0200932 return sync(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200933}
934
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200935/// Criteria
Patrick Benavoli63499d42011-10-24 18:50:03 +0200936CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listCriteriaCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200937{
938 (void)remoteCommand;
939
Kevin Rocard4eae8272013-04-18 19:12:46 +0200940 bool humanReadable = true;
Kevin Rocard7f265822012-12-07 18:51:22 +0100941
Kevin Rocard4eae8272013-04-18 19:12:46 +0200942 // Look for optional arguments
943 if (remoteCommand.getArgumentCount() >= 1) {
944
945 // If csv is provided, format the criterion list in Commas Separated Value pairs
946 if (remoteCommand.getArgument(0) == "csv") {
947 humanReadable = false;
948 } else {
949 return CCommandHandler::EShowUsage;
950 }
951 }
952
953 list<string> lstrResult;
954 getSelectionCriteria()->listSelectionCriteria(lstrResult, true, humanReadable);
Kevin Rocard7f265822012-12-07 18:51:22 +0100955
956 // Concatenate the criterion list as the command result
Frederic Boisnard390b36d2013-05-23 15:28:31 +0200957 CUtility::asString(lstrResult, strResult);
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200958
Patrick Benavoli63499d42011-10-24 18:50:03 +0200959 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200960}
Patrick Benavoli68a91282011-08-31 11:23:23 +0200961
962/// Domains
Patrick Benavoli63499d42011-10-24 18:50:03 +0200963CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200964{
965 (void)remoteCommand;
966
Patrick Benavoli63499d42011-10-24 18:50:03 +0200967 getConfigurableDomains()->listDomains(strResult);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200968
Patrick Benavoli63499d42011-10-24 18:50:03 +0200969 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200970}
971
Patrick Benavoli63499d42011-10-24 18:50:03 +0200972CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200973{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200974 return createDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200975}
976
Patrick Benavoli63499d42011-10-24 18:50:03 +0200977CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200978{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200979 return deleteDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200980}
981
Kevin Rocard170f0a42012-06-18 13:56:05 +0200982CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteAllDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
983{
984 (void)remoteCommand;
985
986 return deleteAllDomains(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
987}
988
Patrick Benavoli63499d42011-10-24 18:50:03 +0200989CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200990{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200991 return getConfigurableDomains()->renameDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200992}
993
Patrick Benavoli63499d42011-10-24 18:50:03 +0200994CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200995{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200996 // Check tuning mode
997 if (!checkTuningModeOn(strResult)) {
998
999 return CCommandHandler::EFailed;
1000 }
1001
1002 // Set property
1003 bool bSequenceAware;
1004
1005 if (remoteCommand.getArgument(1) == "true") {
1006
1007 bSequenceAware = true;
1008
1009 } else if (remoteCommand.getArgument(1) == "false") {
1010
1011 bSequenceAware = false;
1012
1013 } else {
1014 // Show usage
1015 return CCommandHandler::EShowUsage;
1016 }
1017
1018 return getConfigurableDomains()->setSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001019}
1020
Patrick Benavoli63499d42011-10-24 18:50:03 +02001021CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001022{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001023 // Get property
1024 bool bSequenceAware;
1025
1026 if (!getConfigurableDomains()->getSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult)) {
1027
1028 return CCommandHandler::EFailed;
1029 }
1030
1031 strResult = bSequenceAware ? "true" : "false";
1032
1033 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001034}
1035
Patrick Benavoli63499d42011-10-24 18:50:03 +02001036CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001037{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001038 return getConfigurableDomains()->listDomainElements(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001039}
1040
Patrick Benavoli63499d42011-10-24 18:50:03 +02001041CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::addElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001042{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001043 return addConfigurableElementToDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1044}
1045
1046CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::removeElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1047{
1048 return removeConfigurableElementFromDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1049}
1050
1051CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::splitDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1052{
1053 return split(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001054}
1055
1056/// Configurations
Patrick Benavoli63499d42011-10-24 18:50:03 +02001057CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConfigurationsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001058{
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001059 return getConstConfigurableDomains()->listConfigurations(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
1060}
1061
1062CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1063{
1064 (void)remoteCommand;
1065
1066 // Dummy error context
1067 string strError;
1068 CErrorContext errorContext(strError);
1069
1070 // Dump
1071 getConstConfigurableDomains()->dumpContent(strResult, errorContext);
1072
1073 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001074}
1075
Patrick Benavoli63499d42011-10-24 18:50:03 +02001076CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001077{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001078 return createConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001079}
1080
Patrick Benavoli63499d42011-10-24 18:50:03 +02001081CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001082{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001083 return deleteConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001084}
1085
Patrick Benavoli63499d42011-10-24 18:50:03 +02001086CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001087{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001088 return getConfigurableDomains()->renameConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001089}
1090
Patrick Benavoli63499d42011-10-24 18:50:03 +02001091CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::saveConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001092{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001093 return saveConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001094}
1095
Patrick Benavoli63499d42011-10-24 18:50:03 +02001096CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::restoreConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001097{
Kevin Rocardace81f82012-12-11 16:19:17 +01001098 list<string> lstrResult;
1099 if (!restoreConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), lstrResult)) {
1100 //Concatenate the error list as the command result
Frederic Boisnard390b36d2013-05-23 15:28:31 +02001101 CUtility::asString(lstrResult, strResult);
Kevin Rocardace81f82012-12-11 16:19:17 +01001102
1103 return CCommandHandler::EFailed;
1104 }
1105 return CCommandHandler::EDone;
Patrick Benavoli63499d42011-10-24 18:50:03 +02001106}
1107
1108CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1109{
1110 // Check tuning mode
1111 if (!checkTuningModeOn(strResult)) {
1112
1113 return CCommandHandler::EFailed;
1114 }
1115
1116 // Build configurable element path list
1117 vector<string> astrNewElementSequence;
1118
1119 uint32_t uiArgument;
1120
1121 for (uiArgument = 2; uiArgument < remoteCommand.getArgumentCount(); uiArgument++) {
1122
1123 astrNewElementSequence.push_back(remoteCommand.getArgument(uiArgument));
1124 }
1125
1126 // Delegate to configurable domains
1127 return getConfigurableDomains()->setElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), astrNewElementSequence, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1128}
1129
1130CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1131{
1132 // Delegate to configurable domains
1133 return getConfigurableDomains()->getElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001134}
1135
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001136CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1137{
1138 // Delegate to configurable domains
1139 return getConfigurableDomains()->setApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.packArguments(2, remoteCommand.getArgumentCount() - 2), getConstSelectionCriteria()->getSelectionCriteriaDefinition(), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1140}
1141
1142CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::clearRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1143{
1144 // Delegate to configurable domains
1145 return getConfigurableDomains()->clearApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1146}
1147
1148CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1149{
1150 // Delegate to configurable domains
1151 return getConfigurableDomains()->getApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
1152}
1153
Patrick Benavoli68a91282011-08-31 11:23:23 +02001154/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001155CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001156{
1157 CElementLocator elementLocator(getSystemClass(), false);
1158
1159 CElement* pLocatedElement = NULL;
1160
1161 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1162
Patrick Benavoli63499d42011-10-24 18:50:03 +02001163 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001164 }
1165
1166 strResult = string("\n");
1167
1168 if (!pLocatedElement) {
1169
1170 // List from root folder
1171
1172 // Return system class qualified name
1173 pLocatedElement = getSystemClass();
1174 }
1175
1176 // Return sub-elements
1177 strResult += pLocatedElement->listQualifiedPaths(false);
1178
Patrick Benavoli63499d42011-10-24 18:50:03 +02001179 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001180}
1181
1182/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001183CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listParametersCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001184{
1185 CElementLocator elementLocator(getSystemClass(), false);
1186
1187 CElement* pLocatedElement = NULL;
1188
1189 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1190
Patrick Benavoli63499d42011-10-24 18:50:03 +02001191 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001192 }
1193
1194 strResult = string("\n");
1195
1196 if (!pLocatedElement) {
1197
1198 // List from root folder
1199
1200 // Return system class qualified name
1201 pLocatedElement = getSystemClass();
1202 }
1203
1204 // Return sub-elements
1205 strResult += pLocatedElement->listQualifiedPaths(true);
1206
Patrick Benavoli63499d42011-10-24 18:50:03 +02001207 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001208}
1209
Patrick Benavoli63499d42011-10-24 18:50:03 +02001210CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001211{
1212 CElementLocator elementLocator(getSystemClass());
1213
1214 CElement* pLocatedElement = NULL;
1215
1216 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1217
Patrick Benavoli63499d42011-10-24 18:50:03 +02001218 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001219 }
1220
1221 string strError;
1222
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001223 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001224
1225 // Dump elements
1226 pLocatedElement->dumpContent(strResult, parameterAccessContext);
1227
Patrick Benavoli63499d42011-10-24 18:50:03 +02001228 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001229}
1230
Patrick Benavoli63499d42011-10-24 18:50:03 +02001231CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSizeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001232{
1233 CElementLocator elementLocator(getSystemClass());
1234
1235 CElement* pLocatedElement = NULL;
1236
1237 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1238
Patrick Benavoli63499d42011-10-24 18:50:03 +02001239 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001240 }
1241
1242 // Converted to actual sizable element
1243 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1244
1245 // Get size as string
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001246 strResult = pConfigurableElement->getFootprintAsString();
Patrick Benavoli68a91282011-08-31 11:23:23 +02001247
Patrick Benavoli63499d42011-10-24 18:50:03 +02001248 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001249}
1250
Patrick Benavoli63499d42011-10-24 18:50:03 +02001251CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showPropertiesCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001252{
1253 CElementLocator elementLocator(getSystemClass());
1254
1255 CElement* pLocatedElement = NULL;
1256
1257 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1258
Patrick Benavoli63499d42011-10-24 18:50:03 +02001259 return CCommandHandler::EFailed;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001260 }
1261
1262 // Convert element
1263 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1264
1265 // Return element properties
1266 pConfigurableElement->showProperties(strResult);
1267
Patrick Benavoli63499d42011-10-24 18:50:03 +02001268 return CCommandHandler::ESucceeded;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001269}
1270
Patrick Benavoli63499d42011-10-24 18:50:03 +02001271CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001272{
1273 string strValue;
1274
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001275 if (!accessParameterValue(remoteCommand.getArgument(0), strValue, false, strResult)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001276
Patrick Benavoli63499d42011-10-24 18:50:03 +02001277 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001278 }
1279 // Succeeded
1280 strResult = strValue;
1281
Patrick Benavoli63499d42011-10-24 18:50:03 +02001282 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001283}
1284
Patrick Benavoli63499d42011-10-24 18:50:03 +02001285CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001286{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001287 // Check tuning mode
1288 if (!checkTuningModeOn(strResult)) {
1289
1290 return CCommandHandler::EFailed;
1291 }
1292 // Get value to set
1293 string strValue = remoteCommand.packArguments(1, remoteCommand.getArgumentCount() - 1);
1294
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001295 return accessParameterValue(remoteCommand.getArgument(0), strValue, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001296}
1297
Patrick Benavoli63499d42011-10-24 18:50:03 +02001298CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listBelongingDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001299{
1300 CElementLocator elementLocator(getSystemClass());
1301
1302 CElement* pLocatedElement = NULL;
1303
1304 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1305
Patrick Benavoli63499d42011-10-24 18:50:03 +02001306 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001307 }
1308
1309 // Convert element
1310 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1311
1312 // Return element belonging domains
1313 pConfigurableElement->listBelongingDomains(strResult);
1314
Patrick Benavoli63499d42011-10-24 18:50:03 +02001315 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001316}
1317
Patrick Benavoli63499d42011-10-24 18:50:03 +02001318CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001319{
1320 CElementLocator elementLocator(getSystemClass());
1321
1322 CElement* pLocatedElement = NULL;
1323
1324 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1325
Patrick Benavoli63499d42011-10-24 18:50:03 +02001326 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001327 }
1328
1329 // Convert element
1330 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1331
1332 // Return element belonging domains
1333 pConfigurableElement->listAssociatedDomains(strResult);
1334
Patrick Benavoli63499d42011-10-24 18:50:03 +02001335 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001336}
1337
Patrick Benavoli63499d42011-10-24 18:50:03 +02001338CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001339{
1340 (void)remoteCommand;
1341
1342 getConfigurableDomains()->listAssociatedElements(strResult);
1343
Patrick Benavoli63499d42011-10-24 18:50:03 +02001344 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001345}
1346
Patrick Benavoli63499d42011-10-24 18:50:03 +02001347CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConflictingElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001348{
1349 (void)remoteCommand;
1350
1351 getConfigurableDomains()->listConflictingElements(strResult);
1352
Patrick Benavoli63499d42011-10-24 18:50:03 +02001353 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001354}
1355
Patrick Benavoli63499d42011-10-24 18:50:03 +02001356CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listRogueElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001357{
1358 (void)remoteCommand;
1359
1360 getSystemClass()->listRogueElements(strResult);
1361
Patrick Benavoli63499d42011-10-24 18:50:03 +02001362 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001363}
1364
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001365CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getConfigurationParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1366{
1367 string strOutputValue;
1368 string strError;
1369
1370 if (!accessConfigurationValue(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), strOutputValue, false, strError)) {
1371
1372 strResult = strError;
1373 return CCommandHandler::EFailed;
1374 }
1375 // Succeeded
1376 strResult = strOutputValue;
1377
1378 return CCommandHandler::ESucceeded;
1379}
1380
1381CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setConfigurationParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1382{
1383 // Get value to set
1384 string strValue = remoteCommand.packArguments(3, remoteCommand.getArgumentCount() - 3);
1385
1386 bool bSuccess = accessConfigurationValue(remoteCommand.getArgument(0),
1387 remoteCommand.getArgument(1),
1388 remoteCommand.getArgument(2),
1389 strValue, true, strResult);
1390
1391 return bSuccess ? CCommandHandler::EDone : CCommandHandler::EFailed;
1392}
1393
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +02001394CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showMappingCommmandProcess(
1395 const IRemoteCommand& remoteCommand,
1396 string& strResult)
1397{
1398 if (!getParameterMapping(remoteCommand.getArgument(0), strResult)) {
1399
1400 return CCommandHandler::EFailed;
1401 }
1402
1403 return CCommandHandler::ESucceeded;
1404}
1405
Patrick Benavoli68a91282011-08-31 11:23:23 +02001406/// Settings Import/Export
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001407CParameterMgr::CCommandHandler::CommandStatus
1408 CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess(
1409 const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001410{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001411 string strFileName = remoteCommand.getArgument(0);
1412 return exportDomainsXml(strFileName, false, true, strResult) ?
1413 CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001414}
1415
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001416CParameterMgr::CCommandHandler::CommandStatus
1417 CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess(
1418 const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001419{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001420 return importDomainsXml(remoteCommand.getArgument(0), false, true, strResult) ?
1421 CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001422}
1423
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001424CParameterMgr::CCommandHandler::CommandStatus
1425 CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess(
1426 const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001427{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001428 string strFileName = remoteCommand.getArgument(0);
1429 return exportDomainsXml(strFileName, true, true, strResult) ?
1430 CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001431}
1432
Patrick Benavoli63499d42011-10-24 18:50:03 +02001433CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001434{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001435 return importDomainsXml(remoteCommand.getArgument(0), true, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001436}
1437
Patrick Benavoli63499d42011-10-24 18:50:03 +02001438CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001439{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001440 return exportDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001441}
1442
Patrick Benavoli63499d42011-10-24 18:50:03 +02001443CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001444{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001445 return importDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001446}
1447
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001448CParameterMgr::CCommandHandler::CommandStatus
1449 CParameterMgr::getConfigurableDomainsWithSettingsXMLCommmandProcess(
1450 const IRemoteCommand& remoteCommand, string& strResult)
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001451{
1452 (void)remoteCommand;
1453
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001454 if (!exportDomainsXml(strResult, true, false, strResult)) {
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001455
1456 return CCommandHandler::EFailed;
1457 }
1458 // Succeeded
1459 return CCommandHandler::ESucceeded;
1460}
1461
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001462CParameterMgr::CCommandHandler::CommandStatus
1463 CParameterMgr::setConfigurableDomainsWithSettingsXMLCommmandProcess(
1464 const IRemoteCommand& remoteCommand, string& strResult)
1465{
1466 return importDomainsXml(remoteCommand.getArgument(0), true, false, strResult) ?
1467 CCommandHandler::EDone : CCommandHandler::EFailed;
1468}
1469
1470CParameterMgr::CCommandHandler::CommandStatus
1471 CParameterMgr::getSystemClassXMLCommmandProcess(
1472 const IRemoteCommand& remoteCommand, string& strResult)
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001473{
1474 (void)remoteCommand;
1475
1476 if (!getSystemClassXMLString(strResult)) {
1477
1478 return CCommandHandler::EFailed;
1479 }
1480 // Succeeded
1481 return CCommandHandler::ESucceeded;
1482}
1483
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001484// User set/get parameters in main BlackBoard
1485bool CParameterMgr::accessParameterValue(const string& strPath, string& strValue, bool bSet, string& strError)
1486{
1487 // Define context
1488 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
1489
Frédéric Boisnard150407c2013-03-15 14:46:23 +01001490 // Activate the auto synchronization with the hardware
1491 if (bSet) {
1492
1493 parameterAccessContext.setAutoSync(_bAutoSyncOn);
1494 }
1495
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001496 return accessValue(parameterAccessContext, strPath, strValue, bSet, strError);
1497}
1498
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +02001499// User get parameter mapping
1500bool CParameterMgr::getParameterMapping(const string& strPath, string& strResult) const
1501{
1502 CPathNavigator pathNavigator(strPath);
1503
1504 // Nagivate through system class
1505 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strResult)) {
1506
1507 return false;
1508 }
1509
1510 // Get the ConfigurableElement corresponding to strPath
1511 const CConfigurableElement* pConfigurableElement = getConfigurableElement(strPath, strResult);
1512 if (!pConfigurableElement) {
1513
1514 return false;
1515 }
1516
1517 // Find the list of the ancestors of the current ConfigurableElement that have a mapping
1518 list<const CConfigurableElement*> configurableElementPath;
1519 pConfigurableElement->getListOfElementsWithMapping(configurableElementPath);
1520
1521 // Get the Subsystem containing the ConfigurableElement
1522 const CSubsystem* pSubsystem = pConfigurableElement->getBelongingSubsystem();
1523 if (!pSubsystem) {
1524
1525 strResult = "Unable to find the Subsystem containing the parameter";
1526 return false;
1527 }
1528
1529 // Fetch the mapping corresponding to the ConfigurableElement
1530 strResult = pSubsystem->getMapping(configurableElementPath);
1531
1532 return true;
1533}
1534
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001535// User set/get parameters in specific Configuration BlackBoard
1536bool CParameterMgr::accessConfigurationValue(const string& strDomain, const string& strConfiguration, const string& strPath, string& strValue, bool bSet, string& strError)
1537{
1538 CElementLocator elementLocator(getSystemClass());
1539
1540 CElement* pLocatedElement = NULL;
1541
1542 if (!elementLocator.locate(strPath, &pLocatedElement, strError)) {
1543
1544 return false;
1545 }
1546
1547 // Convert element
1548 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1549
1550 // Get the Configuration blackboard and the Base Offset of the configurable element in this blackboard
1551 uint32_t uiBaseOffset;
1552 bool bIsLastApplied;
1553
1554 CParameterBlackboard* pConfigurationBlackboard = getConstConfigurableDomains()->findConfigurationBlackboard(strDomain, strConfiguration, pConfigurableElement, uiBaseOffset, bIsLastApplied, strError);
1555
1556 if (!pConfigurationBlackboard) {
1557
1558 return false;
1559 }
1560
1561 log_info("Element %s in Domain %s, offset: %d, base offset: %d", strPath.c_str(), strDomain.c_str(), pConfigurableElement->getOffset(), uiBaseOffset);
1562
1563 /// Update the Configuration Blackboard
1564
Frédéric Boisnard150407c2013-03-15 14:46:23 +01001565 // 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 +01001566 CParameterAccessContext parameterAccessContext(strError, pConfigurationBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex, uiBaseOffset);
1567
1568 // Access Value in the Configuration Blackboard
1569 if (!accessValue(parameterAccessContext, strPath, strValue, bSet, strError)) {
1570
1571 return false;
1572 }
1573
1574 /// If the Configuration is the last one applied, update the Main Blackboard as well
1575
1576 if (bIsLastApplied) {
1577
1578 // Define Main context
1579 parameterAccessContext.setParameterBlackboard(_pMainParameterBlackboard);
1580
Frédéric Boisnard150407c2013-03-15 14:46:23 +01001581 // Activate the auto synchronization with the hardware
1582 if (bSet) {
1583
1584 parameterAccessContext.setAutoSync(_bAutoSyncOn);
1585 }
1586
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001587 // Access Value in the Main Blackboard
1588 return accessValue(parameterAccessContext, strPath, strValue, bSet, strError);
1589 }
1590
1591 return true;
1592}
1593
Patrick Benavoli68a91282011-08-31 11:23:23 +02001594// User set/get parameters
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001595bool CParameterMgr::accessValue(CParameterAccessContext& parameterAccessContext, const string& strPath, string& strValue, bool bSet, string& strError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001596{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001597 // Lock state
1598 CAutoLock autoLock(&_blackboardMutex);
1599
1600 CPathNavigator pathNavigator(strPath);
1601
1602 // Nagivate through system class
1603 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001604
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +02001605 parameterAccessContext.setError(strError);
1606
Patrick Benavoli68a91282011-08-31 11:23:23 +02001607 return false;
1608 }
1609
Patrick Benavoli065264a2011-11-20 15:46:41 +01001610 // Do the get
1611 return getConstSystemClass()->accessValue(pathNavigator, strValue, bSet, parameterAccessContext);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001612}
1613
1614// Tuning mode
1615bool CParameterMgr::setTuningMode(bool bOn, string& strError)
1616{
1617 // Tuning allowed?
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001618 if (bOn && !getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001619
1620 strError = "Tuning prohibited";
1621
1622 return false;
1623 }
1624 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +01001625 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001626
1627 // Warn domains about exiting tuning mode
1628 if (!bOn && _bTuningModeIsOn) {
1629
1630 // Ensure application of currently selected configurations
Patrick Benavoli1387bda2011-08-31 11:23:24 +02001631 // Force-apply configurations
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01001632 doApplyConfigurations(true);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001633
Patrick Benavoli68a91282011-08-31 11:23:23 +02001634 // Turn auto sync back on
1635 _bAutoSyncOn = true;
1636 }
1637
1638 // Store
1639 _bTuningModeIsOn = bOn;
1640
Patrick Benavoli68a91282011-08-31 11:23:23 +02001641 return true;
1642}
1643
1644bool CParameterMgr::tuningModeOn() const
1645{
1646 return _bTuningModeIsOn;
1647}
1648
1649// Current value space for user set/get value interpretation
1650void CParameterMgr::setValueSpace(bool bIsRaw)
1651{
1652 _bValueSpaceIsRaw = bIsRaw;
1653}
1654
1655bool CParameterMgr::valueSpaceIsRaw()
1656{
1657 return _bValueSpaceIsRaw;
1658}
1659
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001660// Current Output Raw Format for user get value interpretation
1661void CParameterMgr::setOutputRawFormat(bool bIsHex)
1662{
1663 _bOutputRawFormatIsHex = bIsHex;
1664}
1665
1666bool CParameterMgr::outputRawFormatIsHex()
1667{
1668 return _bOutputRawFormatIsHex;
1669}
1670
Patrick Benavoli68a91282011-08-31 11:23:23 +02001671/// Sync
1672// Automatic hardware synchronization control (during tuning session)
1673bool CParameterMgr::setAutoSync(bool bAutoSyncOn, string& strError)
1674{
1675 // Check tuning mode
1676 if (!checkTuningModeOn(strError)) {
1677
1678 return false;
1679 }
1680 // Warn domains about turning auto sync back on
1681 if (bAutoSyncOn && !_bAutoSyncOn) {
1682
Patrick Benavoli592ae562011-09-05 16:53:58 +02001683 // Do the synchronization at system class level (could be optimized by keeping track of all modified parameters)
1684 if (!sync(strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001685
1686 return false;
1687 }
1688 }
1689
1690 // Set Auto sync
1691 _bAutoSyncOn = bAutoSyncOn;
1692
1693 return true;
1694}
1695
1696bool CParameterMgr::autoSyncOn() const
1697{
1698 return _bAutoSyncOn;
1699}
1700
1701// Manual hardware synchronization control (during tuning session)
1702bool CParameterMgr::sync(string& strError)
1703{
1704 // Check tuning mode
1705 if (!checkTuningModeOn(strError)) {
1706
1707 return false;
1708 }
1709 // Warn domains about turning auto sync back on
1710 if (_bAutoSyncOn) {
1711
1712 strError = "Feature unavailable when Auto Sync is on";
1713
1714 return false;
1715 }
1716
1717 // Get syncer set
1718 CSyncerSet syncerSet;
1719 // ... from system class
1720 getConstSystemClass()->fillSyncerSet(syncerSet);
Kevin Rocardace81f82012-12-11 16:19:17 +01001721
Patrick Benavoli68a91282011-08-31 11:23:23 +02001722 // Sync
Kevin Rocardace81f82012-12-11 16:19:17 +01001723 list<string> lstrError;
1724 if (! syncerSet.sync(*_pMainParameterBlackboard, false, &lstrError)){
1725
Frederic Boisnard390b36d2013-05-23 15:28:31 +02001726 CUtility::asString(lstrError, strError);
Kevin Rocardace81f82012-12-11 16:19:17 +01001727 return false;
1728 };
1729
1730 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001731}
1732
1733// Content dump
1734void CParameterMgr::logStructureContent(string& strContent) const
1735{
1736 string strError;
1737
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001738 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001739
1740 dumpContent(strContent, parameterAccessContext);
1741}
1742
1743// Configuration/Domains handling
1744bool CParameterMgr::createDomain(const string& strName, string& strError)
1745{
1746 // Check tuning mode
1747 if (!checkTuningModeOn(strError)) {
1748
1749 return false;
1750 }
1751
1752 // Delegate to configurable domains
1753 return getConfigurableDomains()->createDomain(strName, strError);
1754}
1755
1756bool CParameterMgr::deleteDomain(const string& strName, string& strError)
1757{
1758 // Check tuning mode
1759 if (!checkTuningModeOn(strError)) {
1760
1761 return false;
1762 }
1763
1764 // Delegate to configurable domains
1765 return getConfigurableDomains()->deleteDomain(strName, strError);
1766}
1767
Kevin Rocard170f0a42012-06-18 13:56:05 +02001768bool CParameterMgr::deleteAllDomains(string& strError)
1769{
1770 // Check tuning mode
1771 if (!checkTuningModeOn(strError)) {
1772
1773 return false;
1774 }
1775
1776 // Delegate to configurable domains
1777 getConfigurableDomains()->deleteAllDomains();
1778
1779 return true;
1780}
1781
Patrick Benavoli68a91282011-08-31 11:23:23 +02001782bool CParameterMgr::createConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1783{
1784 // Check tuning mode
1785 if (!checkTuningModeOn(strError)) {
1786
1787 return false;
1788 }
1789
1790 // Delegate to configurable domains
1791 return getConfigurableDomains()->createConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1792}
1793
1794bool CParameterMgr::deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1795{
1796 // Check tuning mode
1797 if (!checkTuningModeOn(strError)) {
1798
1799 return false;
1800 }
1801
1802 // Delegate to configurable domains
1803 return getConfigurableDomains()->deleteConfiguration(strDomain, strConfiguration, strError);
1804}
1805
Kevin Rocardace81f82012-12-11 16:19:17 +01001806bool CParameterMgr::restoreConfiguration(const string& strDomain, const string& strConfiguration, list<string>& lstrError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001807{
Kevin Rocardace81f82012-12-11 16:19:17 +01001808 string strError;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001809 // Check tuning mode
1810 if (!checkTuningModeOn(strError)) {
1811
Kevin Rocardace81f82012-12-11 16:19:17 +01001812 lstrError.push_back(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001813 return false;
1814 }
1815
1816 // Delegate to configurable domains
Kevin Rocardace81f82012-12-11 16:19:17 +01001817 return getConstConfigurableDomains()->restoreConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, lstrError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001818}
1819
1820bool CParameterMgr::saveConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1821{
1822 // Check tuning mode
1823 if (!checkTuningModeOn(strError)) {
1824
1825 return false;
1826 }
1827
1828 // Delegate to configurable domains
1829 return getConfigurableDomains()->saveConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1830}
1831
1832// Configurable element - domain association
1833bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1834{
1835 // Check tuning mode
1836 if (!checkTuningModeOn(strError)) {
1837
1838 return false;
1839 }
1840
1841 CElementLocator elementLocator(getSystemClass());
1842
1843 CElement* pLocatedElement = NULL;
1844
1845 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1846
1847 return false;
1848 }
1849
1850 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001851 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001852
1853 // Delegate
1854 return getConfigurableDomains()->addConfigurableElementToDomain(strDomain, pConfigurableElement, _pMainParameterBlackboard, strError);
1855}
1856
1857bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1858{
1859 // Check tuning mode
1860 if (!checkTuningModeOn(strError)) {
1861
1862 return false;
1863 }
1864
1865 CElementLocator elementLocator(getSystemClass());
1866
1867 CElement* pLocatedElement = NULL;
1868
1869 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1870
Patrick Benavoli63499d42011-10-24 18:50:03 +02001871 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001872 }
1873
1874 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001875 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001876
1877 // Delegate
1878 return getConfigurableDomains()->removeConfigurableElementFromDomain(strDomain, pConfigurableElement, strError);
1879}
1880
1881bool CParameterMgr::split(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1882{
1883 // Check tuning mode
1884 if (!checkTuningModeOn(strError)) {
1885
1886 return false;
1887 }
1888
1889 CElementLocator elementLocator(getSystemClass());
1890
1891 CElement* pLocatedElement = NULL;
1892
1893 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1894
Patrick Benavoli63499d42011-10-24 18:50:03 +02001895 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001896 }
1897
1898 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001899 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001900
1901 // Delegate
1902 return getConfigurableDomains()->split(strDomain, pConfigurableElement, strError);
1903}
1904
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001905bool CParameterMgr::importDomainsXml(const string& strXmlSource, bool bWithSettings,
1906 bool bFromFile, string& strError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001907{
1908 // Check tuning mode
1909 if (!checkTuningModeOn(strError)) {
1910
1911 return false;
1912 }
1913
1914 // check path is absolute
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001915 if (bFromFile && strXmlSource[0] != '/') {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001916
1917 strError = "Please provide absolute path";
1918
1919 return false;
1920 }
1921 // Root element
1922 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1923
1924 // Context
1925 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1926
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001927 // Selection criteria definition for rule creation
1928 xmlDomainSerializingContext.setSelectionCriteriaDefinition(
1929 getConstSelectionCriteria()->getSelectionCriteriaDefinition());
Patrick Benavoli68a91282011-08-31 11:23:23 +02001930
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001931 // Init serializing context
1932 xmlDomainSerializingContext.set(
1933 _pElementLibrarySet->getElementLibrary(EParameterConfigurationLibrary),
1934 "", _strSchemaFolderLocation);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001935
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001936 // Get Schema file associated to root element
1937 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" +
1938 pConfigurableDomains->getKind() + ".xsd";
1939
1940 // Xml Source
1941 CXmlDocSource* pSource;
1942
1943 if (bFromFile) {
1944
1945 // when importing from a file strXmlSource is the file name
1946 pSource = new CXmlFileDocSource(strXmlSource, strXmlSchemaFilePath,
1947 pConfigurableDomains->getKind(),
1948 pConfigurableDomains->getName(), "SystemClassName");
1949
1950 } else {
1951
1952 // when importing from an xml string, strXmlSource contains the string
1953 pSource = new CXmlStringDocSource(strXmlSource, strXmlSchemaFilePath,
1954 pConfigurableDomains->getKind(),
1955 pConfigurableDomains->getName(), "SystemClassName");
1956
1957 }
1958 // Start clean
1959 pConfigurableDomains->clean();
1960
1961 // Use a doc sink that instantiate Configurable Domains from the given doc source
1962 CXmlMemoryDocSink memorySink(pConfigurableDomains);
1963
1964 bool bProcessSuccess = memorySink.process(*pSource, xmlDomainSerializingContext);
1965
1966 if (!bProcessSuccess) {
1967
1968 //Cleanup
1969 pConfigurableDomains->clean();
1970
1971 } else {
1972
1973 // Validate domains after XML import
1974 pConfigurableDomains->validate(_pMainParameterBlackboard);
1975
Patrick Benavoli68a91282011-08-31 11:23:23 +02001976 }
1977
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001978 delete pSource;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001979
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001980 return bProcessSuccess;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001981}
1982
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001983bool CParameterMgr::exportDomainsXml(string& strXmlDest, bool bWithSettings, bool bToFile,
1984 string& strError) const
Patrick Benavoli68a91282011-08-31 11:23:23 +02001985{
1986 // check path is absolute
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001987 if (bToFile && strXmlDest[0] != '/') {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001988
1989 strError = "Please provide absolute path";
1990
1991 return false;
1992 }
1993
1994 // Root element
1995 const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains();
1996
1997 // Get Schema file associated to root element
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001998 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" +
1999 pConfigurableDomains->getKind() + ".xsd";
Patrick Benavoli68a91282011-08-31 11:23:23 +02002000
2001 // Context
2002 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
2003
2004 // Value space
2005 xmlDomainSerializingContext.setValueSpaceRaw(_bValueSpaceIsRaw);
2006
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02002007 // Output raw format
2008 xmlDomainSerializingContext.setOutputRawFormat(_bOutputRawFormatIsHex);
2009
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002010 // Use a doc source by loading data from instantiated Configurable Domains
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002011 CXmlMemoryDocSource memorySource(pConfigurableDomains, pConfigurableDomains->getKind(),
2012 strXmlSchemaFilePath, "parameter-framework", getVersion());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002013
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002014 // Xml Sink
2015 CXmlDocSink* pSink;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002016
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002017 if (bToFile) {
2018
2019 // Use a doc sink to write the doc data in a file
2020 pSink = new CXmlFileDocSink(strXmlDest);
2021
2022 } else {
2023
2024 // Use a doc sink to write the doc data in a string
2025 pSink = new CXmlStringDocSink(strXmlDest);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002026 }
2027
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002028 bool bProcessSuccess = pSink->process(memorySource, xmlDomainSerializingContext);
2029
2030 delete pSink;
2031 return bProcessSuccess;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002032}
2033
2034// Binary Import/Export
2035bool CParameterMgr::importDomainsBinary(const string& strFileName, string& strError)
2036{
2037 // Check tuning mode
2038 if (!checkTuningModeOn(strError)) {
2039
2040 return false;
2041 }
2042 // check path is absolute
2043 if (strFileName[0] != '/') {
2044
2045 strError = "Please provide absolute path";
2046
2047 return false;
2048 }
2049 // Root element
2050 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
2051
2052 // Serialize in
2053 return pConfigurableDomains->serializeSettings(strFileName, false, _uiStructureChecksum, strError);
2054}
2055
2056bool CParameterMgr::exportDomainsBinary(const string& strFileName, string& strError)
2057{
2058 // check path is absolute
2059 if (strFileName[0] != '/') {
2060
2061 strError = "Please provide absolute path";
2062
2063 return false;
2064 }
Patrick Benavoli68a91282011-08-31 11:23:23 +02002065
Patrick Benavoli68a91282011-08-31 11:23:23 +02002066 // Root element
2067 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
2068
2069 // Serialize out
2070 return pConfigurableDomains->serializeSettings(strFileName, true, _uiStructureChecksum, strError);
2071}
2072
2073// For tuning, check we're in tuning mode
2074bool CParameterMgr::checkTuningModeOn(string& strError) const
2075{
2076 // Tuning Mode on?
2077 if (!_bTuningModeIsOn) {
2078
2079 strError = "Tuning Mode must be on";
2080
2081 return false;
2082 }
2083 return true;
2084}
2085
Patrick Benavoli065264a2011-11-20 15:46:41 +01002086// Tuning mutex dynamic parameter handling
2087pthread_mutex_t* CParameterMgr::getBlackboardMutex()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002088{
Patrick Benavoli065264a2011-11-20 15:46:41 +01002089 return &_blackboardMutex;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002090}
2091
Patrick Benavoli065264a2011-11-20 15:46:41 +01002092// Blackboard reference (dynamic parameter handling)
2093CParameterBlackboard* CParameterMgr::getParameterBlackboard()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002094{
Patrick Benavoli065264a2011-11-20 15:46:41 +01002095 return _pMainParameterBlackboard;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002096}
2097
Patrick Benavoli68a91282011-08-31 11:23:23 +02002098// Dynamic creation library feeding
2099void CParameterMgr::feedElementLibraries()
2100{
2101 // Global Configuration handling
2102 CElementLibrary* pFrameworkConfigurationLibrary = new CElementLibrary;
2103
Kevin Rocarda7b69602013-08-07 16:15:33 +02002104 pFrameworkConfigurationLibrary->addElementBuilder("ParameterFrameworkConfiguration", new TElementBuilderTemplate<CParameterFrameworkConfiguration>());
2105 pFrameworkConfigurationLibrary->addElementBuilder("SubsystemPlugins", new TKindElementBuilderTemplate<CSubsystemPlugins>());
2106 pFrameworkConfigurationLibrary->addElementBuilder("Location", new TKindElementBuilderTemplate<CPluginLocation>());
2107 pFrameworkConfigurationLibrary->addElementBuilder("StructureDescriptionFileLocation", new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>());
2108 pFrameworkConfigurationLibrary->addElementBuilder("SettingsConfiguration", new TKindElementBuilderTemplate<CFrameworkConfigurationGroup>());
2109 pFrameworkConfigurationLibrary->addElementBuilder("ConfigurableDomainsFileLocation", new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>());
2110 pFrameworkConfigurationLibrary->addElementBuilder("BinarySettingsFileLocation", new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002111
2112 _pElementLibrarySet->addElementLibrary(pFrameworkConfigurationLibrary);
2113
2114 // Parameter creation
2115 CElementLibrary* pParameterCreationLibrary = new CElementLibrary;
2116
Kevin Rocarda7b69602013-08-07 16:15:33 +02002117 pParameterCreationLibrary->addElementBuilder("Subsystem", new CSubsystemElementBuilder(getSystemClass()->getSubsystemLibrary()));
2118 pParameterCreationLibrary->addElementBuilder("ComponentType", new TNamedElementBuilderTemplate<CComponentType>());
2119 pParameterCreationLibrary->addElementBuilder("Component", new TNamedElementBuilderTemplate<CComponentInstance>());
2120 pParameterCreationLibrary->addElementBuilder("BitParameter", new TNamedElementBuilderTemplate<CBitParameterType>());
2121 pParameterCreationLibrary->addElementBuilder("BitParameterBlock", new TNamedElementBuilderTemplate<CBitParameterBlockType>());
2122 pParameterCreationLibrary->addElementBuilder("StringParameter", new TNamedElementBuilderTemplate<CStringParameterType>());
2123 pParameterCreationLibrary->addElementBuilder("ParameterBlock", new TNamedElementBuilderTemplate<CParameterBlockType>());
2124 pParameterCreationLibrary->addElementBuilder("BooleanParameter", new TNamedElementBuilderTemplate<CBooleanParameterType>());
2125 pParameterCreationLibrary->addElementBuilder("IntegerParameter", new TNamedElementBuilderTemplate<CIntegerParameterType>());
2126 pParameterCreationLibrary->addElementBuilder("LinearAdaptation", new TElementBuilderTemplate<CLinearParameterAdaptation>());
2127 pParameterCreationLibrary->addElementBuilder("EnumParameter", new TNamedElementBuilderTemplate<CEnumParameterType>());
2128 pParameterCreationLibrary->addElementBuilder("ValuePair", new TElementBuilderTemplate<CEnumValuePair>());
2129 pParameterCreationLibrary->addElementBuilder("FixedPointParameter", new TNamedElementBuilderTemplate<CFixedPointParameterType>());
2130 pParameterCreationLibrary->addElementBuilder("SubsystemInclude", new TKindElementBuilderTemplate<CXmlFileIncluderElement>());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002131
2132 _pElementLibrarySet->addElementLibrary(pParameterCreationLibrary);
2133
2134 // Parameter Configuration Domains creation
2135 CElementLibrary* pParameterConfigurationLibrary = new CElementLibrary;
2136
Kevin Rocarda7b69602013-08-07 16:15:33 +02002137 pParameterConfigurationLibrary->addElementBuilder("ConfigurableDomain", new TNamedElementBuilderTemplate<CConfigurableDomain>());
2138 pParameterConfigurationLibrary->addElementBuilder("Configuration", new TNamedElementBuilderTemplate<CDomainConfiguration>());
2139 pParameterConfigurationLibrary->addElementBuilder("CompoundRule", new TElementBuilderTemplate<CCompoundRule>());
2140 pParameterConfigurationLibrary->addElementBuilder("SelectionCriterionRule", new TElementBuilderTemplate<CSelectionCriterionRule>());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002141
2142 _pElementLibrarySet->addElementLibrary(pParameterConfigurationLibrary);
2143}
2144
2145// Remote Processor Server connection handling
2146bool CParameterMgr::handleRemoteProcessingInterface(string& strError)
2147{
2148 CAutoLog autoLog(this, "Handling remote processing interface");
2149
2150 // Start server if tuning allowed
Patrick Benavoli95ac0342011-11-07 20:32:51 +01002151 if (getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02002152
Kevin Rocardace81f82012-12-11 16:19:17 +01002153 log_info("Loading remote processor library");
Patrick Benavoli68a91282011-08-31 11:23:23 +02002154
2155 // Load library
2156 void* lib_handle = dlopen("libremote-processor.so", RTLD_NOW);
2157
2158 if (!lib_handle) {
2159
2160 // Return error
2161 const char* pcError = dlerror();
2162
2163 if (pcError) {
2164
2165 strError = pcError;
2166 } else {
2167
2168 strError = "Unable to load libremote-processor.so library";
2169 }
2170
2171 return false;
2172 }
2173
2174 CreateRemoteProcessorServer pfnCreateRemoteProcessorServer = (CreateRemoteProcessorServer)dlsym(lib_handle, "createRemoteProcessorServer");
2175
2176 if (!pfnCreateRemoteProcessorServer) {
2177
2178 strError = "libremote-process.so does not contain createRemoteProcessorServer symbol.";
2179
2180 return false;
2181 }
2182
2183 // Create server
Patrick Benavoli95ac0342011-11-07 20:32:51 +01002184 _pRemoteProcessorServer = pfnCreateRemoteProcessorServer(getConstFrameworkConfiguration()->getServerPort(), _pCommandHandler);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002185
Kevin Rocardace81f82012-12-11 16:19:17 +01002186 log_info("Starting remote processor server on port %d", getConstFrameworkConfiguration()->getServerPort());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002187 // Start
2188 if (!_pRemoteProcessorServer->start()) {
2189
2190 strError = "Unable to start remote processor server";
2191
2192 return false;
2193 }
2194 }
2195
2196 return true;
2197}
2198
2199// Back synchronization
Kevin Rocardace81f82012-12-11 16:19:17 +01002200CBackSynchronizer* CParameterMgr::createBackSynchronizer() const
Patrick Benavoli68a91282011-08-31 11:23:23 +02002201{
2202#ifdef SIMULATION
2203 // In simulation, back synchronization of the blackboard won't probably work
2204 // We need to ensure though the blackboard is initialized with valid data
Kevin Rocardace81f82012-12-11 16:19:17 +01002205 return new CSimulatedBackSynchronizer(getConstSystemClass(), _pMainParameterBlackboard);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002206#else
2207 // Real back synchronizer from subsystems
Kevin Rocardace81f82012-12-11 16:19:17 +01002208 return new CHardwareBackSynchronizer(getConstSystemClass(), _pMainParameterBlackboard);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002209#endif
2210}
2211
2212// Children typwise access
2213CParameterFrameworkConfiguration* CParameterMgr::getFrameworkConfiguration()
2214{
2215 return static_cast<CParameterFrameworkConfiguration*>(getChild(EFrameworkConfiguration));
2216}
2217
2218const CParameterFrameworkConfiguration* CParameterMgr::getConstFrameworkConfiguration()
2219{
2220 return getFrameworkConfiguration();
2221}
2222
2223CSelectionCriteria* CParameterMgr::getSelectionCriteria()
2224{
2225 return static_cast<CSelectionCriteria*>(getChild(ESelectionCriteria));
2226}
2227
2228const CSelectionCriteria* CParameterMgr::getConstSelectionCriteria()
2229{
2230 return static_cast<const CSelectionCriteria*>(getChild(ESelectionCriteria));
2231}
2232
2233CSystemClass* CParameterMgr::getSystemClass()
2234{
2235 return static_cast<CSystemClass*>(getChild(ESystemClass));
2236}
2237
2238const CSystemClass* CParameterMgr::getConstSystemClass() const
2239{
2240 return static_cast<const CSystemClass*>(getChild(ESystemClass));
2241}
2242
2243// Configurable Domains
2244CConfigurableDomains* CParameterMgr::getConfigurableDomains()
2245{
2246 return static_cast<CConfigurableDomains*>(getChild(EConfigurableDomains));
2247}
2248
2249const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains()
2250{
2251 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
2252}
2253
2254const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains() const
2255{
2256 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
2257}
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002258
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01002259// Apply configurations
2260void CParameterMgr::doApplyConfigurations(bool bForce)
2261{
2262 CSyncerSet syncerSet;
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002263
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01002264 // Check subsystems that need resync
2265 getSystemClass()->checkForSubsystemsToResync(syncerSet);
2266
2267 // Ensure application of currently selected configurations
2268 getConfigurableDomains()->apply(_pMainParameterBlackboard, syncerSet, bForce);
2269
2270 // Reset the modified status of the current criteria to indicate that a new configuration has been applied
2271 getSelectionCriteria()->resetModifiedStatus();
2272}
2273
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002274bool CParameterMgr::getSystemClassXMLString(string& strResult)
2275{
2276 // Root element
2277 const CSystemClass* pSystemClass = getSystemClass();
2278
2279 string strError;
2280
2281 CXmlSerializingContext xmlSerializingContext(strError);
2282
2283 // Use a doc source by loading data from instantiated Configurable Domains
2284 CXmlMemoryDocSource memorySource(pSystemClass, pSystemClass->getKind());
2285
2286 // Use a doc sink that write the doc data in a string
2287 CXmlStringDocSink stringSink(strResult);
2288
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002289 bool bProcessSuccess = stringSink.process(memorySource, xmlSerializingContext);
2290
2291 if (!bProcessSuccess) {
2292
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002293 strResult = strError;
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002294
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002295 }
2296
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002297 return bProcessSuccess;
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002298}