blob: a8335c80bf96c1a9f68eca221ea3c2966bed6b5d [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"
58#include "SystemClassConfiguration.h"
59#include "ConfigurableDomains.h"
60#include "ConfigurableDomain.h"
61#include "DomainConfiguration.h"
62#include "XmlComposer.h"
63#include "XmlDomainSerializingContext.h"
64#include "BitParameterBlockType.h"
65#include "BitParameterType.h"
66#include "RemoteProcessorServerInterface.h"
67#include "ElementLocator.h"
68#include "AutoLog.h"
69#include "CompoundRule.h"
70#include "SelectionCriterionRule.h"
71#include "SimulatedBackSynchronizer.h"
72#include "HardwareBackSynchronizer.h"
Patrick Benavoli1387bda2011-08-31 11:23:24 +020073#include "AutoLock.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020074#include <strings.h>
75#include <dlfcn.h>
76#include <assert.h>
Patrick Benavoli68a91282011-08-31 11:23:23 +020077
78#define base CElement
79
80// Used for remote processor server creation
81typedef IRemoteProcessorServerInterface* (*CreateRemoteProcessorServer)(uint16_t uiPort, IRemoteCommandHandler* pCommandHandler);
82
83// Global configuration file name (fixed)
84const char* gacParameterFrameworkConfigurationFileName = "ParameterFrameworkConfiguration.xml";
85const char* gacSystemSchemasSubFolder = "Schemas";
86
87// Config File System looks normally like this:
88// ---------------------------------------------
89//├── ParameterFrameworkConfiguration.xml
90//├── Schemas
91//│ └── *.xsd
92//├── Settings
93//│ └── <SystemClassName folder>*
94//│ ├── <ConfigurableDomains>.xml
95//│ └── <Settings>.bin?
96//└── Structure
97// └── <SystemClassName folder>*
98// ├── <SystemClassName>Class.xml
99// └── <Subsystem>.xml*
100// --------------------------------------------
101
102
103// Remote command parser array
Patrick Benavoli592ae562011-09-05 16:53:58 +0200104const CParameterMgr::SRemoteCommandParserItem CParameterMgr::gastRemoteCommandParserItems[] = {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200105 /// Help
106 { "help", &CParameterMgr::helpCommandProcess, 0, "", "Show commands description and usage" },
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" },
131 { "listDomainElements", &CParameterMgr::listDomainElementsCommmandProcess, 1, "<domain>", "List elements associated to configurable domain" },
132 { "addElement", &CParameterMgr::addElementCommmandProcess, 2, "<domain> <elem path>", "Associate element at given path to configurable domain" },
133 { "removeElement", &CParameterMgr::removeElementCommmandProcess, 2, "<domain> <elem path>", "Dissociate element at given path from configurable domain" },
134 { "splitDomain", &CParameterMgr::splitDomainCommmandProcess, 2, "<domain> <elem path>", "Split configurable domain at given associated element path" },
135 /// Configurations
136 { "listConfigurations", &CParameterMgr::listConfigurationsCommmandProcess, 1, "<domain>", "List domain configurations" },
137 { "createConfiguration", &CParameterMgr::createConfigurationCommmandProcess, 2, "<domain> <configuration>", "Create new domain configuration" },
138 { "deleteConfiguration", &CParameterMgr::deleteConfigurationCommmandProcess, 2, "<domain> <configuration>", "Delete domain configuration" },
139 { "renameConfiguration", &CParameterMgr::renameConfigurationCommmandProcess, 3, "<domain> <configuration> <new name>", "Rename domain configuration" },
140 { "saveConfiguration", &CParameterMgr::saveConfigurationCommmandProcess, 2, "<domain> <configuration>", "Save current settings into configuration" },
141 { "restoreConfiguration", &CParameterMgr::restoreConfigurationCommmandProcess, 2, "<domain> <configuration>", "Restore current settings from configuration" },
142 /// Elements/Parameters
143 { "listElements", &CParameterMgr::listElementsCommmandProcess, 1, "<elem path>|/", "List elements under element at given path or root" },
Patrick Benavoli592ae562011-09-05 16:53:58 +0200144 { "listParameters", &CParameterMgr::listParametersCommmandProcess, 1, "<elem path>|/", "List parameters under element at given path or root" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200145 { "dumpElement", &CParameterMgr::dumpElementCommmandProcess, 1, "<elem path>", "Dump structure and content of element at given path" },
146 { "getElementSize", &CParameterMgr::getElementSizeCommmandProcess, 1, "<elem path>", "Show size of element at given path" },
Patrick Benavoli2ecf9002011-08-31 11:23:24 +0200147 { "showProperties", &CParameterMgr::showPropertiesCommmandProcess, 1, "<elem path>", "Show properties of element at given path" },
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200148 { "getParameter", &CParameterMgr::getParameterCommmandProcess, 1, "<param path>", "Get value for parameter at given path" },
Patrick Benavoli2ecf9002011-08-31 11:23:24 +0200149 { "setParameter", &CParameterMgr::setParameterCommmandProcess, 2, "<param path> <value>", "Set value for parameter at given path" },
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200150 { "listBelongingDomains", &CParameterMgr::listBelongingDomainsCommmandProcess, 1, "<elem path>", "List domain(s) element at given path belongs to" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200151 { "listAssociatedDomains", &CParameterMgr::listAssociatedDomainsCommmandProcess, 1, "<elem path>", "List domain(s) element at given path is associated to" },
152 /// Browse
153 { "listAssociatedElements", &CParameterMgr::listAssociatedElementsCommmandProcess, 0, "", "List element sub-trees associated to at least one configurable domain" },
154 { "listConflictingElements", &CParameterMgr::listConflictingElementsCommmandProcess, 0, "", "List element sub-trees contained in more than one configurable domain" },
155 { "listRogueElements", &CParameterMgr::listRogueElementsCommmandProcess, 0, "", "List element sub-trees owned by no configurable domain" },
156 /// Settings Import/Export
157 { "exportDomainsXML", &CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess, 1, "<file path> ", "Export domains to XML file" },
158 { "importDomainsXML", &CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess, 1, "<file path>", "Import domains from XML file" },
159 { "exportDomainsWithSettingsXML", &CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess, 1, "<file path> ", "Export domains including settings to XML file" },
160 { "importDomainsWithSettingsXML", &CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess, 1, "<file path>", "Import domains including settings from XML file" },
161 { "exportSettings", &CParameterMgr::exportSettingsCommmandProcess, 1, "<file path>", "Export settings to binary file" },
162 { "importSettings", &CParameterMgr::importSettingsCommmandProcess, 1, "<file path>", "Import settings from binary file" }
163};
164// Remote command parsers array Size
Patrick Benavoli592ae562011-09-05 16:53:58 +0200165const uint32_t CParameterMgr::guiNbRemoteCommandParserItems = sizeof(gastRemoteCommandParserItems) / sizeof(gastRemoteCommandParserItems[0]);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200166
167CParameterMgr::CParameterMgr(const string& strParameterFrameworkConfigurationFolderPath, const string& strSystemClassName) :
168 _bTuningModeIsOn(false),
169 _bValueSpaceIsRaw(false),
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200170 _bOutputRawFormatIsHex(false),
Patrick Benavoli68a91282011-08-31 11:23:23 +0200171 _bAutoSyncOn(true),
172 _pMainParameterBlackboard(new CParameterBlackboard),
173 _pElementLibrarySet(new CElementLibrarySet),
174 _strParameterFrameworkConfigurationFolderPath(strParameterFrameworkConfigurationFolderPath),
175 _strSchemaFolderLocation(strParameterFrameworkConfigurationFolderPath + "/" + gacSystemSchemasSubFolder),
176 _pSystemClassConfiguration(NULL),
177 _uiStructureChecksum(0),
178 _pRemoteProcessorServer(NULL),
179 _uiMaxCommandUsageLength(0),
180 _pLogger(NULL),
181 _uiLogDepth(0)
182{
183 // Tuning Mode Mutex
184 bzero(&_tuningModeMutex, sizeof(_tuningModeMutex));
185 pthread_mutex_init(&_tuningModeMutex, NULL);
186
187 // Deal with children
188 addChild(new CParameterFrameworkConfiguration);
189 addChild(new CSelectionCriteria);
190 addChild(new CSystemClass(strSystemClassName));
191 addChild(new CConfigurableDomains(strSystemClassName));
192
193 // Feed element library
194 feedElementLibraries();
195}
196
197CParameterMgr::~CParameterMgr()
198{
199 // Children
200 delete _pRemoteProcessorServer;
201 delete _pMainParameterBlackboard;
202 delete _pElementLibrarySet;
203
204 // Tuning Mode Mutex
205 pthread_mutex_destroy(&_tuningModeMutex);
206}
207
208string CParameterMgr::getKind() const
209{
210 return "ParameterMgr";
211}
212
213// Logging
214void CParameterMgr::setLogger(CParameterMgr::ILogger* pLogger)
215{
216 _pLogger = pLogger;
217}
218
219// Logging
220void CParameterMgr::doLog(const string& strLog) const
221{
222 if (_pLogger) {
223
224 // Nest
225 string strIndent;
226
227 // Level
228 uint32_t uiNbIndents = _uiLogDepth;
229
230 while (uiNbIndents--) {
231
232 strIndent += " ";
233 }
234
235 // Log
236 _pLogger->log(strIndent + strLog);
237 }
238}
239
240void CParameterMgr::nestLog() const
241{
Patrick Benavoli592ae562011-09-05 16:53:58 +0200242 _uiLogDepth++;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200243}
244
245void CParameterMgr::unnestLog() const
246{
Patrick Benavoli592ae562011-09-05 16:53:58 +0200247 _uiLogDepth--;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200248}
249
250bool CParameterMgr::load(string& strError)
251{
252 CAutoLog autoLog(this, "Loading");
253
254 // Load Framework configuration
255 if (!loadFrameworkConfiguration(strError)) {
256
257 return false;
258 }
259
260 // Load subsystems
261 if (!getSystemClass()->loadSubsystems(strError, _astrPluginFolderPaths)) {
262
263 return false;
264 }
265
266 // Load structure
267 if (!loadStructure(strError)) {
268
269 return false;
270 }
271
272 // Load settings
273 if (!loadSettings(strError)) {
274
275 return false;
276 }
277
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200278 // Back synchronization for areas in parameter blackboard not covered by any domain
279 CBackSynchronizer* pBackSynchronizer = createBackSynchronizer(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200280
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200281 log("Main blackboard back synchronization");
282
283 // Back-synchronize
284 if (!pBackSynchronizer->sync()) {
285 // Get rid of back synchronizer
286 delete pBackSynchronizer;
287
288 strError = "Main blackboard back synchronization failed: " + strError;
289
290 return false;
291 }
292 // Get rif of back synchronizer
293 delete pBackSynchronizer;
294
295 // We're done loading the settings and back synchronizing
296 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
297
298 // We need to ensure all domains are valid
299 pConfigurableDomains->validate(_pMainParameterBlackboard);
300
301 // Ensure application of currently selected configurations
302 // Force-apply configurations
303 if (!pConfigurableDomains->apply(_pMainParameterBlackboard, true, strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200304
305 return false;
306 }
307
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200308 // All is loaded, we're ready to observe selection criteria change events
309 getSelectionCriteria()->setObserver(this);
310
311 // Start remote processor server if appropriate
312 return handleRemoteProcessingInterface(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200313}
314
315bool CParameterMgr::loadFrameworkConfiguration(string& strError)
316{
317 CAutoLog autoLog(this, "Loading framework configuration");
318
319 // Get Xml config file name
320 string strXmlConfigurationFilePath = _strParameterFrameworkConfigurationFolderPath + "/" + gacParameterFrameworkConfigurationFileName;
321
322 // Parse Structure XML file
323 CXmlElementSerializingContext elementSerializingContext(strError);
324
325 if (!xmlParse(elementSerializingContext, getFrameworkConfiguration(), strXmlConfigurationFilePath, _strParameterFrameworkConfigurationFolderPath, EFrameworkConfigurationLibrary)) {
326
327 return false;
328 }
329 // Get subsystem plugins folders element
330 const CFrameworkConfigurationGroup* pSubsystemPluginFolders= static_cast<const CFrameworkConfigurationGroup*>(getConstFrameworkConfiguration()->findChild("SubsystemPluginFolders"));
331
332 if (!pSubsystemPluginFolders) {
333
334 strError = "Parameter Framework Configuration: couldn't find SubsystemPluginFolders element";
335
336 return false;
337 }
338 // Get plugin locations
339 uint32_t uiPluginFolderLocation;
340 uint32_t uiNbPluginFolderLocations = pSubsystemPluginFolders->getNbChildren();
341
342 if (!uiNbPluginFolderLocations) {
343
344 strError = "Parameter Framework Configuration: couldn't find any PluginFolderLocation element";
345
346 return false;
347 }
348
349 for (uiPluginFolderLocation = 0; uiPluginFolderLocation < uiNbPluginFolderLocations; uiPluginFolderLocation++) {
350
351 const CFrameworkConfigurationLocation* pSubsystemPluginLocation = static_cast<const CFrameworkConfigurationLocation*>(pSubsystemPluginFolders->getChild(uiPluginFolderLocation));
352
353 _astrPluginFolderPaths.push_back(pSubsystemPluginLocation->getFilePath(_strParameterFrameworkConfigurationFolderPath));
354 }
355
356 // Get configuration for current system class
357 const CFrameworkConfigurationGroup* pParameterConfigurationGroup = static_cast<const CFrameworkConfigurationGroup*>(getConstFrameworkConfiguration()->findChildOfKind("ParameterConfiguration"));
358
359 if (!pParameterConfigurationGroup) {
360
361 strError = "Parameter Framework Configuration: couldn't find ParameterConfiguration element";
362
363 return false;
364 }
365 _pSystemClassConfiguration = static_cast<const CSystemClassConfiguration*>(pParameterConfigurationGroup->findChild(getSystemClass()->getName()));
366
367 if (!_pSystemClassConfiguration) {
368
369 strError = "No framework configuration found for SystemClass " + getSystemClass()->getName();
370
371 return false;
372 }
373 // Log tuning availability
374 log("Tuning %s", _pSystemClassConfiguration->isTuningAllowed() ? "allowed" : "prohibited");
375
376 return true;
377}
378
379bool CParameterMgr::loadStructure(string& strError)
380{
381 // Retrieve system to load structure to
382 CSystemClass* pSystemClass = getSystemClass();
383
384 CAutoLog autoLog(this, "Loading " + pSystemClass->getName() + " system class structure");
385
386 // Get structure description element
387 const CFrameworkConfigurationLocation* pStructureDescriptionFileLocation = static_cast<const CFrameworkConfigurationLocation*>(_pSystemClassConfiguration->findChildOfKind("StructureDescriptionFileLocation"));
388
389 if (!pStructureDescriptionFileLocation) {
390
391 strError = "No StructureDescriptionFileLocation element found for SystemClass " + pSystemClass->getName();
392
393 return false;
394 }
395
396 // Get Xml structure folder
397 string strXmlStructureFolder = pStructureDescriptionFileLocation->getFolderPath(_strParameterFrameworkConfigurationFolderPath);
398
399 // Get Xml structure file name
400 string strXmlStructureFilePath = pStructureDescriptionFileLocation->getFilePath(_strParameterFrameworkConfigurationFolderPath);
401
402 // Parse Structure XML file
403 CXmlParameterSerializingContext parameterBuildContext(strError);
404
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200405 log("Importing system structure from file %s", strXmlStructureFilePath.c_str());
406
Patrick Benavoli68a91282011-08-31 11:23:23 +0200407 if (!xmlParse(parameterBuildContext, pSystemClass, strXmlStructureFilePath, strXmlStructureFolder, EParameterCreationLibrary)) {
408
409 return false;
410 }
411
412 // Initialize offsets
413 pSystemClass->setOffset(0);
414
415 // Initialize main blackboard's size
416 _pMainParameterBlackboard->setSize(pSystemClass->getFootPrint());
417
418 return true;
419}
420
421bool CParameterMgr::loadSettings(string& strError)
422{
423 CAutoLog autoLog(this, "Loading settings");
424
425 // Get settings configuration element
426 const CFrameworkConfigurationGroup* pParameterConfigurationGroup = static_cast<const CFrameworkConfigurationGroup*>(_pSystemClassConfiguration->findChildOfKind("SettingsConfiguration"));
427
428 if (!pParameterConfigurationGroup) {
429
430 // No settings to load
431
432 return true;
433 }
434 // Get binary settings file location
435 const CFrameworkConfigurationLocation* pBinarySettingsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("BinarySettingsFileLocation"));
436
437 string strXmlBinarySettingsFilePath;
438
439 if (pBinarySettingsFileLocation) {
440
441 // Get Xml binary settings file name
442 strXmlBinarySettingsFilePath = pBinarySettingsFileLocation->getFilePath(_strParameterFrameworkConfigurationFolderPath);
443 }
444
445 // Get configurable domains element
446 const CFrameworkConfigurationLocation* pConfigurableDomainsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("ConfigurableDomainsFileLocation"));
447
448 if (!pConfigurableDomainsFileLocation) {
449
450 strError = "No ConfigurableDomainsFileLocation element found for SystemClass " + getSystemClass()->getName();
451
452 return false;
453 }
454 // Get destination root element
455 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
456
457 // Get Xml configuration domains file name
458 string strXmlConfigurationDomainsFilePath = pConfigurableDomainsFileLocation->getFilePath(_strParameterFrameworkConfigurationFolderPath);
459
460 // Get Xml configuration domains folder
461 string strXmlConfigurationDomainsFolder = pConfigurableDomainsFileLocation->getFolderPath(_strParameterFrameworkConfigurationFolderPath);
462
463 // Parse configuration domains XML file (ask to read settings from XML file if they are not provided as binary)
464 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, !pBinarySettingsFileLocation);
465
466 // Selection criteria definition for rule creation
467 xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
468
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200469 log("Importing configurable domains from file %s %s settings", strXmlConfigurationDomainsFilePath.c_str(), pBinarySettingsFileLocation ? "without" : "with");
470
Patrick Benavoli68a91282011-08-31 11:23:23 +0200471 // Do parse
472 if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strXmlConfigurationDomainsFilePath, strXmlConfigurationDomainsFolder, EParameterConfigurationLibrary, "SystemClassName")) {
473
474 return false;
475 }
476 // We have loaded the whole system structure, compute checksum
477 const CSystemClass* pSystemClass = getConstSystemClass();
478 _uiStructureChecksum = pSystemClass->computeStructureChecksum() + getConfigurableDomains()->computeStructureChecksum() + getSelectionCriteria()->computeStructureChecksum();
479
480 // Load binary settings if any provided
481 if (pBinarySettingsFileLocation && !pConfigurableDomains->serializeSettings(strXmlBinarySettingsFilePath, false, _uiStructureChecksum, strError)) {
482
483 return false;
484 }
485
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200486 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200487}
488
489// XML parsing
490bool CParameterMgr::xmlParse(CXmlElementSerializingContext& elementSerializingContext, CElement* pRootElement, const string& strXmlFilePath, const string& strXmlFolder, CParameterMgr::ElementLibrary eElementLibrary, const string& strNameAttrituteName)
491{
492 // Init serializing context
493 elementSerializingContext.set(_pElementLibrarySet->getElementLibrary(eElementLibrary), strXmlFolder, _strSchemaFolderLocation);
494
495 // Get Schema file associated to root element
496 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pRootElement->getKind() + ".xsd";
497
498 // Parse Structure XML file
499 CXmlParser parser(strXmlFilePath, strXmlSchemaFilePath, pRootElement->getKind(), elementSerializingContext);
500
501 if (!parser.open()) {
502
503 return false;
504 }
505
506 // Check Root element name attribute (if any)
507 string strRootElementName = parser.getRootElementAttributeString(strNameAttrituteName);
508
509 if (!strRootElementName.empty() && strRootElementName != pRootElement->getName()) {
510
511 elementSerializingContext.setError("Error: Wrong XML structure file " + strXmlFilePath);
512 elementSerializingContext.appendLineToError(pRootElement->getKind() + " element " + pRootElement->getName() + " mismatches expected " + pRootElement->getKind() + " type " + pRootElement->getName());
513
514 return false;
515 }
516
517 // Start clean
518 pRootElement->clean();
519
520 // Parse
521 if (!parser.parse(pRootElement)) {
522
523 // Cleanup
524 pRootElement->clean();
525
526 return false;
527 }
528
529 // Close parser
530 if (!parser.close()) {
531
532 return false;
533 }
534
535 return true;
536}
537
538// Init
539bool CParameterMgr::init(string& strError)
540{
541 return base::init(strError);
542}
543
544// Selection criteria interface
545CSelectionCriterionType* CParameterMgr::createSelectionCriterionType(bool bIsInclusive)
546{
547 // Propagate
548 return getSelectionCriteria()->createSelectionCriterionType(bIsInclusive);
549}
550
551CSelectionCriterion* CParameterMgr::createSelectionCriterion(const string& strName, const CSelectionCriterionType* pSelectionCriterionType)
552{
553 // Propagate
554 return getSelectionCriteria()->createSelectionCriterion(strName, pSelectionCriterionType);
555}
556
557// Selection criteria changed event
558void CParameterMgr::selectionCriterionChanged(const CSelectionCriterion* pSelectionCriterion)
559{
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200560 CAutoLog autoLog(this, "Selection criterion changed event: " + pSelectionCriterion->getFormattedDescription(false));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200561
562 // Lock state
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200563 CAutoLock autoLock(&_tuningModeMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200564
565 if (!_bTuningModeIsOn) {
566
567 // Apply configuration(s)
568 string strError;
569
570 if (!getConfigurableDomains()->apply(_pMainParameterBlackboard, false, strError)) {
571
572 log("Failed to apply configurations!");
573 }
574 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200575}
576
577// Command processing
578bool CParameterMgr::remoteCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
579{
580 log("Processing remote command: \"%s\"", remoteCommand.getCommand().c_str());
581
582 // Dispatch
583 uint32_t uiRemoteCommandParserItem;
584
585 for (uiRemoteCommandParserItem = 0; uiRemoteCommandParserItem < guiNbRemoteCommandParserItems; uiRemoteCommandParserItem++) {
586
Patrick Benavoli592ae562011-09-05 16:53:58 +0200587 const SRemoteCommandParserItem* pRemoteCommandParserItem = &gastRemoteCommandParserItems[uiRemoteCommandParserItem];
Patrick Benavoli68a91282011-08-31 11:23:23 +0200588
589 if (string(pRemoteCommandParserItem->_pcCommandName) == remoteCommand.getCommand()) {
590
591 // Check enough arguments supplied
592 if (remoteCommand.getArgumentCount() < pRemoteCommandParserItem->_uiMinArgumentCount) {
593
594 strResult = string("Not enough arguments supplied\nUsage:\n") + pRemoteCommandParserItem->usage();
595
596 return false;
597 }
598
599 switch ((this->*pRemoteCommandParserItem->_pfnParser)(remoteCommand, strResult)) {
600 case EDone:
601 strResult = "Done";
602 case ESucceeded:
603 return true;
604 case EShowUsgae:
605 strResult = pRemoteCommandParserItem->usage();
606 // Fall through intentionally
607 case EFailed:
608 return false;
609 default:
610 assert(0);
611 }
612 }
613 }
614 // Not found
615 strResult = "Command not found!";
616
617 return false;
618}
619
620// Max command usage length, use for formatting
621void CParameterMgr::setMaxCommandUsageLength()
622{
623 // Show usages
624 uint32_t uiRemoteCommandParserItem;
625
626 for (uiRemoteCommandParserItem = 0; uiRemoteCommandParserItem < guiNbRemoteCommandParserItems; uiRemoteCommandParserItem++) {
627
Patrick Benavoli592ae562011-09-05 16:53:58 +0200628 const SRemoteCommandParserItem* pRemoteCommandParserItem = &gastRemoteCommandParserItems[uiRemoteCommandParserItem];
Patrick Benavoli68a91282011-08-31 11:23:23 +0200629
630 uint32_t uiRemoteCommandUsageLength = pRemoteCommandParserItem->usage().length();
631
632 if (uiRemoteCommandUsageLength > _uiMaxCommandUsageLength) {
633
634 _uiMaxCommandUsageLength = uiRemoteCommandUsageLength;
635 }
636 }
637}
638
639/////////////////// Remote command parsers
640/// Help
641CParameterMgr::CommandStatus CParameterMgr::helpCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
642{
643 (void)remoteCommand;
644
645 strResult = "\n";
646
647 // Show usages
648 uint32_t uiRemoteCommandParserItem;
649
650 for (uiRemoteCommandParserItem = 0; uiRemoteCommandParserItem < guiNbRemoteCommandParserItems; uiRemoteCommandParserItem++) {
651
Patrick Benavoli592ae562011-09-05 16:53:58 +0200652 const SRemoteCommandParserItem* pRemoteCommandParserItem = &gastRemoteCommandParserItems[uiRemoteCommandParserItem];
Patrick Benavoli68a91282011-08-31 11:23:23 +0200653
654 string strUsage = pRemoteCommandParserItem->usage();
655
656 strResult += strUsage;
657
658 // Align
659 uint32_t uiToSpacesAdd = _uiMaxCommandUsageLength + 5 - strUsage.length();
660
661 while (uiToSpacesAdd--) {
662
663 strResult += " ";
664 }
665
666 strResult += string("=> ") + string(pRemoteCommandParserItem->_pcDescription) + "\n";
667
668 }
669 return ESucceeded;
670}
671
Patrick Benavoli592ae562011-09-05 16:53:58 +0200672/// Version
673CParameterMgr::CommandStatus CParameterMgr::versionCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
674{
675 (void)remoteCommand;
676
677 // Show versions
678 // Major
679 strResult = toString(guiEditionMajor) + ".";
680 // Minor
681 strResult += toString(guiEditionMinor) + ".";
682 // Revision
683 strResult += toString(guiRevision);
684
685 return ESucceeded;
686}
687
Patrick Benavoli68a91282011-08-31 11:23:23 +0200688/// Status
689CParameterMgr::CommandStatus CParameterMgr::statusCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
690{
691 (void)remoteCommand;
692 // System class
693 const CSystemClass* pSystemClass = getSystemClass();
694
Patrick Benavoli68a91282011-08-31 11:23:23 +0200695 // Show status
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200696 /// General section
697 appendTitle(strResult, "General:");
698 // System class
Patrick Benavoli68a91282011-08-31 11:23:23 +0200699 strResult += "System Class: ";
700 strResult += pSystemClass->getName();
701 strResult += "\n";
702
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200703 // Tuning mode
Patrick Benavoli68a91282011-08-31 11:23:23 +0200704 strResult += "Tuning Mode: ";
705 strResult += tuningModeOn() ? "on" : "off";
706 strResult += "\n";
707
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200708 // Value space
Patrick Benavoli68a91282011-08-31 11:23:23 +0200709 strResult += "Value Space: ";
710 strResult += valueSpaceIsRaw() ? "raw" : "real";
711 strResult += "\n";
712
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200713 // Output raw format
714 strResult += "Output Raw Format: ";
715 strResult += outputRawFormatIsHex() ? "hex" : "dec";
716 strResult += "\n";
717
718 // Auto Sync
Patrick Benavoli68a91282011-08-31 11:23:23 +0200719 strResult += "Auto Sync: ";
720 strResult += autoSyncOn() ? "on" : "off";
721 strResult += "\n";
722
723 /// Subsystem list
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200724 appendTitle(strResult, "Subsystems:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200725 string strSubsystemList;
726 pSystemClass->listChildrenPaths(strSubsystemList);
727 strResult += strSubsystemList;
728
729 /// Last applied configurations
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200730 appendTitle(strResult, "Last applied configurations:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200731 string strLastAppliedConfigurations;
732 getConfigurableDomains()->listLastAppliedConfigurations(strLastAppliedConfigurations);
733 strResult += strLastAppliedConfigurations;
734
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200735 /// Criteria states
736 appendTitle(strResult, "Selection criteria:");
737 string strSelectionCriteria;
738 getSelectionCriteria()->listSelectionCriteria(strSelectionCriteria, false);
739 strResult += strSelectionCriteria;
740
Patrick Benavoli68a91282011-08-31 11:23:23 +0200741 return ESucceeded;
742}
743
744/// Tuning Mode
745CParameterMgr::CommandStatus CParameterMgr::setTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
746{
747 if (remoteCommand.getArgument(0) == "on") {
748
749 if (setTuningMode(true, strResult)) {
750
751 return EDone;
752 }
753 } else if (remoteCommand.getArgument(0) == "off") {
754
755 if (setTuningMode(false, strResult)) {
756
757 return EDone;
758 }
759 } else {
760 // Show usage
761 return EShowUsgae;
762 }
763 return EFailed;
764}
765
766CParameterMgr::CommandStatus CParameterMgr::getTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
767{
768 (void)remoteCommand;
769
770 strResult = tuningModeOn() ? "on" : "off";
771
772 return ESucceeded;
773}
774
775/// Value Space
776CParameterMgr::CommandStatus CParameterMgr::setValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
777{
778 (void)strResult;
779
780 if (remoteCommand.getArgument(0) == "raw") {
781
782 setValueSpace(true);
783
784 return EDone;
785
786 } else if (remoteCommand.getArgument(0) == "real") {
787
788 setValueSpace(false);
789
790 return EDone;
791
792 } else {
793 // Show usage
794 return EShowUsgae;
795 }
796 return EFailed;
797}
798
799CParameterMgr::CommandStatus CParameterMgr::getValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
800{
801 (void)remoteCommand;
802
803 strResult = valueSpaceIsRaw() ? "raw" : "real";
804
805 return ESucceeded;
806}
807
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200808/// Output Raw Format
809CParameterMgr::CommandStatus CParameterMgr::setOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
810{
811 (void)strResult;
812
813 if (remoteCommand.getArgument(0) == "hex") {
814
815 setOutputRawFormat(true);
816
817 return EDone;
818
819 } else if (remoteCommand.getArgument(0) == "dec") {
820
821 setOutputRawFormat(false);
822
823 return EDone;
824
825 } else {
826 // Show usage
827 return EShowUsgae;
828 }
829 return EFailed;
830}
831
832CParameterMgr::CommandStatus CParameterMgr::getOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
833{
834 (void)remoteCommand;
835
836 strResult = outputRawFormatIsHex() ? "hex" : "dec";
837
838 return ESucceeded;
839}
840
Patrick Benavoli68a91282011-08-31 11:23:23 +0200841/// Sync
842CParameterMgr::CommandStatus CParameterMgr::setAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
843{
844 if (remoteCommand.getArgument(0) == "on") {
845
846 if (setAutoSync(true, strResult)) {
847
848 return EDone;
849 }
850 } else if (remoteCommand.getArgument(0) == "off") {
851
852 if (setAutoSync(false, strResult)) {
853
854 return EDone;
855 }
856 } else {
857 // Show usage
858 return EShowUsgae;
859 }
860 return EFailed;
861}
862
863CParameterMgr::CommandStatus CParameterMgr::getAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
864{
865 (void)remoteCommand;
866
867 strResult = autoSyncOn() ? "on" : "off";
868
869 return ESucceeded;
870}
871
872CParameterMgr::CommandStatus CParameterMgr::syncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
873{
874 (void)remoteCommand;
875
876 return sync(strResult) ? EDone : EFailed;
877}
878
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200879/// Criteria
880CParameterMgr::CommandStatus CParameterMgr::listCriteriaCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
881{
882 (void)remoteCommand;
883
884 getSelectionCriteria()->listSelectionCriteria(strResult, true);
885
886 return ESucceeded;
887}
Patrick Benavoli68a91282011-08-31 11:23:23 +0200888
889/// Domains
890CParameterMgr::CommandStatus CParameterMgr::listDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
891{
892 (void)remoteCommand;
893
894 getConfigurableDomains()->listChildren(strResult);
895
896 return ESucceeded;
897}
898
899CParameterMgr::CommandStatus CParameterMgr::createDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
900{
901 return createDomain(remoteCommand.getArgument(0), strResult) ? EDone : EFailed;
902}
903
904CParameterMgr::CommandStatus CParameterMgr::deleteDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
905{
906 return deleteDomain(remoteCommand.getArgument(0), strResult) ? EDone : EFailed;
907}
908
909CParameterMgr::CommandStatus CParameterMgr::renameDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
910{
911 return getConfigurableDomains()->renameDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? EDone : EFailed;
912}
913
914CParameterMgr::CommandStatus CParameterMgr::listDomainElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
915{
916 return getConfigurableDomains()->listDomainElements(remoteCommand.getArgument(0), strResult) ? ESucceeded : EFailed;
917}
918
919CParameterMgr::CommandStatus CParameterMgr::addElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
920{
921 return addConfigurableElementToDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? EDone : EFailed;
922}
923
924CParameterMgr::CommandStatus CParameterMgr::removeElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
925{
926 return removeConfigurableElementFromDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? EDone : EFailed;
927}
928
929CParameterMgr::CommandStatus CParameterMgr::splitDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
930{
931 return split(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? EDone : EFailed;
932}
933
934/// Configurations
935CParameterMgr::CommandStatus CParameterMgr::listConfigurationsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
936{
937 return getConfigurableDomains()->listConfigurations(remoteCommand.getArgument(0), strResult) ? ESucceeded : EFailed;
938}
939
940CParameterMgr::CommandStatus CParameterMgr::createConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
941{
942 return createConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? EDone : EFailed;
943}
944
945CParameterMgr::CommandStatus CParameterMgr::deleteConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
946{
947 return deleteConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? EDone : EFailed;
948}
949
950CParameterMgr::CommandStatus CParameterMgr::renameConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
951{
952 return getConfigurableDomains()->renameConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), strResult) ? EDone : EFailed;
953}
954
955CParameterMgr::CommandStatus CParameterMgr::saveConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
956{
957 return saveConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? EDone : EFailed;
958}
959
960CParameterMgr::CommandStatus CParameterMgr::restoreConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
961{
962 return restoreConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? EDone : EFailed;
963}
964
965/// Elements/Parameters
966CParameterMgr::CommandStatus CParameterMgr::listElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
967{
968 CElementLocator elementLocator(getSystemClass(), false);
969
970 CElement* pLocatedElement = NULL;
971
972 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
973
974 return EFailed;
975 }
976
977 strResult = string("\n");
978
979 if (!pLocatedElement) {
980
981 // List from root folder
982
983 // Return system class qualified name
984 pLocatedElement = getSystemClass();
985 }
986
987 // Return sub-elements
988 strResult += pLocatedElement->listQualifiedPaths(false);
989
990 return ESucceeded;
991}
992
993/// Elements/Parameters
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200994CParameterMgr::CommandStatus CParameterMgr::listParametersCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200995{
996 CElementLocator elementLocator(getSystemClass(), false);
997
998 CElement* pLocatedElement = NULL;
999
1000 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1001
1002 return EFailed;
1003 }
1004
1005 strResult = string("\n");
1006
1007 if (!pLocatedElement) {
1008
1009 // List from root folder
1010
1011 // Return system class qualified name
1012 pLocatedElement = getSystemClass();
1013 }
1014
1015 // Return sub-elements
1016 strResult += pLocatedElement->listQualifiedPaths(true);
1017
1018 return ESucceeded;
1019}
1020
1021CParameterMgr::CommandStatus CParameterMgr::dumpElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1022{
1023 CElementLocator elementLocator(getSystemClass());
1024
1025 CElement* pLocatedElement = NULL;
1026
1027 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1028
1029 return EFailed;
1030 }
1031
1032 string strError;
1033
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001034 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001035
1036 // Dump elements
1037 pLocatedElement->dumpContent(strResult, parameterAccessContext);
1038
1039 return ESucceeded;
1040}
1041
1042CParameterMgr::CommandStatus CParameterMgr::getElementSizeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1043{
1044 CElementLocator elementLocator(getSystemClass());
1045
1046 CElement* pLocatedElement = NULL;
1047
1048 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1049
1050 return EFailed;
1051 }
1052
1053 // Converted to actual sizable element
1054 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1055
1056 // Get size as string
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001057 strResult = pConfigurableElement->getFootprintAsString();
Patrick Benavoli68a91282011-08-31 11:23:23 +02001058
1059 return ESucceeded;
1060}
1061
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001062CParameterMgr::CommandStatus CParameterMgr::showPropertiesCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1063{
1064 CElementLocator elementLocator(getSystemClass());
1065
1066 CElement* pLocatedElement = NULL;
1067
1068 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1069
1070 return EFailed;
1071 }
1072
1073 // Convert element
1074 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1075
1076 // Return element properties
1077 pConfigurableElement->showProperties(strResult);
1078
1079 return ESucceeded;
1080}
1081
Patrick Benavoli68a91282011-08-31 11:23:23 +02001082CParameterMgr::CommandStatus CParameterMgr::getParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1083{
1084 string strValue;
1085
1086 if (!getValue(remoteCommand.getArgument(0), strValue, strResult)) {
1087
1088 return EFailed;
1089 }
1090 // Succeeded
1091 strResult = strValue;
1092
1093 return ESucceeded;
1094}
1095
1096CParameterMgr::CommandStatus CParameterMgr::setParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1097{
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001098 return setValue(remoteCommand.getArgument(0), remoteCommand.packArguments(1, remoteCommand.getArgumentCount() - 1), strResult) ? EDone : EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001099}
1100
1101CParameterMgr::CommandStatus CParameterMgr::listBelongingDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1102{
1103 CElementLocator elementLocator(getSystemClass());
1104
1105 CElement* pLocatedElement = NULL;
1106
1107 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1108
1109 return EFailed;
1110 }
1111
1112 // Convert element
1113 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1114
1115 // Return element belonging domains
1116 pConfigurableElement->listBelongingDomains(strResult);
1117
1118 return ESucceeded;
1119}
1120
1121CParameterMgr::CommandStatus CParameterMgr::listAssociatedDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1122{
1123 CElementLocator elementLocator(getSystemClass());
1124
1125 CElement* pLocatedElement = NULL;
1126
1127 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1128
1129 return EFailed;
1130 }
1131
1132 // Convert element
1133 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1134
1135 // Return element belonging domains
1136 pConfigurableElement->listAssociatedDomains(strResult);
1137
1138 return ESucceeded;
1139}
1140
1141CParameterMgr::CommandStatus CParameterMgr::listAssociatedElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1142{
1143 (void)remoteCommand;
1144
1145 getConfigurableDomains()->listAssociatedElements(strResult);
1146
1147 return ESucceeded;
1148}
1149
1150CParameterMgr::CommandStatus CParameterMgr::listConflictingElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1151{
1152 (void)remoteCommand;
1153
1154 getConfigurableDomains()->listConflictingElements(strResult);
1155
1156 return ESucceeded;
1157}
1158
1159CParameterMgr::CommandStatus CParameterMgr::listRogueElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1160{
1161 (void)remoteCommand;
1162
1163 getSystemClass()->listRogueElements(strResult);
1164
1165 return ESucceeded;
1166}
1167
1168/// Settings Import/Export
1169CParameterMgr::CommandStatus CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1170{
1171 return exportDomainsXml(remoteCommand.getArgument(0), false, strResult) ? EDone : EFailed;
1172}
1173
1174CParameterMgr::CommandStatus CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1175{
1176 return importDomainsXml(remoteCommand.getArgument(0), false, strResult) ? EDone : EFailed;
1177}
1178
1179CParameterMgr::CommandStatus CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1180{
1181 return exportDomainsXml(remoteCommand.getArgument(0), true, strResult) ? EDone : EFailed;
1182}
1183
1184CParameterMgr::CommandStatus CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1185{
1186 return importDomainsXml(remoteCommand.getArgument(0), true, strResult) ? EDone : EFailed;
1187}
1188
1189CParameterMgr::CommandStatus CParameterMgr::exportSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1190{
1191 return exportDomainsBinary(remoteCommand.getArgument(0), strResult) ? EDone : EFailed;
1192}
1193
1194CParameterMgr::CommandStatus CParameterMgr::importSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1195{
1196 return importDomainsBinary(remoteCommand.getArgument(0), strResult) ? EDone : EFailed;
1197}
1198
1199// User set/get parameters
1200bool CParameterMgr::setValue(const string& strPath, const string& strValue, string& strError)
1201{
1202 // Check tuning mode
1203 if (!checkTuningModeOn(strError)) {
1204
1205 return false;
1206 }
1207
1208 CPathNavigator pathNavigator(strPath);
1209
1210 if (!pathNavigator.isPathValid()) {
1211
1212 strError = "Path not well formed";
1213
1214 return false;
1215 }
1216
1217 string* pStrChildName = pathNavigator.next();
1218
1219 if (!pStrChildName) {
1220
1221 strError = "Non settable element";
1222
1223 return false;
1224 }
1225
1226 if (*pStrChildName != getSystemClass()->getName()) {
1227
1228 strError = "Path not found";
1229
1230 return false;
1231 }
1232
1233 // Define context
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001234 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001235
1236 // Set auto sync
1237 parameterAccessContext.setAutoSync(_bAutoSyncOn);
1238
1239 // Do the set
1240 return getSystemClass()->setValue(pathNavigator, strValue, parameterAccessContext);
1241}
1242
1243bool CParameterMgr::getValue(const string& strPath, string& strValue, string& strError) const
1244{
1245 CPathNavigator pathNavigator(strPath);
1246
1247 if (!pathNavigator.isPathValid()) {
1248
1249 strError = "Path not well formed";
1250
1251 return false;
1252 }
1253
1254 string* pStrChildName = pathNavigator.next();
1255
1256 if (!pStrChildName) {
1257
1258 strError = "Non settable element";
1259
1260 return false;
1261 }
1262
1263 if (*pStrChildName != getConstSystemClass()->getName()) {
1264
1265 strError = "Path not found";
1266
1267 return false;
1268 }
1269
1270 // Define context
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001271 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001272
1273 // Do the get
1274 return getConstSystemClass()->getValue(pathNavigator, strValue, parameterAccessContext);
1275}
1276
1277// Tuning mode
1278bool CParameterMgr::setTuningMode(bool bOn, string& strError)
1279{
1280 // Tuning allowed?
1281 if (bOn && !_pSystemClassConfiguration->isTuningAllowed()) {
1282
1283 strError = "Tuning prohibited";
1284
1285 return false;
1286 }
1287 // Lock state
Patrick Benavoli1387bda2011-08-31 11:23:24 +02001288 CAutoLock autoLock(&_tuningModeMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001289
1290 // Warn domains about exiting tuning mode
1291 if (!bOn && _bTuningModeIsOn) {
1292
1293 // Ensure application of currently selected configurations
Patrick Benavoli1387bda2011-08-31 11:23:24 +02001294 // Force-apply configurations
Patrick Benavoli68a91282011-08-31 11:23:23 +02001295 if (!getConfigurableDomains()->apply(_pMainParameterBlackboard, true, strError)) {
1296
1297 return false;
1298 }
1299 // Turn auto sync back on
1300 _bAutoSyncOn = true;
1301 }
1302
1303 // Store
1304 _bTuningModeIsOn = bOn;
1305
Patrick Benavoli68a91282011-08-31 11:23:23 +02001306 return true;
1307}
1308
1309bool CParameterMgr::tuningModeOn() const
1310{
1311 return _bTuningModeIsOn;
1312}
1313
1314// Current value space for user set/get value interpretation
1315void CParameterMgr::setValueSpace(bool bIsRaw)
1316{
1317 _bValueSpaceIsRaw = bIsRaw;
1318}
1319
1320bool CParameterMgr::valueSpaceIsRaw()
1321{
1322 return _bValueSpaceIsRaw;
1323}
1324
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001325// Current Output Raw Format for user get value interpretation
1326void CParameterMgr::setOutputRawFormat(bool bIsHex)
1327{
1328 _bOutputRawFormatIsHex = bIsHex;
1329}
1330
1331bool CParameterMgr::outputRawFormatIsHex()
1332{
1333 return _bOutputRawFormatIsHex;
1334}
1335
Patrick Benavoli68a91282011-08-31 11:23:23 +02001336/// Sync
1337// Automatic hardware synchronization control (during tuning session)
1338bool CParameterMgr::setAutoSync(bool bAutoSyncOn, string& strError)
1339{
1340 // Check tuning mode
1341 if (!checkTuningModeOn(strError)) {
1342
1343 return false;
1344 }
1345 // Warn domains about turning auto sync back on
1346 if (bAutoSyncOn && !_bAutoSyncOn) {
1347
Patrick Benavoli592ae562011-09-05 16:53:58 +02001348 // Do the synchronization at system class level (could be optimized by keeping track of all modified parameters)
1349 if (!sync(strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001350
1351 return false;
1352 }
1353 }
1354
1355 // Set Auto sync
1356 _bAutoSyncOn = bAutoSyncOn;
1357
1358 return true;
1359}
1360
1361bool CParameterMgr::autoSyncOn() const
1362{
1363 return _bAutoSyncOn;
1364}
1365
1366// Manual hardware synchronization control (during tuning session)
1367bool CParameterMgr::sync(string& strError)
1368{
1369 // Check tuning mode
1370 if (!checkTuningModeOn(strError)) {
1371
1372 return false;
1373 }
1374 // Warn domains about turning auto sync back on
1375 if (_bAutoSyncOn) {
1376
1377 strError = "Feature unavailable when Auto Sync is on";
1378
1379 return false;
1380 }
1381
1382 // Get syncer set
1383 CSyncerSet syncerSet;
1384 // ... from system class
1385 getConstSystemClass()->fillSyncerSet(syncerSet);
1386 // Sync
1387 return syncerSet.sync(*_pMainParameterBlackboard, false, strError);
1388}
1389
1390// Content dump
1391void CParameterMgr::logStructureContent(string& strContent) const
1392{
1393 string strError;
1394
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001395 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001396
1397 dumpContent(strContent, parameterAccessContext);
1398}
1399
1400// Configuration/Domains handling
1401bool CParameterMgr::createDomain(const string& strName, string& strError)
1402{
1403 // Check tuning mode
1404 if (!checkTuningModeOn(strError)) {
1405
1406 return false;
1407 }
1408
1409 // Delegate to configurable domains
1410 return getConfigurableDomains()->createDomain(strName, strError);
1411}
1412
1413bool CParameterMgr::deleteDomain(const string& strName, string& strError)
1414{
1415 // Check tuning mode
1416 if (!checkTuningModeOn(strError)) {
1417
1418 return false;
1419 }
1420
1421 // Delegate to configurable domains
1422 return getConfigurableDomains()->deleteDomain(strName, strError);
1423}
1424
1425bool CParameterMgr::createConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1426{
1427 // Check tuning mode
1428 if (!checkTuningModeOn(strError)) {
1429
1430 return false;
1431 }
1432
1433 // Delegate to configurable domains
1434 return getConfigurableDomains()->createConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1435}
1436
1437bool CParameterMgr::deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1438{
1439 // Check tuning mode
1440 if (!checkTuningModeOn(strError)) {
1441
1442 return false;
1443 }
1444
1445 // Delegate to configurable domains
1446 return getConfigurableDomains()->deleteConfiguration(strDomain, strConfiguration, strError);
1447}
1448
1449bool CParameterMgr::restoreConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1450{
1451 // Check tuning mode
1452 if (!checkTuningModeOn(strError)) {
1453
1454 return false;
1455 }
1456
1457 // Delegate to configurable domains
1458 return getConfigurableDomains()->restoreConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, strError);
1459}
1460
1461bool CParameterMgr::saveConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1462{
1463 // Check tuning mode
1464 if (!checkTuningModeOn(strError)) {
1465
1466 return false;
1467 }
1468
1469 // Delegate to configurable domains
1470 return getConfigurableDomains()->saveConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1471}
1472
1473// Configurable element - domain association
1474bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1475{
1476 // Check tuning mode
1477 if (!checkTuningModeOn(strError)) {
1478
1479 return false;
1480 }
1481
1482 CElementLocator elementLocator(getSystemClass());
1483
1484 CElement* pLocatedElement = NULL;
1485
1486 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1487
1488 return false;
1489 }
1490
1491 // Convert element
1492 CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1493
1494 // Delegate
1495 return getConfigurableDomains()->addConfigurableElementToDomain(strDomain, pConfigurableElement, _pMainParameterBlackboard, strError);
1496}
1497
1498bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1499{
1500 // Check tuning mode
1501 if (!checkTuningModeOn(strError)) {
1502
1503 return false;
1504 }
1505
1506 CElementLocator elementLocator(getSystemClass());
1507
1508 CElement* pLocatedElement = NULL;
1509
1510 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1511
1512 return EFailed;
1513 }
1514
1515 // Convert element
1516 CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1517
1518 // Delegate
1519 return getConfigurableDomains()->removeConfigurableElementFromDomain(strDomain, pConfigurableElement, strError);
1520}
1521
1522bool CParameterMgr::split(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1523{
1524 // Check tuning mode
1525 if (!checkTuningModeOn(strError)) {
1526
1527 return false;
1528 }
1529
1530 CElementLocator elementLocator(getSystemClass());
1531
1532 CElement* pLocatedElement = NULL;
1533
1534 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1535
1536 return EFailed;
1537 }
1538
1539 // Convert element
1540 CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1541
1542 // Delegate
1543 return getConfigurableDomains()->split(strDomain, pConfigurableElement, strError);
1544}
1545
1546// XML Import/Export
1547bool CParameterMgr::importDomainsXml(const string& strFileName, bool bWithSettings, string& strError)
1548{
1549 // Check tuning mode
1550 if (!checkTuningModeOn(strError)) {
1551
1552 return false;
1553 }
1554
1555 // check path is absolute
1556 if (strFileName[0] != '/') {
1557
1558 strError = "Please provide absolute path";
1559
1560 return false;
1561 }
1562 // Root element
1563 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1564
1565 // Context
1566 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1567
1568 // Secltion criteria definition for rule creation
1569 xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
1570
1571 // Parse
1572 if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strFileName, "", EParameterConfigurationLibrary, "SystemClassName")) {
1573
1574 return false;
1575 }
1576
1577 // Validate domains after XML import
1578 pConfigurableDomains->validate(_pMainParameterBlackboard);
1579
1580 return true;
1581}
1582
1583bool CParameterMgr::exportDomainsXml(const string& strFileName, bool bWithSettings, string& strError) const
1584{
1585 // check path is absolute
1586 if (strFileName[0] != '/') {
1587
1588 strError = "Please provide absolute path";
1589
1590 return false;
1591 }
1592
1593 // Root element
1594 const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains();
1595
1596 // Get Schema file associated to root element
1597 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pConfigurableDomains->getKind() + ".xsd";
1598
1599 // Context
1600 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1601
1602 // Value space
1603 xmlDomainSerializingContext.setValueSpaceRaw(_bValueSpaceIsRaw);
1604
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001605 // Output raw format
1606 xmlDomainSerializingContext.setOutputRawFormat(_bOutputRawFormatIsHex);
1607
Patrick Benavoli68a91282011-08-31 11:23:23 +02001608 // Instantiate composer
1609 CXmlComposer xmlComposer(strFileName, strXmlSchemaFilePath, pConfigurableDomains->getKind(), xmlDomainSerializingContext);
1610
1611 // Open composer
1612 if (!xmlComposer.open()) {
1613
1614 return false;
1615 }
1616
1617 // Compose
1618 xmlComposer.compose(pConfigurableDomains);
1619
1620 // Close composer
1621 if (!xmlComposer.close()) {
1622
1623 return false;
1624 }
1625
1626 return true;
1627}
1628
1629// Binary Import/Export
1630bool CParameterMgr::importDomainsBinary(const string& strFileName, string& strError)
1631{
1632 // Check tuning mode
1633 if (!checkTuningModeOn(strError)) {
1634
1635 return false;
1636 }
1637 // check path is absolute
1638 if (strFileName[0] != '/') {
1639
1640 strError = "Please provide absolute path";
1641
1642 return false;
1643 }
1644 // Root element
1645 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1646
1647 // Serialize in
1648 return pConfigurableDomains->serializeSettings(strFileName, false, _uiStructureChecksum, strError);
1649}
1650
1651bool CParameterMgr::exportDomainsBinary(const string& strFileName, string& strError)
1652{
1653 // check path is absolute
1654 if (strFileName[0] != '/') {
1655
1656 strError = "Please provide absolute path";
1657
1658 return false;
1659 }
1660 // Check tuning mode
1661 if (!checkTuningModeOn(strError)) {
1662
1663 return false;
1664 }
1665 // Root element
1666 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1667
1668 // Serialize out
1669 return pConfigurableDomains->serializeSettings(strFileName, true, _uiStructureChecksum, strError);
1670}
1671
1672// For tuning, check we're in tuning mode
1673bool CParameterMgr::checkTuningModeOn(string& strError) const
1674{
1675 // Tuning Mode on?
1676 if (!_bTuningModeIsOn) {
1677
1678 strError = "Tuning Mode must be on";
1679
1680 return false;
1681 }
1682 return true;
1683}
1684
1685// Dynamic creation library feeding
1686void CParameterMgr::feedElementLibraries()
1687{
1688 // Global Configuration handling
1689 CElementLibrary* pFrameworkConfigurationLibrary = new CElementLibrary;
1690
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001691 pFrameworkConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CParameterFrameworkConfiguration>("ParameterFrameworkConfiguration"));
1692 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationGroup>("SubsystemPluginFolders"));
1693 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("PluginFolderLocation"));
1694 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationGroup>("ParameterConfiguration"));
1695 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CSystemClassConfiguration>("SystemClassConfiguration"));
1696 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("StructureDescriptionFileLocation"));
1697 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationGroup>("SettingsConfiguration"));
1698 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("ConfigurableDomainsFileLocation"));
1699 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("BinarySettingsFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001700
1701 _pElementLibrarySet->addElementLibrary(pFrameworkConfigurationLibrary);
1702
1703 // Parameter creation
1704 CElementLibrary* pParameterCreationLibrary = new CElementLibrary;
1705
1706 pParameterCreationLibrary->addElementBuilder(new CSubsystemElementBuilder(getSystemClass()->getSubsystemLibrary()));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001707 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CComponentType>("ComponentType"));
1708 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CComponentInstance>("Component"));
1709 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBitParameterType>("BitParameter"));
1710 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBitParameterBlockType>("BitParameterBlock"));
1711 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CParameterBlockType>("ParameterBlock"));
1712 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBooleanParameterType>("BooleanParameter"));
1713 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CIntegerParameterType>("IntegerParameter"));
1714 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CFixedPointParameterType>("FixedPointParameter"));
1715 pParameterCreationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CXmlFileIncluderElement>("SubsystemInclude"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001716
1717 _pElementLibrarySet->addElementLibrary(pParameterCreationLibrary);
1718
1719 // Parameter Configuration Domains creation
1720 CElementLibrary* pParameterConfigurationLibrary = new CElementLibrary;
1721
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001722 pParameterConfigurationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CConfigurableDomain>("ConfigurableDomain"));
1723 pParameterConfigurationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CDomainConfiguration>("Configuration"));
1724 pParameterConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CCompoundRule>("CompoundRule"));
1725 pParameterConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CSelectionCriterionRule>("SelectionCriterionRule"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001726
1727 _pElementLibrarySet->addElementLibrary(pParameterConfigurationLibrary);
1728}
1729
1730// Remote Processor Server connection handling
1731bool CParameterMgr::handleRemoteProcessingInterface(string& strError)
1732{
1733 CAutoLog autoLog(this, "Handling remote processing interface");
1734
1735 // Start server if tuning allowed
1736 if (_pSystemClassConfiguration->isTuningAllowed()) {
1737
1738 log("Loading remote processor library");
1739
1740 // Load library
1741 void* lib_handle = dlopen("libremote-processor.so", RTLD_NOW);
1742
1743 if (!lib_handle) {
1744
1745 // Return error
1746 const char* pcError = dlerror();
1747
1748 if (pcError) {
1749
1750 strError = pcError;
1751 } else {
1752
1753 strError = "Unable to load libremote-processor.so library";
1754 }
1755
1756 return false;
1757 }
1758
1759 CreateRemoteProcessorServer pfnCreateRemoteProcessorServer = (CreateRemoteProcessorServer)dlsym(lib_handle, "createRemoteProcessorServer");
1760
1761 if (!pfnCreateRemoteProcessorServer) {
1762
1763 strError = "libremote-process.so does not contain createRemoteProcessorServer symbol.";
1764
1765 return false;
1766 }
1767
1768 // Create server
1769 _pRemoteProcessorServer = pfnCreateRemoteProcessorServer(_pSystemClassConfiguration->getServerPort(), this);
1770
1771 // Compute max command usage length
1772 setMaxCommandUsageLength();
1773
1774 log("Starting remote processor server on port %d", _pSystemClassConfiguration->getServerPort());
1775 // 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}