blob: 3b6447a7c9c1b8162b912a19795c3ab0e6be6242 [file] [log] [blame]
Patrick Benavoli68a91282011-08-31 11:23:23 +02001/* <auto_header>
2 * <FILENAME>
3 *
4 * INTEL CONFIDENTIAL
5 * Copyright © 2011 Intel
6 * Corporation All Rights Reserved.
7 *
8 * The source code contained or described herein and all documents related to
9 * the source code ("Material") are owned by Intel Corporation or its suppliers
10 * or licensors. Title to the Material remains with Intel Corporation or its
11 * suppliers and licensors. The Material contains trade secrets and proprietary
12 * and confidential information of Intel or its suppliers and licensors. The
13 * Material is protected by worldwide copyright and trade secret laws and
14 * treaty provisions. No part of the Material may be used, copied, reproduced,
15 * modified, published, uploaded, posted, transmitted, distributed, or
16 * disclosed in any way without Intel’s prior express written permission.
17 *
18 * No license under any patent, copyright, trade secret or other intellectual
19 * property right is granted to or conferred upon you by disclosure or delivery
20 * of the Materials, either expressly, by implication, inducement, estoppel or
21 * otherwise. Any license under such intellectual property rights must be
22 * express and approved by Intel in writing.
23 *
24 * AUTHOR: Patrick Benavoli (patrickx.benavoli@intel.com)
25 * CREATED: 2011-06-01
26 * UPDATED: 2011-07-27
27 *
28 *
29 * </auto_header>
30 */
31#include "ParameterMgr.h"
32#include "XmlParser.h"
33#include "XmlParameterSerializingContext.h"
34#include "XmlElementSerializingContext.h"
35#include "SystemClass.h"
36#include "ElementLibrarySet.h"
37#include "SubsystemLibrary.h"
38#include "NamedElementBuilderTemplate.h"
39#include "KindElementBuilderTemplate.h"
40#include "ElementBuilderTemplate.h"
41#include "SelectionCriterionType.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020042#include "SubsystemElementBuilder.h"
43#include "SelectionCriteria.h"
44#include "ComponentType.h"
45#include "ComponentInstance.h"
46#include "ParameterBlockType.h"
47#include "BooleanParameterType.h"
48#include "IntegerParameterType.h"
49#include "FixedPointParameterType.h"
50#include "ParameterBlackboard.h"
51#include "Parameter.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020052#include "ParameterBlackboard.h"
53#include "ParameterAccessContext.h"
54#include "XmlFileIncluderElement.h"
55#include "ParameterFrameworkConfiguration.h"
56#include "FrameworkConfigurationGroup.h"
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +010057#include "PluginLocation.h"
58#include "SubsystemPlugins.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020059#include "FrameworkConfigurationLocation.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020060#include "ConfigurableDomains.h"
61#include "ConfigurableDomain.h"
62#include "DomainConfiguration.h"
63#include "XmlComposer.h"
64#include "XmlDomainSerializingContext.h"
65#include "BitParameterBlockType.h"
66#include "BitParameterType.h"
Patrick Benavoli1352ae52011-10-21 16:48:04 +020067#include "StringParameterType.h"
Patrick Benavoli9fc3c0d2011-10-27 14:27:27 +020068#include "EnumParameterType.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020069#include "RemoteProcessorServerInterface.h"
70#include "ElementLocator.h"
71#include "AutoLog.h"
72#include "CompoundRule.h"
73#include "SelectionCriterionRule.h"
74#include "SimulatedBackSynchronizer.h"
75#include "HardwareBackSynchronizer.h"
Patrick Benavoli1387bda2011-08-31 11:23:24 +020076#include "AutoLock.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020077#include <strings.h>
78#include <dlfcn.h>
79#include <assert.h>
Patrick Benavoli065264a2011-11-20 15:46:41 +010080#include "ParameterHandle.h"
Patrick Benavoliee65e6d2011-11-20 18:52:24 +010081#include "LinearParameterAdaptation.h"
Patrick Benavoli68808c62012-02-02 17:12:41 +010082#include "EnumValuePair.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020083
84#define base CElement
85
86// Used for remote processor server creation
87typedef IRemoteProcessorServerInterface* (*CreateRemoteProcessorServer)(uint16_t uiPort, IRemoteCommandHandler* pCommandHandler);
88
89// Global configuration file name (fixed)
90const char* gacParameterFrameworkConfigurationFileName = "ParameterFrameworkConfiguration.xml";
91const char* gacSystemSchemasSubFolder = "Schemas";
92
93// Config File System looks normally like this:
94// ---------------------------------------------
Patrick Benavoli95ac0342011-11-07 20:32:51 +010095//├── <ParameterFrameworkConfiguration>.xml
Patrick Benavoli68a91282011-08-31 11:23:23 +020096//├── Schemas
97//│ └── *.xsd
98//├── Settings
99//│ └── <SystemClassName folder>*
100//│ ├── <ConfigurableDomains>.xml
101//│ └── <Settings>.bin?
102//└── Structure
103// └── <SystemClassName folder>*
104// ├── <SystemClassName>Class.xml
105// └── <Subsystem>.xml*
106// --------------------------------------------
107
108
109// Remote command parser array
Patrick Benavoli592ae562011-09-05 16:53:58 +0200110const CParameterMgr::SRemoteCommandParserItem CParameterMgr::gastRemoteCommandParserItems[] = {
Patrick Benavoli592ae562011-09-05 16:53:58 +0200111 /// Version
112 { "version", &CParameterMgr::versionCommandProcess, 0, "", "Show version" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200113 /// Status
114 { "status", &CParameterMgr::statusCommandProcess, 0, "", "Show current status" },
115 /// Tuning Mode
116 { "setTuningMode", &CParameterMgr::setTuningModeCommmandProcess, 1, "on|off*", "Turn on or off Tuning Mode" },
117 { "getTuningMode", &CParameterMgr::getTuningModeCommmandProcess, 0, "", "Show Tuning Mode" },
118 /// Value Space
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200119 { "setValueSpace", &CParameterMgr::setValueSpaceCommmandProcess, 1, "raw|real*", "Assigns Value Space used for parameter value interpretation" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200120 { "getValueSpace", &CParameterMgr::getValueSpaceCommmandProcess, 0, "", "Show Value Space" },
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200121 /// Output Raw Format
122 { "setOutputRawFormat", &CParameterMgr::setOutputRawFormatCommmandProcess, 1, "dec*|hex", "Assigns format used to output parameter values when in raw Value Space" },
123 { "getOutputRawFormat", &CParameterMgr::getOutputRawFormatCommmandProcess, 0, "", "Show Output Raw Format" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200124 /// Sync
125 { "setAutoSync", &CParameterMgr::setAutoSyncCommmandProcess, 1, "on*|off", "Turn on or off automatic synchronization to hardware while in Tuning Mode" },
126 { "getAutoSync", &CParameterMgr::getAutoSyncCommmandProcess, 0, "", "Show Auto Sync state" },
127 { "sync", &CParameterMgr::syncCommmandProcess, 0, "", "Synchronize current settings to hardware while in Tuning Mode and Auto Sync off" },
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200128 /// Criteria
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200129 { "listCriteria", &CParameterMgr::listCriteriaCommmandProcess, 0, "", "List selection criteria" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200130 /// Domains
131 { "listDomains", &CParameterMgr::listDomainsCommmandProcess, 0, "", "List configurable domains" },
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100132 { "dumpDomains", &CParameterMgr::dumpDomainsCommmandProcess, 0, "", "Show all domains and configurations, including applicability conditions" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200133 { "createDomain", &CParameterMgr::createDomainCommmandProcess, 1, "<domain>", "Create new configurable domain" },
134 { "deleteDomain", &CParameterMgr::deleteDomainCommmandProcess, 1, "<domain>", "Delete configurable domain" },
135 { "renameDomain", &CParameterMgr::renameDomainCommmandProcess, 2, "<domain> <new name>", "Rename configurable domain" },
Patrick Benavoli63499d42011-10-24 18:50:03 +0200136 { "setSequenceAwareness", &CParameterMgr::setSequenceAwarenessCommmandProcess, 1, "<domain> true|false*", "Set configurable domain sequence awareness" },
137 { "getSequenceAwareness", &CParameterMgr::getSequenceAwarenessCommmandProcess, 1, "<domain>", "Get configurable domain sequence awareness" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200138 { "listDomainElements", &CParameterMgr::listDomainElementsCommmandProcess, 1, "<domain>", "List elements associated to configurable domain" },
139 { "addElement", &CParameterMgr::addElementCommmandProcess, 2, "<domain> <elem path>", "Associate element at given path to configurable domain" },
140 { "removeElement", &CParameterMgr::removeElementCommmandProcess, 2, "<domain> <elem path>", "Dissociate element at given path from configurable domain" },
141 { "splitDomain", &CParameterMgr::splitDomainCommmandProcess, 2, "<domain> <elem path>", "Split configurable domain at given associated element path" },
142 /// Configurations
143 { "listConfigurations", &CParameterMgr::listConfigurationsCommmandProcess, 1, "<domain>", "List domain configurations" },
144 { "createConfiguration", &CParameterMgr::createConfigurationCommmandProcess, 2, "<domain> <configuration>", "Create new domain configuration" },
145 { "deleteConfiguration", &CParameterMgr::deleteConfigurationCommmandProcess, 2, "<domain> <configuration>", "Delete domain configuration" },
146 { "renameConfiguration", &CParameterMgr::renameConfigurationCommmandProcess, 3, "<domain> <configuration> <new name>", "Rename domain configuration" },
147 { "saveConfiguration", &CParameterMgr::saveConfigurationCommmandProcess, 2, "<domain> <configuration>", "Save current settings into configuration" },
148 { "restoreConfiguration", &CParameterMgr::restoreConfigurationCommmandProcess, 2, "<domain> <configuration>", "Restore current settings from configuration" },
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100149 { "setElementSequence", &CParameterMgr::setElementSequenceCommmandProcess, 3, "<domain> <configuration> <elem path list>", "Set element application order for configuration" },
Patrick Benavoli63499d42011-10-24 18:50:03 +0200150 { "getElementSequence", &CParameterMgr::getElementSequenceCommmandProcess, 2, "<domain> <configuration>", "Get element application order for configuration" },
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100151 { "setRule", &CParameterMgr::setRuleCommmandProcess, 3, "<domain> <configuration> <rule>", "Set configuration application rule" },
152 { "clearRule", &CParameterMgr::clearRuleCommmandProcess, 2, "<domain> <configuration>", "Clear configuration application rule" },
153 { "getRule", &CParameterMgr::getRuleCommmandProcess, 2, "<domain> <configuration>", "Get configuration application rule" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200154 /// Elements/Parameters
155 { "listElements", &CParameterMgr::listElementsCommmandProcess, 1, "<elem path>|/", "List elements under element at given path or root" },
Patrick Benavoli592ae562011-09-05 16:53:58 +0200156 { "listParameters", &CParameterMgr::listParametersCommmandProcess, 1, "<elem path>|/", "List parameters under element at given path or root" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200157 { "dumpElement", &CParameterMgr::dumpElementCommmandProcess, 1, "<elem path>", "Dump structure and content of element at given path" },
158 { "getElementSize", &CParameterMgr::getElementSizeCommmandProcess, 1, "<elem path>", "Show size of element at given path" },
Patrick Benavoli2ecf9002011-08-31 11:23:24 +0200159 { "showProperties", &CParameterMgr::showPropertiesCommmandProcess, 1, "<elem path>", "Show properties of element at given path" },
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200160 { "getParameter", &CParameterMgr::getParameterCommmandProcess, 1, "<param path>", "Get value for parameter at given path" },
Patrick Benavoli2ecf9002011-08-31 11:23:24 +0200161 { "setParameter", &CParameterMgr::setParameterCommmandProcess, 2, "<param path> <value>", "Set value for parameter at given path" },
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200162 { "listBelongingDomains", &CParameterMgr::listBelongingDomainsCommmandProcess, 1, "<elem path>", "List domain(s) element at given path belongs to" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200163 { "listAssociatedDomains", &CParameterMgr::listAssociatedDomainsCommmandProcess, 1, "<elem path>", "List domain(s) element at given path is associated to" },
164 /// Browse
165 { "listAssociatedElements", &CParameterMgr::listAssociatedElementsCommmandProcess, 0, "", "List element sub-trees associated to at least one configurable domain" },
166 { "listConflictingElements", &CParameterMgr::listConflictingElementsCommmandProcess, 0, "", "List element sub-trees contained in more than one configurable domain" },
167 { "listRogueElements", &CParameterMgr::listRogueElementsCommmandProcess, 0, "", "List element sub-trees owned by no configurable domain" },
168 /// Settings Import/Export
169 { "exportDomainsXML", &CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess, 1, "<file path> ", "Export domains to XML file" },
170 { "importDomainsXML", &CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess, 1, "<file path>", "Import domains from XML file" },
171 { "exportDomainsWithSettingsXML", &CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess, 1, "<file path> ", "Export domains including settings to XML file" },
172 { "importDomainsWithSettingsXML", &CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess, 1, "<file path>", "Import domains including settings from XML file" },
173 { "exportSettings", &CParameterMgr::exportSettingsCommmandProcess, 1, "<file path>", "Export settings to binary file" },
174 { "importSettings", &CParameterMgr::importSettingsCommmandProcess, 1, "<file path>", "Import settings from binary file" }
175};
176// Remote command parsers array Size
Patrick Benavoli592ae562011-09-05 16:53:58 +0200177const uint32_t CParameterMgr::guiNbRemoteCommandParserItems = sizeof(gastRemoteCommandParserItems) / sizeof(gastRemoteCommandParserItems[0]);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200178
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100179CParameterMgr::CParameterMgr(const string& strConfigurationFilePath) :
Patrick Benavoli68a91282011-08-31 11:23:23 +0200180 _bTuningModeIsOn(false),
181 _bValueSpaceIsRaw(false),
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200182 _bOutputRawFormatIsHex(false),
Patrick Benavoli68a91282011-08-31 11:23:23 +0200183 _bAutoSyncOn(true),
184 _pMainParameterBlackboard(new CParameterBlackboard),
185 _pElementLibrarySet(new CElementLibrarySet),
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100186 _strXmlConfigurationFilePath(strConfigurationFilePath),
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100187 _pSubsystemPlugins(NULL),
Patrick Benavoli68a91282011-08-31 11:23:23 +0200188 _uiStructureChecksum(0),
189 _pRemoteProcessorServer(NULL),
190 _uiMaxCommandUsageLength(0),
191 _pLogger(NULL),
192 _uiLogDepth(0)
193{
194 // Tuning Mode Mutex
Patrick Benavoli065264a2011-11-20 15:46:41 +0100195 bzero(&_blackboardMutex, sizeof(_blackboardMutex));
196 pthread_mutex_init(&_blackboardMutex, NULL);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200197
198 // Deal with children
199 addChild(new CParameterFrameworkConfiguration);
200 addChild(new CSelectionCriteria);
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100201 addChild(new CSystemClass);
202 addChild(new CConfigurableDomains);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200203
204 // Feed element library
205 feedElementLibraries();
Patrick Benavoli63499d42011-10-24 18:50:03 +0200206
207 _pCommandHandler = new CCommandHandler(this);
208
209 // Add command parsers
210 uint32_t uiRemoteCommandParserItem;
211
212 for (uiRemoteCommandParserItem = 0; uiRemoteCommandParserItem < guiNbRemoteCommandParserItems; uiRemoteCommandParserItem++) {
213
214 const SRemoteCommandParserItem* pRemoteCommandParserItem = &gastRemoteCommandParserItems[uiRemoteCommandParserItem];
215
216 _pCommandHandler->addCommandParser(pRemoteCommandParserItem->_pcCommandName,
217 pRemoteCommandParserItem->_pfnParser,
218 pRemoteCommandParserItem->_uiMinArgumentCount,
219 pRemoteCommandParserItem->_pcHelp,
220 pRemoteCommandParserItem->_pcDescription);
221 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100222
223 // Configuration file folder
224 uint32_t uiSlashPos = _strXmlConfigurationFilePath.rfind('/', -1);
225
226 assert(uiSlashPos != (uint32_t)-1);
227
228 _strXmlConfigurationFolderPath = _strXmlConfigurationFilePath.substr(0, uiSlashPos);
229
230 // Schema absolute folder location
231 _strSchemaFolderLocation = _strXmlConfigurationFolderPath + "/" + gacSystemSchemasSubFolder;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200232}
233
234CParameterMgr::~CParameterMgr()
235{
236 // Children
237 delete _pRemoteProcessorServer;
238 delete _pMainParameterBlackboard;
239 delete _pElementLibrarySet;
240
241 // Tuning Mode Mutex
Patrick Benavoli065264a2011-11-20 15:46:41 +0100242 pthread_mutex_destroy(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200243}
244
245string CParameterMgr::getKind() const
246{
247 return "ParameterMgr";
248}
249
250// Logging
251void CParameterMgr::setLogger(CParameterMgr::ILogger* pLogger)
252{
253 _pLogger = pLogger;
254}
255
256// Logging
257void CParameterMgr::doLog(const string& strLog) const
258{
259 if (_pLogger) {
260
261 // Nest
262 string strIndent;
263
264 // Level
265 uint32_t uiNbIndents = _uiLogDepth;
266
267 while (uiNbIndents--) {
268
269 strIndent += " ";
270 }
271
272 // Log
273 _pLogger->log(strIndent + strLog);
274 }
275}
276
277void CParameterMgr::nestLog() const
278{
Patrick Benavoli592ae562011-09-05 16:53:58 +0200279 _uiLogDepth++;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200280}
281
282void CParameterMgr::unnestLog() const
283{
Patrick Benavoli592ae562011-09-05 16:53:58 +0200284 _uiLogDepth--;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200285}
286
Patrick Benavoli63499d42011-10-24 18:50:03 +0200287// Version
288string CParameterMgr::getVersion() const
289{
290 string strVersion;
291
292 // Major
293 strVersion = toString(guiEditionMajor) + ".";
294 // Minor
295 strVersion += toString(guiEditionMinor) + ".";
296 // Revision
297 strVersion += toString(guiRevision);
298
299 return strVersion;
300}
301
Patrick Benavoli68a91282011-08-31 11:23:23 +0200302bool CParameterMgr::load(string& strError)
303{
304 CAutoLog autoLog(this, "Loading");
305
306 // Load Framework configuration
307 if (!loadFrameworkConfiguration(strError)) {
308
309 return false;
310 }
311
312 // Load subsystems
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100313 if (!getSystemClass()->loadSubsystems(strError, _pSubsystemPlugins)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200314
315 return false;
316 }
317
318 // Load structure
319 if (!loadStructure(strError)) {
320
321 return false;
322 }
323
324 // Load settings
325 if (!loadSettings(strError)) {
326
327 return false;
328 }
329
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200330 // Back synchronization for areas in parameter blackboard not covered by any domain
331 CBackSynchronizer* pBackSynchronizer = createBackSynchronizer(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200332
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200333 log("Main blackboard back synchronization");
334
335 // Back-synchronize
336 if (!pBackSynchronizer->sync()) {
337 // Get rid of back synchronizer
338 delete pBackSynchronizer;
339
340 strError = "Main blackboard back synchronization failed: " + strError;
341
342 return false;
343 }
344 // Get rif of back synchronizer
345 delete pBackSynchronizer;
346
347 // We're done loading the settings and back synchronizing
348 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
349
350 // We need to ensure all domains are valid
351 pConfigurableDomains->validate(_pMainParameterBlackboard);
352
353 // Ensure application of currently selected configurations
354 // Force-apply configurations
355 if (!pConfigurableDomains->apply(_pMainParameterBlackboard, true, strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200356
357 return false;
358 }
359
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200360 // Start remote processor server if appropriate
361 return handleRemoteProcessingInterface(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200362}
363
364bool CParameterMgr::loadFrameworkConfiguration(string& strError)
365{
366 CAutoLog autoLog(this, "Loading framework configuration");
367
Patrick Benavoli68a91282011-08-31 11:23:23 +0200368 // Parse Structure XML file
369 CXmlElementSerializingContext elementSerializingContext(strError);
370
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100371 if (!xmlParse(elementSerializingContext, getFrameworkConfiguration(), _strXmlConfigurationFilePath, _strXmlConfigurationFolderPath, EFrameworkConfigurationLibrary)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200372
373 return false;
374 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100375 // Set class name to system class and configurable domains
376 getSystemClass()->setName(getConstFrameworkConfiguration()->getSystemClassName());
377 getConfigurableDomains()->setName(getConstFrameworkConfiguration()->getSystemClassName());
378
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100379 // Get subsystem plugins elements
380 _pSubsystemPlugins = static_cast<const CSubsystemPlugins*>(getConstFrameworkConfiguration()->findChild("SubsystemPlugins"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200381
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100382 if (!_pSubsystemPlugins) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200383
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100384 strError = "Parameter Framework Configuration: couldn't find SubsystemPlugins element";
Patrick Benavoli68a91282011-08-31 11:23:23 +0200385
386 return false;
387 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200388
Patrick Benavoli68a91282011-08-31 11:23:23 +0200389 // Log tuning availability
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100390 log("Tuning %s", getConstFrameworkConfiguration()->isTuningAllowed() ? "allowed" : "prohibited");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200391
392 return true;
393}
394
395bool CParameterMgr::loadStructure(string& strError)
396{
397 // Retrieve system to load structure to
398 CSystemClass* pSystemClass = getSystemClass();
399
400 CAutoLog autoLog(this, "Loading " + pSystemClass->getName() + " system class structure");
401
402 // Get structure description element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100403 const CFrameworkConfigurationLocation* pStructureDescriptionFileLocation = static_cast<const CFrameworkConfigurationLocation*>(getConstFrameworkConfiguration()->findChildOfKind("StructureDescriptionFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200404
405 if (!pStructureDescriptionFileLocation) {
406
407 strError = "No StructureDescriptionFileLocation element found for SystemClass " + pSystemClass->getName();
408
409 return false;
410 }
411
412 // Get Xml structure folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100413 string strXmlStructureFolder = pStructureDescriptionFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200414
415 // Get Xml structure file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100416 string strXmlStructureFilePath = pStructureDescriptionFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200417
418 // Parse Structure XML file
419 CXmlParameterSerializingContext parameterBuildContext(strError);
420
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200421 log("Importing system structure from file %s", strXmlStructureFilePath.c_str());
422
Patrick Benavoli68a91282011-08-31 11:23:23 +0200423 if (!xmlParse(parameterBuildContext, pSystemClass, strXmlStructureFilePath, strXmlStructureFolder, EParameterCreationLibrary)) {
424
425 return false;
426 }
427
428 // Initialize offsets
429 pSystemClass->setOffset(0);
430
431 // Initialize main blackboard's size
432 _pMainParameterBlackboard->setSize(pSystemClass->getFootPrint());
433
434 return true;
435}
436
437bool CParameterMgr::loadSettings(string& strError)
438{
439 CAutoLog autoLog(this, "Loading settings");
440
441 // Get settings configuration element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100442 const CFrameworkConfigurationGroup* pParameterConfigurationGroup = static_cast<const CFrameworkConfigurationGroup*>(getConstFrameworkConfiguration()->findChildOfKind("SettingsConfiguration"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200443
444 if (!pParameterConfigurationGroup) {
445
446 // No settings to load
447
448 return true;
449 }
450 // Get binary settings file location
451 const CFrameworkConfigurationLocation* pBinarySettingsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("BinarySettingsFileLocation"));
452
453 string strXmlBinarySettingsFilePath;
454
455 if (pBinarySettingsFileLocation) {
456
457 // Get Xml binary settings file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100458 strXmlBinarySettingsFilePath = pBinarySettingsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200459 }
460
461 // Get configurable domains element
462 const CFrameworkConfigurationLocation* pConfigurableDomainsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("ConfigurableDomainsFileLocation"));
463
464 if (!pConfigurableDomainsFileLocation) {
465
466 strError = "No ConfigurableDomainsFileLocation element found for SystemClass " + getSystemClass()->getName();
467
468 return false;
469 }
470 // Get destination root element
471 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
472
473 // Get Xml configuration domains file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100474 string strXmlConfigurationDomainsFilePath = pConfigurableDomainsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200475
476 // Get Xml configuration domains folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100477 string strXmlConfigurationDomainsFolder = pConfigurableDomainsFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200478
479 // Parse configuration domains XML file (ask to read settings from XML file if they are not provided as binary)
480 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, !pBinarySettingsFileLocation);
481
482 // Selection criteria definition for rule creation
483 xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
484
Patrick Benavoli63499d42011-10-24 18:50:03 +0200485 // Auto validation of configurations if no binary settings provided
486 xmlDomainSerializingContext.setAutoValidationRequired(!pBinarySettingsFileLocation);
487
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200488 log("Importing configurable domains from file %s %s settings", strXmlConfigurationDomainsFilePath.c_str(), pBinarySettingsFileLocation ? "without" : "with");
489
Patrick Benavoli68a91282011-08-31 11:23:23 +0200490 // Do parse
491 if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strXmlConfigurationDomainsFilePath, strXmlConfigurationDomainsFolder, EParameterConfigurationLibrary, "SystemClassName")) {
492
493 return false;
494 }
495 // We have loaded the whole system structure, compute checksum
496 const CSystemClass* pSystemClass = getConstSystemClass();
497 _uiStructureChecksum = pSystemClass->computeStructureChecksum() + getConfigurableDomains()->computeStructureChecksum() + getSelectionCriteria()->computeStructureChecksum();
498
499 // Load binary settings if any provided
500 if (pBinarySettingsFileLocation && !pConfigurableDomains->serializeSettings(strXmlBinarySettingsFilePath, false, _uiStructureChecksum, strError)) {
501
502 return false;
503 }
504
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200505 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200506}
507
508// XML parsing
509bool CParameterMgr::xmlParse(CXmlElementSerializingContext& elementSerializingContext, CElement* pRootElement, const string& strXmlFilePath, const string& strXmlFolder, CParameterMgr::ElementLibrary eElementLibrary, const string& strNameAttrituteName)
510{
511 // Init serializing context
512 elementSerializingContext.set(_pElementLibrarySet->getElementLibrary(eElementLibrary), strXmlFolder, _strSchemaFolderLocation);
513
514 // Get Schema file associated to root element
515 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pRootElement->getKind() + ".xsd";
516
517 // Parse Structure XML file
518 CXmlParser parser(strXmlFilePath, strXmlSchemaFilePath, pRootElement->getKind(), elementSerializingContext);
519
520 if (!parser.open()) {
521
522 return false;
523 }
524
525 // Check Root element name attribute (if any)
526 string strRootElementName = parser.getRootElementAttributeString(strNameAttrituteName);
527
528 if (!strRootElementName.empty() && strRootElementName != pRootElement->getName()) {
529
530 elementSerializingContext.setError("Error: Wrong XML structure file " + strXmlFilePath);
531 elementSerializingContext.appendLineToError(pRootElement->getKind() + " element " + pRootElement->getName() + " mismatches expected " + pRootElement->getKind() + " type " + pRootElement->getName());
532
533 return false;
534 }
535
536 // Start clean
537 pRootElement->clean();
538
539 // Parse
540 if (!parser.parse(pRootElement)) {
541
542 // Cleanup
543 pRootElement->clean();
544
545 return false;
546 }
547
548 // Close parser
549 if (!parser.close()) {
550
551 return false;
552 }
553
554 return true;
555}
556
557// Init
558bool CParameterMgr::init(string& strError)
559{
560 return base::init(strError);
561}
562
563// Selection criteria interface
564CSelectionCriterionType* CParameterMgr::createSelectionCriterionType(bool bIsInclusive)
565{
566 // Propagate
567 return getSelectionCriteria()->createSelectionCriterionType(bIsInclusive);
568}
569
570CSelectionCriterion* CParameterMgr::createSelectionCriterion(const string& strName, const CSelectionCriterionType* pSelectionCriterionType)
571{
572 // Propagate
573 return getSelectionCriteria()->createSelectionCriterion(strName, pSelectionCriterionType);
574}
575
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200576// Selection criterion retrieval
577CSelectionCriterion* CParameterMgr::getSelectionCriterion(const string& strName)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200578{
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200579 // Propagate
580 return getSelectionCriteria()->getSelectionCriterion(strName);
581}
582
583// Selection criteria changed event
584bool CParameterMgr::applyConfigurations(string& strError)
585{
586 CAutoLog autoLog(this, "Configuration application request");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200587
588 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +0100589 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200590
591 if (!_bTuningModeIsOn) {
592
593 // Apply configuration(s)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200594 if (!getConfigurableDomains()->apply(_pMainParameterBlackboard, false, strError)) {
595
596 log("Failed to apply configurations!");
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200597
598 return false;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200599 }
600 }
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200601
602 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200603}
604
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200605// Dynamic parameter handling
Patrick Benavoli065264a2011-11-20 15:46:41 +0100606CParameterHandle* CParameterMgr::createParameterHandle(const string& strPath, string& strError)
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200607{
Patrick Benavoli065264a2011-11-20 15:46:41 +0100608 CPathNavigator pathNavigator(strPath);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200609
Patrick Benavoli065264a2011-11-20 15:46:41 +0100610 // Nagivate through system class
611 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
612
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100613 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100614 }
615
616 // Find element
617 const CElement* pElement = getConstSystemClass()->findDescendant(pathNavigator);
618
619 if (!pElement) {
620
621 strError = "Path not found";
622
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100623 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100624 }
625
626 // Check found element is a parameter
627 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pElement);
628
629 if (!pConfigurableElement->isParameter()) {
630
631 // Element is not parameter
632 strError = "Not a parameter";
633
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100634 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100635 }
636
637 // Convert as parameter and return new handle
638 return new CParameterHandle(static_cast<const CBaseParameter*>(pElement), this);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200639}
640
Patrick Benavoli68a91282011-08-31 11:23:23 +0200641/////////////////// Remote command parsers
Patrick Benavoli592ae562011-09-05 16:53:58 +0200642/// Version
Patrick Benavoli63499d42011-10-24 18:50:03 +0200643CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::versionCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli592ae562011-09-05 16:53:58 +0200644{
645 (void)remoteCommand;
646
Patrick Benavoli63499d42011-10-24 18:50:03 +0200647 // Show version
648 strResult = getVersion();
Patrick Benavoli592ae562011-09-05 16:53:58 +0200649
Patrick Benavoli63499d42011-10-24 18:50:03 +0200650 return CCommandHandler::ESucceeded;
Patrick Benavoli592ae562011-09-05 16:53:58 +0200651}
652
Patrick Benavoli68a91282011-08-31 11:23:23 +0200653/// Status
Patrick Benavoli63499d42011-10-24 18:50:03 +0200654CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::statusCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200655{
656 (void)remoteCommand;
657 // System class
658 const CSystemClass* pSystemClass = getSystemClass();
659
Patrick Benavoli68a91282011-08-31 11:23:23 +0200660 // Show status
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200661 /// General section
662 appendTitle(strResult, "General:");
663 // System class
Patrick Benavoli68a91282011-08-31 11:23:23 +0200664 strResult += "System Class: ";
665 strResult += pSystemClass->getName();
666 strResult += "\n";
667
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200668 // Tuning mode
Patrick Benavoli68a91282011-08-31 11:23:23 +0200669 strResult += "Tuning Mode: ";
670 strResult += tuningModeOn() ? "on" : "off";
671 strResult += "\n";
672
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200673 // Value space
Patrick Benavoli68a91282011-08-31 11:23:23 +0200674 strResult += "Value Space: ";
675 strResult += valueSpaceIsRaw() ? "raw" : "real";
676 strResult += "\n";
677
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200678 // Output raw format
679 strResult += "Output Raw Format: ";
680 strResult += outputRawFormatIsHex() ? "hex" : "dec";
681 strResult += "\n";
682
683 // Auto Sync
Patrick Benavoli68a91282011-08-31 11:23:23 +0200684 strResult += "Auto Sync: ";
685 strResult += autoSyncOn() ? "on" : "off";
686 strResult += "\n";
687
688 /// Subsystem list
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200689 appendTitle(strResult, "Subsystems:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200690 string strSubsystemList;
691 pSystemClass->listChildrenPaths(strSubsystemList);
692 strResult += strSubsystemList;
693
694 /// Last applied configurations
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200695 appendTitle(strResult, "Last applied configurations:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200696 string strLastAppliedConfigurations;
697 getConfigurableDomains()->listLastAppliedConfigurations(strLastAppliedConfigurations);
698 strResult += strLastAppliedConfigurations;
699
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200700 /// Criteria states
701 appendTitle(strResult, "Selection criteria:");
702 string strSelectionCriteria;
703 getSelectionCriteria()->listSelectionCriteria(strSelectionCriteria, false);
704 strResult += strSelectionCriteria;
705
Patrick Benavoli63499d42011-10-24 18:50:03 +0200706 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200707}
708
709/// Tuning Mode
Patrick Benavoli63499d42011-10-24 18:50:03 +0200710CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200711{
712 if (remoteCommand.getArgument(0) == "on") {
713
714 if (setTuningMode(true, strResult)) {
715
Patrick Benavoli63499d42011-10-24 18:50:03 +0200716 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200717 }
718 } else if (remoteCommand.getArgument(0) == "off") {
719
720 if (setTuningMode(false, strResult)) {
721
Patrick Benavoli63499d42011-10-24 18:50:03 +0200722 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200723 }
724 } else {
725 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200726 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200727 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200728 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200729}
730
Patrick Benavoli63499d42011-10-24 18:50:03 +0200731CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200732{
733 (void)remoteCommand;
734
735 strResult = tuningModeOn() ? "on" : "off";
736
Patrick Benavoli63499d42011-10-24 18:50:03 +0200737 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200738}
739
740/// Value Space
Patrick Benavoli63499d42011-10-24 18:50:03 +0200741CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200742{
743 (void)strResult;
744
745 if (remoteCommand.getArgument(0) == "raw") {
746
747 setValueSpace(true);
748
Patrick Benavoli63499d42011-10-24 18:50:03 +0200749 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200750
751 } else if (remoteCommand.getArgument(0) == "real") {
752
753 setValueSpace(false);
754
Patrick Benavoli63499d42011-10-24 18:50:03 +0200755 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200756
757 } else {
758 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200759 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200760 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200761 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200762}
763
Patrick Benavoli63499d42011-10-24 18:50:03 +0200764CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200765{
766 (void)remoteCommand;
767
768 strResult = valueSpaceIsRaw() ? "raw" : "real";
769
Patrick Benavoli63499d42011-10-24 18:50:03 +0200770 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200771}
772
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200773/// Output Raw Format
Patrick Benavoli63499d42011-10-24 18:50:03 +0200774CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200775{
776 (void)strResult;
777
778 if (remoteCommand.getArgument(0) == "hex") {
779
780 setOutputRawFormat(true);
781
Patrick Benavoli63499d42011-10-24 18:50:03 +0200782 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200783
784 } else if (remoteCommand.getArgument(0) == "dec") {
785
786 setOutputRawFormat(false);
787
Patrick Benavoli63499d42011-10-24 18:50:03 +0200788 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200789
790 } else {
791 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200792 return CCommandHandler::EShowUsage;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200793 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200794 return CCommandHandler::EFailed;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200795}
796
Patrick Benavoli63499d42011-10-24 18:50:03 +0200797CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200798{
799 (void)remoteCommand;
800
801 strResult = outputRawFormatIsHex() ? "hex" : "dec";
802
Patrick Benavoli63499d42011-10-24 18:50:03 +0200803 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200804}
805
Patrick Benavoli68a91282011-08-31 11:23:23 +0200806/// Sync
Patrick Benavoli63499d42011-10-24 18:50:03 +0200807CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200808{
809 if (remoteCommand.getArgument(0) == "on") {
810
811 if (setAutoSync(true, strResult)) {
812
Patrick Benavoli63499d42011-10-24 18:50:03 +0200813 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200814 }
815 } else if (remoteCommand.getArgument(0) == "off") {
816
817 if (setAutoSync(false, strResult)) {
818
Patrick Benavoli63499d42011-10-24 18:50:03 +0200819 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200820 }
821 } else {
822 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200823 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200824 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200825 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200826}
827
Patrick Benavoli63499d42011-10-24 18:50:03 +0200828CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200829{
830 (void)remoteCommand;
831
832 strResult = autoSyncOn() ? "on" : "off";
833
Patrick Benavoli63499d42011-10-24 18:50:03 +0200834 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200835}
836
Patrick Benavoli63499d42011-10-24 18:50:03 +0200837CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::syncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200838{
839 (void)remoteCommand;
840
Patrick Benavoli63499d42011-10-24 18:50:03 +0200841 return sync(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200842}
843
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200844/// Criteria
Patrick Benavoli63499d42011-10-24 18:50:03 +0200845CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listCriteriaCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200846{
847 (void)remoteCommand;
848
849 getSelectionCriteria()->listSelectionCriteria(strResult, true);
850
Patrick Benavoli63499d42011-10-24 18:50:03 +0200851 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200852}
Patrick Benavoli68a91282011-08-31 11:23:23 +0200853
854/// Domains
Patrick Benavoli63499d42011-10-24 18:50:03 +0200855CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200856{
857 (void)remoteCommand;
858
Patrick Benavoli63499d42011-10-24 18:50:03 +0200859 getConfigurableDomains()->listDomains(strResult);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200860
Patrick Benavoli63499d42011-10-24 18:50:03 +0200861 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200862}
863
Patrick Benavoli63499d42011-10-24 18:50:03 +0200864CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200865{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200866 return createDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200867}
868
Patrick Benavoli63499d42011-10-24 18:50:03 +0200869CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200870{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200871 return deleteDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200872}
873
Patrick Benavoli63499d42011-10-24 18:50:03 +0200874CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200875{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200876 return getConfigurableDomains()->renameDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200877}
878
Patrick Benavoli63499d42011-10-24 18:50:03 +0200879CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200880{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200881 // Check tuning mode
882 if (!checkTuningModeOn(strResult)) {
883
884 return CCommandHandler::EFailed;
885 }
886
887 // Set property
888 bool bSequenceAware;
889
890 if (remoteCommand.getArgument(1) == "true") {
891
892 bSequenceAware = true;
893
894 } else if (remoteCommand.getArgument(1) == "false") {
895
896 bSequenceAware = false;
897
898 } else {
899 // Show usage
900 return CCommandHandler::EShowUsage;
901 }
902
903 return getConfigurableDomains()->setSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200904}
905
Patrick Benavoli63499d42011-10-24 18:50:03 +0200906CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200907{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200908 // Get property
909 bool bSequenceAware;
910
911 if (!getConfigurableDomains()->getSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult)) {
912
913 return CCommandHandler::EFailed;
914 }
915
916 strResult = bSequenceAware ? "true" : "false";
917
918 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200919}
920
Patrick Benavoli63499d42011-10-24 18:50:03 +0200921CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200922{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200923 return getConfigurableDomains()->listDomainElements(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200924}
925
Patrick Benavoli63499d42011-10-24 18:50:03 +0200926CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::addElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200927{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200928 return addConfigurableElementToDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
929}
930
931CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::removeElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
932{
933 return removeConfigurableElementFromDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
934}
935
936CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::splitDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
937{
938 return split(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200939}
940
941/// Configurations
Patrick Benavoli63499d42011-10-24 18:50:03 +0200942CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConfigurationsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200943{
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100944 return getConstConfigurableDomains()->listConfigurations(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
945}
946
947CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
948{
949 (void)remoteCommand;
950
951 // Dummy error context
952 string strError;
953 CErrorContext errorContext(strError);
954
955 // Dump
956 getConstConfigurableDomains()->dumpContent(strResult, errorContext);
957
958 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200959}
960
Patrick Benavoli63499d42011-10-24 18:50:03 +0200961CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200962{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200963 return createConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200964}
965
Patrick Benavoli63499d42011-10-24 18:50:03 +0200966CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200967{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200968 return deleteConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200969}
970
Patrick Benavoli63499d42011-10-24 18:50:03 +0200971CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200972{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200973 return getConfigurableDomains()->renameConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200974}
975
Patrick Benavoli63499d42011-10-24 18:50:03 +0200976CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::saveConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200977{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200978 return saveConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200979}
980
Patrick Benavoli63499d42011-10-24 18:50:03 +0200981CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::restoreConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200982{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200983 return restoreConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
984}
985
986CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
987{
988 // Check tuning mode
989 if (!checkTuningModeOn(strResult)) {
990
991 return CCommandHandler::EFailed;
992 }
993
994 // Build configurable element path list
995 vector<string> astrNewElementSequence;
996
997 uint32_t uiArgument;
998
999 for (uiArgument = 2; uiArgument < remoteCommand.getArgumentCount(); uiArgument++) {
1000
1001 astrNewElementSequence.push_back(remoteCommand.getArgument(uiArgument));
1002 }
1003
1004 // Delegate to configurable domains
1005 return getConfigurableDomains()->setElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), astrNewElementSequence, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1006}
1007
1008CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1009{
1010 // Delegate to configurable domains
1011 return getConfigurableDomains()->getElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001012}
1013
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001014CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1015{
1016 // Delegate to configurable domains
1017 return getConfigurableDomains()->setApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.packArguments(2, remoteCommand.getArgumentCount() - 2), getConstSelectionCriteria()->getSelectionCriteriaDefinition(), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1018}
1019
1020CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::clearRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1021{
1022 // Delegate to configurable domains
1023 return getConfigurableDomains()->clearApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1024}
1025
1026CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1027{
1028 // Delegate to configurable domains
1029 return getConfigurableDomains()->getApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
1030}
1031
Patrick Benavoli68a91282011-08-31 11:23:23 +02001032/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001033CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001034{
1035 CElementLocator elementLocator(getSystemClass(), false);
1036
1037 CElement* pLocatedElement = NULL;
1038
1039 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1040
Patrick Benavoli63499d42011-10-24 18:50:03 +02001041 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001042 }
1043
1044 strResult = string("\n");
1045
1046 if (!pLocatedElement) {
1047
1048 // List from root folder
1049
1050 // Return system class qualified name
1051 pLocatedElement = getSystemClass();
1052 }
1053
1054 // Return sub-elements
1055 strResult += pLocatedElement->listQualifiedPaths(false);
1056
Patrick Benavoli63499d42011-10-24 18:50:03 +02001057 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001058}
1059
1060/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001061CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listParametersCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001062{
1063 CElementLocator elementLocator(getSystemClass(), false);
1064
1065 CElement* pLocatedElement = NULL;
1066
1067 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1068
Patrick Benavoli63499d42011-10-24 18:50:03 +02001069 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001070 }
1071
1072 strResult = string("\n");
1073
1074 if (!pLocatedElement) {
1075
1076 // List from root folder
1077
1078 // Return system class qualified name
1079 pLocatedElement = getSystemClass();
1080 }
1081
1082 // Return sub-elements
1083 strResult += pLocatedElement->listQualifiedPaths(true);
1084
Patrick Benavoli63499d42011-10-24 18:50:03 +02001085 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001086}
1087
Patrick Benavoli63499d42011-10-24 18:50:03 +02001088CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001089{
1090 CElementLocator elementLocator(getSystemClass());
1091
1092 CElement* pLocatedElement = NULL;
1093
1094 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1095
Patrick Benavoli63499d42011-10-24 18:50:03 +02001096 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001097 }
1098
1099 string strError;
1100
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001101 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001102
1103 // Dump elements
1104 pLocatedElement->dumpContent(strResult, parameterAccessContext);
1105
Patrick Benavoli63499d42011-10-24 18:50:03 +02001106 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001107}
1108
Patrick Benavoli63499d42011-10-24 18:50:03 +02001109CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSizeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001110{
1111 CElementLocator elementLocator(getSystemClass());
1112
1113 CElement* pLocatedElement = NULL;
1114
1115 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1116
Patrick Benavoli63499d42011-10-24 18:50:03 +02001117 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001118 }
1119
1120 // Converted to actual sizable element
1121 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1122
1123 // Get size as string
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001124 strResult = pConfigurableElement->getFootprintAsString();
Patrick Benavoli68a91282011-08-31 11:23:23 +02001125
Patrick Benavoli63499d42011-10-24 18:50:03 +02001126 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001127}
1128
Patrick Benavoli63499d42011-10-24 18:50:03 +02001129CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showPropertiesCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001130{
1131 CElementLocator elementLocator(getSystemClass());
1132
1133 CElement* pLocatedElement = NULL;
1134
1135 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1136
Patrick Benavoli63499d42011-10-24 18:50:03 +02001137 return CCommandHandler::EFailed;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001138 }
1139
1140 // Convert element
1141 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1142
1143 // Return element properties
1144 pConfigurableElement->showProperties(strResult);
1145
Patrick Benavoli63499d42011-10-24 18:50:03 +02001146 return CCommandHandler::ESucceeded;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001147}
1148
Patrick Benavoli63499d42011-10-24 18:50:03 +02001149CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001150{
1151 string strValue;
1152
Patrick Benavoli065264a2011-11-20 15:46:41 +01001153 if (!accessValue(remoteCommand.getArgument(0), strValue, false, strResult)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001154
Patrick Benavoli63499d42011-10-24 18:50:03 +02001155 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001156 }
1157 // Succeeded
1158 strResult = strValue;
1159
Patrick Benavoli63499d42011-10-24 18:50:03 +02001160 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001161}
1162
Patrick Benavoli63499d42011-10-24 18:50:03 +02001163CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001164{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001165 // Check tuning mode
1166 if (!checkTuningModeOn(strResult)) {
1167
1168 return CCommandHandler::EFailed;
1169 }
1170 // Get value to set
1171 string strValue = remoteCommand.packArguments(1, remoteCommand.getArgumentCount() - 1);
1172
1173 return accessValue(remoteCommand.getArgument(0), strValue, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001174}
1175
Patrick Benavoli63499d42011-10-24 18:50:03 +02001176CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listBelongingDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001177{
1178 CElementLocator elementLocator(getSystemClass());
1179
1180 CElement* pLocatedElement = NULL;
1181
1182 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1183
Patrick Benavoli63499d42011-10-24 18:50:03 +02001184 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001185 }
1186
1187 // Convert element
1188 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1189
1190 // Return element belonging domains
1191 pConfigurableElement->listBelongingDomains(strResult);
1192
Patrick Benavoli63499d42011-10-24 18:50:03 +02001193 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001194}
1195
Patrick Benavoli63499d42011-10-24 18:50:03 +02001196CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001197{
1198 CElementLocator elementLocator(getSystemClass());
1199
1200 CElement* pLocatedElement = NULL;
1201
1202 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1203
Patrick Benavoli63499d42011-10-24 18:50:03 +02001204 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001205 }
1206
1207 // Convert element
1208 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1209
1210 // Return element belonging domains
1211 pConfigurableElement->listAssociatedDomains(strResult);
1212
Patrick Benavoli63499d42011-10-24 18:50:03 +02001213 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001214}
1215
Patrick Benavoli63499d42011-10-24 18:50:03 +02001216CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001217{
1218 (void)remoteCommand;
1219
1220 getConfigurableDomains()->listAssociatedElements(strResult);
1221
Patrick Benavoli63499d42011-10-24 18:50:03 +02001222 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001223}
1224
Patrick Benavoli63499d42011-10-24 18:50:03 +02001225CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConflictingElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001226{
1227 (void)remoteCommand;
1228
1229 getConfigurableDomains()->listConflictingElements(strResult);
1230
Patrick Benavoli63499d42011-10-24 18:50:03 +02001231 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001232}
1233
Patrick Benavoli63499d42011-10-24 18:50:03 +02001234CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listRogueElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001235{
1236 (void)remoteCommand;
1237
1238 getSystemClass()->listRogueElements(strResult);
1239
Patrick Benavoli63499d42011-10-24 18:50:03 +02001240 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001241}
1242
1243/// Settings Import/Export
Patrick Benavoli63499d42011-10-24 18:50:03 +02001244CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001245{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001246 return exportDomainsXml(remoteCommand.getArgument(0), false, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001247}
1248
Patrick Benavoli63499d42011-10-24 18:50:03 +02001249CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001250{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001251 return importDomainsXml(remoteCommand.getArgument(0), false, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001252}
1253
Patrick Benavoli63499d42011-10-24 18:50:03 +02001254CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001255{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001256 return exportDomainsXml(remoteCommand.getArgument(0), true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001257}
1258
Patrick Benavoli63499d42011-10-24 18:50:03 +02001259CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001260{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001261 return importDomainsXml(remoteCommand.getArgument(0), true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001262}
1263
Patrick Benavoli63499d42011-10-24 18:50:03 +02001264CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001265{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001266 return exportDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001267}
1268
Patrick Benavoli63499d42011-10-24 18:50:03 +02001269CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001270{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001271 return importDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001272}
1273
1274// User set/get parameters
Patrick Benavoli065264a2011-11-20 15:46:41 +01001275bool CParameterMgr::accessValue(const string& strPath, string& strValue, bool bSet, string& strError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001276{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001277 // Lock state
1278 CAutoLock autoLock(&_blackboardMutex);
1279
1280 CPathNavigator pathNavigator(strPath);
1281
1282 // Nagivate through system class
1283 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001284
1285 return false;
1286 }
1287
Patrick Benavoli065264a2011-11-20 15:46:41 +01001288 // Define context
1289 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001290
Patrick Benavoli68808c62012-02-02 17:12:41 +01001291 // Auto Sync
1292 if (bSet) {
1293
1294 parameterAccessContext.setAutoSync(_bAutoSyncOn);
1295 }
1296
Patrick Benavoli065264a2011-11-20 15:46:41 +01001297 // Do the get
1298 return getConstSystemClass()->accessValue(pathNavigator, strValue, bSet, parameterAccessContext);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001299}
1300
1301// Tuning mode
1302bool CParameterMgr::setTuningMode(bool bOn, string& strError)
1303{
1304 // Tuning allowed?
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001305 if (bOn && !getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001306
1307 strError = "Tuning prohibited";
1308
1309 return false;
1310 }
1311 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +01001312 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001313
1314 // Warn domains about exiting tuning mode
1315 if (!bOn && _bTuningModeIsOn) {
1316
1317 // Ensure application of currently selected configurations
Patrick Benavoli1387bda2011-08-31 11:23:24 +02001318 // Force-apply configurations
Patrick Benavoli68a91282011-08-31 11:23:23 +02001319 if (!getConfigurableDomains()->apply(_pMainParameterBlackboard, true, strError)) {
1320
1321 return false;
1322 }
1323 // Turn auto sync back on
1324 _bAutoSyncOn = true;
1325 }
1326
1327 // Store
1328 _bTuningModeIsOn = bOn;
1329
Patrick Benavoli68a91282011-08-31 11:23:23 +02001330 return true;
1331}
1332
1333bool CParameterMgr::tuningModeOn() const
1334{
1335 return _bTuningModeIsOn;
1336}
1337
1338// Current value space for user set/get value interpretation
1339void CParameterMgr::setValueSpace(bool bIsRaw)
1340{
1341 _bValueSpaceIsRaw = bIsRaw;
1342}
1343
1344bool CParameterMgr::valueSpaceIsRaw()
1345{
1346 return _bValueSpaceIsRaw;
1347}
1348
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001349// Current Output Raw Format for user get value interpretation
1350void CParameterMgr::setOutputRawFormat(bool bIsHex)
1351{
1352 _bOutputRawFormatIsHex = bIsHex;
1353}
1354
1355bool CParameterMgr::outputRawFormatIsHex()
1356{
1357 return _bOutputRawFormatIsHex;
1358}
1359
Patrick Benavoli68a91282011-08-31 11:23:23 +02001360/// Sync
1361// Automatic hardware synchronization control (during tuning session)
1362bool CParameterMgr::setAutoSync(bool bAutoSyncOn, string& strError)
1363{
1364 // Check tuning mode
1365 if (!checkTuningModeOn(strError)) {
1366
1367 return false;
1368 }
1369 // Warn domains about turning auto sync back on
1370 if (bAutoSyncOn && !_bAutoSyncOn) {
1371
Patrick Benavoli592ae562011-09-05 16:53:58 +02001372 // Do the synchronization at system class level (could be optimized by keeping track of all modified parameters)
1373 if (!sync(strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001374
1375 return false;
1376 }
1377 }
1378
1379 // Set Auto sync
1380 _bAutoSyncOn = bAutoSyncOn;
1381
1382 return true;
1383}
1384
1385bool CParameterMgr::autoSyncOn() const
1386{
1387 return _bAutoSyncOn;
1388}
1389
1390// Manual hardware synchronization control (during tuning session)
1391bool CParameterMgr::sync(string& strError)
1392{
1393 // Check tuning mode
1394 if (!checkTuningModeOn(strError)) {
1395
1396 return false;
1397 }
1398 // Warn domains about turning auto sync back on
1399 if (_bAutoSyncOn) {
1400
1401 strError = "Feature unavailable when Auto Sync is on";
1402
1403 return false;
1404 }
1405
1406 // Get syncer set
1407 CSyncerSet syncerSet;
1408 // ... from system class
1409 getConstSystemClass()->fillSyncerSet(syncerSet);
1410 // Sync
1411 return syncerSet.sync(*_pMainParameterBlackboard, false, strError);
1412}
1413
1414// Content dump
1415void CParameterMgr::logStructureContent(string& strContent) const
1416{
1417 string strError;
1418
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001419 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001420
1421 dumpContent(strContent, parameterAccessContext);
1422}
1423
1424// Configuration/Domains handling
1425bool CParameterMgr::createDomain(const string& strName, string& strError)
1426{
1427 // Check tuning mode
1428 if (!checkTuningModeOn(strError)) {
1429
1430 return false;
1431 }
1432
1433 // Delegate to configurable domains
1434 return getConfigurableDomains()->createDomain(strName, strError);
1435}
1436
1437bool CParameterMgr::deleteDomain(const string& strName, string& strError)
1438{
1439 // Check tuning mode
1440 if (!checkTuningModeOn(strError)) {
1441
1442 return false;
1443 }
1444
1445 // Delegate to configurable domains
1446 return getConfigurableDomains()->deleteDomain(strName, strError);
1447}
1448
1449bool CParameterMgr::createConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1450{
1451 // Check tuning mode
1452 if (!checkTuningModeOn(strError)) {
1453
1454 return false;
1455 }
1456
1457 // Delegate to configurable domains
1458 return getConfigurableDomains()->createConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1459}
1460
1461bool CParameterMgr::deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1462{
1463 // Check tuning mode
1464 if (!checkTuningModeOn(strError)) {
1465
1466 return false;
1467 }
1468
1469 // Delegate to configurable domains
1470 return getConfigurableDomains()->deleteConfiguration(strDomain, strConfiguration, strError);
1471}
1472
1473bool CParameterMgr::restoreConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1474{
1475 // Check tuning mode
1476 if (!checkTuningModeOn(strError)) {
1477
1478 return false;
1479 }
1480
1481 // Delegate to configurable domains
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001482 return getConstConfigurableDomains()->restoreConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001483}
1484
1485bool CParameterMgr::saveConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1486{
1487 // Check tuning mode
1488 if (!checkTuningModeOn(strError)) {
1489
1490 return false;
1491 }
1492
1493 // Delegate to configurable domains
1494 return getConfigurableDomains()->saveConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1495}
1496
1497// Configurable element - domain association
1498bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1499{
1500 // Check tuning mode
1501 if (!checkTuningModeOn(strError)) {
1502
1503 return false;
1504 }
1505
1506 CElementLocator elementLocator(getSystemClass());
1507
1508 CElement* pLocatedElement = NULL;
1509
1510 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1511
1512 return false;
1513 }
1514
1515 // Convert element
1516 CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1517
1518 // Delegate
1519 return getConfigurableDomains()->addConfigurableElementToDomain(strDomain, pConfigurableElement, _pMainParameterBlackboard, strError);
1520}
1521
1522bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1523{
1524 // Check tuning mode
1525 if (!checkTuningModeOn(strError)) {
1526
1527 return false;
1528 }
1529
1530 CElementLocator elementLocator(getSystemClass());
1531
1532 CElement* pLocatedElement = NULL;
1533
1534 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1535
Patrick Benavoli63499d42011-10-24 18:50:03 +02001536 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001537 }
1538
1539 // Convert element
1540 CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1541
1542 // Delegate
1543 return getConfigurableDomains()->removeConfigurableElementFromDomain(strDomain, pConfigurableElement, strError);
1544}
1545
1546bool CParameterMgr::split(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1547{
1548 // Check tuning mode
1549 if (!checkTuningModeOn(strError)) {
1550
1551 return false;
1552 }
1553
1554 CElementLocator elementLocator(getSystemClass());
1555
1556 CElement* pLocatedElement = NULL;
1557
1558 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1559
Patrick Benavoli63499d42011-10-24 18:50:03 +02001560 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001561 }
1562
1563 // Convert element
1564 CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1565
1566 // Delegate
1567 return getConfigurableDomains()->split(strDomain, pConfigurableElement, strError);
1568}
1569
1570// XML Import/Export
1571bool CParameterMgr::importDomainsXml(const string& strFileName, bool bWithSettings, string& strError)
1572{
1573 // Check tuning mode
1574 if (!checkTuningModeOn(strError)) {
1575
1576 return false;
1577 }
1578
1579 // check path is absolute
1580 if (strFileName[0] != '/') {
1581
1582 strError = "Please provide absolute path";
1583
1584 return false;
1585 }
1586 // Root element
1587 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1588
1589 // Context
1590 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1591
1592 // Secltion criteria definition for rule creation
1593 xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
1594
1595 // Parse
1596 if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strFileName, "", EParameterConfigurationLibrary, "SystemClassName")) {
1597
1598 return false;
1599 }
1600
1601 // Validate domains after XML import
1602 pConfigurableDomains->validate(_pMainParameterBlackboard);
1603
1604 return true;
1605}
1606
1607bool CParameterMgr::exportDomainsXml(const string& strFileName, bool bWithSettings, string& strError) const
1608{
1609 // check path is absolute
1610 if (strFileName[0] != '/') {
1611
1612 strError = "Please provide absolute path";
1613
1614 return false;
1615 }
1616
1617 // Root element
1618 const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains();
1619
1620 // Get Schema file associated to root element
1621 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pConfigurableDomains->getKind() + ".xsd";
1622
1623 // Context
1624 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1625
1626 // Value space
1627 xmlDomainSerializingContext.setValueSpaceRaw(_bValueSpaceIsRaw);
1628
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001629 // Output raw format
1630 xmlDomainSerializingContext.setOutputRawFormat(_bOutputRawFormatIsHex);
1631
Patrick Benavoli68a91282011-08-31 11:23:23 +02001632 // Instantiate composer
1633 CXmlComposer xmlComposer(strFileName, strXmlSchemaFilePath, pConfigurableDomains->getKind(), xmlDomainSerializingContext);
1634
1635 // Open composer
1636 if (!xmlComposer.open()) {
1637
1638 return false;
1639 }
1640
1641 // Compose
Patrick Benavoli63499d42011-10-24 18:50:03 +02001642 xmlComposer.compose(pConfigurableDomains, "parameter-framework", getVersion());
Patrick Benavoli68a91282011-08-31 11:23:23 +02001643
1644 // Close composer
1645 if (!xmlComposer.close()) {
1646
1647 return false;
1648 }
1649
1650 return true;
1651}
1652
1653// Binary Import/Export
1654bool CParameterMgr::importDomainsBinary(const string& strFileName, string& strError)
1655{
1656 // Check tuning mode
1657 if (!checkTuningModeOn(strError)) {
1658
1659 return false;
1660 }
1661 // check path is absolute
1662 if (strFileName[0] != '/') {
1663
1664 strError = "Please provide absolute path";
1665
1666 return false;
1667 }
1668 // Root element
1669 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1670
1671 // Serialize in
1672 return pConfigurableDomains->serializeSettings(strFileName, false, _uiStructureChecksum, strError);
1673}
1674
1675bool CParameterMgr::exportDomainsBinary(const string& strFileName, string& strError)
1676{
1677 // check path is absolute
1678 if (strFileName[0] != '/') {
1679
1680 strError = "Please provide absolute path";
1681
1682 return false;
1683 }
Patrick Benavoli68a91282011-08-31 11:23:23 +02001684
Patrick Benavoli68a91282011-08-31 11:23:23 +02001685 // Root element
1686 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1687
1688 // Serialize out
1689 return pConfigurableDomains->serializeSettings(strFileName, true, _uiStructureChecksum, strError);
1690}
1691
1692// For tuning, check we're in tuning mode
1693bool CParameterMgr::checkTuningModeOn(string& strError) const
1694{
1695 // Tuning Mode on?
1696 if (!_bTuningModeIsOn) {
1697
1698 strError = "Tuning Mode must be on";
1699
1700 return false;
1701 }
1702 return true;
1703}
1704
Patrick Benavoli065264a2011-11-20 15:46:41 +01001705// Tuning mutex dynamic parameter handling
1706pthread_mutex_t* CParameterMgr::getBlackboardMutex()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001707{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001708 return &_blackboardMutex;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001709}
1710
Patrick Benavoli065264a2011-11-20 15:46:41 +01001711// Blackboard reference (dynamic parameter handling)
1712CParameterBlackboard* CParameterMgr::getParameterBlackboard()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001713{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001714 return _pMainParameterBlackboard;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001715}
1716
Patrick Benavoli68a91282011-08-31 11:23:23 +02001717// Dynamic creation library feeding
1718void CParameterMgr::feedElementLibraries()
1719{
1720 // Global Configuration handling
1721 CElementLibrary* pFrameworkConfigurationLibrary = new CElementLibrary;
1722
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001723 pFrameworkConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CParameterFrameworkConfiguration>("ParameterFrameworkConfiguration"));
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +01001724 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CSubsystemPlugins>("SubsystemPlugins"));
1725 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CPluginLocation>("Location"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001726 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("StructureDescriptionFileLocation"));
1727 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationGroup>("SettingsConfiguration"));
1728 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("ConfigurableDomainsFileLocation"));
1729 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("BinarySettingsFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001730
1731 _pElementLibrarySet->addElementLibrary(pFrameworkConfigurationLibrary);
1732
1733 // Parameter creation
1734 CElementLibrary* pParameterCreationLibrary = new CElementLibrary;
1735
1736 pParameterCreationLibrary->addElementBuilder(new CSubsystemElementBuilder(getSystemClass()->getSubsystemLibrary()));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001737 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CComponentType>("ComponentType"));
1738 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CComponentInstance>("Component"));
1739 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBitParameterType>("BitParameter"));
1740 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBitParameterBlockType>("BitParameterBlock"));
Patrick Benavoli1352ae52011-10-21 16:48:04 +02001741 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CStringParameterType>("StringParameter"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001742 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CParameterBlockType>("ParameterBlock"));
1743 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBooleanParameterType>("BooleanParameter"));
1744 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CIntegerParameterType>("IntegerParameter"));
Patrick Benavoliee65e6d2011-11-20 18:52:24 +01001745 pParameterCreationLibrary->addElementBuilder(new TElementBuilderTemplate<CLinearParameterAdaptation>("LinearAdaptation"));
Patrick Benavoli9fc3c0d2011-10-27 14:27:27 +02001746 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CEnumParameterType>("EnumParameter"));
Patrick Benavoli68808c62012-02-02 17:12:41 +01001747 pParameterCreationLibrary->addElementBuilder(new TElementBuilderTemplate<CEnumValuePair>("ValuePair"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001748 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CFixedPointParameterType>("FixedPointParameter"));
1749 pParameterCreationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CXmlFileIncluderElement>("SubsystemInclude"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001750
1751 _pElementLibrarySet->addElementLibrary(pParameterCreationLibrary);
1752
1753 // Parameter Configuration Domains creation
1754 CElementLibrary* pParameterConfigurationLibrary = new CElementLibrary;
1755
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001756 pParameterConfigurationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CConfigurableDomain>("ConfigurableDomain"));
1757 pParameterConfigurationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CDomainConfiguration>("Configuration"));
1758 pParameterConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CCompoundRule>("CompoundRule"));
1759 pParameterConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CSelectionCriterionRule>("SelectionCriterionRule"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001760
1761 _pElementLibrarySet->addElementLibrary(pParameterConfigurationLibrary);
1762}
1763
1764// Remote Processor Server connection handling
1765bool CParameterMgr::handleRemoteProcessingInterface(string& strError)
1766{
1767 CAutoLog autoLog(this, "Handling remote processing interface");
1768
1769 // Start server if tuning allowed
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001770 if (getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001771
1772 log("Loading remote processor library");
1773
1774 // Load library
1775 void* lib_handle = dlopen("libremote-processor.so", RTLD_NOW);
1776
1777 if (!lib_handle) {
1778
1779 // Return error
1780 const char* pcError = dlerror();
1781
1782 if (pcError) {
1783
1784 strError = pcError;
1785 } else {
1786
1787 strError = "Unable to load libremote-processor.so library";
1788 }
1789
1790 return false;
1791 }
1792
1793 CreateRemoteProcessorServer pfnCreateRemoteProcessorServer = (CreateRemoteProcessorServer)dlsym(lib_handle, "createRemoteProcessorServer");
1794
1795 if (!pfnCreateRemoteProcessorServer) {
1796
1797 strError = "libremote-process.so does not contain createRemoteProcessorServer symbol.";
1798
1799 return false;
1800 }
1801
1802 // Create server
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001803 _pRemoteProcessorServer = pfnCreateRemoteProcessorServer(getConstFrameworkConfiguration()->getServerPort(), _pCommandHandler);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001804
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001805 log("Starting remote processor server on port %d", getConstFrameworkConfiguration()->getServerPort());
Patrick Benavoli68a91282011-08-31 11:23:23 +02001806 // Start
1807 if (!_pRemoteProcessorServer->start()) {
1808
1809 strError = "Unable to start remote processor server";
1810
1811 return false;
1812 }
1813 }
1814
1815 return true;
1816}
1817
1818// Back synchronization
1819CBackSynchronizer* CParameterMgr::createBackSynchronizer(string& strError) const
1820{
1821#ifdef SIMULATION
1822 // In simulation, back synchronization of the blackboard won't probably work
1823 // We need to ensure though the blackboard is initialized with valid data
1824 return new CSimulatedBackSynchronizer(getConstSystemClass(), strError, _pMainParameterBlackboard);
1825#else
1826 // Real back synchronizer from subsystems
1827 return new CHardwareBackSynchronizer(getConstSystemClass(), strError, _pMainParameterBlackboard);
1828#endif
1829}
1830
1831// Children typwise access
1832CParameterFrameworkConfiguration* CParameterMgr::getFrameworkConfiguration()
1833{
1834 return static_cast<CParameterFrameworkConfiguration*>(getChild(EFrameworkConfiguration));
1835}
1836
1837const CParameterFrameworkConfiguration* CParameterMgr::getConstFrameworkConfiguration()
1838{
1839 return getFrameworkConfiguration();
1840}
1841
1842CSelectionCriteria* CParameterMgr::getSelectionCriteria()
1843{
1844 return static_cast<CSelectionCriteria*>(getChild(ESelectionCriteria));
1845}
1846
1847const CSelectionCriteria* CParameterMgr::getConstSelectionCriteria()
1848{
1849 return static_cast<const CSelectionCriteria*>(getChild(ESelectionCriteria));
1850}
1851
1852CSystemClass* CParameterMgr::getSystemClass()
1853{
1854 return static_cast<CSystemClass*>(getChild(ESystemClass));
1855}
1856
1857const CSystemClass* CParameterMgr::getConstSystemClass() const
1858{
1859 return static_cast<const CSystemClass*>(getChild(ESystemClass));
1860}
1861
1862// Configurable Domains
1863CConfigurableDomains* CParameterMgr::getConfigurableDomains()
1864{
1865 return static_cast<CConfigurableDomains*>(getChild(EConfigurableDomains));
1866}
1867
1868const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains()
1869{
1870 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
1871}
1872
1873const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains() const
1874{
1875 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
1876}