blob: 66c8d9e0417c520cafadc5206f178736f79ddb75 [file] [log] [blame]
Patrick Benavoli68a91282011-08-31 11:23:23 +02001/* <auto_header>
2 * <FILENAME>
3 *
4 * INTEL CONFIDENTIAL
5 * Copyright © 2011 Intel
6 * Corporation All Rights Reserved.
7 *
8 * The source code contained or described herein and all documents related to
9 * the source code ("Material") are owned by Intel Corporation or its suppliers
10 * or licensors. Title to the Material remains with Intel Corporation or its
11 * suppliers and licensors. The Material contains trade secrets and proprietary
12 * and confidential information of Intel or its suppliers and licensors. The
13 * Material is protected by worldwide copyright and trade secret laws and
14 * treaty provisions. No part of the Material may be used, copied, reproduced,
15 * modified, published, uploaded, posted, transmitted, distributed, or
16 * disclosed in any way without Intel’s prior express written permission.
17 *
18 * No license under any patent, copyright, trade secret or other intellectual
19 * property right is granted to or conferred upon you by disclosure or delivery
20 * of the Materials, either expressly, by implication, inducement, estoppel or
21 * otherwise. Any license under such intellectual property rights must be
22 * express and approved by Intel in writing.
23 *
24 * AUTHOR: Patrick Benavoli (patrickx.benavoli@intel.com)
25 * CREATED: 2011-06-01
26 * UPDATED: 2011-07-27
27 *
28 *
29 * </auto_header>
30 */
31#include "ParameterMgr.h"
32#include "XmlParser.h"
33#include "XmlParameterSerializingContext.h"
34#include "XmlElementSerializingContext.h"
35#include "SystemClass.h"
36#include "ElementLibrarySet.h"
37#include "SubsystemLibrary.h"
38#include "NamedElementBuilderTemplate.h"
39#include "KindElementBuilderTemplate.h"
40#include "ElementBuilderTemplate.h"
41#include "SelectionCriterionType.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020042#include "SubsystemElementBuilder.h"
43#include "SelectionCriteria.h"
44#include "ComponentType.h"
45#include "ComponentInstance.h"
46#include "ParameterBlockType.h"
47#include "BooleanParameterType.h"
48#include "IntegerParameterType.h"
49#include "FixedPointParameterType.h"
50#include "ParameterBlackboard.h"
51#include "Parameter.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020052#include "ParameterBlackboard.h"
53#include "ParameterAccessContext.h"
54#include "XmlFileIncluderElement.h"
55#include "ParameterFrameworkConfiguration.h"
56#include "FrameworkConfigurationGroup.h"
57#include "FrameworkConfigurationLocation.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020058#include "ConfigurableDomains.h"
59#include "ConfigurableDomain.h"
60#include "DomainConfiguration.h"
61#include "XmlComposer.h"
62#include "XmlDomainSerializingContext.h"
63#include "BitParameterBlockType.h"
64#include "BitParameterType.h"
Patrick Benavoli1352ae52011-10-21 16:48:04 +020065#include "StringParameterType.h"
Patrick Benavoli9fc3c0d2011-10-27 14:27:27 +020066#include "EnumParameterType.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020067#include "RemoteProcessorServerInterface.h"
68#include "ElementLocator.h"
69#include "AutoLog.h"
70#include "CompoundRule.h"
71#include "SelectionCriterionRule.h"
72#include "SimulatedBackSynchronizer.h"
73#include "HardwareBackSynchronizer.h"
Patrick Benavoli1387bda2011-08-31 11:23:24 +020074#include "AutoLock.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020075#include <strings.h>
76#include <dlfcn.h>
77#include <assert.h>
Patrick Benavoli065264a2011-11-20 15:46:41 +010078#include "ParameterHandle.h"
Patrick Benavoliee65e6d2011-11-20 18:52:24 +010079#include "LinearParameterAdaptation.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020080
81#define base CElement
82
83// Used for remote processor server creation
84typedef IRemoteProcessorServerInterface* (*CreateRemoteProcessorServer)(uint16_t uiPort, IRemoteCommandHandler* pCommandHandler);
85
86// Global configuration file name (fixed)
87const char* gacParameterFrameworkConfigurationFileName = "ParameterFrameworkConfiguration.xml";
88const char* gacSystemSchemasSubFolder = "Schemas";
89
90// Config File System looks normally like this:
91// ---------------------------------------------
Patrick Benavoli95ac0342011-11-07 20:32:51 +010092//├── <ParameterFrameworkConfiguration>.xml
Patrick Benavoli68a91282011-08-31 11:23:23 +020093//├── Schemas
94//│ └── *.xsd
95//├── Settings
96//│ └── <SystemClassName folder>*
97//│ ├── <ConfigurableDomains>.xml
98//│ └── <Settings>.bin?
99//└── Structure
100// └── <SystemClassName folder>*
101// ├── <SystemClassName>Class.xml
102// └── <Subsystem>.xml*
103// --------------------------------------------
104
105
106// Remote command parser array
Patrick Benavoli592ae562011-09-05 16:53:58 +0200107const CParameterMgr::SRemoteCommandParserItem CParameterMgr::gastRemoteCommandParserItems[] = {
Patrick Benavoli592ae562011-09-05 16:53:58 +0200108 /// Version
109 { "version", &CParameterMgr::versionCommandProcess, 0, "", "Show version" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200110 /// Status
111 { "status", &CParameterMgr::statusCommandProcess, 0, "", "Show current status" },
112 /// Tuning Mode
113 { "setTuningMode", &CParameterMgr::setTuningModeCommmandProcess, 1, "on|off*", "Turn on or off Tuning Mode" },
114 { "getTuningMode", &CParameterMgr::getTuningModeCommmandProcess, 0, "", "Show Tuning Mode" },
115 /// Value Space
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200116 { "setValueSpace", &CParameterMgr::setValueSpaceCommmandProcess, 1, "raw|real*", "Assigns Value Space used for parameter value interpretation" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200117 { "getValueSpace", &CParameterMgr::getValueSpaceCommmandProcess, 0, "", "Show Value Space" },
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200118 /// Output Raw Format
119 { "setOutputRawFormat", &CParameterMgr::setOutputRawFormatCommmandProcess, 1, "dec*|hex", "Assigns format used to output parameter values when in raw Value Space" },
120 { "getOutputRawFormat", &CParameterMgr::getOutputRawFormatCommmandProcess, 0, "", "Show Output Raw Format" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200121 /// Sync
122 { "setAutoSync", &CParameterMgr::setAutoSyncCommmandProcess, 1, "on*|off", "Turn on or off automatic synchronization to hardware while in Tuning Mode" },
123 { "getAutoSync", &CParameterMgr::getAutoSyncCommmandProcess, 0, "", "Show Auto Sync state" },
124 { "sync", &CParameterMgr::syncCommmandProcess, 0, "", "Synchronize current settings to hardware while in Tuning Mode and Auto Sync off" },
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200125 /// Criteria
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200126 { "listCriteria", &CParameterMgr::listCriteriaCommmandProcess, 0, "", "List selection criteria" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200127 /// Domains
128 { "listDomains", &CParameterMgr::listDomainsCommmandProcess, 0, "", "List configurable domains" },
129 { "createDomain", &CParameterMgr::createDomainCommmandProcess, 1, "<domain>", "Create new configurable domain" },
130 { "deleteDomain", &CParameterMgr::deleteDomainCommmandProcess, 1, "<domain>", "Delete configurable domain" },
131 { "renameDomain", &CParameterMgr::renameDomainCommmandProcess, 2, "<domain> <new name>", "Rename configurable domain" },
Patrick Benavoli63499d42011-10-24 18:50:03 +0200132 { "setSequenceAwareness", &CParameterMgr::setSequenceAwarenessCommmandProcess, 1, "<domain> true|false*", "Set configurable domain sequence awareness" },
133 { "getSequenceAwareness", &CParameterMgr::getSequenceAwarenessCommmandProcess, 1, "<domain>", "Get configurable domain sequence awareness" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200134 { "listDomainElements", &CParameterMgr::listDomainElementsCommmandProcess, 1, "<domain>", "List elements associated to configurable domain" },
135 { "addElement", &CParameterMgr::addElementCommmandProcess, 2, "<domain> <elem path>", "Associate element at given path to configurable domain" },
136 { "removeElement", &CParameterMgr::removeElementCommmandProcess, 2, "<domain> <elem path>", "Dissociate element at given path from configurable domain" },
137 { "splitDomain", &CParameterMgr::splitDomainCommmandProcess, 2, "<domain> <elem path>", "Split configurable domain at given associated element path" },
138 /// Configurations
139 { "listConfigurations", &CParameterMgr::listConfigurationsCommmandProcess, 1, "<domain>", "List domain configurations" },
140 { "createConfiguration", &CParameterMgr::createConfigurationCommmandProcess, 2, "<domain> <configuration>", "Create new domain configuration" },
141 { "deleteConfiguration", &CParameterMgr::deleteConfigurationCommmandProcess, 2, "<domain> <configuration>", "Delete domain configuration" },
142 { "renameConfiguration", &CParameterMgr::renameConfigurationCommmandProcess, 3, "<domain> <configuration> <new name>", "Rename domain configuration" },
143 { "saveConfiguration", &CParameterMgr::saveConfigurationCommmandProcess, 2, "<domain> <configuration>", "Save current settings into configuration" },
144 { "restoreConfiguration", &CParameterMgr::restoreConfigurationCommmandProcess, 2, "<domain> <configuration>", "Restore current settings from configuration" },
Patrick Benavoli63499d42011-10-24 18:50:03 +0200145 { "setElementSequence", &CParameterMgr::setElementSequenceCommmandProcess, 2, "<domain> <configuration> <elem path list>", "Set element application order for configuration" },
146 { "getElementSequence", &CParameterMgr::getElementSequenceCommmandProcess, 2, "<domain> <configuration>", "Get element application order for configuration" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200147 /// Elements/Parameters
148 { "listElements", &CParameterMgr::listElementsCommmandProcess, 1, "<elem path>|/", "List elements under element at given path or root" },
Patrick Benavoli592ae562011-09-05 16:53:58 +0200149 { "listParameters", &CParameterMgr::listParametersCommmandProcess, 1, "<elem path>|/", "List parameters under element at given path or root" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200150 { "dumpElement", &CParameterMgr::dumpElementCommmandProcess, 1, "<elem path>", "Dump structure and content of element at given path" },
151 { "getElementSize", &CParameterMgr::getElementSizeCommmandProcess, 1, "<elem path>", "Show size of element at given path" },
Patrick Benavoli2ecf9002011-08-31 11:23:24 +0200152 { "showProperties", &CParameterMgr::showPropertiesCommmandProcess, 1, "<elem path>", "Show properties of element at given path" },
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200153 { "getParameter", &CParameterMgr::getParameterCommmandProcess, 1, "<param path>", "Get value for parameter at given path" },
Patrick Benavoli2ecf9002011-08-31 11:23:24 +0200154 { "setParameter", &CParameterMgr::setParameterCommmandProcess, 2, "<param path> <value>", "Set value for parameter at given path" },
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200155 { "listBelongingDomains", &CParameterMgr::listBelongingDomainsCommmandProcess, 1, "<elem path>", "List domain(s) element at given path belongs to" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200156 { "listAssociatedDomains", &CParameterMgr::listAssociatedDomainsCommmandProcess, 1, "<elem path>", "List domain(s) element at given path is associated to" },
157 /// Browse
158 { "listAssociatedElements", &CParameterMgr::listAssociatedElementsCommmandProcess, 0, "", "List element sub-trees associated to at least one configurable domain" },
159 { "listConflictingElements", &CParameterMgr::listConflictingElementsCommmandProcess, 0, "", "List element sub-trees contained in more than one configurable domain" },
160 { "listRogueElements", &CParameterMgr::listRogueElementsCommmandProcess, 0, "", "List element sub-trees owned by no configurable domain" },
161 /// Settings Import/Export
162 { "exportDomainsXML", &CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess, 1, "<file path> ", "Export domains to XML file" },
163 { "importDomainsXML", &CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess, 1, "<file path>", "Import domains from XML file" },
164 { "exportDomainsWithSettingsXML", &CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess, 1, "<file path> ", "Export domains including settings to XML file" },
165 { "importDomainsWithSettingsXML", &CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess, 1, "<file path>", "Import domains including settings from XML file" },
166 { "exportSettings", &CParameterMgr::exportSettingsCommmandProcess, 1, "<file path>", "Export settings to binary file" },
167 { "importSettings", &CParameterMgr::importSettingsCommmandProcess, 1, "<file path>", "Import settings from binary file" }
168};
169// Remote command parsers array Size
Patrick Benavoli592ae562011-09-05 16:53:58 +0200170const uint32_t CParameterMgr::guiNbRemoteCommandParserItems = sizeof(gastRemoteCommandParserItems) / sizeof(gastRemoteCommandParserItems[0]);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200171
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100172CParameterMgr::CParameterMgr(const string& strConfigurationFilePath) :
Patrick Benavoli68a91282011-08-31 11:23:23 +0200173 _bTuningModeIsOn(false),
174 _bValueSpaceIsRaw(false),
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200175 _bOutputRawFormatIsHex(false),
Patrick Benavoli68a91282011-08-31 11:23:23 +0200176 _bAutoSyncOn(true),
177 _pMainParameterBlackboard(new CParameterBlackboard),
178 _pElementLibrarySet(new CElementLibrarySet),
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100179 _strXmlConfigurationFilePath(strConfigurationFilePath),
Patrick Benavoli68a91282011-08-31 11:23:23 +0200180 _uiStructureChecksum(0),
181 _pRemoteProcessorServer(NULL),
182 _uiMaxCommandUsageLength(0),
183 _pLogger(NULL),
184 _uiLogDepth(0)
185{
186 // Tuning Mode Mutex
Patrick Benavoli065264a2011-11-20 15:46:41 +0100187 bzero(&_blackboardMutex, sizeof(_blackboardMutex));
188 pthread_mutex_init(&_blackboardMutex, NULL);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200189
190 // Deal with children
191 addChild(new CParameterFrameworkConfiguration);
192 addChild(new CSelectionCriteria);
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100193 addChild(new CSystemClass);
194 addChild(new CConfigurableDomains);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200195
196 // Feed element library
197 feedElementLibraries();
Patrick Benavoli63499d42011-10-24 18:50:03 +0200198
199 _pCommandHandler = new CCommandHandler(this);
200
201 // Add command parsers
202 uint32_t uiRemoteCommandParserItem;
203
204 for (uiRemoteCommandParserItem = 0; uiRemoteCommandParserItem < guiNbRemoteCommandParserItems; uiRemoteCommandParserItem++) {
205
206 const SRemoteCommandParserItem* pRemoteCommandParserItem = &gastRemoteCommandParserItems[uiRemoteCommandParserItem];
207
208 _pCommandHandler->addCommandParser(pRemoteCommandParserItem->_pcCommandName,
209 pRemoteCommandParserItem->_pfnParser,
210 pRemoteCommandParserItem->_uiMinArgumentCount,
211 pRemoteCommandParserItem->_pcHelp,
212 pRemoteCommandParserItem->_pcDescription);
213 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100214
215 // Configuration file folder
216 uint32_t uiSlashPos = _strXmlConfigurationFilePath.rfind('/', -1);
217
218 assert(uiSlashPos != (uint32_t)-1);
219
220 _strXmlConfigurationFolderPath = _strXmlConfigurationFilePath.substr(0, uiSlashPos);
221
222 // Schema absolute folder location
223 _strSchemaFolderLocation = _strXmlConfigurationFolderPath + "/" + gacSystemSchemasSubFolder;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200224}
225
226CParameterMgr::~CParameterMgr()
227{
228 // Children
229 delete _pRemoteProcessorServer;
230 delete _pMainParameterBlackboard;
231 delete _pElementLibrarySet;
232
233 // Tuning Mode Mutex
Patrick Benavoli065264a2011-11-20 15:46:41 +0100234 pthread_mutex_destroy(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200235}
236
237string CParameterMgr::getKind() const
238{
239 return "ParameterMgr";
240}
241
242// Logging
243void CParameterMgr::setLogger(CParameterMgr::ILogger* pLogger)
244{
245 _pLogger = pLogger;
246}
247
248// Logging
249void CParameterMgr::doLog(const string& strLog) const
250{
251 if (_pLogger) {
252
253 // Nest
254 string strIndent;
255
256 // Level
257 uint32_t uiNbIndents = _uiLogDepth;
258
259 while (uiNbIndents--) {
260
261 strIndent += " ";
262 }
263
264 // Log
265 _pLogger->log(strIndent + strLog);
266 }
267}
268
269void CParameterMgr::nestLog() const
270{
Patrick Benavoli592ae562011-09-05 16:53:58 +0200271 _uiLogDepth++;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200272}
273
274void CParameterMgr::unnestLog() const
275{
Patrick Benavoli592ae562011-09-05 16:53:58 +0200276 _uiLogDepth--;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200277}
278
Patrick Benavoli63499d42011-10-24 18:50:03 +0200279// Version
280string CParameterMgr::getVersion() const
281{
282 string strVersion;
283
284 // Major
285 strVersion = toString(guiEditionMajor) + ".";
286 // Minor
287 strVersion += toString(guiEditionMinor) + ".";
288 // Revision
289 strVersion += toString(guiRevision);
290
291 return strVersion;
292}
293
Patrick Benavoli68a91282011-08-31 11:23:23 +0200294bool CParameterMgr::load(string& strError)
295{
296 CAutoLog autoLog(this, "Loading");
297
298 // Load Framework configuration
299 if (!loadFrameworkConfiguration(strError)) {
300
301 return false;
302 }
303
304 // Load subsystems
305 if (!getSystemClass()->loadSubsystems(strError, _astrPluginFolderPaths)) {
306
307 return false;
308 }
309
310 // Load structure
311 if (!loadStructure(strError)) {
312
313 return false;
314 }
315
316 // Load settings
317 if (!loadSettings(strError)) {
318
319 return false;
320 }
321
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200322 // Back synchronization for areas in parameter blackboard not covered by any domain
323 CBackSynchronizer* pBackSynchronizer = createBackSynchronizer(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200324
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200325 log("Main blackboard back synchronization");
326
327 // Back-synchronize
328 if (!pBackSynchronizer->sync()) {
329 // Get rid of back synchronizer
330 delete pBackSynchronizer;
331
332 strError = "Main blackboard back synchronization failed: " + strError;
333
334 return false;
335 }
336 // Get rif of back synchronizer
337 delete pBackSynchronizer;
338
339 // We're done loading the settings and back synchronizing
340 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
341
342 // We need to ensure all domains are valid
343 pConfigurableDomains->validate(_pMainParameterBlackboard);
344
345 // Ensure application of currently selected configurations
346 // Force-apply configurations
347 if (!pConfigurableDomains->apply(_pMainParameterBlackboard, true, strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200348
349 return false;
350 }
351
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200352 // Start remote processor server if appropriate
353 return handleRemoteProcessingInterface(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200354}
355
356bool CParameterMgr::loadFrameworkConfiguration(string& strError)
357{
358 CAutoLog autoLog(this, "Loading framework configuration");
359
Patrick Benavoli68a91282011-08-31 11:23:23 +0200360 // Parse Structure XML file
361 CXmlElementSerializingContext elementSerializingContext(strError);
362
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100363 if (!xmlParse(elementSerializingContext, getFrameworkConfiguration(), _strXmlConfigurationFilePath, _strXmlConfigurationFolderPath, EFrameworkConfigurationLibrary)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200364
365 return false;
366 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100367 // Set class name to system class and configurable domains
368 getSystemClass()->setName(getConstFrameworkConfiguration()->getSystemClassName());
369 getConfigurableDomains()->setName(getConstFrameworkConfiguration()->getSystemClassName());
370
Patrick Benavoli68a91282011-08-31 11:23:23 +0200371 // Get subsystem plugins folders element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100372 const CFrameworkConfigurationGroup* pSubsystemPluginFolders = static_cast<const CFrameworkConfigurationGroup*>(getConstFrameworkConfiguration()->findChild("SubsystemPluginFolders"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200373
374 if (!pSubsystemPluginFolders) {
375
376 strError = "Parameter Framework Configuration: couldn't find SubsystemPluginFolders element";
377
378 return false;
379 }
380 // Get plugin locations
381 uint32_t uiPluginFolderLocation;
382 uint32_t uiNbPluginFolderLocations = pSubsystemPluginFolders->getNbChildren();
383
384 if (!uiNbPluginFolderLocations) {
385
386 strError = "Parameter Framework Configuration: couldn't find any PluginFolderLocation element";
387
388 return false;
389 }
390
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100391 // Collect plugin paths
Patrick Benavoli68a91282011-08-31 11:23:23 +0200392 for (uiPluginFolderLocation = 0; uiPluginFolderLocation < uiNbPluginFolderLocations; uiPluginFolderLocation++) {
393
394 const CFrameworkConfigurationLocation* pSubsystemPluginLocation = static_cast<const CFrameworkConfigurationLocation*>(pSubsystemPluginFolders->getChild(uiPluginFolderLocation));
395
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100396 _astrPluginFolderPaths.push_back(pSubsystemPluginLocation->getFilePath(_strXmlConfigurationFilePath));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200397 }
398
Patrick Benavoli68a91282011-08-31 11:23:23 +0200399 // Log tuning availability
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100400 log("Tuning %s", getConstFrameworkConfiguration()->isTuningAllowed() ? "allowed" : "prohibited");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200401
402 return true;
403}
404
405bool CParameterMgr::loadStructure(string& strError)
406{
407 // Retrieve system to load structure to
408 CSystemClass* pSystemClass = getSystemClass();
409
410 CAutoLog autoLog(this, "Loading " + pSystemClass->getName() + " system class structure");
411
412 // Get structure description element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100413 const CFrameworkConfigurationLocation* pStructureDescriptionFileLocation = static_cast<const CFrameworkConfigurationLocation*>(getConstFrameworkConfiguration()->findChildOfKind("StructureDescriptionFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200414
415 if (!pStructureDescriptionFileLocation) {
416
417 strError = "No StructureDescriptionFileLocation element found for SystemClass " + pSystemClass->getName();
418
419 return false;
420 }
421
422 // Get Xml structure folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100423 string strXmlStructureFolder = pStructureDescriptionFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200424
425 // Get Xml structure file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100426 string strXmlStructureFilePath = pStructureDescriptionFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200427
428 // Parse Structure XML file
429 CXmlParameterSerializingContext parameterBuildContext(strError);
430
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200431 log("Importing system structure from file %s", strXmlStructureFilePath.c_str());
432
Patrick Benavoli68a91282011-08-31 11:23:23 +0200433 if (!xmlParse(parameterBuildContext, pSystemClass, strXmlStructureFilePath, strXmlStructureFolder, EParameterCreationLibrary)) {
434
435 return false;
436 }
437
438 // Initialize offsets
439 pSystemClass->setOffset(0);
440
441 // Initialize main blackboard's size
442 _pMainParameterBlackboard->setSize(pSystemClass->getFootPrint());
443
444 return true;
445}
446
447bool CParameterMgr::loadSettings(string& strError)
448{
449 CAutoLog autoLog(this, "Loading settings");
450
451 // Get settings configuration element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100452 const CFrameworkConfigurationGroup* pParameterConfigurationGroup = static_cast<const CFrameworkConfigurationGroup*>(getConstFrameworkConfiguration()->findChildOfKind("SettingsConfiguration"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200453
454 if (!pParameterConfigurationGroup) {
455
456 // No settings to load
457
458 return true;
459 }
460 // Get binary settings file location
461 const CFrameworkConfigurationLocation* pBinarySettingsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("BinarySettingsFileLocation"));
462
463 string strXmlBinarySettingsFilePath;
464
465 if (pBinarySettingsFileLocation) {
466
467 // Get Xml binary settings file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100468 strXmlBinarySettingsFilePath = pBinarySettingsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200469 }
470
471 // Get configurable domains element
472 const CFrameworkConfigurationLocation* pConfigurableDomainsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("ConfigurableDomainsFileLocation"));
473
474 if (!pConfigurableDomainsFileLocation) {
475
476 strError = "No ConfigurableDomainsFileLocation element found for SystemClass " + getSystemClass()->getName();
477
478 return false;
479 }
480 // Get destination root element
481 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
482
483 // Get Xml configuration domains file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100484 string strXmlConfigurationDomainsFilePath = pConfigurableDomainsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200485
486 // Get Xml configuration domains folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100487 string strXmlConfigurationDomainsFolder = pConfigurableDomainsFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200488
489 // Parse configuration domains XML file (ask to read settings from XML file if they are not provided as binary)
490 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, !pBinarySettingsFileLocation);
491
492 // Selection criteria definition for rule creation
493 xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
494
Patrick Benavoli63499d42011-10-24 18:50:03 +0200495 // Auto validation of configurations if no binary settings provided
496 xmlDomainSerializingContext.setAutoValidationRequired(!pBinarySettingsFileLocation);
497
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200498 log("Importing configurable domains from file %s %s settings", strXmlConfigurationDomainsFilePath.c_str(), pBinarySettingsFileLocation ? "without" : "with");
499
Patrick Benavoli68a91282011-08-31 11:23:23 +0200500 // Do parse
501 if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strXmlConfigurationDomainsFilePath, strXmlConfigurationDomainsFolder, EParameterConfigurationLibrary, "SystemClassName")) {
502
503 return false;
504 }
505 // We have loaded the whole system structure, compute checksum
506 const CSystemClass* pSystemClass = getConstSystemClass();
507 _uiStructureChecksum = pSystemClass->computeStructureChecksum() + getConfigurableDomains()->computeStructureChecksum() + getSelectionCriteria()->computeStructureChecksum();
508
509 // Load binary settings if any provided
510 if (pBinarySettingsFileLocation && !pConfigurableDomains->serializeSettings(strXmlBinarySettingsFilePath, false, _uiStructureChecksum, strError)) {
511
512 return false;
513 }
514
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200515 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200516}
517
518// XML parsing
519bool CParameterMgr::xmlParse(CXmlElementSerializingContext& elementSerializingContext, CElement* pRootElement, const string& strXmlFilePath, const string& strXmlFolder, CParameterMgr::ElementLibrary eElementLibrary, const string& strNameAttrituteName)
520{
521 // Init serializing context
522 elementSerializingContext.set(_pElementLibrarySet->getElementLibrary(eElementLibrary), strXmlFolder, _strSchemaFolderLocation);
523
524 // Get Schema file associated to root element
525 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pRootElement->getKind() + ".xsd";
526
527 // Parse Structure XML file
528 CXmlParser parser(strXmlFilePath, strXmlSchemaFilePath, pRootElement->getKind(), elementSerializingContext);
529
530 if (!parser.open()) {
531
532 return false;
533 }
534
535 // Check Root element name attribute (if any)
536 string strRootElementName = parser.getRootElementAttributeString(strNameAttrituteName);
537
538 if (!strRootElementName.empty() && strRootElementName != pRootElement->getName()) {
539
540 elementSerializingContext.setError("Error: Wrong XML structure file " + strXmlFilePath);
541 elementSerializingContext.appendLineToError(pRootElement->getKind() + " element " + pRootElement->getName() + " mismatches expected " + pRootElement->getKind() + " type " + pRootElement->getName());
542
543 return false;
544 }
545
546 // Start clean
547 pRootElement->clean();
548
549 // Parse
550 if (!parser.parse(pRootElement)) {
551
552 // Cleanup
553 pRootElement->clean();
554
555 return false;
556 }
557
558 // Close parser
559 if (!parser.close()) {
560
561 return false;
562 }
563
564 return true;
565}
566
567// Init
568bool CParameterMgr::init(string& strError)
569{
570 return base::init(strError);
571}
572
573// Selection criteria interface
574CSelectionCriterionType* CParameterMgr::createSelectionCriterionType(bool bIsInclusive)
575{
576 // Propagate
577 return getSelectionCriteria()->createSelectionCriterionType(bIsInclusive);
578}
579
580CSelectionCriterion* CParameterMgr::createSelectionCriterion(const string& strName, const CSelectionCriterionType* pSelectionCriterionType)
581{
582 // Propagate
583 return getSelectionCriteria()->createSelectionCriterion(strName, pSelectionCriterionType);
584}
585
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200586// Selection criterion retrieval
587CSelectionCriterion* CParameterMgr::getSelectionCriterion(const string& strName)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200588{
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200589 // Propagate
590 return getSelectionCriteria()->getSelectionCriterion(strName);
591}
592
593// Selection criteria changed event
594bool CParameterMgr::applyConfigurations(string& strError)
595{
596 CAutoLog autoLog(this, "Configuration application request");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200597
598 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +0100599 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200600
601 if (!_bTuningModeIsOn) {
602
603 // Apply configuration(s)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200604 if (!getConfigurableDomains()->apply(_pMainParameterBlackboard, false, strError)) {
605
606 log("Failed to apply configurations!");
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200607
608 return false;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200609 }
610 }
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200611
612 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200613}
614
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200615// Dynamic parameter handling
Patrick Benavoli065264a2011-11-20 15:46:41 +0100616CParameterHandle* CParameterMgr::createParameterHandle(const string& strPath, string& strError)
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200617{
Patrick Benavoli065264a2011-11-20 15:46:41 +0100618 CPathNavigator pathNavigator(strPath);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200619
Patrick Benavoli065264a2011-11-20 15:46:41 +0100620 // Nagivate through system class
621 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
622
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100623 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100624 }
625
626 // Find element
627 const CElement* pElement = getConstSystemClass()->findDescendant(pathNavigator);
628
629 if (!pElement) {
630
631 strError = "Path not found";
632
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100633 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100634 }
635
636 // Check found element is a parameter
637 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pElement);
638
639 if (!pConfigurableElement->isParameter()) {
640
641 // Element is not parameter
642 strError = "Not a parameter";
643
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100644 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100645 }
646
647 // Convert as parameter and return new handle
648 return new CParameterHandle(static_cast<const CBaseParameter*>(pElement), this);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200649}
650
Patrick Benavoli68a91282011-08-31 11:23:23 +0200651/////////////////// Remote command parsers
Patrick Benavoli592ae562011-09-05 16:53:58 +0200652/// Version
Patrick Benavoli63499d42011-10-24 18:50:03 +0200653CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::versionCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli592ae562011-09-05 16:53:58 +0200654{
655 (void)remoteCommand;
656
Patrick Benavoli63499d42011-10-24 18:50:03 +0200657 // Show version
658 strResult = getVersion();
Patrick Benavoli592ae562011-09-05 16:53:58 +0200659
Patrick Benavoli63499d42011-10-24 18:50:03 +0200660 return CCommandHandler::ESucceeded;
Patrick Benavoli592ae562011-09-05 16:53:58 +0200661}
662
Patrick Benavoli68a91282011-08-31 11:23:23 +0200663/// Status
Patrick Benavoli63499d42011-10-24 18:50:03 +0200664CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::statusCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200665{
666 (void)remoteCommand;
667 // System class
668 const CSystemClass* pSystemClass = getSystemClass();
669
Patrick Benavoli68a91282011-08-31 11:23:23 +0200670 // Show status
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200671 /// General section
672 appendTitle(strResult, "General:");
673 // System class
Patrick Benavoli68a91282011-08-31 11:23:23 +0200674 strResult += "System Class: ";
675 strResult += pSystemClass->getName();
676 strResult += "\n";
677
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200678 // Tuning mode
Patrick Benavoli68a91282011-08-31 11:23:23 +0200679 strResult += "Tuning Mode: ";
680 strResult += tuningModeOn() ? "on" : "off";
681 strResult += "\n";
682
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200683 // Value space
Patrick Benavoli68a91282011-08-31 11:23:23 +0200684 strResult += "Value Space: ";
685 strResult += valueSpaceIsRaw() ? "raw" : "real";
686 strResult += "\n";
687
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200688 // Output raw format
689 strResult += "Output Raw Format: ";
690 strResult += outputRawFormatIsHex() ? "hex" : "dec";
691 strResult += "\n";
692
693 // Auto Sync
Patrick Benavoli68a91282011-08-31 11:23:23 +0200694 strResult += "Auto Sync: ";
695 strResult += autoSyncOn() ? "on" : "off";
696 strResult += "\n";
697
698 /// Subsystem list
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200699 appendTitle(strResult, "Subsystems:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200700 string strSubsystemList;
701 pSystemClass->listChildrenPaths(strSubsystemList);
702 strResult += strSubsystemList;
703
704 /// Last applied configurations
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200705 appendTitle(strResult, "Last applied configurations:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200706 string strLastAppliedConfigurations;
707 getConfigurableDomains()->listLastAppliedConfigurations(strLastAppliedConfigurations);
708 strResult += strLastAppliedConfigurations;
709
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200710 /// Criteria states
711 appendTitle(strResult, "Selection criteria:");
712 string strSelectionCriteria;
713 getSelectionCriteria()->listSelectionCriteria(strSelectionCriteria, false);
714 strResult += strSelectionCriteria;
715
Patrick Benavoli63499d42011-10-24 18:50:03 +0200716 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200717}
718
719/// Tuning Mode
Patrick Benavoli63499d42011-10-24 18:50:03 +0200720CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200721{
722 if (remoteCommand.getArgument(0) == "on") {
723
724 if (setTuningMode(true, strResult)) {
725
Patrick Benavoli63499d42011-10-24 18:50:03 +0200726 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200727 }
728 } else if (remoteCommand.getArgument(0) == "off") {
729
730 if (setTuningMode(false, strResult)) {
731
Patrick Benavoli63499d42011-10-24 18:50:03 +0200732 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200733 }
734 } else {
735 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200736 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200737 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200738 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200739}
740
Patrick Benavoli63499d42011-10-24 18:50:03 +0200741CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200742{
743 (void)remoteCommand;
744
745 strResult = tuningModeOn() ? "on" : "off";
746
Patrick Benavoli63499d42011-10-24 18:50:03 +0200747 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200748}
749
750/// Value Space
Patrick Benavoli63499d42011-10-24 18:50:03 +0200751CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200752{
753 (void)strResult;
754
755 if (remoteCommand.getArgument(0) == "raw") {
756
757 setValueSpace(true);
758
Patrick Benavoli63499d42011-10-24 18:50:03 +0200759 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200760
761 } else if (remoteCommand.getArgument(0) == "real") {
762
763 setValueSpace(false);
764
Patrick Benavoli63499d42011-10-24 18:50:03 +0200765 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200766
767 } else {
768 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200769 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200770 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200771 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200772}
773
Patrick Benavoli63499d42011-10-24 18:50:03 +0200774CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200775{
776 (void)remoteCommand;
777
778 strResult = valueSpaceIsRaw() ? "raw" : "real";
779
Patrick Benavoli63499d42011-10-24 18:50:03 +0200780 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200781}
782
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200783/// Output Raw Format
Patrick Benavoli63499d42011-10-24 18:50:03 +0200784CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200785{
786 (void)strResult;
787
788 if (remoteCommand.getArgument(0) == "hex") {
789
790 setOutputRawFormat(true);
791
Patrick Benavoli63499d42011-10-24 18:50:03 +0200792 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200793
794 } else if (remoteCommand.getArgument(0) == "dec") {
795
796 setOutputRawFormat(false);
797
Patrick Benavoli63499d42011-10-24 18:50:03 +0200798 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200799
800 } else {
801 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200802 return CCommandHandler::EShowUsage;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200803 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200804 return CCommandHandler::EFailed;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200805}
806
Patrick Benavoli63499d42011-10-24 18:50:03 +0200807CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200808{
809 (void)remoteCommand;
810
811 strResult = outputRawFormatIsHex() ? "hex" : "dec";
812
Patrick Benavoli63499d42011-10-24 18:50:03 +0200813 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200814}
815
Patrick Benavoli68a91282011-08-31 11:23:23 +0200816/// Sync
Patrick Benavoli63499d42011-10-24 18:50:03 +0200817CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200818{
819 if (remoteCommand.getArgument(0) == "on") {
820
821 if (setAutoSync(true, strResult)) {
822
Patrick Benavoli63499d42011-10-24 18:50:03 +0200823 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200824 }
825 } else if (remoteCommand.getArgument(0) == "off") {
826
827 if (setAutoSync(false, strResult)) {
828
Patrick Benavoli63499d42011-10-24 18:50:03 +0200829 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200830 }
831 } else {
832 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200833 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200834 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200835 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200836}
837
Patrick Benavoli63499d42011-10-24 18:50:03 +0200838CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200839{
840 (void)remoteCommand;
841
842 strResult = autoSyncOn() ? "on" : "off";
843
Patrick Benavoli63499d42011-10-24 18:50:03 +0200844 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200845}
846
Patrick Benavoli63499d42011-10-24 18:50:03 +0200847CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::syncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200848{
849 (void)remoteCommand;
850
Patrick Benavoli63499d42011-10-24 18:50:03 +0200851 return sync(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200852}
853
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200854/// Criteria
Patrick Benavoli63499d42011-10-24 18:50:03 +0200855CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listCriteriaCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200856{
857 (void)remoteCommand;
858
859 getSelectionCriteria()->listSelectionCriteria(strResult, true);
860
Patrick Benavoli63499d42011-10-24 18:50:03 +0200861 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200862}
Patrick Benavoli68a91282011-08-31 11:23:23 +0200863
864/// Domains
Patrick Benavoli63499d42011-10-24 18:50:03 +0200865CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200866{
867 (void)remoteCommand;
868
Patrick Benavoli63499d42011-10-24 18:50:03 +0200869 getConfigurableDomains()->listDomains(strResult);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200870
Patrick Benavoli63499d42011-10-24 18:50:03 +0200871 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200872}
873
Patrick Benavoli63499d42011-10-24 18:50:03 +0200874CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200875{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200876 return createDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200877}
878
Patrick Benavoli63499d42011-10-24 18:50:03 +0200879CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200880{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200881 return deleteDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200882}
883
Patrick Benavoli63499d42011-10-24 18:50:03 +0200884CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200885{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200886 return getConfigurableDomains()->renameDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200887}
888
Patrick Benavoli63499d42011-10-24 18:50:03 +0200889CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200890{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200891 // Check tuning mode
892 if (!checkTuningModeOn(strResult)) {
893
894 return CCommandHandler::EFailed;
895 }
896
897 // Set property
898 bool bSequenceAware;
899
900 if (remoteCommand.getArgument(1) == "true") {
901
902 bSequenceAware = true;
903
904 } else if (remoteCommand.getArgument(1) == "false") {
905
906 bSequenceAware = false;
907
908 } else {
909 // Show usage
910 return CCommandHandler::EShowUsage;
911 }
912
913 return getConfigurableDomains()->setSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200914}
915
Patrick Benavoli63499d42011-10-24 18:50:03 +0200916CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200917{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200918 // Get property
919 bool bSequenceAware;
920
921 if (!getConfigurableDomains()->getSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult)) {
922
923 return CCommandHandler::EFailed;
924 }
925
926 strResult = bSequenceAware ? "true" : "false";
927
928 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200929}
930
Patrick Benavoli63499d42011-10-24 18:50:03 +0200931CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200932{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200933 return getConfigurableDomains()->listDomainElements(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200934}
935
Patrick Benavoli63499d42011-10-24 18:50:03 +0200936CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::addElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200937{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200938 return addConfigurableElementToDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
939}
940
941CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::removeElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
942{
943 return removeConfigurableElementFromDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
944}
945
946CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::splitDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
947{
948 return split(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200949}
950
951/// Configurations
Patrick Benavoli63499d42011-10-24 18:50:03 +0200952CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConfigurationsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200953{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200954 return getConfigurableDomains()->listConfigurations(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200955}
956
Patrick Benavoli63499d42011-10-24 18:50:03 +0200957CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200958{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200959 return createConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200960}
961
Patrick Benavoli63499d42011-10-24 18:50:03 +0200962CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200963{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200964 return deleteConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200965}
966
Patrick Benavoli63499d42011-10-24 18:50:03 +0200967CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200968{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200969 return getConfigurableDomains()->renameConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200970}
971
Patrick Benavoli63499d42011-10-24 18:50:03 +0200972CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::saveConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200973{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200974 return saveConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200975}
976
Patrick Benavoli63499d42011-10-24 18:50:03 +0200977CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::restoreConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200978{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200979 return restoreConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
980}
981
982CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
983{
984 // Check tuning mode
985 if (!checkTuningModeOn(strResult)) {
986
987 return CCommandHandler::EFailed;
988 }
989
990 // Build configurable element path list
991 vector<string> astrNewElementSequence;
992
993 uint32_t uiArgument;
994
995 for (uiArgument = 2; uiArgument < remoteCommand.getArgumentCount(); uiArgument++) {
996
997 astrNewElementSequence.push_back(remoteCommand.getArgument(uiArgument));
998 }
999
1000 // Delegate to configurable domains
1001 return getConfigurableDomains()->setElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), astrNewElementSequence, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1002}
1003
1004CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1005{
1006 // Delegate to configurable domains
1007 return getConfigurableDomains()->getElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001008}
1009
1010/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001011CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001012{
1013 CElementLocator elementLocator(getSystemClass(), false);
1014
1015 CElement* pLocatedElement = NULL;
1016
1017 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1018
Patrick Benavoli63499d42011-10-24 18:50:03 +02001019 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001020 }
1021
1022 strResult = string("\n");
1023
1024 if (!pLocatedElement) {
1025
1026 // List from root folder
1027
1028 // Return system class qualified name
1029 pLocatedElement = getSystemClass();
1030 }
1031
1032 // Return sub-elements
1033 strResult += pLocatedElement->listQualifiedPaths(false);
1034
Patrick Benavoli63499d42011-10-24 18:50:03 +02001035 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001036}
1037
1038/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001039CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listParametersCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001040{
1041 CElementLocator elementLocator(getSystemClass(), false);
1042
1043 CElement* pLocatedElement = NULL;
1044
1045 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1046
Patrick Benavoli63499d42011-10-24 18:50:03 +02001047 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001048 }
1049
1050 strResult = string("\n");
1051
1052 if (!pLocatedElement) {
1053
1054 // List from root folder
1055
1056 // Return system class qualified name
1057 pLocatedElement = getSystemClass();
1058 }
1059
1060 // Return sub-elements
1061 strResult += pLocatedElement->listQualifiedPaths(true);
1062
Patrick Benavoli63499d42011-10-24 18:50:03 +02001063 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001064}
1065
Patrick Benavoli63499d42011-10-24 18:50:03 +02001066CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001067{
1068 CElementLocator elementLocator(getSystemClass());
1069
1070 CElement* pLocatedElement = NULL;
1071
1072 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1073
Patrick Benavoli63499d42011-10-24 18:50:03 +02001074 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001075 }
1076
1077 string strError;
1078
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001079 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001080
1081 // Dump elements
1082 pLocatedElement->dumpContent(strResult, parameterAccessContext);
1083
Patrick Benavoli63499d42011-10-24 18:50:03 +02001084 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001085}
1086
Patrick Benavoli63499d42011-10-24 18:50:03 +02001087CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSizeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001088{
1089 CElementLocator elementLocator(getSystemClass());
1090
1091 CElement* pLocatedElement = NULL;
1092
1093 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1094
Patrick Benavoli63499d42011-10-24 18:50:03 +02001095 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001096 }
1097
1098 // Converted to actual sizable element
1099 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1100
1101 // Get size as string
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001102 strResult = pConfigurableElement->getFootprintAsString();
Patrick Benavoli68a91282011-08-31 11:23:23 +02001103
Patrick Benavoli63499d42011-10-24 18:50:03 +02001104 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001105}
1106
Patrick Benavoli63499d42011-10-24 18:50:03 +02001107CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showPropertiesCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001108{
1109 CElementLocator elementLocator(getSystemClass());
1110
1111 CElement* pLocatedElement = NULL;
1112
1113 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1114
Patrick Benavoli63499d42011-10-24 18:50:03 +02001115 return CCommandHandler::EFailed;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001116 }
1117
1118 // Convert element
1119 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1120
1121 // Return element properties
1122 pConfigurableElement->showProperties(strResult);
1123
Patrick Benavoli63499d42011-10-24 18:50:03 +02001124 return CCommandHandler::ESucceeded;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001125}
1126
Patrick Benavoli63499d42011-10-24 18:50:03 +02001127CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001128{
1129 string strValue;
1130
Patrick Benavoli065264a2011-11-20 15:46:41 +01001131 if (!accessValue(remoteCommand.getArgument(0), strValue, false, strResult)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001132
Patrick Benavoli63499d42011-10-24 18:50:03 +02001133 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001134 }
1135 // Succeeded
1136 strResult = strValue;
1137
Patrick Benavoli63499d42011-10-24 18:50:03 +02001138 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001139}
1140
Patrick Benavoli63499d42011-10-24 18:50:03 +02001141CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001142{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001143 // Check tuning mode
1144 if (!checkTuningModeOn(strResult)) {
1145
1146 return CCommandHandler::EFailed;
1147 }
1148 // Get value to set
1149 string strValue = remoteCommand.packArguments(1, remoteCommand.getArgumentCount() - 1);
1150
1151 return accessValue(remoteCommand.getArgument(0), strValue, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001152}
1153
Patrick Benavoli63499d42011-10-24 18:50:03 +02001154CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listBelongingDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001155{
1156 CElementLocator elementLocator(getSystemClass());
1157
1158 CElement* pLocatedElement = NULL;
1159
1160 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1161
Patrick Benavoli63499d42011-10-24 18:50:03 +02001162 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001163 }
1164
1165 // Convert element
1166 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1167
1168 // Return element belonging domains
1169 pConfigurableElement->listBelongingDomains(strResult);
1170
Patrick Benavoli63499d42011-10-24 18:50:03 +02001171 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001172}
1173
Patrick Benavoli63499d42011-10-24 18:50:03 +02001174CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001175{
1176 CElementLocator elementLocator(getSystemClass());
1177
1178 CElement* pLocatedElement = NULL;
1179
1180 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1181
Patrick Benavoli63499d42011-10-24 18:50:03 +02001182 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001183 }
1184
1185 // Convert element
1186 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1187
1188 // Return element belonging domains
1189 pConfigurableElement->listAssociatedDomains(strResult);
1190
Patrick Benavoli63499d42011-10-24 18:50:03 +02001191 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001192}
1193
Patrick Benavoli63499d42011-10-24 18:50:03 +02001194CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001195{
1196 (void)remoteCommand;
1197
1198 getConfigurableDomains()->listAssociatedElements(strResult);
1199
Patrick Benavoli63499d42011-10-24 18:50:03 +02001200 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001201}
1202
Patrick Benavoli63499d42011-10-24 18:50:03 +02001203CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConflictingElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001204{
1205 (void)remoteCommand;
1206
1207 getConfigurableDomains()->listConflictingElements(strResult);
1208
Patrick Benavoli63499d42011-10-24 18:50:03 +02001209 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001210}
1211
Patrick Benavoli63499d42011-10-24 18:50:03 +02001212CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listRogueElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001213{
1214 (void)remoteCommand;
1215
1216 getSystemClass()->listRogueElements(strResult);
1217
Patrick Benavoli63499d42011-10-24 18:50:03 +02001218 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001219}
1220
1221/// Settings Import/Export
Patrick Benavoli63499d42011-10-24 18:50:03 +02001222CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001223{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001224 return exportDomainsXml(remoteCommand.getArgument(0), false, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001225}
1226
Patrick Benavoli63499d42011-10-24 18:50:03 +02001227CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001228{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001229 return importDomainsXml(remoteCommand.getArgument(0), false, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001230}
1231
Patrick Benavoli63499d42011-10-24 18:50:03 +02001232CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001233{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001234 return exportDomainsXml(remoteCommand.getArgument(0), true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001235}
1236
Patrick Benavoli63499d42011-10-24 18:50:03 +02001237CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001238{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001239 return importDomainsXml(remoteCommand.getArgument(0), true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001240}
1241
Patrick Benavoli63499d42011-10-24 18:50:03 +02001242CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001243{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001244 return exportDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001245}
1246
Patrick Benavoli63499d42011-10-24 18:50:03 +02001247CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001248{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001249 return importDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001250}
1251
1252// User set/get parameters
Patrick Benavoli065264a2011-11-20 15:46:41 +01001253bool CParameterMgr::accessValue(const string& strPath, string& strValue, bool bSet, string& strError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001254{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001255 // Lock state
1256 CAutoLock autoLock(&_blackboardMutex);
1257
1258 CPathNavigator pathNavigator(strPath);
1259
1260 // Nagivate through system class
1261 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001262
1263 return false;
1264 }
1265
Patrick Benavoli065264a2011-11-20 15:46:41 +01001266 // Define context
1267 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001268
Patrick Benavoli065264a2011-11-20 15:46:41 +01001269 // Do the get
1270 return getConstSystemClass()->accessValue(pathNavigator, strValue, bSet, parameterAccessContext);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001271}
1272
1273// Tuning mode
1274bool CParameterMgr::setTuningMode(bool bOn, string& strError)
1275{
1276 // Tuning allowed?
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001277 if (bOn && !getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001278
1279 strError = "Tuning prohibited";
1280
1281 return false;
1282 }
1283 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +01001284 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001285
1286 // Warn domains about exiting tuning mode
1287 if (!bOn && _bTuningModeIsOn) {
1288
1289 // Ensure application of currently selected configurations
Patrick Benavoli1387bda2011-08-31 11:23:24 +02001290 // Force-apply configurations
Patrick Benavoli68a91282011-08-31 11:23:23 +02001291 if (!getConfigurableDomains()->apply(_pMainParameterBlackboard, true, strError)) {
1292
1293 return false;
1294 }
1295 // Turn auto sync back on
1296 _bAutoSyncOn = true;
1297 }
1298
1299 // Store
1300 _bTuningModeIsOn = bOn;
1301
Patrick Benavoli68a91282011-08-31 11:23:23 +02001302 return true;
1303}
1304
1305bool CParameterMgr::tuningModeOn() const
1306{
1307 return _bTuningModeIsOn;
1308}
1309
1310// Current value space for user set/get value interpretation
1311void CParameterMgr::setValueSpace(bool bIsRaw)
1312{
1313 _bValueSpaceIsRaw = bIsRaw;
1314}
1315
1316bool CParameterMgr::valueSpaceIsRaw()
1317{
1318 return _bValueSpaceIsRaw;
1319}
1320
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001321// Current Output Raw Format for user get value interpretation
1322void CParameterMgr::setOutputRawFormat(bool bIsHex)
1323{
1324 _bOutputRawFormatIsHex = bIsHex;
1325}
1326
1327bool CParameterMgr::outputRawFormatIsHex()
1328{
1329 return _bOutputRawFormatIsHex;
1330}
1331
Patrick Benavoli68a91282011-08-31 11:23:23 +02001332/// Sync
1333// Automatic hardware synchronization control (during tuning session)
1334bool CParameterMgr::setAutoSync(bool bAutoSyncOn, string& strError)
1335{
1336 // Check tuning mode
1337 if (!checkTuningModeOn(strError)) {
1338
1339 return false;
1340 }
1341 // Warn domains about turning auto sync back on
1342 if (bAutoSyncOn && !_bAutoSyncOn) {
1343
Patrick Benavoli592ae562011-09-05 16:53:58 +02001344 // Do the synchronization at system class level (could be optimized by keeping track of all modified parameters)
1345 if (!sync(strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001346
1347 return false;
1348 }
1349 }
1350
1351 // Set Auto sync
1352 _bAutoSyncOn = bAutoSyncOn;
1353
1354 return true;
1355}
1356
1357bool CParameterMgr::autoSyncOn() const
1358{
1359 return _bAutoSyncOn;
1360}
1361
1362// Manual hardware synchronization control (during tuning session)
1363bool CParameterMgr::sync(string& strError)
1364{
1365 // Check tuning mode
1366 if (!checkTuningModeOn(strError)) {
1367
1368 return false;
1369 }
1370 // Warn domains about turning auto sync back on
1371 if (_bAutoSyncOn) {
1372
1373 strError = "Feature unavailable when Auto Sync is on";
1374
1375 return false;
1376 }
1377
1378 // Get syncer set
1379 CSyncerSet syncerSet;
1380 // ... from system class
1381 getConstSystemClass()->fillSyncerSet(syncerSet);
1382 // Sync
1383 return syncerSet.sync(*_pMainParameterBlackboard, false, strError);
1384}
1385
1386// Content dump
1387void CParameterMgr::logStructureContent(string& strContent) const
1388{
1389 string strError;
1390
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001391 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001392
1393 dumpContent(strContent, parameterAccessContext);
1394}
1395
1396// Configuration/Domains handling
1397bool CParameterMgr::createDomain(const string& strName, string& strError)
1398{
1399 // Check tuning mode
1400 if (!checkTuningModeOn(strError)) {
1401
1402 return false;
1403 }
1404
1405 // Delegate to configurable domains
1406 return getConfigurableDomains()->createDomain(strName, strError);
1407}
1408
1409bool CParameterMgr::deleteDomain(const string& strName, string& strError)
1410{
1411 // Check tuning mode
1412 if (!checkTuningModeOn(strError)) {
1413
1414 return false;
1415 }
1416
1417 // Delegate to configurable domains
1418 return getConfigurableDomains()->deleteDomain(strName, strError);
1419}
1420
1421bool CParameterMgr::createConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1422{
1423 // Check tuning mode
1424 if (!checkTuningModeOn(strError)) {
1425
1426 return false;
1427 }
1428
1429 // Delegate to configurable domains
1430 return getConfigurableDomains()->createConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1431}
1432
1433bool CParameterMgr::deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1434{
1435 // Check tuning mode
1436 if (!checkTuningModeOn(strError)) {
1437
1438 return false;
1439 }
1440
1441 // Delegate to configurable domains
1442 return getConfigurableDomains()->deleteConfiguration(strDomain, strConfiguration, strError);
1443}
1444
1445bool CParameterMgr::restoreConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1446{
1447 // Check tuning mode
1448 if (!checkTuningModeOn(strError)) {
1449
1450 return false;
1451 }
1452
1453 // Delegate to configurable domains
1454 return getConfigurableDomains()->restoreConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, strError);
1455}
1456
1457bool CParameterMgr::saveConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1458{
1459 // Check tuning mode
1460 if (!checkTuningModeOn(strError)) {
1461
1462 return false;
1463 }
1464
1465 // Delegate to configurable domains
1466 return getConfigurableDomains()->saveConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1467}
1468
1469// Configurable element - domain association
1470bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1471{
1472 // Check tuning mode
1473 if (!checkTuningModeOn(strError)) {
1474
1475 return false;
1476 }
1477
1478 CElementLocator elementLocator(getSystemClass());
1479
1480 CElement* pLocatedElement = NULL;
1481
1482 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1483
1484 return false;
1485 }
1486
1487 // Convert element
1488 CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1489
1490 // Delegate
1491 return getConfigurableDomains()->addConfigurableElementToDomain(strDomain, pConfigurableElement, _pMainParameterBlackboard, strError);
1492}
1493
1494bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1495{
1496 // Check tuning mode
1497 if (!checkTuningModeOn(strError)) {
1498
1499 return false;
1500 }
1501
1502 CElementLocator elementLocator(getSystemClass());
1503
1504 CElement* pLocatedElement = NULL;
1505
1506 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1507
Patrick Benavoli63499d42011-10-24 18:50:03 +02001508 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001509 }
1510
1511 // Convert element
1512 CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1513
1514 // Delegate
1515 return getConfigurableDomains()->removeConfigurableElementFromDomain(strDomain, pConfigurableElement, strError);
1516}
1517
1518bool CParameterMgr::split(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1519{
1520 // Check tuning mode
1521 if (!checkTuningModeOn(strError)) {
1522
1523 return false;
1524 }
1525
1526 CElementLocator elementLocator(getSystemClass());
1527
1528 CElement* pLocatedElement = NULL;
1529
1530 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1531
Patrick Benavoli63499d42011-10-24 18:50:03 +02001532 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001533 }
1534
1535 // Convert element
1536 CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1537
1538 // Delegate
1539 return getConfigurableDomains()->split(strDomain, pConfigurableElement, strError);
1540}
1541
1542// XML Import/Export
1543bool CParameterMgr::importDomainsXml(const string& strFileName, bool bWithSettings, string& strError)
1544{
1545 // Check tuning mode
1546 if (!checkTuningModeOn(strError)) {
1547
1548 return false;
1549 }
1550
1551 // check path is absolute
1552 if (strFileName[0] != '/') {
1553
1554 strError = "Please provide absolute path";
1555
1556 return false;
1557 }
1558 // Root element
1559 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1560
1561 // Context
1562 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1563
1564 // Secltion criteria definition for rule creation
1565 xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
1566
1567 // Parse
1568 if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strFileName, "", EParameterConfigurationLibrary, "SystemClassName")) {
1569
1570 return false;
1571 }
1572
1573 // Validate domains after XML import
1574 pConfigurableDomains->validate(_pMainParameterBlackboard);
1575
1576 return true;
1577}
1578
1579bool CParameterMgr::exportDomainsXml(const string& strFileName, bool bWithSettings, string& strError) const
1580{
1581 // check path is absolute
1582 if (strFileName[0] != '/') {
1583
1584 strError = "Please provide absolute path";
1585
1586 return false;
1587 }
1588
1589 // Root element
1590 const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains();
1591
1592 // Get Schema file associated to root element
1593 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pConfigurableDomains->getKind() + ".xsd";
1594
1595 // Context
1596 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1597
1598 // Value space
1599 xmlDomainSerializingContext.setValueSpaceRaw(_bValueSpaceIsRaw);
1600
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001601 // Output raw format
1602 xmlDomainSerializingContext.setOutputRawFormat(_bOutputRawFormatIsHex);
1603
Patrick Benavoli68a91282011-08-31 11:23:23 +02001604 // Instantiate composer
1605 CXmlComposer xmlComposer(strFileName, strXmlSchemaFilePath, pConfigurableDomains->getKind(), xmlDomainSerializingContext);
1606
1607 // Open composer
1608 if (!xmlComposer.open()) {
1609
1610 return false;
1611 }
1612
1613 // Compose
Patrick Benavoli63499d42011-10-24 18:50:03 +02001614 xmlComposer.compose(pConfigurableDomains, "parameter-framework", getVersion());
Patrick Benavoli68a91282011-08-31 11:23:23 +02001615
1616 // Close composer
1617 if (!xmlComposer.close()) {
1618
1619 return false;
1620 }
1621
1622 return true;
1623}
1624
1625// Binary Import/Export
1626bool CParameterMgr::importDomainsBinary(const string& strFileName, string& strError)
1627{
1628 // Check tuning mode
1629 if (!checkTuningModeOn(strError)) {
1630
1631 return false;
1632 }
1633 // check path is absolute
1634 if (strFileName[0] != '/') {
1635
1636 strError = "Please provide absolute path";
1637
1638 return false;
1639 }
1640 // Root element
1641 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1642
1643 // Serialize in
1644 return pConfigurableDomains->serializeSettings(strFileName, false, _uiStructureChecksum, strError);
1645}
1646
1647bool CParameterMgr::exportDomainsBinary(const string& strFileName, string& strError)
1648{
1649 // check path is absolute
1650 if (strFileName[0] != '/') {
1651
1652 strError = "Please provide absolute path";
1653
1654 return false;
1655 }
Patrick Benavoli68a91282011-08-31 11:23:23 +02001656
Patrick Benavoli68a91282011-08-31 11:23:23 +02001657 // Root element
1658 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1659
1660 // Serialize out
1661 return pConfigurableDomains->serializeSettings(strFileName, true, _uiStructureChecksum, strError);
1662}
1663
1664// For tuning, check we're in tuning mode
1665bool CParameterMgr::checkTuningModeOn(string& strError) const
1666{
1667 // Tuning Mode on?
1668 if (!_bTuningModeIsOn) {
1669
1670 strError = "Tuning Mode must be on";
1671
1672 return false;
1673 }
1674 return true;
1675}
1676
Patrick Benavoli065264a2011-11-20 15:46:41 +01001677// Tuning mutex dynamic parameter handling
1678pthread_mutex_t* CParameterMgr::getBlackboardMutex()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001679{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001680 return &_blackboardMutex;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001681}
1682
Patrick Benavoli065264a2011-11-20 15:46:41 +01001683// Blackboard reference (dynamic parameter handling)
1684CParameterBlackboard* CParameterMgr::getParameterBlackboard()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001685{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001686 return _pMainParameterBlackboard;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001687}
1688
Patrick Benavoli68a91282011-08-31 11:23:23 +02001689// Dynamic creation library feeding
1690void CParameterMgr::feedElementLibraries()
1691{
1692 // Global Configuration handling
1693 CElementLibrary* pFrameworkConfigurationLibrary = new CElementLibrary;
1694
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001695 pFrameworkConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CParameterFrameworkConfiguration>("ParameterFrameworkConfiguration"));
1696 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationGroup>("SubsystemPluginFolders"));
1697 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("PluginFolderLocation"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001698 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("StructureDescriptionFileLocation"));
1699 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationGroup>("SettingsConfiguration"));
1700 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("ConfigurableDomainsFileLocation"));
1701 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("BinarySettingsFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001702
1703 _pElementLibrarySet->addElementLibrary(pFrameworkConfigurationLibrary);
1704
1705 // Parameter creation
1706 CElementLibrary* pParameterCreationLibrary = new CElementLibrary;
1707
1708 pParameterCreationLibrary->addElementBuilder(new CSubsystemElementBuilder(getSystemClass()->getSubsystemLibrary()));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001709 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CComponentType>("ComponentType"));
1710 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CComponentInstance>("Component"));
1711 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBitParameterType>("BitParameter"));
1712 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBitParameterBlockType>("BitParameterBlock"));
Patrick Benavoli1352ae52011-10-21 16:48:04 +02001713 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CStringParameterType>("StringParameter"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001714 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CParameterBlockType>("ParameterBlock"));
1715 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBooleanParameterType>("BooleanParameter"));
1716 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CIntegerParameterType>("IntegerParameter"));
Patrick Benavoliee65e6d2011-11-20 18:52:24 +01001717 pParameterCreationLibrary->addElementBuilder(new TElementBuilderTemplate<CLinearParameterAdaptation>("LinearAdaptation"));
Patrick Benavoli9fc3c0d2011-10-27 14:27:27 +02001718 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CEnumParameterType>("EnumParameter"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001719 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CFixedPointParameterType>("FixedPointParameter"));
1720 pParameterCreationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CXmlFileIncluderElement>("SubsystemInclude"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001721
1722 _pElementLibrarySet->addElementLibrary(pParameterCreationLibrary);
1723
1724 // Parameter Configuration Domains creation
1725 CElementLibrary* pParameterConfigurationLibrary = new CElementLibrary;
1726
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001727 pParameterConfigurationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CConfigurableDomain>("ConfigurableDomain"));
1728 pParameterConfigurationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CDomainConfiguration>("Configuration"));
1729 pParameterConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CCompoundRule>("CompoundRule"));
1730 pParameterConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CSelectionCriterionRule>("SelectionCriterionRule"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001731
1732 _pElementLibrarySet->addElementLibrary(pParameterConfigurationLibrary);
1733}
1734
1735// Remote Processor Server connection handling
1736bool CParameterMgr::handleRemoteProcessingInterface(string& strError)
1737{
1738 CAutoLog autoLog(this, "Handling remote processing interface");
1739
1740 // Start server if tuning allowed
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001741 if (getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001742
1743 log("Loading remote processor library");
1744
1745 // Load library
1746 void* lib_handle = dlopen("libremote-processor.so", RTLD_NOW);
1747
1748 if (!lib_handle) {
1749
1750 // Return error
1751 const char* pcError = dlerror();
1752
1753 if (pcError) {
1754
1755 strError = pcError;
1756 } else {
1757
1758 strError = "Unable to load libremote-processor.so library";
1759 }
1760
1761 return false;
1762 }
1763
1764 CreateRemoteProcessorServer pfnCreateRemoteProcessorServer = (CreateRemoteProcessorServer)dlsym(lib_handle, "createRemoteProcessorServer");
1765
1766 if (!pfnCreateRemoteProcessorServer) {
1767
1768 strError = "libremote-process.so does not contain createRemoteProcessorServer symbol.";
1769
1770 return false;
1771 }
1772
1773 // Create server
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001774 _pRemoteProcessorServer = pfnCreateRemoteProcessorServer(getConstFrameworkConfiguration()->getServerPort(), _pCommandHandler);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001775
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001776 log("Starting remote processor server on port %d", getConstFrameworkConfiguration()->getServerPort());
Patrick Benavoli68a91282011-08-31 11:23:23 +02001777 // Start
1778 if (!_pRemoteProcessorServer->start()) {
1779
1780 strError = "Unable to start remote processor server";
1781
1782 return false;
1783 }
1784 }
1785
1786 return true;
1787}
1788
1789// Back synchronization
1790CBackSynchronizer* CParameterMgr::createBackSynchronizer(string& strError) const
1791{
1792#ifdef SIMULATION
1793 // In simulation, back synchronization of the blackboard won't probably work
1794 // We need to ensure though the blackboard is initialized with valid data
1795 return new CSimulatedBackSynchronizer(getConstSystemClass(), strError, _pMainParameterBlackboard);
1796#else
1797 // Real back synchronizer from subsystems
1798 return new CHardwareBackSynchronizer(getConstSystemClass(), strError, _pMainParameterBlackboard);
1799#endif
1800}
1801
1802// Children typwise access
1803CParameterFrameworkConfiguration* CParameterMgr::getFrameworkConfiguration()
1804{
1805 return static_cast<CParameterFrameworkConfiguration*>(getChild(EFrameworkConfiguration));
1806}
1807
1808const CParameterFrameworkConfiguration* CParameterMgr::getConstFrameworkConfiguration()
1809{
1810 return getFrameworkConfiguration();
1811}
1812
1813CSelectionCriteria* CParameterMgr::getSelectionCriteria()
1814{
1815 return static_cast<CSelectionCriteria*>(getChild(ESelectionCriteria));
1816}
1817
1818const CSelectionCriteria* CParameterMgr::getConstSelectionCriteria()
1819{
1820 return static_cast<const CSelectionCriteria*>(getChild(ESelectionCriteria));
1821}
1822
1823CSystemClass* CParameterMgr::getSystemClass()
1824{
1825 return static_cast<CSystemClass*>(getChild(ESystemClass));
1826}
1827
1828const CSystemClass* CParameterMgr::getConstSystemClass() const
1829{
1830 return static_cast<const CSystemClass*>(getChild(ESystemClass));
1831}
1832
1833// Configurable Domains
1834CConfigurableDomains* CParameterMgr::getConfigurableDomains()
1835{
1836 return static_cast<CConfigurableDomains*>(getChild(EConfigurableDomains));
1837}
1838
1839const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains()
1840{
1841 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
1842}
1843
1844const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains() const
1845{
1846 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
1847}