blob: 927515c76319c1cff4ed6c0dfffea368c253133c [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),
284 _bFailOnMissingSubsystem(true)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200285{
286 // Tuning Mode Mutex
Patrick Benavoli065264a2011-11-20 15:46:41 +0100287 bzero(&_blackboardMutex, sizeof(_blackboardMutex));
288 pthread_mutex_init(&_blackboardMutex, NULL);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200289
290 // Deal with children
291 addChild(new CParameterFrameworkConfiguration);
292 addChild(new CSelectionCriteria);
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100293 addChild(new CSystemClass);
294 addChild(new CConfigurableDomains);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200295
296 // Feed element library
297 feedElementLibraries();
Patrick Benavoli63499d42011-10-24 18:50:03 +0200298
299 _pCommandHandler = new CCommandHandler(this);
300
301 // Add command parsers
302 uint32_t uiRemoteCommandParserItem;
303
304 for (uiRemoteCommandParserItem = 0; uiRemoteCommandParserItem < guiNbRemoteCommandParserItems; uiRemoteCommandParserItem++) {
305
306 const SRemoteCommandParserItem* pRemoteCommandParserItem = &gastRemoteCommandParserItems[uiRemoteCommandParserItem];
307
308 _pCommandHandler->addCommandParser(pRemoteCommandParserItem->_pcCommandName,
309 pRemoteCommandParserItem->_pfnParser,
310 pRemoteCommandParserItem->_uiMinArgumentCount,
311 pRemoteCommandParserItem->_pcHelp,
312 pRemoteCommandParserItem->_pcDescription);
313 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100314
315 // Configuration file folder
316 uint32_t uiSlashPos = _strXmlConfigurationFilePath.rfind('/', -1);
317
318 assert(uiSlashPos != (uint32_t)-1);
319
320 _strXmlConfigurationFolderPath = _strXmlConfigurationFilePath.substr(0, uiSlashPos);
321
322 // Schema absolute folder location
323 _strSchemaFolderLocation = _strXmlConfigurationFolderPath + "/" + gacSystemSchemasSubFolder;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200324}
325
326CParameterMgr::~CParameterMgr()
327{
328 // Children
329 delete _pRemoteProcessorServer;
Frederic Boisnard31242302012-04-26 17:07:34 +0200330 delete _pCommandHandler;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200331 delete _pMainParameterBlackboard;
332 delete _pElementLibrarySet;
333
334 // Tuning Mode Mutex
Patrick Benavoli065264a2011-11-20 15:46:41 +0100335 pthread_mutex_destroy(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200336}
337
338string CParameterMgr::getKind() const
339{
340 return "ParameterMgr";
341}
342
343// Logging
344void CParameterMgr::setLogger(CParameterMgr::ILogger* pLogger)
345{
346 _pLogger = pLogger;
347}
348
349// Logging
Kevin Rocardace81f82012-12-11 16:19:17 +0100350void CParameterMgr::doLog(bool bIsWarning, const string& strLog) const
Patrick Benavoli68a91282011-08-31 11:23:23 +0200351{
352 if (_pLogger) {
353
354 // Nest
355 string strIndent;
356
357 // Level
358 uint32_t uiNbIndents = _uiLogDepth;
359
360 while (uiNbIndents--) {
361
362 strIndent += " ";
363 }
364
365 // Log
Kevin Rocardace81f82012-12-11 16:19:17 +0100366 _pLogger->log(bIsWarning, strIndent + strLog);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200367 }
368}
369
370void CParameterMgr::nestLog() const
371{
Patrick Benavoli592ae562011-09-05 16:53:58 +0200372 _uiLogDepth++;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200373}
374
375void CParameterMgr::unnestLog() const
376{
Patrick Benavoli592ae562011-09-05 16:53:58 +0200377 _uiLogDepth--;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200378}
379
Patrick Benavoli63499d42011-10-24 18:50:03 +0200380// Version
381string CParameterMgr::getVersion() const
382{
383 string strVersion;
384
385 // Major
386 strVersion = toString(guiEditionMajor) + ".";
387 // Minor
388 strVersion += toString(guiEditionMinor) + ".";
389 // Revision
390 strVersion += toString(guiRevision);
391
392 return strVersion;
393}
394
Patrick Benavoli68a91282011-08-31 11:23:23 +0200395bool CParameterMgr::load(string& strError)
396{
397 CAutoLog autoLog(this, "Loading");
398
399 // Load Framework configuration
400 if (!loadFrameworkConfiguration(strError)) {
401
402 return false;
403 }
404
405 // Load subsystems
Kevin Rocardecf93102013-07-10 18:28:10 +0200406 if (!getSystemClass()->loadSubsystems(strError,
407 _pSubsystemPlugins, !_bFailOnMissingSubsystem)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200408
409 return false;
410 }
411
412 // Load structure
413 if (!loadStructure(strError)) {
414
415 return false;
416 }
417
418 // Load settings
419 if (!loadSettings(strError)) {
420
421 return false;
422 }
423
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200424 // Back synchronization for areas in parameter blackboard not covered by any domain
Kevin Rocardace81f82012-12-11 16:19:17 +0100425 CBackSynchronizer* pBackSynchronizer = createBackSynchronizer();
Patrick Benavoli68a91282011-08-31 11:23:23 +0200426
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200427 // Back-synchronize
Kevin Rocard57096bd2012-11-30 11:24:20 +0100428 {
429 CAutoLog autoLog(this, "Main blackboard back synchronization");
430
Kevin Rocard5d6e05a2013-01-21 15:57:45 +0100431 pBackSynchronizer->sync();
Kevin Rocard57096bd2012-11-30 11:24:20 +0100432
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200433 // Get rid of back synchronizer
434 delete pBackSynchronizer;
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200435 }
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200436
437 // We're done loading the settings and back synchronizing
438 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
439
440 // We need to ensure all domains are valid
441 pConfigurableDomains->validate(_pMainParameterBlackboard);
442
Kevin Rocard7f265822012-12-07 18:51:22 +0100443 // Log selection criterion states
444 {
445 CAutoLog autoLog(this, "Criterion states");
446
447 const CSelectionCriteria* selectionCriteria = getConstSelectionCriteria();
448
449 list<string> lstrSelectionCriteron;
450 selectionCriteria->listSelectionCriteria(lstrSelectionCriteron, true, false);
451
Kevin Rocard36299362013-02-04 14:57:47 +0100452 log_table(false, lstrSelectionCriteron);
Kevin Rocard7f265822012-12-07 18:51:22 +0100453 }
454
Kevin Rocard2fbe6e82013-03-26 17:09:29 +0100455 // Subsystem can not ask for resync as they have not been synced yet
456 getSystemClass()->cleanSubsystemsNeedToResync();
457
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100458 // At initialization, check subsystems that need resync
459 doApplyConfigurations(true);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200460
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200461 // Start remote processor server if appropriate
462 return handleRemoteProcessingInterface(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200463}
464
465bool CParameterMgr::loadFrameworkConfiguration(string& strError)
466{
467 CAutoLog autoLog(this, "Loading framework configuration");
468
Patrick Benavoli68a91282011-08-31 11:23:23 +0200469 // Parse Structure XML file
470 CXmlElementSerializingContext elementSerializingContext(strError);
471
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100472 if (!xmlParse(elementSerializingContext, getFrameworkConfiguration(), _strXmlConfigurationFilePath, _strXmlConfigurationFolderPath, EFrameworkConfigurationLibrary)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200473
474 return false;
475 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100476 // Set class name to system class and configurable domains
477 getSystemClass()->setName(getConstFrameworkConfiguration()->getSystemClassName());
478 getConfigurableDomains()->setName(getConstFrameworkConfiguration()->getSystemClassName());
479
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100480 // Get subsystem plugins elements
481 _pSubsystemPlugins = static_cast<const CSubsystemPlugins*>(getConstFrameworkConfiguration()->findChild("SubsystemPlugins"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200482
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100483 if (!_pSubsystemPlugins) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200484
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100485 strError = "Parameter Framework Configuration: couldn't find SubsystemPlugins element";
Patrick Benavoli68a91282011-08-31 11:23:23 +0200486
487 return false;
488 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200489
Patrick Benavoli68a91282011-08-31 11:23:23 +0200490 // Log tuning availability
Kevin Rocardace81f82012-12-11 16:19:17 +0100491 log_info("Tuning %s", getConstFrameworkConfiguration()->isTuningAllowed() ? "allowed" : "prohibited");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200492
493 return true;
494}
495
496bool CParameterMgr::loadStructure(string& strError)
497{
498 // Retrieve system to load structure to
499 CSystemClass* pSystemClass = getSystemClass();
500
Kevin Rocarde25ee792013-04-22 17:46:28 +0200501 log_info("Loading " + pSystemClass->getName() + " system class structure");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200502
503 // Get structure description element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100504 const CFrameworkConfigurationLocation* pStructureDescriptionFileLocation = static_cast<const CFrameworkConfigurationLocation*>(getConstFrameworkConfiguration()->findChildOfKind("StructureDescriptionFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200505
506 if (!pStructureDescriptionFileLocation) {
507
508 strError = "No StructureDescriptionFileLocation element found for SystemClass " + pSystemClass->getName();
509
510 return false;
511 }
512
513 // Get Xml structure folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100514 string strXmlStructureFolder = pStructureDescriptionFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200515
516 // Get Xml structure file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100517 string strXmlStructureFilePath = pStructureDescriptionFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200518
519 // Parse Structure XML file
520 CXmlParameterSerializingContext parameterBuildContext(strError);
521
Kevin Rocard57096bd2012-11-30 11:24:20 +0100522 CAutoLog autolog(pSystemClass, "Importing system structure from file " + strXmlStructureFilePath);
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200523
Patrick Benavoli68a91282011-08-31 11:23:23 +0200524 if (!xmlParse(parameterBuildContext, pSystemClass, strXmlStructureFilePath, strXmlStructureFolder, EParameterCreationLibrary)) {
525
526 return false;
527 }
528
529 // Initialize offsets
530 pSystemClass->setOffset(0);
531
532 // Initialize main blackboard's size
533 _pMainParameterBlackboard->setSize(pSystemClass->getFootPrint());
534
535 return true;
536}
537
538bool CParameterMgr::loadSettings(string& strError)
539{
540 CAutoLog autoLog(this, "Loading settings");
541
542 // Get settings configuration element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100543 const CFrameworkConfigurationGroup* pParameterConfigurationGroup = static_cast<const CFrameworkConfigurationGroup*>(getConstFrameworkConfiguration()->findChildOfKind("SettingsConfiguration"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200544
545 if (!pParameterConfigurationGroup) {
546
547 // No settings to load
548
549 return true;
550 }
551 // Get binary settings file location
552 const CFrameworkConfigurationLocation* pBinarySettingsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("BinarySettingsFileLocation"));
553
554 string strXmlBinarySettingsFilePath;
555
556 if (pBinarySettingsFileLocation) {
557
558 // Get Xml binary settings file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100559 strXmlBinarySettingsFilePath = pBinarySettingsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200560 }
561
562 // Get configurable domains element
563 const CFrameworkConfigurationLocation* pConfigurableDomainsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("ConfigurableDomainsFileLocation"));
564
565 if (!pConfigurableDomainsFileLocation) {
566
567 strError = "No ConfigurableDomainsFileLocation element found for SystemClass " + getSystemClass()->getName();
568
569 return false;
570 }
571 // Get destination root element
572 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
573
574 // Get Xml configuration domains file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100575 string strXmlConfigurationDomainsFilePath = pConfigurableDomainsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200576
577 // Get Xml configuration domains folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100578 string strXmlConfigurationDomainsFolder = pConfigurableDomainsFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200579
580 // Parse configuration domains XML file (ask to read settings from XML file if they are not provided as binary)
581 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, !pBinarySettingsFileLocation);
582
583 // Selection criteria definition for rule creation
584 xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
585
Patrick Benavoli63499d42011-10-24 18:50:03 +0200586 // Auto validation of configurations if no binary settings provided
587 xmlDomainSerializingContext.setAutoValidationRequired(!pBinarySettingsFileLocation);
588
Kevin Rocardace81f82012-12-11 16:19:17 +0100589 log_info("Importing configurable domains from file %s %s settings", strXmlConfigurationDomainsFilePath.c_str(), pBinarySettingsFileLocation ? "without" : "with");
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200590
Patrick Benavoli68a91282011-08-31 11:23:23 +0200591 // Do parse
592 if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strXmlConfigurationDomainsFilePath, strXmlConfigurationDomainsFolder, EParameterConfigurationLibrary, "SystemClassName")) {
593
594 return false;
595 }
596 // We have loaded the whole system structure, compute checksum
597 const CSystemClass* pSystemClass = getConstSystemClass();
598 _uiStructureChecksum = pSystemClass->computeStructureChecksum() + getConfigurableDomains()->computeStructureChecksum() + getSelectionCriteria()->computeStructureChecksum();
599
600 // Load binary settings if any provided
601 if (pBinarySettingsFileLocation && !pConfigurableDomains->serializeSettings(strXmlBinarySettingsFilePath, false, _uiStructureChecksum, strError)) {
602
603 return false;
604 }
605
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200606 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200607}
608
609// XML parsing
610bool CParameterMgr::xmlParse(CXmlElementSerializingContext& elementSerializingContext, CElement* pRootElement, const string& strXmlFilePath, const string& strXmlFolder, CParameterMgr::ElementLibrary eElementLibrary, const string& strNameAttrituteName)
611{
612 // Init serializing context
613 elementSerializingContext.set(_pElementLibrarySet->getElementLibrary(eElementLibrary), strXmlFolder, _strSchemaFolderLocation);
614
615 // Get Schema file associated to root element
616 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pRootElement->getKind() + ".xsd";
617
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200618 CXmlFileDocSource fileDocSource(strXmlFilePath, strXmlSchemaFilePath, pRootElement->getKind(), pRootElement->getName(), strNameAttrituteName);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200619
620 // Start clean
621 pRootElement->clean();
622
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200623 CXmlMemoryDocSink memorySink(pRootElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200624
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200625 if (!memorySink.process(fileDocSource, elementSerializingContext)) {
626 //Cleanup
Patrick Benavoli68a91282011-08-31 11:23:23 +0200627 pRootElement->clean();
628
629 return false;
630 }
631
Patrick Benavoli68a91282011-08-31 11:23:23 +0200632 return true;
633}
634
635// Init
636bool CParameterMgr::init(string& strError)
637{
638 return base::init(strError);
639}
640
641// Selection criteria interface
642CSelectionCriterionType* CParameterMgr::createSelectionCriterionType(bool bIsInclusive)
643{
644 // Propagate
645 return getSelectionCriteria()->createSelectionCriterionType(bIsInclusive);
646}
647
648CSelectionCriterion* CParameterMgr::createSelectionCriterion(const string& strName, const CSelectionCriterionType* pSelectionCriterionType)
649{
650 // Propagate
651 return getSelectionCriteria()->createSelectionCriterion(strName, pSelectionCriterionType);
652}
653
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200654// Selection criterion retrieval
655CSelectionCriterion* CParameterMgr::getSelectionCriterion(const string& strName)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200656{
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200657 // Propagate
658 return getSelectionCriteria()->getSelectionCriterion(strName);
659}
660
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100661// Configuration application
Kevin Rocardace81f82012-12-11 16:19:17 +0100662void CParameterMgr::applyConfigurations()
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200663{
664 CAutoLog autoLog(this, "Configuration application request");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200665
666 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +0100667 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200668
669 if (!_bTuningModeIsOn) {
670
671 // Apply configuration(s)
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100672 doApplyConfigurations(false);
Frédéric Boisnarddaaa63c2012-08-27 15:48:15 +0200673 } else {
674
Kevin Rocardace81f82012-12-11 16:19:17 +0100675 log_warning("Configurations were not applied because the TuningMode is on");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200676 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200677}
678
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200679// Get the configurableElement corresponding to the given path
680const CConfigurableElement* CParameterMgr::getConfigurableElement(const string& strPath,
681 string& strError) const
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200682{
Patrick Benavoli065264a2011-11-20 15:46:41 +0100683 CPathNavigator pathNavigator(strPath);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200684
Patrick Benavoli065264a2011-11-20 15:46:41 +0100685 // Nagivate through system class
686 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
687
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100688 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100689 }
690
691 // Find element
692 const CElement* pElement = getConstSystemClass()->findDescendant(pathNavigator);
693
694 if (!pElement) {
695
696 strError = "Path not found";
697
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100698 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100699 }
700
701 // Check found element is a parameter
702 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pElement);
703
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200704 return pConfigurableElement;
705}
706
707// Dynamic parameter handling
708CParameterHandle* CParameterMgr::createParameterHandle(const string& strPath, string& strError)
709{
710 const CConfigurableElement* pConfigurableElement = getConfigurableElement(strPath, strError);
711
712 if (!pConfigurableElement) {
713
714 // Element not found
715 strError = "Element not found";
716 return NULL;
717 }
718
Patrick Benavoli065264a2011-11-20 15:46:41 +0100719 if (!pConfigurableElement->isParameter()) {
720
721 // Element is not parameter
722 strError = "Not a parameter";
723
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100724 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100725 }
726
727 // Convert as parameter and return new handle
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200728 return new CParameterHandle(static_cast<const CBaseParameter*>(pConfigurableElement), this);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200729}
730
Kevin Rocardecf93102013-07-10 18:28:10 +0200731void CParameterMgr::setFailureOnMissingSubsystem(bool bFail)
732{
733 _bFailOnMissingSubsystem = bFail;
734}
735
736bool CParameterMgr::getFailureOnMissingSubsystem() const
737{
738 return _bFailOnMissingSubsystem;
739}
Patrick Benavoli68a91282011-08-31 11:23:23 +0200740/////////////////// Remote command parsers
Patrick Benavoli592ae562011-09-05 16:53:58 +0200741/// Version
Patrick Benavoli63499d42011-10-24 18:50:03 +0200742CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::versionCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli592ae562011-09-05 16:53:58 +0200743{
744 (void)remoteCommand;
745
Patrick Benavoli63499d42011-10-24 18:50:03 +0200746 // Show version
747 strResult = getVersion();
Patrick Benavoli592ae562011-09-05 16:53:58 +0200748
Patrick Benavoli63499d42011-10-24 18:50:03 +0200749 return CCommandHandler::ESucceeded;
Patrick Benavoli592ae562011-09-05 16:53:58 +0200750}
751
Patrick Benavoli68a91282011-08-31 11:23:23 +0200752/// Status
Patrick Benavoli63499d42011-10-24 18:50:03 +0200753CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::statusCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200754{
755 (void)remoteCommand;
756 // System class
757 const CSystemClass* pSystemClass = getSystemClass();
758
Patrick Benavoli68a91282011-08-31 11:23:23 +0200759 // Show status
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200760 /// General section
761 appendTitle(strResult, "General:");
762 // System class
Patrick Benavoli68a91282011-08-31 11:23:23 +0200763 strResult += "System Class: ";
764 strResult += pSystemClass->getName();
765 strResult += "\n";
766
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200767 // Tuning mode
Patrick Benavoli68a91282011-08-31 11:23:23 +0200768 strResult += "Tuning Mode: ";
769 strResult += tuningModeOn() ? "on" : "off";
770 strResult += "\n";
771
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200772 // Value space
Patrick Benavoli68a91282011-08-31 11:23:23 +0200773 strResult += "Value Space: ";
774 strResult += valueSpaceIsRaw() ? "raw" : "real";
775 strResult += "\n";
776
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200777 // Output raw format
778 strResult += "Output Raw Format: ";
779 strResult += outputRawFormatIsHex() ? "hex" : "dec";
780 strResult += "\n";
781
782 // Auto Sync
Patrick Benavoli68a91282011-08-31 11:23:23 +0200783 strResult += "Auto Sync: ";
784 strResult += autoSyncOn() ? "on" : "off";
785 strResult += "\n";
786
787 /// Subsystem list
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200788 appendTitle(strResult, "Subsystems:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200789 string strSubsystemList;
790 pSystemClass->listChildrenPaths(strSubsystemList);
791 strResult += strSubsystemList;
792
793 /// Last applied configurations
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200794 appendTitle(strResult, "Last Applied [Pending] Configurations:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200795 string strLastAppliedConfigurations;
796 getConfigurableDomains()->listLastAppliedConfigurations(strLastAppliedConfigurations);
797 strResult += strLastAppliedConfigurations;
798
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200799 /// Criteria states
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200800 appendTitle(strResult, "Selection Criteria:");
Kevin Rocard7f265822012-12-07 18:51:22 +0100801 list<string> lstrSelectionCriteria;
802 getSelectionCriteria()->listSelectionCriteria(lstrSelectionCriteria, false, true);
803 // Concatenate the criterion list as the command result
Frederic Boisnard390b36d2013-05-23 15:28:31 +0200804 string strCriteriaStates;
805 CUtility::asString(lstrSelectionCriteria, strCriteriaStates);
806 strResult += strCriteriaStates;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200807
Patrick Benavoli63499d42011-10-24 18:50:03 +0200808 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200809}
810
811/// Tuning Mode
Patrick Benavoli63499d42011-10-24 18:50:03 +0200812CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200813{
814 if (remoteCommand.getArgument(0) == "on") {
815
816 if (setTuningMode(true, strResult)) {
817
Patrick Benavoli63499d42011-10-24 18:50:03 +0200818 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200819 }
820 } else if (remoteCommand.getArgument(0) == "off") {
821
822 if (setTuningMode(false, strResult)) {
823
Patrick Benavoli63499d42011-10-24 18:50:03 +0200824 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200825 }
826 } else {
827 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200828 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200829 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200830 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200831}
832
Patrick Benavoli63499d42011-10-24 18:50:03 +0200833CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200834{
835 (void)remoteCommand;
836
837 strResult = tuningModeOn() ? "on" : "off";
838
Patrick Benavoli63499d42011-10-24 18:50:03 +0200839 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200840}
841
842/// Value Space
Patrick Benavoli63499d42011-10-24 18:50:03 +0200843CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200844{
845 (void)strResult;
846
847 if (remoteCommand.getArgument(0) == "raw") {
848
849 setValueSpace(true);
850
Patrick Benavoli63499d42011-10-24 18:50:03 +0200851 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200852
853 } else if (remoteCommand.getArgument(0) == "real") {
854
855 setValueSpace(false);
856
Patrick Benavoli63499d42011-10-24 18:50:03 +0200857 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200858
859 } else {
860 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200861 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200862 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200863 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200864}
865
Patrick Benavoli63499d42011-10-24 18:50:03 +0200866CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200867{
868 (void)remoteCommand;
869
870 strResult = valueSpaceIsRaw() ? "raw" : "real";
871
Patrick Benavoli63499d42011-10-24 18:50:03 +0200872 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200873}
874
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200875/// Output Raw Format
Patrick Benavoli63499d42011-10-24 18:50:03 +0200876CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200877{
878 (void)strResult;
879
880 if (remoteCommand.getArgument(0) == "hex") {
881
882 setOutputRawFormat(true);
883
Patrick Benavoli63499d42011-10-24 18:50:03 +0200884 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200885
886 } else if (remoteCommand.getArgument(0) == "dec") {
887
888 setOutputRawFormat(false);
889
Patrick Benavoli63499d42011-10-24 18:50:03 +0200890 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200891
892 } else {
893 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200894 return CCommandHandler::EShowUsage;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200895 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200896 return CCommandHandler::EFailed;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200897}
898
Patrick Benavoli63499d42011-10-24 18:50:03 +0200899CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200900{
901 (void)remoteCommand;
902
903 strResult = outputRawFormatIsHex() ? "hex" : "dec";
904
Patrick Benavoli63499d42011-10-24 18:50:03 +0200905 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200906}
907
Patrick Benavoli68a91282011-08-31 11:23:23 +0200908/// Sync
Patrick Benavoli63499d42011-10-24 18:50:03 +0200909CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200910{
911 if (remoteCommand.getArgument(0) == "on") {
912
913 if (setAutoSync(true, strResult)) {
914
Patrick Benavoli63499d42011-10-24 18:50:03 +0200915 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200916 }
917 } else if (remoteCommand.getArgument(0) == "off") {
918
919 if (setAutoSync(false, strResult)) {
920
Patrick Benavoli63499d42011-10-24 18:50:03 +0200921 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200922 }
923 } else {
924 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200925 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200926 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200927 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200928}
929
Patrick Benavoli63499d42011-10-24 18:50:03 +0200930CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200931{
932 (void)remoteCommand;
933
934 strResult = autoSyncOn() ? "on" : "off";
935
Patrick Benavoli63499d42011-10-24 18:50:03 +0200936 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200937}
938
Patrick Benavoli63499d42011-10-24 18:50:03 +0200939CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::syncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200940{
941 (void)remoteCommand;
942
Patrick Benavoli63499d42011-10-24 18:50:03 +0200943 return sync(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200944}
945
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200946/// Criteria
Patrick Benavoli63499d42011-10-24 18:50:03 +0200947CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listCriteriaCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200948{
949 (void)remoteCommand;
950
Kevin Rocard4eae8272013-04-18 19:12:46 +0200951 bool humanReadable = true;
Kevin Rocard7f265822012-12-07 18:51:22 +0100952
Kevin Rocard4eae8272013-04-18 19:12:46 +0200953 // Look for optional arguments
954 if (remoteCommand.getArgumentCount() >= 1) {
955
956 // If csv is provided, format the criterion list in Commas Separated Value pairs
957 if (remoteCommand.getArgument(0) == "csv") {
958 humanReadable = false;
959 } else {
960 return CCommandHandler::EShowUsage;
961 }
962 }
963
964 list<string> lstrResult;
965 getSelectionCriteria()->listSelectionCriteria(lstrResult, true, humanReadable);
Kevin Rocard7f265822012-12-07 18:51:22 +0100966
967 // Concatenate the criterion list as the command result
Frederic Boisnard390b36d2013-05-23 15:28:31 +0200968 CUtility::asString(lstrResult, strResult);
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200969
Patrick Benavoli63499d42011-10-24 18:50:03 +0200970 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200971}
Patrick Benavoli68a91282011-08-31 11:23:23 +0200972
973/// Domains
Patrick Benavoli63499d42011-10-24 18:50:03 +0200974CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200975{
976 (void)remoteCommand;
977
Patrick Benavoli63499d42011-10-24 18:50:03 +0200978 getConfigurableDomains()->listDomains(strResult);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200979
Patrick Benavoli63499d42011-10-24 18:50:03 +0200980 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200981}
982
Patrick Benavoli63499d42011-10-24 18:50:03 +0200983CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200984{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200985 return createDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200986}
987
Patrick Benavoli63499d42011-10-24 18:50:03 +0200988CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200989{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200990 return deleteDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200991}
992
Kevin Rocard170f0a42012-06-18 13:56:05 +0200993CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteAllDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
994{
995 (void)remoteCommand;
996
997 return deleteAllDomains(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
998}
999
Patrick Benavoli63499d42011-10-24 18:50:03 +02001000CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001001{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001002 return getConfigurableDomains()->renameDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001003}
1004
Patrick Benavoli63499d42011-10-24 18:50:03 +02001005CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001006{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001007 // Check tuning mode
1008 if (!checkTuningModeOn(strResult)) {
1009
1010 return CCommandHandler::EFailed;
1011 }
1012
1013 // Set property
1014 bool bSequenceAware;
1015
1016 if (remoteCommand.getArgument(1) == "true") {
1017
1018 bSequenceAware = true;
1019
1020 } else if (remoteCommand.getArgument(1) == "false") {
1021
1022 bSequenceAware = false;
1023
1024 } else {
1025 // Show usage
1026 return CCommandHandler::EShowUsage;
1027 }
1028
1029 return getConfigurableDomains()->setSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001030}
1031
Patrick Benavoli63499d42011-10-24 18:50:03 +02001032CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001033{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001034 // Get property
1035 bool bSequenceAware;
1036
1037 if (!getConfigurableDomains()->getSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult)) {
1038
1039 return CCommandHandler::EFailed;
1040 }
1041
1042 strResult = bSequenceAware ? "true" : "false";
1043
1044 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001045}
1046
Patrick Benavoli63499d42011-10-24 18:50:03 +02001047CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001048{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001049 return getConfigurableDomains()->listDomainElements(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001050}
1051
Patrick Benavoli63499d42011-10-24 18:50:03 +02001052CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::addElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001053{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001054 return addConfigurableElementToDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1055}
1056
1057CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::removeElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1058{
1059 return removeConfigurableElementFromDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1060}
1061
1062CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::splitDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1063{
1064 return split(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001065}
1066
1067/// Configurations
Patrick Benavoli63499d42011-10-24 18:50:03 +02001068CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConfigurationsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001069{
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001070 return getConstConfigurableDomains()->listConfigurations(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
1071}
1072
1073CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1074{
1075 (void)remoteCommand;
1076
1077 // Dummy error context
1078 string strError;
1079 CErrorContext errorContext(strError);
1080
1081 // Dump
1082 getConstConfigurableDomains()->dumpContent(strResult, errorContext);
1083
1084 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001085}
1086
Patrick Benavoli63499d42011-10-24 18:50:03 +02001087CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001088{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001089 return createConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001090}
1091
Patrick Benavoli63499d42011-10-24 18:50:03 +02001092CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001093{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001094 return deleteConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001095}
1096
Patrick Benavoli63499d42011-10-24 18:50:03 +02001097CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001098{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001099 return getConfigurableDomains()->renameConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001100}
1101
Patrick Benavoli63499d42011-10-24 18:50:03 +02001102CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::saveConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001103{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001104 return saveConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001105}
1106
Patrick Benavoli63499d42011-10-24 18:50:03 +02001107CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::restoreConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001108{
Kevin Rocardace81f82012-12-11 16:19:17 +01001109 list<string> lstrResult;
1110 if (!restoreConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), lstrResult)) {
1111 //Concatenate the error list as the command result
Frederic Boisnard390b36d2013-05-23 15:28:31 +02001112 CUtility::asString(lstrResult, strResult);
Kevin Rocardace81f82012-12-11 16:19:17 +01001113
1114 return CCommandHandler::EFailed;
1115 }
1116 return CCommandHandler::EDone;
Patrick Benavoli63499d42011-10-24 18:50:03 +02001117}
1118
1119CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1120{
1121 // Check tuning mode
1122 if (!checkTuningModeOn(strResult)) {
1123
1124 return CCommandHandler::EFailed;
1125 }
1126
1127 // Build configurable element path list
1128 vector<string> astrNewElementSequence;
1129
1130 uint32_t uiArgument;
1131
1132 for (uiArgument = 2; uiArgument < remoteCommand.getArgumentCount(); uiArgument++) {
1133
1134 astrNewElementSequence.push_back(remoteCommand.getArgument(uiArgument));
1135 }
1136
1137 // Delegate to configurable domains
1138 return getConfigurableDomains()->setElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), astrNewElementSequence, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1139}
1140
1141CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1142{
1143 // Delegate to configurable domains
1144 return getConfigurableDomains()->getElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001145}
1146
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001147CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1148{
1149 // Delegate to configurable domains
1150 return getConfigurableDomains()->setApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.packArguments(2, remoteCommand.getArgumentCount() - 2), getConstSelectionCriteria()->getSelectionCriteriaDefinition(), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1151}
1152
1153CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::clearRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1154{
1155 // Delegate to configurable domains
1156 return getConfigurableDomains()->clearApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1157}
1158
1159CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1160{
1161 // Delegate to configurable domains
1162 return getConfigurableDomains()->getApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
1163}
1164
Patrick Benavoli68a91282011-08-31 11:23:23 +02001165/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001166CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001167{
1168 CElementLocator elementLocator(getSystemClass(), false);
1169
1170 CElement* pLocatedElement = NULL;
1171
1172 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1173
Patrick Benavoli63499d42011-10-24 18:50:03 +02001174 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001175 }
1176
1177 strResult = string("\n");
1178
1179 if (!pLocatedElement) {
1180
1181 // List from root folder
1182
1183 // Return system class qualified name
1184 pLocatedElement = getSystemClass();
1185 }
1186
1187 // Return sub-elements
1188 strResult += pLocatedElement->listQualifiedPaths(false);
1189
Patrick Benavoli63499d42011-10-24 18:50:03 +02001190 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001191}
1192
1193/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001194CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listParametersCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001195{
1196 CElementLocator elementLocator(getSystemClass(), false);
1197
1198 CElement* pLocatedElement = NULL;
1199
1200 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1201
Patrick Benavoli63499d42011-10-24 18:50:03 +02001202 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001203 }
1204
1205 strResult = string("\n");
1206
1207 if (!pLocatedElement) {
1208
1209 // List from root folder
1210
1211 // Return system class qualified name
1212 pLocatedElement = getSystemClass();
1213 }
1214
1215 // Return sub-elements
1216 strResult += pLocatedElement->listQualifiedPaths(true);
1217
Patrick Benavoli63499d42011-10-24 18:50:03 +02001218 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001219}
1220
Patrick Benavoli63499d42011-10-24 18:50:03 +02001221CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001222{
1223 CElementLocator elementLocator(getSystemClass());
1224
1225 CElement* pLocatedElement = NULL;
1226
1227 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1228
Patrick Benavoli63499d42011-10-24 18:50:03 +02001229 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001230 }
1231
1232 string strError;
1233
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001234 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001235
1236 // Dump elements
1237 pLocatedElement->dumpContent(strResult, parameterAccessContext);
1238
Patrick Benavoli63499d42011-10-24 18:50:03 +02001239 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001240}
1241
Patrick Benavoli63499d42011-10-24 18:50:03 +02001242CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSizeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001243{
1244 CElementLocator elementLocator(getSystemClass());
1245
1246 CElement* pLocatedElement = NULL;
1247
1248 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1249
Patrick Benavoli63499d42011-10-24 18:50:03 +02001250 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001251 }
1252
1253 // Converted to actual sizable element
1254 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1255
1256 // Get size as string
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001257 strResult = pConfigurableElement->getFootprintAsString();
Patrick Benavoli68a91282011-08-31 11:23:23 +02001258
Patrick Benavoli63499d42011-10-24 18:50:03 +02001259 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001260}
1261
Patrick Benavoli63499d42011-10-24 18:50:03 +02001262CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showPropertiesCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001263{
1264 CElementLocator elementLocator(getSystemClass());
1265
1266 CElement* pLocatedElement = NULL;
1267
1268 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1269
Patrick Benavoli63499d42011-10-24 18:50:03 +02001270 return CCommandHandler::EFailed;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001271 }
1272
1273 // Convert element
1274 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1275
1276 // Return element properties
1277 pConfigurableElement->showProperties(strResult);
1278
Patrick Benavoli63499d42011-10-24 18:50:03 +02001279 return CCommandHandler::ESucceeded;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001280}
1281
Patrick Benavoli63499d42011-10-24 18:50:03 +02001282CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001283{
1284 string strValue;
1285
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001286 if (!accessParameterValue(remoteCommand.getArgument(0), strValue, false, strResult)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001287
Patrick Benavoli63499d42011-10-24 18:50:03 +02001288 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001289 }
1290 // Succeeded
1291 strResult = strValue;
1292
Patrick Benavoli63499d42011-10-24 18:50:03 +02001293 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001294}
1295
Patrick Benavoli63499d42011-10-24 18:50:03 +02001296CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001297{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001298 // Check tuning mode
1299 if (!checkTuningModeOn(strResult)) {
1300
1301 return CCommandHandler::EFailed;
1302 }
1303 // Get value to set
1304 string strValue = remoteCommand.packArguments(1, remoteCommand.getArgumentCount() - 1);
1305
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001306 return accessParameterValue(remoteCommand.getArgument(0), strValue, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001307}
1308
Patrick Benavoli63499d42011-10-24 18:50:03 +02001309CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listBelongingDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001310{
1311 CElementLocator elementLocator(getSystemClass());
1312
1313 CElement* pLocatedElement = NULL;
1314
1315 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1316
Patrick Benavoli63499d42011-10-24 18:50:03 +02001317 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001318 }
1319
1320 // Convert element
1321 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1322
1323 // Return element belonging domains
1324 pConfigurableElement->listBelongingDomains(strResult);
1325
Patrick Benavoli63499d42011-10-24 18:50:03 +02001326 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001327}
1328
Patrick Benavoli63499d42011-10-24 18:50:03 +02001329CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001330{
1331 CElementLocator elementLocator(getSystemClass());
1332
1333 CElement* pLocatedElement = NULL;
1334
1335 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1336
Patrick Benavoli63499d42011-10-24 18:50:03 +02001337 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001338 }
1339
1340 // Convert element
1341 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1342
1343 // Return element belonging domains
1344 pConfigurableElement->listAssociatedDomains(strResult);
1345
Patrick Benavoli63499d42011-10-24 18:50:03 +02001346 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001347}
1348
Patrick Benavoli63499d42011-10-24 18:50:03 +02001349CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001350{
1351 (void)remoteCommand;
1352
1353 getConfigurableDomains()->listAssociatedElements(strResult);
1354
Patrick Benavoli63499d42011-10-24 18:50:03 +02001355 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001356}
1357
Patrick Benavoli63499d42011-10-24 18:50:03 +02001358CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConflictingElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001359{
1360 (void)remoteCommand;
1361
1362 getConfigurableDomains()->listConflictingElements(strResult);
1363
Patrick Benavoli63499d42011-10-24 18:50:03 +02001364 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001365}
1366
Patrick Benavoli63499d42011-10-24 18:50:03 +02001367CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listRogueElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001368{
1369 (void)remoteCommand;
1370
1371 getSystemClass()->listRogueElements(strResult);
1372
Patrick Benavoli63499d42011-10-24 18:50:03 +02001373 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001374}
1375
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001376CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getConfigurationParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1377{
1378 string strOutputValue;
1379 string strError;
1380
1381 if (!accessConfigurationValue(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), strOutputValue, false, strError)) {
1382
1383 strResult = strError;
1384 return CCommandHandler::EFailed;
1385 }
1386 // Succeeded
1387 strResult = strOutputValue;
1388
1389 return CCommandHandler::ESucceeded;
1390}
1391
1392CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setConfigurationParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1393{
1394 // Get value to set
1395 string strValue = remoteCommand.packArguments(3, remoteCommand.getArgumentCount() - 3);
1396
1397 bool bSuccess = accessConfigurationValue(remoteCommand.getArgument(0),
1398 remoteCommand.getArgument(1),
1399 remoteCommand.getArgument(2),
1400 strValue, true, strResult);
1401
1402 return bSuccess ? CCommandHandler::EDone : CCommandHandler::EFailed;
1403}
1404
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +02001405CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showMappingCommmandProcess(
1406 const IRemoteCommand& remoteCommand,
1407 string& strResult)
1408{
1409 if (!getParameterMapping(remoteCommand.getArgument(0), strResult)) {
1410
1411 return CCommandHandler::EFailed;
1412 }
1413
1414 return CCommandHandler::ESucceeded;
1415}
1416
Patrick Benavoli68a91282011-08-31 11:23:23 +02001417/// Settings Import/Export
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001418CParameterMgr::CCommandHandler::CommandStatus
1419 CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess(
1420 const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001421{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001422 string strFileName = remoteCommand.getArgument(0);
1423 return exportDomainsXml(strFileName, false, true, strResult) ?
1424 CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001425}
1426
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001427CParameterMgr::CCommandHandler::CommandStatus
1428 CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess(
1429 const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001430{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001431 return importDomainsXml(remoteCommand.getArgument(0), false, true, strResult) ?
1432 CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001433}
1434
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001435CParameterMgr::CCommandHandler::CommandStatus
1436 CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess(
1437 const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001438{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001439 string strFileName = remoteCommand.getArgument(0);
1440 return exportDomainsXml(strFileName, true, true, strResult) ?
1441 CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001442}
1443
Patrick Benavoli63499d42011-10-24 18:50:03 +02001444CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001445{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001446 return importDomainsXml(remoteCommand.getArgument(0), true, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001447}
1448
Patrick Benavoli63499d42011-10-24 18:50:03 +02001449CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001450{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001451 return exportDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001452}
1453
Patrick Benavoli63499d42011-10-24 18:50:03 +02001454CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001455{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001456 return importDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001457}
1458
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001459CParameterMgr::CCommandHandler::CommandStatus
1460 CParameterMgr::getConfigurableDomainsWithSettingsXMLCommmandProcess(
1461 const IRemoteCommand& remoteCommand, string& strResult)
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001462{
1463 (void)remoteCommand;
1464
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001465 if (!exportDomainsXml(strResult, true, false, strResult)) {
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001466
1467 return CCommandHandler::EFailed;
1468 }
1469 // Succeeded
1470 return CCommandHandler::ESucceeded;
1471}
1472
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001473CParameterMgr::CCommandHandler::CommandStatus
1474 CParameterMgr::setConfigurableDomainsWithSettingsXMLCommmandProcess(
1475 const IRemoteCommand& remoteCommand, string& strResult)
1476{
1477 return importDomainsXml(remoteCommand.getArgument(0), true, false, strResult) ?
1478 CCommandHandler::EDone : CCommandHandler::EFailed;
1479}
1480
1481CParameterMgr::CCommandHandler::CommandStatus
1482 CParameterMgr::getSystemClassXMLCommmandProcess(
1483 const IRemoteCommand& remoteCommand, string& strResult)
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001484{
1485 (void)remoteCommand;
1486
1487 if (!getSystemClassXMLString(strResult)) {
1488
1489 return CCommandHandler::EFailed;
1490 }
1491 // Succeeded
1492 return CCommandHandler::ESucceeded;
1493}
1494
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001495// User set/get parameters in main BlackBoard
1496bool CParameterMgr::accessParameterValue(const string& strPath, string& strValue, bool bSet, string& strError)
1497{
1498 // Define context
1499 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
1500
Frédéric Boisnard150407c2013-03-15 14:46:23 +01001501 // Activate the auto synchronization with the hardware
1502 if (bSet) {
1503
1504 parameterAccessContext.setAutoSync(_bAutoSyncOn);
1505 }
1506
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001507 return accessValue(parameterAccessContext, strPath, strValue, bSet, strError);
1508}
1509
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +02001510// User get parameter mapping
1511bool CParameterMgr::getParameterMapping(const string& strPath, string& strResult) const
1512{
1513 CPathNavigator pathNavigator(strPath);
1514
1515 // Nagivate through system class
1516 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strResult)) {
1517
1518 return false;
1519 }
1520
1521 // Get the ConfigurableElement corresponding to strPath
1522 const CConfigurableElement* pConfigurableElement = getConfigurableElement(strPath, strResult);
1523 if (!pConfigurableElement) {
1524
1525 return false;
1526 }
1527
1528 // Find the list of the ancestors of the current ConfigurableElement that have a mapping
1529 list<const CConfigurableElement*> configurableElementPath;
1530 pConfigurableElement->getListOfElementsWithMapping(configurableElementPath);
1531
1532 // Get the Subsystem containing the ConfigurableElement
1533 const CSubsystem* pSubsystem = pConfigurableElement->getBelongingSubsystem();
1534 if (!pSubsystem) {
1535
1536 strResult = "Unable to find the Subsystem containing the parameter";
1537 return false;
1538 }
1539
1540 // Fetch the mapping corresponding to the ConfigurableElement
1541 strResult = pSubsystem->getMapping(configurableElementPath);
1542
1543 return true;
1544}
1545
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001546// User set/get parameters in specific Configuration BlackBoard
1547bool CParameterMgr::accessConfigurationValue(const string& strDomain, const string& strConfiguration, const string& strPath, string& strValue, bool bSet, string& strError)
1548{
1549 CElementLocator elementLocator(getSystemClass());
1550
1551 CElement* pLocatedElement = NULL;
1552
1553 if (!elementLocator.locate(strPath, &pLocatedElement, strError)) {
1554
1555 return false;
1556 }
1557
1558 // Convert element
1559 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1560
1561 // Get the Configuration blackboard and the Base Offset of the configurable element in this blackboard
1562 uint32_t uiBaseOffset;
1563 bool bIsLastApplied;
1564
1565 CParameterBlackboard* pConfigurationBlackboard = getConstConfigurableDomains()->findConfigurationBlackboard(strDomain, strConfiguration, pConfigurableElement, uiBaseOffset, bIsLastApplied, strError);
1566
1567 if (!pConfigurationBlackboard) {
1568
1569 return false;
1570 }
1571
1572 log_info("Element %s in Domain %s, offset: %d, base offset: %d", strPath.c_str(), strDomain.c_str(), pConfigurableElement->getOffset(), uiBaseOffset);
1573
1574 /// Update the Configuration Blackboard
1575
Frédéric Boisnard150407c2013-03-15 14:46:23 +01001576 // 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 +01001577 CParameterAccessContext parameterAccessContext(strError, pConfigurationBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex, uiBaseOffset);
1578
1579 // Access Value in the Configuration Blackboard
1580 if (!accessValue(parameterAccessContext, strPath, strValue, bSet, strError)) {
1581
1582 return false;
1583 }
1584
1585 /// If the Configuration is the last one applied, update the Main Blackboard as well
1586
1587 if (bIsLastApplied) {
1588
1589 // Define Main context
1590 parameterAccessContext.setParameterBlackboard(_pMainParameterBlackboard);
1591
Frédéric Boisnard150407c2013-03-15 14:46:23 +01001592 // Activate the auto synchronization with the hardware
1593 if (bSet) {
1594
1595 parameterAccessContext.setAutoSync(_bAutoSyncOn);
1596 }
1597
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001598 // Access Value in the Main Blackboard
1599 return accessValue(parameterAccessContext, strPath, strValue, bSet, strError);
1600 }
1601
1602 return true;
1603}
1604
Patrick Benavoli68a91282011-08-31 11:23:23 +02001605// User set/get parameters
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001606bool CParameterMgr::accessValue(CParameterAccessContext& parameterAccessContext, const string& strPath, string& strValue, bool bSet, string& strError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001607{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001608 // Lock state
1609 CAutoLock autoLock(&_blackboardMutex);
1610
1611 CPathNavigator pathNavigator(strPath);
1612
1613 // Nagivate through system class
1614 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001615
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +02001616 parameterAccessContext.setError(strError);
1617
Patrick Benavoli68a91282011-08-31 11:23:23 +02001618 return false;
1619 }
1620
Patrick Benavoli065264a2011-11-20 15:46:41 +01001621 // Do the get
1622 return getConstSystemClass()->accessValue(pathNavigator, strValue, bSet, parameterAccessContext);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001623}
1624
1625// Tuning mode
1626bool CParameterMgr::setTuningMode(bool bOn, string& strError)
1627{
1628 // Tuning allowed?
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001629 if (bOn && !getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001630
1631 strError = "Tuning prohibited";
1632
1633 return false;
1634 }
1635 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +01001636 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001637
1638 // Warn domains about exiting tuning mode
1639 if (!bOn && _bTuningModeIsOn) {
1640
1641 // Ensure application of currently selected configurations
Patrick Benavoli1387bda2011-08-31 11:23:24 +02001642 // Force-apply configurations
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01001643 doApplyConfigurations(true);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001644
Patrick Benavoli68a91282011-08-31 11:23:23 +02001645 // Turn auto sync back on
1646 _bAutoSyncOn = true;
1647 }
1648
1649 // Store
1650 _bTuningModeIsOn = bOn;
1651
Patrick Benavoli68a91282011-08-31 11:23:23 +02001652 return true;
1653}
1654
1655bool CParameterMgr::tuningModeOn() const
1656{
1657 return _bTuningModeIsOn;
1658}
1659
1660// Current value space for user set/get value interpretation
1661void CParameterMgr::setValueSpace(bool bIsRaw)
1662{
1663 _bValueSpaceIsRaw = bIsRaw;
1664}
1665
1666bool CParameterMgr::valueSpaceIsRaw()
1667{
1668 return _bValueSpaceIsRaw;
1669}
1670
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001671// Current Output Raw Format for user get value interpretation
1672void CParameterMgr::setOutputRawFormat(bool bIsHex)
1673{
1674 _bOutputRawFormatIsHex = bIsHex;
1675}
1676
1677bool CParameterMgr::outputRawFormatIsHex()
1678{
1679 return _bOutputRawFormatIsHex;
1680}
1681
Patrick Benavoli68a91282011-08-31 11:23:23 +02001682/// Sync
1683// Automatic hardware synchronization control (during tuning session)
1684bool CParameterMgr::setAutoSync(bool bAutoSyncOn, string& strError)
1685{
1686 // Check tuning mode
1687 if (!checkTuningModeOn(strError)) {
1688
1689 return false;
1690 }
1691 // Warn domains about turning auto sync back on
1692 if (bAutoSyncOn && !_bAutoSyncOn) {
1693
Patrick Benavoli592ae562011-09-05 16:53:58 +02001694 // Do the synchronization at system class level (could be optimized by keeping track of all modified parameters)
1695 if (!sync(strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001696
1697 return false;
1698 }
1699 }
1700
1701 // Set Auto sync
1702 _bAutoSyncOn = bAutoSyncOn;
1703
1704 return true;
1705}
1706
1707bool CParameterMgr::autoSyncOn() const
1708{
1709 return _bAutoSyncOn;
1710}
1711
1712// Manual hardware synchronization control (during tuning session)
1713bool CParameterMgr::sync(string& strError)
1714{
1715 // Check tuning mode
1716 if (!checkTuningModeOn(strError)) {
1717
1718 return false;
1719 }
1720 // Warn domains about turning auto sync back on
1721 if (_bAutoSyncOn) {
1722
1723 strError = "Feature unavailable when Auto Sync is on";
1724
1725 return false;
1726 }
1727
1728 // Get syncer set
1729 CSyncerSet syncerSet;
1730 // ... from system class
1731 getConstSystemClass()->fillSyncerSet(syncerSet);
Kevin Rocardace81f82012-12-11 16:19:17 +01001732
Patrick Benavoli68a91282011-08-31 11:23:23 +02001733 // Sync
Kevin Rocardace81f82012-12-11 16:19:17 +01001734 list<string> lstrError;
1735 if (! syncerSet.sync(*_pMainParameterBlackboard, false, &lstrError)){
1736
Frederic Boisnard390b36d2013-05-23 15:28:31 +02001737 CUtility::asString(lstrError, strError);
Kevin Rocardace81f82012-12-11 16:19:17 +01001738 return false;
1739 };
1740
1741 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001742}
1743
1744// Content dump
1745void CParameterMgr::logStructureContent(string& strContent) const
1746{
1747 string strError;
1748
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001749 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001750
1751 dumpContent(strContent, parameterAccessContext);
1752}
1753
1754// Configuration/Domains handling
1755bool CParameterMgr::createDomain(const string& strName, string& strError)
1756{
1757 // Check tuning mode
1758 if (!checkTuningModeOn(strError)) {
1759
1760 return false;
1761 }
1762
1763 // Delegate to configurable domains
1764 return getConfigurableDomains()->createDomain(strName, strError);
1765}
1766
1767bool CParameterMgr::deleteDomain(const string& strName, string& strError)
1768{
1769 // Check tuning mode
1770 if (!checkTuningModeOn(strError)) {
1771
1772 return false;
1773 }
1774
1775 // Delegate to configurable domains
1776 return getConfigurableDomains()->deleteDomain(strName, strError);
1777}
1778
Kevin Rocard170f0a42012-06-18 13:56:05 +02001779bool CParameterMgr::deleteAllDomains(string& strError)
1780{
1781 // Check tuning mode
1782 if (!checkTuningModeOn(strError)) {
1783
1784 return false;
1785 }
1786
1787 // Delegate to configurable domains
1788 getConfigurableDomains()->deleteAllDomains();
1789
1790 return true;
1791}
1792
Patrick Benavoli68a91282011-08-31 11:23:23 +02001793bool CParameterMgr::createConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1794{
1795 // Check tuning mode
1796 if (!checkTuningModeOn(strError)) {
1797
1798 return false;
1799 }
1800
1801 // Delegate to configurable domains
1802 return getConfigurableDomains()->createConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1803}
1804
1805bool CParameterMgr::deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1806{
1807 // Check tuning mode
1808 if (!checkTuningModeOn(strError)) {
1809
1810 return false;
1811 }
1812
1813 // Delegate to configurable domains
1814 return getConfigurableDomains()->deleteConfiguration(strDomain, strConfiguration, strError);
1815}
1816
Kevin Rocardace81f82012-12-11 16:19:17 +01001817bool CParameterMgr::restoreConfiguration(const string& strDomain, const string& strConfiguration, list<string>& lstrError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001818{
Kevin Rocardace81f82012-12-11 16:19:17 +01001819 string strError;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001820 // Check tuning mode
1821 if (!checkTuningModeOn(strError)) {
1822
Kevin Rocardace81f82012-12-11 16:19:17 +01001823 lstrError.push_back(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001824 return false;
1825 }
1826
1827 // Delegate to configurable domains
Kevin Rocardace81f82012-12-11 16:19:17 +01001828 return getConstConfigurableDomains()->restoreConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, lstrError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001829}
1830
1831bool CParameterMgr::saveConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1832{
1833 // Check tuning mode
1834 if (!checkTuningModeOn(strError)) {
1835
1836 return false;
1837 }
1838
1839 // Delegate to configurable domains
1840 return getConfigurableDomains()->saveConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1841}
1842
1843// Configurable element - domain association
1844bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1845{
1846 // Check tuning mode
1847 if (!checkTuningModeOn(strError)) {
1848
1849 return false;
1850 }
1851
1852 CElementLocator elementLocator(getSystemClass());
1853
1854 CElement* pLocatedElement = NULL;
1855
1856 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1857
1858 return false;
1859 }
1860
1861 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001862 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001863
1864 // Delegate
1865 return getConfigurableDomains()->addConfigurableElementToDomain(strDomain, pConfigurableElement, _pMainParameterBlackboard, strError);
1866}
1867
1868bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1869{
1870 // Check tuning mode
1871 if (!checkTuningModeOn(strError)) {
1872
1873 return false;
1874 }
1875
1876 CElementLocator elementLocator(getSystemClass());
1877
1878 CElement* pLocatedElement = NULL;
1879
1880 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1881
Patrick Benavoli63499d42011-10-24 18:50:03 +02001882 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001883 }
1884
1885 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001886 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001887
1888 // Delegate
1889 return getConfigurableDomains()->removeConfigurableElementFromDomain(strDomain, pConfigurableElement, strError);
1890}
1891
1892bool CParameterMgr::split(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1893{
1894 // Check tuning mode
1895 if (!checkTuningModeOn(strError)) {
1896
1897 return false;
1898 }
1899
1900 CElementLocator elementLocator(getSystemClass());
1901
1902 CElement* pLocatedElement = NULL;
1903
1904 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1905
Patrick Benavoli63499d42011-10-24 18:50:03 +02001906 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001907 }
1908
1909 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001910 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001911
1912 // Delegate
1913 return getConfigurableDomains()->split(strDomain, pConfigurableElement, strError);
1914}
1915
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001916bool CParameterMgr::importDomainsXml(const string& strXmlSource, bool bWithSettings,
1917 bool bFromFile, string& strError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001918{
1919 // Check tuning mode
1920 if (!checkTuningModeOn(strError)) {
1921
1922 return false;
1923 }
1924
1925 // check path is absolute
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001926 if (bFromFile && strXmlSource[0] != '/') {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001927
1928 strError = "Please provide absolute path";
1929
1930 return false;
1931 }
1932 // Root element
1933 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1934
1935 // Context
1936 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1937
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001938 // Selection criteria definition for rule creation
1939 xmlDomainSerializingContext.setSelectionCriteriaDefinition(
1940 getConstSelectionCriteria()->getSelectionCriteriaDefinition());
Patrick Benavoli68a91282011-08-31 11:23:23 +02001941
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001942 // Init serializing context
1943 xmlDomainSerializingContext.set(
1944 _pElementLibrarySet->getElementLibrary(EParameterConfigurationLibrary),
1945 "", _strSchemaFolderLocation);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001946
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001947 // Get Schema file associated to root element
1948 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" +
1949 pConfigurableDomains->getKind() + ".xsd";
1950
1951 // Xml Source
1952 CXmlDocSource* pSource;
1953
1954 if (bFromFile) {
1955
1956 // when importing from a file strXmlSource is the file name
1957 pSource = new CXmlFileDocSource(strXmlSource, strXmlSchemaFilePath,
1958 pConfigurableDomains->getKind(),
1959 pConfigurableDomains->getName(), "SystemClassName");
1960
1961 } else {
1962
1963 // when importing from an xml string, strXmlSource contains the string
1964 pSource = new CXmlStringDocSource(strXmlSource, strXmlSchemaFilePath,
1965 pConfigurableDomains->getKind(),
1966 pConfigurableDomains->getName(), "SystemClassName");
1967
1968 }
1969 // Start clean
1970 pConfigurableDomains->clean();
1971
1972 // Use a doc sink that instantiate Configurable Domains from the given doc source
1973 CXmlMemoryDocSink memorySink(pConfigurableDomains);
1974
1975 bool bProcessSuccess = memorySink.process(*pSource, xmlDomainSerializingContext);
1976
1977 if (!bProcessSuccess) {
1978
1979 //Cleanup
1980 pConfigurableDomains->clean();
1981
1982 } else {
1983
1984 // Validate domains after XML import
1985 pConfigurableDomains->validate(_pMainParameterBlackboard);
1986
Patrick Benavoli68a91282011-08-31 11:23:23 +02001987 }
1988
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001989 delete pSource;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001990
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001991 return bProcessSuccess;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001992}
1993
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001994bool CParameterMgr::exportDomainsXml(string& strXmlDest, bool bWithSettings, bool bToFile,
1995 string& strError) const
Patrick Benavoli68a91282011-08-31 11:23:23 +02001996{
1997 // check path is absolute
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001998 if (bToFile && strXmlDest[0] != '/') {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001999
2000 strError = "Please provide absolute path";
2001
2002 return false;
2003 }
2004
2005 // Root element
2006 const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains();
2007
2008 // Get Schema file associated to root element
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002009 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" +
2010 pConfigurableDomains->getKind() + ".xsd";
Patrick Benavoli68a91282011-08-31 11:23:23 +02002011
2012 // Context
2013 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
2014
2015 // Value space
2016 xmlDomainSerializingContext.setValueSpaceRaw(_bValueSpaceIsRaw);
2017
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02002018 // Output raw format
2019 xmlDomainSerializingContext.setOutputRawFormat(_bOutputRawFormatIsHex);
2020
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002021 // Use a doc source by loading data from instantiated Configurable Domains
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002022 CXmlMemoryDocSource memorySource(pConfigurableDomains, pConfigurableDomains->getKind(),
2023 strXmlSchemaFilePath, "parameter-framework", getVersion());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002024
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002025 // Xml Sink
2026 CXmlDocSink* pSink;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002027
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002028 if (bToFile) {
2029
2030 // Use a doc sink to write the doc data in a file
2031 pSink = new CXmlFileDocSink(strXmlDest);
2032
2033 } else {
2034
2035 // Use a doc sink to write the doc data in a string
2036 pSink = new CXmlStringDocSink(strXmlDest);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002037 }
2038
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002039 bool bProcessSuccess = pSink->process(memorySource, xmlDomainSerializingContext);
2040
2041 delete pSink;
2042 return bProcessSuccess;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002043}
2044
2045// Binary Import/Export
2046bool CParameterMgr::importDomainsBinary(const string& strFileName, string& strError)
2047{
2048 // Check tuning mode
2049 if (!checkTuningModeOn(strError)) {
2050
2051 return false;
2052 }
2053 // check path is absolute
2054 if (strFileName[0] != '/') {
2055
2056 strError = "Please provide absolute path";
2057
2058 return false;
2059 }
2060 // Root element
2061 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
2062
2063 // Serialize in
2064 return pConfigurableDomains->serializeSettings(strFileName, false, _uiStructureChecksum, strError);
2065}
2066
2067bool CParameterMgr::exportDomainsBinary(const string& strFileName, string& strError)
2068{
2069 // check path is absolute
2070 if (strFileName[0] != '/') {
2071
2072 strError = "Please provide absolute path";
2073
2074 return false;
2075 }
Patrick Benavoli68a91282011-08-31 11:23:23 +02002076
Patrick Benavoli68a91282011-08-31 11:23:23 +02002077 // Root element
2078 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
2079
2080 // Serialize out
2081 return pConfigurableDomains->serializeSettings(strFileName, true, _uiStructureChecksum, strError);
2082}
2083
2084// For tuning, check we're in tuning mode
2085bool CParameterMgr::checkTuningModeOn(string& strError) const
2086{
2087 // Tuning Mode on?
2088 if (!_bTuningModeIsOn) {
2089
2090 strError = "Tuning Mode must be on";
2091
2092 return false;
2093 }
2094 return true;
2095}
2096
Patrick Benavoli065264a2011-11-20 15:46:41 +01002097// Tuning mutex dynamic parameter handling
2098pthread_mutex_t* CParameterMgr::getBlackboardMutex()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002099{
Patrick Benavoli065264a2011-11-20 15:46:41 +01002100 return &_blackboardMutex;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002101}
2102
Patrick Benavoli065264a2011-11-20 15:46:41 +01002103// Blackboard reference (dynamic parameter handling)
2104CParameterBlackboard* CParameterMgr::getParameterBlackboard()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002105{
Patrick Benavoli065264a2011-11-20 15:46:41 +01002106 return _pMainParameterBlackboard;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002107}
2108
Patrick Benavoli68a91282011-08-31 11:23:23 +02002109// Dynamic creation library feeding
2110void CParameterMgr::feedElementLibraries()
2111{
2112 // Global Configuration handling
2113 CElementLibrary* pFrameworkConfigurationLibrary = new CElementLibrary;
2114
Kevin Rocarda7b69602013-08-07 16:15:33 +02002115 pFrameworkConfigurationLibrary->addElementBuilder("ParameterFrameworkConfiguration", new TElementBuilderTemplate<CParameterFrameworkConfiguration>());
2116 pFrameworkConfigurationLibrary->addElementBuilder("SubsystemPlugins", new TKindElementBuilderTemplate<CSubsystemPlugins>());
2117 pFrameworkConfigurationLibrary->addElementBuilder("Location", new TKindElementBuilderTemplate<CPluginLocation>());
2118 pFrameworkConfigurationLibrary->addElementBuilder("StructureDescriptionFileLocation", new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>());
2119 pFrameworkConfigurationLibrary->addElementBuilder("SettingsConfiguration", new TKindElementBuilderTemplate<CFrameworkConfigurationGroup>());
2120 pFrameworkConfigurationLibrary->addElementBuilder("ConfigurableDomainsFileLocation", new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>());
2121 pFrameworkConfigurationLibrary->addElementBuilder("BinarySettingsFileLocation", new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002122
2123 _pElementLibrarySet->addElementLibrary(pFrameworkConfigurationLibrary);
2124
2125 // Parameter creation
2126 CElementLibrary* pParameterCreationLibrary = new CElementLibrary;
2127
Kevin Rocarda7b69602013-08-07 16:15:33 +02002128 pParameterCreationLibrary->addElementBuilder("Subsystem", new CSubsystemElementBuilder(getSystemClass()->getSubsystemLibrary()));
2129 pParameterCreationLibrary->addElementBuilder("ComponentType", new TNamedElementBuilderTemplate<CComponentType>());
2130 pParameterCreationLibrary->addElementBuilder("Component", new TNamedElementBuilderTemplate<CComponentInstance>());
2131 pParameterCreationLibrary->addElementBuilder("BitParameter", new TNamedElementBuilderTemplate<CBitParameterType>());
2132 pParameterCreationLibrary->addElementBuilder("BitParameterBlock", new TNamedElementBuilderTemplate<CBitParameterBlockType>());
2133 pParameterCreationLibrary->addElementBuilder("StringParameter", new TNamedElementBuilderTemplate<CStringParameterType>());
2134 pParameterCreationLibrary->addElementBuilder("ParameterBlock", new TNamedElementBuilderTemplate<CParameterBlockType>());
2135 pParameterCreationLibrary->addElementBuilder("BooleanParameter", new TNamedElementBuilderTemplate<CBooleanParameterType>());
2136 pParameterCreationLibrary->addElementBuilder("IntegerParameter", new TNamedElementBuilderTemplate<CIntegerParameterType>());
2137 pParameterCreationLibrary->addElementBuilder("LinearAdaptation", new TElementBuilderTemplate<CLinearParameterAdaptation>());
2138 pParameterCreationLibrary->addElementBuilder("EnumParameter", new TNamedElementBuilderTemplate<CEnumParameterType>());
2139 pParameterCreationLibrary->addElementBuilder("ValuePair", new TElementBuilderTemplate<CEnumValuePair>());
2140 pParameterCreationLibrary->addElementBuilder("FixedPointParameter", new TNamedElementBuilderTemplate<CFixedPointParameterType>());
2141 pParameterCreationLibrary->addElementBuilder("SubsystemInclude", new TKindElementBuilderTemplate<CXmlFileIncluderElement>());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002142
2143 _pElementLibrarySet->addElementLibrary(pParameterCreationLibrary);
2144
2145 // Parameter Configuration Domains creation
2146 CElementLibrary* pParameterConfigurationLibrary = new CElementLibrary;
2147
Kevin Rocarda7b69602013-08-07 16:15:33 +02002148 pParameterConfigurationLibrary->addElementBuilder("ConfigurableDomain", new TNamedElementBuilderTemplate<CConfigurableDomain>());
2149 pParameterConfigurationLibrary->addElementBuilder("Configuration", new TNamedElementBuilderTemplate<CDomainConfiguration>());
2150 pParameterConfigurationLibrary->addElementBuilder("CompoundRule", new TElementBuilderTemplate<CCompoundRule>());
2151 pParameterConfigurationLibrary->addElementBuilder("SelectionCriterionRule", new TElementBuilderTemplate<CSelectionCriterionRule>());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002152
2153 _pElementLibrarySet->addElementLibrary(pParameterConfigurationLibrary);
2154}
2155
2156// Remote Processor Server connection handling
2157bool CParameterMgr::handleRemoteProcessingInterface(string& strError)
2158{
2159 CAutoLog autoLog(this, "Handling remote processing interface");
2160
2161 // Start server if tuning allowed
Patrick Benavoli95ac0342011-11-07 20:32:51 +01002162 if (getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02002163
Kevin Rocardace81f82012-12-11 16:19:17 +01002164 log_info("Loading remote processor library");
Patrick Benavoli68a91282011-08-31 11:23:23 +02002165
2166 // Load library
2167 void* lib_handle = dlopen("libremote-processor.so", RTLD_NOW);
2168
2169 if (!lib_handle) {
2170
2171 // Return error
2172 const char* pcError = dlerror();
2173
2174 if (pcError) {
2175
2176 strError = pcError;
2177 } else {
2178
2179 strError = "Unable to load libremote-processor.so library";
2180 }
2181
2182 return false;
2183 }
2184
2185 CreateRemoteProcessorServer pfnCreateRemoteProcessorServer = (CreateRemoteProcessorServer)dlsym(lib_handle, "createRemoteProcessorServer");
2186
2187 if (!pfnCreateRemoteProcessorServer) {
2188
2189 strError = "libremote-process.so does not contain createRemoteProcessorServer symbol.";
2190
2191 return false;
2192 }
2193
2194 // Create server
Patrick Benavoli95ac0342011-11-07 20:32:51 +01002195 _pRemoteProcessorServer = pfnCreateRemoteProcessorServer(getConstFrameworkConfiguration()->getServerPort(), _pCommandHandler);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002196
Kevin Rocardace81f82012-12-11 16:19:17 +01002197 log_info("Starting remote processor server on port %d", getConstFrameworkConfiguration()->getServerPort());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002198 // Start
2199 if (!_pRemoteProcessorServer->start()) {
2200
2201 strError = "Unable to start remote processor server";
2202
2203 return false;
2204 }
2205 }
2206
2207 return true;
2208}
2209
2210// Back synchronization
Kevin Rocardace81f82012-12-11 16:19:17 +01002211CBackSynchronizer* CParameterMgr::createBackSynchronizer() const
Patrick Benavoli68a91282011-08-31 11:23:23 +02002212{
2213#ifdef SIMULATION
2214 // In simulation, back synchronization of the blackboard won't probably work
2215 // We need to ensure though the blackboard is initialized with valid data
Kevin Rocardace81f82012-12-11 16:19:17 +01002216 return new CSimulatedBackSynchronizer(getConstSystemClass(), _pMainParameterBlackboard);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002217#else
2218 // Real back synchronizer from subsystems
Kevin Rocardace81f82012-12-11 16:19:17 +01002219 return new CHardwareBackSynchronizer(getConstSystemClass(), _pMainParameterBlackboard);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002220#endif
2221}
2222
2223// Children typwise access
2224CParameterFrameworkConfiguration* CParameterMgr::getFrameworkConfiguration()
2225{
2226 return static_cast<CParameterFrameworkConfiguration*>(getChild(EFrameworkConfiguration));
2227}
2228
2229const CParameterFrameworkConfiguration* CParameterMgr::getConstFrameworkConfiguration()
2230{
2231 return getFrameworkConfiguration();
2232}
2233
2234CSelectionCriteria* CParameterMgr::getSelectionCriteria()
2235{
2236 return static_cast<CSelectionCriteria*>(getChild(ESelectionCriteria));
2237}
2238
2239const CSelectionCriteria* CParameterMgr::getConstSelectionCriteria()
2240{
2241 return static_cast<const CSelectionCriteria*>(getChild(ESelectionCriteria));
2242}
2243
2244CSystemClass* CParameterMgr::getSystemClass()
2245{
2246 return static_cast<CSystemClass*>(getChild(ESystemClass));
2247}
2248
2249const CSystemClass* CParameterMgr::getConstSystemClass() const
2250{
2251 return static_cast<const CSystemClass*>(getChild(ESystemClass));
2252}
2253
2254// Configurable Domains
2255CConfigurableDomains* CParameterMgr::getConfigurableDomains()
2256{
2257 return static_cast<CConfigurableDomains*>(getChild(EConfigurableDomains));
2258}
2259
2260const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains()
2261{
2262 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
2263}
2264
2265const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains() const
2266{
2267 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
2268}
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002269
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01002270// Apply configurations
2271void CParameterMgr::doApplyConfigurations(bool bForce)
2272{
2273 CSyncerSet syncerSet;
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002274
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01002275 // Check subsystems that need resync
2276 getSystemClass()->checkForSubsystemsToResync(syncerSet);
2277
2278 // Ensure application of currently selected configurations
2279 getConfigurableDomains()->apply(_pMainParameterBlackboard, syncerSet, bForce);
2280
2281 // Reset the modified status of the current criteria to indicate that a new configuration has been applied
2282 getSelectionCriteria()->resetModifiedStatus();
2283}
2284
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002285bool CParameterMgr::getSystemClassXMLString(string& strResult)
2286{
2287 // Root element
2288 const CSystemClass* pSystemClass = getSystemClass();
2289
2290 string strError;
2291
2292 CXmlSerializingContext xmlSerializingContext(strError);
2293
2294 // Use a doc source by loading data from instantiated Configurable Domains
2295 CXmlMemoryDocSource memorySource(pSystemClass, pSystemClass->getKind());
2296
2297 // Use a doc sink that write the doc data in a string
2298 CXmlStringDocSink stringSink(strResult);
2299
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002300 bool bProcessSuccess = stringSink.process(memorySource, xmlSerializingContext);
2301
2302 if (!bProcessSuccess) {
2303
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002304 strResult = strError;
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002305
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002306 }
2307
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002308 return bProcessSuccess;
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002309}