blob: 87f66621e4215c8882787d706963733df20e791c [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
104const CParameterMgr::SRemoteCommandParserItem CParameterMgr::gaRemoteCommandParserItems[] = {
105 /// Help
106 { "help", &CParameterMgr::helpCommandProcess, 0, "", "Show commands description and usage" },
107 /// Status
108 { "status", &CParameterMgr::statusCommandProcess, 0, "", "Show current status" },
109 /// Tuning Mode
110 { "setTuningMode", &CParameterMgr::setTuningModeCommmandProcess, 1, "on|off*", "Turn on or off Tuning Mode" },
111 { "getTuningMode", &CParameterMgr::getTuningModeCommmandProcess, 0, "", "Show Tuning Mode" },
112 /// Value Space
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200113 { "setValueSpace", &CParameterMgr::setValueSpaceCommmandProcess, 1, "raw|real*", "Assigns Value Space used for parameter value interpretation" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200114 { "getValueSpace", &CParameterMgr::getValueSpaceCommmandProcess, 0, "", "Show Value Space" },
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200115 /// Output Raw Format
116 { "setOutputRawFormat", &CParameterMgr::setOutputRawFormatCommmandProcess, 1, "dec*|hex", "Assigns format used to output parameter values when in raw Value Space" },
117 { "getOutputRawFormat", &CParameterMgr::getOutputRawFormatCommmandProcess, 0, "", "Show Output Raw Format" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200118 /// Sync
119 { "setAutoSync", &CParameterMgr::setAutoSyncCommmandProcess, 1, "on*|off", "Turn on or off automatic synchronization to hardware while in Tuning Mode" },
120 { "getAutoSync", &CParameterMgr::getAutoSyncCommmandProcess, 0, "", "Show Auto Sync state" },
121 { "sync", &CParameterMgr::syncCommmandProcess, 0, "", "Synchronize current settings to hardware while in Tuning Mode and Auto Sync off" },
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200122 /// Criteria
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200123 { "listCriteria", &CParameterMgr::listCriteriaCommmandProcess, 0, "", "List selection criteria" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200124 /// Domains
125 { "listDomains", &CParameterMgr::listDomainsCommmandProcess, 0, "", "List configurable domains" },
126 { "createDomain", &CParameterMgr::createDomainCommmandProcess, 1, "<domain>", "Create new configurable domain" },
127 { "deleteDomain", &CParameterMgr::deleteDomainCommmandProcess, 1, "<domain>", "Delete configurable domain" },
128 { "renameDomain", &CParameterMgr::renameDomainCommmandProcess, 2, "<domain> <new name>", "Rename configurable domain" },
129 { "listDomainElements", &CParameterMgr::listDomainElementsCommmandProcess, 1, "<domain>", "List elements associated to configurable domain" },
130 { "addElement", &CParameterMgr::addElementCommmandProcess, 2, "<domain> <elem path>", "Associate element at given path to configurable domain" },
131 { "removeElement", &CParameterMgr::removeElementCommmandProcess, 2, "<domain> <elem path>", "Dissociate element at given path from configurable domain" },
132 { "splitDomain", &CParameterMgr::splitDomainCommmandProcess, 2, "<domain> <elem path>", "Split configurable domain at given associated element path" },
133 /// Configurations
134 { "listConfigurations", &CParameterMgr::listConfigurationsCommmandProcess, 1, "<domain>", "List domain configurations" },
135 { "createConfiguration", &CParameterMgr::createConfigurationCommmandProcess, 2, "<domain> <configuration>", "Create new domain configuration" },
136 { "deleteConfiguration", &CParameterMgr::deleteConfigurationCommmandProcess, 2, "<domain> <configuration>", "Delete domain configuration" },
137 { "renameConfiguration", &CParameterMgr::renameConfigurationCommmandProcess, 3, "<domain> <configuration> <new name>", "Rename domain configuration" },
138 { "saveConfiguration", &CParameterMgr::saveConfigurationCommmandProcess, 2, "<domain> <configuration>", "Save current settings into configuration" },
139 { "restoreConfiguration", &CParameterMgr::restoreConfigurationCommmandProcess, 2, "<domain> <configuration>", "Restore current settings from configuration" },
140 /// Elements/Parameters
141 { "listElements", &CParameterMgr::listElementsCommmandProcess, 1, "<elem path>|/", "List elements under element at given path or root" },
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200142 { "listParameters", &CParameterMgr::listParametersCommmandProcess, 1, "<elem path>|/", "Recursively list elements under element at given path or root" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200143 { "dumpElement", &CParameterMgr::dumpElementCommmandProcess, 1, "<elem path>", "Dump structure and content of element at given path" },
144 { "getElementSize", &CParameterMgr::getElementSizeCommmandProcess, 1, "<elem path>", "Show size of element at given path" },
Patrick Benavoli2ecf9002011-08-31 11:23:24 +0200145 { "showProperties", &CParameterMgr::showPropertiesCommmandProcess, 1, "<elem path>", "Show properties of element at given path" },
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200146 { "getParameter", &CParameterMgr::getParameterCommmandProcess, 1, "<param path>", "Get value for parameter at given path" },
Patrick Benavoli2ecf9002011-08-31 11:23:24 +0200147 { "setParameter", &CParameterMgr::setParameterCommmandProcess, 2, "<param path> <value>", "Set value for parameter at given path" },
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200148 { "listBelongingDomains", &CParameterMgr::listBelongingDomainsCommmandProcess, 1, "<elem path>", "List domain(s) element at given path belongs to" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200149 { "listAssociatedDomains", &CParameterMgr::listAssociatedDomainsCommmandProcess, 1, "<elem path>", "List domain(s) element at given path is associated to" },
150 /// Browse
151 { "listAssociatedElements", &CParameterMgr::listAssociatedElementsCommmandProcess, 0, "", "List element sub-trees associated to at least one configurable domain" },
152 { "listConflictingElements", &CParameterMgr::listConflictingElementsCommmandProcess, 0, "", "List element sub-trees contained in more than one configurable domain" },
153 { "listRogueElements", &CParameterMgr::listRogueElementsCommmandProcess, 0, "", "List element sub-trees owned by no configurable domain" },
154 /// Settings Import/Export
155 { "exportDomainsXML", &CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess, 1, "<file path> ", "Export domains to XML file" },
156 { "importDomainsXML", &CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess, 1, "<file path>", "Import domains from XML file" },
157 { "exportDomainsWithSettingsXML", &CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess, 1, "<file path> ", "Export domains including settings to XML file" },
158 { "importDomainsWithSettingsXML", &CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess, 1, "<file path>", "Import domains including settings from XML file" },
159 { "exportSettings", &CParameterMgr::exportSettingsCommmandProcess, 1, "<file path>", "Export settings to binary file" },
160 { "importSettings", &CParameterMgr::importSettingsCommmandProcess, 1, "<file path>", "Import settings from binary file" }
161};
162// Remote command parsers array Size
163const uint32_t CParameterMgr::guiNbRemoteCommandParserItems = sizeof(gaRemoteCommandParserItems) / sizeof(gaRemoteCommandParserItems[0]);
164
165CParameterMgr::CParameterMgr(const string& strParameterFrameworkConfigurationFolderPath, const string& strSystemClassName) :
166 _bTuningModeIsOn(false),
167 _bValueSpaceIsRaw(false),
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200168 _bOutputRawFormatIsHex(false),
Patrick Benavoli68a91282011-08-31 11:23:23 +0200169 _bAutoSyncOn(true),
170 _pMainParameterBlackboard(new CParameterBlackboard),
171 _pElementLibrarySet(new CElementLibrarySet),
172 _strParameterFrameworkConfigurationFolderPath(strParameterFrameworkConfigurationFolderPath),
173 _strSchemaFolderLocation(strParameterFrameworkConfigurationFolderPath + "/" + gacSystemSchemasSubFolder),
174 _pSystemClassConfiguration(NULL),
175 _uiStructureChecksum(0),
176 _pRemoteProcessorServer(NULL),
177 _uiMaxCommandUsageLength(0),
178 _pLogger(NULL),
179 _uiLogDepth(0)
180{
181 // Tuning Mode Mutex
182 bzero(&_tuningModeMutex, sizeof(_tuningModeMutex));
183 pthread_mutex_init(&_tuningModeMutex, NULL);
184
185 // Deal with children
186 addChild(new CParameterFrameworkConfiguration);
187 addChild(new CSelectionCriteria);
188 addChild(new CSystemClass(strSystemClassName));
189 addChild(new CConfigurableDomains(strSystemClassName));
190
191 // Feed element library
192 feedElementLibraries();
193}
194
195CParameterMgr::~CParameterMgr()
196{
197 // Children
198 delete _pRemoteProcessorServer;
199 delete _pMainParameterBlackboard;
200 delete _pElementLibrarySet;
201
202 // Tuning Mode Mutex
203 pthread_mutex_destroy(&_tuningModeMutex);
204}
205
206string CParameterMgr::getKind() const
207{
208 return "ParameterMgr";
209}
210
211// Logging
212void CParameterMgr::setLogger(CParameterMgr::ILogger* pLogger)
213{
214 _pLogger = pLogger;
215}
216
217// Logging
218void CParameterMgr::doLog(const string& strLog) const
219{
220 if (_pLogger) {
221
222 // Nest
223 string strIndent;
224
225 // Level
226 uint32_t uiNbIndents = _uiLogDepth;
227
228 while (uiNbIndents--) {
229
230 strIndent += " ";
231 }
232
233 // Log
234 _pLogger->log(strIndent + strLog);
235 }
236}
237
238void CParameterMgr::nestLog() const
239{
240 ((uint32_t&)_uiLogDepth)++;
241}
242
243void CParameterMgr::unnestLog() const
244{
245 ((uint32_t&)_uiLogDepth)--;
246}
247
248bool CParameterMgr::load(string& strError)
249{
250 CAutoLog autoLog(this, "Loading");
251
252 // Load Framework configuration
253 if (!loadFrameworkConfiguration(strError)) {
254
255 return false;
256 }
257
258 // Load subsystems
259 if (!getSystemClass()->loadSubsystems(strError, _astrPluginFolderPaths)) {
260
261 return false;
262 }
263
264 // Load structure
265 if (!loadStructure(strError)) {
266
267 return false;
268 }
269
270 // Load settings
271 if (!loadSettings(strError)) {
272
273 return false;
274 }
275
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200276 // Back synchronization for areas in parameter blackboard not covered by any domain
277 CBackSynchronizer* pBackSynchronizer = createBackSynchronizer(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200278
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200279 log("Main blackboard back synchronization");
280
281 // Back-synchronize
282 if (!pBackSynchronizer->sync()) {
283 // Get rid of back synchronizer
284 delete pBackSynchronizer;
285
286 strError = "Main blackboard back synchronization failed: " + strError;
287
288 return false;
289 }
290 // Get rif of back synchronizer
291 delete pBackSynchronizer;
292
293 // We're done loading the settings and back synchronizing
294 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
295
296 // We need to ensure all domains are valid
297 pConfigurableDomains->validate(_pMainParameterBlackboard);
298
299 // Ensure application of currently selected configurations
300 // Force-apply configurations
301 if (!pConfigurableDomains->apply(_pMainParameterBlackboard, true, strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200302
303 return false;
304 }
305
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200306 // All is loaded, we're ready to observe selection criteria change events
307 getSelectionCriteria()->setObserver(this);
308
309 // 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
555// Selection criteria changed event
556void CParameterMgr::selectionCriterionChanged(const CSelectionCriterion* pSelectionCriterion)
557{
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200558 CAutoLog autoLog(this, "Selection criterion changed event: " + pSelectionCriterion->getFormattedDescription(false));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200559
560 // Lock state
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200561 CAutoLock autoLock(&_tuningModeMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200562
563 if (!_bTuningModeIsOn) {
564
565 // Apply configuration(s)
566 string strError;
567
568 if (!getConfigurableDomains()->apply(_pMainParameterBlackboard, false, strError)) {
569
570 log("Failed to apply configurations!");
571 }
572 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200573}
574
575// Command processing
576bool CParameterMgr::remoteCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
577{
578 log("Processing remote command: \"%s\"", remoteCommand.getCommand().c_str());
579
580 // Dispatch
581 uint32_t uiRemoteCommandParserItem;
582
583 for (uiRemoteCommandParserItem = 0; uiRemoteCommandParserItem < guiNbRemoteCommandParserItems; uiRemoteCommandParserItem++) {
584
585 const SRemoteCommandParserItem* pRemoteCommandParserItem = &gaRemoteCommandParserItems[uiRemoteCommandParserItem];
586
587 if (string(pRemoteCommandParserItem->_pcCommandName) == remoteCommand.getCommand()) {
588
589 // Check enough arguments supplied
590 if (remoteCommand.getArgumentCount() < pRemoteCommandParserItem->_uiMinArgumentCount) {
591
592 strResult = string("Not enough arguments supplied\nUsage:\n") + pRemoteCommandParserItem->usage();
593
594 return false;
595 }
596
597 switch ((this->*pRemoteCommandParserItem->_pfnParser)(remoteCommand, strResult)) {
598 case EDone:
599 strResult = "Done";
600 case ESucceeded:
601 return true;
602 case EShowUsgae:
603 strResult = pRemoteCommandParserItem->usage();
604 // Fall through intentionally
605 case EFailed:
606 return false;
607 default:
608 assert(0);
609 }
610 }
611 }
612 // Not found
613 strResult = "Command not found!";
614
615 return false;
616}
617
618// Max command usage length, use for formatting
619void CParameterMgr::setMaxCommandUsageLength()
620{
621 // Show usages
622 uint32_t uiRemoteCommandParserItem;
623
624 for (uiRemoteCommandParserItem = 0; uiRemoteCommandParserItem < guiNbRemoteCommandParserItems; uiRemoteCommandParserItem++) {
625
626 const SRemoteCommandParserItem* pRemoteCommandParserItem = &gaRemoteCommandParserItems[uiRemoteCommandParserItem];
627
628 uint32_t uiRemoteCommandUsageLength = pRemoteCommandParserItem->usage().length();
629
630 if (uiRemoteCommandUsageLength > _uiMaxCommandUsageLength) {
631
632 _uiMaxCommandUsageLength = uiRemoteCommandUsageLength;
633 }
634 }
635}
636
637/////////////////// Remote command parsers
638/// Help
639CParameterMgr::CommandStatus CParameterMgr::helpCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
640{
641 (void)remoteCommand;
642
643 strResult = "\n";
644
645 // Show usages
646 uint32_t uiRemoteCommandParserItem;
647
648 for (uiRemoteCommandParserItem = 0; uiRemoteCommandParserItem < guiNbRemoteCommandParserItems; uiRemoteCommandParserItem++) {
649
650 const SRemoteCommandParserItem* pRemoteCommandParserItem = &gaRemoteCommandParserItems[uiRemoteCommandParserItem];
651
652 string strUsage = pRemoteCommandParserItem->usage();
653
654 strResult += strUsage;
655
656 // Align
657 uint32_t uiToSpacesAdd = _uiMaxCommandUsageLength + 5 - strUsage.length();
658
659 while (uiToSpacesAdd--) {
660
661 strResult += " ";
662 }
663
664 strResult += string("=> ") + string(pRemoteCommandParserItem->_pcDescription) + "\n";
665
666 }
667 return ESucceeded;
668}
669
670/// Status
671CParameterMgr::CommandStatus CParameterMgr::statusCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
672{
673 (void)remoteCommand;
674 // System class
675 const CSystemClass* pSystemClass = getSystemClass();
676
Patrick Benavoli68a91282011-08-31 11:23:23 +0200677 // Show status
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200678 /// General section
679 appendTitle(strResult, "General:");
680 // System class
Patrick Benavoli68a91282011-08-31 11:23:23 +0200681 strResult += "System Class: ";
682 strResult += pSystemClass->getName();
683 strResult += "\n";
684
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200685 // Tuning mode
Patrick Benavoli68a91282011-08-31 11:23:23 +0200686 strResult += "Tuning Mode: ";
687 strResult += tuningModeOn() ? "on" : "off";
688 strResult += "\n";
689
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200690 // Value space
Patrick Benavoli68a91282011-08-31 11:23:23 +0200691 strResult += "Value Space: ";
692 strResult += valueSpaceIsRaw() ? "raw" : "real";
693 strResult += "\n";
694
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200695 // Output raw format
696 strResult += "Output Raw Format: ";
697 strResult += outputRawFormatIsHex() ? "hex" : "dec";
698 strResult += "\n";
699
700 // Auto Sync
Patrick Benavoli68a91282011-08-31 11:23:23 +0200701 strResult += "Auto Sync: ";
702 strResult += autoSyncOn() ? "on" : "off";
703 strResult += "\n";
704
705 /// Subsystem list
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200706 appendTitle(strResult, "Subsystems:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200707 string strSubsystemList;
708 pSystemClass->listChildrenPaths(strSubsystemList);
709 strResult += strSubsystemList;
710
711 /// Last applied configurations
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200712 appendTitle(strResult, "Last applied configurations:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200713 string strLastAppliedConfigurations;
714 getConfigurableDomains()->listLastAppliedConfigurations(strLastAppliedConfigurations);
715 strResult += strLastAppliedConfigurations;
716
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200717 /// Criteria states
718 appendTitle(strResult, "Selection criteria:");
719 string strSelectionCriteria;
720 getSelectionCriteria()->listSelectionCriteria(strSelectionCriteria, false);
721 strResult += strSelectionCriteria;
722
Patrick Benavoli68a91282011-08-31 11:23:23 +0200723 return ESucceeded;
724}
725
726/// Tuning Mode
727CParameterMgr::CommandStatus CParameterMgr::setTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
728{
729 if (remoteCommand.getArgument(0) == "on") {
730
731 if (setTuningMode(true, strResult)) {
732
733 return EDone;
734 }
735 } else if (remoteCommand.getArgument(0) == "off") {
736
737 if (setTuningMode(false, strResult)) {
738
739 return EDone;
740 }
741 } else {
742 // Show usage
743 return EShowUsgae;
744 }
745 return EFailed;
746}
747
748CParameterMgr::CommandStatus CParameterMgr::getTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
749{
750 (void)remoteCommand;
751
752 strResult = tuningModeOn() ? "on" : "off";
753
754 return ESucceeded;
755}
756
757/// Value Space
758CParameterMgr::CommandStatus CParameterMgr::setValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
759{
760 (void)strResult;
761
762 if (remoteCommand.getArgument(0) == "raw") {
763
764 setValueSpace(true);
765
766 return EDone;
767
768 } else if (remoteCommand.getArgument(0) == "real") {
769
770 setValueSpace(false);
771
772 return EDone;
773
774 } else {
775 // Show usage
776 return EShowUsgae;
777 }
778 return EFailed;
779}
780
781CParameterMgr::CommandStatus CParameterMgr::getValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
782{
783 (void)remoteCommand;
784
785 strResult = valueSpaceIsRaw() ? "raw" : "real";
786
787 return ESucceeded;
788}
789
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200790/// Output Raw Format
791CParameterMgr::CommandStatus CParameterMgr::setOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
792{
793 (void)strResult;
794
795 if (remoteCommand.getArgument(0) == "hex") {
796
797 setOutputRawFormat(true);
798
799 return EDone;
800
801 } else if (remoteCommand.getArgument(0) == "dec") {
802
803 setOutputRawFormat(false);
804
805 return EDone;
806
807 } else {
808 // Show usage
809 return EShowUsgae;
810 }
811 return EFailed;
812}
813
814CParameterMgr::CommandStatus CParameterMgr::getOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
815{
816 (void)remoteCommand;
817
818 strResult = outputRawFormatIsHex() ? "hex" : "dec";
819
820 return ESucceeded;
821}
822
Patrick Benavoli68a91282011-08-31 11:23:23 +0200823/// Sync
824CParameterMgr::CommandStatus CParameterMgr::setAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
825{
826 if (remoteCommand.getArgument(0) == "on") {
827
828 if (setAutoSync(true, strResult)) {
829
830 return EDone;
831 }
832 } else if (remoteCommand.getArgument(0) == "off") {
833
834 if (setAutoSync(false, strResult)) {
835
836 return EDone;
837 }
838 } else {
839 // Show usage
840 return EShowUsgae;
841 }
842 return EFailed;
843}
844
845CParameterMgr::CommandStatus CParameterMgr::getAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
846{
847 (void)remoteCommand;
848
849 strResult = autoSyncOn() ? "on" : "off";
850
851 return ESucceeded;
852}
853
854CParameterMgr::CommandStatus CParameterMgr::syncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
855{
856 (void)remoteCommand;
857
858 return sync(strResult) ? EDone : EFailed;
859}
860
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200861/// Criteria
862CParameterMgr::CommandStatus CParameterMgr::listCriteriaCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
863{
864 (void)remoteCommand;
865
866 getSelectionCriteria()->listSelectionCriteria(strResult, true);
867
868 return ESucceeded;
869}
Patrick Benavoli68a91282011-08-31 11:23:23 +0200870
871/// Domains
872CParameterMgr::CommandStatus CParameterMgr::listDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
873{
874 (void)remoteCommand;
875
876 getConfigurableDomains()->listChildren(strResult);
877
878 return ESucceeded;
879}
880
881CParameterMgr::CommandStatus CParameterMgr::createDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
882{
883 return createDomain(remoteCommand.getArgument(0), strResult) ? EDone : EFailed;
884}
885
886CParameterMgr::CommandStatus CParameterMgr::deleteDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
887{
888 return deleteDomain(remoteCommand.getArgument(0), strResult) ? EDone : EFailed;
889}
890
891CParameterMgr::CommandStatus CParameterMgr::renameDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
892{
893 return getConfigurableDomains()->renameDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? EDone : EFailed;
894}
895
896CParameterMgr::CommandStatus CParameterMgr::listDomainElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
897{
898 return getConfigurableDomains()->listDomainElements(remoteCommand.getArgument(0), strResult) ? ESucceeded : EFailed;
899}
900
901CParameterMgr::CommandStatus CParameterMgr::addElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
902{
903 return addConfigurableElementToDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? EDone : EFailed;
904}
905
906CParameterMgr::CommandStatus CParameterMgr::removeElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
907{
908 return removeConfigurableElementFromDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? EDone : EFailed;
909}
910
911CParameterMgr::CommandStatus CParameterMgr::splitDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
912{
913 return split(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? EDone : EFailed;
914}
915
916/// Configurations
917CParameterMgr::CommandStatus CParameterMgr::listConfigurationsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
918{
919 return getConfigurableDomains()->listConfigurations(remoteCommand.getArgument(0), strResult) ? ESucceeded : EFailed;
920}
921
922CParameterMgr::CommandStatus CParameterMgr::createConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
923{
924 return createConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? EDone : EFailed;
925}
926
927CParameterMgr::CommandStatus CParameterMgr::deleteConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
928{
929 return deleteConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? EDone : EFailed;
930}
931
932CParameterMgr::CommandStatus CParameterMgr::renameConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
933{
934 return getConfigurableDomains()->renameConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), strResult) ? EDone : EFailed;
935}
936
937CParameterMgr::CommandStatus CParameterMgr::saveConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
938{
939 return saveConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? EDone : EFailed;
940}
941
942CParameterMgr::CommandStatus CParameterMgr::restoreConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
943{
944 return restoreConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? EDone : EFailed;
945}
946
947/// Elements/Parameters
948CParameterMgr::CommandStatus CParameterMgr::listElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
949{
950 CElementLocator elementLocator(getSystemClass(), false);
951
952 CElement* pLocatedElement = NULL;
953
954 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
955
956 return EFailed;
957 }
958
959 strResult = string("\n");
960
961 if (!pLocatedElement) {
962
963 // List from root folder
964
965 // Return system class qualified name
966 pLocatedElement = getSystemClass();
967 }
968
969 // Return sub-elements
970 strResult += pLocatedElement->listQualifiedPaths(false);
971
972 return ESucceeded;
973}
974
975/// Elements/Parameters
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200976CParameterMgr::CommandStatus CParameterMgr::listParametersCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200977{
978 CElementLocator elementLocator(getSystemClass(), false);
979
980 CElement* pLocatedElement = NULL;
981
982 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
983
984 return EFailed;
985 }
986
987 strResult = string("\n");
988
989 if (!pLocatedElement) {
990
991 // List from root folder
992
993 // Return system class qualified name
994 pLocatedElement = getSystemClass();
995 }
996
997 // Return sub-elements
998 strResult += pLocatedElement->listQualifiedPaths(true);
999
1000 return ESucceeded;
1001}
1002
1003CParameterMgr::CommandStatus CParameterMgr::dumpElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1004{
1005 CElementLocator elementLocator(getSystemClass());
1006
1007 CElement* pLocatedElement = NULL;
1008
1009 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1010
1011 return EFailed;
1012 }
1013
1014 string strError;
1015
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001016 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001017
1018 // Dump elements
1019 pLocatedElement->dumpContent(strResult, parameterAccessContext);
1020
1021 return ESucceeded;
1022}
1023
1024CParameterMgr::CommandStatus CParameterMgr::getElementSizeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1025{
1026 CElementLocator elementLocator(getSystemClass());
1027
1028 CElement* pLocatedElement = NULL;
1029
1030 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1031
1032 return EFailed;
1033 }
1034
1035 // Converted to actual sizable element
1036 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1037
1038 // Get size as string
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001039 strResult = pConfigurableElement->getFootprintAsString();
Patrick Benavoli68a91282011-08-31 11:23:23 +02001040
1041 return ESucceeded;
1042}
1043
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001044CParameterMgr::CommandStatus CParameterMgr::showPropertiesCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1045{
1046 CElementLocator elementLocator(getSystemClass());
1047
1048 CElement* pLocatedElement = NULL;
1049
1050 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1051
1052 return EFailed;
1053 }
1054
1055 // Convert element
1056 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1057
1058 // Return element properties
1059 pConfigurableElement->showProperties(strResult);
1060
1061 return ESucceeded;
1062}
1063
Patrick Benavoli68a91282011-08-31 11:23:23 +02001064CParameterMgr::CommandStatus CParameterMgr::getParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1065{
1066 string strValue;
1067
1068 if (!getValue(remoteCommand.getArgument(0), strValue, strResult)) {
1069
1070 return EFailed;
1071 }
1072 // Succeeded
1073 strResult = strValue;
1074
1075 return ESucceeded;
1076}
1077
1078CParameterMgr::CommandStatus CParameterMgr::setParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1079{
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001080 return setValue(remoteCommand.getArgument(0), remoteCommand.packArguments(1, remoteCommand.getArgumentCount() - 1), strResult) ? EDone : EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001081}
1082
1083CParameterMgr::CommandStatus CParameterMgr::listBelongingDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1084{
1085 CElementLocator elementLocator(getSystemClass());
1086
1087 CElement* pLocatedElement = NULL;
1088
1089 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1090
1091 return EFailed;
1092 }
1093
1094 // Convert element
1095 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1096
1097 // Return element belonging domains
1098 pConfigurableElement->listBelongingDomains(strResult);
1099
1100 return ESucceeded;
1101}
1102
1103CParameterMgr::CommandStatus CParameterMgr::listAssociatedDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1104{
1105 CElementLocator elementLocator(getSystemClass());
1106
1107 CElement* pLocatedElement = NULL;
1108
1109 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1110
1111 return EFailed;
1112 }
1113
1114 // Convert element
1115 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1116
1117 // Return element belonging domains
1118 pConfigurableElement->listAssociatedDomains(strResult);
1119
1120 return ESucceeded;
1121}
1122
1123CParameterMgr::CommandStatus CParameterMgr::listAssociatedElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1124{
1125 (void)remoteCommand;
1126
1127 getConfigurableDomains()->listAssociatedElements(strResult);
1128
1129 return ESucceeded;
1130}
1131
1132CParameterMgr::CommandStatus CParameterMgr::listConflictingElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1133{
1134 (void)remoteCommand;
1135
1136 getConfigurableDomains()->listConflictingElements(strResult);
1137
1138 return ESucceeded;
1139}
1140
1141CParameterMgr::CommandStatus CParameterMgr::listRogueElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1142{
1143 (void)remoteCommand;
1144
1145 getSystemClass()->listRogueElements(strResult);
1146
1147 return ESucceeded;
1148}
1149
1150/// Settings Import/Export
1151CParameterMgr::CommandStatus CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1152{
1153 return exportDomainsXml(remoteCommand.getArgument(0), false, strResult) ? EDone : EFailed;
1154}
1155
1156CParameterMgr::CommandStatus CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1157{
1158 return importDomainsXml(remoteCommand.getArgument(0), false, strResult) ? EDone : EFailed;
1159}
1160
1161CParameterMgr::CommandStatus CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1162{
1163 return exportDomainsXml(remoteCommand.getArgument(0), true, strResult) ? EDone : EFailed;
1164}
1165
1166CParameterMgr::CommandStatus CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1167{
1168 return importDomainsXml(remoteCommand.getArgument(0), true, strResult) ? EDone : EFailed;
1169}
1170
1171CParameterMgr::CommandStatus CParameterMgr::exportSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1172{
1173 return exportDomainsBinary(remoteCommand.getArgument(0), strResult) ? EDone : EFailed;
1174}
1175
1176CParameterMgr::CommandStatus CParameterMgr::importSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1177{
1178 return importDomainsBinary(remoteCommand.getArgument(0), strResult) ? EDone : EFailed;
1179}
1180
1181// User set/get parameters
1182bool CParameterMgr::setValue(const string& strPath, const string& strValue, string& strError)
1183{
1184 // Check tuning mode
1185 if (!checkTuningModeOn(strError)) {
1186
1187 return false;
1188 }
1189
1190 CPathNavigator pathNavigator(strPath);
1191
1192 if (!pathNavigator.isPathValid()) {
1193
1194 strError = "Path not well formed";
1195
1196 return false;
1197 }
1198
1199 string* pStrChildName = pathNavigator.next();
1200
1201 if (!pStrChildName) {
1202
1203 strError = "Non settable element";
1204
1205 return false;
1206 }
1207
1208 if (*pStrChildName != getSystemClass()->getName()) {
1209
1210 strError = "Path not found";
1211
1212 return false;
1213 }
1214
1215 // Define context
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001216 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001217
1218 // Set auto sync
1219 parameterAccessContext.setAutoSync(_bAutoSyncOn);
1220
1221 // Do the set
1222 return getSystemClass()->setValue(pathNavigator, strValue, parameterAccessContext);
1223}
1224
1225bool CParameterMgr::getValue(const string& strPath, string& strValue, string& strError) const
1226{
1227 CPathNavigator pathNavigator(strPath);
1228
1229 if (!pathNavigator.isPathValid()) {
1230
1231 strError = "Path not well formed";
1232
1233 return false;
1234 }
1235
1236 string* pStrChildName = pathNavigator.next();
1237
1238 if (!pStrChildName) {
1239
1240 strError = "Non settable element";
1241
1242 return false;
1243 }
1244
1245 if (*pStrChildName != getConstSystemClass()->getName()) {
1246
1247 strError = "Path not found";
1248
1249 return false;
1250 }
1251
1252 // Define context
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001253 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001254
1255 // Do the get
1256 return getConstSystemClass()->getValue(pathNavigator, strValue, parameterAccessContext);
1257}
1258
1259// Tuning mode
1260bool CParameterMgr::setTuningMode(bool bOn, string& strError)
1261{
1262 // Tuning allowed?
1263 if (bOn && !_pSystemClassConfiguration->isTuningAllowed()) {
1264
1265 strError = "Tuning prohibited";
1266
1267 return false;
1268 }
1269 // Lock state
Patrick Benavoli1387bda2011-08-31 11:23:24 +02001270 CAutoLock autoLock(&_tuningModeMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001271
1272 // Warn domains about exiting tuning mode
1273 if (!bOn && _bTuningModeIsOn) {
1274
1275 // Ensure application of currently selected configurations
Patrick Benavoli1387bda2011-08-31 11:23:24 +02001276 // Force-apply configurations
Patrick Benavoli68a91282011-08-31 11:23:23 +02001277 if (!getConfigurableDomains()->apply(_pMainParameterBlackboard, true, strError)) {
1278
1279 return false;
1280 }
1281 // Turn auto sync back on
1282 _bAutoSyncOn = true;
1283 }
1284
1285 // Store
1286 _bTuningModeIsOn = bOn;
1287
Patrick Benavoli68a91282011-08-31 11:23:23 +02001288 return true;
1289}
1290
1291bool CParameterMgr::tuningModeOn() const
1292{
1293 return _bTuningModeIsOn;
1294}
1295
1296// Current value space for user set/get value interpretation
1297void CParameterMgr::setValueSpace(bool bIsRaw)
1298{
1299 _bValueSpaceIsRaw = bIsRaw;
1300}
1301
1302bool CParameterMgr::valueSpaceIsRaw()
1303{
1304 return _bValueSpaceIsRaw;
1305}
1306
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001307// Current Output Raw Format for user get value interpretation
1308void CParameterMgr::setOutputRawFormat(bool bIsHex)
1309{
1310 _bOutputRawFormatIsHex = bIsHex;
1311}
1312
1313bool CParameterMgr::outputRawFormatIsHex()
1314{
1315 return _bOutputRawFormatIsHex;
1316}
1317
Patrick Benavoli68a91282011-08-31 11:23:23 +02001318/// Sync
1319// Automatic hardware synchronization control (during tuning session)
1320bool CParameterMgr::setAutoSync(bool bAutoSyncOn, string& strError)
1321{
1322 // Check tuning mode
1323 if (!checkTuningModeOn(strError)) {
1324
1325 return false;
1326 }
1327 // Warn domains about turning auto sync back on
1328 if (bAutoSyncOn && !_bAutoSyncOn) {
1329
1330 // Ensure application of currently selected configurations
Patrick Benavoli1387bda2011-08-31 11:23:24 +02001331 // Force-apply configurations
Patrick Benavoli68a91282011-08-31 11:23:23 +02001332 if (!getConfigurableDomains()->apply(_pMainParameterBlackboard, true, strError)) {
1333
1334 return false;
1335 }
1336 }
1337
1338 // Set Auto sync
1339 _bAutoSyncOn = bAutoSyncOn;
1340
1341 return true;
1342}
1343
1344bool CParameterMgr::autoSyncOn() const
1345{
1346 return _bAutoSyncOn;
1347}
1348
1349// Manual hardware synchronization control (during tuning session)
1350bool CParameterMgr::sync(string& strError)
1351{
1352 // Check tuning mode
1353 if (!checkTuningModeOn(strError)) {
1354
1355 return false;
1356 }
1357 // Warn domains about turning auto sync back on
1358 if (_bAutoSyncOn) {
1359
1360 strError = "Feature unavailable when Auto Sync is on";
1361
1362 return false;
1363 }
1364
1365 // Get syncer set
1366 CSyncerSet syncerSet;
1367 // ... from system class
1368 getConstSystemClass()->fillSyncerSet(syncerSet);
1369 // Sync
1370 return syncerSet.sync(*_pMainParameterBlackboard, false, strError);
1371}
1372
1373// Content dump
1374void CParameterMgr::logStructureContent(string& strContent) const
1375{
1376 string strError;
1377
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001378 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001379
1380 dumpContent(strContent, parameterAccessContext);
1381}
1382
1383// Configuration/Domains handling
1384bool CParameterMgr::createDomain(const string& strName, string& strError)
1385{
1386 // Check tuning mode
1387 if (!checkTuningModeOn(strError)) {
1388
1389 return false;
1390 }
1391
1392 // Delegate to configurable domains
1393 return getConfigurableDomains()->createDomain(strName, strError);
1394}
1395
1396bool CParameterMgr::deleteDomain(const string& strName, string& strError)
1397{
1398 // Check tuning mode
1399 if (!checkTuningModeOn(strError)) {
1400
1401 return false;
1402 }
1403
1404 // Delegate to configurable domains
1405 return getConfigurableDomains()->deleteDomain(strName, strError);
1406}
1407
1408bool CParameterMgr::createConfiguration(const string& strDomain, const string& strConfiguration, 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()->createConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1418}
1419
1420bool CParameterMgr::deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1421{
1422 // Check tuning mode
1423 if (!checkTuningModeOn(strError)) {
1424
1425 return false;
1426 }
1427
1428 // Delegate to configurable domains
1429 return getConfigurableDomains()->deleteConfiguration(strDomain, strConfiguration, strError);
1430}
1431
1432bool CParameterMgr::restoreConfiguration(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()->restoreConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, strError);
1442}
1443
1444bool CParameterMgr::saveConfiguration(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()->saveConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1454}
1455
1456// Configurable element - domain association
1457bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1458{
1459 // Check tuning mode
1460 if (!checkTuningModeOn(strError)) {
1461
1462 return false;
1463 }
1464
1465 CElementLocator elementLocator(getSystemClass());
1466
1467 CElement* pLocatedElement = NULL;
1468
1469 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1470
1471 return false;
1472 }
1473
1474 // Convert element
1475 CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1476
1477 // Delegate
1478 return getConfigurableDomains()->addConfigurableElementToDomain(strDomain, pConfigurableElement, _pMainParameterBlackboard, strError);
1479}
1480
1481bool CParameterMgr::removeConfigurableElementFromDomain(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 EFailed;
1496 }
1497
1498 // Convert element
1499 CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1500
1501 // Delegate
1502 return getConfigurableDomains()->removeConfigurableElementFromDomain(strDomain, pConfigurableElement, strError);
1503}
1504
1505bool CParameterMgr::split(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()->split(strDomain, pConfigurableElement, strError);
1527}
1528
1529// XML Import/Export
1530bool CParameterMgr::importDomainsXml(const string& strFileName, bool bWithSettings, string& strError)
1531{
1532 // Check tuning mode
1533 if (!checkTuningModeOn(strError)) {
1534
1535 return false;
1536 }
1537
1538 // check path is absolute
1539 if (strFileName[0] != '/') {
1540
1541 strError = "Please provide absolute path";
1542
1543 return false;
1544 }
1545 // Root element
1546 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1547
1548 // Context
1549 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1550
1551 // Secltion criteria definition for rule creation
1552 xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
1553
1554 // Parse
1555 if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strFileName, "", EParameterConfigurationLibrary, "SystemClassName")) {
1556
1557 return false;
1558 }
1559
1560 // Validate domains after XML import
1561 pConfigurableDomains->validate(_pMainParameterBlackboard);
1562
1563 return true;
1564}
1565
1566bool CParameterMgr::exportDomainsXml(const string& strFileName, bool bWithSettings, string& strError) const
1567{
1568 // check path is absolute
1569 if (strFileName[0] != '/') {
1570
1571 strError = "Please provide absolute path";
1572
1573 return false;
1574 }
1575
1576 // Root element
1577 const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains();
1578
1579 // Get Schema file associated to root element
1580 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pConfigurableDomains->getKind() + ".xsd";
1581
1582 // Context
1583 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1584
1585 // Value space
1586 xmlDomainSerializingContext.setValueSpaceRaw(_bValueSpaceIsRaw);
1587
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001588 // Output raw format
1589 xmlDomainSerializingContext.setOutputRawFormat(_bOutputRawFormatIsHex);
1590
Patrick Benavoli68a91282011-08-31 11:23:23 +02001591 // Instantiate composer
1592 CXmlComposer xmlComposer(strFileName, strXmlSchemaFilePath, pConfigurableDomains->getKind(), xmlDomainSerializingContext);
1593
1594 // Open composer
1595 if (!xmlComposer.open()) {
1596
1597 return false;
1598 }
1599
1600 // Compose
1601 xmlComposer.compose(pConfigurableDomains);
1602
1603 // Close composer
1604 if (!xmlComposer.close()) {
1605
1606 return false;
1607 }
1608
1609 return true;
1610}
1611
1612// Binary Import/Export
1613bool CParameterMgr::importDomainsBinary(const string& strFileName, string& strError)
1614{
1615 // Check tuning mode
1616 if (!checkTuningModeOn(strError)) {
1617
1618 return false;
1619 }
1620 // check path is absolute
1621 if (strFileName[0] != '/') {
1622
1623 strError = "Please provide absolute path";
1624
1625 return false;
1626 }
1627 // Root element
1628 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1629
1630 // Serialize in
1631 return pConfigurableDomains->serializeSettings(strFileName, false, _uiStructureChecksum, strError);
1632}
1633
1634bool CParameterMgr::exportDomainsBinary(const string& strFileName, string& strError)
1635{
1636 // check path is absolute
1637 if (strFileName[0] != '/') {
1638
1639 strError = "Please provide absolute path";
1640
1641 return false;
1642 }
1643 // Check tuning mode
1644 if (!checkTuningModeOn(strError)) {
1645
1646 return false;
1647 }
1648 // Root element
1649 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1650
1651 // Serialize out
1652 return pConfigurableDomains->serializeSettings(strFileName, true, _uiStructureChecksum, strError);
1653}
1654
1655// For tuning, check we're in tuning mode
1656bool CParameterMgr::checkTuningModeOn(string& strError) const
1657{
1658 // Tuning Mode on?
1659 if (!_bTuningModeIsOn) {
1660
1661 strError = "Tuning Mode must be on";
1662
1663 return false;
1664 }
1665 return true;
1666}
1667
1668// Dynamic creation library feeding
1669void CParameterMgr::feedElementLibraries()
1670{
1671 // Global Configuration handling
1672 CElementLibrary* pFrameworkConfigurationLibrary = new CElementLibrary;
1673
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001674 pFrameworkConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CParameterFrameworkConfiguration>("ParameterFrameworkConfiguration"));
1675 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationGroup>("SubsystemPluginFolders"));
1676 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("PluginFolderLocation"));
1677 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationGroup>("ParameterConfiguration"));
1678 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CSystemClassConfiguration>("SystemClassConfiguration"));
1679 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("StructureDescriptionFileLocation"));
1680 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationGroup>("SettingsConfiguration"));
1681 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("ConfigurableDomainsFileLocation"));
1682 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("BinarySettingsFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001683
1684 _pElementLibrarySet->addElementLibrary(pFrameworkConfigurationLibrary);
1685
1686 // Parameter creation
1687 CElementLibrary* pParameterCreationLibrary = new CElementLibrary;
1688
1689 pParameterCreationLibrary->addElementBuilder(new CSubsystemElementBuilder(getSystemClass()->getSubsystemLibrary()));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001690 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CComponentType>("ComponentType"));
1691 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CComponentInstance>("Component"));
1692 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBitParameterType>("BitParameter"));
1693 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBitParameterBlockType>("BitParameterBlock"));
1694 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CParameterBlockType>("ParameterBlock"));
1695 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBooleanParameterType>("BooleanParameter"));
1696 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CIntegerParameterType>("IntegerParameter"));
1697 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CFixedPointParameterType>("FixedPointParameter"));
1698 pParameterCreationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CXmlFileIncluderElement>("SubsystemInclude"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001699
1700 _pElementLibrarySet->addElementLibrary(pParameterCreationLibrary);
1701
1702 // Parameter Configuration Domains creation
1703 CElementLibrary* pParameterConfigurationLibrary = new CElementLibrary;
1704
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001705 pParameterConfigurationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CConfigurableDomain>("ConfigurableDomain"));
1706 pParameterConfigurationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CDomainConfiguration>("Configuration"));
1707 pParameterConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CCompoundRule>("CompoundRule"));
1708 pParameterConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CSelectionCriterionRule>("SelectionCriterionRule"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001709
1710 _pElementLibrarySet->addElementLibrary(pParameterConfigurationLibrary);
1711}
1712
1713// Remote Processor Server connection handling
1714bool CParameterMgr::handleRemoteProcessingInterface(string& strError)
1715{
1716 CAutoLog autoLog(this, "Handling remote processing interface");
1717
1718 // Start server if tuning allowed
1719 if (_pSystemClassConfiguration->isTuningAllowed()) {
1720
1721 log("Loading remote processor library");
1722
1723 // Load library
1724 void* lib_handle = dlopen("libremote-processor.so", RTLD_NOW);
1725
1726 if (!lib_handle) {
1727
1728 // Return error
1729 const char* pcError = dlerror();
1730
1731 if (pcError) {
1732
1733 strError = pcError;
1734 } else {
1735
1736 strError = "Unable to load libremote-processor.so library";
1737 }
1738
1739 return false;
1740 }
1741
1742 CreateRemoteProcessorServer pfnCreateRemoteProcessorServer = (CreateRemoteProcessorServer)dlsym(lib_handle, "createRemoteProcessorServer");
1743
1744 if (!pfnCreateRemoteProcessorServer) {
1745
1746 strError = "libremote-process.so does not contain createRemoteProcessorServer symbol.";
1747
1748 return false;
1749 }
1750
1751 // Create server
1752 _pRemoteProcessorServer = pfnCreateRemoteProcessorServer(_pSystemClassConfiguration->getServerPort(), this);
1753
1754 // Compute max command usage length
1755 setMaxCommandUsageLength();
1756
1757 log("Starting remote processor server on port %d", _pSystemClassConfiguration->getServerPort());
1758 // Start
1759 if (!_pRemoteProcessorServer->start()) {
1760
1761 strError = "Unable to start remote processor server";
1762
1763 return false;
1764 }
1765 }
1766
1767 return true;
1768}
1769
1770// Back synchronization
1771CBackSynchronizer* CParameterMgr::createBackSynchronizer(string& strError) const
1772{
1773#ifdef SIMULATION
1774 // In simulation, back synchronization of the blackboard won't probably work
1775 // We need to ensure though the blackboard is initialized with valid data
1776 return new CSimulatedBackSynchronizer(getConstSystemClass(), strError, _pMainParameterBlackboard);
1777#else
1778 // Real back synchronizer from subsystems
1779 return new CHardwareBackSynchronizer(getConstSystemClass(), strError, _pMainParameterBlackboard);
1780#endif
1781}
1782
1783// Children typwise access
1784CParameterFrameworkConfiguration* CParameterMgr::getFrameworkConfiguration()
1785{
1786 return static_cast<CParameterFrameworkConfiguration*>(getChild(EFrameworkConfiguration));
1787}
1788
1789const CParameterFrameworkConfiguration* CParameterMgr::getConstFrameworkConfiguration()
1790{
1791 return getFrameworkConfiguration();
1792}
1793
1794CSelectionCriteria* CParameterMgr::getSelectionCriteria()
1795{
1796 return static_cast<CSelectionCriteria*>(getChild(ESelectionCriteria));
1797}
1798
1799const CSelectionCriteria* CParameterMgr::getConstSelectionCriteria()
1800{
1801 return static_cast<const CSelectionCriteria*>(getChild(ESelectionCriteria));
1802}
1803
1804CSystemClass* CParameterMgr::getSystemClass()
1805{
1806 return static_cast<CSystemClass*>(getChild(ESystemClass));
1807}
1808
1809const CSystemClass* CParameterMgr::getConstSystemClass() const
1810{
1811 return static_cast<const CSystemClass*>(getChild(ESystemClass));
1812}
1813
1814// Configurable Domains
1815CConfigurableDomains* CParameterMgr::getConfigurableDomains()
1816{
1817 return static_cast<CConfigurableDomains*>(getChild(EConfigurableDomains));
1818}
1819
1820const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains()
1821{
1822 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
1823}
1824
1825const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains() const
1826{
1827 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
1828}