blob: 1e1a5620fa5e158ec6167f1500dac418d1c0e26e [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 Benavoli68a91282011-08-31 11:23:23 +020079
80#define base CElement
81
82// Used for remote processor server creation
83typedef IRemoteProcessorServerInterface* (*CreateRemoteProcessorServer)(uint16_t uiPort, IRemoteCommandHandler* pCommandHandler);
84
85// Global configuration file name (fixed)
86const char* gacParameterFrameworkConfigurationFileName = "ParameterFrameworkConfiguration.xml";
87const char* gacSystemSchemasSubFolder = "Schemas";
88
89// Config File System looks normally like this:
90// ---------------------------------------------
Patrick Benavoli95ac0342011-11-07 20:32:51 +010091//├── <ParameterFrameworkConfiguration>.xml
Patrick Benavoli68a91282011-08-31 11:23:23 +020092//├── Schemas
93//│ └── *.xsd
94//├── Settings
95//│ └── <SystemClassName folder>*
96//│ ├── <ConfigurableDomains>.xml
97//│ └── <Settings>.bin?
98//└── Structure
99// └── <SystemClassName folder>*
100// ├── <SystemClassName>Class.xml
101// └── <Subsystem>.xml*
102// --------------------------------------------
103
104
105// Remote command parser array
Patrick Benavoli592ae562011-09-05 16:53:58 +0200106const CParameterMgr::SRemoteCommandParserItem CParameterMgr::gastRemoteCommandParserItems[] = {
Patrick Benavoli592ae562011-09-05 16:53:58 +0200107 /// Version
108 { "version", &CParameterMgr::versionCommandProcess, 0, "", "Show version" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200109 /// Status
110 { "status", &CParameterMgr::statusCommandProcess, 0, "", "Show current status" },
111 /// Tuning Mode
112 { "setTuningMode", &CParameterMgr::setTuningModeCommmandProcess, 1, "on|off*", "Turn on or off Tuning Mode" },
113 { "getTuningMode", &CParameterMgr::getTuningModeCommmandProcess, 0, "", "Show Tuning Mode" },
114 /// Value Space
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200115 { "setValueSpace", &CParameterMgr::setValueSpaceCommmandProcess, 1, "raw|real*", "Assigns Value Space used for parameter value interpretation" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200116 { "getValueSpace", &CParameterMgr::getValueSpaceCommmandProcess, 0, "", "Show Value Space" },
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200117 /// Output Raw Format
118 { "setOutputRawFormat", &CParameterMgr::setOutputRawFormatCommmandProcess, 1, "dec*|hex", "Assigns format used to output parameter values when in raw Value Space" },
119 { "getOutputRawFormat", &CParameterMgr::getOutputRawFormatCommmandProcess, 0, "", "Show Output Raw Format" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200120 /// Sync
121 { "setAutoSync", &CParameterMgr::setAutoSyncCommmandProcess, 1, "on*|off", "Turn on or off automatic synchronization to hardware while in Tuning Mode" },
122 { "getAutoSync", &CParameterMgr::getAutoSyncCommmandProcess, 0, "", "Show Auto Sync state" },
123 { "sync", &CParameterMgr::syncCommmandProcess, 0, "", "Synchronize current settings to hardware while in Tuning Mode and Auto Sync off" },
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200124 /// Criteria
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200125 { "listCriteria", &CParameterMgr::listCriteriaCommmandProcess, 0, "", "List selection criteria" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200126 /// Domains
127 { "listDomains", &CParameterMgr::listDomainsCommmandProcess, 0, "", "List configurable domains" },
128 { "createDomain", &CParameterMgr::createDomainCommmandProcess, 1, "<domain>", "Create new configurable domain" },
129 { "deleteDomain", &CParameterMgr::deleteDomainCommmandProcess, 1, "<domain>", "Delete configurable domain" },
130 { "renameDomain", &CParameterMgr::renameDomainCommmandProcess, 2, "<domain> <new name>", "Rename configurable domain" },
Patrick Benavoli63499d42011-10-24 18:50:03 +0200131 { "setSequenceAwareness", &CParameterMgr::setSequenceAwarenessCommmandProcess, 1, "<domain> true|false*", "Set configurable domain sequence awareness" },
132 { "getSequenceAwareness", &CParameterMgr::getSequenceAwarenessCommmandProcess, 1, "<domain>", "Get configurable domain sequence awareness" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200133 { "listDomainElements", &CParameterMgr::listDomainElementsCommmandProcess, 1, "<domain>", "List elements associated to configurable domain" },
134 { "addElement", &CParameterMgr::addElementCommmandProcess, 2, "<domain> <elem path>", "Associate element at given path to configurable domain" },
135 { "removeElement", &CParameterMgr::removeElementCommmandProcess, 2, "<domain> <elem path>", "Dissociate element at given path from configurable domain" },
136 { "splitDomain", &CParameterMgr::splitDomainCommmandProcess, 2, "<domain> <elem path>", "Split configurable domain at given associated element path" },
137 /// Configurations
138 { "listConfigurations", &CParameterMgr::listConfigurationsCommmandProcess, 1, "<domain>", "List domain configurations" },
139 { "createConfiguration", &CParameterMgr::createConfigurationCommmandProcess, 2, "<domain> <configuration>", "Create new domain configuration" },
140 { "deleteConfiguration", &CParameterMgr::deleteConfigurationCommmandProcess, 2, "<domain> <configuration>", "Delete domain configuration" },
141 { "renameConfiguration", &CParameterMgr::renameConfigurationCommmandProcess, 3, "<domain> <configuration> <new name>", "Rename domain configuration" },
142 { "saveConfiguration", &CParameterMgr::saveConfigurationCommmandProcess, 2, "<domain> <configuration>", "Save current settings into configuration" },
143 { "restoreConfiguration", &CParameterMgr::restoreConfigurationCommmandProcess, 2, "<domain> <configuration>", "Restore current settings from configuration" },
Patrick Benavoli63499d42011-10-24 18:50:03 +0200144 { "setElementSequence", &CParameterMgr::setElementSequenceCommmandProcess, 2, "<domain> <configuration> <elem path list>", "Set element application order for configuration" },
145 { "getElementSequence", &CParameterMgr::getElementSequenceCommmandProcess, 2, "<domain> <configuration>", "Get element application order for configuration" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200146 /// Elements/Parameters
147 { "listElements", &CParameterMgr::listElementsCommmandProcess, 1, "<elem path>|/", "List elements under element at given path or root" },
Patrick Benavoli592ae562011-09-05 16:53:58 +0200148 { "listParameters", &CParameterMgr::listParametersCommmandProcess, 1, "<elem path>|/", "List parameters under element at given path or root" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200149 { "dumpElement", &CParameterMgr::dumpElementCommmandProcess, 1, "<elem path>", "Dump structure and content of element at given path" },
150 { "getElementSize", &CParameterMgr::getElementSizeCommmandProcess, 1, "<elem path>", "Show size of element at given path" },
Patrick Benavoli2ecf9002011-08-31 11:23:24 +0200151 { "showProperties", &CParameterMgr::showPropertiesCommmandProcess, 1, "<elem path>", "Show properties of element at given path" },
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200152 { "getParameter", &CParameterMgr::getParameterCommmandProcess, 1, "<param path>", "Get value for parameter at given path" },
Patrick Benavoli2ecf9002011-08-31 11:23:24 +0200153 { "setParameter", &CParameterMgr::setParameterCommmandProcess, 2, "<param path> <value>", "Set value for parameter at given path" },
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200154 { "listBelongingDomains", &CParameterMgr::listBelongingDomainsCommmandProcess, 1, "<elem path>", "List domain(s) element at given path belongs to" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200155 { "listAssociatedDomains", &CParameterMgr::listAssociatedDomainsCommmandProcess, 1, "<elem path>", "List domain(s) element at given path is associated to" },
156 /// Browse
157 { "listAssociatedElements", &CParameterMgr::listAssociatedElementsCommmandProcess, 0, "", "List element sub-trees associated to at least one configurable domain" },
158 { "listConflictingElements", &CParameterMgr::listConflictingElementsCommmandProcess, 0, "", "List element sub-trees contained in more than one configurable domain" },
159 { "listRogueElements", &CParameterMgr::listRogueElementsCommmandProcess, 0, "", "List element sub-trees owned by no configurable domain" },
160 /// Settings Import/Export
161 { "exportDomainsXML", &CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess, 1, "<file path> ", "Export domains to XML file" },
162 { "importDomainsXML", &CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess, 1, "<file path>", "Import domains from XML file" },
163 { "exportDomainsWithSettingsXML", &CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess, 1, "<file path> ", "Export domains including settings to XML file" },
164 { "importDomainsWithSettingsXML", &CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess, 1, "<file path>", "Import domains including settings from XML file" },
165 { "exportSettings", &CParameterMgr::exportSettingsCommmandProcess, 1, "<file path>", "Export settings to binary file" },
166 { "importSettings", &CParameterMgr::importSettingsCommmandProcess, 1, "<file path>", "Import settings from binary file" }
167};
168// Remote command parsers array Size
Patrick Benavoli592ae562011-09-05 16:53:58 +0200169const uint32_t CParameterMgr::guiNbRemoteCommandParserItems = sizeof(gastRemoteCommandParserItems) / sizeof(gastRemoteCommandParserItems[0]);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200170
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100171CParameterMgr::CParameterMgr(const string& strConfigurationFilePath) :
Patrick Benavoli68a91282011-08-31 11:23:23 +0200172 _bTuningModeIsOn(false),
173 _bValueSpaceIsRaw(false),
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200174 _bOutputRawFormatIsHex(false),
Patrick Benavoli68a91282011-08-31 11:23:23 +0200175 _bAutoSyncOn(true),
176 _pMainParameterBlackboard(new CParameterBlackboard),
177 _pElementLibrarySet(new CElementLibrarySet),
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100178 _strXmlConfigurationFilePath(strConfigurationFilePath),
Patrick Benavoli68a91282011-08-31 11:23:23 +0200179 _uiStructureChecksum(0),
180 _pRemoteProcessorServer(NULL),
181 _uiMaxCommandUsageLength(0),
182 _pLogger(NULL),
183 _uiLogDepth(0)
184{
185 // Tuning Mode Mutex
Patrick Benavoli065264a2011-11-20 15:46:41 +0100186 bzero(&_blackboardMutex, sizeof(_blackboardMutex));
187 pthread_mutex_init(&_blackboardMutex, NULL);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200188
189 // Deal with children
190 addChild(new CParameterFrameworkConfiguration);
191 addChild(new CSelectionCriteria);
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100192 addChild(new CSystemClass);
193 addChild(new CConfigurableDomains);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200194
195 // Feed element library
196 feedElementLibraries();
Patrick Benavoli63499d42011-10-24 18:50:03 +0200197
198 _pCommandHandler = new CCommandHandler(this);
199
200 // Add command parsers
201 uint32_t uiRemoteCommandParserItem;
202
203 for (uiRemoteCommandParserItem = 0; uiRemoteCommandParserItem < guiNbRemoteCommandParserItems; uiRemoteCommandParserItem++) {
204
205 const SRemoteCommandParserItem* pRemoteCommandParserItem = &gastRemoteCommandParserItems[uiRemoteCommandParserItem];
206
207 _pCommandHandler->addCommandParser(pRemoteCommandParserItem->_pcCommandName,
208 pRemoteCommandParserItem->_pfnParser,
209 pRemoteCommandParserItem->_uiMinArgumentCount,
210 pRemoteCommandParserItem->_pcHelp,
211 pRemoteCommandParserItem->_pcDescription);
212 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100213
214 // Configuration file folder
215 uint32_t uiSlashPos = _strXmlConfigurationFilePath.rfind('/', -1);
216
217 assert(uiSlashPos != (uint32_t)-1);
218
219 _strXmlConfigurationFolderPath = _strXmlConfigurationFilePath.substr(0, uiSlashPos);
220
221 // Schema absolute folder location
222 _strSchemaFolderLocation = _strXmlConfigurationFolderPath + "/" + gacSystemSchemasSubFolder;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200223}
224
225CParameterMgr::~CParameterMgr()
226{
227 // Children
228 delete _pRemoteProcessorServer;
229 delete _pMainParameterBlackboard;
230 delete _pElementLibrarySet;
231
232 // Tuning Mode Mutex
Patrick Benavoli065264a2011-11-20 15:46:41 +0100233 pthread_mutex_destroy(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200234}
235
236string CParameterMgr::getKind() const
237{
238 return "ParameterMgr";
239}
240
241// Logging
242void CParameterMgr::setLogger(CParameterMgr::ILogger* pLogger)
243{
244 _pLogger = pLogger;
245}
246
247// Logging
248void CParameterMgr::doLog(const string& strLog) const
249{
250 if (_pLogger) {
251
252 // Nest
253 string strIndent;
254
255 // Level
256 uint32_t uiNbIndents = _uiLogDepth;
257
258 while (uiNbIndents--) {
259
260 strIndent += " ";
261 }
262
263 // Log
264 _pLogger->log(strIndent + strLog);
265 }
266}
267
268void CParameterMgr::nestLog() const
269{
Patrick Benavoli592ae562011-09-05 16:53:58 +0200270 _uiLogDepth++;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200271}
272
273void CParameterMgr::unnestLog() const
274{
Patrick Benavoli592ae562011-09-05 16:53:58 +0200275 _uiLogDepth--;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200276}
277
Patrick Benavoli63499d42011-10-24 18:50:03 +0200278// Version
279string CParameterMgr::getVersion() const
280{
281 string strVersion;
282
283 // Major
284 strVersion = toString(guiEditionMajor) + ".";
285 // Minor
286 strVersion += toString(guiEditionMinor) + ".";
287 // Revision
288 strVersion += toString(guiRevision);
289
290 return strVersion;
291}
292
Patrick Benavoli68a91282011-08-31 11:23:23 +0200293bool CParameterMgr::load(string& strError)
294{
295 CAutoLog autoLog(this, "Loading");
296
297 // Load Framework configuration
298 if (!loadFrameworkConfiguration(strError)) {
299
300 return false;
301 }
302
303 // Load subsystems
304 if (!getSystemClass()->loadSubsystems(strError, _astrPluginFolderPaths)) {
305
306 return false;
307 }
308
309 // Load structure
310 if (!loadStructure(strError)) {
311
312 return false;
313 }
314
315 // Load settings
316 if (!loadSettings(strError)) {
317
318 return false;
319 }
320
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200321 // Back synchronization for areas in parameter blackboard not covered by any domain
322 CBackSynchronizer* pBackSynchronizer = createBackSynchronizer(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200323
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200324 log("Main blackboard back synchronization");
325
326 // Back-synchronize
327 if (!pBackSynchronizer->sync()) {
328 // Get rid of back synchronizer
329 delete pBackSynchronizer;
330
331 strError = "Main blackboard back synchronization failed: " + strError;
332
333 return false;
334 }
335 // Get rif of back synchronizer
336 delete pBackSynchronizer;
337
338 // We're done loading the settings and back synchronizing
339 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
340
341 // We need to ensure all domains are valid
342 pConfigurableDomains->validate(_pMainParameterBlackboard);
343
344 // Ensure application of currently selected configurations
345 // Force-apply configurations
346 if (!pConfigurableDomains->apply(_pMainParameterBlackboard, true, strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200347
348 return false;
349 }
350
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200351 // Start remote processor server if appropriate
352 return handleRemoteProcessingInterface(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200353}
354
355bool CParameterMgr::loadFrameworkConfiguration(string& strError)
356{
357 CAutoLog autoLog(this, "Loading framework configuration");
358
Patrick Benavoli68a91282011-08-31 11:23:23 +0200359 // Parse Structure XML file
360 CXmlElementSerializingContext elementSerializingContext(strError);
361
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100362 if (!xmlParse(elementSerializingContext, getFrameworkConfiguration(), _strXmlConfigurationFilePath, _strXmlConfigurationFolderPath, EFrameworkConfigurationLibrary)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200363
364 return false;
365 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100366 // Set class name to system class and configurable domains
367 getSystemClass()->setName(getConstFrameworkConfiguration()->getSystemClassName());
368 getConfigurableDomains()->setName(getConstFrameworkConfiguration()->getSystemClassName());
369
Patrick Benavoli68a91282011-08-31 11:23:23 +0200370 // Get subsystem plugins folders element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100371 const CFrameworkConfigurationGroup* pSubsystemPluginFolders = static_cast<const CFrameworkConfigurationGroup*>(getConstFrameworkConfiguration()->findChild("SubsystemPluginFolders"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200372
373 if (!pSubsystemPluginFolders) {
374
375 strError = "Parameter Framework Configuration: couldn't find SubsystemPluginFolders element";
376
377 return false;
378 }
379 // Get plugin locations
380 uint32_t uiPluginFolderLocation;
381 uint32_t uiNbPluginFolderLocations = pSubsystemPluginFolders->getNbChildren();
382
383 if (!uiNbPluginFolderLocations) {
384
385 strError = "Parameter Framework Configuration: couldn't find any PluginFolderLocation element";
386
387 return false;
388 }
389
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100390 // Collect plugin paths
Patrick Benavoli68a91282011-08-31 11:23:23 +0200391 for (uiPluginFolderLocation = 0; uiPluginFolderLocation < uiNbPluginFolderLocations; uiPluginFolderLocation++) {
392
393 const CFrameworkConfigurationLocation* pSubsystemPluginLocation = static_cast<const CFrameworkConfigurationLocation*>(pSubsystemPluginFolders->getChild(uiPluginFolderLocation));
394
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100395 _astrPluginFolderPaths.push_back(pSubsystemPluginLocation->getFilePath(_strXmlConfigurationFilePath));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200396 }
397
Patrick Benavoli68a91282011-08-31 11:23:23 +0200398 // Log tuning availability
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100399 log("Tuning %s", getConstFrameworkConfiguration()->isTuningAllowed() ? "allowed" : "prohibited");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200400
401 return true;
402}
403
404bool CParameterMgr::loadStructure(string& strError)
405{
406 // Retrieve system to load structure to
407 CSystemClass* pSystemClass = getSystemClass();
408
409 CAutoLog autoLog(this, "Loading " + pSystemClass->getName() + " system class structure");
410
411 // Get structure description element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100412 const CFrameworkConfigurationLocation* pStructureDescriptionFileLocation = static_cast<const CFrameworkConfigurationLocation*>(getConstFrameworkConfiguration()->findChildOfKind("StructureDescriptionFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200413
414 if (!pStructureDescriptionFileLocation) {
415
416 strError = "No StructureDescriptionFileLocation element found for SystemClass " + pSystemClass->getName();
417
418 return false;
419 }
420
421 // Get Xml structure folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100422 string strXmlStructureFolder = pStructureDescriptionFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200423
424 // Get Xml structure file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100425 string strXmlStructureFilePath = pStructureDescriptionFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200426
427 // Parse Structure XML file
428 CXmlParameterSerializingContext parameterBuildContext(strError);
429
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200430 log("Importing system structure from file %s", strXmlStructureFilePath.c_str());
431
Patrick Benavoli68a91282011-08-31 11:23:23 +0200432 if (!xmlParse(parameterBuildContext, pSystemClass, strXmlStructureFilePath, strXmlStructureFolder, EParameterCreationLibrary)) {
433
434 return false;
435 }
436
437 // Initialize offsets
438 pSystemClass->setOffset(0);
439
440 // Initialize main blackboard's size
441 _pMainParameterBlackboard->setSize(pSystemClass->getFootPrint());
442
443 return true;
444}
445
446bool CParameterMgr::loadSettings(string& strError)
447{
448 CAutoLog autoLog(this, "Loading settings");
449
450 // Get settings configuration element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100451 const CFrameworkConfigurationGroup* pParameterConfigurationGroup = static_cast<const CFrameworkConfigurationGroup*>(getConstFrameworkConfiguration()->findChildOfKind("SettingsConfiguration"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200452
453 if (!pParameterConfigurationGroup) {
454
455 // No settings to load
456
457 return true;
458 }
459 // Get binary settings file location
460 const CFrameworkConfigurationLocation* pBinarySettingsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("BinarySettingsFileLocation"));
461
462 string strXmlBinarySettingsFilePath;
463
464 if (pBinarySettingsFileLocation) {
465
466 // Get Xml binary settings file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100467 strXmlBinarySettingsFilePath = pBinarySettingsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200468 }
469
470 // Get configurable domains element
471 const CFrameworkConfigurationLocation* pConfigurableDomainsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("ConfigurableDomainsFileLocation"));
472
473 if (!pConfigurableDomainsFileLocation) {
474
475 strError = "No ConfigurableDomainsFileLocation element found for SystemClass " + getSystemClass()->getName();
476
477 return false;
478 }
479 // Get destination root element
480 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
481
482 // Get Xml configuration domains file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100483 string strXmlConfigurationDomainsFilePath = pConfigurableDomainsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200484
485 // Get Xml configuration domains folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100486 string strXmlConfigurationDomainsFolder = pConfigurableDomainsFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200487
488 // Parse configuration domains XML file (ask to read settings from XML file if they are not provided as binary)
489 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, !pBinarySettingsFileLocation);
490
491 // Selection criteria definition for rule creation
492 xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
493
Patrick Benavoli63499d42011-10-24 18:50:03 +0200494 // Auto validation of configurations if no binary settings provided
495 xmlDomainSerializingContext.setAutoValidationRequired(!pBinarySettingsFileLocation);
496
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200497 log("Importing configurable domains from file %s %s settings", strXmlConfigurationDomainsFilePath.c_str(), pBinarySettingsFileLocation ? "without" : "with");
498
Patrick Benavoli68a91282011-08-31 11:23:23 +0200499 // Do parse
500 if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strXmlConfigurationDomainsFilePath, strXmlConfigurationDomainsFolder, EParameterConfigurationLibrary, "SystemClassName")) {
501
502 return false;
503 }
504 // We have loaded the whole system structure, compute checksum
505 const CSystemClass* pSystemClass = getConstSystemClass();
506 _uiStructureChecksum = pSystemClass->computeStructureChecksum() + getConfigurableDomains()->computeStructureChecksum() + getSelectionCriteria()->computeStructureChecksum();
507
508 // Load binary settings if any provided
509 if (pBinarySettingsFileLocation && !pConfigurableDomains->serializeSettings(strXmlBinarySettingsFilePath, false, _uiStructureChecksum, strError)) {
510
511 return false;
512 }
513
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200514 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200515}
516
517// XML parsing
518bool CParameterMgr::xmlParse(CXmlElementSerializingContext& elementSerializingContext, CElement* pRootElement, const string& strXmlFilePath, const string& strXmlFolder, CParameterMgr::ElementLibrary eElementLibrary, const string& strNameAttrituteName)
519{
520 // Init serializing context
521 elementSerializingContext.set(_pElementLibrarySet->getElementLibrary(eElementLibrary), strXmlFolder, _strSchemaFolderLocation);
522
523 // Get Schema file associated to root element
524 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pRootElement->getKind() + ".xsd";
525
526 // Parse Structure XML file
527 CXmlParser parser(strXmlFilePath, strXmlSchemaFilePath, pRootElement->getKind(), elementSerializingContext);
528
529 if (!parser.open()) {
530
531 return false;
532 }
533
534 // Check Root element name attribute (if any)
535 string strRootElementName = parser.getRootElementAttributeString(strNameAttrituteName);
536
537 if (!strRootElementName.empty() && strRootElementName != pRootElement->getName()) {
538
539 elementSerializingContext.setError("Error: Wrong XML structure file " + strXmlFilePath);
540 elementSerializingContext.appendLineToError(pRootElement->getKind() + " element " + pRootElement->getName() + " mismatches expected " + pRootElement->getKind() + " type " + pRootElement->getName());
541
542 return false;
543 }
544
545 // Start clean
546 pRootElement->clean();
547
548 // Parse
549 if (!parser.parse(pRootElement)) {
550
551 // Cleanup
552 pRootElement->clean();
553
554 return false;
555 }
556
557 // Close parser
558 if (!parser.close()) {
559
560 return false;
561 }
562
563 return true;
564}
565
566// Init
567bool CParameterMgr::init(string& strError)
568{
569 return base::init(strError);
570}
571
572// Selection criteria interface
573CSelectionCriterionType* CParameterMgr::createSelectionCriterionType(bool bIsInclusive)
574{
575 // Propagate
576 return getSelectionCriteria()->createSelectionCriterionType(bIsInclusive);
577}
578
579CSelectionCriterion* CParameterMgr::createSelectionCriterion(const string& strName, const CSelectionCriterionType* pSelectionCriterionType)
580{
581 // Propagate
582 return getSelectionCriteria()->createSelectionCriterion(strName, pSelectionCriterionType);
583}
584
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200585// Selection criterion retrieval
586CSelectionCriterion* CParameterMgr::getSelectionCriterion(const string& strName)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200587{
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200588 // Propagate
589 return getSelectionCriteria()->getSelectionCriterion(strName);
590}
591
592// Selection criteria changed event
593bool CParameterMgr::applyConfigurations(string& strError)
594{
595 CAutoLog autoLog(this, "Configuration application request");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200596
597 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +0100598 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200599
600 if (!_bTuningModeIsOn) {
601
602 // Apply configuration(s)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200603 if (!getConfigurableDomains()->apply(_pMainParameterBlackboard, false, strError)) {
604
605 log("Failed to apply configurations!");
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200606
607 return false;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200608 }
609 }
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200610
611 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200612}
613
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200614// Dynamic parameter handling
Patrick Benavoli065264a2011-11-20 15:46:41 +0100615CParameterHandle* CParameterMgr::createParameterHandle(const string& strPath, string& strError)
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200616{
Patrick Benavoli065264a2011-11-20 15:46:41 +0100617 CPathNavigator pathNavigator(strPath);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200618
Patrick Benavoli065264a2011-11-20 15:46:41 +0100619 // Nagivate through system class
620 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
621
622 return false;
623 }
624
625 // Find element
626 const CElement* pElement = getConstSystemClass()->findDescendant(pathNavigator);
627
628 if (!pElement) {
629
630 strError = "Path not found";
631
632 return false;
633 }
634
635 // Check found element is a parameter
636 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pElement);
637
638 if (!pConfigurableElement->isParameter()) {
639
640 // Element is not parameter
641 strError = "Not a parameter";
642
643 return false;
644 }
645
646 // Convert as parameter and return new handle
647 return new CParameterHandle(static_cast<const CBaseParameter*>(pElement), this);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200648}
649
Patrick Benavoli68a91282011-08-31 11:23:23 +0200650/////////////////// Remote command parsers
Patrick Benavoli592ae562011-09-05 16:53:58 +0200651/// Version
Patrick Benavoli63499d42011-10-24 18:50:03 +0200652CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::versionCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli592ae562011-09-05 16:53:58 +0200653{
654 (void)remoteCommand;
655
Patrick Benavoli63499d42011-10-24 18:50:03 +0200656 // Show version
657 strResult = getVersion();
Patrick Benavoli592ae562011-09-05 16:53:58 +0200658
Patrick Benavoli63499d42011-10-24 18:50:03 +0200659 return CCommandHandler::ESucceeded;
Patrick Benavoli592ae562011-09-05 16:53:58 +0200660}
661
Patrick Benavoli68a91282011-08-31 11:23:23 +0200662/// Status
Patrick Benavoli63499d42011-10-24 18:50:03 +0200663CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::statusCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200664{
665 (void)remoteCommand;
666 // System class
667 const CSystemClass* pSystemClass = getSystemClass();
668
Patrick Benavoli68a91282011-08-31 11:23:23 +0200669 // Show status
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200670 /// General section
671 appendTitle(strResult, "General:");
672 // System class
Patrick Benavoli68a91282011-08-31 11:23:23 +0200673 strResult += "System Class: ";
674 strResult += pSystemClass->getName();
675 strResult += "\n";
676
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200677 // Tuning mode
Patrick Benavoli68a91282011-08-31 11:23:23 +0200678 strResult += "Tuning Mode: ";
679 strResult += tuningModeOn() ? "on" : "off";
680 strResult += "\n";
681
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200682 // Value space
Patrick Benavoli68a91282011-08-31 11:23:23 +0200683 strResult += "Value Space: ";
684 strResult += valueSpaceIsRaw() ? "raw" : "real";
685 strResult += "\n";
686
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200687 // Output raw format
688 strResult += "Output Raw Format: ";
689 strResult += outputRawFormatIsHex() ? "hex" : "dec";
690 strResult += "\n";
691
692 // Auto Sync
Patrick Benavoli68a91282011-08-31 11:23:23 +0200693 strResult += "Auto Sync: ";
694 strResult += autoSyncOn() ? "on" : "off";
695 strResult += "\n";
696
697 /// Subsystem list
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200698 appendTitle(strResult, "Subsystems:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200699 string strSubsystemList;
700 pSystemClass->listChildrenPaths(strSubsystemList);
701 strResult += strSubsystemList;
702
703 /// Last applied configurations
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200704 appendTitle(strResult, "Last applied configurations:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200705 string strLastAppliedConfigurations;
706 getConfigurableDomains()->listLastAppliedConfigurations(strLastAppliedConfigurations);
707 strResult += strLastAppliedConfigurations;
708
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200709 /// Criteria states
710 appendTitle(strResult, "Selection criteria:");
711 string strSelectionCriteria;
712 getSelectionCriteria()->listSelectionCriteria(strSelectionCriteria, false);
713 strResult += strSelectionCriteria;
714
Patrick Benavoli63499d42011-10-24 18:50:03 +0200715 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200716}
717
718/// Tuning Mode
Patrick Benavoli63499d42011-10-24 18:50:03 +0200719CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200720{
721 if (remoteCommand.getArgument(0) == "on") {
722
723 if (setTuningMode(true, strResult)) {
724
Patrick Benavoli63499d42011-10-24 18:50:03 +0200725 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200726 }
727 } else if (remoteCommand.getArgument(0) == "off") {
728
729 if (setTuningMode(false, strResult)) {
730
Patrick Benavoli63499d42011-10-24 18:50:03 +0200731 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200732 }
733 } else {
734 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200735 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200736 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200737 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200738}
739
Patrick Benavoli63499d42011-10-24 18:50:03 +0200740CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200741{
742 (void)remoteCommand;
743
744 strResult = tuningModeOn() ? "on" : "off";
745
Patrick Benavoli63499d42011-10-24 18:50:03 +0200746 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200747}
748
749/// Value Space
Patrick Benavoli63499d42011-10-24 18:50:03 +0200750CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200751{
752 (void)strResult;
753
754 if (remoteCommand.getArgument(0) == "raw") {
755
756 setValueSpace(true);
757
Patrick Benavoli63499d42011-10-24 18:50:03 +0200758 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200759
760 } else if (remoteCommand.getArgument(0) == "real") {
761
762 setValueSpace(false);
763
Patrick Benavoli63499d42011-10-24 18:50:03 +0200764 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200765
766 } else {
767 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200768 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200769 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200770 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200771}
772
Patrick Benavoli63499d42011-10-24 18:50:03 +0200773CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200774{
775 (void)remoteCommand;
776
777 strResult = valueSpaceIsRaw() ? "raw" : "real";
778
Patrick Benavoli63499d42011-10-24 18:50:03 +0200779 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200780}
781
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200782/// Output Raw Format
Patrick Benavoli63499d42011-10-24 18:50:03 +0200783CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200784{
785 (void)strResult;
786
787 if (remoteCommand.getArgument(0) == "hex") {
788
789 setOutputRawFormat(true);
790
Patrick Benavoli63499d42011-10-24 18:50:03 +0200791 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200792
793 } else if (remoteCommand.getArgument(0) == "dec") {
794
795 setOutputRawFormat(false);
796
Patrick Benavoli63499d42011-10-24 18:50:03 +0200797 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200798
799 } else {
800 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200801 return CCommandHandler::EShowUsage;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200802 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200803 return CCommandHandler::EFailed;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200804}
805
Patrick Benavoli63499d42011-10-24 18:50:03 +0200806CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200807{
808 (void)remoteCommand;
809
810 strResult = outputRawFormatIsHex() ? "hex" : "dec";
811
Patrick Benavoli63499d42011-10-24 18:50:03 +0200812 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200813}
814
Patrick Benavoli68a91282011-08-31 11:23:23 +0200815/// Sync
Patrick Benavoli63499d42011-10-24 18:50:03 +0200816CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200817{
818 if (remoteCommand.getArgument(0) == "on") {
819
820 if (setAutoSync(true, strResult)) {
821
Patrick Benavoli63499d42011-10-24 18:50:03 +0200822 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200823 }
824 } else if (remoteCommand.getArgument(0) == "off") {
825
826 if (setAutoSync(false, strResult)) {
827
Patrick Benavoli63499d42011-10-24 18:50:03 +0200828 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200829 }
830 } else {
831 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200832 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200833 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200834 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200835}
836
Patrick Benavoli63499d42011-10-24 18:50:03 +0200837CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200838{
839 (void)remoteCommand;
840
841 strResult = autoSyncOn() ? "on" : "off";
842
Patrick Benavoli63499d42011-10-24 18:50:03 +0200843 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200844}
845
Patrick Benavoli63499d42011-10-24 18:50:03 +0200846CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::syncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200847{
848 (void)remoteCommand;
849
Patrick Benavoli63499d42011-10-24 18:50:03 +0200850 return sync(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200851}
852
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200853/// Criteria
Patrick Benavoli63499d42011-10-24 18:50:03 +0200854CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listCriteriaCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200855{
856 (void)remoteCommand;
857
858 getSelectionCriteria()->listSelectionCriteria(strResult, true);
859
Patrick Benavoli63499d42011-10-24 18:50:03 +0200860 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200861}
Patrick Benavoli68a91282011-08-31 11:23:23 +0200862
863/// Domains
Patrick Benavoli63499d42011-10-24 18:50:03 +0200864CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200865{
866 (void)remoteCommand;
867
Patrick Benavoli63499d42011-10-24 18:50:03 +0200868 getConfigurableDomains()->listDomains(strResult);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200869
Patrick Benavoli63499d42011-10-24 18:50:03 +0200870 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200871}
872
Patrick Benavoli63499d42011-10-24 18:50:03 +0200873CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200874{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200875 return createDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200876}
877
Patrick Benavoli63499d42011-10-24 18:50:03 +0200878CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200879{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200880 return deleteDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200881}
882
Patrick Benavoli63499d42011-10-24 18:50:03 +0200883CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200884{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200885 return getConfigurableDomains()->renameDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200886}
887
Patrick Benavoli63499d42011-10-24 18:50:03 +0200888CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200889{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200890 // Check tuning mode
891 if (!checkTuningModeOn(strResult)) {
892
893 return CCommandHandler::EFailed;
894 }
895
896 // Set property
897 bool bSequenceAware;
898
899 if (remoteCommand.getArgument(1) == "true") {
900
901 bSequenceAware = true;
902
903 } else if (remoteCommand.getArgument(1) == "false") {
904
905 bSequenceAware = false;
906
907 } else {
908 // Show usage
909 return CCommandHandler::EShowUsage;
910 }
911
912 return getConfigurableDomains()->setSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200913}
914
Patrick Benavoli63499d42011-10-24 18:50:03 +0200915CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200916{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200917 // Get property
918 bool bSequenceAware;
919
920 if (!getConfigurableDomains()->getSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult)) {
921
922 return CCommandHandler::EFailed;
923 }
924
925 strResult = bSequenceAware ? "true" : "false";
926
927 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200928}
929
Patrick Benavoli63499d42011-10-24 18:50:03 +0200930CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200931{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200932 return getConfigurableDomains()->listDomainElements(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200933}
934
Patrick Benavoli63499d42011-10-24 18:50:03 +0200935CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::addElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200936{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200937 return addConfigurableElementToDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
938}
939
940CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::removeElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
941{
942 return removeConfigurableElementFromDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
943}
944
945CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::splitDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
946{
947 return split(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200948}
949
950/// Configurations
Patrick Benavoli63499d42011-10-24 18:50:03 +0200951CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConfigurationsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200952{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200953 return getConfigurableDomains()->listConfigurations(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200954}
955
Patrick Benavoli63499d42011-10-24 18:50:03 +0200956CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200957{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200958 return createConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200959}
960
Patrick Benavoli63499d42011-10-24 18:50:03 +0200961CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200962{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200963 return deleteConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200964}
965
Patrick Benavoli63499d42011-10-24 18:50:03 +0200966CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200967{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200968 return getConfigurableDomains()->renameConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200969}
970
Patrick Benavoli63499d42011-10-24 18:50:03 +0200971CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::saveConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200972{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200973 return saveConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200974}
975
Patrick Benavoli63499d42011-10-24 18:50:03 +0200976CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::restoreConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200977{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200978 return restoreConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
979}
980
981CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
982{
983 // Check tuning mode
984 if (!checkTuningModeOn(strResult)) {
985
986 return CCommandHandler::EFailed;
987 }
988
989 // Build configurable element path list
990 vector<string> astrNewElementSequence;
991
992 uint32_t uiArgument;
993
994 for (uiArgument = 2; uiArgument < remoteCommand.getArgumentCount(); uiArgument++) {
995
996 astrNewElementSequence.push_back(remoteCommand.getArgument(uiArgument));
997 }
998
999 // Delegate to configurable domains
1000 return getConfigurableDomains()->setElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), astrNewElementSequence, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1001}
1002
1003CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1004{
1005 // Delegate to configurable domains
1006 return getConfigurableDomains()->getElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001007}
1008
1009/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001010CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001011{
1012 CElementLocator elementLocator(getSystemClass(), false);
1013
1014 CElement* pLocatedElement = NULL;
1015
1016 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1017
Patrick Benavoli63499d42011-10-24 18:50:03 +02001018 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001019 }
1020
1021 strResult = string("\n");
1022
1023 if (!pLocatedElement) {
1024
1025 // List from root folder
1026
1027 // Return system class qualified name
1028 pLocatedElement = getSystemClass();
1029 }
1030
1031 // Return sub-elements
1032 strResult += pLocatedElement->listQualifiedPaths(false);
1033
Patrick Benavoli63499d42011-10-24 18:50:03 +02001034 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001035}
1036
1037/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001038CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listParametersCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001039{
1040 CElementLocator elementLocator(getSystemClass(), false);
1041
1042 CElement* pLocatedElement = NULL;
1043
1044 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1045
Patrick Benavoli63499d42011-10-24 18:50:03 +02001046 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001047 }
1048
1049 strResult = string("\n");
1050
1051 if (!pLocatedElement) {
1052
1053 // List from root folder
1054
1055 // Return system class qualified name
1056 pLocatedElement = getSystemClass();
1057 }
1058
1059 // Return sub-elements
1060 strResult += pLocatedElement->listQualifiedPaths(true);
1061
Patrick Benavoli63499d42011-10-24 18:50:03 +02001062 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001063}
1064
Patrick Benavoli63499d42011-10-24 18:50:03 +02001065CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001066{
1067 CElementLocator elementLocator(getSystemClass());
1068
1069 CElement* pLocatedElement = NULL;
1070
1071 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1072
Patrick Benavoli63499d42011-10-24 18:50:03 +02001073 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001074 }
1075
1076 string strError;
1077
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001078 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001079
1080 // Dump elements
1081 pLocatedElement->dumpContent(strResult, parameterAccessContext);
1082
Patrick Benavoli63499d42011-10-24 18:50:03 +02001083 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001084}
1085
Patrick Benavoli63499d42011-10-24 18:50:03 +02001086CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSizeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001087{
1088 CElementLocator elementLocator(getSystemClass());
1089
1090 CElement* pLocatedElement = NULL;
1091
1092 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1093
Patrick Benavoli63499d42011-10-24 18:50:03 +02001094 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001095 }
1096
1097 // Converted to actual sizable element
1098 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1099
1100 // Get size as string
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001101 strResult = pConfigurableElement->getFootprintAsString();
Patrick Benavoli68a91282011-08-31 11:23:23 +02001102
Patrick Benavoli63499d42011-10-24 18:50:03 +02001103 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001104}
1105
Patrick Benavoli63499d42011-10-24 18:50:03 +02001106CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showPropertiesCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001107{
1108 CElementLocator elementLocator(getSystemClass());
1109
1110 CElement* pLocatedElement = NULL;
1111
1112 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1113
Patrick Benavoli63499d42011-10-24 18:50:03 +02001114 return CCommandHandler::EFailed;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001115 }
1116
1117 // Convert element
1118 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1119
1120 // Return element properties
1121 pConfigurableElement->showProperties(strResult);
1122
Patrick Benavoli63499d42011-10-24 18:50:03 +02001123 return CCommandHandler::ESucceeded;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001124}
1125
Patrick Benavoli63499d42011-10-24 18:50:03 +02001126CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001127{
1128 string strValue;
1129
Patrick Benavoli065264a2011-11-20 15:46:41 +01001130 if (!accessValue(remoteCommand.getArgument(0), strValue, false, strResult)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001131
Patrick Benavoli63499d42011-10-24 18:50:03 +02001132 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001133 }
1134 // Succeeded
1135 strResult = strValue;
1136
Patrick Benavoli63499d42011-10-24 18:50:03 +02001137 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001138}
1139
Patrick Benavoli63499d42011-10-24 18:50:03 +02001140CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001141{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001142 // Check tuning mode
1143 if (!checkTuningModeOn(strResult)) {
1144
1145 return CCommandHandler::EFailed;
1146 }
1147 // Get value to set
1148 string strValue = remoteCommand.packArguments(1, remoteCommand.getArgumentCount() - 1);
1149
1150 return accessValue(remoteCommand.getArgument(0), strValue, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001151}
1152
Patrick Benavoli63499d42011-10-24 18:50:03 +02001153CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listBelongingDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001154{
1155 CElementLocator elementLocator(getSystemClass());
1156
1157 CElement* pLocatedElement = NULL;
1158
1159 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1160
Patrick Benavoli63499d42011-10-24 18:50:03 +02001161 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001162 }
1163
1164 // Convert element
1165 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1166
1167 // Return element belonging domains
1168 pConfigurableElement->listBelongingDomains(strResult);
1169
Patrick Benavoli63499d42011-10-24 18:50:03 +02001170 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001171}
1172
Patrick Benavoli63499d42011-10-24 18:50:03 +02001173CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001174{
1175 CElementLocator elementLocator(getSystemClass());
1176
1177 CElement* pLocatedElement = NULL;
1178
1179 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1180
Patrick Benavoli63499d42011-10-24 18:50:03 +02001181 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001182 }
1183
1184 // Convert element
1185 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1186
1187 // Return element belonging domains
1188 pConfigurableElement->listAssociatedDomains(strResult);
1189
Patrick Benavoli63499d42011-10-24 18:50:03 +02001190 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001191}
1192
Patrick Benavoli63499d42011-10-24 18:50:03 +02001193CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001194{
1195 (void)remoteCommand;
1196
1197 getConfigurableDomains()->listAssociatedElements(strResult);
1198
Patrick Benavoli63499d42011-10-24 18:50:03 +02001199 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001200}
1201
Patrick Benavoli63499d42011-10-24 18:50:03 +02001202CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConflictingElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001203{
1204 (void)remoteCommand;
1205
1206 getConfigurableDomains()->listConflictingElements(strResult);
1207
Patrick Benavoli63499d42011-10-24 18:50:03 +02001208 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001209}
1210
Patrick Benavoli63499d42011-10-24 18:50:03 +02001211CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listRogueElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001212{
1213 (void)remoteCommand;
1214
1215 getSystemClass()->listRogueElements(strResult);
1216
Patrick Benavoli63499d42011-10-24 18:50:03 +02001217 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001218}
1219
1220/// Settings Import/Export
Patrick Benavoli63499d42011-10-24 18:50:03 +02001221CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001222{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001223 return exportDomainsXml(remoteCommand.getArgument(0), false, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001224}
1225
Patrick Benavoli63499d42011-10-24 18:50:03 +02001226CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001227{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001228 return importDomainsXml(remoteCommand.getArgument(0), false, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001229}
1230
Patrick Benavoli63499d42011-10-24 18:50:03 +02001231CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001232{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001233 return exportDomainsXml(remoteCommand.getArgument(0), true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001234}
1235
Patrick Benavoli63499d42011-10-24 18:50:03 +02001236CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001237{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001238 return importDomainsXml(remoteCommand.getArgument(0), true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001239}
1240
Patrick Benavoli63499d42011-10-24 18:50:03 +02001241CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001242{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001243 return exportDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001244}
1245
Patrick Benavoli63499d42011-10-24 18:50:03 +02001246CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001247{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001248 return importDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001249}
1250
1251// User set/get parameters
Patrick Benavoli065264a2011-11-20 15:46:41 +01001252bool CParameterMgr::accessValue(const string& strPath, string& strValue, bool bSet, string& strError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001253{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001254 // Lock state
1255 CAutoLock autoLock(&_blackboardMutex);
1256
1257 CPathNavigator pathNavigator(strPath);
1258
1259 // Nagivate through system class
1260 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001261
1262 return false;
1263 }
1264
Patrick Benavoli065264a2011-11-20 15:46:41 +01001265 // Define context
1266 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001267
Patrick Benavoli065264a2011-11-20 15:46:41 +01001268 // Do the get
1269 return getConstSystemClass()->accessValue(pathNavigator, strValue, bSet, parameterAccessContext);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001270}
1271
1272// Tuning mode
1273bool CParameterMgr::setTuningMode(bool bOn, string& strError)
1274{
1275 // Tuning allowed?
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001276 if (bOn && !getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001277
1278 strError = "Tuning prohibited";
1279
1280 return false;
1281 }
1282 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +01001283 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001284
1285 // Warn domains about exiting tuning mode
1286 if (!bOn && _bTuningModeIsOn) {
1287
1288 // Ensure application of currently selected configurations
Patrick Benavoli1387bda2011-08-31 11:23:24 +02001289 // Force-apply configurations
Patrick Benavoli68a91282011-08-31 11:23:23 +02001290 if (!getConfigurableDomains()->apply(_pMainParameterBlackboard, true, strError)) {
1291
1292 return false;
1293 }
1294 // Turn auto sync back on
1295 _bAutoSyncOn = true;
1296 }
1297
1298 // Store
1299 _bTuningModeIsOn = bOn;
1300
Patrick Benavoli68a91282011-08-31 11:23:23 +02001301 return true;
1302}
1303
1304bool CParameterMgr::tuningModeOn() const
1305{
1306 return _bTuningModeIsOn;
1307}
1308
1309// Current value space for user set/get value interpretation
1310void CParameterMgr::setValueSpace(bool bIsRaw)
1311{
1312 _bValueSpaceIsRaw = bIsRaw;
1313}
1314
1315bool CParameterMgr::valueSpaceIsRaw()
1316{
1317 return _bValueSpaceIsRaw;
1318}
1319
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001320// Current Output Raw Format for user get value interpretation
1321void CParameterMgr::setOutputRawFormat(bool bIsHex)
1322{
1323 _bOutputRawFormatIsHex = bIsHex;
1324}
1325
1326bool CParameterMgr::outputRawFormatIsHex()
1327{
1328 return _bOutputRawFormatIsHex;
1329}
1330
Patrick Benavoli68a91282011-08-31 11:23:23 +02001331/// Sync
1332// Automatic hardware synchronization control (during tuning session)
1333bool CParameterMgr::setAutoSync(bool bAutoSyncOn, string& strError)
1334{
1335 // Check tuning mode
1336 if (!checkTuningModeOn(strError)) {
1337
1338 return false;
1339 }
1340 // Warn domains about turning auto sync back on
1341 if (bAutoSyncOn && !_bAutoSyncOn) {
1342
Patrick Benavoli592ae562011-09-05 16:53:58 +02001343 // Do the synchronization at system class level (could be optimized by keeping track of all modified parameters)
1344 if (!sync(strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001345
1346 return false;
1347 }
1348 }
1349
1350 // Set Auto sync
1351 _bAutoSyncOn = bAutoSyncOn;
1352
1353 return true;
1354}
1355
1356bool CParameterMgr::autoSyncOn() const
1357{
1358 return _bAutoSyncOn;
1359}
1360
1361// Manual hardware synchronization control (during tuning session)
1362bool CParameterMgr::sync(string& strError)
1363{
1364 // Check tuning mode
1365 if (!checkTuningModeOn(strError)) {
1366
1367 return false;
1368 }
1369 // Warn domains about turning auto sync back on
1370 if (_bAutoSyncOn) {
1371
1372 strError = "Feature unavailable when Auto Sync is on";
1373
1374 return false;
1375 }
1376
1377 // Get syncer set
1378 CSyncerSet syncerSet;
1379 // ... from system class
1380 getConstSystemClass()->fillSyncerSet(syncerSet);
1381 // Sync
1382 return syncerSet.sync(*_pMainParameterBlackboard, false, strError);
1383}
1384
1385// Content dump
1386void CParameterMgr::logStructureContent(string& strContent) const
1387{
1388 string strError;
1389
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001390 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001391
1392 dumpContent(strContent, parameterAccessContext);
1393}
1394
1395// Configuration/Domains handling
1396bool CParameterMgr::createDomain(const string& strName, string& strError)
1397{
1398 // Check tuning mode
1399 if (!checkTuningModeOn(strError)) {
1400
1401 return false;
1402 }
1403
1404 // Delegate to configurable domains
1405 return getConfigurableDomains()->createDomain(strName, strError);
1406}
1407
1408bool CParameterMgr::deleteDomain(const string& strName, string& strError)
1409{
1410 // Check tuning mode
1411 if (!checkTuningModeOn(strError)) {
1412
1413 return false;
1414 }
1415
1416 // Delegate to configurable domains
1417 return getConfigurableDomains()->deleteDomain(strName, strError);
1418}
1419
1420bool CParameterMgr::createConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1421{
1422 // Check tuning mode
1423 if (!checkTuningModeOn(strError)) {
1424
1425 return false;
1426 }
1427
1428 // Delegate to configurable domains
1429 return getConfigurableDomains()->createConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1430}
1431
1432bool CParameterMgr::deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1433{
1434 // Check tuning mode
1435 if (!checkTuningModeOn(strError)) {
1436
1437 return false;
1438 }
1439
1440 // Delegate to configurable domains
1441 return getConfigurableDomains()->deleteConfiguration(strDomain, strConfiguration, strError);
1442}
1443
1444bool CParameterMgr::restoreConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1445{
1446 // Check tuning mode
1447 if (!checkTuningModeOn(strError)) {
1448
1449 return false;
1450 }
1451
1452 // Delegate to configurable domains
1453 return getConfigurableDomains()->restoreConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, strError);
1454}
1455
1456bool CParameterMgr::saveConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1457{
1458 // Check tuning mode
1459 if (!checkTuningModeOn(strError)) {
1460
1461 return false;
1462 }
1463
1464 // Delegate to configurable domains
1465 return getConfigurableDomains()->saveConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1466}
1467
1468// Configurable element - domain association
1469bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1470{
1471 // Check tuning mode
1472 if (!checkTuningModeOn(strError)) {
1473
1474 return false;
1475 }
1476
1477 CElementLocator elementLocator(getSystemClass());
1478
1479 CElement* pLocatedElement = NULL;
1480
1481 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1482
1483 return false;
1484 }
1485
1486 // Convert element
1487 CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1488
1489 // Delegate
1490 return getConfigurableDomains()->addConfigurableElementToDomain(strDomain, pConfigurableElement, _pMainParameterBlackboard, strError);
1491}
1492
1493bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1494{
1495 // Check tuning mode
1496 if (!checkTuningModeOn(strError)) {
1497
1498 return false;
1499 }
1500
1501 CElementLocator elementLocator(getSystemClass());
1502
1503 CElement* pLocatedElement = NULL;
1504
1505 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1506
Patrick Benavoli63499d42011-10-24 18:50:03 +02001507 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001508 }
1509
1510 // Convert element
1511 CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1512
1513 // Delegate
1514 return getConfigurableDomains()->removeConfigurableElementFromDomain(strDomain, pConfigurableElement, strError);
1515}
1516
1517bool CParameterMgr::split(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1518{
1519 // Check tuning mode
1520 if (!checkTuningModeOn(strError)) {
1521
1522 return false;
1523 }
1524
1525 CElementLocator elementLocator(getSystemClass());
1526
1527 CElement* pLocatedElement = NULL;
1528
1529 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1530
Patrick Benavoli63499d42011-10-24 18:50:03 +02001531 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001532 }
1533
1534 // Convert element
1535 CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1536
1537 // Delegate
1538 return getConfigurableDomains()->split(strDomain, pConfigurableElement, strError);
1539}
1540
1541// XML Import/Export
1542bool CParameterMgr::importDomainsXml(const string& strFileName, bool bWithSettings, string& strError)
1543{
1544 // Check tuning mode
1545 if (!checkTuningModeOn(strError)) {
1546
1547 return false;
1548 }
1549
1550 // check path is absolute
1551 if (strFileName[0] != '/') {
1552
1553 strError = "Please provide absolute path";
1554
1555 return false;
1556 }
1557 // Root element
1558 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1559
1560 // Context
1561 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1562
1563 // Secltion criteria definition for rule creation
1564 xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
1565
1566 // Parse
1567 if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strFileName, "", EParameterConfigurationLibrary, "SystemClassName")) {
1568
1569 return false;
1570 }
1571
1572 // Validate domains after XML import
1573 pConfigurableDomains->validate(_pMainParameterBlackboard);
1574
1575 return true;
1576}
1577
1578bool CParameterMgr::exportDomainsXml(const string& strFileName, bool bWithSettings, string& strError) const
1579{
1580 // check path is absolute
1581 if (strFileName[0] != '/') {
1582
1583 strError = "Please provide absolute path";
1584
1585 return false;
1586 }
1587
1588 // Root element
1589 const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains();
1590
1591 // Get Schema file associated to root element
1592 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pConfigurableDomains->getKind() + ".xsd";
1593
1594 // Context
1595 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1596
1597 // Value space
1598 xmlDomainSerializingContext.setValueSpaceRaw(_bValueSpaceIsRaw);
1599
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001600 // Output raw format
1601 xmlDomainSerializingContext.setOutputRawFormat(_bOutputRawFormatIsHex);
1602
Patrick Benavoli68a91282011-08-31 11:23:23 +02001603 // Instantiate composer
1604 CXmlComposer xmlComposer(strFileName, strXmlSchemaFilePath, pConfigurableDomains->getKind(), xmlDomainSerializingContext);
1605
1606 // Open composer
1607 if (!xmlComposer.open()) {
1608
1609 return false;
1610 }
1611
1612 // Compose
Patrick Benavoli63499d42011-10-24 18:50:03 +02001613 xmlComposer.compose(pConfigurableDomains, "parameter-framework", getVersion());
Patrick Benavoli68a91282011-08-31 11:23:23 +02001614
1615 // Close composer
1616 if (!xmlComposer.close()) {
1617
1618 return false;
1619 }
1620
1621 return true;
1622}
1623
1624// Binary Import/Export
1625bool CParameterMgr::importDomainsBinary(const string& strFileName, string& strError)
1626{
1627 // Check tuning mode
1628 if (!checkTuningModeOn(strError)) {
1629
1630 return false;
1631 }
1632 // check path is absolute
1633 if (strFileName[0] != '/') {
1634
1635 strError = "Please provide absolute path";
1636
1637 return false;
1638 }
1639 // Root element
1640 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1641
1642 // Serialize in
1643 return pConfigurableDomains->serializeSettings(strFileName, false, _uiStructureChecksum, strError);
1644}
1645
1646bool CParameterMgr::exportDomainsBinary(const string& strFileName, string& strError)
1647{
1648 // check path is absolute
1649 if (strFileName[0] != '/') {
1650
1651 strError = "Please provide absolute path";
1652
1653 return false;
1654 }
Patrick Benavoli68a91282011-08-31 11:23:23 +02001655
Patrick Benavoli68a91282011-08-31 11:23:23 +02001656 // Root element
1657 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1658
1659 // Serialize out
1660 return pConfigurableDomains->serializeSettings(strFileName, true, _uiStructureChecksum, strError);
1661}
1662
1663// For tuning, check we're in tuning mode
1664bool CParameterMgr::checkTuningModeOn(string& strError) const
1665{
1666 // Tuning Mode on?
1667 if (!_bTuningModeIsOn) {
1668
1669 strError = "Tuning Mode must be on";
1670
1671 return false;
1672 }
1673 return true;
1674}
1675
Patrick Benavoli065264a2011-11-20 15:46:41 +01001676// Tuning mutex dynamic parameter handling
1677pthread_mutex_t* CParameterMgr::getBlackboardMutex()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001678{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001679 return &_blackboardMutex;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001680}
1681
Patrick Benavoli065264a2011-11-20 15:46:41 +01001682// Blackboard reference (dynamic parameter handling)
1683CParameterBlackboard* CParameterMgr::getParameterBlackboard()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001684{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001685 return _pMainParameterBlackboard;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001686}
1687
Patrick Benavoli68a91282011-08-31 11:23:23 +02001688// Dynamic creation library feeding
1689void CParameterMgr::feedElementLibraries()
1690{
1691 // Global Configuration handling
1692 CElementLibrary* pFrameworkConfigurationLibrary = new CElementLibrary;
1693
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001694 pFrameworkConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CParameterFrameworkConfiguration>("ParameterFrameworkConfiguration"));
1695 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationGroup>("SubsystemPluginFolders"));
1696 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("PluginFolderLocation"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001697 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("StructureDescriptionFileLocation"));
1698 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationGroup>("SettingsConfiguration"));
1699 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("ConfigurableDomainsFileLocation"));
1700 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("BinarySettingsFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001701
1702 _pElementLibrarySet->addElementLibrary(pFrameworkConfigurationLibrary);
1703
1704 // Parameter creation
1705 CElementLibrary* pParameterCreationLibrary = new CElementLibrary;
1706
1707 pParameterCreationLibrary->addElementBuilder(new CSubsystemElementBuilder(getSystemClass()->getSubsystemLibrary()));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001708 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CComponentType>("ComponentType"));
1709 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CComponentInstance>("Component"));
1710 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBitParameterType>("BitParameter"));
1711 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBitParameterBlockType>("BitParameterBlock"));
Patrick Benavoli1352ae52011-10-21 16:48:04 +02001712 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CStringParameterType>("StringParameter"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001713 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CParameterBlockType>("ParameterBlock"));
1714 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBooleanParameterType>("BooleanParameter"));
1715 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CIntegerParameterType>("IntegerParameter"));
Patrick Benavoli9fc3c0d2011-10-27 14:27:27 +02001716 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CEnumParameterType>("EnumParameter"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001717 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CFixedPointParameterType>("FixedPointParameter"));
1718 pParameterCreationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CXmlFileIncluderElement>("SubsystemInclude"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001719
1720 _pElementLibrarySet->addElementLibrary(pParameterCreationLibrary);
1721
1722 // Parameter Configuration Domains creation
1723 CElementLibrary* pParameterConfigurationLibrary = new CElementLibrary;
1724
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001725 pParameterConfigurationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CConfigurableDomain>("ConfigurableDomain"));
1726 pParameterConfigurationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CDomainConfiguration>("Configuration"));
1727 pParameterConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CCompoundRule>("CompoundRule"));
1728 pParameterConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CSelectionCriterionRule>("SelectionCriterionRule"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001729
1730 _pElementLibrarySet->addElementLibrary(pParameterConfigurationLibrary);
1731}
1732
1733// Remote Processor Server connection handling
1734bool CParameterMgr::handleRemoteProcessingInterface(string& strError)
1735{
1736 CAutoLog autoLog(this, "Handling remote processing interface");
1737
1738 // Start server if tuning allowed
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001739 if (getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001740
1741 log("Loading remote processor library");
1742
1743 // Load library
1744 void* lib_handle = dlopen("libremote-processor.so", RTLD_NOW);
1745
1746 if (!lib_handle) {
1747
1748 // Return error
1749 const char* pcError = dlerror();
1750
1751 if (pcError) {
1752
1753 strError = pcError;
1754 } else {
1755
1756 strError = "Unable to load libremote-processor.so library";
1757 }
1758
1759 return false;
1760 }
1761
1762 CreateRemoteProcessorServer pfnCreateRemoteProcessorServer = (CreateRemoteProcessorServer)dlsym(lib_handle, "createRemoteProcessorServer");
1763
1764 if (!pfnCreateRemoteProcessorServer) {
1765
1766 strError = "libremote-process.so does not contain createRemoteProcessorServer symbol.";
1767
1768 return false;
1769 }
1770
1771 // Create server
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001772 _pRemoteProcessorServer = pfnCreateRemoteProcessorServer(getConstFrameworkConfiguration()->getServerPort(), _pCommandHandler);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001773
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001774 log("Starting remote processor server on port %d", getConstFrameworkConfiguration()->getServerPort());
Patrick Benavoli68a91282011-08-31 11:23:23 +02001775 // Start
1776 if (!_pRemoteProcessorServer->start()) {
1777
1778 strError = "Unable to start remote processor server";
1779
1780 return false;
1781 }
1782 }
1783
1784 return true;
1785}
1786
1787// Back synchronization
1788CBackSynchronizer* CParameterMgr::createBackSynchronizer(string& strError) const
1789{
1790#ifdef SIMULATION
1791 // In simulation, back synchronization of the blackboard won't probably work
1792 // We need to ensure though the blackboard is initialized with valid data
1793 return new CSimulatedBackSynchronizer(getConstSystemClass(), strError, _pMainParameterBlackboard);
1794#else
1795 // Real back synchronizer from subsystems
1796 return new CHardwareBackSynchronizer(getConstSystemClass(), strError, _pMainParameterBlackboard);
1797#endif
1798}
1799
1800// Children typwise access
1801CParameterFrameworkConfiguration* CParameterMgr::getFrameworkConfiguration()
1802{
1803 return static_cast<CParameterFrameworkConfiguration*>(getChild(EFrameworkConfiguration));
1804}
1805
1806const CParameterFrameworkConfiguration* CParameterMgr::getConstFrameworkConfiguration()
1807{
1808 return getFrameworkConfiguration();
1809}
1810
1811CSelectionCriteria* CParameterMgr::getSelectionCriteria()
1812{
1813 return static_cast<CSelectionCriteria*>(getChild(ESelectionCriteria));
1814}
1815
1816const CSelectionCriteria* CParameterMgr::getConstSelectionCriteria()
1817{
1818 return static_cast<const CSelectionCriteria*>(getChild(ESelectionCriteria));
1819}
1820
1821CSystemClass* CParameterMgr::getSystemClass()
1822{
1823 return static_cast<CSystemClass*>(getChild(ESystemClass));
1824}
1825
1826const CSystemClass* CParameterMgr::getConstSystemClass() const
1827{
1828 return static_cast<const CSystemClass*>(getChild(ESystemClass));
1829}
1830
1831// Configurable Domains
1832CConfigurableDomains* CParameterMgr::getConfigurableDomains()
1833{
1834 return static_cast<CConfigurableDomains*>(getChild(EConfigurableDomains));
1835}
1836
1837const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains()
1838{
1839 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
1840}
1841
1842const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains() const
1843{
1844 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
1845}