blob: a07cc57879c92de97ac0d920fe07a38b7b061e06 [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),
Kevin Rocardecf93102013-07-10 18:28:10 +0200283 _uiLogDepth(0),
Kevin Rocardd6909eb2013-07-18 09:13:51 +0200284 _bFailOnMissingSubsystem(true),
285 _bFailOnFailedSettingsLoad(true)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200286{
287 // Tuning Mode Mutex
Patrick Benavoli065264a2011-11-20 15:46:41 +0100288 bzero(&_blackboardMutex, sizeof(_blackboardMutex));
289 pthread_mutex_init(&_blackboardMutex, NULL);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200290
291 // Deal with children
292 addChild(new CParameterFrameworkConfiguration);
293 addChild(new CSelectionCriteria);
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100294 addChild(new CSystemClass);
295 addChild(new CConfigurableDomains);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200296
297 // Feed element library
298 feedElementLibraries();
Patrick Benavoli63499d42011-10-24 18:50:03 +0200299
300 _pCommandHandler = new CCommandHandler(this);
301
302 // Add command parsers
303 uint32_t uiRemoteCommandParserItem;
304
305 for (uiRemoteCommandParserItem = 0; uiRemoteCommandParserItem < guiNbRemoteCommandParserItems; uiRemoteCommandParserItem++) {
306
307 const SRemoteCommandParserItem* pRemoteCommandParserItem = &gastRemoteCommandParserItems[uiRemoteCommandParserItem];
308
309 _pCommandHandler->addCommandParser(pRemoteCommandParserItem->_pcCommandName,
310 pRemoteCommandParserItem->_pfnParser,
311 pRemoteCommandParserItem->_uiMinArgumentCount,
312 pRemoteCommandParserItem->_pcHelp,
313 pRemoteCommandParserItem->_pcDescription);
314 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100315
316 // Configuration file folder
317 uint32_t uiSlashPos = _strXmlConfigurationFilePath.rfind('/', -1);
318
319 assert(uiSlashPos != (uint32_t)-1);
320
321 _strXmlConfigurationFolderPath = _strXmlConfigurationFilePath.substr(0, uiSlashPos);
322
323 // Schema absolute folder location
324 _strSchemaFolderLocation = _strXmlConfigurationFolderPath + "/" + gacSystemSchemasSubFolder;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200325}
326
327CParameterMgr::~CParameterMgr()
328{
329 // Children
330 delete _pRemoteProcessorServer;
Frederic Boisnard31242302012-04-26 17:07:34 +0200331 delete _pCommandHandler;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200332 delete _pMainParameterBlackboard;
333 delete _pElementLibrarySet;
334
335 // Tuning Mode Mutex
Patrick Benavoli065264a2011-11-20 15:46:41 +0100336 pthread_mutex_destroy(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200337}
338
339string CParameterMgr::getKind() const
340{
341 return "ParameterMgr";
342}
343
344// Logging
345void CParameterMgr::setLogger(CParameterMgr::ILogger* pLogger)
346{
347 _pLogger = pLogger;
348}
349
350// Logging
Kevin Rocardace81f82012-12-11 16:19:17 +0100351void CParameterMgr::doLog(bool bIsWarning, const string& strLog) const
Patrick Benavoli68a91282011-08-31 11:23:23 +0200352{
353 if (_pLogger) {
354
355 // Nest
356 string strIndent;
357
358 // Level
359 uint32_t uiNbIndents = _uiLogDepth;
360
361 while (uiNbIndents--) {
362
363 strIndent += " ";
364 }
365
366 // Log
Kevin Rocardace81f82012-12-11 16:19:17 +0100367 _pLogger->log(bIsWarning, strIndent + strLog);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200368 }
369}
370
371void CParameterMgr::nestLog() const
372{
Patrick Benavoli592ae562011-09-05 16:53:58 +0200373 _uiLogDepth++;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200374}
375
376void CParameterMgr::unnestLog() const
377{
Patrick Benavoli592ae562011-09-05 16:53:58 +0200378 _uiLogDepth--;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200379}
380
Patrick Benavoli63499d42011-10-24 18:50:03 +0200381// Version
382string CParameterMgr::getVersion() const
383{
384 string strVersion;
385
386 // Major
387 strVersion = toString(guiEditionMajor) + ".";
388 // Minor
389 strVersion += toString(guiEditionMinor) + ".";
390 // Revision
391 strVersion += toString(guiRevision);
392
393 return strVersion;
394}
395
Patrick Benavoli68a91282011-08-31 11:23:23 +0200396bool CParameterMgr::load(string& strError)
397{
398 CAutoLog autoLog(this, "Loading");
399
400 // Load Framework configuration
401 if (!loadFrameworkConfiguration(strError)) {
402
403 return false;
404 }
405
406 // Load subsystems
Kevin Rocardecf93102013-07-10 18:28:10 +0200407 if (!getSystemClass()->loadSubsystems(strError,
408 _pSubsystemPlugins, !_bFailOnMissingSubsystem)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200409
410 return false;
411 }
412
413 // Load structure
414 if (!loadStructure(strError)) {
415
416 return false;
417 }
418
419 // Load settings
420 if (!loadSettings(strError)) {
421
422 return false;
423 }
424
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200425 // Back synchronization for areas in parameter blackboard not covered by any domain
Kevin Rocardace81f82012-12-11 16:19:17 +0100426 CBackSynchronizer* pBackSynchronizer = createBackSynchronizer();
Patrick Benavoli68a91282011-08-31 11:23:23 +0200427
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200428 // Back-synchronize
Kevin Rocard57096bd2012-11-30 11:24:20 +0100429 {
430 CAutoLog autoLog(this, "Main blackboard back synchronization");
431
Kevin Rocard5d6e05a2013-01-21 15:57:45 +0100432 pBackSynchronizer->sync();
Kevin Rocard57096bd2012-11-30 11:24:20 +0100433
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200434 // Get rid of back synchronizer
435 delete pBackSynchronizer;
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200436 }
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200437
438 // We're done loading the settings and back synchronizing
439 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
440
441 // We need to ensure all domains are valid
442 pConfigurableDomains->validate(_pMainParameterBlackboard);
443
Kevin Rocard7f265822012-12-07 18:51:22 +0100444 // Log selection criterion states
445 {
446 CAutoLog autoLog(this, "Criterion states");
447
448 const CSelectionCriteria* selectionCriteria = getConstSelectionCriteria();
449
450 list<string> lstrSelectionCriteron;
451 selectionCriteria->listSelectionCriteria(lstrSelectionCriteron, true, false);
452
Kevin Rocard36299362013-02-04 14:57:47 +0100453 log_table(false, lstrSelectionCriteron);
Kevin Rocard7f265822012-12-07 18:51:22 +0100454 }
455
Kevin Rocard2fbe6e82013-03-26 17:09:29 +0100456 // Subsystem can not ask for resync as they have not been synced yet
457 getSystemClass()->cleanSubsystemsNeedToResync();
458
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100459 // At initialization, check subsystems that need resync
460 doApplyConfigurations(true);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200461
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200462 // Start remote processor server if appropriate
463 return handleRemoteProcessingInterface(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200464}
465
466bool CParameterMgr::loadFrameworkConfiguration(string& strError)
467{
468 CAutoLog autoLog(this, "Loading framework configuration");
469
Patrick Benavoli68a91282011-08-31 11:23:23 +0200470 // Parse Structure XML file
471 CXmlElementSerializingContext elementSerializingContext(strError);
472
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100473 if (!xmlParse(elementSerializingContext, getFrameworkConfiguration(), _strXmlConfigurationFilePath, _strXmlConfigurationFolderPath, EFrameworkConfigurationLibrary)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200474
475 return false;
476 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100477 // Set class name to system class and configurable domains
478 getSystemClass()->setName(getConstFrameworkConfiguration()->getSystemClassName());
479 getConfigurableDomains()->setName(getConstFrameworkConfiguration()->getSystemClassName());
480
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100481 // Get subsystem plugins elements
482 _pSubsystemPlugins = static_cast<const CSubsystemPlugins*>(getConstFrameworkConfiguration()->findChild("SubsystemPlugins"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200483
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100484 if (!_pSubsystemPlugins) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200485
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100486 strError = "Parameter Framework Configuration: couldn't find SubsystemPlugins element";
Patrick Benavoli68a91282011-08-31 11:23:23 +0200487
488 return false;
489 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200490
Patrick Benavoli68a91282011-08-31 11:23:23 +0200491 // Log tuning availability
Kevin Rocardace81f82012-12-11 16:19:17 +0100492 log_info("Tuning %s", getConstFrameworkConfiguration()->isTuningAllowed() ? "allowed" : "prohibited");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200493
494 return true;
495}
496
497bool CParameterMgr::loadStructure(string& strError)
498{
499 // Retrieve system to load structure to
500 CSystemClass* pSystemClass = getSystemClass();
501
Kevin Rocarde25ee792013-04-22 17:46:28 +0200502 log_info("Loading " + pSystemClass->getName() + " system class structure");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200503
504 // Get structure description element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100505 const CFrameworkConfigurationLocation* pStructureDescriptionFileLocation = static_cast<const CFrameworkConfigurationLocation*>(getConstFrameworkConfiguration()->findChildOfKind("StructureDescriptionFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200506
507 if (!pStructureDescriptionFileLocation) {
508
509 strError = "No StructureDescriptionFileLocation element found for SystemClass " + pSystemClass->getName();
510
511 return false;
512 }
513
514 // Get Xml structure folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100515 string strXmlStructureFolder = pStructureDescriptionFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200516
517 // Get Xml structure file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100518 string strXmlStructureFilePath = pStructureDescriptionFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200519
520 // Parse Structure XML file
521 CXmlParameterSerializingContext parameterBuildContext(strError);
522
Kevin Rocard57096bd2012-11-30 11:24:20 +0100523 CAutoLog autolog(pSystemClass, "Importing system structure from file " + strXmlStructureFilePath);
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200524
Patrick Benavoli68a91282011-08-31 11:23:23 +0200525 if (!xmlParse(parameterBuildContext, pSystemClass, strXmlStructureFilePath, strXmlStructureFolder, EParameterCreationLibrary)) {
526
527 return false;
528 }
529
530 // Initialize offsets
531 pSystemClass->setOffset(0);
532
533 // Initialize main blackboard's size
534 _pMainParameterBlackboard->setSize(pSystemClass->getFootPrint());
535
536 return true;
537}
538
539bool CParameterMgr::loadSettings(string& strError)
540{
Kevin Rocardd6909eb2013-07-18 09:13:51 +0200541 string strLoadError;
542 bool success = loadSettingsFromConfigFile(strLoadError);
543
544 if (!success && !_bFailOnFailedSettingsLoad) {
545 // Load can not fail, ie continue but log the load errors
546 log_info(strLoadError);
547 log_info("Failed to load settings, continue without domains.");
548 success = true;
549 }
550
551 if (!success) {
552 // Propagate the litteral error only if the function fails
553 strError = strLoadError;
554 return false;
555 }
556
557 return true;
558}
559
560bool CParameterMgr::loadSettingsFromConfigFile(string& strError)
561{
Patrick Benavoli68a91282011-08-31 11:23:23 +0200562 CAutoLog autoLog(this, "Loading settings");
563
564 // Get settings configuration element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100565 const CFrameworkConfigurationGroup* pParameterConfigurationGroup = static_cast<const CFrameworkConfigurationGroup*>(getConstFrameworkConfiguration()->findChildOfKind("SettingsConfiguration"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200566
567 if (!pParameterConfigurationGroup) {
568
569 // No settings to load
570
571 return true;
572 }
573 // Get binary settings file location
574 const CFrameworkConfigurationLocation* pBinarySettingsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("BinarySettingsFileLocation"));
575
576 string strXmlBinarySettingsFilePath;
577
578 if (pBinarySettingsFileLocation) {
579
580 // Get Xml binary settings file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100581 strXmlBinarySettingsFilePath = pBinarySettingsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200582 }
583
584 // Get configurable domains element
585 const CFrameworkConfigurationLocation* pConfigurableDomainsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("ConfigurableDomainsFileLocation"));
586
587 if (!pConfigurableDomainsFileLocation) {
588
589 strError = "No ConfigurableDomainsFileLocation element found for SystemClass " + getSystemClass()->getName();
590
591 return false;
Kevin Rocardd6909eb2013-07-18 09:13:51 +0200592 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200593 // Get destination root element
594 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
595
596 // Get Xml configuration domains file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100597 string strXmlConfigurationDomainsFilePath = pConfigurableDomainsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200598
599 // Get Xml configuration domains folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100600 string strXmlConfigurationDomainsFolder = pConfigurableDomainsFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200601
602 // Parse configuration domains XML file (ask to read settings from XML file if they are not provided as binary)
603 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, !pBinarySettingsFileLocation);
604
605 // Selection criteria definition for rule creation
606 xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
607
Patrick Benavoli63499d42011-10-24 18:50:03 +0200608 // Auto validation of configurations if no binary settings provided
609 xmlDomainSerializingContext.setAutoValidationRequired(!pBinarySettingsFileLocation);
610
Kevin Rocardace81f82012-12-11 16:19:17 +0100611 log_info("Importing configurable domains from file %s %s settings", strXmlConfigurationDomainsFilePath.c_str(), pBinarySettingsFileLocation ? "without" : "with");
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200612
Patrick Benavoli68a91282011-08-31 11:23:23 +0200613 // Do parse
614 if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strXmlConfigurationDomainsFilePath, strXmlConfigurationDomainsFolder, EParameterConfigurationLibrary, "SystemClassName")) {
615
616 return false;
617 }
618 // We have loaded the whole system structure, compute checksum
619 const CSystemClass* pSystemClass = getConstSystemClass();
620 _uiStructureChecksum = pSystemClass->computeStructureChecksum() + getConfigurableDomains()->computeStructureChecksum() + getSelectionCriteria()->computeStructureChecksum();
621
622 // Load binary settings if any provided
623 if (pBinarySettingsFileLocation && !pConfigurableDomains->serializeSettings(strXmlBinarySettingsFilePath, false, _uiStructureChecksum, strError)) {
624
625 return false;
626 }
627
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200628 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200629}
630
631// XML parsing
632bool CParameterMgr::xmlParse(CXmlElementSerializingContext& elementSerializingContext, CElement* pRootElement, const string& strXmlFilePath, const string& strXmlFolder, CParameterMgr::ElementLibrary eElementLibrary, const string& strNameAttrituteName)
633{
634 // Init serializing context
635 elementSerializingContext.set(_pElementLibrarySet->getElementLibrary(eElementLibrary), strXmlFolder, _strSchemaFolderLocation);
636
637 // Get Schema file associated to root element
638 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pRootElement->getKind() + ".xsd";
639
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200640 CXmlFileDocSource fileDocSource(strXmlFilePath, strXmlSchemaFilePath, pRootElement->getKind(), pRootElement->getName(), strNameAttrituteName);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200641
642 // Start clean
643 pRootElement->clean();
644
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200645 CXmlMemoryDocSink memorySink(pRootElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200646
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200647 if (!memorySink.process(fileDocSource, elementSerializingContext)) {
648 //Cleanup
Patrick Benavoli68a91282011-08-31 11:23:23 +0200649 pRootElement->clean();
650
651 return false;
652 }
653
Patrick Benavoli68a91282011-08-31 11:23:23 +0200654 return true;
655}
656
657// Init
658bool CParameterMgr::init(string& strError)
659{
660 return base::init(strError);
661}
662
663// Selection criteria interface
664CSelectionCriterionType* CParameterMgr::createSelectionCriterionType(bool bIsInclusive)
665{
666 // Propagate
667 return getSelectionCriteria()->createSelectionCriterionType(bIsInclusive);
668}
669
670CSelectionCriterion* CParameterMgr::createSelectionCriterion(const string& strName, const CSelectionCriterionType* pSelectionCriterionType)
671{
672 // Propagate
673 return getSelectionCriteria()->createSelectionCriterion(strName, pSelectionCriterionType);
674}
675
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200676// Selection criterion retrieval
677CSelectionCriterion* CParameterMgr::getSelectionCriterion(const string& strName)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200678{
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200679 // Propagate
680 return getSelectionCriteria()->getSelectionCriterion(strName);
681}
682
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100683// Configuration application
Kevin Rocardace81f82012-12-11 16:19:17 +0100684void CParameterMgr::applyConfigurations()
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200685{
686 CAutoLog autoLog(this, "Configuration application request");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200687
688 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +0100689 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200690
691 if (!_bTuningModeIsOn) {
692
693 // Apply configuration(s)
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100694 doApplyConfigurations(false);
Frédéric Boisnarddaaa63c2012-08-27 15:48:15 +0200695 } else {
696
Kevin Rocardace81f82012-12-11 16:19:17 +0100697 log_warning("Configurations were not applied because the TuningMode is on");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200698 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200699}
700
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200701// Get the configurableElement corresponding to the given path
702const CConfigurableElement* CParameterMgr::getConfigurableElement(const string& strPath,
703 string& strError) const
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200704{
Patrick Benavoli065264a2011-11-20 15:46:41 +0100705 CPathNavigator pathNavigator(strPath);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200706
Patrick Benavoli065264a2011-11-20 15:46:41 +0100707 // Nagivate through system class
708 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
709
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100710 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100711 }
712
713 // Find element
714 const CElement* pElement = getConstSystemClass()->findDescendant(pathNavigator);
715
716 if (!pElement) {
717
Kevin Rocard4c3f8d82013-11-21 12:16:28 +0100718 strError = "Path not found: " + strPath;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100719
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100720 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100721 }
722
723 // Check found element is a parameter
724 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pElement);
725
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200726 return pConfigurableElement;
727}
728
729// Dynamic parameter handling
730CParameterHandle* CParameterMgr::createParameterHandle(const string& strPath, string& strError)
731{
732 const CConfigurableElement* pConfigurableElement = getConfigurableElement(strPath, strError);
733
734 if (!pConfigurableElement) {
735
736 // Element not found
Kevin Rocard4c3f8d82013-11-21 12:16:28 +0100737 strError = "Element not found: " + strPath;
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200738 return NULL;
739 }
740
Patrick Benavoli065264a2011-11-20 15:46:41 +0100741 if (!pConfigurableElement->isParameter()) {
742
743 // Element is not parameter
Kevin Rocard4c3f8d82013-11-21 12:16:28 +0100744 strError = "Not a parameter: " + strPath;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100745
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100746 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100747 }
748
749 // Convert as parameter and return new handle
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200750 return new CParameterHandle(static_cast<const CBaseParameter*>(pConfigurableElement), this);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200751}
752
Kevin Rocardecf93102013-07-10 18:28:10 +0200753void CParameterMgr::setFailureOnMissingSubsystem(bool bFail)
754{
755 _bFailOnMissingSubsystem = bFail;
756}
757
758bool CParameterMgr::getFailureOnMissingSubsystem() const
759{
760 return _bFailOnMissingSubsystem;
761}
Kevin Rocardd6909eb2013-07-18 09:13:51 +0200762
763void CParameterMgr::setFailureOnFailedSettingsLoad(bool bFail)
764{
765 _bFailOnFailedSettingsLoad = bFail;
766}
767bool CParameterMgr::getFailureOnFailedSettingsLoad()
768{
769 return _bFailOnFailedSettingsLoad;
770}
Patrick Benavoli68a91282011-08-31 11:23:23 +0200771/////////////////// Remote command parsers
Patrick Benavoli592ae562011-09-05 16:53:58 +0200772/// Version
Patrick Benavoli63499d42011-10-24 18:50:03 +0200773CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::versionCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli592ae562011-09-05 16:53:58 +0200774{
775 (void)remoteCommand;
776
Patrick Benavoli63499d42011-10-24 18:50:03 +0200777 // Show version
778 strResult = getVersion();
Patrick Benavoli592ae562011-09-05 16:53:58 +0200779
Patrick Benavoli63499d42011-10-24 18:50:03 +0200780 return CCommandHandler::ESucceeded;
Patrick Benavoli592ae562011-09-05 16:53:58 +0200781}
782
Patrick Benavoli68a91282011-08-31 11:23:23 +0200783/// Status
Patrick Benavoli63499d42011-10-24 18:50:03 +0200784CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::statusCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200785{
786 (void)remoteCommand;
787 // System class
788 const CSystemClass* pSystemClass = getSystemClass();
789
Patrick Benavoli68a91282011-08-31 11:23:23 +0200790 // Show status
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200791 /// General section
792 appendTitle(strResult, "General:");
793 // System class
Patrick Benavoli68a91282011-08-31 11:23:23 +0200794 strResult += "System Class: ";
795 strResult += pSystemClass->getName();
796 strResult += "\n";
797
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200798 // Tuning mode
Patrick Benavoli68a91282011-08-31 11:23:23 +0200799 strResult += "Tuning Mode: ";
800 strResult += tuningModeOn() ? "on" : "off";
801 strResult += "\n";
802
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200803 // Value space
Patrick Benavoli68a91282011-08-31 11:23:23 +0200804 strResult += "Value Space: ";
805 strResult += valueSpaceIsRaw() ? "raw" : "real";
806 strResult += "\n";
807
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200808 // Output raw format
809 strResult += "Output Raw Format: ";
810 strResult += outputRawFormatIsHex() ? "hex" : "dec";
811 strResult += "\n";
812
813 // Auto Sync
Patrick Benavoli68a91282011-08-31 11:23:23 +0200814 strResult += "Auto Sync: ";
815 strResult += autoSyncOn() ? "on" : "off";
816 strResult += "\n";
817
818 /// Subsystem list
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200819 appendTitle(strResult, "Subsystems:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200820 string strSubsystemList;
821 pSystemClass->listChildrenPaths(strSubsystemList);
822 strResult += strSubsystemList;
823
824 /// Last applied configurations
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200825 appendTitle(strResult, "Last Applied [Pending] Configurations:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200826 string strLastAppliedConfigurations;
827 getConfigurableDomains()->listLastAppliedConfigurations(strLastAppliedConfigurations);
828 strResult += strLastAppliedConfigurations;
829
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200830 /// Criteria states
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200831 appendTitle(strResult, "Selection Criteria:");
Kevin Rocard7f265822012-12-07 18:51:22 +0100832 list<string> lstrSelectionCriteria;
833 getSelectionCriteria()->listSelectionCriteria(lstrSelectionCriteria, false, true);
834 // Concatenate the criterion list as the command result
Frederic Boisnard390b36d2013-05-23 15:28:31 +0200835 string strCriteriaStates;
836 CUtility::asString(lstrSelectionCriteria, strCriteriaStates);
837 strResult += strCriteriaStates;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200838
Patrick Benavoli63499d42011-10-24 18:50:03 +0200839 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200840}
841
842/// Tuning Mode
Patrick Benavoli63499d42011-10-24 18:50:03 +0200843CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200844{
845 if (remoteCommand.getArgument(0) == "on") {
846
847 if (setTuningMode(true, strResult)) {
848
Patrick Benavoli63499d42011-10-24 18:50:03 +0200849 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200850 }
851 } else if (remoteCommand.getArgument(0) == "off") {
852
853 if (setTuningMode(false, strResult)) {
854
Patrick Benavoli63499d42011-10-24 18:50:03 +0200855 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200856 }
857 } else {
858 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200859 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200860 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200861 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200862}
863
Patrick Benavoli63499d42011-10-24 18:50:03 +0200864CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200865{
866 (void)remoteCommand;
867
868 strResult = tuningModeOn() ? "on" : "off";
869
Patrick Benavoli63499d42011-10-24 18:50:03 +0200870 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200871}
872
873/// Value Space
Patrick Benavoli63499d42011-10-24 18:50:03 +0200874CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200875{
876 (void)strResult;
877
878 if (remoteCommand.getArgument(0) == "raw") {
879
880 setValueSpace(true);
881
Patrick Benavoli63499d42011-10-24 18:50:03 +0200882 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200883
884 } else if (remoteCommand.getArgument(0) == "real") {
885
886 setValueSpace(false);
887
Patrick Benavoli63499d42011-10-24 18:50:03 +0200888 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200889
890 } else {
891 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200892 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200893 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200894 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200895}
896
Patrick Benavoli63499d42011-10-24 18:50:03 +0200897CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200898{
899 (void)remoteCommand;
900
901 strResult = valueSpaceIsRaw() ? "raw" : "real";
902
Patrick Benavoli63499d42011-10-24 18:50:03 +0200903 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200904}
905
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200906/// Output Raw Format
Patrick Benavoli63499d42011-10-24 18:50:03 +0200907CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200908{
909 (void)strResult;
910
911 if (remoteCommand.getArgument(0) == "hex") {
912
913 setOutputRawFormat(true);
914
Patrick Benavoli63499d42011-10-24 18:50:03 +0200915 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200916
917 } else if (remoteCommand.getArgument(0) == "dec") {
918
919 setOutputRawFormat(false);
920
Patrick Benavoli63499d42011-10-24 18:50:03 +0200921 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200922
923 } else {
924 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200925 return CCommandHandler::EShowUsage;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200926 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200927 return CCommandHandler::EFailed;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200928}
929
Patrick Benavoli63499d42011-10-24 18:50:03 +0200930CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200931{
932 (void)remoteCommand;
933
934 strResult = outputRawFormatIsHex() ? "hex" : "dec";
935
Patrick Benavoli63499d42011-10-24 18:50:03 +0200936 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200937}
938
Patrick Benavoli68a91282011-08-31 11:23:23 +0200939/// Sync
Patrick Benavoli63499d42011-10-24 18:50:03 +0200940CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200941{
942 if (remoteCommand.getArgument(0) == "on") {
943
944 if (setAutoSync(true, strResult)) {
945
Patrick Benavoli63499d42011-10-24 18:50:03 +0200946 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200947 }
948 } else if (remoteCommand.getArgument(0) == "off") {
949
950 if (setAutoSync(false, strResult)) {
951
Patrick Benavoli63499d42011-10-24 18:50:03 +0200952 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200953 }
954 } else {
955 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200956 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200957 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200958 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200959}
960
Patrick Benavoli63499d42011-10-24 18:50:03 +0200961CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200962{
963 (void)remoteCommand;
964
965 strResult = autoSyncOn() ? "on" : "off";
966
Patrick Benavoli63499d42011-10-24 18:50:03 +0200967 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200968}
969
Patrick Benavoli63499d42011-10-24 18:50:03 +0200970CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::syncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200971{
972 (void)remoteCommand;
973
Patrick Benavoli63499d42011-10-24 18:50:03 +0200974 return sync(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200975}
976
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200977/// Criteria
Patrick Benavoli63499d42011-10-24 18:50:03 +0200978CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listCriteriaCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200979{
980 (void)remoteCommand;
981
Kevin Rocard4eae8272013-04-18 19:12:46 +0200982 bool humanReadable = true;
Kevin Rocard7f265822012-12-07 18:51:22 +0100983
Kevin Rocard4eae8272013-04-18 19:12:46 +0200984 // Look for optional arguments
985 if (remoteCommand.getArgumentCount() >= 1) {
986
987 // If csv is provided, format the criterion list in Commas Separated Value pairs
988 if (remoteCommand.getArgument(0) == "csv") {
989 humanReadable = false;
990 } else {
991 return CCommandHandler::EShowUsage;
992 }
993 }
994
995 list<string> lstrResult;
996 getSelectionCriteria()->listSelectionCriteria(lstrResult, true, humanReadable);
Kevin Rocard7f265822012-12-07 18:51:22 +0100997
998 // Concatenate the criterion list as the command result
Frederic Boisnard390b36d2013-05-23 15:28:31 +0200999 CUtility::asString(lstrResult, strResult);
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001000
Patrick Benavoli63499d42011-10-24 18:50:03 +02001001 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001002}
Patrick Benavoli68a91282011-08-31 11:23:23 +02001003
1004/// Domains
Patrick Benavoli63499d42011-10-24 18:50:03 +02001005CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001006{
1007 (void)remoteCommand;
1008
Patrick Benavoli63499d42011-10-24 18:50:03 +02001009 getConfigurableDomains()->listDomains(strResult);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001010
Patrick Benavoli63499d42011-10-24 18:50:03 +02001011 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001012}
1013
Patrick Benavoli63499d42011-10-24 18:50:03 +02001014CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001015{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001016 return createDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001017}
1018
Patrick Benavoli63499d42011-10-24 18:50:03 +02001019CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001020{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001021 return deleteDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001022}
1023
Kevin Rocard170f0a42012-06-18 13:56:05 +02001024CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteAllDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1025{
1026 (void)remoteCommand;
1027
1028 return deleteAllDomains(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1029}
1030
Patrick Benavoli63499d42011-10-24 18:50:03 +02001031CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001032{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001033 return getConfigurableDomains()->renameDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001034}
1035
Patrick Benavoli63499d42011-10-24 18:50:03 +02001036CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001037{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001038 // Check tuning mode
1039 if (!checkTuningModeOn(strResult)) {
1040
1041 return CCommandHandler::EFailed;
1042 }
1043
1044 // Set property
1045 bool bSequenceAware;
1046
1047 if (remoteCommand.getArgument(1) == "true") {
1048
1049 bSequenceAware = true;
1050
1051 } else if (remoteCommand.getArgument(1) == "false") {
1052
1053 bSequenceAware = false;
1054
1055 } else {
1056 // Show usage
1057 return CCommandHandler::EShowUsage;
1058 }
1059
1060 return getConfigurableDomains()->setSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001061}
1062
Patrick Benavoli63499d42011-10-24 18:50:03 +02001063CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001064{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001065 // Get property
1066 bool bSequenceAware;
1067
1068 if (!getConfigurableDomains()->getSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult)) {
1069
1070 return CCommandHandler::EFailed;
1071 }
1072
1073 strResult = bSequenceAware ? "true" : "false";
1074
1075 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001076}
1077
Patrick Benavoli63499d42011-10-24 18:50:03 +02001078CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001079{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001080 return getConfigurableDomains()->listDomainElements(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001081}
1082
Patrick Benavoli63499d42011-10-24 18:50:03 +02001083CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::addElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001084{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001085 return addConfigurableElementToDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1086}
1087
1088CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::removeElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1089{
1090 return removeConfigurableElementFromDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1091}
1092
1093CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::splitDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1094{
1095 return split(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001096}
1097
1098/// Configurations
Patrick Benavoli63499d42011-10-24 18:50:03 +02001099CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConfigurationsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001100{
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001101 return getConstConfigurableDomains()->listConfigurations(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
1102}
1103
1104CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1105{
1106 (void)remoteCommand;
1107
1108 // Dummy error context
1109 string strError;
1110 CErrorContext errorContext(strError);
1111
1112 // Dump
1113 getConstConfigurableDomains()->dumpContent(strResult, errorContext);
1114
1115 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001116}
1117
Patrick Benavoli63499d42011-10-24 18:50:03 +02001118CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001119{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001120 return createConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001121}
1122
Patrick Benavoli63499d42011-10-24 18:50:03 +02001123CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001124{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001125 return deleteConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001126}
1127
Patrick Benavoli63499d42011-10-24 18:50:03 +02001128CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001129{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001130 return getConfigurableDomains()->renameConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001131}
1132
Patrick Benavoli63499d42011-10-24 18:50:03 +02001133CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::saveConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001134{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001135 return saveConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001136}
1137
Patrick Benavoli63499d42011-10-24 18:50:03 +02001138CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::restoreConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001139{
Kevin Rocardace81f82012-12-11 16:19:17 +01001140 list<string> lstrResult;
1141 if (!restoreConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), lstrResult)) {
1142 //Concatenate the error list as the command result
Frederic Boisnard390b36d2013-05-23 15:28:31 +02001143 CUtility::asString(lstrResult, strResult);
Kevin Rocardace81f82012-12-11 16:19:17 +01001144
1145 return CCommandHandler::EFailed;
1146 }
1147 return CCommandHandler::EDone;
Patrick Benavoli63499d42011-10-24 18:50:03 +02001148}
1149
1150CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1151{
1152 // Check tuning mode
1153 if (!checkTuningModeOn(strResult)) {
1154
1155 return CCommandHandler::EFailed;
1156 }
1157
1158 // Build configurable element path list
1159 vector<string> astrNewElementSequence;
1160
1161 uint32_t uiArgument;
1162
1163 for (uiArgument = 2; uiArgument < remoteCommand.getArgumentCount(); uiArgument++) {
1164
1165 astrNewElementSequence.push_back(remoteCommand.getArgument(uiArgument));
1166 }
1167
1168 // Delegate to configurable domains
1169 return getConfigurableDomains()->setElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), astrNewElementSequence, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1170}
1171
1172CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1173{
1174 // Delegate to configurable domains
1175 return getConfigurableDomains()->getElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001176}
1177
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001178CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1179{
1180 // Delegate to configurable domains
1181 return getConfigurableDomains()->setApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.packArguments(2, remoteCommand.getArgumentCount() - 2), getConstSelectionCriteria()->getSelectionCriteriaDefinition(), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1182}
1183
1184CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::clearRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1185{
1186 // Delegate to configurable domains
1187 return getConfigurableDomains()->clearApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1188}
1189
1190CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1191{
1192 // Delegate to configurable domains
1193 return getConfigurableDomains()->getApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
1194}
1195
Patrick Benavoli68a91282011-08-31 11:23:23 +02001196/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001197CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001198{
1199 CElementLocator elementLocator(getSystemClass(), false);
1200
1201 CElement* pLocatedElement = NULL;
1202
1203 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1204
Patrick Benavoli63499d42011-10-24 18:50:03 +02001205 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001206 }
1207
1208 strResult = string("\n");
1209
1210 if (!pLocatedElement) {
1211
1212 // List from root folder
1213
1214 // Return system class qualified name
1215 pLocatedElement = getSystemClass();
1216 }
1217
1218 // Return sub-elements
1219 strResult += pLocatedElement->listQualifiedPaths(false);
1220
Patrick Benavoli63499d42011-10-24 18:50:03 +02001221 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001222}
1223
1224/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001225CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listParametersCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001226{
1227 CElementLocator elementLocator(getSystemClass(), false);
1228
1229 CElement* pLocatedElement = NULL;
1230
1231 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1232
Patrick Benavoli63499d42011-10-24 18:50:03 +02001233 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001234 }
1235
1236 strResult = string("\n");
1237
1238 if (!pLocatedElement) {
1239
1240 // List from root folder
1241
1242 // Return system class qualified name
1243 pLocatedElement = getSystemClass();
1244 }
1245
1246 // Return sub-elements
1247 strResult += pLocatedElement->listQualifiedPaths(true);
1248
Patrick Benavoli63499d42011-10-24 18:50:03 +02001249 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001250}
1251
Patrick Benavoli63499d42011-10-24 18:50:03 +02001252CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001253{
1254 CElementLocator elementLocator(getSystemClass());
1255
1256 CElement* pLocatedElement = NULL;
1257
1258 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1259
Patrick Benavoli63499d42011-10-24 18:50:03 +02001260 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001261 }
1262
1263 string strError;
1264
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001265 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001266
1267 // Dump elements
1268 pLocatedElement->dumpContent(strResult, parameterAccessContext);
1269
Patrick Benavoli63499d42011-10-24 18:50:03 +02001270 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001271}
1272
Patrick Benavoli63499d42011-10-24 18:50:03 +02001273CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSizeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001274{
1275 CElementLocator elementLocator(getSystemClass());
1276
1277 CElement* pLocatedElement = NULL;
1278
1279 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1280
Patrick Benavoli63499d42011-10-24 18:50:03 +02001281 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001282 }
1283
1284 // Converted to actual sizable element
1285 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1286
1287 // Get size as string
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001288 strResult = pConfigurableElement->getFootprintAsString();
Patrick Benavoli68a91282011-08-31 11:23:23 +02001289
Patrick Benavoli63499d42011-10-24 18:50:03 +02001290 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001291}
1292
Patrick Benavoli63499d42011-10-24 18:50:03 +02001293CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showPropertiesCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001294{
1295 CElementLocator elementLocator(getSystemClass());
1296
1297 CElement* pLocatedElement = NULL;
1298
1299 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1300
Patrick Benavoli63499d42011-10-24 18:50:03 +02001301 return CCommandHandler::EFailed;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001302 }
1303
1304 // Convert element
1305 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1306
1307 // Return element properties
1308 pConfigurableElement->showProperties(strResult);
1309
Patrick Benavoli63499d42011-10-24 18:50:03 +02001310 return CCommandHandler::ESucceeded;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001311}
1312
Patrick Benavoli63499d42011-10-24 18:50:03 +02001313CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001314{
1315 string strValue;
1316
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001317 if (!accessParameterValue(remoteCommand.getArgument(0), strValue, false, strResult)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001318
Patrick Benavoli63499d42011-10-24 18:50:03 +02001319 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001320 }
1321 // Succeeded
1322 strResult = strValue;
1323
Patrick Benavoli63499d42011-10-24 18:50:03 +02001324 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001325}
1326
Patrick Benavoli63499d42011-10-24 18:50:03 +02001327CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001328{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001329 // Check tuning mode
1330 if (!checkTuningModeOn(strResult)) {
1331
1332 return CCommandHandler::EFailed;
1333 }
1334 // Get value to set
1335 string strValue = remoteCommand.packArguments(1, remoteCommand.getArgumentCount() - 1);
1336
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001337 return accessParameterValue(remoteCommand.getArgument(0), strValue, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001338}
1339
Patrick Benavoli63499d42011-10-24 18:50:03 +02001340CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listBelongingDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001341{
1342 CElementLocator elementLocator(getSystemClass());
1343
1344 CElement* pLocatedElement = NULL;
1345
1346 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1347
Patrick Benavoli63499d42011-10-24 18:50:03 +02001348 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001349 }
1350
1351 // Convert element
1352 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1353
1354 // Return element belonging domains
1355 pConfigurableElement->listBelongingDomains(strResult);
1356
Patrick Benavoli63499d42011-10-24 18:50:03 +02001357 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001358}
1359
Patrick Benavoli63499d42011-10-24 18:50:03 +02001360CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001361{
1362 CElementLocator elementLocator(getSystemClass());
1363
1364 CElement* pLocatedElement = NULL;
1365
1366 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1367
Patrick Benavoli63499d42011-10-24 18:50:03 +02001368 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001369 }
1370
1371 // Convert element
1372 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1373
1374 // Return element belonging domains
1375 pConfigurableElement->listAssociatedDomains(strResult);
1376
Patrick Benavoli63499d42011-10-24 18:50:03 +02001377 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001378}
1379
Patrick Benavoli63499d42011-10-24 18:50:03 +02001380CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001381{
1382 (void)remoteCommand;
1383
1384 getConfigurableDomains()->listAssociatedElements(strResult);
1385
Patrick Benavoli63499d42011-10-24 18:50:03 +02001386 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001387}
1388
Patrick Benavoli63499d42011-10-24 18:50:03 +02001389CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConflictingElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001390{
1391 (void)remoteCommand;
1392
1393 getConfigurableDomains()->listConflictingElements(strResult);
1394
Patrick Benavoli63499d42011-10-24 18:50:03 +02001395 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001396}
1397
Patrick Benavoli63499d42011-10-24 18:50:03 +02001398CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listRogueElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001399{
1400 (void)remoteCommand;
1401
1402 getSystemClass()->listRogueElements(strResult);
1403
Patrick Benavoli63499d42011-10-24 18:50:03 +02001404 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001405}
1406
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001407CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getConfigurationParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1408{
1409 string strOutputValue;
1410 string strError;
1411
1412 if (!accessConfigurationValue(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), strOutputValue, false, strError)) {
1413
1414 strResult = strError;
1415 return CCommandHandler::EFailed;
1416 }
1417 // Succeeded
1418 strResult = strOutputValue;
1419
1420 return CCommandHandler::ESucceeded;
1421}
1422
1423CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setConfigurationParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1424{
1425 // Get value to set
1426 string strValue = remoteCommand.packArguments(3, remoteCommand.getArgumentCount() - 3);
1427
1428 bool bSuccess = accessConfigurationValue(remoteCommand.getArgument(0),
1429 remoteCommand.getArgument(1),
1430 remoteCommand.getArgument(2),
1431 strValue, true, strResult);
1432
1433 return bSuccess ? CCommandHandler::EDone : CCommandHandler::EFailed;
1434}
1435
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +02001436CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showMappingCommmandProcess(
1437 const IRemoteCommand& remoteCommand,
1438 string& strResult)
1439{
1440 if (!getParameterMapping(remoteCommand.getArgument(0), strResult)) {
1441
1442 return CCommandHandler::EFailed;
1443 }
1444
1445 return CCommandHandler::ESucceeded;
1446}
1447
Patrick Benavoli68a91282011-08-31 11:23:23 +02001448/// Settings Import/Export
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001449CParameterMgr::CCommandHandler::CommandStatus
1450 CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess(
1451 const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001452{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001453 string strFileName = remoteCommand.getArgument(0);
1454 return exportDomainsXml(strFileName, false, true, strResult) ?
1455 CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001456}
1457
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001458CParameterMgr::CCommandHandler::CommandStatus
1459 CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess(
1460 const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001461{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001462 return importDomainsXml(remoteCommand.getArgument(0), false, true, strResult) ?
1463 CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001464}
1465
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001466CParameterMgr::CCommandHandler::CommandStatus
1467 CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess(
1468 const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001469{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001470 string strFileName = remoteCommand.getArgument(0);
1471 return exportDomainsXml(strFileName, true, true, strResult) ?
1472 CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001473}
1474
Patrick Benavoli63499d42011-10-24 18:50:03 +02001475CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001476{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001477 return importDomainsXml(remoteCommand.getArgument(0), true, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001478}
1479
Patrick Benavoli63499d42011-10-24 18:50:03 +02001480CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001481{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001482 return exportDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001483}
1484
Patrick Benavoli63499d42011-10-24 18:50:03 +02001485CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001486{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001487 return importDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001488}
1489
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001490CParameterMgr::CCommandHandler::CommandStatus
1491 CParameterMgr::getConfigurableDomainsWithSettingsXMLCommmandProcess(
1492 const IRemoteCommand& remoteCommand, string& strResult)
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001493{
1494 (void)remoteCommand;
1495
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001496 if (!exportDomainsXml(strResult, true, false, strResult)) {
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001497
1498 return CCommandHandler::EFailed;
1499 }
1500 // Succeeded
1501 return CCommandHandler::ESucceeded;
1502}
1503
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001504CParameterMgr::CCommandHandler::CommandStatus
1505 CParameterMgr::setConfigurableDomainsWithSettingsXMLCommmandProcess(
1506 const IRemoteCommand& remoteCommand, string& strResult)
1507{
1508 return importDomainsXml(remoteCommand.getArgument(0), true, false, strResult) ?
1509 CCommandHandler::EDone : CCommandHandler::EFailed;
1510}
1511
1512CParameterMgr::CCommandHandler::CommandStatus
1513 CParameterMgr::getSystemClassXMLCommmandProcess(
1514 const IRemoteCommand& remoteCommand, string& strResult)
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001515{
1516 (void)remoteCommand;
1517
1518 if (!getSystemClassXMLString(strResult)) {
1519
1520 return CCommandHandler::EFailed;
1521 }
1522 // Succeeded
1523 return CCommandHandler::ESucceeded;
1524}
1525
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001526// User set/get parameters in main BlackBoard
1527bool CParameterMgr::accessParameterValue(const string& strPath, string& strValue, bool bSet, string& strError)
1528{
1529 // Define context
1530 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
1531
Frédéric Boisnard150407c2013-03-15 14:46:23 +01001532 // Activate the auto synchronization with the hardware
1533 if (bSet) {
1534
1535 parameterAccessContext.setAutoSync(_bAutoSyncOn);
1536 }
1537
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001538 return accessValue(parameterAccessContext, strPath, strValue, bSet, strError);
1539}
1540
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +02001541// User get parameter mapping
1542bool CParameterMgr::getParameterMapping(const string& strPath, string& strResult) const
1543{
1544 CPathNavigator pathNavigator(strPath);
1545
1546 // Nagivate through system class
1547 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strResult)) {
1548
1549 return false;
1550 }
1551
1552 // Get the ConfigurableElement corresponding to strPath
1553 const CConfigurableElement* pConfigurableElement = getConfigurableElement(strPath, strResult);
1554 if (!pConfigurableElement) {
1555
1556 return false;
1557 }
1558
1559 // Find the list of the ancestors of the current ConfigurableElement that have a mapping
1560 list<const CConfigurableElement*> configurableElementPath;
1561 pConfigurableElement->getListOfElementsWithMapping(configurableElementPath);
1562
1563 // Get the Subsystem containing the ConfigurableElement
1564 const CSubsystem* pSubsystem = pConfigurableElement->getBelongingSubsystem();
1565 if (!pSubsystem) {
1566
1567 strResult = "Unable to find the Subsystem containing the parameter";
1568 return false;
1569 }
1570
1571 // Fetch the mapping corresponding to the ConfigurableElement
1572 strResult = pSubsystem->getMapping(configurableElementPath);
1573
1574 return true;
1575}
1576
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001577// User set/get parameters in specific Configuration BlackBoard
1578bool CParameterMgr::accessConfigurationValue(const string& strDomain, const string& strConfiguration, const string& strPath, string& strValue, bool bSet, string& strError)
1579{
1580 CElementLocator elementLocator(getSystemClass());
1581
1582 CElement* pLocatedElement = NULL;
1583
1584 if (!elementLocator.locate(strPath, &pLocatedElement, strError)) {
1585
1586 return false;
1587 }
1588
1589 // Convert element
1590 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1591
1592 // Get the Configuration blackboard and the Base Offset of the configurable element in this blackboard
1593 uint32_t uiBaseOffset;
1594 bool bIsLastApplied;
1595
1596 CParameterBlackboard* pConfigurationBlackboard = getConstConfigurableDomains()->findConfigurationBlackboard(strDomain, strConfiguration, pConfigurableElement, uiBaseOffset, bIsLastApplied, strError);
1597
1598 if (!pConfigurationBlackboard) {
1599
1600 return false;
1601 }
1602
1603 log_info("Element %s in Domain %s, offset: %d, base offset: %d", strPath.c_str(), strDomain.c_str(), pConfigurableElement->getOffset(), uiBaseOffset);
1604
1605 /// Update the Configuration Blackboard
1606
Frédéric Boisnard150407c2013-03-15 14:46:23 +01001607 // 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 +01001608 CParameterAccessContext parameterAccessContext(strError, pConfigurationBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex, uiBaseOffset);
1609
1610 // Access Value in the Configuration Blackboard
1611 if (!accessValue(parameterAccessContext, strPath, strValue, bSet, strError)) {
1612
1613 return false;
1614 }
1615
1616 /// If the Configuration is the last one applied, update the Main Blackboard as well
1617
1618 if (bIsLastApplied) {
1619
1620 // Define Main context
1621 parameterAccessContext.setParameterBlackboard(_pMainParameterBlackboard);
1622
Frédéric Boisnard150407c2013-03-15 14:46:23 +01001623 // Activate the auto synchronization with the hardware
1624 if (bSet) {
1625
1626 parameterAccessContext.setAutoSync(_bAutoSyncOn);
1627 }
1628
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001629 // Access Value in the Main Blackboard
1630 return accessValue(parameterAccessContext, strPath, strValue, bSet, strError);
1631 }
1632
1633 return true;
1634}
1635
Patrick Benavoli68a91282011-08-31 11:23:23 +02001636// User set/get parameters
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001637bool CParameterMgr::accessValue(CParameterAccessContext& parameterAccessContext, const string& strPath, string& strValue, bool bSet, string& strError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001638{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001639 // Lock state
1640 CAutoLock autoLock(&_blackboardMutex);
1641
1642 CPathNavigator pathNavigator(strPath);
1643
1644 // Nagivate through system class
1645 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001646
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +02001647 parameterAccessContext.setError(strError);
1648
Patrick Benavoli68a91282011-08-31 11:23:23 +02001649 return false;
1650 }
1651
Patrick Benavoli065264a2011-11-20 15:46:41 +01001652 // Do the get
1653 return getConstSystemClass()->accessValue(pathNavigator, strValue, bSet, parameterAccessContext);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001654}
1655
1656// Tuning mode
1657bool CParameterMgr::setTuningMode(bool bOn, string& strError)
1658{
1659 // Tuning allowed?
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001660 if (bOn && !getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001661
1662 strError = "Tuning prohibited";
1663
1664 return false;
1665 }
1666 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +01001667 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001668
1669 // Warn domains about exiting tuning mode
1670 if (!bOn && _bTuningModeIsOn) {
1671
1672 // Ensure application of currently selected configurations
Patrick Benavoli1387bda2011-08-31 11:23:24 +02001673 // Force-apply configurations
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01001674 doApplyConfigurations(true);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001675
Patrick Benavoli68a91282011-08-31 11:23:23 +02001676 // Turn auto sync back on
1677 _bAutoSyncOn = true;
1678 }
1679
1680 // Store
1681 _bTuningModeIsOn = bOn;
1682
Patrick Benavoli68a91282011-08-31 11:23:23 +02001683 return true;
1684}
1685
1686bool CParameterMgr::tuningModeOn() const
1687{
1688 return _bTuningModeIsOn;
1689}
1690
1691// Current value space for user set/get value interpretation
1692void CParameterMgr::setValueSpace(bool bIsRaw)
1693{
1694 _bValueSpaceIsRaw = bIsRaw;
1695}
1696
1697bool CParameterMgr::valueSpaceIsRaw()
1698{
1699 return _bValueSpaceIsRaw;
1700}
1701
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001702// Current Output Raw Format for user get value interpretation
1703void CParameterMgr::setOutputRawFormat(bool bIsHex)
1704{
1705 _bOutputRawFormatIsHex = bIsHex;
1706}
1707
1708bool CParameterMgr::outputRawFormatIsHex()
1709{
1710 return _bOutputRawFormatIsHex;
1711}
1712
Patrick Benavoli68a91282011-08-31 11:23:23 +02001713/// Sync
1714// Automatic hardware synchronization control (during tuning session)
1715bool CParameterMgr::setAutoSync(bool bAutoSyncOn, string& strError)
1716{
1717 // Check tuning mode
1718 if (!checkTuningModeOn(strError)) {
1719
1720 return false;
1721 }
1722 // Warn domains about turning auto sync back on
1723 if (bAutoSyncOn && !_bAutoSyncOn) {
1724
Patrick Benavoli592ae562011-09-05 16:53:58 +02001725 // Do the synchronization at system class level (could be optimized by keeping track of all modified parameters)
1726 if (!sync(strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001727
1728 return false;
1729 }
1730 }
1731
1732 // Set Auto sync
1733 _bAutoSyncOn = bAutoSyncOn;
1734
1735 return true;
1736}
1737
1738bool CParameterMgr::autoSyncOn() const
1739{
1740 return _bAutoSyncOn;
1741}
1742
1743// Manual hardware synchronization control (during tuning session)
1744bool CParameterMgr::sync(string& strError)
1745{
1746 // Check tuning mode
1747 if (!checkTuningModeOn(strError)) {
1748
1749 return false;
1750 }
1751 // Warn domains about turning auto sync back on
1752 if (_bAutoSyncOn) {
1753
1754 strError = "Feature unavailable when Auto Sync is on";
1755
1756 return false;
1757 }
1758
1759 // Get syncer set
1760 CSyncerSet syncerSet;
1761 // ... from system class
1762 getConstSystemClass()->fillSyncerSet(syncerSet);
Kevin Rocardace81f82012-12-11 16:19:17 +01001763
Patrick Benavoli68a91282011-08-31 11:23:23 +02001764 // Sync
Kevin Rocardace81f82012-12-11 16:19:17 +01001765 list<string> lstrError;
1766 if (! syncerSet.sync(*_pMainParameterBlackboard, false, &lstrError)){
1767
Frederic Boisnard390b36d2013-05-23 15:28:31 +02001768 CUtility::asString(lstrError, strError);
Kevin Rocardace81f82012-12-11 16:19:17 +01001769 return false;
1770 };
1771
1772 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001773}
1774
1775// Content dump
1776void CParameterMgr::logStructureContent(string& strContent) const
1777{
1778 string strError;
1779
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001780 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001781
1782 dumpContent(strContent, parameterAccessContext);
1783}
1784
1785// Configuration/Domains handling
1786bool CParameterMgr::createDomain(const string& strName, string& strError)
1787{
1788 // Check tuning mode
1789 if (!checkTuningModeOn(strError)) {
1790
1791 return false;
1792 }
1793
1794 // Delegate to configurable domains
1795 return getConfigurableDomains()->createDomain(strName, strError);
1796}
1797
1798bool CParameterMgr::deleteDomain(const string& strName, string& strError)
1799{
1800 // Check tuning mode
1801 if (!checkTuningModeOn(strError)) {
1802
1803 return false;
1804 }
1805
1806 // Delegate to configurable domains
1807 return getConfigurableDomains()->deleteDomain(strName, strError);
1808}
1809
Kevin Rocard170f0a42012-06-18 13:56:05 +02001810bool CParameterMgr::deleteAllDomains(string& strError)
1811{
1812 // Check tuning mode
1813 if (!checkTuningModeOn(strError)) {
1814
1815 return false;
1816 }
1817
1818 // Delegate to configurable domains
1819 getConfigurableDomains()->deleteAllDomains();
1820
1821 return true;
1822}
1823
Patrick Benavoli68a91282011-08-31 11:23:23 +02001824bool CParameterMgr::createConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1825{
1826 // Check tuning mode
1827 if (!checkTuningModeOn(strError)) {
1828
1829 return false;
1830 }
1831
1832 // Delegate to configurable domains
1833 return getConfigurableDomains()->createConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1834}
1835
1836bool CParameterMgr::deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1837{
1838 // Check tuning mode
1839 if (!checkTuningModeOn(strError)) {
1840
1841 return false;
1842 }
1843
1844 // Delegate to configurable domains
1845 return getConfigurableDomains()->deleteConfiguration(strDomain, strConfiguration, strError);
1846}
1847
Kevin Rocardace81f82012-12-11 16:19:17 +01001848bool CParameterMgr::restoreConfiguration(const string& strDomain, const string& strConfiguration, list<string>& lstrError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001849{
Kevin Rocardace81f82012-12-11 16:19:17 +01001850 string strError;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001851 // Check tuning mode
1852 if (!checkTuningModeOn(strError)) {
1853
Kevin Rocardace81f82012-12-11 16:19:17 +01001854 lstrError.push_back(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001855 return false;
1856 }
1857
1858 // Delegate to configurable domains
Kevin Rocardace81f82012-12-11 16:19:17 +01001859 return getConstConfigurableDomains()->restoreConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, lstrError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001860}
1861
1862bool CParameterMgr::saveConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1863{
1864 // Check tuning mode
1865 if (!checkTuningModeOn(strError)) {
1866
1867 return false;
1868 }
1869
1870 // Delegate to configurable domains
1871 return getConfigurableDomains()->saveConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1872}
1873
1874// Configurable element - domain association
1875bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1876{
1877 // Check tuning mode
1878 if (!checkTuningModeOn(strError)) {
1879
1880 return false;
1881 }
1882
1883 CElementLocator elementLocator(getSystemClass());
1884
1885 CElement* pLocatedElement = NULL;
1886
1887 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1888
1889 return false;
1890 }
1891
1892 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001893 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001894
1895 // Delegate
1896 return getConfigurableDomains()->addConfigurableElementToDomain(strDomain, pConfigurableElement, _pMainParameterBlackboard, strError);
1897}
1898
1899bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1900{
1901 // Check tuning mode
1902 if (!checkTuningModeOn(strError)) {
1903
1904 return false;
1905 }
1906
1907 CElementLocator elementLocator(getSystemClass());
1908
1909 CElement* pLocatedElement = NULL;
1910
1911 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1912
Patrick Benavoli63499d42011-10-24 18:50:03 +02001913 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001914 }
1915
1916 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001917 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001918
1919 // Delegate
1920 return getConfigurableDomains()->removeConfigurableElementFromDomain(strDomain, pConfigurableElement, strError);
1921}
1922
1923bool CParameterMgr::split(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1924{
1925 // Check tuning mode
1926 if (!checkTuningModeOn(strError)) {
1927
1928 return false;
1929 }
1930
1931 CElementLocator elementLocator(getSystemClass());
1932
1933 CElement* pLocatedElement = NULL;
1934
1935 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1936
Patrick Benavoli63499d42011-10-24 18:50:03 +02001937 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001938 }
1939
1940 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001941 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001942
1943 // Delegate
1944 return getConfigurableDomains()->split(strDomain, pConfigurableElement, strError);
1945}
1946
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001947bool CParameterMgr::importDomainsXml(const string& strXmlSource, bool bWithSettings,
1948 bool bFromFile, string& strError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001949{
1950 // Check tuning mode
1951 if (!checkTuningModeOn(strError)) {
1952
1953 return false;
1954 }
1955
1956 // check path is absolute
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001957 if (bFromFile && strXmlSource[0] != '/') {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001958
1959 strError = "Please provide absolute path";
1960
1961 return false;
1962 }
1963 // Root element
1964 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1965
1966 // Context
1967 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1968
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001969 // Selection criteria definition for rule creation
1970 xmlDomainSerializingContext.setSelectionCriteriaDefinition(
1971 getConstSelectionCriteria()->getSelectionCriteriaDefinition());
Patrick Benavoli68a91282011-08-31 11:23:23 +02001972
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001973 // Init serializing context
1974 xmlDomainSerializingContext.set(
1975 _pElementLibrarySet->getElementLibrary(EParameterConfigurationLibrary),
1976 "", _strSchemaFolderLocation);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001977
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001978 // Get Schema file associated to root element
1979 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" +
1980 pConfigurableDomains->getKind() + ".xsd";
1981
1982 // Xml Source
1983 CXmlDocSource* pSource;
1984
1985 if (bFromFile) {
1986
1987 // when importing from a file strXmlSource is the file name
1988 pSource = new CXmlFileDocSource(strXmlSource, strXmlSchemaFilePath,
1989 pConfigurableDomains->getKind(),
1990 pConfigurableDomains->getName(), "SystemClassName");
1991
1992 } else {
1993
1994 // when importing from an xml string, strXmlSource contains the string
1995 pSource = new CXmlStringDocSource(strXmlSource, strXmlSchemaFilePath,
1996 pConfigurableDomains->getKind(),
1997 pConfigurableDomains->getName(), "SystemClassName");
1998
1999 }
2000 // Start clean
2001 pConfigurableDomains->clean();
2002
2003 // Use a doc sink that instantiate Configurable Domains from the given doc source
2004 CXmlMemoryDocSink memorySink(pConfigurableDomains);
2005
2006 bool bProcessSuccess = memorySink.process(*pSource, xmlDomainSerializingContext);
2007
2008 if (!bProcessSuccess) {
2009
2010 //Cleanup
2011 pConfigurableDomains->clean();
2012
2013 } else {
2014
2015 // Validate domains after XML import
2016 pConfigurableDomains->validate(_pMainParameterBlackboard);
2017
Patrick Benavoli68a91282011-08-31 11:23:23 +02002018 }
2019
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002020 delete pSource;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002021
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002022 return bProcessSuccess;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002023}
2024
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002025bool CParameterMgr::exportDomainsXml(string& strXmlDest, bool bWithSettings, bool bToFile,
2026 string& strError) const
Patrick Benavoli68a91282011-08-31 11:23:23 +02002027{
2028 // check path is absolute
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002029 if (bToFile && strXmlDest[0] != '/') {
Patrick Benavoli68a91282011-08-31 11:23:23 +02002030
2031 strError = "Please provide absolute path";
2032
2033 return false;
2034 }
2035
2036 // Root element
2037 const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains();
2038
2039 // Get Schema file associated to root element
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002040 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" +
2041 pConfigurableDomains->getKind() + ".xsd";
Patrick Benavoli68a91282011-08-31 11:23:23 +02002042
2043 // Context
2044 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
2045
2046 // Value space
2047 xmlDomainSerializingContext.setValueSpaceRaw(_bValueSpaceIsRaw);
2048
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02002049 // Output raw format
2050 xmlDomainSerializingContext.setOutputRawFormat(_bOutputRawFormatIsHex);
2051
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002052 // Use a doc source by loading data from instantiated Configurable Domains
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002053 CXmlMemoryDocSource memorySource(pConfigurableDomains, pConfigurableDomains->getKind(),
2054 strXmlSchemaFilePath, "parameter-framework", getVersion());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002055
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002056 // Xml Sink
2057 CXmlDocSink* pSink;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002058
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002059 if (bToFile) {
2060
2061 // Use a doc sink to write the doc data in a file
2062 pSink = new CXmlFileDocSink(strXmlDest);
2063
2064 } else {
2065
2066 // Use a doc sink to write the doc data in a string
2067 pSink = new CXmlStringDocSink(strXmlDest);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002068 }
2069
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002070 bool bProcessSuccess = pSink->process(memorySource, xmlDomainSerializingContext);
2071
2072 delete pSink;
2073 return bProcessSuccess;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002074}
2075
2076// Binary Import/Export
2077bool CParameterMgr::importDomainsBinary(const string& strFileName, string& strError)
2078{
2079 // Check tuning mode
2080 if (!checkTuningModeOn(strError)) {
2081
2082 return false;
2083 }
2084 // check path is absolute
2085 if (strFileName[0] != '/') {
2086
2087 strError = "Please provide absolute path";
2088
2089 return false;
2090 }
2091 // Root element
2092 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
2093
2094 // Serialize in
2095 return pConfigurableDomains->serializeSettings(strFileName, false, _uiStructureChecksum, strError);
2096}
2097
2098bool CParameterMgr::exportDomainsBinary(const string& strFileName, string& strError)
2099{
2100 // check path is absolute
2101 if (strFileName[0] != '/') {
2102
2103 strError = "Please provide absolute path";
2104
2105 return false;
2106 }
Patrick Benavoli68a91282011-08-31 11:23:23 +02002107
Patrick Benavoli68a91282011-08-31 11:23:23 +02002108 // Root element
2109 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
2110
2111 // Serialize out
2112 return pConfigurableDomains->serializeSettings(strFileName, true, _uiStructureChecksum, strError);
2113}
2114
2115// For tuning, check we're in tuning mode
2116bool CParameterMgr::checkTuningModeOn(string& strError) const
2117{
2118 // Tuning Mode on?
2119 if (!_bTuningModeIsOn) {
2120
2121 strError = "Tuning Mode must be on";
2122
2123 return false;
2124 }
2125 return true;
2126}
2127
Patrick Benavoli065264a2011-11-20 15:46:41 +01002128// Tuning mutex dynamic parameter handling
2129pthread_mutex_t* CParameterMgr::getBlackboardMutex()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002130{
Patrick Benavoli065264a2011-11-20 15:46:41 +01002131 return &_blackboardMutex;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002132}
2133
Patrick Benavoli065264a2011-11-20 15:46:41 +01002134// Blackboard reference (dynamic parameter handling)
2135CParameterBlackboard* CParameterMgr::getParameterBlackboard()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002136{
Patrick Benavoli065264a2011-11-20 15:46:41 +01002137 return _pMainParameterBlackboard;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002138}
2139
Patrick Benavoli68a91282011-08-31 11:23:23 +02002140// Dynamic creation library feeding
2141void CParameterMgr::feedElementLibraries()
2142{
2143 // Global Configuration handling
2144 CElementLibrary* pFrameworkConfigurationLibrary = new CElementLibrary;
2145
Kevin Rocarda7b69602013-08-07 16:15:33 +02002146 pFrameworkConfigurationLibrary->addElementBuilder("ParameterFrameworkConfiguration", new TElementBuilderTemplate<CParameterFrameworkConfiguration>());
2147 pFrameworkConfigurationLibrary->addElementBuilder("SubsystemPlugins", new TKindElementBuilderTemplate<CSubsystemPlugins>());
2148 pFrameworkConfigurationLibrary->addElementBuilder("Location", new TKindElementBuilderTemplate<CPluginLocation>());
2149 pFrameworkConfigurationLibrary->addElementBuilder("StructureDescriptionFileLocation", new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>());
2150 pFrameworkConfigurationLibrary->addElementBuilder("SettingsConfiguration", new TKindElementBuilderTemplate<CFrameworkConfigurationGroup>());
2151 pFrameworkConfigurationLibrary->addElementBuilder("ConfigurableDomainsFileLocation", new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>());
2152 pFrameworkConfigurationLibrary->addElementBuilder("BinarySettingsFileLocation", new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002153
2154 _pElementLibrarySet->addElementLibrary(pFrameworkConfigurationLibrary);
2155
2156 // Parameter creation
2157 CElementLibrary* pParameterCreationLibrary = new CElementLibrary;
2158
Kevin Rocarda7b69602013-08-07 16:15:33 +02002159 pParameterCreationLibrary->addElementBuilder("Subsystem", new CSubsystemElementBuilder(getSystemClass()->getSubsystemLibrary()));
2160 pParameterCreationLibrary->addElementBuilder("ComponentType", new TNamedElementBuilderTemplate<CComponentType>());
2161 pParameterCreationLibrary->addElementBuilder("Component", new TNamedElementBuilderTemplate<CComponentInstance>());
2162 pParameterCreationLibrary->addElementBuilder("BitParameter", new TNamedElementBuilderTemplate<CBitParameterType>());
2163 pParameterCreationLibrary->addElementBuilder("BitParameterBlock", new TNamedElementBuilderTemplate<CBitParameterBlockType>());
2164 pParameterCreationLibrary->addElementBuilder("StringParameter", new TNamedElementBuilderTemplate<CStringParameterType>());
2165 pParameterCreationLibrary->addElementBuilder("ParameterBlock", new TNamedElementBuilderTemplate<CParameterBlockType>());
2166 pParameterCreationLibrary->addElementBuilder("BooleanParameter", new TNamedElementBuilderTemplate<CBooleanParameterType>());
2167 pParameterCreationLibrary->addElementBuilder("IntegerParameter", new TNamedElementBuilderTemplate<CIntegerParameterType>());
2168 pParameterCreationLibrary->addElementBuilder("LinearAdaptation", new TElementBuilderTemplate<CLinearParameterAdaptation>());
2169 pParameterCreationLibrary->addElementBuilder("EnumParameter", new TNamedElementBuilderTemplate<CEnumParameterType>());
2170 pParameterCreationLibrary->addElementBuilder("ValuePair", new TElementBuilderTemplate<CEnumValuePair>());
2171 pParameterCreationLibrary->addElementBuilder("FixedPointParameter", new TNamedElementBuilderTemplate<CFixedPointParameterType>());
2172 pParameterCreationLibrary->addElementBuilder("SubsystemInclude", new TKindElementBuilderTemplate<CXmlFileIncluderElement>());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002173
2174 _pElementLibrarySet->addElementLibrary(pParameterCreationLibrary);
2175
2176 // Parameter Configuration Domains creation
2177 CElementLibrary* pParameterConfigurationLibrary = new CElementLibrary;
2178
Kevin Rocarda7b69602013-08-07 16:15:33 +02002179 pParameterConfigurationLibrary->addElementBuilder("ConfigurableDomain", new TNamedElementBuilderTemplate<CConfigurableDomain>());
2180 pParameterConfigurationLibrary->addElementBuilder("Configuration", new TNamedElementBuilderTemplate<CDomainConfiguration>());
2181 pParameterConfigurationLibrary->addElementBuilder("CompoundRule", new TElementBuilderTemplate<CCompoundRule>());
2182 pParameterConfigurationLibrary->addElementBuilder("SelectionCriterionRule", new TElementBuilderTemplate<CSelectionCriterionRule>());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002183
2184 _pElementLibrarySet->addElementLibrary(pParameterConfigurationLibrary);
2185}
2186
2187// Remote Processor Server connection handling
2188bool CParameterMgr::handleRemoteProcessingInterface(string& strError)
2189{
2190 CAutoLog autoLog(this, "Handling remote processing interface");
2191
2192 // Start server if tuning allowed
Patrick Benavoli95ac0342011-11-07 20:32:51 +01002193 if (getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02002194
Kevin Rocardace81f82012-12-11 16:19:17 +01002195 log_info("Loading remote processor library");
Patrick Benavoli68a91282011-08-31 11:23:23 +02002196
2197 // Load library
2198 void* lib_handle = dlopen("libremote-processor.so", RTLD_NOW);
2199
2200 if (!lib_handle) {
2201
2202 // Return error
2203 const char* pcError = dlerror();
2204
2205 if (pcError) {
2206
2207 strError = pcError;
2208 } else {
2209
2210 strError = "Unable to load libremote-processor.so library";
2211 }
2212
2213 return false;
2214 }
2215
2216 CreateRemoteProcessorServer pfnCreateRemoteProcessorServer = (CreateRemoteProcessorServer)dlsym(lib_handle, "createRemoteProcessorServer");
2217
2218 if (!pfnCreateRemoteProcessorServer) {
2219
2220 strError = "libremote-process.so does not contain createRemoteProcessorServer symbol.";
2221
2222 return false;
2223 }
2224
2225 // Create server
Patrick Benavoli95ac0342011-11-07 20:32:51 +01002226 _pRemoteProcessorServer = pfnCreateRemoteProcessorServer(getConstFrameworkConfiguration()->getServerPort(), _pCommandHandler);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002227
Kevin Rocardace81f82012-12-11 16:19:17 +01002228 log_info("Starting remote processor server on port %d", getConstFrameworkConfiguration()->getServerPort());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002229 // Start
2230 if (!_pRemoteProcessorServer->start()) {
2231
2232 strError = "Unable to start remote processor server";
2233
2234 return false;
2235 }
2236 }
2237
2238 return true;
2239}
2240
2241// Back synchronization
Kevin Rocardace81f82012-12-11 16:19:17 +01002242CBackSynchronizer* CParameterMgr::createBackSynchronizer() const
Patrick Benavoli68a91282011-08-31 11:23:23 +02002243{
2244#ifdef SIMULATION
2245 // In simulation, back synchronization of the blackboard won't probably work
2246 // We need to ensure though the blackboard is initialized with valid data
Kevin Rocardace81f82012-12-11 16:19:17 +01002247 return new CSimulatedBackSynchronizer(getConstSystemClass(), _pMainParameterBlackboard);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002248#else
2249 // Real back synchronizer from subsystems
Kevin Rocardace81f82012-12-11 16:19:17 +01002250 return new CHardwareBackSynchronizer(getConstSystemClass(), _pMainParameterBlackboard);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002251#endif
2252}
2253
2254// Children typwise access
2255CParameterFrameworkConfiguration* CParameterMgr::getFrameworkConfiguration()
2256{
2257 return static_cast<CParameterFrameworkConfiguration*>(getChild(EFrameworkConfiguration));
2258}
2259
2260const CParameterFrameworkConfiguration* CParameterMgr::getConstFrameworkConfiguration()
2261{
2262 return getFrameworkConfiguration();
2263}
2264
2265CSelectionCriteria* CParameterMgr::getSelectionCriteria()
2266{
2267 return static_cast<CSelectionCriteria*>(getChild(ESelectionCriteria));
2268}
2269
2270const CSelectionCriteria* CParameterMgr::getConstSelectionCriteria()
2271{
2272 return static_cast<const CSelectionCriteria*>(getChild(ESelectionCriteria));
2273}
2274
2275CSystemClass* CParameterMgr::getSystemClass()
2276{
2277 return static_cast<CSystemClass*>(getChild(ESystemClass));
2278}
2279
2280const CSystemClass* CParameterMgr::getConstSystemClass() const
2281{
2282 return static_cast<const CSystemClass*>(getChild(ESystemClass));
2283}
2284
2285// Configurable Domains
2286CConfigurableDomains* CParameterMgr::getConfigurableDomains()
2287{
2288 return static_cast<CConfigurableDomains*>(getChild(EConfigurableDomains));
2289}
2290
2291const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains()
2292{
2293 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
2294}
2295
2296const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains() const
2297{
2298 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
2299}
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002300
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01002301// Apply configurations
2302void CParameterMgr::doApplyConfigurations(bool bForce)
2303{
2304 CSyncerSet syncerSet;
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002305
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01002306 // Check subsystems that need resync
2307 getSystemClass()->checkForSubsystemsToResync(syncerSet);
2308
2309 // Ensure application of currently selected configurations
2310 getConfigurableDomains()->apply(_pMainParameterBlackboard, syncerSet, bForce);
2311
2312 // Reset the modified status of the current criteria to indicate that a new configuration has been applied
2313 getSelectionCriteria()->resetModifiedStatus();
2314}
2315
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002316bool CParameterMgr::getSystemClassXMLString(string& strResult)
2317{
2318 // Root element
2319 const CSystemClass* pSystemClass = getSystemClass();
2320
2321 string strError;
2322
2323 CXmlSerializingContext xmlSerializingContext(strError);
2324
2325 // Use a doc source by loading data from instantiated Configurable Domains
2326 CXmlMemoryDocSource memorySource(pSystemClass, pSystemClass->getKind());
2327
2328 // Use a doc sink that write the doc data in a string
2329 CXmlStringDocSink stringSink(strResult);
2330
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002331 bool bProcessSuccess = stringSink.process(memorySource, xmlSerializingContext);
2332
2333 if (!bProcessSuccess) {
2334
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002335 strResult = strError;
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002336
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002337 }
2338
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002339 return bProcessSuccess;
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002340}