blob: dc38f95b7f8ec9c6b4ca1875c7f8b8429aa95947 [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;
Frederic Boisnard31242302012-04-26 17:07:34 +0200238 delete _pCommandHandler;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200239 delete _pMainParameterBlackboard;
240 delete _pElementLibrarySet;
241
242 // Tuning Mode Mutex
Patrick Benavoli065264a2011-11-20 15:46:41 +0100243 pthread_mutex_destroy(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200244}
245
246string CParameterMgr::getKind() const
247{
248 return "ParameterMgr";
249}
250
251// Logging
252void CParameterMgr::setLogger(CParameterMgr::ILogger* pLogger)
253{
254 _pLogger = pLogger;
255}
256
257// Logging
258void CParameterMgr::doLog(const string& strLog) const
259{
260 if (_pLogger) {
261
262 // Nest
263 string strIndent;
264
265 // Level
266 uint32_t uiNbIndents = _uiLogDepth;
267
268 while (uiNbIndents--) {
269
270 strIndent += " ";
271 }
272
273 // Log
274 _pLogger->log(strIndent + strLog);
275 }
276}
277
278void CParameterMgr::nestLog() const
279{
Patrick Benavoli592ae562011-09-05 16:53:58 +0200280 _uiLogDepth++;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200281}
282
283void CParameterMgr::unnestLog() const
284{
Patrick Benavoli592ae562011-09-05 16:53:58 +0200285 _uiLogDepth--;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200286}
287
Patrick Benavoli63499d42011-10-24 18:50:03 +0200288// Version
289string CParameterMgr::getVersion() const
290{
291 string strVersion;
292
293 // Major
294 strVersion = toString(guiEditionMajor) + ".";
295 // Minor
296 strVersion += toString(guiEditionMinor) + ".";
297 // Revision
298 strVersion += toString(guiRevision);
299
300 return strVersion;
301}
302
Patrick Benavoli68a91282011-08-31 11:23:23 +0200303bool CParameterMgr::load(string& strError)
304{
305 CAutoLog autoLog(this, "Loading");
306
307 // Load Framework configuration
308 if (!loadFrameworkConfiguration(strError)) {
309
310 return false;
311 }
312
313 // Load subsystems
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100314 if (!getSystemClass()->loadSubsystems(strError, _pSubsystemPlugins)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200315
316 return false;
317 }
318
319 // Load structure
320 if (!loadStructure(strError)) {
321
322 return false;
323 }
324
325 // Load settings
326 if (!loadSettings(strError)) {
327
328 return false;
329 }
330
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200331 // Back synchronization for areas in parameter blackboard not covered by any domain
332 CBackSynchronizer* pBackSynchronizer = createBackSynchronizer(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200333
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200334 log("Main blackboard back synchronization");
335
336 // Back-synchronize
337 if (!pBackSynchronizer->sync()) {
338 // Get rid of back synchronizer
339 delete pBackSynchronizer;
340
341 strError = "Main blackboard back synchronization failed: " + strError;
342
343 return false;
344 }
345 // Get rif of back synchronizer
346 delete pBackSynchronizer;
347
348 // We're done loading the settings and back synchronizing
349 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
350
351 // We need to ensure all domains are valid
352 pConfigurableDomains->validate(_pMainParameterBlackboard);
353
354 // Ensure application of currently selected configurations
355 // Force-apply configurations
356 if (!pConfigurableDomains->apply(_pMainParameterBlackboard, true, strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200357
358 return false;
359 }
360
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200361 // Start remote processor server if appropriate
362 return handleRemoteProcessingInterface(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200363}
364
365bool CParameterMgr::loadFrameworkConfiguration(string& strError)
366{
367 CAutoLog autoLog(this, "Loading framework configuration");
368
Patrick Benavoli68a91282011-08-31 11:23:23 +0200369 // Parse Structure XML file
370 CXmlElementSerializingContext elementSerializingContext(strError);
371
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100372 if (!xmlParse(elementSerializingContext, getFrameworkConfiguration(), _strXmlConfigurationFilePath, _strXmlConfigurationFolderPath, EFrameworkConfigurationLibrary)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200373
374 return false;
375 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100376 // Set class name to system class and configurable domains
377 getSystemClass()->setName(getConstFrameworkConfiguration()->getSystemClassName());
378 getConfigurableDomains()->setName(getConstFrameworkConfiguration()->getSystemClassName());
379
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100380 // Get subsystem plugins elements
381 _pSubsystemPlugins = static_cast<const CSubsystemPlugins*>(getConstFrameworkConfiguration()->findChild("SubsystemPlugins"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200382
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100383 if (!_pSubsystemPlugins) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200384
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100385 strError = "Parameter Framework Configuration: couldn't find SubsystemPlugins element";
Patrick Benavoli68a91282011-08-31 11:23:23 +0200386
387 return false;
388 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200389
Patrick Benavoli68a91282011-08-31 11:23:23 +0200390 // Log tuning availability
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100391 log("Tuning %s", getConstFrameworkConfiguration()->isTuningAllowed() ? "allowed" : "prohibited");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200392
393 return true;
394}
395
396bool CParameterMgr::loadStructure(string& strError)
397{
398 // Retrieve system to load structure to
399 CSystemClass* pSystemClass = getSystemClass();
400
401 CAutoLog autoLog(this, "Loading " + pSystemClass->getName() + " system class structure");
402
403 // Get structure description element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100404 const CFrameworkConfigurationLocation* pStructureDescriptionFileLocation = static_cast<const CFrameworkConfigurationLocation*>(getConstFrameworkConfiguration()->findChildOfKind("StructureDescriptionFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200405
406 if (!pStructureDescriptionFileLocation) {
407
408 strError = "No StructureDescriptionFileLocation element found for SystemClass " + pSystemClass->getName();
409
410 return false;
411 }
412
413 // Get Xml structure folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100414 string strXmlStructureFolder = pStructureDescriptionFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200415
416 // Get Xml structure file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100417 string strXmlStructureFilePath = pStructureDescriptionFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200418
419 // Parse Structure XML file
420 CXmlParameterSerializingContext parameterBuildContext(strError);
421
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200422 log("Importing system structure from file %s", strXmlStructureFilePath.c_str());
423
Patrick Benavoli68a91282011-08-31 11:23:23 +0200424 if (!xmlParse(parameterBuildContext, pSystemClass, strXmlStructureFilePath, strXmlStructureFolder, EParameterCreationLibrary)) {
425
426 return false;
427 }
428
429 // Initialize offsets
430 pSystemClass->setOffset(0);
431
432 // Initialize main blackboard's size
433 _pMainParameterBlackboard->setSize(pSystemClass->getFootPrint());
434
435 return true;
436}
437
438bool CParameterMgr::loadSettings(string& strError)
439{
440 CAutoLog autoLog(this, "Loading settings");
441
442 // Get settings configuration element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100443 const CFrameworkConfigurationGroup* pParameterConfigurationGroup = static_cast<const CFrameworkConfigurationGroup*>(getConstFrameworkConfiguration()->findChildOfKind("SettingsConfiguration"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200444
445 if (!pParameterConfigurationGroup) {
446
447 // No settings to load
448
449 return true;
450 }
451 // Get binary settings file location
452 const CFrameworkConfigurationLocation* pBinarySettingsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("BinarySettingsFileLocation"));
453
454 string strXmlBinarySettingsFilePath;
455
456 if (pBinarySettingsFileLocation) {
457
458 // Get Xml binary settings file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100459 strXmlBinarySettingsFilePath = pBinarySettingsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200460 }
461
462 // Get configurable domains element
463 const CFrameworkConfigurationLocation* pConfigurableDomainsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("ConfigurableDomainsFileLocation"));
464
465 if (!pConfigurableDomainsFileLocation) {
466
467 strError = "No ConfigurableDomainsFileLocation element found for SystemClass " + getSystemClass()->getName();
468
469 return false;
470 }
471 // Get destination root element
472 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
473
474 // Get Xml configuration domains file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100475 string strXmlConfigurationDomainsFilePath = pConfigurableDomainsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200476
477 // Get Xml configuration domains folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100478 string strXmlConfigurationDomainsFolder = pConfigurableDomainsFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200479
480 // Parse configuration domains XML file (ask to read settings from XML file if they are not provided as binary)
481 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, !pBinarySettingsFileLocation);
482
483 // Selection criteria definition for rule creation
484 xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
485
Patrick Benavoli63499d42011-10-24 18:50:03 +0200486 // Auto validation of configurations if no binary settings provided
487 xmlDomainSerializingContext.setAutoValidationRequired(!pBinarySettingsFileLocation);
488
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200489 log("Importing configurable domains from file %s %s settings", strXmlConfigurationDomainsFilePath.c_str(), pBinarySettingsFileLocation ? "without" : "with");
490
Patrick Benavoli68a91282011-08-31 11:23:23 +0200491 // Do parse
492 if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strXmlConfigurationDomainsFilePath, strXmlConfigurationDomainsFolder, EParameterConfigurationLibrary, "SystemClassName")) {
493
494 return false;
495 }
496 // We have loaded the whole system structure, compute checksum
497 const CSystemClass* pSystemClass = getConstSystemClass();
498 _uiStructureChecksum = pSystemClass->computeStructureChecksum() + getConfigurableDomains()->computeStructureChecksum() + getSelectionCriteria()->computeStructureChecksum();
499
500 // Load binary settings if any provided
501 if (pBinarySettingsFileLocation && !pConfigurableDomains->serializeSettings(strXmlBinarySettingsFilePath, false, _uiStructureChecksum, strError)) {
502
503 return false;
504 }
505
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200506 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200507}
508
509// XML parsing
510bool CParameterMgr::xmlParse(CXmlElementSerializingContext& elementSerializingContext, CElement* pRootElement, const string& strXmlFilePath, const string& strXmlFolder, CParameterMgr::ElementLibrary eElementLibrary, const string& strNameAttrituteName)
511{
512 // Init serializing context
513 elementSerializingContext.set(_pElementLibrarySet->getElementLibrary(eElementLibrary), strXmlFolder, _strSchemaFolderLocation);
514
515 // Get Schema file associated to root element
516 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pRootElement->getKind() + ".xsd";
517
518 // Parse Structure XML file
519 CXmlParser parser(strXmlFilePath, strXmlSchemaFilePath, pRootElement->getKind(), elementSerializingContext);
520
521 if (!parser.open()) {
522
523 return false;
524 }
525
526 // Check Root element name attribute (if any)
527 string strRootElementName = parser.getRootElementAttributeString(strNameAttrituteName);
528
529 if (!strRootElementName.empty() && strRootElementName != pRootElement->getName()) {
530
531 elementSerializingContext.setError("Error: Wrong XML structure file " + strXmlFilePath);
532 elementSerializingContext.appendLineToError(pRootElement->getKind() + " element " + pRootElement->getName() + " mismatches expected " + pRootElement->getKind() + " type " + pRootElement->getName());
533
534 return false;
535 }
536
537 // Start clean
538 pRootElement->clean();
539
540 // Parse
541 if (!parser.parse(pRootElement)) {
542
543 // Cleanup
544 pRootElement->clean();
545
546 return false;
547 }
548
549 // Close parser
550 if (!parser.close()) {
551
552 return false;
553 }
554
555 return true;
556}
557
558// Init
559bool CParameterMgr::init(string& strError)
560{
561 return base::init(strError);
562}
563
564// Selection criteria interface
565CSelectionCriterionType* CParameterMgr::createSelectionCriterionType(bool bIsInclusive)
566{
567 // Propagate
568 return getSelectionCriteria()->createSelectionCriterionType(bIsInclusive);
569}
570
571CSelectionCriterion* CParameterMgr::createSelectionCriterion(const string& strName, const CSelectionCriterionType* pSelectionCriterionType)
572{
573 // Propagate
574 return getSelectionCriteria()->createSelectionCriterion(strName, pSelectionCriterionType);
575}
576
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200577// Selection criterion retrieval
578CSelectionCriterion* CParameterMgr::getSelectionCriterion(const string& strName)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200579{
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200580 // Propagate
581 return getSelectionCriteria()->getSelectionCriterion(strName);
582}
583
584// Selection criteria changed event
585bool CParameterMgr::applyConfigurations(string& strError)
586{
587 CAutoLog autoLog(this, "Configuration application request");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200588
589 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +0100590 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200591
592 if (!_bTuningModeIsOn) {
593
594 // Apply configuration(s)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200595 if (!getConfigurableDomains()->apply(_pMainParameterBlackboard, false, strError)) {
596
597 log("Failed to apply configurations!");
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200598
599 return false;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200600 }
601 }
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200602
603 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200604}
605
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200606// Dynamic parameter handling
Patrick Benavoli065264a2011-11-20 15:46:41 +0100607CParameterHandle* CParameterMgr::createParameterHandle(const string& strPath, string& strError)
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200608{
Patrick Benavoli065264a2011-11-20 15:46:41 +0100609 CPathNavigator pathNavigator(strPath);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200610
Patrick Benavoli065264a2011-11-20 15:46:41 +0100611 // Nagivate through system class
612 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
613
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100614 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100615 }
616
617 // Find element
618 const CElement* pElement = getConstSystemClass()->findDescendant(pathNavigator);
619
620 if (!pElement) {
621
622 strError = "Path not found";
623
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100624 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100625 }
626
627 // Check found element is a parameter
628 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pElement);
629
630 if (!pConfigurableElement->isParameter()) {
631
632 // Element is not parameter
633 strError = "Not a parameter";
634
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100635 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100636 }
637
638 // Convert as parameter and return new handle
639 return new CParameterHandle(static_cast<const CBaseParameter*>(pElement), this);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200640}
641
Patrick Benavoli68a91282011-08-31 11:23:23 +0200642/////////////////// Remote command parsers
Patrick Benavoli592ae562011-09-05 16:53:58 +0200643/// Version
Patrick Benavoli63499d42011-10-24 18:50:03 +0200644CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::versionCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli592ae562011-09-05 16:53:58 +0200645{
646 (void)remoteCommand;
647
Patrick Benavoli63499d42011-10-24 18:50:03 +0200648 // Show version
649 strResult = getVersion();
Patrick Benavoli592ae562011-09-05 16:53:58 +0200650
Patrick Benavoli63499d42011-10-24 18:50:03 +0200651 return CCommandHandler::ESucceeded;
Patrick Benavoli592ae562011-09-05 16:53:58 +0200652}
653
Patrick Benavoli68a91282011-08-31 11:23:23 +0200654/// Status
Patrick Benavoli63499d42011-10-24 18:50:03 +0200655CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::statusCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200656{
657 (void)remoteCommand;
658 // System class
659 const CSystemClass* pSystemClass = getSystemClass();
660
Patrick Benavoli68a91282011-08-31 11:23:23 +0200661 // Show status
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200662 /// General section
663 appendTitle(strResult, "General:");
664 // System class
Patrick Benavoli68a91282011-08-31 11:23:23 +0200665 strResult += "System Class: ";
666 strResult += pSystemClass->getName();
667 strResult += "\n";
668
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200669 // Tuning mode
Patrick Benavoli68a91282011-08-31 11:23:23 +0200670 strResult += "Tuning Mode: ";
671 strResult += tuningModeOn() ? "on" : "off";
672 strResult += "\n";
673
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200674 // Value space
Patrick Benavoli68a91282011-08-31 11:23:23 +0200675 strResult += "Value Space: ";
676 strResult += valueSpaceIsRaw() ? "raw" : "real";
677 strResult += "\n";
678
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200679 // Output raw format
680 strResult += "Output Raw Format: ";
681 strResult += outputRawFormatIsHex() ? "hex" : "dec";
682 strResult += "\n";
683
684 // Auto Sync
Patrick Benavoli68a91282011-08-31 11:23:23 +0200685 strResult += "Auto Sync: ";
686 strResult += autoSyncOn() ? "on" : "off";
687 strResult += "\n";
688
689 /// Subsystem list
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200690 appendTitle(strResult, "Subsystems:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200691 string strSubsystemList;
692 pSystemClass->listChildrenPaths(strSubsystemList);
693 strResult += strSubsystemList;
694
695 /// Last applied configurations
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200696 appendTitle(strResult, "Last applied configurations:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200697 string strLastAppliedConfigurations;
698 getConfigurableDomains()->listLastAppliedConfigurations(strLastAppliedConfigurations);
699 strResult += strLastAppliedConfigurations;
700
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200701 /// Criteria states
702 appendTitle(strResult, "Selection criteria:");
703 string strSelectionCriteria;
704 getSelectionCriteria()->listSelectionCriteria(strSelectionCriteria, false);
705 strResult += strSelectionCriteria;
706
Patrick Benavoli63499d42011-10-24 18:50:03 +0200707 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200708}
709
710/// Tuning Mode
Patrick Benavoli63499d42011-10-24 18:50:03 +0200711CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200712{
713 if (remoteCommand.getArgument(0) == "on") {
714
715 if (setTuningMode(true, strResult)) {
716
Patrick Benavoli63499d42011-10-24 18:50:03 +0200717 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200718 }
719 } else if (remoteCommand.getArgument(0) == "off") {
720
721 if (setTuningMode(false, strResult)) {
722
Patrick Benavoli63499d42011-10-24 18:50:03 +0200723 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200724 }
725 } else {
726 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200727 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200728 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200729 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200730}
731
Patrick Benavoli63499d42011-10-24 18:50:03 +0200732CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200733{
734 (void)remoteCommand;
735
736 strResult = tuningModeOn() ? "on" : "off";
737
Patrick Benavoli63499d42011-10-24 18:50:03 +0200738 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200739}
740
741/// Value Space
Patrick Benavoli63499d42011-10-24 18:50:03 +0200742CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200743{
744 (void)strResult;
745
746 if (remoteCommand.getArgument(0) == "raw") {
747
748 setValueSpace(true);
749
Patrick Benavoli63499d42011-10-24 18:50:03 +0200750 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200751
752 } else if (remoteCommand.getArgument(0) == "real") {
753
754 setValueSpace(false);
755
Patrick Benavoli63499d42011-10-24 18:50:03 +0200756 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200757
758 } else {
759 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200760 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200761 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200762 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200763}
764
Patrick Benavoli63499d42011-10-24 18:50:03 +0200765CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200766{
767 (void)remoteCommand;
768
769 strResult = valueSpaceIsRaw() ? "raw" : "real";
770
Patrick Benavoli63499d42011-10-24 18:50:03 +0200771 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200772}
773
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200774/// Output Raw Format
Patrick Benavoli63499d42011-10-24 18:50:03 +0200775CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200776{
777 (void)strResult;
778
779 if (remoteCommand.getArgument(0) == "hex") {
780
781 setOutputRawFormat(true);
782
Patrick Benavoli63499d42011-10-24 18:50:03 +0200783 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200784
785 } else if (remoteCommand.getArgument(0) == "dec") {
786
787 setOutputRawFormat(false);
788
Patrick Benavoli63499d42011-10-24 18:50:03 +0200789 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200790
791 } else {
792 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200793 return CCommandHandler::EShowUsage;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200794 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200795 return CCommandHandler::EFailed;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200796}
797
Patrick Benavoli63499d42011-10-24 18:50:03 +0200798CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200799{
800 (void)remoteCommand;
801
802 strResult = outputRawFormatIsHex() ? "hex" : "dec";
803
Patrick Benavoli63499d42011-10-24 18:50:03 +0200804 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200805}
806
Patrick Benavoli68a91282011-08-31 11:23:23 +0200807/// Sync
Patrick Benavoli63499d42011-10-24 18:50:03 +0200808CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200809{
810 if (remoteCommand.getArgument(0) == "on") {
811
812 if (setAutoSync(true, strResult)) {
813
Patrick Benavoli63499d42011-10-24 18:50:03 +0200814 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200815 }
816 } else if (remoteCommand.getArgument(0) == "off") {
817
818 if (setAutoSync(false, strResult)) {
819
Patrick Benavoli63499d42011-10-24 18:50:03 +0200820 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200821 }
822 } else {
823 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200824 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200825 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200826 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200827}
828
Patrick Benavoli63499d42011-10-24 18:50:03 +0200829CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200830{
831 (void)remoteCommand;
832
833 strResult = autoSyncOn() ? "on" : "off";
834
Patrick Benavoli63499d42011-10-24 18:50:03 +0200835 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200836}
837
Patrick Benavoli63499d42011-10-24 18:50:03 +0200838CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::syncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200839{
840 (void)remoteCommand;
841
Patrick Benavoli63499d42011-10-24 18:50:03 +0200842 return sync(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200843}
844
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200845/// Criteria
Patrick Benavoli63499d42011-10-24 18:50:03 +0200846CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listCriteriaCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200847{
848 (void)remoteCommand;
849
850 getSelectionCriteria()->listSelectionCriteria(strResult, true);
851
Patrick Benavoli63499d42011-10-24 18:50:03 +0200852 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200853}
Patrick Benavoli68a91282011-08-31 11:23:23 +0200854
855/// Domains
Patrick Benavoli63499d42011-10-24 18:50:03 +0200856CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200857{
858 (void)remoteCommand;
859
Patrick Benavoli63499d42011-10-24 18:50:03 +0200860 getConfigurableDomains()->listDomains(strResult);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200861
Patrick Benavoli63499d42011-10-24 18:50:03 +0200862 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200863}
864
Patrick Benavoli63499d42011-10-24 18:50:03 +0200865CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200866{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200867 return createDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200868}
869
Patrick Benavoli63499d42011-10-24 18:50:03 +0200870CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200871{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200872 return deleteDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200873}
874
Patrick Benavoli63499d42011-10-24 18:50:03 +0200875CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200876{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200877 return getConfigurableDomains()->renameDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200878}
879
Patrick Benavoli63499d42011-10-24 18:50:03 +0200880CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200881{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200882 // Check tuning mode
883 if (!checkTuningModeOn(strResult)) {
884
885 return CCommandHandler::EFailed;
886 }
887
888 // Set property
889 bool bSequenceAware;
890
891 if (remoteCommand.getArgument(1) == "true") {
892
893 bSequenceAware = true;
894
895 } else if (remoteCommand.getArgument(1) == "false") {
896
897 bSequenceAware = false;
898
899 } else {
900 // Show usage
901 return CCommandHandler::EShowUsage;
902 }
903
904 return getConfigurableDomains()->setSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200905}
906
Patrick Benavoli63499d42011-10-24 18:50:03 +0200907CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200908{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200909 // Get property
910 bool bSequenceAware;
911
912 if (!getConfigurableDomains()->getSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult)) {
913
914 return CCommandHandler::EFailed;
915 }
916
917 strResult = bSequenceAware ? "true" : "false";
918
919 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200920}
921
Patrick Benavoli63499d42011-10-24 18:50:03 +0200922CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200923{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200924 return getConfigurableDomains()->listDomainElements(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200925}
926
Patrick Benavoli63499d42011-10-24 18:50:03 +0200927CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::addElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200928{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200929 return addConfigurableElementToDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
930}
931
932CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::removeElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
933{
934 return removeConfigurableElementFromDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
935}
936
937CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::splitDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
938{
939 return split(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200940}
941
942/// Configurations
Patrick Benavoli63499d42011-10-24 18:50:03 +0200943CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConfigurationsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200944{
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100945 return getConstConfigurableDomains()->listConfigurations(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
946}
947
948CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
949{
950 (void)remoteCommand;
951
952 // Dummy error context
953 string strError;
954 CErrorContext errorContext(strError);
955
956 // Dump
957 getConstConfigurableDomains()->dumpContent(strResult, errorContext);
958
959 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200960}
961
Patrick Benavoli63499d42011-10-24 18:50:03 +0200962CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200963{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200964 return createConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200965}
966
Patrick Benavoli63499d42011-10-24 18:50:03 +0200967CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200968{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200969 return deleteConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200970}
971
Patrick Benavoli63499d42011-10-24 18:50:03 +0200972CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200973{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200974 return getConfigurableDomains()->renameConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200975}
976
Patrick Benavoli63499d42011-10-24 18:50:03 +0200977CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::saveConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200978{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200979 return saveConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200980}
981
Patrick Benavoli63499d42011-10-24 18:50:03 +0200982CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::restoreConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200983{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200984 return restoreConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
985}
986
987CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
988{
989 // Check tuning mode
990 if (!checkTuningModeOn(strResult)) {
991
992 return CCommandHandler::EFailed;
993 }
994
995 // Build configurable element path list
996 vector<string> astrNewElementSequence;
997
998 uint32_t uiArgument;
999
1000 for (uiArgument = 2; uiArgument < remoteCommand.getArgumentCount(); uiArgument++) {
1001
1002 astrNewElementSequence.push_back(remoteCommand.getArgument(uiArgument));
1003 }
1004
1005 // Delegate to configurable domains
1006 return getConfigurableDomains()->setElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), astrNewElementSequence, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1007}
1008
1009CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1010{
1011 // Delegate to configurable domains
1012 return getConfigurableDomains()->getElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001013}
1014
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001015CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1016{
1017 // Delegate to configurable domains
1018 return getConfigurableDomains()->setApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.packArguments(2, remoteCommand.getArgumentCount() - 2), getConstSelectionCriteria()->getSelectionCriteriaDefinition(), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1019}
1020
1021CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::clearRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1022{
1023 // Delegate to configurable domains
1024 return getConfigurableDomains()->clearApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1025}
1026
1027CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1028{
1029 // Delegate to configurable domains
1030 return getConfigurableDomains()->getApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
1031}
1032
Patrick Benavoli68a91282011-08-31 11:23:23 +02001033/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001034CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001035{
1036 CElementLocator elementLocator(getSystemClass(), false);
1037
1038 CElement* pLocatedElement = NULL;
1039
1040 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1041
Patrick Benavoli63499d42011-10-24 18:50:03 +02001042 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001043 }
1044
1045 strResult = string("\n");
1046
1047 if (!pLocatedElement) {
1048
1049 // List from root folder
1050
1051 // Return system class qualified name
1052 pLocatedElement = getSystemClass();
1053 }
1054
1055 // Return sub-elements
1056 strResult += pLocatedElement->listQualifiedPaths(false);
1057
Patrick Benavoli63499d42011-10-24 18:50:03 +02001058 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001059}
1060
1061/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001062CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listParametersCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001063{
1064 CElementLocator elementLocator(getSystemClass(), false);
1065
1066 CElement* pLocatedElement = NULL;
1067
1068 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1069
Patrick Benavoli63499d42011-10-24 18:50:03 +02001070 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001071 }
1072
1073 strResult = string("\n");
1074
1075 if (!pLocatedElement) {
1076
1077 // List from root folder
1078
1079 // Return system class qualified name
1080 pLocatedElement = getSystemClass();
1081 }
1082
1083 // Return sub-elements
1084 strResult += pLocatedElement->listQualifiedPaths(true);
1085
Patrick Benavoli63499d42011-10-24 18:50:03 +02001086 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001087}
1088
Patrick Benavoli63499d42011-10-24 18:50:03 +02001089CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001090{
1091 CElementLocator elementLocator(getSystemClass());
1092
1093 CElement* pLocatedElement = NULL;
1094
1095 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1096
Patrick Benavoli63499d42011-10-24 18:50:03 +02001097 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001098 }
1099
1100 string strError;
1101
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001102 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001103
1104 // Dump elements
1105 pLocatedElement->dumpContent(strResult, parameterAccessContext);
1106
Patrick Benavoli63499d42011-10-24 18:50:03 +02001107 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001108}
1109
Patrick Benavoli63499d42011-10-24 18:50:03 +02001110CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSizeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001111{
1112 CElementLocator elementLocator(getSystemClass());
1113
1114 CElement* pLocatedElement = NULL;
1115
1116 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1117
Patrick Benavoli63499d42011-10-24 18:50:03 +02001118 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001119 }
1120
1121 // Converted to actual sizable element
1122 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1123
1124 // Get size as string
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001125 strResult = pConfigurableElement->getFootprintAsString();
Patrick Benavoli68a91282011-08-31 11:23:23 +02001126
Patrick Benavoli63499d42011-10-24 18:50:03 +02001127 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001128}
1129
Patrick Benavoli63499d42011-10-24 18:50:03 +02001130CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showPropertiesCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001131{
1132 CElementLocator elementLocator(getSystemClass());
1133
1134 CElement* pLocatedElement = NULL;
1135
1136 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1137
Patrick Benavoli63499d42011-10-24 18:50:03 +02001138 return CCommandHandler::EFailed;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001139 }
1140
1141 // Convert element
1142 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1143
1144 // Return element properties
1145 pConfigurableElement->showProperties(strResult);
1146
Patrick Benavoli63499d42011-10-24 18:50:03 +02001147 return CCommandHandler::ESucceeded;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001148}
1149
Patrick Benavoli63499d42011-10-24 18:50:03 +02001150CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001151{
1152 string strValue;
1153
Patrick Benavoli065264a2011-11-20 15:46:41 +01001154 if (!accessValue(remoteCommand.getArgument(0), strValue, false, strResult)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001155
Patrick Benavoli63499d42011-10-24 18:50:03 +02001156 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001157 }
1158 // Succeeded
1159 strResult = strValue;
1160
Patrick Benavoli63499d42011-10-24 18:50:03 +02001161 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001162}
1163
Patrick Benavoli63499d42011-10-24 18:50:03 +02001164CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001165{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001166 // Check tuning mode
1167 if (!checkTuningModeOn(strResult)) {
1168
1169 return CCommandHandler::EFailed;
1170 }
1171 // Get value to set
1172 string strValue = remoteCommand.packArguments(1, remoteCommand.getArgumentCount() - 1);
1173
1174 return accessValue(remoteCommand.getArgument(0), strValue, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001175}
1176
Patrick Benavoli63499d42011-10-24 18:50:03 +02001177CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listBelongingDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001178{
1179 CElementLocator elementLocator(getSystemClass());
1180
1181 CElement* pLocatedElement = NULL;
1182
1183 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1184
Patrick Benavoli63499d42011-10-24 18:50:03 +02001185 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001186 }
1187
1188 // Convert element
1189 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1190
1191 // Return element belonging domains
1192 pConfigurableElement->listBelongingDomains(strResult);
1193
Patrick Benavoli63499d42011-10-24 18:50:03 +02001194 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001195}
1196
Patrick Benavoli63499d42011-10-24 18:50:03 +02001197CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001198{
1199 CElementLocator elementLocator(getSystemClass());
1200
1201 CElement* pLocatedElement = NULL;
1202
1203 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1204
Patrick Benavoli63499d42011-10-24 18:50:03 +02001205 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001206 }
1207
1208 // Convert element
1209 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1210
1211 // Return element belonging domains
1212 pConfigurableElement->listAssociatedDomains(strResult);
1213
Patrick Benavoli63499d42011-10-24 18:50:03 +02001214 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001215}
1216
Patrick Benavoli63499d42011-10-24 18:50:03 +02001217CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001218{
1219 (void)remoteCommand;
1220
1221 getConfigurableDomains()->listAssociatedElements(strResult);
1222
Patrick Benavoli63499d42011-10-24 18:50:03 +02001223 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001224}
1225
Patrick Benavoli63499d42011-10-24 18:50:03 +02001226CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConflictingElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001227{
1228 (void)remoteCommand;
1229
1230 getConfigurableDomains()->listConflictingElements(strResult);
1231
Patrick Benavoli63499d42011-10-24 18:50:03 +02001232 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001233}
1234
Patrick Benavoli63499d42011-10-24 18:50:03 +02001235CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listRogueElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001236{
1237 (void)remoteCommand;
1238
1239 getSystemClass()->listRogueElements(strResult);
1240
Patrick Benavoli63499d42011-10-24 18:50:03 +02001241 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001242}
1243
1244/// Settings Import/Export
Patrick Benavoli63499d42011-10-24 18:50:03 +02001245CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001246{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001247 return exportDomainsXml(remoteCommand.getArgument(0), false, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001248}
1249
Patrick Benavoli63499d42011-10-24 18:50:03 +02001250CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001251{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001252 return importDomainsXml(remoteCommand.getArgument(0), false, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001253}
1254
Patrick Benavoli63499d42011-10-24 18:50:03 +02001255CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001256{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001257 return exportDomainsXml(remoteCommand.getArgument(0), true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001258}
1259
Patrick Benavoli63499d42011-10-24 18:50:03 +02001260CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001261{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001262 return importDomainsXml(remoteCommand.getArgument(0), true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001263}
1264
Patrick Benavoli63499d42011-10-24 18:50:03 +02001265CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001266{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001267 return exportDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001268}
1269
Patrick Benavoli63499d42011-10-24 18:50:03 +02001270CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001271{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001272 return importDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001273}
1274
1275// User set/get parameters
Patrick Benavoli065264a2011-11-20 15:46:41 +01001276bool CParameterMgr::accessValue(const string& strPath, string& strValue, bool bSet, string& strError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001277{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001278 // Lock state
1279 CAutoLock autoLock(&_blackboardMutex);
1280
1281 CPathNavigator pathNavigator(strPath);
1282
1283 // Nagivate through system class
1284 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001285
1286 return false;
1287 }
1288
Patrick Benavoli065264a2011-11-20 15:46:41 +01001289 // Define context
1290 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001291
Patrick Benavoli68808c62012-02-02 17:12:41 +01001292 // Auto Sync
1293 if (bSet) {
1294
1295 parameterAccessContext.setAutoSync(_bAutoSyncOn);
1296 }
1297
Patrick Benavoli065264a2011-11-20 15:46:41 +01001298 // Do the get
1299 return getConstSystemClass()->accessValue(pathNavigator, strValue, bSet, parameterAccessContext);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001300}
1301
1302// Tuning mode
1303bool CParameterMgr::setTuningMode(bool bOn, string& strError)
1304{
1305 // Tuning allowed?
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001306 if (bOn && !getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001307
1308 strError = "Tuning prohibited";
1309
1310 return false;
1311 }
1312 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +01001313 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001314
1315 // Warn domains about exiting tuning mode
1316 if (!bOn && _bTuningModeIsOn) {
1317
1318 // Ensure application of currently selected configurations
Patrick Benavoli1387bda2011-08-31 11:23:24 +02001319 // Force-apply configurations
Patrick Benavoli68a91282011-08-31 11:23:23 +02001320 if (!getConfigurableDomains()->apply(_pMainParameterBlackboard, true, strError)) {
1321
1322 return false;
1323 }
1324 // Turn auto sync back on
1325 _bAutoSyncOn = true;
1326 }
1327
1328 // Store
1329 _bTuningModeIsOn = bOn;
1330
Patrick Benavoli68a91282011-08-31 11:23:23 +02001331 return true;
1332}
1333
1334bool CParameterMgr::tuningModeOn() const
1335{
1336 return _bTuningModeIsOn;
1337}
1338
1339// Current value space for user set/get value interpretation
1340void CParameterMgr::setValueSpace(bool bIsRaw)
1341{
1342 _bValueSpaceIsRaw = bIsRaw;
1343}
1344
1345bool CParameterMgr::valueSpaceIsRaw()
1346{
1347 return _bValueSpaceIsRaw;
1348}
1349
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001350// Current Output Raw Format for user get value interpretation
1351void CParameterMgr::setOutputRawFormat(bool bIsHex)
1352{
1353 _bOutputRawFormatIsHex = bIsHex;
1354}
1355
1356bool CParameterMgr::outputRawFormatIsHex()
1357{
1358 return _bOutputRawFormatIsHex;
1359}
1360
Patrick Benavoli68a91282011-08-31 11:23:23 +02001361/// Sync
1362// Automatic hardware synchronization control (during tuning session)
1363bool CParameterMgr::setAutoSync(bool bAutoSyncOn, string& strError)
1364{
1365 // Check tuning mode
1366 if (!checkTuningModeOn(strError)) {
1367
1368 return false;
1369 }
1370 // Warn domains about turning auto sync back on
1371 if (bAutoSyncOn && !_bAutoSyncOn) {
1372
Patrick Benavoli592ae562011-09-05 16:53:58 +02001373 // Do the synchronization at system class level (could be optimized by keeping track of all modified parameters)
1374 if (!sync(strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001375
1376 return false;
1377 }
1378 }
1379
1380 // Set Auto sync
1381 _bAutoSyncOn = bAutoSyncOn;
1382
1383 return true;
1384}
1385
1386bool CParameterMgr::autoSyncOn() const
1387{
1388 return _bAutoSyncOn;
1389}
1390
1391// Manual hardware synchronization control (during tuning session)
1392bool CParameterMgr::sync(string& strError)
1393{
1394 // Check tuning mode
1395 if (!checkTuningModeOn(strError)) {
1396
1397 return false;
1398 }
1399 // Warn domains about turning auto sync back on
1400 if (_bAutoSyncOn) {
1401
1402 strError = "Feature unavailable when Auto Sync is on";
1403
1404 return false;
1405 }
1406
1407 // Get syncer set
1408 CSyncerSet syncerSet;
1409 // ... from system class
1410 getConstSystemClass()->fillSyncerSet(syncerSet);
1411 // Sync
1412 return syncerSet.sync(*_pMainParameterBlackboard, false, strError);
1413}
1414
1415// Content dump
1416void CParameterMgr::logStructureContent(string& strContent) const
1417{
1418 string strError;
1419
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001420 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001421
1422 dumpContent(strContent, parameterAccessContext);
1423}
1424
1425// Configuration/Domains handling
1426bool CParameterMgr::createDomain(const string& strName, string& strError)
1427{
1428 // Check tuning mode
1429 if (!checkTuningModeOn(strError)) {
1430
1431 return false;
1432 }
1433
1434 // Delegate to configurable domains
1435 return getConfigurableDomains()->createDomain(strName, strError);
1436}
1437
1438bool CParameterMgr::deleteDomain(const string& strName, string& strError)
1439{
1440 // Check tuning mode
1441 if (!checkTuningModeOn(strError)) {
1442
1443 return false;
1444 }
1445
1446 // Delegate to configurable domains
1447 return getConfigurableDomains()->deleteDomain(strName, strError);
1448}
1449
1450bool CParameterMgr::createConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1451{
1452 // Check tuning mode
1453 if (!checkTuningModeOn(strError)) {
1454
1455 return false;
1456 }
1457
1458 // Delegate to configurable domains
1459 return getConfigurableDomains()->createConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1460}
1461
1462bool CParameterMgr::deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1463{
1464 // Check tuning mode
1465 if (!checkTuningModeOn(strError)) {
1466
1467 return false;
1468 }
1469
1470 // Delegate to configurable domains
1471 return getConfigurableDomains()->deleteConfiguration(strDomain, strConfiguration, strError);
1472}
1473
1474bool CParameterMgr::restoreConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1475{
1476 // Check tuning mode
1477 if (!checkTuningModeOn(strError)) {
1478
1479 return false;
1480 }
1481
1482 // Delegate to configurable domains
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001483 return getConstConfigurableDomains()->restoreConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001484}
1485
1486bool CParameterMgr::saveConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1487{
1488 // Check tuning mode
1489 if (!checkTuningModeOn(strError)) {
1490
1491 return false;
1492 }
1493
1494 // Delegate to configurable domains
1495 return getConfigurableDomains()->saveConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1496}
1497
1498// Configurable element - domain association
1499bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1500{
1501 // Check tuning mode
1502 if (!checkTuningModeOn(strError)) {
1503
1504 return false;
1505 }
1506
1507 CElementLocator elementLocator(getSystemClass());
1508
1509 CElement* pLocatedElement = NULL;
1510
1511 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1512
1513 return false;
1514 }
1515
1516 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001517 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001518
1519 // Delegate
1520 return getConfigurableDomains()->addConfigurableElementToDomain(strDomain, pConfigurableElement, _pMainParameterBlackboard, strError);
1521}
1522
1523bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1524{
1525 // Check tuning mode
1526 if (!checkTuningModeOn(strError)) {
1527
1528 return false;
1529 }
1530
1531 CElementLocator elementLocator(getSystemClass());
1532
1533 CElement* pLocatedElement = NULL;
1534
1535 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1536
Patrick Benavoli63499d42011-10-24 18:50:03 +02001537 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001538 }
1539
1540 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001541 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001542
1543 // Delegate
1544 return getConfigurableDomains()->removeConfigurableElementFromDomain(strDomain, pConfigurableElement, strError);
1545}
1546
1547bool CParameterMgr::split(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1548{
1549 // Check tuning mode
1550 if (!checkTuningModeOn(strError)) {
1551
1552 return false;
1553 }
1554
1555 CElementLocator elementLocator(getSystemClass());
1556
1557 CElement* pLocatedElement = NULL;
1558
1559 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1560
Patrick Benavoli63499d42011-10-24 18:50:03 +02001561 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001562 }
1563
1564 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001565 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001566
1567 // Delegate
1568 return getConfigurableDomains()->split(strDomain, pConfigurableElement, strError);
1569}
1570
1571// XML Import/Export
1572bool CParameterMgr::importDomainsXml(const string& strFileName, bool bWithSettings, string& strError)
1573{
1574 // Check tuning mode
1575 if (!checkTuningModeOn(strError)) {
1576
1577 return false;
1578 }
1579
1580 // check path is absolute
1581 if (strFileName[0] != '/') {
1582
1583 strError = "Please provide absolute path";
1584
1585 return false;
1586 }
1587 // Root element
1588 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1589
1590 // Context
1591 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1592
1593 // Secltion criteria definition for rule creation
1594 xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
1595
1596 // Parse
1597 if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strFileName, "", EParameterConfigurationLibrary, "SystemClassName")) {
1598
1599 return false;
1600 }
1601
1602 // Validate domains after XML import
1603 pConfigurableDomains->validate(_pMainParameterBlackboard);
1604
1605 return true;
1606}
1607
1608bool CParameterMgr::exportDomainsXml(const string& strFileName, bool bWithSettings, string& strError) const
1609{
1610 // check path is absolute
1611 if (strFileName[0] != '/') {
1612
1613 strError = "Please provide absolute path";
1614
1615 return false;
1616 }
1617
1618 // Root element
1619 const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains();
1620
1621 // Get Schema file associated to root element
1622 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pConfigurableDomains->getKind() + ".xsd";
1623
1624 // Context
1625 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1626
1627 // Value space
1628 xmlDomainSerializingContext.setValueSpaceRaw(_bValueSpaceIsRaw);
1629
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001630 // Output raw format
1631 xmlDomainSerializingContext.setOutputRawFormat(_bOutputRawFormatIsHex);
1632
Patrick Benavoli68a91282011-08-31 11:23:23 +02001633 // Instantiate composer
1634 CXmlComposer xmlComposer(strFileName, strXmlSchemaFilePath, pConfigurableDomains->getKind(), xmlDomainSerializingContext);
1635
1636 // Open composer
1637 if (!xmlComposer.open()) {
1638
1639 return false;
1640 }
1641
1642 // Compose
Patrick Benavoli63499d42011-10-24 18:50:03 +02001643 xmlComposer.compose(pConfigurableDomains, "parameter-framework", getVersion());
Patrick Benavoli68a91282011-08-31 11:23:23 +02001644
1645 // Close composer
1646 if (!xmlComposer.close()) {
1647
1648 return false;
1649 }
1650
1651 return true;
1652}
1653
1654// Binary Import/Export
1655bool CParameterMgr::importDomainsBinary(const string& strFileName, string& strError)
1656{
1657 // Check tuning mode
1658 if (!checkTuningModeOn(strError)) {
1659
1660 return false;
1661 }
1662 // check path is absolute
1663 if (strFileName[0] != '/') {
1664
1665 strError = "Please provide absolute path";
1666
1667 return false;
1668 }
1669 // Root element
1670 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1671
1672 // Serialize in
1673 return pConfigurableDomains->serializeSettings(strFileName, false, _uiStructureChecksum, strError);
1674}
1675
1676bool CParameterMgr::exportDomainsBinary(const string& strFileName, string& strError)
1677{
1678 // check path is absolute
1679 if (strFileName[0] != '/') {
1680
1681 strError = "Please provide absolute path";
1682
1683 return false;
1684 }
Patrick Benavoli68a91282011-08-31 11:23:23 +02001685
Patrick Benavoli68a91282011-08-31 11:23:23 +02001686 // Root element
1687 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1688
1689 // Serialize out
1690 return pConfigurableDomains->serializeSettings(strFileName, true, _uiStructureChecksum, strError);
1691}
1692
1693// For tuning, check we're in tuning mode
1694bool CParameterMgr::checkTuningModeOn(string& strError) const
1695{
1696 // Tuning Mode on?
1697 if (!_bTuningModeIsOn) {
1698
1699 strError = "Tuning Mode must be on";
1700
1701 return false;
1702 }
1703 return true;
1704}
1705
Patrick Benavoli065264a2011-11-20 15:46:41 +01001706// Tuning mutex dynamic parameter handling
1707pthread_mutex_t* CParameterMgr::getBlackboardMutex()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001708{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001709 return &_blackboardMutex;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001710}
1711
Patrick Benavoli065264a2011-11-20 15:46:41 +01001712// Blackboard reference (dynamic parameter handling)
1713CParameterBlackboard* CParameterMgr::getParameterBlackboard()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001714{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001715 return _pMainParameterBlackboard;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001716}
1717
Patrick Benavoli68a91282011-08-31 11:23:23 +02001718// Dynamic creation library feeding
1719void CParameterMgr::feedElementLibraries()
1720{
1721 // Global Configuration handling
1722 CElementLibrary* pFrameworkConfigurationLibrary = new CElementLibrary;
1723
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001724 pFrameworkConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CParameterFrameworkConfiguration>("ParameterFrameworkConfiguration"));
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +01001725 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CSubsystemPlugins>("SubsystemPlugins"));
1726 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CPluginLocation>("Location"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001727 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("StructureDescriptionFileLocation"));
1728 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationGroup>("SettingsConfiguration"));
1729 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("ConfigurableDomainsFileLocation"));
1730 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("BinarySettingsFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001731
1732 _pElementLibrarySet->addElementLibrary(pFrameworkConfigurationLibrary);
1733
1734 // Parameter creation
1735 CElementLibrary* pParameterCreationLibrary = new CElementLibrary;
1736
1737 pParameterCreationLibrary->addElementBuilder(new CSubsystemElementBuilder(getSystemClass()->getSubsystemLibrary()));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001738 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CComponentType>("ComponentType"));
1739 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CComponentInstance>("Component"));
1740 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBitParameterType>("BitParameter"));
1741 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBitParameterBlockType>("BitParameterBlock"));
Patrick Benavoli1352ae52011-10-21 16:48:04 +02001742 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CStringParameterType>("StringParameter"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001743 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CParameterBlockType>("ParameterBlock"));
1744 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBooleanParameterType>("BooleanParameter"));
1745 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CIntegerParameterType>("IntegerParameter"));
Patrick Benavoliee65e6d2011-11-20 18:52:24 +01001746 pParameterCreationLibrary->addElementBuilder(new TElementBuilderTemplate<CLinearParameterAdaptation>("LinearAdaptation"));
Patrick Benavoli9fc3c0d2011-10-27 14:27:27 +02001747 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CEnumParameterType>("EnumParameter"));
Patrick Benavoli68808c62012-02-02 17:12:41 +01001748 pParameterCreationLibrary->addElementBuilder(new TElementBuilderTemplate<CEnumValuePair>("ValuePair"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001749 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CFixedPointParameterType>("FixedPointParameter"));
1750 pParameterCreationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CXmlFileIncluderElement>("SubsystemInclude"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001751
1752 _pElementLibrarySet->addElementLibrary(pParameterCreationLibrary);
1753
1754 // Parameter Configuration Domains creation
1755 CElementLibrary* pParameterConfigurationLibrary = new CElementLibrary;
1756
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001757 pParameterConfigurationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CConfigurableDomain>("ConfigurableDomain"));
1758 pParameterConfigurationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CDomainConfiguration>("Configuration"));
1759 pParameterConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CCompoundRule>("CompoundRule"));
1760 pParameterConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CSelectionCriterionRule>("SelectionCriterionRule"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001761
1762 _pElementLibrarySet->addElementLibrary(pParameterConfigurationLibrary);
1763}
1764
1765// Remote Processor Server connection handling
1766bool CParameterMgr::handleRemoteProcessingInterface(string& strError)
1767{
1768 CAutoLog autoLog(this, "Handling remote processing interface");
1769
1770 // Start server if tuning allowed
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001771 if (getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001772
1773 log("Loading remote processor library");
1774
1775 // Load library
1776 void* lib_handle = dlopen("libremote-processor.so", RTLD_NOW);
1777
1778 if (!lib_handle) {
1779
1780 // Return error
1781 const char* pcError = dlerror();
1782
1783 if (pcError) {
1784
1785 strError = pcError;
1786 } else {
1787
1788 strError = "Unable to load libremote-processor.so library";
1789 }
1790
1791 return false;
1792 }
1793
1794 CreateRemoteProcessorServer pfnCreateRemoteProcessorServer = (CreateRemoteProcessorServer)dlsym(lib_handle, "createRemoteProcessorServer");
1795
1796 if (!pfnCreateRemoteProcessorServer) {
1797
1798 strError = "libremote-process.so does not contain createRemoteProcessorServer symbol.";
1799
1800 return false;
1801 }
1802
1803 // Create server
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001804 _pRemoteProcessorServer = pfnCreateRemoteProcessorServer(getConstFrameworkConfiguration()->getServerPort(), _pCommandHandler);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001805
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001806 log("Starting remote processor server on port %d", getConstFrameworkConfiguration()->getServerPort());
Patrick Benavoli68a91282011-08-31 11:23:23 +02001807 // Start
1808 if (!_pRemoteProcessorServer->start()) {
1809
1810 strError = "Unable to start remote processor server";
1811
1812 return false;
1813 }
1814 }
1815
1816 return true;
1817}
1818
1819// Back synchronization
1820CBackSynchronizer* CParameterMgr::createBackSynchronizer(string& strError) const
1821{
1822#ifdef SIMULATION
1823 // In simulation, back synchronization of the blackboard won't probably work
1824 // We need to ensure though the blackboard is initialized with valid data
1825 return new CSimulatedBackSynchronizer(getConstSystemClass(), strError, _pMainParameterBlackboard);
1826#else
1827 // Real back synchronizer from subsystems
1828 return new CHardwareBackSynchronizer(getConstSystemClass(), strError, _pMainParameterBlackboard);
1829#endif
1830}
1831
1832// Children typwise access
1833CParameterFrameworkConfiguration* CParameterMgr::getFrameworkConfiguration()
1834{
1835 return static_cast<CParameterFrameworkConfiguration*>(getChild(EFrameworkConfiguration));
1836}
1837
1838const CParameterFrameworkConfiguration* CParameterMgr::getConstFrameworkConfiguration()
1839{
1840 return getFrameworkConfiguration();
1841}
1842
1843CSelectionCriteria* CParameterMgr::getSelectionCriteria()
1844{
1845 return static_cast<CSelectionCriteria*>(getChild(ESelectionCriteria));
1846}
1847
1848const CSelectionCriteria* CParameterMgr::getConstSelectionCriteria()
1849{
1850 return static_cast<const CSelectionCriteria*>(getChild(ESelectionCriteria));
1851}
1852
1853CSystemClass* CParameterMgr::getSystemClass()
1854{
1855 return static_cast<CSystemClass*>(getChild(ESystemClass));
1856}
1857
1858const CSystemClass* CParameterMgr::getConstSystemClass() const
1859{
1860 return static_cast<const CSystemClass*>(getChild(ESystemClass));
1861}
1862
1863// Configurable Domains
1864CConfigurableDomains* CParameterMgr::getConfigurableDomains()
1865{
1866 return static_cast<CConfigurableDomains*>(getChild(EConfigurableDomains));
1867}
1868
1869const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains()
1870{
1871 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
1872}
1873
1874const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains() const
1875{
1876 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
1877}