blob: ddce6104845e145a2a2c2791c5201419e4fa4db9 [file] [log] [blame]
Kevin Rocard93250d12012-07-19 17:48:30 +02001/*
Patrick Benavoli68a91282011-08-31 11:23:23 +02002 * INTEL CONFIDENTIAL
3 * Copyright © 2011 Intel
4 * Corporation All Rights Reserved.
5 *
6 * The source code contained or described herein and all documents related to
7 * the source code ("Material") are owned by Intel Corporation or its suppliers
8 * or licensors. Title to the Material remains with Intel Corporation or its
9 * suppliers and licensors. The Material contains trade secrets and proprietary
10 * and confidential information of Intel or its suppliers and licensors. The
11 * Material is protected by worldwide copyright and trade secret laws and
12 * treaty provisions. No part of the Material may be used, copied, reproduced,
13 * modified, published, uploaded, posted, transmitted, distributed, or
14 * disclosed in any way without Intel’s prior express written permission.
15 *
16 * No license under any patent, copyright, trade secret or other intellectual
17 * property right is granted to or conferred upon you by disclosure or delivery
18 * of the Materials, either expressly, by implication, inducement, estoppel or
19 * otherwise. Any license under such intellectual property rights must be
20 * express and approved by Intel in writing.
21 *
Patrick Benavoli68a91282011-08-31 11:23:23 +020022 * CREATED: 2011-06-01
23 * UPDATED: 2011-07-27
Patrick Benavoli68a91282011-08-31 11:23:23 +020024 */
25#include "ParameterMgr.h"
26#include "XmlParser.h"
27#include "XmlParameterSerializingContext.h"
28#include "XmlElementSerializingContext.h"
29#include "SystemClass.h"
30#include "ElementLibrarySet.h"
31#include "SubsystemLibrary.h"
32#include "NamedElementBuilderTemplate.h"
33#include "KindElementBuilderTemplate.h"
34#include "ElementBuilderTemplate.h"
35#include "SelectionCriterionType.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020036#include "SubsystemElementBuilder.h"
37#include "SelectionCriteria.h"
38#include "ComponentType.h"
39#include "ComponentInstance.h"
40#include "ParameterBlockType.h"
41#include "BooleanParameterType.h"
42#include "IntegerParameterType.h"
43#include "FixedPointParameterType.h"
44#include "ParameterBlackboard.h"
45#include "Parameter.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020046#include "ParameterBlackboard.h"
47#include "ParameterAccessContext.h"
48#include "XmlFileIncluderElement.h"
49#include "ParameterFrameworkConfiguration.h"
50#include "FrameworkConfigurationGroup.h"
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +010051#include "PluginLocation.h"
52#include "SubsystemPlugins.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020053#include "FrameworkConfigurationLocation.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020054#include "ConfigurableDomains.h"
55#include "ConfigurableDomain.h"
56#include "DomainConfiguration.h"
57#include "XmlComposer.h"
58#include "XmlDomainSerializingContext.h"
59#include "BitParameterBlockType.h"
60#include "BitParameterType.h"
Patrick Benavoli1352ae52011-10-21 16:48:04 +020061#include "StringParameterType.h"
Patrick Benavoli9fc3c0d2011-10-27 14:27:27 +020062#include "EnumParameterType.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020063#include "RemoteProcessorServerInterface.h"
64#include "ElementLocator.h"
65#include "AutoLog.h"
66#include "CompoundRule.h"
67#include "SelectionCriterionRule.h"
68#include "SimulatedBackSynchronizer.h"
69#include "HardwareBackSynchronizer.h"
Patrick Benavoli1387bda2011-08-31 11:23:24 +020070#include "AutoLock.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020071#include <strings.h>
72#include <dlfcn.h>
73#include <assert.h>
Patrick Benavoli065264a2011-11-20 15:46:41 +010074#include "ParameterHandle.h"
Patrick Benavoliee65e6d2011-11-20 18:52:24 +010075#include "LinearParameterAdaptation.h"
Patrick Benavoli68808c62012-02-02 17:12:41 +010076#include "EnumValuePair.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// ---------------------------------------------
Patrick Benavoli95ac0342011-11-07 20:32:51 +010089//├── <ParameterFrameworkConfiguration>.xml
Patrick Benavoli68a91282011-08-31 11:23:23 +020090//├── Schemas
91//│ └── *.xsd
92//├── Settings
93//│ └── <SystemClassName folder>*
94//│ ├── <ConfigurableDomains>.xml
95//│ └── <Settings>.bin?
96//└── Structure
97// └── <SystemClassName folder>*
98// ├── <SystemClassName>Class.xml
99// └── <Subsystem>.xml*
100// --------------------------------------------
101
102
103// Remote command parser array
Patrick Benavoli592ae562011-09-05 16:53:58 +0200104const CParameterMgr::SRemoteCommandParserItem CParameterMgr::gastRemoteCommandParserItems[] = {
Patrick Benavoli592ae562011-09-05 16:53:58 +0200105 /// Version
106 { "version", &CParameterMgr::versionCommandProcess, 0, "", "Show version" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200107 /// 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" },
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100126 { "dumpDomains", &CParameterMgr::dumpDomainsCommmandProcess, 0, "", "Show all domains and configurations, including applicability conditions" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200127 { "createDomain", &CParameterMgr::createDomainCommmandProcess, 1, "<domain>", "Create new configurable domain" },
128 { "deleteDomain", &CParameterMgr::deleteDomainCommmandProcess, 1, "<domain>", "Delete configurable domain" },
Kevin Rocard170f0a42012-06-18 13:56:05 +0200129 { "deleteAllDomains", &CParameterMgr::deleteAllDomainsCommmandProcess, 0, "", "Delete all configurable domains" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200130 { "renameDomain", &CParameterMgr::renameDomainCommmandProcess, 2, "<domain> <new name>", "Rename configurable domain" },
Patrick Benavoli63499d42011-10-24 18:50:03 +0200131 { "setSequenceAwareness", &CParameterMgr::setSequenceAwarenessCommmandProcess, 1, "<domain> true|false*", "Set configurable domain sequence awareness" },
132 { "getSequenceAwareness", &CParameterMgr::getSequenceAwarenessCommmandProcess, 1, "<domain>", "Get configurable domain sequence awareness" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200133 { "listDomainElements", &CParameterMgr::listDomainElementsCommmandProcess, 1, "<domain>", "List elements associated to configurable domain" },
134 { "addElement", &CParameterMgr::addElementCommmandProcess, 2, "<domain> <elem path>", "Associate element at given path to configurable domain" },
135 { "removeElement", &CParameterMgr::removeElementCommmandProcess, 2, "<domain> <elem path>", "Dissociate element at given path from configurable domain" },
136 { "splitDomain", &CParameterMgr::splitDomainCommmandProcess, 2, "<domain> <elem path>", "Split configurable domain at given associated element path" },
137 /// Configurations
138 { "listConfigurations", &CParameterMgr::listConfigurationsCommmandProcess, 1, "<domain>", "List domain configurations" },
139 { "createConfiguration", &CParameterMgr::createConfigurationCommmandProcess, 2, "<domain> <configuration>", "Create new domain configuration" },
140 { "deleteConfiguration", &CParameterMgr::deleteConfigurationCommmandProcess, 2, "<domain> <configuration>", "Delete domain configuration" },
141 { "renameConfiguration", &CParameterMgr::renameConfigurationCommmandProcess, 3, "<domain> <configuration> <new name>", "Rename domain configuration" },
142 { "saveConfiguration", &CParameterMgr::saveConfigurationCommmandProcess, 2, "<domain> <configuration>", "Save current settings into configuration" },
143 { "restoreConfiguration", &CParameterMgr::restoreConfigurationCommmandProcess, 2, "<domain> <configuration>", "Restore current settings from configuration" },
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100144 { "setElementSequence", &CParameterMgr::setElementSequenceCommmandProcess, 3, "<domain> <configuration> <elem path list>", "Set element application order for configuration" },
Patrick Benavoli63499d42011-10-24 18:50:03 +0200145 { "getElementSequence", &CParameterMgr::getElementSequenceCommmandProcess, 2, "<domain> <configuration>", "Get element application order for configuration" },
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100146 { "setRule", &CParameterMgr::setRuleCommmandProcess, 3, "<domain> <configuration> <rule>", "Set configuration application rule" },
147 { "clearRule", &CParameterMgr::clearRuleCommmandProcess, 2, "<domain> <configuration>", "Clear configuration application rule" },
148 { "getRule", &CParameterMgr::getRuleCommmandProcess, 2, "<domain> <configuration>", "Get configuration application rule" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200149 /// Elements/Parameters
150 { "listElements", &CParameterMgr::listElementsCommmandProcess, 1, "<elem path>|/", "List elements under element at given path or root" },
Patrick Benavoli592ae562011-09-05 16:53:58 +0200151 { "listParameters", &CParameterMgr::listParametersCommmandProcess, 1, "<elem path>|/", "List parameters under element at given path or root" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200152 { "dumpElement", &CParameterMgr::dumpElementCommmandProcess, 1, "<elem path>", "Dump structure and content of element at given path" },
153 { "getElementSize", &CParameterMgr::getElementSizeCommmandProcess, 1, "<elem path>", "Show size of element at given path" },
Patrick Benavoli2ecf9002011-08-31 11:23:24 +0200154 { "showProperties", &CParameterMgr::showPropertiesCommmandProcess, 1, "<elem path>", "Show properties of element at given path" },
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200155 { "getParameter", &CParameterMgr::getParameterCommmandProcess, 1, "<param path>", "Get value for parameter at given path" },
Patrick Benavoli2ecf9002011-08-31 11:23:24 +0200156 { "setParameter", &CParameterMgr::setParameterCommmandProcess, 2, "<param path> <value>", "Set value for parameter at given path" },
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200157 { "listBelongingDomains", &CParameterMgr::listBelongingDomainsCommmandProcess, 1, "<elem path>", "List domain(s) element at given path belongs to" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200158 { "listAssociatedDomains", &CParameterMgr::listAssociatedDomainsCommmandProcess, 1, "<elem path>", "List domain(s) element at given path is associated to" },
159 /// Browse
160 { "listAssociatedElements", &CParameterMgr::listAssociatedElementsCommmandProcess, 0, "", "List element sub-trees associated to at least one configurable domain" },
161 { "listConflictingElements", &CParameterMgr::listConflictingElementsCommmandProcess, 0, "", "List element sub-trees contained in more than one configurable domain" },
162 { "listRogueElements", &CParameterMgr::listRogueElementsCommmandProcess, 0, "", "List element sub-trees owned by no configurable domain" },
163 /// Settings Import/Export
164 { "exportDomainsXML", &CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess, 1, "<file path> ", "Export domains to XML file" },
165 { "importDomainsXML", &CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess, 1, "<file path>", "Import domains from XML file" },
166 { "exportDomainsWithSettingsXML", &CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess, 1, "<file path> ", "Export domains including settings to XML file" },
167 { "importDomainsWithSettingsXML", &CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess, 1, "<file path>", "Import domains including settings from XML file" },
168 { "exportSettings", &CParameterMgr::exportSettingsCommmandProcess, 1, "<file path>", "Export settings to binary file" },
169 { "importSettings", &CParameterMgr::importSettingsCommmandProcess, 1, "<file path>", "Import settings from binary file" }
170};
171// Remote command parsers array Size
Patrick Benavoli592ae562011-09-05 16:53:58 +0200172const uint32_t CParameterMgr::guiNbRemoteCommandParserItems = sizeof(gastRemoteCommandParserItems) / sizeof(gastRemoteCommandParserItems[0]);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200173
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100174CParameterMgr::CParameterMgr(const string& strConfigurationFilePath) :
Patrick Benavoli68a91282011-08-31 11:23:23 +0200175 _bTuningModeIsOn(false),
176 _bValueSpaceIsRaw(false),
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200177 _bOutputRawFormatIsHex(false),
Patrick Benavoli68a91282011-08-31 11:23:23 +0200178 _bAutoSyncOn(true),
179 _pMainParameterBlackboard(new CParameterBlackboard),
180 _pElementLibrarySet(new CElementLibrarySet),
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100181 _strXmlConfigurationFilePath(strConfigurationFilePath),
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100182 _pSubsystemPlugins(NULL),
Patrick Benavoli68a91282011-08-31 11:23:23 +0200183 _uiStructureChecksum(0),
184 _pRemoteProcessorServer(NULL),
185 _uiMaxCommandUsageLength(0),
186 _pLogger(NULL),
187 _uiLogDepth(0)
188{
189 // Tuning Mode Mutex
Patrick Benavoli065264a2011-11-20 15:46:41 +0100190 bzero(&_blackboardMutex, sizeof(_blackboardMutex));
191 pthread_mutex_init(&_blackboardMutex, NULL);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200192
193 // Deal with children
194 addChild(new CParameterFrameworkConfiguration);
195 addChild(new CSelectionCriteria);
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100196 addChild(new CSystemClass);
197 addChild(new CConfigurableDomains);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200198
199 // Feed element library
200 feedElementLibraries();
Patrick Benavoli63499d42011-10-24 18:50:03 +0200201
202 _pCommandHandler = new CCommandHandler(this);
203
204 // Add command parsers
205 uint32_t uiRemoteCommandParserItem;
206
207 for (uiRemoteCommandParserItem = 0; uiRemoteCommandParserItem < guiNbRemoteCommandParserItems; uiRemoteCommandParserItem++) {
208
209 const SRemoteCommandParserItem* pRemoteCommandParserItem = &gastRemoteCommandParserItems[uiRemoteCommandParserItem];
210
211 _pCommandHandler->addCommandParser(pRemoteCommandParserItem->_pcCommandName,
212 pRemoteCommandParserItem->_pfnParser,
213 pRemoteCommandParserItem->_uiMinArgumentCount,
214 pRemoteCommandParserItem->_pcHelp,
215 pRemoteCommandParserItem->_pcDescription);
216 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100217
218 // Configuration file folder
219 uint32_t uiSlashPos = _strXmlConfigurationFilePath.rfind('/', -1);
220
221 assert(uiSlashPos != (uint32_t)-1);
222
223 _strXmlConfigurationFolderPath = _strXmlConfigurationFilePath.substr(0, uiSlashPos);
224
225 // Schema absolute folder location
226 _strSchemaFolderLocation = _strXmlConfigurationFolderPath + "/" + gacSystemSchemasSubFolder;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200227}
228
229CParameterMgr::~CParameterMgr()
230{
231 // Children
232 delete _pRemoteProcessorServer;
Frederic Boisnard31242302012-04-26 17:07:34 +0200233 delete _pCommandHandler;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200234 delete _pMainParameterBlackboard;
235 delete _pElementLibrarySet;
236
237 // Tuning Mode Mutex
Patrick Benavoli065264a2011-11-20 15:46:41 +0100238 pthread_mutex_destroy(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200239}
240
241string CParameterMgr::getKind() const
242{
243 return "ParameterMgr";
244}
245
246// Logging
247void CParameterMgr::setLogger(CParameterMgr::ILogger* pLogger)
248{
249 _pLogger = pLogger;
250}
251
252// Logging
253void CParameterMgr::doLog(const string& strLog) const
254{
255 if (_pLogger) {
256
257 // Nest
258 string strIndent;
259
260 // Level
261 uint32_t uiNbIndents = _uiLogDepth;
262
263 while (uiNbIndents--) {
264
265 strIndent += " ";
266 }
267
268 // Log
269 _pLogger->log(strIndent + strLog);
270 }
271}
272
273void CParameterMgr::nestLog() const
274{
Patrick Benavoli592ae562011-09-05 16:53:58 +0200275 _uiLogDepth++;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200276}
277
278void CParameterMgr::unnestLog() const
279{
Patrick Benavoli592ae562011-09-05 16:53:58 +0200280 _uiLogDepth--;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200281}
282
Patrick Benavoli63499d42011-10-24 18:50:03 +0200283// Version
284string CParameterMgr::getVersion() const
285{
286 string strVersion;
287
288 // Major
289 strVersion = toString(guiEditionMajor) + ".";
290 // Minor
291 strVersion += toString(guiEditionMinor) + ".";
292 // Revision
293 strVersion += toString(guiRevision);
294
295 return strVersion;
296}
297
Patrick Benavoli68a91282011-08-31 11:23:23 +0200298bool CParameterMgr::load(string& strError)
299{
300 CAutoLog autoLog(this, "Loading");
301
302 // Load Framework configuration
303 if (!loadFrameworkConfiguration(strError)) {
304
305 return false;
306 }
307
308 // Load subsystems
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100309 if (!getSystemClass()->loadSubsystems(strError, _pSubsystemPlugins)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200310
311 return false;
312 }
313
314 // Load structure
315 if (!loadStructure(strError)) {
316
317 return false;
318 }
319
320 // Load settings
321 if (!loadSettings(strError)) {
322
323 return false;
324 }
325
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200326 // Back synchronization for areas in parameter blackboard not covered by any domain
327 CBackSynchronizer* pBackSynchronizer = createBackSynchronizer(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200328
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200329 log("Main blackboard back synchronization");
330
331 // Back-synchronize
332 if (!pBackSynchronizer->sync()) {
333 // Get rid of back synchronizer
334 delete pBackSynchronizer;
335
336 strError = "Main blackboard back synchronization failed: " + strError;
337
338 return false;
339 }
340 // Get rif of back synchronizer
341 delete pBackSynchronizer;
342
343 // We're done loading the settings and back synchronizing
344 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
345
346 // We need to ensure all domains are valid
347 pConfigurableDomains->validate(_pMainParameterBlackboard);
348
349 // Ensure application of currently selected configurations
350 // Force-apply configurations
351 if (!pConfigurableDomains->apply(_pMainParameterBlackboard, true, strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200352
353 return false;
354 }
355
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200356 // Start remote processor server if appropriate
357 return handleRemoteProcessingInterface(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200358}
359
360bool CParameterMgr::loadFrameworkConfiguration(string& strError)
361{
362 CAutoLog autoLog(this, "Loading framework configuration");
363
Patrick Benavoli68a91282011-08-31 11:23:23 +0200364 // Parse Structure XML file
365 CXmlElementSerializingContext elementSerializingContext(strError);
366
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100367 if (!xmlParse(elementSerializingContext, getFrameworkConfiguration(), _strXmlConfigurationFilePath, _strXmlConfigurationFolderPath, EFrameworkConfigurationLibrary)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200368
369 return false;
370 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100371 // Set class name to system class and configurable domains
372 getSystemClass()->setName(getConstFrameworkConfiguration()->getSystemClassName());
373 getConfigurableDomains()->setName(getConstFrameworkConfiguration()->getSystemClassName());
374
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100375 // Get subsystem plugins elements
376 _pSubsystemPlugins = static_cast<const CSubsystemPlugins*>(getConstFrameworkConfiguration()->findChild("SubsystemPlugins"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200377
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100378 if (!_pSubsystemPlugins) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200379
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100380 strError = "Parameter Framework Configuration: couldn't find SubsystemPlugins element";
Patrick Benavoli68a91282011-08-31 11:23:23 +0200381
382 return false;
383 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200384
Patrick Benavoli68a91282011-08-31 11:23:23 +0200385 // Log tuning availability
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100386 log("Tuning %s", getConstFrameworkConfiguration()->isTuningAllowed() ? "allowed" : "prohibited");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200387
388 return true;
389}
390
391bool CParameterMgr::loadStructure(string& strError)
392{
393 // Retrieve system to load structure to
394 CSystemClass* pSystemClass = getSystemClass();
395
396 CAutoLog autoLog(this, "Loading " + pSystemClass->getName() + " system class structure");
397
398 // Get structure description element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100399 const CFrameworkConfigurationLocation* pStructureDescriptionFileLocation = static_cast<const CFrameworkConfigurationLocation*>(getConstFrameworkConfiguration()->findChildOfKind("StructureDescriptionFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200400
401 if (!pStructureDescriptionFileLocation) {
402
403 strError = "No StructureDescriptionFileLocation element found for SystemClass " + pSystemClass->getName();
404
405 return false;
406 }
407
408 // Get Xml structure folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100409 string strXmlStructureFolder = pStructureDescriptionFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200410
411 // Get Xml structure file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100412 string strXmlStructureFilePath = pStructureDescriptionFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200413
414 // Parse Structure XML file
415 CXmlParameterSerializingContext parameterBuildContext(strError);
416
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200417 log("Importing system structure from file %s", strXmlStructureFilePath.c_str());
418
Patrick Benavoli68a91282011-08-31 11:23:23 +0200419 if (!xmlParse(parameterBuildContext, pSystemClass, strXmlStructureFilePath, strXmlStructureFolder, EParameterCreationLibrary)) {
420
421 return false;
422 }
423
424 // Initialize offsets
425 pSystemClass->setOffset(0);
426
427 // Initialize main blackboard's size
428 _pMainParameterBlackboard->setSize(pSystemClass->getFootPrint());
429
430 return true;
431}
432
433bool CParameterMgr::loadSettings(string& strError)
434{
435 CAutoLog autoLog(this, "Loading settings");
436
437 // Get settings configuration element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100438 const CFrameworkConfigurationGroup* pParameterConfigurationGroup = static_cast<const CFrameworkConfigurationGroup*>(getConstFrameworkConfiguration()->findChildOfKind("SettingsConfiguration"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200439
440 if (!pParameterConfigurationGroup) {
441
442 // No settings to load
443
444 return true;
445 }
446 // Get binary settings file location
447 const CFrameworkConfigurationLocation* pBinarySettingsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("BinarySettingsFileLocation"));
448
449 string strXmlBinarySettingsFilePath;
450
451 if (pBinarySettingsFileLocation) {
452
453 // Get Xml binary settings file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100454 strXmlBinarySettingsFilePath = pBinarySettingsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200455 }
456
457 // Get configurable domains element
458 const CFrameworkConfigurationLocation* pConfigurableDomainsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("ConfigurableDomainsFileLocation"));
459
460 if (!pConfigurableDomainsFileLocation) {
461
462 strError = "No ConfigurableDomainsFileLocation element found for SystemClass " + getSystemClass()->getName();
463
464 return false;
465 }
466 // Get destination root element
467 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
468
469 // Get Xml configuration domains file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100470 string strXmlConfigurationDomainsFilePath = pConfigurableDomainsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200471
472 // Get Xml configuration domains folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100473 string strXmlConfigurationDomainsFolder = pConfigurableDomainsFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200474
475 // Parse configuration domains XML file (ask to read settings from XML file if they are not provided as binary)
476 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, !pBinarySettingsFileLocation);
477
478 // Selection criteria definition for rule creation
479 xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
480
Patrick Benavoli63499d42011-10-24 18:50:03 +0200481 // Auto validation of configurations if no binary settings provided
482 xmlDomainSerializingContext.setAutoValidationRequired(!pBinarySettingsFileLocation);
483
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200484 log("Importing configurable domains from file %s %s settings", strXmlConfigurationDomainsFilePath.c_str(), pBinarySettingsFileLocation ? "without" : "with");
485
Patrick Benavoli68a91282011-08-31 11:23:23 +0200486 // Do parse
487 if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strXmlConfigurationDomainsFilePath, strXmlConfigurationDomainsFolder, EParameterConfigurationLibrary, "SystemClassName")) {
488
489 return false;
490 }
491 // We have loaded the whole system structure, compute checksum
492 const CSystemClass* pSystemClass = getConstSystemClass();
493 _uiStructureChecksum = pSystemClass->computeStructureChecksum() + getConfigurableDomains()->computeStructureChecksum() + getSelectionCriteria()->computeStructureChecksum();
494
495 // Load binary settings if any provided
496 if (pBinarySettingsFileLocation && !pConfigurableDomains->serializeSettings(strXmlBinarySettingsFilePath, false, _uiStructureChecksum, strError)) {
497
498 return false;
499 }
500
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200501 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200502}
503
504// XML parsing
505bool CParameterMgr::xmlParse(CXmlElementSerializingContext& elementSerializingContext, CElement* pRootElement, const string& strXmlFilePath, const string& strXmlFolder, CParameterMgr::ElementLibrary eElementLibrary, const string& strNameAttrituteName)
506{
507 // Init serializing context
508 elementSerializingContext.set(_pElementLibrarySet->getElementLibrary(eElementLibrary), strXmlFolder, _strSchemaFolderLocation);
509
510 // Get Schema file associated to root element
511 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pRootElement->getKind() + ".xsd";
512
513 // Parse Structure XML file
514 CXmlParser parser(strXmlFilePath, strXmlSchemaFilePath, pRootElement->getKind(), elementSerializingContext);
515
516 if (!parser.open()) {
517
518 return false;
519 }
520
521 // Check Root element name attribute (if any)
522 string strRootElementName = parser.getRootElementAttributeString(strNameAttrituteName);
523
524 if (!strRootElementName.empty() && strRootElementName != pRootElement->getName()) {
525
526 elementSerializingContext.setError("Error: Wrong XML structure file " + strXmlFilePath);
527 elementSerializingContext.appendLineToError(pRootElement->getKind() + " element " + pRootElement->getName() + " mismatches expected " + pRootElement->getKind() + " type " + pRootElement->getName());
528
529 return false;
530 }
531
532 // Start clean
533 pRootElement->clean();
534
535 // Parse
536 if (!parser.parse(pRootElement)) {
537
538 // Cleanup
539 pRootElement->clean();
540
541 return false;
542 }
543
544 // Close parser
545 if (!parser.close()) {
546
547 return false;
548 }
549
550 return true;
551}
552
553// Init
554bool CParameterMgr::init(string& strError)
555{
556 return base::init(strError);
557}
558
559// Selection criteria interface
560CSelectionCriterionType* CParameterMgr::createSelectionCriterionType(bool bIsInclusive)
561{
562 // Propagate
563 return getSelectionCriteria()->createSelectionCriterionType(bIsInclusive);
564}
565
566CSelectionCriterion* CParameterMgr::createSelectionCriterion(const string& strName, const CSelectionCriterionType* pSelectionCriterionType)
567{
568 // Propagate
569 return getSelectionCriteria()->createSelectionCriterion(strName, pSelectionCriterionType);
570}
571
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200572// Selection criterion retrieval
573CSelectionCriterion* CParameterMgr::getSelectionCriterion(const string& strName)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200574{
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200575 // Propagate
576 return getSelectionCriteria()->getSelectionCriterion(strName);
577}
578
579// Selection criteria changed event
580bool CParameterMgr::applyConfigurations(string& strError)
581{
582 CAutoLog autoLog(this, "Configuration application request");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200583
584 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +0100585 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200586
587 if (!_bTuningModeIsOn) {
588
589 // Apply configuration(s)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200590 if (!getConfigurableDomains()->apply(_pMainParameterBlackboard, false, strError)) {
591
592 log("Failed to apply configurations!");
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200593
594 return false;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200595 }
596 }
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200597
598 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200599}
600
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200601// Dynamic parameter handling
Patrick Benavoli065264a2011-11-20 15:46:41 +0100602CParameterHandle* CParameterMgr::createParameterHandle(const string& strPath, string& strError)
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200603{
Patrick Benavoli065264a2011-11-20 15:46:41 +0100604 CPathNavigator pathNavigator(strPath);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200605
Patrick Benavoli065264a2011-11-20 15:46:41 +0100606 // Nagivate through system class
607 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
608
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100609 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100610 }
611
612 // Find element
613 const CElement* pElement = getConstSystemClass()->findDescendant(pathNavigator);
614
615 if (!pElement) {
616
617 strError = "Path not found";
618
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100619 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100620 }
621
622 // Check found element is a parameter
623 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pElement);
624
625 if (!pConfigurableElement->isParameter()) {
626
627 // Element is not parameter
628 strError = "Not a parameter";
629
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100630 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100631 }
632
633 // Convert as parameter and return new handle
634 return new CParameterHandle(static_cast<const CBaseParameter*>(pElement), this);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200635}
636
Patrick Benavoli68a91282011-08-31 11:23:23 +0200637/////////////////// Remote command parsers
Patrick Benavoli592ae562011-09-05 16:53:58 +0200638/// Version
Patrick Benavoli63499d42011-10-24 18:50:03 +0200639CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::versionCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli592ae562011-09-05 16:53:58 +0200640{
641 (void)remoteCommand;
642
Patrick Benavoli63499d42011-10-24 18:50:03 +0200643 // Show version
644 strResult = getVersion();
Patrick Benavoli592ae562011-09-05 16:53:58 +0200645
Patrick Benavoli63499d42011-10-24 18:50:03 +0200646 return CCommandHandler::ESucceeded;
Patrick Benavoli592ae562011-09-05 16:53:58 +0200647}
648
Patrick Benavoli68a91282011-08-31 11:23:23 +0200649/// Status
Patrick Benavoli63499d42011-10-24 18:50:03 +0200650CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::statusCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200651{
652 (void)remoteCommand;
653 // System class
654 const CSystemClass* pSystemClass = getSystemClass();
655
Patrick Benavoli68a91282011-08-31 11:23:23 +0200656 // Show status
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200657 /// General section
658 appendTitle(strResult, "General:");
659 // System class
Patrick Benavoli68a91282011-08-31 11:23:23 +0200660 strResult += "System Class: ";
661 strResult += pSystemClass->getName();
662 strResult += "\n";
663
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200664 // Tuning mode
Patrick Benavoli68a91282011-08-31 11:23:23 +0200665 strResult += "Tuning Mode: ";
666 strResult += tuningModeOn() ? "on" : "off";
667 strResult += "\n";
668
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200669 // Value space
Patrick Benavoli68a91282011-08-31 11:23:23 +0200670 strResult += "Value Space: ";
671 strResult += valueSpaceIsRaw() ? "raw" : "real";
672 strResult += "\n";
673
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200674 // Output raw format
675 strResult += "Output Raw Format: ";
676 strResult += outputRawFormatIsHex() ? "hex" : "dec";
677 strResult += "\n";
678
679 // Auto Sync
Patrick Benavoli68a91282011-08-31 11:23:23 +0200680 strResult += "Auto Sync: ";
681 strResult += autoSyncOn() ? "on" : "off";
682 strResult += "\n";
683
684 /// Subsystem list
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200685 appendTitle(strResult, "Subsystems:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200686 string strSubsystemList;
687 pSystemClass->listChildrenPaths(strSubsystemList);
688 strResult += strSubsystemList;
689
690 /// Last applied configurations
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200691 appendTitle(strResult, "Last applied configurations:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200692 string strLastAppliedConfigurations;
693 getConfigurableDomains()->listLastAppliedConfigurations(strLastAppliedConfigurations);
694 strResult += strLastAppliedConfigurations;
695
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200696 /// Criteria states
697 appendTitle(strResult, "Selection criteria:");
698 string strSelectionCriteria;
699 getSelectionCriteria()->listSelectionCriteria(strSelectionCriteria, false);
700 strResult += strSelectionCriteria;
701
Patrick Benavoli63499d42011-10-24 18:50:03 +0200702 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200703}
704
705/// Tuning Mode
Patrick Benavoli63499d42011-10-24 18:50:03 +0200706CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200707{
708 if (remoteCommand.getArgument(0) == "on") {
709
710 if (setTuningMode(true, strResult)) {
711
Patrick Benavoli63499d42011-10-24 18:50:03 +0200712 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200713 }
714 } else if (remoteCommand.getArgument(0) == "off") {
715
716 if (setTuningMode(false, strResult)) {
717
Patrick Benavoli63499d42011-10-24 18:50:03 +0200718 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200719 }
720 } else {
721 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200722 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200723 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200724 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200725}
726
Patrick Benavoli63499d42011-10-24 18:50:03 +0200727CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200728{
729 (void)remoteCommand;
730
731 strResult = tuningModeOn() ? "on" : "off";
732
Patrick Benavoli63499d42011-10-24 18:50:03 +0200733 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200734}
735
736/// Value Space
Patrick Benavoli63499d42011-10-24 18:50:03 +0200737CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200738{
739 (void)strResult;
740
741 if (remoteCommand.getArgument(0) == "raw") {
742
743 setValueSpace(true);
744
Patrick Benavoli63499d42011-10-24 18:50:03 +0200745 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200746
747 } else if (remoteCommand.getArgument(0) == "real") {
748
749 setValueSpace(false);
750
Patrick Benavoli63499d42011-10-24 18:50:03 +0200751 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200752
753 } else {
754 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200755 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200756 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200757 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200758}
759
Patrick Benavoli63499d42011-10-24 18:50:03 +0200760CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200761{
762 (void)remoteCommand;
763
764 strResult = valueSpaceIsRaw() ? "raw" : "real";
765
Patrick Benavoli63499d42011-10-24 18:50:03 +0200766 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200767}
768
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200769/// Output Raw Format
Patrick Benavoli63499d42011-10-24 18:50:03 +0200770CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200771{
772 (void)strResult;
773
774 if (remoteCommand.getArgument(0) == "hex") {
775
776 setOutputRawFormat(true);
777
Patrick Benavoli63499d42011-10-24 18:50:03 +0200778 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200779
780 } else if (remoteCommand.getArgument(0) == "dec") {
781
782 setOutputRawFormat(false);
783
Patrick Benavoli63499d42011-10-24 18:50:03 +0200784 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200785
786 } else {
787 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200788 return CCommandHandler::EShowUsage;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200789 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200790 return CCommandHandler::EFailed;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200791}
792
Patrick Benavoli63499d42011-10-24 18:50:03 +0200793CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200794{
795 (void)remoteCommand;
796
797 strResult = outputRawFormatIsHex() ? "hex" : "dec";
798
Patrick Benavoli63499d42011-10-24 18:50:03 +0200799 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200800}
801
Patrick Benavoli68a91282011-08-31 11:23:23 +0200802/// Sync
Patrick Benavoli63499d42011-10-24 18:50:03 +0200803CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200804{
805 if (remoteCommand.getArgument(0) == "on") {
806
807 if (setAutoSync(true, strResult)) {
808
Patrick Benavoli63499d42011-10-24 18:50:03 +0200809 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200810 }
811 } else if (remoteCommand.getArgument(0) == "off") {
812
813 if (setAutoSync(false, strResult)) {
814
Patrick Benavoli63499d42011-10-24 18:50:03 +0200815 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200816 }
817 } else {
818 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200819 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200820 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200821 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200822}
823
Patrick Benavoli63499d42011-10-24 18:50:03 +0200824CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200825{
826 (void)remoteCommand;
827
828 strResult = autoSyncOn() ? "on" : "off";
829
Patrick Benavoli63499d42011-10-24 18:50:03 +0200830 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200831}
832
Patrick Benavoli63499d42011-10-24 18:50:03 +0200833CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::syncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200834{
835 (void)remoteCommand;
836
Patrick Benavoli63499d42011-10-24 18:50:03 +0200837 return sync(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200838}
839
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200840/// Criteria
Patrick Benavoli63499d42011-10-24 18:50:03 +0200841CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listCriteriaCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200842{
843 (void)remoteCommand;
844
845 getSelectionCriteria()->listSelectionCriteria(strResult, true);
846
Patrick Benavoli63499d42011-10-24 18:50:03 +0200847 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200848}
Patrick Benavoli68a91282011-08-31 11:23:23 +0200849
850/// Domains
Patrick Benavoli63499d42011-10-24 18:50:03 +0200851CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200852{
853 (void)remoteCommand;
854
Patrick Benavoli63499d42011-10-24 18:50:03 +0200855 getConfigurableDomains()->listDomains(strResult);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200856
Patrick Benavoli63499d42011-10-24 18:50:03 +0200857 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200858}
859
Patrick Benavoli63499d42011-10-24 18:50:03 +0200860CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200861{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200862 return createDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200863}
864
Patrick Benavoli63499d42011-10-24 18:50:03 +0200865CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200866{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200867 return deleteDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200868}
869
Kevin Rocard170f0a42012-06-18 13:56:05 +0200870CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteAllDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
871{
872 (void)remoteCommand;
873
874 return deleteAllDomains(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
875}
876
Patrick Benavoli63499d42011-10-24 18:50:03 +0200877CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200878{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200879 return getConfigurableDomains()->renameDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200880}
881
Patrick Benavoli63499d42011-10-24 18:50:03 +0200882CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200883{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200884 // Check tuning mode
885 if (!checkTuningModeOn(strResult)) {
886
887 return CCommandHandler::EFailed;
888 }
889
890 // Set property
891 bool bSequenceAware;
892
893 if (remoteCommand.getArgument(1) == "true") {
894
895 bSequenceAware = true;
896
897 } else if (remoteCommand.getArgument(1) == "false") {
898
899 bSequenceAware = false;
900
901 } else {
902 // Show usage
903 return CCommandHandler::EShowUsage;
904 }
905
906 return getConfigurableDomains()->setSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200907}
908
Patrick Benavoli63499d42011-10-24 18:50:03 +0200909CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200910{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200911 // Get property
912 bool bSequenceAware;
913
914 if (!getConfigurableDomains()->getSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult)) {
915
916 return CCommandHandler::EFailed;
917 }
918
919 strResult = bSequenceAware ? "true" : "false";
920
921 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200922}
923
Patrick Benavoli63499d42011-10-24 18:50:03 +0200924CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200925{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200926 return getConfigurableDomains()->listDomainElements(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200927}
928
Patrick Benavoli63499d42011-10-24 18:50:03 +0200929CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::addElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200930{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200931 return addConfigurableElementToDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
932}
933
934CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::removeElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
935{
936 return removeConfigurableElementFromDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
937}
938
939CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::splitDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
940{
941 return split(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200942}
943
944/// Configurations
Patrick Benavoli63499d42011-10-24 18:50:03 +0200945CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConfigurationsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200946{
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100947 return getConstConfigurableDomains()->listConfigurations(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
948}
949
950CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
951{
952 (void)remoteCommand;
953
954 // Dummy error context
955 string strError;
956 CErrorContext errorContext(strError);
957
958 // Dump
959 getConstConfigurableDomains()->dumpContent(strResult, errorContext);
960
961 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200962}
963
Patrick Benavoli63499d42011-10-24 18:50:03 +0200964CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200965{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200966 return createConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200967}
968
Patrick Benavoli63499d42011-10-24 18:50:03 +0200969CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200970{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200971 return deleteConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200972}
973
Patrick Benavoli63499d42011-10-24 18:50:03 +0200974CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200975{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200976 return getConfigurableDomains()->renameConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200977}
978
Patrick Benavoli63499d42011-10-24 18:50:03 +0200979CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::saveConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200980{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200981 return saveConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200982}
983
Patrick Benavoli63499d42011-10-24 18:50:03 +0200984CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::restoreConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200985{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200986 return restoreConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
987}
988
989CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
990{
991 // Check tuning mode
992 if (!checkTuningModeOn(strResult)) {
993
994 return CCommandHandler::EFailed;
995 }
996
997 // Build configurable element path list
998 vector<string> astrNewElementSequence;
999
1000 uint32_t uiArgument;
1001
1002 for (uiArgument = 2; uiArgument < remoteCommand.getArgumentCount(); uiArgument++) {
1003
1004 astrNewElementSequence.push_back(remoteCommand.getArgument(uiArgument));
1005 }
1006
1007 // Delegate to configurable domains
1008 return getConfigurableDomains()->setElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), astrNewElementSequence, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1009}
1010
1011CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1012{
1013 // Delegate to configurable domains
1014 return getConfigurableDomains()->getElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001015}
1016
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001017CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1018{
1019 // Delegate to configurable domains
1020 return getConfigurableDomains()->setApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.packArguments(2, remoteCommand.getArgumentCount() - 2), getConstSelectionCriteria()->getSelectionCriteriaDefinition(), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1021}
1022
1023CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::clearRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1024{
1025 // Delegate to configurable domains
1026 return getConfigurableDomains()->clearApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1027}
1028
1029CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1030{
1031 // Delegate to configurable domains
1032 return getConfigurableDomains()->getApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
1033}
1034
Patrick Benavoli68a91282011-08-31 11:23:23 +02001035/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001036CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001037{
1038 CElementLocator elementLocator(getSystemClass(), false);
1039
1040 CElement* pLocatedElement = NULL;
1041
1042 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1043
Patrick Benavoli63499d42011-10-24 18:50:03 +02001044 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001045 }
1046
1047 strResult = string("\n");
1048
1049 if (!pLocatedElement) {
1050
1051 // List from root folder
1052
1053 // Return system class qualified name
1054 pLocatedElement = getSystemClass();
1055 }
1056
1057 // Return sub-elements
1058 strResult += pLocatedElement->listQualifiedPaths(false);
1059
Patrick Benavoli63499d42011-10-24 18:50:03 +02001060 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001061}
1062
1063/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001064CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listParametersCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001065{
1066 CElementLocator elementLocator(getSystemClass(), false);
1067
1068 CElement* pLocatedElement = NULL;
1069
1070 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1071
Patrick Benavoli63499d42011-10-24 18:50:03 +02001072 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001073 }
1074
1075 strResult = string("\n");
1076
1077 if (!pLocatedElement) {
1078
1079 // List from root folder
1080
1081 // Return system class qualified name
1082 pLocatedElement = getSystemClass();
1083 }
1084
1085 // Return sub-elements
1086 strResult += pLocatedElement->listQualifiedPaths(true);
1087
Patrick Benavoli63499d42011-10-24 18:50:03 +02001088 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001089}
1090
Patrick Benavoli63499d42011-10-24 18:50:03 +02001091CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001092{
1093 CElementLocator elementLocator(getSystemClass());
1094
1095 CElement* pLocatedElement = NULL;
1096
1097 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1098
Patrick Benavoli63499d42011-10-24 18:50:03 +02001099 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001100 }
1101
1102 string strError;
1103
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001104 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001105
1106 // Dump elements
1107 pLocatedElement->dumpContent(strResult, parameterAccessContext);
1108
Patrick Benavoli63499d42011-10-24 18:50:03 +02001109 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001110}
1111
Patrick Benavoli63499d42011-10-24 18:50:03 +02001112CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSizeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001113{
1114 CElementLocator elementLocator(getSystemClass());
1115
1116 CElement* pLocatedElement = NULL;
1117
1118 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1119
Patrick Benavoli63499d42011-10-24 18:50:03 +02001120 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001121 }
1122
1123 // Converted to actual sizable element
1124 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1125
1126 // Get size as string
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001127 strResult = pConfigurableElement->getFootprintAsString();
Patrick Benavoli68a91282011-08-31 11:23:23 +02001128
Patrick Benavoli63499d42011-10-24 18:50:03 +02001129 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001130}
1131
Patrick Benavoli63499d42011-10-24 18:50:03 +02001132CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showPropertiesCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001133{
1134 CElementLocator elementLocator(getSystemClass());
1135
1136 CElement* pLocatedElement = NULL;
1137
1138 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1139
Patrick Benavoli63499d42011-10-24 18:50:03 +02001140 return CCommandHandler::EFailed;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001141 }
1142
1143 // Convert element
1144 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1145
1146 // Return element properties
1147 pConfigurableElement->showProperties(strResult);
1148
Patrick Benavoli63499d42011-10-24 18:50:03 +02001149 return CCommandHandler::ESucceeded;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001150}
1151
Patrick Benavoli63499d42011-10-24 18:50:03 +02001152CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001153{
1154 string strValue;
1155
Patrick Benavoli065264a2011-11-20 15:46:41 +01001156 if (!accessValue(remoteCommand.getArgument(0), strValue, false, strResult)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001157
Patrick Benavoli63499d42011-10-24 18:50:03 +02001158 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001159 }
1160 // Succeeded
1161 strResult = strValue;
1162
Patrick Benavoli63499d42011-10-24 18:50:03 +02001163 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001164}
1165
Patrick Benavoli63499d42011-10-24 18:50:03 +02001166CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001167{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001168 // Check tuning mode
1169 if (!checkTuningModeOn(strResult)) {
1170
1171 return CCommandHandler::EFailed;
1172 }
1173 // Get value to set
1174 string strValue = remoteCommand.packArguments(1, remoteCommand.getArgumentCount() - 1);
1175
1176 return accessValue(remoteCommand.getArgument(0), strValue, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001177}
1178
Patrick Benavoli63499d42011-10-24 18:50:03 +02001179CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listBelongingDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001180{
1181 CElementLocator elementLocator(getSystemClass());
1182
1183 CElement* pLocatedElement = NULL;
1184
1185 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1186
Patrick Benavoli63499d42011-10-24 18:50:03 +02001187 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001188 }
1189
1190 // Convert element
1191 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1192
1193 // Return element belonging domains
1194 pConfigurableElement->listBelongingDomains(strResult);
1195
Patrick Benavoli63499d42011-10-24 18:50:03 +02001196 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001197}
1198
Patrick Benavoli63499d42011-10-24 18:50:03 +02001199CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001200{
1201 CElementLocator elementLocator(getSystemClass());
1202
1203 CElement* pLocatedElement = NULL;
1204
1205 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1206
Patrick Benavoli63499d42011-10-24 18:50:03 +02001207 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001208 }
1209
1210 // Convert element
1211 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1212
1213 // Return element belonging domains
1214 pConfigurableElement->listAssociatedDomains(strResult);
1215
Patrick Benavoli63499d42011-10-24 18:50:03 +02001216 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001217}
1218
Patrick Benavoli63499d42011-10-24 18:50:03 +02001219CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001220{
1221 (void)remoteCommand;
1222
1223 getConfigurableDomains()->listAssociatedElements(strResult);
1224
Patrick Benavoli63499d42011-10-24 18:50:03 +02001225 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001226}
1227
Patrick Benavoli63499d42011-10-24 18:50:03 +02001228CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConflictingElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001229{
1230 (void)remoteCommand;
1231
1232 getConfigurableDomains()->listConflictingElements(strResult);
1233
Patrick Benavoli63499d42011-10-24 18:50:03 +02001234 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001235}
1236
Patrick Benavoli63499d42011-10-24 18:50:03 +02001237CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listRogueElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001238{
1239 (void)remoteCommand;
1240
1241 getSystemClass()->listRogueElements(strResult);
1242
Patrick Benavoli63499d42011-10-24 18:50:03 +02001243 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001244}
1245
1246/// Settings Import/Export
Patrick Benavoli63499d42011-10-24 18:50:03 +02001247CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001248{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001249 return exportDomainsXml(remoteCommand.getArgument(0), false, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001250}
1251
Patrick Benavoli63499d42011-10-24 18:50:03 +02001252CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001253{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001254 return importDomainsXml(remoteCommand.getArgument(0), false, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001255}
1256
Patrick Benavoli63499d42011-10-24 18:50:03 +02001257CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001258{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001259 return exportDomainsXml(remoteCommand.getArgument(0), true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001260}
1261
Patrick Benavoli63499d42011-10-24 18:50:03 +02001262CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001263{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001264 return importDomainsXml(remoteCommand.getArgument(0), true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001265}
1266
Patrick Benavoli63499d42011-10-24 18:50:03 +02001267CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001268{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001269 return exportDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001270}
1271
Patrick Benavoli63499d42011-10-24 18:50:03 +02001272CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001273{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001274 return importDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001275}
1276
1277// User set/get parameters
Patrick Benavoli065264a2011-11-20 15:46:41 +01001278bool CParameterMgr::accessValue(const string& strPath, string& strValue, bool bSet, string& strError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001279{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001280 // Lock state
1281 CAutoLock autoLock(&_blackboardMutex);
1282
1283 CPathNavigator pathNavigator(strPath);
1284
1285 // Nagivate through system class
1286 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001287
1288 return false;
1289 }
1290
Patrick Benavoli065264a2011-11-20 15:46:41 +01001291 // Define context
1292 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001293
Patrick Benavoli68808c62012-02-02 17:12:41 +01001294 // Auto Sync
1295 if (bSet) {
1296
1297 parameterAccessContext.setAutoSync(_bAutoSyncOn);
1298 }
1299
Patrick Benavoli065264a2011-11-20 15:46:41 +01001300 // Do the get
1301 return getConstSystemClass()->accessValue(pathNavigator, strValue, bSet, parameterAccessContext);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001302}
1303
1304// Tuning mode
1305bool CParameterMgr::setTuningMode(bool bOn, string& strError)
1306{
1307 // Tuning allowed?
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001308 if (bOn && !getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001309
1310 strError = "Tuning prohibited";
1311
1312 return false;
1313 }
1314 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +01001315 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001316
1317 // Warn domains about exiting tuning mode
1318 if (!bOn && _bTuningModeIsOn) {
1319
1320 // Ensure application of currently selected configurations
Patrick Benavoli1387bda2011-08-31 11:23:24 +02001321 // Force-apply configurations
Patrick Benavoli68a91282011-08-31 11:23:23 +02001322 if (!getConfigurableDomains()->apply(_pMainParameterBlackboard, true, strError)) {
1323
1324 return false;
1325 }
1326 // Turn auto sync back on
1327 _bAutoSyncOn = true;
1328 }
1329
1330 // Store
1331 _bTuningModeIsOn = bOn;
1332
Patrick Benavoli68a91282011-08-31 11:23:23 +02001333 return true;
1334}
1335
1336bool CParameterMgr::tuningModeOn() const
1337{
1338 return _bTuningModeIsOn;
1339}
1340
1341// Current value space for user set/get value interpretation
1342void CParameterMgr::setValueSpace(bool bIsRaw)
1343{
1344 _bValueSpaceIsRaw = bIsRaw;
1345}
1346
1347bool CParameterMgr::valueSpaceIsRaw()
1348{
1349 return _bValueSpaceIsRaw;
1350}
1351
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001352// Current Output Raw Format for user get value interpretation
1353void CParameterMgr::setOutputRawFormat(bool bIsHex)
1354{
1355 _bOutputRawFormatIsHex = bIsHex;
1356}
1357
1358bool CParameterMgr::outputRawFormatIsHex()
1359{
1360 return _bOutputRawFormatIsHex;
1361}
1362
Patrick Benavoli68a91282011-08-31 11:23:23 +02001363/// Sync
1364// Automatic hardware synchronization control (during tuning session)
1365bool CParameterMgr::setAutoSync(bool bAutoSyncOn, string& strError)
1366{
1367 // Check tuning mode
1368 if (!checkTuningModeOn(strError)) {
1369
1370 return false;
1371 }
1372 // Warn domains about turning auto sync back on
1373 if (bAutoSyncOn && !_bAutoSyncOn) {
1374
Patrick Benavoli592ae562011-09-05 16:53:58 +02001375 // Do the synchronization at system class level (could be optimized by keeping track of all modified parameters)
1376 if (!sync(strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001377
1378 return false;
1379 }
1380 }
1381
1382 // Set Auto sync
1383 _bAutoSyncOn = bAutoSyncOn;
1384
1385 return true;
1386}
1387
1388bool CParameterMgr::autoSyncOn() const
1389{
1390 return _bAutoSyncOn;
1391}
1392
1393// Manual hardware synchronization control (during tuning session)
1394bool CParameterMgr::sync(string& strError)
1395{
1396 // Check tuning mode
1397 if (!checkTuningModeOn(strError)) {
1398
1399 return false;
1400 }
1401 // Warn domains about turning auto sync back on
1402 if (_bAutoSyncOn) {
1403
1404 strError = "Feature unavailable when Auto Sync is on";
1405
1406 return false;
1407 }
1408
1409 // Get syncer set
1410 CSyncerSet syncerSet;
1411 // ... from system class
1412 getConstSystemClass()->fillSyncerSet(syncerSet);
1413 // Sync
1414 return syncerSet.sync(*_pMainParameterBlackboard, false, strError);
1415}
1416
1417// Content dump
1418void CParameterMgr::logStructureContent(string& strContent) const
1419{
1420 string strError;
1421
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001422 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001423
1424 dumpContent(strContent, parameterAccessContext);
1425}
1426
1427// Configuration/Domains handling
1428bool CParameterMgr::createDomain(const string& strName, string& strError)
1429{
1430 // Check tuning mode
1431 if (!checkTuningModeOn(strError)) {
1432
1433 return false;
1434 }
1435
1436 // Delegate to configurable domains
1437 return getConfigurableDomains()->createDomain(strName, strError);
1438}
1439
1440bool CParameterMgr::deleteDomain(const string& strName, string& strError)
1441{
1442 // Check tuning mode
1443 if (!checkTuningModeOn(strError)) {
1444
1445 return false;
1446 }
1447
1448 // Delegate to configurable domains
1449 return getConfigurableDomains()->deleteDomain(strName, strError);
1450}
1451
Kevin Rocard170f0a42012-06-18 13:56:05 +02001452bool CParameterMgr::deleteAllDomains(string& strError)
1453{
1454 // Check tuning mode
1455 if (!checkTuningModeOn(strError)) {
1456
1457 return false;
1458 }
1459
1460 // Delegate to configurable domains
1461 getConfigurableDomains()->deleteAllDomains();
1462
1463 return true;
1464}
1465
Patrick Benavoli68a91282011-08-31 11:23:23 +02001466bool CParameterMgr::createConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1467{
1468 // Check tuning mode
1469 if (!checkTuningModeOn(strError)) {
1470
1471 return false;
1472 }
1473
1474 // Delegate to configurable domains
1475 return getConfigurableDomains()->createConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1476}
1477
1478bool CParameterMgr::deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1479{
1480 // Check tuning mode
1481 if (!checkTuningModeOn(strError)) {
1482
1483 return false;
1484 }
1485
1486 // Delegate to configurable domains
1487 return getConfigurableDomains()->deleteConfiguration(strDomain, strConfiguration, strError);
1488}
1489
1490bool CParameterMgr::restoreConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1491{
1492 // Check tuning mode
1493 if (!checkTuningModeOn(strError)) {
1494
1495 return false;
1496 }
1497
1498 // Delegate to configurable domains
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001499 return getConstConfigurableDomains()->restoreConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001500}
1501
1502bool CParameterMgr::saveConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1503{
1504 // Check tuning mode
1505 if (!checkTuningModeOn(strError)) {
1506
1507 return false;
1508 }
1509
1510 // Delegate to configurable domains
1511 return getConfigurableDomains()->saveConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1512}
1513
1514// Configurable element - domain association
1515bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1516{
1517 // Check tuning mode
1518 if (!checkTuningModeOn(strError)) {
1519
1520 return false;
1521 }
1522
1523 CElementLocator elementLocator(getSystemClass());
1524
1525 CElement* pLocatedElement = NULL;
1526
1527 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1528
1529 return false;
1530 }
1531
1532 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001533 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001534
1535 // Delegate
1536 return getConfigurableDomains()->addConfigurableElementToDomain(strDomain, pConfigurableElement, _pMainParameterBlackboard, strError);
1537}
1538
1539bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1540{
1541 // Check tuning mode
1542 if (!checkTuningModeOn(strError)) {
1543
1544 return false;
1545 }
1546
1547 CElementLocator elementLocator(getSystemClass());
1548
1549 CElement* pLocatedElement = NULL;
1550
1551 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1552
Patrick Benavoli63499d42011-10-24 18:50:03 +02001553 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001554 }
1555
1556 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001557 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001558
1559 // Delegate
1560 return getConfigurableDomains()->removeConfigurableElementFromDomain(strDomain, pConfigurableElement, strError);
1561}
1562
1563bool CParameterMgr::split(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1564{
1565 // Check tuning mode
1566 if (!checkTuningModeOn(strError)) {
1567
1568 return false;
1569 }
1570
1571 CElementLocator elementLocator(getSystemClass());
1572
1573 CElement* pLocatedElement = NULL;
1574
1575 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1576
Patrick Benavoli63499d42011-10-24 18:50:03 +02001577 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001578 }
1579
1580 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001581 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001582
1583 // Delegate
1584 return getConfigurableDomains()->split(strDomain, pConfigurableElement, strError);
1585}
1586
1587// XML Import/Export
1588bool CParameterMgr::importDomainsXml(const string& strFileName, bool bWithSettings, string& strError)
1589{
1590 // Check tuning mode
1591 if (!checkTuningModeOn(strError)) {
1592
1593 return false;
1594 }
1595
1596 // check path is absolute
1597 if (strFileName[0] != '/') {
1598
1599 strError = "Please provide absolute path";
1600
1601 return false;
1602 }
1603 // Root element
1604 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1605
1606 // Context
1607 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1608
1609 // Secltion criteria definition for rule creation
1610 xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
1611
1612 // Parse
1613 if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strFileName, "", EParameterConfigurationLibrary, "SystemClassName")) {
1614
1615 return false;
1616 }
1617
1618 // Validate domains after XML import
1619 pConfigurableDomains->validate(_pMainParameterBlackboard);
1620
1621 return true;
1622}
1623
1624bool CParameterMgr::exportDomainsXml(const string& strFileName, bool bWithSettings, string& strError) const
1625{
1626 // check path is absolute
1627 if (strFileName[0] != '/') {
1628
1629 strError = "Please provide absolute path";
1630
1631 return false;
1632 }
1633
1634 // Root element
1635 const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains();
1636
1637 // Get Schema file associated to root element
1638 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pConfigurableDomains->getKind() + ".xsd";
1639
1640 // Context
1641 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1642
1643 // Value space
1644 xmlDomainSerializingContext.setValueSpaceRaw(_bValueSpaceIsRaw);
1645
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001646 // Output raw format
1647 xmlDomainSerializingContext.setOutputRawFormat(_bOutputRawFormatIsHex);
1648
Patrick Benavoli68a91282011-08-31 11:23:23 +02001649 // Instantiate composer
1650 CXmlComposer xmlComposer(strFileName, strXmlSchemaFilePath, pConfigurableDomains->getKind(), xmlDomainSerializingContext);
1651
1652 // Open composer
1653 if (!xmlComposer.open()) {
1654
1655 return false;
1656 }
1657
1658 // Compose
Patrick Benavoli63499d42011-10-24 18:50:03 +02001659 xmlComposer.compose(pConfigurableDomains, "parameter-framework", getVersion());
Patrick Benavoli68a91282011-08-31 11:23:23 +02001660
1661 // Close composer
1662 if (!xmlComposer.close()) {
1663
1664 return false;
1665 }
1666
1667 return true;
1668}
1669
1670// Binary Import/Export
1671bool CParameterMgr::importDomainsBinary(const string& strFileName, string& strError)
1672{
1673 // Check tuning mode
1674 if (!checkTuningModeOn(strError)) {
1675
1676 return false;
1677 }
1678 // check path is absolute
1679 if (strFileName[0] != '/') {
1680
1681 strError = "Please provide absolute path";
1682
1683 return false;
1684 }
1685 // Root element
1686 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1687
1688 // Serialize in
1689 return pConfigurableDomains->serializeSettings(strFileName, false, _uiStructureChecksum, strError);
1690}
1691
1692bool CParameterMgr::exportDomainsBinary(const string& strFileName, string& strError)
1693{
1694 // check path is absolute
1695 if (strFileName[0] != '/') {
1696
1697 strError = "Please provide absolute path";
1698
1699 return false;
1700 }
Patrick Benavoli68a91282011-08-31 11:23:23 +02001701
Patrick Benavoli68a91282011-08-31 11:23:23 +02001702 // Root element
1703 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1704
1705 // Serialize out
1706 return pConfigurableDomains->serializeSettings(strFileName, true, _uiStructureChecksum, strError);
1707}
1708
1709// For tuning, check we're in tuning mode
1710bool CParameterMgr::checkTuningModeOn(string& strError) const
1711{
1712 // Tuning Mode on?
1713 if (!_bTuningModeIsOn) {
1714
1715 strError = "Tuning Mode must be on";
1716
1717 return false;
1718 }
1719 return true;
1720}
1721
Patrick Benavoli065264a2011-11-20 15:46:41 +01001722// Tuning mutex dynamic parameter handling
1723pthread_mutex_t* CParameterMgr::getBlackboardMutex()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001724{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001725 return &_blackboardMutex;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001726}
1727
Patrick Benavoli065264a2011-11-20 15:46:41 +01001728// Blackboard reference (dynamic parameter handling)
1729CParameterBlackboard* CParameterMgr::getParameterBlackboard()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001730{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001731 return _pMainParameterBlackboard;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001732}
1733
Patrick Benavoli68a91282011-08-31 11:23:23 +02001734// Dynamic creation library feeding
1735void CParameterMgr::feedElementLibraries()
1736{
1737 // Global Configuration handling
1738 CElementLibrary* pFrameworkConfigurationLibrary = new CElementLibrary;
1739
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001740 pFrameworkConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CParameterFrameworkConfiguration>("ParameterFrameworkConfiguration"));
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +01001741 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CSubsystemPlugins>("SubsystemPlugins"));
1742 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CPluginLocation>("Location"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001743 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("StructureDescriptionFileLocation"));
1744 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationGroup>("SettingsConfiguration"));
1745 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("ConfigurableDomainsFileLocation"));
1746 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("BinarySettingsFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001747
1748 _pElementLibrarySet->addElementLibrary(pFrameworkConfigurationLibrary);
1749
1750 // Parameter creation
1751 CElementLibrary* pParameterCreationLibrary = new CElementLibrary;
1752
1753 pParameterCreationLibrary->addElementBuilder(new CSubsystemElementBuilder(getSystemClass()->getSubsystemLibrary()));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001754 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CComponentType>("ComponentType"));
1755 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CComponentInstance>("Component"));
1756 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBitParameterType>("BitParameter"));
1757 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBitParameterBlockType>("BitParameterBlock"));
Patrick Benavoli1352ae52011-10-21 16:48:04 +02001758 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CStringParameterType>("StringParameter"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001759 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CParameterBlockType>("ParameterBlock"));
1760 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBooleanParameterType>("BooleanParameter"));
1761 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CIntegerParameterType>("IntegerParameter"));
Patrick Benavoliee65e6d2011-11-20 18:52:24 +01001762 pParameterCreationLibrary->addElementBuilder(new TElementBuilderTemplate<CLinearParameterAdaptation>("LinearAdaptation"));
Patrick Benavoli9fc3c0d2011-10-27 14:27:27 +02001763 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CEnumParameterType>("EnumParameter"));
Patrick Benavoli68808c62012-02-02 17:12:41 +01001764 pParameterCreationLibrary->addElementBuilder(new TElementBuilderTemplate<CEnumValuePair>("ValuePair"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001765 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CFixedPointParameterType>("FixedPointParameter"));
1766 pParameterCreationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CXmlFileIncluderElement>("SubsystemInclude"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001767
1768 _pElementLibrarySet->addElementLibrary(pParameterCreationLibrary);
1769
1770 // Parameter Configuration Domains creation
1771 CElementLibrary* pParameterConfigurationLibrary = new CElementLibrary;
1772
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001773 pParameterConfigurationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CConfigurableDomain>("ConfigurableDomain"));
1774 pParameterConfigurationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CDomainConfiguration>("Configuration"));
1775 pParameterConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CCompoundRule>("CompoundRule"));
1776 pParameterConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CSelectionCriterionRule>("SelectionCriterionRule"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001777
1778 _pElementLibrarySet->addElementLibrary(pParameterConfigurationLibrary);
1779}
1780
1781// Remote Processor Server connection handling
1782bool CParameterMgr::handleRemoteProcessingInterface(string& strError)
1783{
1784 CAutoLog autoLog(this, "Handling remote processing interface");
1785
1786 // Start server if tuning allowed
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001787 if (getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001788
1789 log("Loading remote processor library");
1790
1791 // Load library
1792 void* lib_handle = dlopen("libremote-processor.so", RTLD_NOW);
1793
1794 if (!lib_handle) {
1795
1796 // Return error
1797 const char* pcError = dlerror();
1798
1799 if (pcError) {
1800
1801 strError = pcError;
1802 } else {
1803
1804 strError = "Unable to load libremote-processor.so library";
1805 }
1806
1807 return false;
1808 }
1809
1810 CreateRemoteProcessorServer pfnCreateRemoteProcessorServer = (CreateRemoteProcessorServer)dlsym(lib_handle, "createRemoteProcessorServer");
1811
1812 if (!pfnCreateRemoteProcessorServer) {
1813
1814 strError = "libremote-process.so does not contain createRemoteProcessorServer symbol.";
1815
1816 return false;
1817 }
1818
1819 // Create server
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001820 _pRemoteProcessorServer = pfnCreateRemoteProcessorServer(getConstFrameworkConfiguration()->getServerPort(), _pCommandHandler);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001821
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001822 log("Starting remote processor server on port %d", getConstFrameworkConfiguration()->getServerPort());
Patrick Benavoli68a91282011-08-31 11:23:23 +02001823 // Start
1824 if (!_pRemoteProcessorServer->start()) {
1825
1826 strError = "Unable to start remote processor server";
1827
1828 return false;
1829 }
1830 }
1831
1832 return true;
1833}
1834
1835// Back synchronization
1836CBackSynchronizer* CParameterMgr::createBackSynchronizer(string& strError) const
1837{
1838#ifdef SIMULATION
1839 // In simulation, back synchronization of the blackboard won't probably work
1840 // We need to ensure though the blackboard is initialized with valid data
1841 return new CSimulatedBackSynchronizer(getConstSystemClass(), strError, _pMainParameterBlackboard);
1842#else
1843 // Real back synchronizer from subsystems
1844 return new CHardwareBackSynchronizer(getConstSystemClass(), strError, _pMainParameterBlackboard);
1845#endif
1846}
1847
1848// Children typwise access
1849CParameterFrameworkConfiguration* CParameterMgr::getFrameworkConfiguration()
1850{
1851 return static_cast<CParameterFrameworkConfiguration*>(getChild(EFrameworkConfiguration));
1852}
1853
1854const CParameterFrameworkConfiguration* CParameterMgr::getConstFrameworkConfiguration()
1855{
1856 return getFrameworkConfiguration();
1857}
1858
1859CSelectionCriteria* CParameterMgr::getSelectionCriteria()
1860{
1861 return static_cast<CSelectionCriteria*>(getChild(ESelectionCriteria));
1862}
1863
1864const CSelectionCriteria* CParameterMgr::getConstSelectionCriteria()
1865{
1866 return static_cast<const CSelectionCriteria*>(getChild(ESelectionCriteria));
1867}
1868
1869CSystemClass* CParameterMgr::getSystemClass()
1870{
1871 return static_cast<CSystemClass*>(getChild(ESystemClass));
1872}
1873
1874const CSystemClass* CParameterMgr::getConstSystemClass() const
1875{
1876 return static_cast<const CSystemClass*>(getChild(ESystemClass));
1877}
1878
1879// Configurable Domains
1880CConfigurableDomains* CParameterMgr::getConfigurableDomains()
1881{
1882 return static_cast<CConfigurableDomains*>(getChild(EConfigurableDomains));
1883}
1884
1885const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains()
1886{
1887 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
1888}
1889
1890const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains() const
1891{
1892 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
1893}