blob: 102d28b79e29602c1304f6cecdd167369fcbf6ac [file] [log] [blame]
Patrick Benavoli68a91282011-08-31 11:23:23 +02001/* <auto_header>
2 * <FILENAME>
3 *
4 * INTEL CONFIDENTIAL
5 * Copyright © 2011 Intel
6 * Corporation All Rights Reserved.
7 *
8 * The source code contained or described herein and all documents related to
9 * the source code ("Material") are owned by Intel Corporation or its suppliers
10 * or licensors. Title to the Material remains with Intel Corporation or its
11 * suppliers and licensors. The Material contains trade secrets and proprietary
12 * and confidential information of Intel or its suppliers and licensors. The
13 * Material is protected by worldwide copyright and trade secret laws and
14 * treaty provisions. No part of the Material may be used, copied, reproduced,
15 * modified, published, uploaded, posted, transmitted, distributed, or
16 * disclosed in any way without Intel’s prior express written permission.
17 *
18 * No license under any patent, copyright, trade secret or other intellectual
19 * property right is granted to or conferred upon you by disclosure or delivery
20 * of the Materials, either expressly, by implication, inducement, estoppel or
21 * otherwise. Any license under such intellectual property rights must be
22 * express and approved by Intel in writing.
23 *
24 * AUTHOR: Patrick Benavoli (patrickx.benavoli@intel.com)
25 * CREATED: 2011-06-01
26 * UPDATED: 2011-07-27
27 *
28 *
29 * </auto_header>
30 */
31#include "ParameterMgr.h"
32#include "XmlParser.h"
33#include "XmlParameterSerializingContext.h"
34#include "XmlElementSerializingContext.h"
35#include "SystemClass.h"
36#include "ElementLibrarySet.h"
37#include "SubsystemLibrary.h"
38#include "NamedElementBuilderTemplate.h"
39#include "KindElementBuilderTemplate.h"
40#include "ElementBuilderTemplate.h"
41#include "SelectionCriterionType.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020042#include "SubsystemElementBuilder.h"
43#include "SelectionCriteria.h"
44#include "ComponentType.h"
45#include "ComponentInstance.h"
46#include "ParameterBlockType.h"
47#include "BooleanParameterType.h"
48#include "IntegerParameterType.h"
49#include "FixedPointParameterType.h"
50#include "ParameterBlackboard.h"
51#include "Parameter.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020052#include "ParameterBlackboard.h"
53#include "ParameterAccessContext.h"
54#include "XmlFileIncluderElement.h"
55#include "ParameterFrameworkConfiguration.h"
56#include "FrameworkConfigurationGroup.h"
57#include "FrameworkConfigurationLocation.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020058#include "ConfigurableDomains.h"
59#include "ConfigurableDomain.h"
60#include "DomainConfiguration.h"
61#include "XmlComposer.h"
62#include "XmlDomainSerializingContext.h"
63#include "BitParameterBlockType.h"
64#include "BitParameterType.h"
Patrick Benavoli1352ae52011-10-21 16:48:04 +020065#include "StringParameterType.h"
Patrick Benavoli9fc3c0d2011-10-27 14:27:27 +020066#include "EnumParameterType.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020067#include "RemoteProcessorServerInterface.h"
68#include "ElementLocator.h"
69#include "AutoLog.h"
70#include "CompoundRule.h"
71#include "SelectionCriterionRule.h"
72#include "SimulatedBackSynchronizer.h"
73#include "HardwareBackSynchronizer.h"
Patrick Benavoli1387bda2011-08-31 11:23:24 +020074#include "AutoLock.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020075#include <strings.h>
76#include <dlfcn.h>
77#include <assert.h>
Patrick 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// ---------------------------------------------
Patrick Benavoli95ac0342011-11-07 20:32:51 +010090//├── <ParameterFrameworkConfiguration>.xml
Patrick Benavoli68a91282011-08-31 11:23:23 +020091//├── 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 Benavoli592ae562011-09-05 16:53:58 +0200106 /// Version
107 { "version", &CParameterMgr::versionCommandProcess, 0, "", "Show version" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200108 /// Status
109 { "status", &CParameterMgr::statusCommandProcess, 0, "", "Show current status" },
110 /// Tuning Mode
111 { "setTuningMode", &CParameterMgr::setTuningModeCommmandProcess, 1, "on|off*", "Turn on or off Tuning Mode" },
112 { "getTuningMode", &CParameterMgr::getTuningModeCommmandProcess, 0, "", "Show Tuning Mode" },
113 /// Value Space
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200114 { "setValueSpace", &CParameterMgr::setValueSpaceCommmandProcess, 1, "raw|real*", "Assigns Value Space used for parameter value interpretation" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200115 { "getValueSpace", &CParameterMgr::getValueSpaceCommmandProcess, 0, "", "Show Value Space" },
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200116 /// Output Raw Format
117 { "setOutputRawFormat", &CParameterMgr::setOutputRawFormatCommmandProcess, 1, "dec*|hex", "Assigns format used to output parameter values when in raw Value Space" },
118 { "getOutputRawFormat", &CParameterMgr::getOutputRawFormatCommmandProcess, 0, "", "Show Output Raw Format" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200119 /// Sync
120 { "setAutoSync", &CParameterMgr::setAutoSyncCommmandProcess, 1, "on*|off", "Turn on or off automatic synchronization to hardware while in Tuning Mode" },
121 { "getAutoSync", &CParameterMgr::getAutoSyncCommmandProcess, 0, "", "Show Auto Sync state" },
122 { "sync", &CParameterMgr::syncCommmandProcess, 0, "", "Synchronize current settings to hardware while in Tuning Mode and Auto Sync off" },
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200123 /// Criteria
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200124 { "listCriteria", &CParameterMgr::listCriteriaCommmandProcess, 0, "", "List selection criteria" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200125 /// Domains
126 { "listDomains", &CParameterMgr::listDomainsCommmandProcess, 0, "", "List configurable domains" },
127 { "createDomain", &CParameterMgr::createDomainCommmandProcess, 1, "<domain>", "Create new configurable domain" },
128 { "deleteDomain", &CParameterMgr::deleteDomainCommmandProcess, 1, "<domain>", "Delete configurable domain" },
129 { "renameDomain", &CParameterMgr::renameDomainCommmandProcess, 2, "<domain> <new name>", "Rename configurable domain" },
Patrick Benavoli63499d42011-10-24 18:50:03 +0200130 { "setSequenceAwareness", &CParameterMgr::setSequenceAwarenessCommmandProcess, 1, "<domain> true|false*", "Set configurable domain sequence awareness" },
131 { "getSequenceAwareness", &CParameterMgr::getSequenceAwarenessCommmandProcess, 1, "<domain>", "Get configurable domain sequence awareness" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200132 { "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" },
Patrick Benavoli63499d42011-10-24 18:50:03 +0200143 { "setElementSequence", &CParameterMgr::setElementSequenceCommmandProcess, 2, "<domain> <configuration> <elem path list>", "Set element application order for configuration" },
144 { "getElementSequence", &CParameterMgr::getElementSequenceCommmandProcess, 2, "<domain> <configuration>", "Get element application order for configuration" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200145 /// Elements/Parameters
146 { "listElements", &CParameterMgr::listElementsCommmandProcess, 1, "<elem path>|/", "List elements under element at given path or root" },
Patrick Benavoli592ae562011-09-05 16:53:58 +0200147 { "listParameters", &CParameterMgr::listParametersCommmandProcess, 1, "<elem path>|/", "List parameters under element at given path or root" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200148 { "dumpElement", &CParameterMgr::dumpElementCommmandProcess, 1, "<elem path>", "Dump structure and content of element at given path" },
149 { "getElementSize", &CParameterMgr::getElementSizeCommmandProcess, 1, "<elem path>", "Show size of element at given path" },
Patrick Benavoli2ecf9002011-08-31 11:23:24 +0200150 { "showProperties", &CParameterMgr::showPropertiesCommmandProcess, 1, "<elem path>", "Show properties of element at given path" },
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200151 { "getParameter", &CParameterMgr::getParameterCommmandProcess, 1, "<param path>", "Get value for parameter at given path" },
Patrick Benavoli2ecf9002011-08-31 11:23:24 +0200152 { "setParameter", &CParameterMgr::setParameterCommmandProcess, 2, "<param path> <value>", "Set value for parameter at given path" },
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200153 { "listBelongingDomains", &CParameterMgr::listBelongingDomainsCommmandProcess, 1, "<elem path>", "List domain(s) element at given path belongs to" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200154 { "listAssociatedDomains", &CParameterMgr::listAssociatedDomainsCommmandProcess, 1, "<elem path>", "List domain(s) element at given path is associated to" },
155 /// Browse
156 { "listAssociatedElements", &CParameterMgr::listAssociatedElementsCommmandProcess, 0, "", "List element sub-trees associated to at least one configurable domain" },
157 { "listConflictingElements", &CParameterMgr::listConflictingElementsCommmandProcess, 0, "", "List element sub-trees contained in more than one configurable domain" },
158 { "listRogueElements", &CParameterMgr::listRogueElementsCommmandProcess, 0, "", "List element sub-trees owned by no configurable domain" },
159 /// Settings Import/Export
160 { "exportDomainsXML", &CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess, 1, "<file path> ", "Export domains to XML file" },
161 { "importDomainsXML", &CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess, 1, "<file path>", "Import domains from XML file" },
162 { "exportDomainsWithSettingsXML", &CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess, 1, "<file path> ", "Export domains including settings to XML file" },
163 { "importDomainsWithSettingsXML", &CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess, 1, "<file path>", "Import domains including settings from XML file" },
164 { "exportSettings", &CParameterMgr::exportSettingsCommmandProcess, 1, "<file path>", "Export settings to binary file" },
165 { "importSettings", &CParameterMgr::importSettingsCommmandProcess, 1, "<file path>", "Import settings from binary file" }
166};
167// Remote command parsers array Size
Patrick Benavoli592ae562011-09-05 16:53:58 +0200168const uint32_t CParameterMgr::guiNbRemoteCommandParserItems = sizeof(gastRemoteCommandParserItems) / sizeof(gastRemoteCommandParserItems[0]);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200169
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100170CParameterMgr::CParameterMgr(const string& strConfigurationFilePath) :
Patrick Benavoli68a91282011-08-31 11:23:23 +0200171 _bTuningModeIsOn(false),
172 _bValueSpaceIsRaw(false),
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200173 _bOutputRawFormatIsHex(false),
Patrick Benavoli68a91282011-08-31 11:23:23 +0200174 _bAutoSyncOn(true),
175 _pMainParameterBlackboard(new CParameterBlackboard),
176 _pElementLibrarySet(new CElementLibrarySet),
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100177 _strXmlConfigurationFilePath(strConfigurationFilePath),
Patrick Benavoli68a91282011-08-31 11:23:23 +0200178 _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);
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100191 addChild(new CSystemClass);
192 addChild(new CConfigurableDomains);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200193
194 // Feed element library
195 feedElementLibraries();
Patrick Benavoli63499d42011-10-24 18:50:03 +0200196
197 _pCommandHandler = new CCommandHandler(this);
198
199 // Add command parsers
200 uint32_t uiRemoteCommandParserItem;
201
202 for (uiRemoteCommandParserItem = 0; uiRemoteCommandParserItem < guiNbRemoteCommandParserItems; uiRemoteCommandParserItem++) {
203
204 const SRemoteCommandParserItem* pRemoteCommandParserItem = &gastRemoteCommandParserItems[uiRemoteCommandParserItem];
205
206 _pCommandHandler->addCommandParser(pRemoteCommandParserItem->_pcCommandName,
207 pRemoteCommandParserItem->_pfnParser,
208 pRemoteCommandParserItem->_uiMinArgumentCount,
209 pRemoteCommandParserItem->_pcHelp,
210 pRemoteCommandParserItem->_pcDescription);
211 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100212
213 // Configuration file folder
214 uint32_t uiSlashPos = _strXmlConfigurationFilePath.rfind('/', -1);
215
216 assert(uiSlashPos != (uint32_t)-1);
217
218 _strXmlConfigurationFolderPath = _strXmlConfigurationFilePath.substr(0, uiSlashPos);
219
220 // Schema absolute folder location
221 _strSchemaFolderLocation = _strXmlConfigurationFolderPath + "/" + gacSystemSchemasSubFolder;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200222}
223
224CParameterMgr::~CParameterMgr()
225{
226 // Children
227 delete _pRemoteProcessorServer;
228 delete _pMainParameterBlackboard;
229 delete _pElementLibrarySet;
230
231 // Tuning Mode Mutex
232 pthread_mutex_destroy(&_tuningModeMutex);
233}
234
235string CParameterMgr::getKind() const
236{
237 return "ParameterMgr";
238}
239
240// Logging
241void CParameterMgr::setLogger(CParameterMgr::ILogger* pLogger)
242{
243 _pLogger = pLogger;
244}
245
246// Logging
247void CParameterMgr::doLog(const string& strLog) const
248{
249 if (_pLogger) {
250
251 // Nest
252 string strIndent;
253
254 // Level
255 uint32_t uiNbIndents = _uiLogDepth;
256
257 while (uiNbIndents--) {
258
259 strIndent += " ";
260 }
261
262 // Log
263 _pLogger->log(strIndent + strLog);
264 }
265}
266
267void CParameterMgr::nestLog() const
268{
Patrick Benavoli592ae562011-09-05 16:53:58 +0200269 _uiLogDepth++;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200270}
271
272void CParameterMgr::unnestLog() const
273{
Patrick Benavoli592ae562011-09-05 16:53:58 +0200274 _uiLogDepth--;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200275}
276
Patrick Benavoli63499d42011-10-24 18:50:03 +0200277// Version
278string CParameterMgr::getVersion() const
279{
280 string strVersion;
281
282 // Major
283 strVersion = toString(guiEditionMajor) + ".";
284 // Minor
285 strVersion += toString(guiEditionMinor) + ".";
286 // Revision
287 strVersion += toString(guiRevision);
288
289 return strVersion;
290}
291
Patrick Benavoli68a91282011-08-31 11:23:23 +0200292bool CParameterMgr::load(string& strError)
293{
294 CAutoLog autoLog(this, "Loading");
295
296 // Load Framework configuration
297 if (!loadFrameworkConfiguration(strError)) {
298
299 return false;
300 }
301
302 // Load subsystems
303 if (!getSystemClass()->loadSubsystems(strError, _astrPluginFolderPaths)) {
304
305 return false;
306 }
307
308 // Load structure
309 if (!loadStructure(strError)) {
310
311 return false;
312 }
313
314 // Load settings
315 if (!loadSettings(strError)) {
316
317 return false;
318 }
319
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200320 // Back synchronization for areas in parameter blackboard not covered by any domain
321 CBackSynchronizer* pBackSynchronizer = createBackSynchronizer(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200322
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200323 log("Main blackboard back synchronization");
324
325 // Back-synchronize
326 if (!pBackSynchronizer->sync()) {
327 // Get rid of back synchronizer
328 delete pBackSynchronizer;
329
330 strError = "Main blackboard back synchronization failed: " + strError;
331
332 return false;
333 }
334 // Get rif of back synchronizer
335 delete pBackSynchronizer;
336
337 // We're done loading the settings and back synchronizing
338 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
339
340 // We need to ensure all domains are valid
341 pConfigurableDomains->validate(_pMainParameterBlackboard);
342
343 // Ensure application of currently selected configurations
344 // Force-apply configurations
345 if (!pConfigurableDomains->apply(_pMainParameterBlackboard, true, strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200346
347 return false;
348 }
349
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200350 // Start remote processor server if appropriate
351 return handleRemoteProcessingInterface(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200352}
353
354bool CParameterMgr::loadFrameworkConfiguration(string& strError)
355{
356 CAutoLog autoLog(this, "Loading framework configuration");
357
Patrick Benavoli68a91282011-08-31 11:23:23 +0200358 // Parse Structure XML file
359 CXmlElementSerializingContext elementSerializingContext(strError);
360
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100361 if (!xmlParse(elementSerializingContext, getFrameworkConfiguration(), _strXmlConfigurationFilePath, _strXmlConfigurationFolderPath, EFrameworkConfigurationLibrary)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200362
363 return false;
364 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100365 // Set class name to system class and configurable domains
366 getSystemClass()->setName(getConstFrameworkConfiguration()->getSystemClassName());
367 getConfigurableDomains()->setName(getConstFrameworkConfiguration()->getSystemClassName());
368
Patrick Benavoli68a91282011-08-31 11:23:23 +0200369 // Get subsystem plugins folders element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100370 const CFrameworkConfigurationGroup* pSubsystemPluginFolders = static_cast<const CFrameworkConfigurationGroup*>(getConstFrameworkConfiguration()->findChild("SubsystemPluginFolders"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200371
372 if (!pSubsystemPluginFolders) {
373
374 strError = "Parameter Framework Configuration: couldn't find SubsystemPluginFolders element";
375
376 return false;
377 }
378 // Get plugin locations
379 uint32_t uiPluginFolderLocation;
380 uint32_t uiNbPluginFolderLocations = pSubsystemPluginFolders->getNbChildren();
381
382 if (!uiNbPluginFolderLocations) {
383
384 strError = "Parameter Framework Configuration: couldn't find any PluginFolderLocation element";
385
386 return false;
387 }
388
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100389 // Collect plugin paths
Patrick Benavoli68a91282011-08-31 11:23:23 +0200390 for (uiPluginFolderLocation = 0; uiPluginFolderLocation < uiNbPluginFolderLocations; uiPluginFolderLocation++) {
391
392 const CFrameworkConfigurationLocation* pSubsystemPluginLocation = static_cast<const CFrameworkConfigurationLocation*>(pSubsystemPluginFolders->getChild(uiPluginFolderLocation));
393
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100394 _astrPluginFolderPaths.push_back(pSubsystemPluginLocation->getFilePath(_strXmlConfigurationFilePath));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200395 }
396
Patrick Benavoli68a91282011-08-31 11:23:23 +0200397 // Log tuning availability
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100398 log("Tuning %s", getConstFrameworkConfiguration()->isTuningAllowed() ? "allowed" : "prohibited");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200399
400 return true;
401}
402
403bool CParameterMgr::loadStructure(string& strError)
404{
405 // Retrieve system to load structure to
406 CSystemClass* pSystemClass = getSystemClass();
407
408 CAutoLog autoLog(this, "Loading " + pSystemClass->getName() + " system class structure");
409
410 // Get structure description element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100411 const CFrameworkConfigurationLocation* pStructureDescriptionFileLocation = static_cast<const CFrameworkConfigurationLocation*>(getConstFrameworkConfiguration()->findChildOfKind("StructureDescriptionFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200412
413 if (!pStructureDescriptionFileLocation) {
414
415 strError = "No StructureDescriptionFileLocation element found for SystemClass " + pSystemClass->getName();
416
417 return false;
418 }
419
420 // Get Xml structure folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100421 string strXmlStructureFolder = pStructureDescriptionFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200422
423 // Get Xml structure file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100424 string strXmlStructureFilePath = pStructureDescriptionFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200425
426 // Parse Structure XML file
427 CXmlParameterSerializingContext parameterBuildContext(strError);
428
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200429 log("Importing system structure from file %s", strXmlStructureFilePath.c_str());
430
Patrick Benavoli68a91282011-08-31 11:23:23 +0200431 if (!xmlParse(parameterBuildContext, pSystemClass, strXmlStructureFilePath, strXmlStructureFolder, EParameterCreationLibrary)) {
432
433 return false;
434 }
435
436 // Initialize offsets
437 pSystemClass->setOffset(0);
438
439 // Initialize main blackboard's size
440 _pMainParameterBlackboard->setSize(pSystemClass->getFootPrint());
441
442 return true;
443}
444
445bool CParameterMgr::loadSettings(string& strError)
446{
447 CAutoLog autoLog(this, "Loading settings");
448
449 // Get settings configuration element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100450 const CFrameworkConfigurationGroup* pParameterConfigurationGroup = static_cast<const CFrameworkConfigurationGroup*>(getConstFrameworkConfiguration()->findChildOfKind("SettingsConfiguration"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200451
452 if (!pParameterConfigurationGroup) {
453
454 // No settings to load
455
456 return true;
457 }
458 // Get binary settings file location
459 const CFrameworkConfigurationLocation* pBinarySettingsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("BinarySettingsFileLocation"));
460
461 string strXmlBinarySettingsFilePath;
462
463 if (pBinarySettingsFileLocation) {
464
465 // Get Xml binary settings file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100466 strXmlBinarySettingsFilePath = pBinarySettingsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200467 }
468
469 // Get configurable domains element
470 const CFrameworkConfigurationLocation* pConfigurableDomainsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("ConfigurableDomainsFileLocation"));
471
472 if (!pConfigurableDomainsFileLocation) {
473
474 strError = "No ConfigurableDomainsFileLocation element found for SystemClass " + getSystemClass()->getName();
475
476 return false;
477 }
478 // Get destination root element
479 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
480
481 // Get Xml configuration domains file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100482 string strXmlConfigurationDomainsFilePath = pConfigurableDomainsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200483
484 // Get Xml configuration domains folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100485 string strXmlConfigurationDomainsFolder = pConfigurableDomainsFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200486
487 // Parse configuration domains XML file (ask to read settings from XML file if they are not provided as binary)
488 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, !pBinarySettingsFileLocation);
489
490 // Selection criteria definition for rule creation
491 xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
492
Patrick Benavoli63499d42011-10-24 18:50:03 +0200493 // Auto validation of configurations if no binary settings provided
494 xmlDomainSerializingContext.setAutoValidationRequired(!pBinarySettingsFileLocation);
495
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200496 log("Importing configurable domains from file %s %s settings", strXmlConfigurationDomainsFilePath.c_str(), pBinarySettingsFileLocation ? "without" : "with");
497
Patrick Benavoli68a91282011-08-31 11:23:23 +0200498 // Do parse
499 if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strXmlConfigurationDomainsFilePath, strXmlConfigurationDomainsFolder, EParameterConfigurationLibrary, "SystemClassName")) {
500
501 return false;
502 }
503 // We have loaded the whole system structure, compute checksum
504 const CSystemClass* pSystemClass = getConstSystemClass();
505 _uiStructureChecksum = pSystemClass->computeStructureChecksum() + getConfigurableDomains()->computeStructureChecksum() + getSelectionCriteria()->computeStructureChecksum();
506
507 // Load binary settings if any provided
508 if (pBinarySettingsFileLocation && !pConfigurableDomains->serializeSettings(strXmlBinarySettingsFilePath, false, _uiStructureChecksum, strError)) {
509
510 return false;
511 }
512
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200513 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200514}
515
516// XML parsing
517bool CParameterMgr::xmlParse(CXmlElementSerializingContext& elementSerializingContext, CElement* pRootElement, const string& strXmlFilePath, const string& strXmlFolder, CParameterMgr::ElementLibrary eElementLibrary, const string& strNameAttrituteName)
518{
519 // Init serializing context
520 elementSerializingContext.set(_pElementLibrarySet->getElementLibrary(eElementLibrary), strXmlFolder, _strSchemaFolderLocation);
521
522 // Get Schema file associated to root element
523 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pRootElement->getKind() + ".xsd";
524
525 // Parse Structure XML file
526 CXmlParser parser(strXmlFilePath, strXmlSchemaFilePath, pRootElement->getKind(), elementSerializingContext);
527
528 if (!parser.open()) {
529
530 return false;
531 }
532
533 // Check Root element name attribute (if any)
534 string strRootElementName = parser.getRootElementAttributeString(strNameAttrituteName);
535
536 if (!strRootElementName.empty() && strRootElementName != pRootElement->getName()) {
537
538 elementSerializingContext.setError("Error: Wrong XML structure file " + strXmlFilePath);
539 elementSerializingContext.appendLineToError(pRootElement->getKind() + " element " + pRootElement->getName() + " mismatches expected " + pRootElement->getKind() + " type " + pRootElement->getName());
540
541 return false;
542 }
543
544 // Start clean
545 pRootElement->clean();
546
547 // Parse
548 if (!parser.parse(pRootElement)) {
549
550 // Cleanup
551 pRootElement->clean();
552
553 return false;
554 }
555
556 // Close parser
557 if (!parser.close()) {
558
559 return false;
560 }
561
562 return true;
563}
564
565// Init
566bool CParameterMgr::init(string& strError)
567{
568 return base::init(strError);
569}
570
571// Selection criteria interface
572CSelectionCriterionType* CParameterMgr::createSelectionCriterionType(bool bIsInclusive)
573{
574 // Propagate
575 return getSelectionCriteria()->createSelectionCriterionType(bIsInclusive);
576}
577
578CSelectionCriterion* CParameterMgr::createSelectionCriterion(const string& strName, const CSelectionCriterionType* pSelectionCriterionType)
579{
580 // Propagate
581 return getSelectionCriteria()->createSelectionCriterion(strName, pSelectionCriterionType);
582}
583
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200584// Selection criterion retrieval
585CSelectionCriterion* CParameterMgr::getSelectionCriterion(const string& strName)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200586{
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200587 // Propagate
588 return getSelectionCriteria()->getSelectionCriterion(strName);
589}
590
591// Selection criteria changed event
592bool CParameterMgr::applyConfigurations(string& strError)
593{
594 CAutoLog autoLog(this, "Configuration application request");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200595
596 // Lock state
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200597 CAutoLock autoLock(&_tuningModeMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200598
599 if (!_bTuningModeIsOn) {
600
601 // Apply configuration(s)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200602 if (!getConfigurableDomains()->apply(_pMainParameterBlackboard, false, strError)) {
603
604 log("Failed to apply configurations!");
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200605
606 return false;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200607 }
608 }
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200609
610 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200611}
612
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200613// Dynamic parameter handling
614bool CParameterMgr::setValue(const string& strPath, const string& strValue, bool bRawValueSpace, string& strError)
615{
616 // Delegate to low level functionality
617 return doSetValue(strPath, strValue, bRawValueSpace, true, strError);
618}
619
620bool CParameterMgr::getValue(const string& strPath, string& strValue, bool bRawValueSpace, bool bHexOutputRawFormat, string& strError) const
621{
622 // Delegate to low level functionality
623 return doGetValue(strPath, strValue, bRawValueSpace, bHexOutputRawFormat, true, strError);
624}
625
Patrick Benavoli68a91282011-08-31 11:23:23 +0200626/////////////////// Remote command parsers
Patrick Benavoli592ae562011-09-05 16:53:58 +0200627/// Version
Patrick Benavoli63499d42011-10-24 18:50:03 +0200628CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::versionCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli592ae562011-09-05 16:53:58 +0200629{
630 (void)remoteCommand;
631
Patrick Benavoli63499d42011-10-24 18:50:03 +0200632 // Show version
633 strResult = getVersion();
Patrick Benavoli592ae562011-09-05 16:53:58 +0200634
Patrick Benavoli63499d42011-10-24 18:50:03 +0200635 return CCommandHandler::ESucceeded;
Patrick Benavoli592ae562011-09-05 16:53:58 +0200636}
637
Patrick Benavoli68a91282011-08-31 11:23:23 +0200638/// Status
Patrick Benavoli63499d42011-10-24 18:50:03 +0200639CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::statusCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200640{
641 (void)remoteCommand;
642 // System class
643 const CSystemClass* pSystemClass = getSystemClass();
644
Patrick Benavoli68a91282011-08-31 11:23:23 +0200645 // Show status
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200646 /// General section
647 appendTitle(strResult, "General:");
648 // System class
Patrick Benavoli68a91282011-08-31 11:23:23 +0200649 strResult += "System Class: ";
650 strResult += pSystemClass->getName();
651 strResult += "\n";
652
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200653 // Tuning mode
Patrick Benavoli68a91282011-08-31 11:23:23 +0200654 strResult += "Tuning Mode: ";
655 strResult += tuningModeOn() ? "on" : "off";
656 strResult += "\n";
657
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200658 // Value space
Patrick Benavoli68a91282011-08-31 11:23:23 +0200659 strResult += "Value Space: ";
660 strResult += valueSpaceIsRaw() ? "raw" : "real";
661 strResult += "\n";
662
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200663 // Output raw format
664 strResult += "Output Raw Format: ";
665 strResult += outputRawFormatIsHex() ? "hex" : "dec";
666 strResult += "\n";
667
668 // Auto Sync
Patrick Benavoli68a91282011-08-31 11:23:23 +0200669 strResult += "Auto Sync: ";
670 strResult += autoSyncOn() ? "on" : "off";
671 strResult += "\n";
672
673 /// Subsystem list
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200674 appendTitle(strResult, "Subsystems:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200675 string strSubsystemList;
676 pSystemClass->listChildrenPaths(strSubsystemList);
677 strResult += strSubsystemList;
678
679 /// Last applied configurations
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200680 appendTitle(strResult, "Last applied configurations:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200681 string strLastAppliedConfigurations;
682 getConfigurableDomains()->listLastAppliedConfigurations(strLastAppliedConfigurations);
683 strResult += strLastAppliedConfigurations;
684
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200685 /// Criteria states
686 appendTitle(strResult, "Selection criteria:");
687 string strSelectionCriteria;
688 getSelectionCriteria()->listSelectionCriteria(strSelectionCriteria, false);
689 strResult += strSelectionCriteria;
690
Patrick Benavoli63499d42011-10-24 18:50:03 +0200691 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200692}
693
694/// Tuning Mode
Patrick Benavoli63499d42011-10-24 18:50:03 +0200695CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200696{
697 if (remoteCommand.getArgument(0) == "on") {
698
699 if (setTuningMode(true, strResult)) {
700
Patrick Benavoli63499d42011-10-24 18:50:03 +0200701 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200702 }
703 } else if (remoteCommand.getArgument(0) == "off") {
704
705 if (setTuningMode(false, strResult)) {
706
Patrick Benavoli63499d42011-10-24 18:50:03 +0200707 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200708 }
709 } else {
710 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200711 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200712 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200713 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200714}
715
Patrick Benavoli63499d42011-10-24 18:50:03 +0200716CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200717{
718 (void)remoteCommand;
719
720 strResult = tuningModeOn() ? "on" : "off";
721
Patrick Benavoli63499d42011-10-24 18:50:03 +0200722 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200723}
724
725/// Value Space
Patrick Benavoli63499d42011-10-24 18:50:03 +0200726CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200727{
728 (void)strResult;
729
730 if (remoteCommand.getArgument(0) == "raw") {
731
732 setValueSpace(true);
733
Patrick Benavoli63499d42011-10-24 18:50:03 +0200734 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200735
736 } else if (remoteCommand.getArgument(0) == "real") {
737
738 setValueSpace(false);
739
Patrick Benavoli63499d42011-10-24 18:50:03 +0200740 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200741
742 } else {
743 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200744 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200745 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200746 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200747}
748
Patrick Benavoli63499d42011-10-24 18:50:03 +0200749CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200750{
751 (void)remoteCommand;
752
753 strResult = valueSpaceIsRaw() ? "raw" : "real";
754
Patrick Benavoli63499d42011-10-24 18:50:03 +0200755 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200756}
757
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200758/// Output Raw Format
Patrick Benavoli63499d42011-10-24 18:50:03 +0200759CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200760{
761 (void)strResult;
762
763 if (remoteCommand.getArgument(0) == "hex") {
764
765 setOutputRawFormat(true);
766
Patrick Benavoli63499d42011-10-24 18:50:03 +0200767 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200768
769 } else if (remoteCommand.getArgument(0) == "dec") {
770
771 setOutputRawFormat(false);
772
Patrick Benavoli63499d42011-10-24 18:50:03 +0200773 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200774
775 } else {
776 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200777 return CCommandHandler::EShowUsage;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200778 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200779 return CCommandHandler::EFailed;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200780}
781
Patrick Benavoli63499d42011-10-24 18:50:03 +0200782CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200783{
784 (void)remoteCommand;
785
786 strResult = outputRawFormatIsHex() ? "hex" : "dec";
787
Patrick Benavoli63499d42011-10-24 18:50:03 +0200788 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200789}
790
Patrick Benavoli68a91282011-08-31 11:23:23 +0200791/// Sync
Patrick Benavoli63499d42011-10-24 18:50:03 +0200792CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200793{
794 if (remoteCommand.getArgument(0) == "on") {
795
796 if (setAutoSync(true, strResult)) {
797
Patrick Benavoli63499d42011-10-24 18:50:03 +0200798 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200799 }
800 } else if (remoteCommand.getArgument(0) == "off") {
801
802 if (setAutoSync(false, strResult)) {
803
Patrick Benavoli63499d42011-10-24 18:50:03 +0200804 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200805 }
806 } else {
807 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200808 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200809 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200810 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200811}
812
Patrick Benavoli63499d42011-10-24 18:50:03 +0200813CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200814{
815 (void)remoteCommand;
816
817 strResult = autoSyncOn() ? "on" : "off";
818
Patrick Benavoli63499d42011-10-24 18:50:03 +0200819 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200820}
821
Patrick Benavoli63499d42011-10-24 18:50:03 +0200822CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::syncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200823{
824 (void)remoteCommand;
825
Patrick Benavoli63499d42011-10-24 18:50:03 +0200826 return sync(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200827}
828
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200829/// Criteria
Patrick Benavoli63499d42011-10-24 18:50:03 +0200830CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listCriteriaCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200831{
832 (void)remoteCommand;
833
834 getSelectionCriteria()->listSelectionCriteria(strResult, true);
835
Patrick Benavoli63499d42011-10-24 18:50:03 +0200836 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200837}
Patrick Benavoli68a91282011-08-31 11:23:23 +0200838
839/// Domains
Patrick Benavoli63499d42011-10-24 18:50:03 +0200840CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200841{
842 (void)remoteCommand;
843
Patrick Benavoli63499d42011-10-24 18:50:03 +0200844 getConfigurableDomains()->listDomains(strResult);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200845
Patrick Benavoli63499d42011-10-24 18:50:03 +0200846 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200847}
848
Patrick Benavoli63499d42011-10-24 18:50:03 +0200849CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200850{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200851 return createDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200852}
853
Patrick Benavoli63499d42011-10-24 18:50:03 +0200854CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200855{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200856 return deleteDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200857}
858
Patrick Benavoli63499d42011-10-24 18:50:03 +0200859CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200860{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200861 return getConfigurableDomains()->renameDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200862}
863
Patrick Benavoli63499d42011-10-24 18:50:03 +0200864CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200865{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200866 // Check tuning mode
867 if (!checkTuningModeOn(strResult)) {
868
869 return CCommandHandler::EFailed;
870 }
871
872 // Set property
873 bool bSequenceAware;
874
875 if (remoteCommand.getArgument(1) == "true") {
876
877 bSequenceAware = true;
878
879 } else if (remoteCommand.getArgument(1) == "false") {
880
881 bSequenceAware = false;
882
883 } else {
884 // Show usage
885 return CCommandHandler::EShowUsage;
886 }
887
888 return getConfigurableDomains()->setSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200889}
890
Patrick Benavoli63499d42011-10-24 18:50:03 +0200891CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200892{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200893 // Get property
894 bool bSequenceAware;
895
896 if (!getConfigurableDomains()->getSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult)) {
897
898 return CCommandHandler::EFailed;
899 }
900
901 strResult = bSequenceAware ? "true" : "false";
902
903 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200904}
905
Patrick Benavoli63499d42011-10-24 18:50:03 +0200906CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200907{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200908 return getConfigurableDomains()->listDomainElements(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200909}
910
Patrick Benavoli63499d42011-10-24 18:50:03 +0200911CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::addElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200912{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200913 return addConfigurableElementToDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
914}
915
916CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::removeElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
917{
918 return removeConfigurableElementFromDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
919}
920
921CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::splitDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
922{
923 return split(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200924}
925
926/// Configurations
Patrick Benavoli63499d42011-10-24 18:50:03 +0200927CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConfigurationsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200928{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200929 return getConfigurableDomains()->listConfigurations(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200930}
931
Patrick Benavoli63499d42011-10-24 18:50:03 +0200932CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200933{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200934 return createConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200935}
936
Patrick Benavoli63499d42011-10-24 18:50:03 +0200937CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200938{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200939 return deleteConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200940}
941
Patrick Benavoli63499d42011-10-24 18:50:03 +0200942CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200943{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200944 return getConfigurableDomains()->renameConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200945}
946
Patrick Benavoli63499d42011-10-24 18:50:03 +0200947CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::saveConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200948{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200949 return saveConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200950}
951
Patrick Benavoli63499d42011-10-24 18:50:03 +0200952CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::restoreConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200953{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200954 return restoreConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
955}
956
957CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
958{
959 // Check tuning mode
960 if (!checkTuningModeOn(strResult)) {
961
962 return CCommandHandler::EFailed;
963 }
964
965 // Build configurable element path list
966 vector<string> astrNewElementSequence;
967
968 uint32_t uiArgument;
969
970 for (uiArgument = 2; uiArgument < remoteCommand.getArgumentCount(); uiArgument++) {
971
972 astrNewElementSequence.push_back(remoteCommand.getArgument(uiArgument));
973 }
974
975 // Delegate to configurable domains
976 return getConfigurableDomains()->setElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), astrNewElementSequence, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
977}
978
979CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
980{
981 // Delegate to configurable domains
982 return getConfigurableDomains()->getElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200983}
984
985/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +0200986CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200987{
988 CElementLocator elementLocator(getSystemClass(), false);
989
990 CElement* pLocatedElement = NULL;
991
992 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
993
Patrick Benavoli63499d42011-10-24 18:50:03 +0200994 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200995 }
996
997 strResult = string("\n");
998
999 if (!pLocatedElement) {
1000
1001 // List from root folder
1002
1003 // Return system class qualified name
1004 pLocatedElement = getSystemClass();
1005 }
1006
1007 // Return sub-elements
1008 strResult += pLocatedElement->listQualifiedPaths(false);
1009
Patrick Benavoli63499d42011-10-24 18:50:03 +02001010 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001011}
1012
1013/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001014CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listParametersCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001015{
1016 CElementLocator elementLocator(getSystemClass(), false);
1017
1018 CElement* pLocatedElement = NULL;
1019
1020 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1021
Patrick Benavoli63499d42011-10-24 18:50:03 +02001022 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001023 }
1024
1025 strResult = string("\n");
1026
1027 if (!pLocatedElement) {
1028
1029 // List from root folder
1030
1031 // Return system class qualified name
1032 pLocatedElement = getSystemClass();
1033 }
1034
1035 // Return sub-elements
1036 strResult += pLocatedElement->listQualifiedPaths(true);
1037
Patrick Benavoli63499d42011-10-24 18:50:03 +02001038 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001039}
1040
Patrick Benavoli63499d42011-10-24 18:50:03 +02001041CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001042{
1043 CElementLocator elementLocator(getSystemClass());
1044
1045 CElement* pLocatedElement = NULL;
1046
1047 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1048
Patrick Benavoli63499d42011-10-24 18:50:03 +02001049 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001050 }
1051
1052 string strError;
1053
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001054 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001055
1056 // Dump elements
1057 pLocatedElement->dumpContent(strResult, parameterAccessContext);
1058
Patrick Benavoli63499d42011-10-24 18:50:03 +02001059 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001060}
1061
Patrick Benavoli63499d42011-10-24 18:50:03 +02001062CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSizeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001063{
1064 CElementLocator elementLocator(getSystemClass());
1065
1066 CElement* pLocatedElement = NULL;
1067
1068 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1069
Patrick Benavoli63499d42011-10-24 18:50:03 +02001070 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001071 }
1072
1073 // Converted to actual sizable element
1074 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1075
1076 // Get size as string
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001077 strResult = pConfigurableElement->getFootprintAsString();
Patrick Benavoli68a91282011-08-31 11:23:23 +02001078
Patrick Benavoli63499d42011-10-24 18:50:03 +02001079 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001080}
1081
Patrick Benavoli63499d42011-10-24 18:50:03 +02001082CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showPropertiesCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001083{
1084 CElementLocator elementLocator(getSystemClass());
1085
1086 CElement* pLocatedElement = NULL;
1087
1088 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1089
Patrick Benavoli63499d42011-10-24 18:50:03 +02001090 return CCommandHandler::EFailed;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001091 }
1092
1093 // Convert element
1094 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1095
1096 // Return element properties
1097 pConfigurableElement->showProperties(strResult);
1098
Patrick Benavoli63499d42011-10-24 18:50:03 +02001099 return CCommandHandler::ESucceeded;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001100}
1101
Patrick Benavoli63499d42011-10-24 18:50:03 +02001102CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001103{
1104 string strValue;
1105
1106 if (!getValue(remoteCommand.getArgument(0), strValue, strResult)) {
1107
Patrick Benavoli63499d42011-10-24 18:50:03 +02001108 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001109 }
1110 // Succeeded
1111 strResult = strValue;
1112
Patrick Benavoli63499d42011-10-24 18:50:03 +02001113 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001114}
1115
Patrick Benavoli63499d42011-10-24 18:50:03 +02001116CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001117{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001118 return setValue(remoteCommand.getArgument(0), remoteCommand.packArguments(1, remoteCommand.getArgumentCount() - 1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001119}
1120
Patrick Benavoli63499d42011-10-24 18:50:03 +02001121CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listBelongingDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001122{
1123 CElementLocator elementLocator(getSystemClass());
1124
1125 CElement* pLocatedElement = NULL;
1126
1127 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1128
Patrick Benavoli63499d42011-10-24 18:50:03 +02001129 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001130 }
1131
1132 // Convert element
1133 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1134
1135 // Return element belonging domains
1136 pConfigurableElement->listBelongingDomains(strResult);
1137
Patrick Benavoli63499d42011-10-24 18:50:03 +02001138 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001139}
1140
Patrick Benavoli63499d42011-10-24 18:50:03 +02001141CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001142{
1143 CElementLocator elementLocator(getSystemClass());
1144
1145 CElement* pLocatedElement = NULL;
1146
1147 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1148
Patrick Benavoli63499d42011-10-24 18:50:03 +02001149 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001150 }
1151
1152 // Convert element
1153 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1154
1155 // Return element belonging domains
1156 pConfigurableElement->listAssociatedDomains(strResult);
1157
Patrick Benavoli63499d42011-10-24 18:50:03 +02001158 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001159}
1160
Patrick Benavoli63499d42011-10-24 18:50:03 +02001161CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001162{
1163 (void)remoteCommand;
1164
1165 getConfigurableDomains()->listAssociatedElements(strResult);
1166
Patrick Benavoli63499d42011-10-24 18:50:03 +02001167 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001168}
1169
Patrick Benavoli63499d42011-10-24 18:50:03 +02001170CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConflictingElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001171{
1172 (void)remoteCommand;
1173
1174 getConfigurableDomains()->listConflictingElements(strResult);
1175
Patrick Benavoli63499d42011-10-24 18:50:03 +02001176 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001177}
1178
Patrick Benavoli63499d42011-10-24 18:50:03 +02001179CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listRogueElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001180{
1181 (void)remoteCommand;
1182
1183 getSystemClass()->listRogueElements(strResult);
1184
Patrick Benavoli63499d42011-10-24 18:50:03 +02001185 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001186}
1187
1188/// Settings Import/Export
Patrick Benavoli63499d42011-10-24 18:50:03 +02001189CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001190{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001191 return exportDomainsXml(remoteCommand.getArgument(0), false, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001192}
1193
Patrick Benavoli63499d42011-10-24 18:50:03 +02001194CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001195{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001196 return importDomainsXml(remoteCommand.getArgument(0), false, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001197}
1198
Patrick Benavoli63499d42011-10-24 18:50:03 +02001199CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001200{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001201 return exportDomainsXml(remoteCommand.getArgument(0), true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001202}
1203
Patrick Benavoli63499d42011-10-24 18:50:03 +02001204CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001205{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001206 return importDomainsXml(remoteCommand.getArgument(0), true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001207}
1208
Patrick Benavoli63499d42011-10-24 18:50:03 +02001209CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001210{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001211 return exportDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001212}
1213
Patrick Benavoli63499d42011-10-24 18:50:03 +02001214CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001215{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001216 return importDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001217}
1218
1219// User set/get parameters
1220bool CParameterMgr::setValue(const string& strPath, const string& strValue, string& strError)
1221{
1222 // Check tuning mode
1223 if (!checkTuningModeOn(strError)) {
1224
1225 return false;
1226 }
1227
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001228 // Delegate to low level functionality
1229 return doSetValue(strPath, strValue, _bValueSpaceIsRaw, false, strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001230}
1231
1232bool CParameterMgr::getValue(const string& strPath, string& strValue, string& strError) const
1233{
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001234 // Delegate to low level functionality
1235 return doGetValue(strPath, strValue, _bValueSpaceIsRaw, _bOutputRawFormatIsHex, false, strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001236}
1237
1238// Tuning mode
1239bool CParameterMgr::setTuningMode(bool bOn, string& strError)
1240{
1241 // Tuning allowed?
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001242 if (bOn && !getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001243
1244 strError = "Tuning prohibited";
1245
1246 return false;
1247 }
1248 // Lock state
Patrick Benavoli1387bda2011-08-31 11:23:24 +02001249 CAutoLock autoLock(&_tuningModeMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001250
1251 // Warn domains about exiting tuning mode
1252 if (!bOn && _bTuningModeIsOn) {
1253
1254 // Ensure application of currently selected configurations
Patrick Benavoli1387bda2011-08-31 11:23:24 +02001255 // Force-apply configurations
Patrick Benavoli68a91282011-08-31 11:23:23 +02001256 if (!getConfigurableDomains()->apply(_pMainParameterBlackboard, true, strError)) {
1257
1258 return false;
1259 }
1260 // Turn auto sync back on
1261 _bAutoSyncOn = true;
1262 }
1263
1264 // Store
1265 _bTuningModeIsOn = bOn;
1266
Patrick Benavoli68a91282011-08-31 11:23:23 +02001267 return true;
1268}
1269
1270bool CParameterMgr::tuningModeOn() const
1271{
1272 return _bTuningModeIsOn;
1273}
1274
1275// Current value space for user set/get value interpretation
1276void CParameterMgr::setValueSpace(bool bIsRaw)
1277{
1278 _bValueSpaceIsRaw = bIsRaw;
1279}
1280
1281bool CParameterMgr::valueSpaceIsRaw()
1282{
1283 return _bValueSpaceIsRaw;
1284}
1285
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001286// Current Output Raw Format for user get value interpretation
1287void CParameterMgr::setOutputRawFormat(bool bIsHex)
1288{
1289 _bOutputRawFormatIsHex = bIsHex;
1290}
1291
1292bool CParameterMgr::outputRawFormatIsHex()
1293{
1294 return _bOutputRawFormatIsHex;
1295}
1296
Patrick Benavoli68a91282011-08-31 11:23:23 +02001297/// Sync
1298// Automatic hardware synchronization control (during tuning session)
1299bool CParameterMgr::setAutoSync(bool bAutoSyncOn, string& strError)
1300{
1301 // Check tuning mode
1302 if (!checkTuningModeOn(strError)) {
1303
1304 return false;
1305 }
1306 // Warn domains about turning auto sync back on
1307 if (bAutoSyncOn && !_bAutoSyncOn) {
1308
Patrick Benavoli592ae562011-09-05 16:53:58 +02001309 // Do the synchronization at system class level (could be optimized by keeping track of all modified parameters)
1310 if (!sync(strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001311
1312 return false;
1313 }
1314 }
1315
1316 // Set Auto sync
1317 _bAutoSyncOn = bAutoSyncOn;
1318
1319 return true;
1320}
1321
1322bool CParameterMgr::autoSyncOn() const
1323{
1324 return _bAutoSyncOn;
1325}
1326
1327// Manual hardware synchronization control (during tuning session)
1328bool CParameterMgr::sync(string& strError)
1329{
1330 // Check tuning mode
1331 if (!checkTuningModeOn(strError)) {
1332
1333 return false;
1334 }
1335 // Warn domains about turning auto sync back on
1336 if (_bAutoSyncOn) {
1337
1338 strError = "Feature unavailable when Auto Sync is on";
1339
1340 return false;
1341 }
1342
1343 // Get syncer set
1344 CSyncerSet syncerSet;
1345 // ... from system class
1346 getConstSystemClass()->fillSyncerSet(syncerSet);
1347 // Sync
1348 return syncerSet.sync(*_pMainParameterBlackboard, false, strError);
1349}
1350
1351// Content dump
1352void CParameterMgr::logStructureContent(string& strContent) const
1353{
1354 string strError;
1355
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001356 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001357
1358 dumpContent(strContent, parameterAccessContext);
1359}
1360
1361// Configuration/Domains handling
1362bool CParameterMgr::createDomain(const string& strName, string& strError)
1363{
1364 // Check tuning mode
1365 if (!checkTuningModeOn(strError)) {
1366
1367 return false;
1368 }
1369
1370 // Delegate to configurable domains
1371 return getConfigurableDomains()->createDomain(strName, strError);
1372}
1373
1374bool CParameterMgr::deleteDomain(const string& strName, string& strError)
1375{
1376 // Check tuning mode
1377 if (!checkTuningModeOn(strError)) {
1378
1379 return false;
1380 }
1381
1382 // Delegate to configurable domains
1383 return getConfigurableDomains()->deleteDomain(strName, strError);
1384}
1385
1386bool CParameterMgr::createConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1387{
1388 // Check tuning mode
1389 if (!checkTuningModeOn(strError)) {
1390
1391 return false;
1392 }
1393
1394 // Delegate to configurable domains
1395 return getConfigurableDomains()->createConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1396}
1397
1398bool CParameterMgr::deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1399{
1400 // Check tuning mode
1401 if (!checkTuningModeOn(strError)) {
1402
1403 return false;
1404 }
1405
1406 // Delegate to configurable domains
1407 return getConfigurableDomains()->deleteConfiguration(strDomain, strConfiguration, strError);
1408}
1409
1410bool CParameterMgr::restoreConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1411{
1412 // Check tuning mode
1413 if (!checkTuningModeOn(strError)) {
1414
1415 return false;
1416 }
1417
1418 // Delegate to configurable domains
1419 return getConfigurableDomains()->restoreConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, strError);
1420}
1421
1422bool CParameterMgr::saveConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1423{
1424 // Check tuning mode
1425 if (!checkTuningModeOn(strError)) {
1426
1427 return false;
1428 }
1429
1430 // Delegate to configurable domains
1431 return getConfigurableDomains()->saveConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1432}
1433
1434// Configurable element - domain association
1435bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1436{
1437 // Check tuning mode
1438 if (!checkTuningModeOn(strError)) {
1439
1440 return false;
1441 }
1442
1443 CElementLocator elementLocator(getSystemClass());
1444
1445 CElement* pLocatedElement = NULL;
1446
1447 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1448
1449 return false;
1450 }
1451
1452 // Convert element
1453 CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1454
1455 // Delegate
1456 return getConfigurableDomains()->addConfigurableElementToDomain(strDomain, pConfigurableElement, _pMainParameterBlackboard, strError);
1457}
1458
1459bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1460{
1461 // Check tuning mode
1462 if (!checkTuningModeOn(strError)) {
1463
1464 return false;
1465 }
1466
1467 CElementLocator elementLocator(getSystemClass());
1468
1469 CElement* pLocatedElement = NULL;
1470
1471 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1472
Patrick Benavoli63499d42011-10-24 18:50:03 +02001473 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001474 }
1475
1476 // Convert element
1477 CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1478
1479 // Delegate
1480 return getConfigurableDomains()->removeConfigurableElementFromDomain(strDomain, pConfigurableElement, strError);
1481}
1482
1483bool CParameterMgr::split(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1484{
1485 // Check tuning mode
1486 if (!checkTuningModeOn(strError)) {
1487
1488 return false;
1489 }
1490
1491 CElementLocator elementLocator(getSystemClass());
1492
1493 CElement* pLocatedElement = NULL;
1494
1495 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1496
Patrick Benavoli63499d42011-10-24 18:50:03 +02001497 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001498 }
1499
1500 // Convert element
1501 CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1502
1503 // Delegate
1504 return getConfigurableDomains()->split(strDomain, pConfigurableElement, strError);
1505}
1506
1507// XML Import/Export
1508bool CParameterMgr::importDomainsXml(const string& strFileName, bool bWithSettings, string& strError)
1509{
1510 // Check tuning mode
1511 if (!checkTuningModeOn(strError)) {
1512
1513 return false;
1514 }
1515
1516 // check path is absolute
1517 if (strFileName[0] != '/') {
1518
1519 strError = "Please provide absolute path";
1520
1521 return false;
1522 }
1523 // Root element
1524 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1525
1526 // Context
1527 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1528
1529 // Secltion criteria definition for rule creation
1530 xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
1531
1532 // Parse
1533 if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strFileName, "", EParameterConfigurationLibrary, "SystemClassName")) {
1534
1535 return false;
1536 }
1537
1538 // Validate domains after XML import
1539 pConfigurableDomains->validate(_pMainParameterBlackboard);
1540
1541 return true;
1542}
1543
1544bool CParameterMgr::exportDomainsXml(const string& strFileName, bool bWithSettings, string& strError) const
1545{
1546 // check path is absolute
1547 if (strFileName[0] != '/') {
1548
1549 strError = "Please provide absolute path";
1550
1551 return false;
1552 }
1553
1554 // Root element
1555 const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains();
1556
1557 // Get Schema file associated to root element
1558 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pConfigurableDomains->getKind() + ".xsd";
1559
1560 // Context
1561 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1562
1563 // Value space
1564 xmlDomainSerializingContext.setValueSpaceRaw(_bValueSpaceIsRaw);
1565
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001566 // Output raw format
1567 xmlDomainSerializingContext.setOutputRawFormat(_bOutputRawFormatIsHex);
1568
Patrick Benavoli68a91282011-08-31 11:23:23 +02001569 // Instantiate composer
1570 CXmlComposer xmlComposer(strFileName, strXmlSchemaFilePath, pConfigurableDomains->getKind(), xmlDomainSerializingContext);
1571
1572 // Open composer
1573 if (!xmlComposer.open()) {
1574
1575 return false;
1576 }
1577
1578 // Compose
Patrick Benavoli63499d42011-10-24 18:50:03 +02001579 xmlComposer.compose(pConfigurableDomains, "parameter-framework", getVersion());
Patrick Benavoli68a91282011-08-31 11:23:23 +02001580
1581 // Close composer
1582 if (!xmlComposer.close()) {
1583
1584 return false;
1585 }
1586
1587 return true;
1588}
1589
1590// Binary Import/Export
1591bool CParameterMgr::importDomainsBinary(const string& strFileName, string& strError)
1592{
1593 // Check tuning mode
1594 if (!checkTuningModeOn(strError)) {
1595
1596 return false;
1597 }
1598 // check path is absolute
1599 if (strFileName[0] != '/') {
1600
1601 strError = "Please provide absolute path";
1602
1603 return false;
1604 }
1605 // Root element
1606 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1607
1608 // Serialize in
1609 return pConfigurableDomains->serializeSettings(strFileName, false, _uiStructureChecksum, strError);
1610}
1611
1612bool CParameterMgr::exportDomainsBinary(const string& strFileName, string& strError)
1613{
1614 // check path is absolute
1615 if (strFileName[0] != '/') {
1616
1617 strError = "Please provide absolute path";
1618
1619 return false;
1620 }
Patrick Benavoli68a91282011-08-31 11:23:23 +02001621
Patrick Benavoli68a91282011-08-31 11:23:23 +02001622 // Root element
1623 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1624
1625 // Serialize out
1626 return pConfigurableDomains->serializeSettings(strFileName, true, _uiStructureChecksum, strError);
1627}
1628
1629// For tuning, check we're in tuning mode
1630bool CParameterMgr::checkTuningModeOn(string& strError) const
1631{
1632 // Tuning Mode on?
1633 if (!_bTuningModeIsOn) {
1634
1635 strError = "Tuning Mode must be on";
1636
1637 return false;
1638 }
1639 return true;
1640}
1641
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001642// Parameter access
1643bool CParameterMgr::doSetValue(const string& strPath, const string& strValue, bool bRawValueSpace, bool bDynamicAccess, string& strError)
1644{
1645 CPathNavigator pathNavigator(strPath);
1646
Patrick Benavoli99041c52011-11-07 20:01:02 +01001647 // Nagivate through system class
1648 if (!pathNavigator.navigateThrough(getSystemClass()->getName(), strError)) {
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001649
1650 return false;
1651 }
1652
1653 // Define context
Patrick Benavoli99041c52011-11-07 20:01:02 +01001654 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, bRawValueSpace);
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001655
1656 // Set auto sync
1657 parameterAccessContext.setAutoSync(_bAutoSyncOn);
1658
1659 // Set dynamic access
1660 parameterAccessContext.setDynamicAccess(bDynamicAccess);
1661
1662 // Do the set
1663 return getSystemClass()->setValue(pathNavigator, strValue, parameterAccessContext);
1664}
1665
1666bool CParameterMgr::doGetValue(const string& strPath, string& strValue, bool bRawValueSpace, bool bHexOutputRawFormat, bool bDynamicAccess, string& strError) const
1667{
1668 CPathNavigator pathNavigator(strPath);
1669
Patrick Benavoli99041c52011-11-07 20:01:02 +01001670 // Nagivate through system class
1671 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001672
1673 return false;
1674 }
1675
1676 // Define context
1677 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, bRawValueSpace, bHexOutputRawFormat);
1678
1679 // Set dynamic access
1680 parameterAccessContext.setDynamicAccess(bDynamicAccess);
1681
1682 // Do the get
1683 return getConstSystemClass()->getValue(pathNavigator, strValue, parameterAccessContext);
1684}
1685
Patrick Benavoli68a91282011-08-31 11:23:23 +02001686// Dynamic creation library feeding
1687void CParameterMgr::feedElementLibraries()
1688{
1689 // Global Configuration handling
1690 CElementLibrary* pFrameworkConfigurationLibrary = new CElementLibrary;
1691
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001692 pFrameworkConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CParameterFrameworkConfiguration>("ParameterFrameworkConfiguration"));
1693 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationGroup>("SubsystemPluginFolders"));
1694 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("PluginFolderLocation"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001695 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("StructureDescriptionFileLocation"));
1696 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationGroup>("SettingsConfiguration"));
1697 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("ConfigurableDomainsFileLocation"));
1698 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("BinarySettingsFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001699
1700 _pElementLibrarySet->addElementLibrary(pFrameworkConfigurationLibrary);
1701
1702 // Parameter creation
1703 CElementLibrary* pParameterCreationLibrary = new CElementLibrary;
1704
1705 pParameterCreationLibrary->addElementBuilder(new CSubsystemElementBuilder(getSystemClass()->getSubsystemLibrary()));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001706 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CComponentType>("ComponentType"));
1707 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CComponentInstance>("Component"));
1708 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBitParameterType>("BitParameter"));
1709 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBitParameterBlockType>("BitParameterBlock"));
Patrick Benavoli1352ae52011-10-21 16:48:04 +02001710 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CStringParameterType>("StringParameter"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001711 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CParameterBlockType>("ParameterBlock"));
1712 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBooleanParameterType>("BooleanParameter"));
1713 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CIntegerParameterType>("IntegerParameter"));
Patrick Benavoli9fc3c0d2011-10-27 14:27:27 +02001714 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CEnumParameterType>("EnumParameter"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001715 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CFixedPointParameterType>("FixedPointParameter"));
1716 pParameterCreationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CXmlFileIncluderElement>("SubsystemInclude"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001717
1718 _pElementLibrarySet->addElementLibrary(pParameterCreationLibrary);
1719
1720 // Parameter Configuration Domains creation
1721 CElementLibrary* pParameterConfigurationLibrary = new CElementLibrary;
1722
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001723 pParameterConfigurationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CConfigurableDomain>("ConfigurableDomain"));
1724 pParameterConfigurationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CDomainConfiguration>("Configuration"));
1725 pParameterConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CCompoundRule>("CompoundRule"));
1726 pParameterConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CSelectionCriterionRule>("SelectionCriterionRule"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001727
1728 _pElementLibrarySet->addElementLibrary(pParameterConfigurationLibrary);
1729}
1730
1731// Remote Processor Server connection handling
1732bool CParameterMgr::handleRemoteProcessingInterface(string& strError)
1733{
1734 CAutoLog autoLog(this, "Handling remote processing interface");
1735
1736 // Start server if tuning allowed
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001737 if (getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001738
1739 log("Loading remote processor library");
1740
1741 // Load library
1742 void* lib_handle = dlopen("libremote-processor.so", RTLD_NOW);
1743
1744 if (!lib_handle) {
1745
1746 // Return error
1747 const char* pcError = dlerror();
1748
1749 if (pcError) {
1750
1751 strError = pcError;
1752 } else {
1753
1754 strError = "Unable to load libremote-processor.so library";
1755 }
1756
1757 return false;
1758 }
1759
1760 CreateRemoteProcessorServer pfnCreateRemoteProcessorServer = (CreateRemoteProcessorServer)dlsym(lib_handle, "createRemoteProcessorServer");
1761
1762 if (!pfnCreateRemoteProcessorServer) {
1763
1764 strError = "libremote-process.so does not contain createRemoteProcessorServer symbol.";
1765
1766 return false;
1767 }
1768
1769 // Create server
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001770 _pRemoteProcessorServer = pfnCreateRemoteProcessorServer(getConstFrameworkConfiguration()->getServerPort(), _pCommandHandler);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001771
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001772 log("Starting remote processor server on port %d", getConstFrameworkConfiguration()->getServerPort());
Patrick Benavoli68a91282011-08-31 11:23:23 +02001773 // Start
1774 if (!_pRemoteProcessorServer->start()) {
1775
1776 strError = "Unable to start remote processor server";
1777
1778 return false;
1779 }
1780 }
1781
1782 return true;
1783}
1784
1785// Back synchronization
1786CBackSynchronizer* CParameterMgr::createBackSynchronizer(string& strError) const
1787{
1788#ifdef SIMULATION
1789 // In simulation, back synchronization of the blackboard won't probably work
1790 // We need to ensure though the blackboard is initialized with valid data
1791 return new CSimulatedBackSynchronizer(getConstSystemClass(), strError, _pMainParameterBlackboard);
1792#else
1793 // Real back synchronizer from subsystems
1794 return new CHardwareBackSynchronizer(getConstSystemClass(), strError, _pMainParameterBlackboard);
1795#endif
1796}
1797
1798// Children typwise access
1799CParameterFrameworkConfiguration* CParameterMgr::getFrameworkConfiguration()
1800{
1801 return static_cast<CParameterFrameworkConfiguration*>(getChild(EFrameworkConfiguration));
1802}
1803
1804const CParameterFrameworkConfiguration* CParameterMgr::getConstFrameworkConfiguration()
1805{
1806 return getFrameworkConfiguration();
1807}
1808
1809CSelectionCriteria* CParameterMgr::getSelectionCriteria()
1810{
1811 return static_cast<CSelectionCriteria*>(getChild(ESelectionCriteria));
1812}
1813
1814const CSelectionCriteria* CParameterMgr::getConstSelectionCriteria()
1815{
1816 return static_cast<const CSelectionCriteria*>(getChild(ESelectionCriteria));
1817}
1818
1819CSystemClass* CParameterMgr::getSystemClass()
1820{
1821 return static_cast<CSystemClass*>(getChild(ESystemClass));
1822}
1823
1824const CSystemClass* CParameterMgr::getConstSystemClass() const
1825{
1826 return static_cast<const CSystemClass*>(getChild(ESystemClass));
1827}
1828
1829// Configurable Domains
1830CConfigurableDomains* CParameterMgr::getConfigurableDomains()
1831{
1832 return static_cast<CConfigurableDomains*>(getChild(EConfigurableDomains));
1833}
1834
1835const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains()
1836{
1837 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
1838}
1839
1840const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains() const
1841{
1842 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
1843}