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