blob: c1538dfcadd1731518769f94cf8d8f0d043e302f [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" },
Kevin Rocard170f0a42012-06-18 13:56:05 +0200135 { "deleteAllDomains", &CParameterMgr::deleteAllDomainsCommmandProcess, 0, "", "Delete all configurable domains" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200136 { "renameDomain", &CParameterMgr::renameDomainCommmandProcess, 2, "<domain> <new name>", "Rename configurable domain" },
Patrick Benavoli63499d42011-10-24 18:50:03 +0200137 { "setSequenceAwareness", &CParameterMgr::setSequenceAwarenessCommmandProcess, 1, "<domain> true|false*", "Set configurable domain sequence awareness" },
138 { "getSequenceAwareness", &CParameterMgr::getSequenceAwarenessCommmandProcess, 1, "<domain>", "Get configurable domain sequence awareness" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200139 { "listDomainElements", &CParameterMgr::listDomainElementsCommmandProcess, 1, "<domain>", "List elements associated to configurable domain" },
140 { "addElement", &CParameterMgr::addElementCommmandProcess, 2, "<domain> <elem path>", "Associate element at given path to configurable domain" },
141 { "removeElement", &CParameterMgr::removeElementCommmandProcess, 2, "<domain> <elem path>", "Dissociate element at given path from configurable domain" },
142 { "splitDomain", &CParameterMgr::splitDomainCommmandProcess, 2, "<domain> <elem path>", "Split configurable domain at given associated element path" },
143 /// Configurations
144 { "listConfigurations", &CParameterMgr::listConfigurationsCommmandProcess, 1, "<domain>", "List domain configurations" },
145 { "createConfiguration", &CParameterMgr::createConfigurationCommmandProcess, 2, "<domain> <configuration>", "Create new domain configuration" },
146 { "deleteConfiguration", &CParameterMgr::deleteConfigurationCommmandProcess, 2, "<domain> <configuration>", "Delete domain configuration" },
147 { "renameConfiguration", &CParameterMgr::renameConfigurationCommmandProcess, 3, "<domain> <configuration> <new name>", "Rename domain configuration" },
148 { "saveConfiguration", &CParameterMgr::saveConfigurationCommmandProcess, 2, "<domain> <configuration>", "Save current settings into configuration" },
149 { "restoreConfiguration", &CParameterMgr::restoreConfigurationCommmandProcess, 2, "<domain> <configuration>", "Restore current settings from configuration" },
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100150 { "setElementSequence", &CParameterMgr::setElementSequenceCommmandProcess, 3, "<domain> <configuration> <elem path list>", "Set element application order for configuration" },
Patrick Benavoli63499d42011-10-24 18:50:03 +0200151 { "getElementSequence", &CParameterMgr::getElementSequenceCommmandProcess, 2, "<domain> <configuration>", "Get element application order for configuration" },
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100152 { "setRule", &CParameterMgr::setRuleCommmandProcess, 3, "<domain> <configuration> <rule>", "Set configuration application rule" },
153 { "clearRule", &CParameterMgr::clearRuleCommmandProcess, 2, "<domain> <configuration>", "Clear configuration application rule" },
154 { "getRule", &CParameterMgr::getRuleCommmandProcess, 2, "<domain> <configuration>", "Get configuration application rule" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200155 /// Elements/Parameters
156 { "listElements", &CParameterMgr::listElementsCommmandProcess, 1, "<elem path>|/", "List elements under element at given path or root" },
Patrick Benavoli592ae562011-09-05 16:53:58 +0200157 { "listParameters", &CParameterMgr::listParametersCommmandProcess, 1, "<elem path>|/", "List parameters under element at given path or root" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200158 { "dumpElement", &CParameterMgr::dumpElementCommmandProcess, 1, "<elem path>", "Dump structure and content of element at given path" },
159 { "getElementSize", &CParameterMgr::getElementSizeCommmandProcess, 1, "<elem path>", "Show size of element at given path" },
Patrick Benavoli2ecf9002011-08-31 11:23:24 +0200160 { "showProperties", &CParameterMgr::showPropertiesCommmandProcess, 1, "<elem path>", "Show properties of element at given path" },
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200161 { "getParameter", &CParameterMgr::getParameterCommmandProcess, 1, "<param path>", "Get value for parameter at given path" },
Patrick Benavoli2ecf9002011-08-31 11:23:24 +0200162 { "setParameter", &CParameterMgr::setParameterCommmandProcess, 2, "<param path> <value>", "Set value for parameter at given path" },
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200163 { "listBelongingDomains", &CParameterMgr::listBelongingDomainsCommmandProcess, 1, "<elem path>", "List domain(s) element at given path belongs to" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200164 { "listAssociatedDomains", &CParameterMgr::listAssociatedDomainsCommmandProcess, 1, "<elem path>", "List domain(s) element at given path is associated to" },
165 /// Browse
166 { "listAssociatedElements", &CParameterMgr::listAssociatedElementsCommmandProcess, 0, "", "List element sub-trees associated to at least one configurable domain" },
167 { "listConflictingElements", &CParameterMgr::listConflictingElementsCommmandProcess, 0, "", "List element sub-trees contained in more than one configurable domain" },
168 { "listRogueElements", &CParameterMgr::listRogueElementsCommmandProcess, 0, "", "List element sub-trees owned by no configurable domain" },
169 /// Settings Import/Export
170 { "exportDomainsXML", &CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess, 1, "<file path> ", "Export domains to XML file" },
171 { "importDomainsXML", &CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess, 1, "<file path>", "Import domains from XML file" },
172 { "exportDomainsWithSettingsXML", &CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess, 1, "<file path> ", "Export domains including settings to XML file" },
173 { "importDomainsWithSettingsXML", &CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess, 1, "<file path>", "Import domains including settings from XML file" },
174 { "exportSettings", &CParameterMgr::exportSettingsCommmandProcess, 1, "<file path>", "Export settings to binary file" },
175 { "importSettings", &CParameterMgr::importSettingsCommmandProcess, 1, "<file path>", "Import settings from binary file" }
176};
177// Remote command parsers array Size
Patrick Benavoli592ae562011-09-05 16:53:58 +0200178const uint32_t CParameterMgr::guiNbRemoteCommandParserItems = sizeof(gastRemoteCommandParserItems) / sizeof(gastRemoteCommandParserItems[0]);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200179
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100180CParameterMgr::CParameterMgr(const string& strConfigurationFilePath) :
Patrick Benavoli68a91282011-08-31 11:23:23 +0200181 _bTuningModeIsOn(false),
182 _bValueSpaceIsRaw(false),
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200183 _bOutputRawFormatIsHex(false),
Patrick Benavoli68a91282011-08-31 11:23:23 +0200184 _bAutoSyncOn(true),
185 _pMainParameterBlackboard(new CParameterBlackboard),
186 _pElementLibrarySet(new CElementLibrarySet),
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100187 _strXmlConfigurationFilePath(strConfigurationFilePath),
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100188 _pSubsystemPlugins(NULL),
Patrick Benavoli68a91282011-08-31 11:23:23 +0200189 _uiStructureChecksum(0),
190 _pRemoteProcessorServer(NULL),
191 _uiMaxCommandUsageLength(0),
192 _pLogger(NULL),
193 _uiLogDepth(0)
194{
195 // Tuning Mode Mutex
Patrick Benavoli065264a2011-11-20 15:46:41 +0100196 bzero(&_blackboardMutex, sizeof(_blackboardMutex));
197 pthread_mutex_init(&_blackboardMutex, NULL);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200198
199 // Deal with children
200 addChild(new CParameterFrameworkConfiguration);
201 addChild(new CSelectionCriteria);
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100202 addChild(new CSystemClass);
203 addChild(new CConfigurableDomains);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200204
205 // Feed element library
206 feedElementLibraries();
Patrick Benavoli63499d42011-10-24 18:50:03 +0200207
208 _pCommandHandler = new CCommandHandler(this);
209
210 // Add command parsers
211 uint32_t uiRemoteCommandParserItem;
212
213 for (uiRemoteCommandParserItem = 0; uiRemoteCommandParserItem < guiNbRemoteCommandParserItems; uiRemoteCommandParserItem++) {
214
215 const SRemoteCommandParserItem* pRemoteCommandParserItem = &gastRemoteCommandParserItems[uiRemoteCommandParserItem];
216
217 _pCommandHandler->addCommandParser(pRemoteCommandParserItem->_pcCommandName,
218 pRemoteCommandParserItem->_pfnParser,
219 pRemoteCommandParserItem->_uiMinArgumentCount,
220 pRemoteCommandParserItem->_pcHelp,
221 pRemoteCommandParserItem->_pcDescription);
222 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100223
224 // Configuration file folder
225 uint32_t uiSlashPos = _strXmlConfigurationFilePath.rfind('/', -1);
226
227 assert(uiSlashPos != (uint32_t)-1);
228
229 _strXmlConfigurationFolderPath = _strXmlConfigurationFilePath.substr(0, uiSlashPos);
230
231 // Schema absolute folder location
232 _strSchemaFolderLocation = _strXmlConfigurationFolderPath + "/" + gacSystemSchemasSubFolder;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200233}
234
235CParameterMgr::~CParameterMgr()
236{
237 // Children
238 delete _pRemoteProcessorServer;
Frederic Boisnard31242302012-04-26 17:07:34 +0200239 delete _pCommandHandler;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200240 delete _pMainParameterBlackboard;
241 delete _pElementLibrarySet;
242
243 // Tuning Mode Mutex
Patrick Benavoli065264a2011-11-20 15:46:41 +0100244 pthread_mutex_destroy(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200245}
246
247string CParameterMgr::getKind() const
248{
249 return "ParameterMgr";
250}
251
252// Logging
253void CParameterMgr::setLogger(CParameterMgr::ILogger* pLogger)
254{
255 _pLogger = pLogger;
256}
257
258// Logging
259void CParameterMgr::doLog(const string& strLog) const
260{
261 if (_pLogger) {
262
263 // Nest
264 string strIndent;
265
266 // Level
267 uint32_t uiNbIndents = _uiLogDepth;
268
269 while (uiNbIndents--) {
270
271 strIndent += " ";
272 }
273
274 // Log
275 _pLogger->log(strIndent + strLog);
276 }
277}
278
279void CParameterMgr::nestLog() const
280{
Patrick Benavoli592ae562011-09-05 16:53:58 +0200281 _uiLogDepth++;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200282}
283
284void CParameterMgr::unnestLog() const
285{
Patrick Benavoli592ae562011-09-05 16:53:58 +0200286 _uiLogDepth--;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200287}
288
Patrick Benavoli63499d42011-10-24 18:50:03 +0200289// Version
290string CParameterMgr::getVersion() const
291{
292 string strVersion;
293
294 // Major
295 strVersion = toString(guiEditionMajor) + ".";
296 // Minor
297 strVersion += toString(guiEditionMinor) + ".";
298 // Revision
299 strVersion += toString(guiRevision);
300
301 return strVersion;
302}
303
Patrick Benavoli68a91282011-08-31 11:23:23 +0200304bool CParameterMgr::load(string& strError)
305{
306 CAutoLog autoLog(this, "Loading");
307
308 // Load Framework configuration
309 if (!loadFrameworkConfiguration(strError)) {
310
311 return false;
312 }
313
314 // Load subsystems
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100315 if (!getSystemClass()->loadSubsystems(strError, _pSubsystemPlugins)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200316
317 return false;
318 }
319
320 // Load structure
321 if (!loadStructure(strError)) {
322
323 return false;
324 }
325
326 // Load settings
327 if (!loadSettings(strError)) {
328
329 return false;
330 }
331
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200332 // Back synchronization for areas in parameter blackboard not covered by any domain
333 CBackSynchronizer* pBackSynchronizer = createBackSynchronizer(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200334
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200335 log("Main blackboard back synchronization");
336
337 // Back-synchronize
338 if (!pBackSynchronizer->sync()) {
339 // Get rid of back synchronizer
340 delete pBackSynchronizer;
341
342 strError = "Main blackboard back synchronization failed: " + strError;
343
344 return false;
345 }
346 // Get rif of back synchronizer
347 delete pBackSynchronizer;
348
349 // We're done loading the settings and back synchronizing
350 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
351
352 // We need to ensure all domains are valid
353 pConfigurableDomains->validate(_pMainParameterBlackboard);
354
355 // Ensure application of currently selected configurations
356 // Force-apply configurations
357 if (!pConfigurableDomains->apply(_pMainParameterBlackboard, true, strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200358
359 return false;
360 }
361
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200362 // Start remote processor server if appropriate
363 return handleRemoteProcessingInterface(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200364}
365
366bool CParameterMgr::loadFrameworkConfiguration(string& strError)
367{
368 CAutoLog autoLog(this, "Loading framework configuration");
369
Patrick Benavoli68a91282011-08-31 11:23:23 +0200370 // Parse Structure XML file
371 CXmlElementSerializingContext elementSerializingContext(strError);
372
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100373 if (!xmlParse(elementSerializingContext, getFrameworkConfiguration(), _strXmlConfigurationFilePath, _strXmlConfigurationFolderPath, EFrameworkConfigurationLibrary)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200374
375 return false;
376 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100377 // Set class name to system class and configurable domains
378 getSystemClass()->setName(getConstFrameworkConfiguration()->getSystemClassName());
379 getConfigurableDomains()->setName(getConstFrameworkConfiguration()->getSystemClassName());
380
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100381 // Get subsystem plugins elements
382 _pSubsystemPlugins = static_cast<const CSubsystemPlugins*>(getConstFrameworkConfiguration()->findChild("SubsystemPlugins"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200383
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100384 if (!_pSubsystemPlugins) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200385
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100386 strError = "Parameter Framework Configuration: couldn't find SubsystemPlugins element";
Patrick Benavoli68a91282011-08-31 11:23:23 +0200387
388 return false;
389 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200390
Patrick Benavoli68a91282011-08-31 11:23:23 +0200391 // Log tuning availability
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100392 log("Tuning %s", getConstFrameworkConfiguration()->isTuningAllowed() ? "allowed" : "prohibited");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200393
394 return true;
395}
396
397bool CParameterMgr::loadStructure(string& strError)
398{
399 // Retrieve system to load structure to
400 CSystemClass* pSystemClass = getSystemClass();
401
402 CAutoLog autoLog(this, "Loading " + pSystemClass->getName() + " system class structure");
403
404 // Get structure description element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100405 const CFrameworkConfigurationLocation* pStructureDescriptionFileLocation = static_cast<const CFrameworkConfigurationLocation*>(getConstFrameworkConfiguration()->findChildOfKind("StructureDescriptionFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200406
407 if (!pStructureDescriptionFileLocation) {
408
409 strError = "No StructureDescriptionFileLocation element found for SystemClass " + pSystemClass->getName();
410
411 return false;
412 }
413
414 // Get Xml structure folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100415 string strXmlStructureFolder = pStructureDescriptionFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200416
417 // Get Xml structure file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100418 string strXmlStructureFilePath = pStructureDescriptionFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200419
420 // Parse Structure XML file
421 CXmlParameterSerializingContext parameterBuildContext(strError);
422
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200423 log("Importing system structure from file %s", strXmlStructureFilePath.c_str());
424
Patrick Benavoli68a91282011-08-31 11:23:23 +0200425 if (!xmlParse(parameterBuildContext, pSystemClass, strXmlStructureFilePath, strXmlStructureFolder, EParameterCreationLibrary)) {
426
427 return false;
428 }
429
430 // Initialize offsets
431 pSystemClass->setOffset(0);
432
433 // Initialize main blackboard's size
434 _pMainParameterBlackboard->setSize(pSystemClass->getFootPrint());
435
436 return true;
437}
438
439bool CParameterMgr::loadSettings(string& strError)
440{
441 CAutoLog autoLog(this, "Loading settings");
442
443 // Get settings configuration element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100444 const CFrameworkConfigurationGroup* pParameterConfigurationGroup = static_cast<const CFrameworkConfigurationGroup*>(getConstFrameworkConfiguration()->findChildOfKind("SettingsConfiguration"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200445
446 if (!pParameterConfigurationGroup) {
447
448 // No settings to load
449
450 return true;
451 }
452 // Get binary settings file location
453 const CFrameworkConfigurationLocation* pBinarySettingsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("BinarySettingsFileLocation"));
454
455 string strXmlBinarySettingsFilePath;
456
457 if (pBinarySettingsFileLocation) {
458
459 // Get Xml binary settings file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100460 strXmlBinarySettingsFilePath = pBinarySettingsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200461 }
462
463 // Get configurable domains element
464 const CFrameworkConfigurationLocation* pConfigurableDomainsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("ConfigurableDomainsFileLocation"));
465
466 if (!pConfigurableDomainsFileLocation) {
467
468 strError = "No ConfigurableDomainsFileLocation element found for SystemClass " + getSystemClass()->getName();
469
470 return false;
471 }
472 // Get destination root element
473 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
474
475 // Get Xml configuration domains file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100476 string strXmlConfigurationDomainsFilePath = pConfigurableDomainsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200477
478 // Get Xml configuration domains folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100479 string strXmlConfigurationDomainsFolder = pConfigurableDomainsFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200480
481 // Parse configuration domains XML file (ask to read settings from XML file if they are not provided as binary)
482 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, !pBinarySettingsFileLocation);
483
484 // Selection criteria definition for rule creation
485 xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
486
Patrick Benavoli63499d42011-10-24 18:50:03 +0200487 // Auto validation of configurations if no binary settings provided
488 xmlDomainSerializingContext.setAutoValidationRequired(!pBinarySettingsFileLocation);
489
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200490 log("Importing configurable domains from file %s %s settings", strXmlConfigurationDomainsFilePath.c_str(), pBinarySettingsFileLocation ? "without" : "with");
491
Patrick Benavoli68a91282011-08-31 11:23:23 +0200492 // Do parse
493 if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strXmlConfigurationDomainsFilePath, strXmlConfigurationDomainsFolder, EParameterConfigurationLibrary, "SystemClassName")) {
494
495 return false;
496 }
497 // We have loaded the whole system structure, compute checksum
498 const CSystemClass* pSystemClass = getConstSystemClass();
499 _uiStructureChecksum = pSystemClass->computeStructureChecksum() + getConfigurableDomains()->computeStructureChecksum() + getSelectionCriteria()->computeStructureChecksum();
500
501 // Load binary settings if any provided
502 if (pBinarySettingsFileLocation && !pConfigurableDomains->serializeSettings(strXmlBinarySettingsFilePath, false, _uiStructureChecksum, strError)) {
503
504 return false;
505 }
506
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200507 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200508}
509
510// XML parsing
511bool CParameterMgr::xmlParse(CXmlElementSerializingContext& elementSerializingContext, CElement* pRootElement, const string& strXmlFilePath, const string& strXmlFolder, CParameterMgr::ElementLibrary eElementLibrary, const string& strNameAttrituteName)
512{
513 // Init serializing context
514 elementSerializingContext.set(_pElementLibrarySet->getElementLibrary(eElementLibrary), strXmlFolder, _strSchemaFolderLocation);
515
516 // Get Schema file associated to root element
517 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pRootElement->getKind() + ".xsd";
518
519 // Parse Structure XML file
520 CXmlParser parser(strXmlFilePath, strXmlSchemaFilePath, pRootElement->getKind(), elementSerializingContext);
521
522 if (!parser.open()) {
523
524 return false;
525 }
526
527 // Check Root element name attribute (if any)
528 string strRootElementName = parser.getRootElementAttributeString(strNameAttrituteName);
529
530 if (!strRootElementName.empty() && strRootElementName != pRootElement->getName()) {
531
532 elementSerializingContext.setError("Error: Wrong XML structure file " + strXmlFilePath);
533 elementSerializingContext.appendLineToError(pRootElement->getKind() + " element " + pRootElement->getName() + " mismatches expected " + pRootElement->getKind() + " type " + pRootElement->getName());
534
535 return false;
536 }
537
538 // Start clean
539 pRootElement->clean();
540
541 // Parse
542 if (!parser.parse(pRootElement)) {
543
544 // Cleanup
545 pRootElement->clean();
546
547 return false;
548 }
549
550 // Close parser
551 if (!parser.close()) {
552
553 return false;
554 }
555
556 return true;
557}
558
559// Init
560bool CParameterMgr::init(string& strError)
561{
562 return base::init(strError);
563}
564
565// Selection criteria interface
566CSelectionCriterionType* CParameterMgr::createSelectionCriterionType(bool bIsInclusive)
567{
568 // Propagate
569 return getSelectionCriteria()->createSelectionCriterionType(bIsInclusive);
570}
571
572CSelectionCriterion* CParameterMgr::createSelectionCriterion(const string& strName, const CSelectionCriterionType* pSelectionCriterionType)
573{
574 // Propagate
575 return getSelectionCriteria()->createSelectionCriterion(strName, pSelectionCriterionType);
576}
577
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200578// Selection criterion retrieval
579CSelectionCriterion* CParameterMgr::getSelectionCriterion(const string& strName)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200580{
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200581 // Propagate
582 return getSelectionCriteria()->getSelectionCriterion(strName);
583}
584
585// Selection criteria changed event
586bool CParameterMgr::applyConfigurations(string& strError)
587{
588 CAutoLog autoLog(this, "Configuration application request");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200589
590 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +0100591 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200592
593 if (!_bTuningModeIsOn) {
594
595 // Apply configuration(s)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200596 if (!getConfigurableDomains()->apply(_pMainParameterBlackboard, false, strError)) {
597
598 log("Failed to apply configurations!");
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200599
600 return false;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200601 }
602 }
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200603
604 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200605}
606
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200607// Dynamic parameter handling
Patrick Benavoli065264a2011-11-20 15:46:41 +0100608CParameterHandle* CParameterMgr::createParameterHandle(const string& strPath, string& strError)
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200609{
Patrick Benavoli065264a2011-11-20 15:46:41 +0100610 CPathNavigator pathNavigator(strPath);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200611
Patrick Benavoli065264a2011-11-20 15:46:41 +0100612 // Nagivate through system class
613 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
614
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100615 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100616 }
617
618 // Find element
619 const CElement* pElement = getConstSystemClass()->findDescendant(pathNavigator);
620
621 if (!pElement) {
622
623 strError = "Path not found";
624
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100625 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100626 }
627
628 // Check found element is a parameter
629 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pElement);
630
631 if (!pConfigurableElement->isParameter()) {
632
633 // Element is not parameter
634 strError = "Not a parameter";
635
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100636 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100637 }
638
639 // Convert as parameter and return new handle
640 return new CParameterHandle(static_cast<const CBaseParameter*>(pElement), this);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200641}
642
Patrick Benavoli68a91282011-08-31 11:23:23 +0200643/////////////////// Remote command parsers
Patrick Benavoli592ae562011-09-05 16:53:58 +0200644/// Version
Patrick Benavoli63499d42011-10-24 18:50:03 +0200645CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::versionCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli592ae562011-09-05 16:53:58 +0200646{
647 (void)remoteCommand;
648
Patrick Benavoli63499d42011-10-24 18:50:03 +0200649 // Show version
650 strResult = getVersion();
Patrick Benavoli592ae562011-09-05 16:53:58 +0200651
Patrick Benavoli63499d42011-10-24 18:50:03 +0200652 return CCommandHandler::ESucceeded;
Patrick Benavoli592ae562011-09-05 16:53:58 +0200653}
654
Patrick Benavoli68a91282011-08-31 11:23:23 +0200655/// Status
Patrick Benavoli63499d42011-10-24 18:50:03 +0200656CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::statusCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200657{
658 (void)remoteCommand;
659 // System class
660 const CSystemClass* pSystemClass = getSystemClass();
661
Patrick Benavoli68a91282011-08-31 11:23:23 +0200662 // Show status
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200663 /// General section
664 appendTitle(strResult, "General:");
665 // System class
Patrick Benavoli68a91282011-08-31 11:23:23 +0200666 strResult += "System Class: ";
667 strResult += pSystemClass->getName();
668 strResult += "\n";
669
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200670 // Tuning mode
Patrick Benavoli68a91282011-08-31 11:23:23 +0200671 strResult += "Tuning Mode: ";
672 strResult += tuningModeOn() ? "on" : "off";
673 strResult += "\n";
674
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200675 // Value space
Patrick Benavoli68a91282011-08-31 11:23:23 +0200676 strResult += "Value Space: ";
677 strResult += valueSpaceIsRaw() ? "raw" : "real";
678 strResult += "\n";
679
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200680 // Output raw format
681 strResult += "Output Raw Format: ";
682 strResult += outputRawFormatIsHex() ? "hex" : "dec";
683 strResult += "\n";
684
685 // Auto Sync
Patrick Benavoli68a91282011-08-31 11:23:23 +0200686 strResult += "Auto Sync: ";
687 strResult += autoSyncOn() ? "on" : "off";
688 strResult += "\n";
689
690 /// Subsystem list
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200691 appendTitle(strResult, "Subsystems:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200692 string strSubsystemList;
693 pSystemClass->listChildrenPaths(strSubsystemList);
694 strResult += strSubsystemList;
695
696 /// Last applied configurations
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200697 appendTitle(strResult, "Last applied configurations:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200698 string strLastAppliedConfigurations;
699 getConfigurableDomains()->listLastAppliedConfigurations(strLastAppliedConfigurations);
700 strResult += strLastAppliedConfigurations;
701
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200702 /// Criteria states
703 appendTitle(strResult, "Selection criteria:");
704 string strSelectionCriteria;
705 getSelectionCriteria()->listSelectionCriteria(strSelectionCriteria, false);
706 strResult += strSelectionCriteria;
707
Patrick Benavoli63499d42011-10-24 18:50:03 +0200708 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200709}
710
711/// Tuning Mode
Patrick Benavoli63499d42011-10-24 18:50:03 +0200712CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200713{
714 if (remoteCommand.getArgument(0) == "on") {
715
716 if (setTuningMode(true, strResult)) {
717
Patrick Benavoli63499d42011-10-24 18:50:03 +0200718 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200719 }
720 } else if (remoteCommand.getArgument(0) == "off") {
721
722 if (setTuningMode(false, strResult)) {
723
Patrick Benavoli63499d42011-10-24 18:50:03 +0200724 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200725 }
726 } else {
727 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200728 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200729 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200730 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200731}
732
Patrick Benavoli63499d42011-10-24 18:50:03 +0200733CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200734{
735 (void)remoteCommand;
736
737 strResult = tuningModeOn() ? "on" : "off";
738
Patrick Benavoli63499d42011-10-24 18:50:03 +0200739 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200740}
741
742/// Value Space
Patrick Benavoli63499d42011-10-24 18:50:03 +0200743CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200744{
745 (void)strResult;
746
747 if (remoteCommand.getArgument(0) == "raw") {
748
749 setValueSpace(true);
750
Patrick Benavoli63499d42011-10-24 18:50:03 +0200751 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200752
753 } else if (remoteCommand.getArgument(0) == "real") {
754
755 setValueSpace(false);
756
Patrick Benavoli63499d42011-10-24 18:50:03 +0200757 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200758
759 } else {
760 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200761 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200762 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200763 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200764}
765
Patrick Benavoli63499d42011-10-24 18:50:03 +0200766CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200767{
768 (void)remoteCommand;
769
770 strResult = valueSpaceIsRaw() ? "raw" : "real";
771
Patrick Benavoli63499d42011-10-24 18:50:03 +0200772 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200773}
774
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200775/// Output Raw Format
Patrick Benavoli63499d42011-10-24 18:50:03 +0200776CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200777{
778 (void)strResult;
779
780 if (remoteCommand.getArgument(0) == "hex") {
781
782 setOutputRawFormat(true);
783
Patrick Benavoli63499d42011-10-24 18:50:03 +0200784 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200785
786 } else if (remoteCommand.getArgument(0) == "dec") {
787
788 setOutputRawFormat(false);
789
Patrick Benavoli63499d42011-10-24 18:50:03 +0200790 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200791
792 } else {
793 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200794 return CCommandHandler::EShowUsage;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200795 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200796 return CCommandHandler::EFailed;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200797}
798
Patrick Benavoli63499d42011-10-24 18:50:03 +0200799CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200800{
801 (void)remoteCommand;
802
803 strResult = outputRawFormatIsHex() ? "hex" : "dec";
804
Patrick Benavoli63499d42011-10-24 18:50:03 +0200805 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200806}
807
Patrick Benavoli68a91282011-08-31 11:23:23 +0200808/// Sync
Patrick Benavoli63499d42011-10-24 18:50:03 +0200809CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200810{
811 if (remoteCommand.getArgument(0) == "on") {
812
813 if (setAutoSync(true, strResult)) {
814
Patrick Benavoli63499d42011-10-24 18:50:03 +0200815 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200816 }
817 } else if (remoteCommand.getArgument(0) == "off") {
818
819 if (setAutoSync(false, strResult)) {
820
Patrick Benavoli63499d42011-10-24 18:50:03 +0200821 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200822 }
823 } else {
824 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200825 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200826 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200827 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200828}
829
Patrick Benavoli63499d42011-10-24 18:50:03 +0200830CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200831{
832 (void)remoteCommand;
833
834 strResult = autoSyncOn() ? "on" : "off";
835
Patrick Benavoli63499d42011-10-24 18:50:03 +0200836 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200837}
838
Patrick Benavoli63499d42011-10-24 18:50:03 +0200839CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::syncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200840{
841 (void)remoteCommand;
842
Patrick Benavoli63499d42011-10-24 18:50:03 +0200843 return sync(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200844}
845
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200846/// Criteria
Patrick Benavoli63499d42011-10-24 18:50:03 +0200847CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listCriteriaCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200848{
849 (void)remoteCommand;
850
851 getSelectionCriteria()->listSelectionCriteria(strResult, true);
852
Patrick Benavoli63499d42011-10-24 18:50:03 +0200853 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200854}
Patrick Benavoli68a91282011-08-31 11:23:23 +0200855
856/// Domains
Patrick Benavoli63499d42011-10-24 18:50:03 +0200857CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200858{
859 (void)remoteCommand;
860
Patrick Benavoli63499d42011-10-24 18:50:03 +0200861 getConfigurableDomains()->listDomains(strResult);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200862
Patrick Benavoli63499d42011-10-24 18:50:03 +0200863 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200864}
865
Patrick Benavoli63499d42011-10-24 18:50:03 +0200866CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200867{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200868 return createDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200869}
870
Patrick Benavoli63499d42011-10-24 18:50:03 +0200871CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200872{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200873 return deleteDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200874}
875
Kevin Rocard170f0a42012-06-18 13:56:05 +0200876CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteAllDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
877{
878 (void)remoteCommand;
879
880 return deleteAllDomains(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
881}
882
Patrick Benavoli63499d42011-10-24 18:50:03 +0200883CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200884{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200885 return getConfigurableDomains()->renameDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200886}
887
Patrick Benavoli63499d42011-10-24 18:50:03 +0200888CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200889{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200890 // Check tuning mode
891 if (!checkTuningModeOn(strResult)) {
892
893 return CCommandHandler::EFailed;
894 }
895
896 // Set property
897 bool bSequenceAware;
898
899 if (remoteCommand.getArgument(1) == "true") {
900
901 bSequenceAware = true;
902
903 } else if (remoteCommand.getArgument(1) == "false") {
904
905 bSequenceAware = false;
906
907 } else {
908 // Show usage
909 return CCommandHandler::EShowUsage;
910 }
911
912 return getConfigurableDomains()->setSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200913}
914
Patrick Benavoli63499d42011-10-24 18:50:03 +0200915CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200916{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200917 // Get property
918 bool bSequenceAware;
919
920 if (!getConfigurableDomains()->getSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult)) {
921
922 return CCommandHandler::EFailed;
923 }
924
925 strResult = bSequenceAware ? "true" : "false";
926
927 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200928}
929
Patrick Benavoli63499d42011-10-24 18:50:03 +0200930CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200931{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200932 return getConfigurableDomains()->listDomainElements(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200933}
934
Patrick Benavoli63499d42011-10-24 18:50:03 +0200935CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::addElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200936{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200937 return addConfigurableElementToDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
938}
939
940CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::removeElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
941{
942 return removeConfigurableElementFromDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
943}
944
945CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::splitDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
946{
947 return split(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200948}
949
950/// Configurations
Patrick Benavoli63499d42011-10-24 18:50:03 +0200951CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConfigurationsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200952{
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100953 return getConstConfigurableDomains()->listConfigurations(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
954}
955
956CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
957{
958 (void)remoteCommand;
959
960 // Dummy error context
961 string strError;
962 CErrorContext errorContext(strError);
963
964 // Dump
965 getConstConfigurableDomains()->dumpContent(strResult, errorContext);
966
967 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200968}
969
Patrick Benavoli63499d42011-10-24 18:50:03 +0200970CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200971{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200972 return createConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200973}
974
Patrick Benavoli63499d42011-10-24 18:50:03 +0200975CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200976{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200977 return deleteConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200978}
979
Patrick Benavoli63499d42011-10-24 18:50:03 +0200980CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200981{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200982 return getConfigurableDomains()->renameConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200983}
984
Patrick Benavoli63499d42011-10-24 18:50:03 +0200985CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::saveConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200986{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200987 return saveConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200988}
989
Patrick Benavoli63499d42011-10-24 18:50:03 +0200990CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::restoreConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200991{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200992 return restoreConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
993}
994
995CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
996{
997 // Check tuning mode
998 if (!checkTuningModeOn(strResult)) {
999
1000 return CCommandHandler::EFailed;
1001 }
1002
1003 // Build configurable element path list
1004 vector<string> astrNewElementSequence;
1005
1006 uint32_t uiArgument;
1007
1008 for (uiArgument = 2; uiArgument < remoteCommand.getArgumentCount(); uiArgument++) {
1009
1010 astrNewElementSequence.push_back(remoteCommand.getArgument(uiArgument));
1011 }
1012
1013 // Delegate to configurable domains
1014 return getConfigurableDomains()->setElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), astrNewElementSequence, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1015}
1016
1017CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1018{
1019 // Delegate to configurable domains
1020 return getConfigurableDomains()->getElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001021}
1022
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001023CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1024{
1025 // Delegate to configurable domains
1026 return getConfigurableDomains()->setApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.packArguments(2, remoteCommand.getArgumentCount() - 2), getConstSelectionCriteria()->getSelectionCriteriaDefinition(), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1027}
1028
1029CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::clearRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1030{
1031 // Delegate to configurable domains
1032 return getConfigurableDomains()->clearApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1033}
1034
1035CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1036{
1037 // Delegate to configurable domains
1038 return getConfigurableDomains()->getApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
1039}
1040
Patrick Benavoli68a91282011-08-31 11:23:23 +02001041/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001042CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001043{
1044 CElementLocator elementLocator(getSystemClass(), false);
1045
1046 CElement* pLocatedElement = NULL;
1047
1048 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1049
Patrick Benavoli63499d42011-10-24 18:50:03 +02001050 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001051 }
1052
1053 strResult = string("\n");
1054
1055 if (!pLocatedElement) {
1056
1057 // List from root folder
1058
1059 // Return system class qualified name
1060 pLocatedElement = getSystemClass();
1061 }
1062
1063 // Return sub-elements
1064 strResult += pLocatedElement->listQualifiedPaths(false);
1065
Patrick Benavoli63499d42011-10-24 18:50:03 +02001066 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001067}
1068
1069/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001070CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listParametersCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001071{
1072 CElementLocator elementLocator(getSystemClass(), false);
1073
1074 CElement* pLocatedElement = NULL;
1075
1076 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1077
Patrick Benavoli63499d42011-10-24 18:50:03 +02001078 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001079 }
1080
1081 strResult = string("\n");
1082
1083 if (!pLocatedElement) {
1084
1085 // List from root folder
1086
1087 // Return system class qualified name
1088 pLocatedElement = getSystemClass();
1089 }
1090
1091 // Return sub-elements
1092 strResult += pLocatedElement->listQualifiedPaths(true);
1093
Patrick Benavoli63499d42011-10-24 18:50:03 +02001094 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001095}
1096
Patrick Benavoli63499d42011-10-24 18:50:03 +02001097CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001098{
1099 CElementLocator elementLocator(getSystemClass());
1100
1101 CElement* pLocatedElement = NULL;
1102
1103 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1104
Patrick Benavoli63499d42011-10-24 18:50:03 +02001105 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001106 }
1107
1108 string strError;
1109
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001110 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001111
1112 // Dump elements
1113 pLocatedElement->dumpContent(strResult, parameterAccessContext);
1114
Patrick Benavoli63499d42011-10-24 18:50:03 +02001115 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001116}
1117
Patrick Benavoli63499d42011-10-24 18:50:03 +02001118CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSizeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001119{
1120 CElementLocator elementLocator(getSystemClass());
1121
1122 CElement* pLocatedElement = NULL;
1123
1124 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1125
Patrick Benavoli63499d42011-10-24 18:50:03 +02001126 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001127 }
1128
1129 // Converted to actual sizable element
1130 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1131
1132 // Get size as string
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001133 strResult = pConfigurableElement->getFootprintAsString();
Patrick Benavoli68a91282011-08-31 11:23:23 +02001134
Patrick Benavoli63499d42011-10-24 18:50:03 +02001135 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001136}
1137
Patrick Benavoli63499d42011-10-24 18:50:03 +02001138CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showPropertiesCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001139{
1140 CElementLocator elementLocator(getSystemClass());
1141
1142 CElement* pLocatedElement = NULL;
1143
1144 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1145
Patrick Benavoli63499d42011-10-24 18:50:03 +02001146 return CCommandHandler::EFailed;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001147 }
1148
1149 // Convert element
1150 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1151
1152 // Return element properties
1153 pConfigurableElement->showProperties(strResult);
1154
Patrick Benavoli63499d42011-10-24 18:50:03 +02001155 return CCommandHandler::ESucceeded;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001156}
1157
Patrick Benavoli63499d42011-10-24 18:50:03 +02001158CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001159{
1160 string strValue;
1161
Patrick Benavoli065264a2011-11-20 15:46:41 +01001162 if (!accessValue(remoteCommand.getArgument(0), strValue, false, strResult)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001163
Patrick Benavoli63499d42011-10-24 18:50:03 +02001164 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001165 }
1166 // Succeeded
1167 strResult = strValue;
1168
Patrick Benavoli63499d42011-10-24 18:50:03 +02001169 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001170}
1171
Patrick Benavoli63499d42011-10-24 18:50:03 +02001172CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001173{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001174 // Check tuning mode
1175 if (!checkTuningModeOn(strResult)) {
1176
1177 return CCommandHandler::EFailed;
1178 }
1179 // Get value to set
1180 string strValue = remoteCommand.packArguments(1, remoteCommand.getArgumentCount() - 1);
1181
1182 return accessValue(remoteCommand.getArgument(0), strValue, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001183}
1184
Patrick Benavoli63499d42011-10-24 18:50:03 +02001185CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listBelongingDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001186{
1187 CElementLocator elementLocator(getSystemClass());
1188
1189 CElement* pLocatedElement = NULL;
1190
1191 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1192
Patrick Benavoli63499d42011-10-24 18:50:03 +02001193 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001194 }
1195
1196 // Convert element
1197 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1198
1199 // Return element belonging domains
1200 pConfigurableElement->listBelongingDomains(strResult);
1201
Patrick Benavoli63499d42011-10-24 18:50:03 +02001202 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001203}
1204
Patrick Benavoli63499d42011-10-24 18:50:03 +02001205CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001206{
1207 CElementLocator elementLocator(getSystemClass());
1208
1209 CElement* pLocatedElement = NULL;
1210
1211 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1212
Patrick Benavoli63499d42011-10-24 18:50:03 +02001213 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001214 }
1215
1216 // Convert element
1217 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1218
1219 // Return element belonging domains
1220 pConfigurableElement->listAssociatedDomains(strResult);
1221
Patrick Benavoli63499d42011-10-24 18:50:03 +02001222 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001223}
1224
Patrick Benavoli63499d42011-10-24 18:50:03 +02001225CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001226{
1227 (void)remoteCommand;
1228
1229 getConfigurableDomains()->listAssociatedElements(strResult);
1230
Patrick Benavoli63499d42011-10-24 18:50:03 +02001231 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001232}
1233
Patrick Benavoli63499d42011-10-24 18:50:03 +02001234CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConflictingElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001235{
1236 (void)remoteCommand;
1237
1238 getConfigurableDomains()->listConflictingElements(strResult);
1239
Patrick Benavoli63499d42011-10-24 18:50:03 +02001240 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001241}
1242
Patrick Benavoli63499d42011-10-24 18:50:03 +02001243CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listRogueElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001244{
1245 (void)remoteCommand;
1246
1247 getSystemClass()->listRogueElements(strResult);
1248
Patrick Benavoli63499d42011-10-24 18:50:03 +02001249 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001250}
1251
1252/// Settings Import/Export
Patrick Benavoli63499d42011-10-24 18:50:03 +02001253CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001254{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001255 return exportDomainsXml(remoteCommand.getArgument(0), false, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001256}
1257
Patrick Benavoli63499d42011-10-24 18:50:03 +02001258CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001259{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001260 return importDomainsXml(remoteCommand.getArgument(0), false, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001261}
1262
Patrick Benavoli63499d42011-10-24 18:50:03 +02001263CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001264{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001265 return exportDomainsXml(remoteCommand.getArgument(0), true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001266}
1267
Patrick Benavoli63499d42011-10-24 18:50:03 +02001268CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001269{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001270 return importDomainsXml(remoteCommand.getArgument(0), true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001271}
1272
Patrick Benavoli63499d42011-10-24 18:50:03 +02001273CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001274{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001275 return exportDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001276}
1277
Patrick Benavoli63499d42011-10-24 18:50:03 +02001278CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001279{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001280 return importDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001281}
1282
1283// User set/get parameters
Patrick Benavoli065264a2011-11-20 15:46:41 +01001284bool CParameterMgr::accessValue(const string& strPath, string& strValue, bool bSet, string& strError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001285{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001286 // Lock state
1287 CAutoLock autoLock(&_blackboardMutex);
1288
1289 CPathNavigator pathNavigator(strPath);
1290
1291 // Nagivate through system class
1292 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001293
1294 return false;
1295 }
1296
Patrick Benavoli065264a2011-11-20 15:46:41 +01001297 // Define context
1298 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001299
Patrick Benavoli68808c62012-02-02 17:12:41 +01001300 // Auto Sync
1301 if (bSet) {
1302
1303 parameterAccessContext.setAutoSync(_bAutoSyncOn);
1304 }
1305
Patrick Benavoli065264a2011-11-20 15:46:41 +01001306 // Do the get
1307 return getConstSystemClass()->accessValue(pathNavigator, strValue, bSet, parameterAccessContext);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001308}
1309
1310// Tuning mode
1311bool CParameterMgr::setTuningMode(bool bOn, string& strError)
1312{
1313 // Tuning allowed?
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001314 if (bOn && !getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001315
1316 strError = "Tuning prohibited";
1317
1318 return false;
1319 }
1320 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +01001321 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001322
1323 // Warn domains about exiting tuning mode
1324 if (!bOn && _bTuningModeIsOn) {
1325
1326 // Ensure application of currently selected configurations
Patrick Benavoli1387bda2011-08-31 11:23:24 +02001327 // Force-apply configurations
Patrick Benavoli68a91282011-08-31 11:23:23 +02001328 if (!getConfigurableDomains()->apply(_pMainParameterBlackboard, true, strError)) {
1329
1330 return false;
1331 }
1332 // Turn auto sync back on
1333 _bAutoSyncOn = true;
1334 }
1335
1336 // Store
1337 _bTuningModeIsOn = bOn;
1338
Patrick Benavoli68a91282011-08-31 11:23:23 +02001339 return true;
1340}
1341
1342bool CParameterMgr::tuningModeOn() const
1343{
1344 return _bTuningModeIsOn;
1345}
1346
1347// Current value space for user set/get value interpretation
1348void CParameterMgr::setValueSpace(bool bIsRaw)
1349{
1350 _bValueSpaceIsRaw = bIsRaw;
1351}
1352
1353bool CParameterMgr::valueSpaceIsRaw()
1354{
1355 return _bValueSpaceIsRaw;
1356}
1357
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001358// Current Output Raw Format for user get value interpretation
1359void CParameterMgr::setOutputRawFormat(bool bIsHex)
1360{
1361 _bOutputRawFormatIsHex = bIsHex;
1362}
1363
1364bool CParameterMgr::outputRawFormatIsHex()
1365{
1366 return _bOutputRawFormatIsHex;
1367}
1368
Patrick Benavoli68a91282011-08-31 11:23:23 +02001369/// Sync
1370// Automatic hardware synchronization control (during tuning session)
1371bool CParameterMgr::setAutoSync(bool bAutoSyncOn, string& strError)
1372{
1373 // Check tuning mode
1374 if (!checkTuningModeOn(strError)) {
1375
1376 return false;
1377 }
1378 // Warn domains about turning auto sync back on
1379 if (bAutoSyncOn && !_bAutoSyncOn) {
1380
Patrick Benavoli592ae562011-09-05 16:53:58 +02001381 // Do the synchronization at system class level (could be optimized by keeping track of all modified parameters)
1382 if (!sync(strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001383
1384 return false;
1385 }
1386 }
1387
1388 // Set Auto sync
1389 _bAutoSyncOn = bAutoSyncOn;
1390
1391 return true;
1392}
1393
1394bool CParameterMgr::autoSyncOn() const
1395{
1396 return _bAutoSyncOn;
1397}
1398
1399// Manual hardware synchronization control (during tuning session)
1400bool CParameterMgr::sync(string& strError)
1401{
1402 // Check tuning mode
1403 if (!checkTuningModeOn(strError)) {
1404
1405 return false;
1406 }
1407 // Warn domains about turning auto sync back on
1408 if (_bAutoSyncOn) {
1409
1410 strError = "Feature unavailable when Auto Sync is on";
1411
1412 return false;
1413 }
1414
1415 // Get syncer set
1416 CSyncerSet syncerSet;
1417 // ... from system class
1418 getConstSystemClass()->fillSyncerSet(syncerSet);
1419 // Sync
1420 return syncerSet.sync(*_pMainParameterBlackboard, false, strError);
1421}
1422
1423// Content dump
1424void CParameterMgr::logStructureContent(string& strContent) const
1425{
1426 string strError;
1427
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001428 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001429
1430 dumpContent(strContent, parameterAccessContext);
1431}
1432
1433// Configuration/Domains handling
1434bool CParameterMgr::createDomain(const string& strName, string& strError)
1435{
1436 // Check tuning mode
1437 if (!checkTuningModeOn(strError)) {
1438
1439 return false;
1440 }
1441
1442 // Delegate to configurable domains
1443 return getConfigurableDomains()->createDomain(strName, strError);
1444}
1445
1446bool CParameterMgr::deleteDomain(const string& strName, string& strError)
1447{
1448 // Check tuning mode
1449 if (!checkTuningModeOn(strError)) {
1450
1451 return false;
1452 }
1453
1454 // Delegate to configurable domains
1455 return getConfigurableDomains()->deleteDomain(strName, strError);
1456}
1457
Kevin Rocard170f0a42012-06-18 13:56:05 +02001458bool CParameterMgr::deleteAllDomains(string& strError)
1459{
1460 // Check tuning mode
1461 if (!checkTuningModeOn(strError)) {
1462
1463 return false;
1464 }
1465
1466 // Delegate to configurable domains
1467 getConfigurableDomains()->deleteAllDomains();
1468
1469 return true;
1470}
1471
Patrick Benavoli68a91282011-08-31 11:23:23 +02001472bool CParameterMgr::createConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1473{
1474 // Check tuning mode
1475 if (!checkTuningModeOn(strError)) {
1476
1477 return false;
1478 }
1479
1480 // Delegate to configurable domains
1481 return getConfigurableDomains()->createConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1482}
1483
1484bool CParameterMgr::deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1485{
1486 // Check tuning mode
1487 if (!checkTuningModeOn(strError)) {
1488
1489 return false;
1490 }
1491
1492 // Delegate to configurable domains
1493 return getConfigurableDomains()->deleteConfiguration(strDomain, strConfiguration, strError);
1494}
1495
1496bool CParameterMgr::restoreConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1497{
1498 // Check tuning mode
1499 if (!checkTuningModeOn(strError)) {
1500
1501 return false;
1502 }
1503
1504 // Delegate to configurable domains
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001505 return getConstConfigurableDomains()->restoreConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001506}
1507
1508bool CParameterMgr::saveConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1509{
1510 // Check tuning mode
1511 if (!checkTuningModeOn(strError)) {
1512
1513 return false;
1514 }
1515
1516 // Delegate to configurable domains
1517 return getConfigurableDomains()->saveConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1518}
1519
1520// Configurable element - domain association
1521bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1522{
1523 // Check tuning mode
1524 if (!checkTuningModeOn(strError)) {
1525
1526 return false;
1527 }
1528
1529 CElementLocator elementLocator(getSystemClass());
1530
1531 CElement* pLocatedElement = NULL;
1532
1533 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1534
1535 return false;
1536 }
1537
1538 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001539 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001540
1541 // Delegate
1542 return getConfigurableDomains()->addConfigurableElementToDomain(strDomain, pConfigurableElement, _pMainParameterBlackboard, strError);
1543}
1544
1545bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1546{
1547 // Check tuning mode
1548 if (!checkTuningModeOn(strError)) {
1549
1550 return false;
1551 }
1552
1553 CElementLocator elementLocator(getSystemClass());
1554
1555 CElement* pLocatedElement = NULL;
1556
1557 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1558
Patrick Benavoli63499d42011-10-24 18:50:03 +02001559 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001560 }
1561
1562 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001563 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001564
1565 // Delegate
1566 return getConfigurableDomains()->removeConfigurableElementFromDomain(strDomain, pConfigurableElement, strError);
1567}
1568
1569bool CParameterMgr::split(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1570{
1571 // Check tuning mode
1572 if (!checkTuningModeOn(strError)) {
1573
1574 return false;
1575 }
1576
1577 CElementLocator elementLocator(getSystemClass());
1578
1579 CElement* pLocatedElement = NULL;
1580
1581 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1582
Patrick Benavoli63499d42011-10-24 18:50:03 +02001583 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001584 }
1585
1586 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001587 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001588
1589 // Delegate
1590 return getConfigurableDomains()->split(strDomain, pConfigurableElement, strError);
1591}
1592
1593// XML Import/Export
1594bool CParameterMgr::importDomainsXml(const string& strFileName, bool bWithSettings, string& strError)
1595{
1596 // Check tuning mode
1597 if (!checkTuningModeOn(strError)) {
1598
1599 return false;
1600 }
1601
1602 // check path is absolute
1603 if (strFileName[0] != '/') {
1604
1605 strError = "Please provide absolute path";
1606
1607 return false;
1608 }
1609 // Root element
1610 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1611
1612 // Context
1613 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1614
1615 // Secltion criteria definition for rule creation
1616 xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
1617
1618 // Parse
1619 if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strFileName, "", EParameterConfigurationLibrary, "SystemClassName")) {
1620
1621 return false;
1622 }
1623
1624 // Validate domains after XML import
1625 pConfigurableDomains->validate(_pMainParameterBlackboard);
1626
1627 return true;
1628}
1629
1630bool CParameterMgr::exportDomainsXml(const string& strFileName, bool bWithSettings, string& strError) const
1631{
1632 // check path is absolute
1633 if (strFileName[0] != '/') {
1634
1635 strError = "Please provide absolute path";
1636
1637 return false;
1638 }
1639
1640 // Root element
1641 const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains();
1642
1643 // Get Schema file associated to root element
1644 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pConfigurableDomains->getKind() + ".xsd";
1645
1646 // Context
1647 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1648
1649 // Value space
1650 xmlDomainSerializingContext.setValueSpaceRaw(_bValueSpaceIsRaw);
1651
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001652 // Output raw format
1653 xmlDomainSerializingContext.setOutputRawFormat(_bOutputRawFormatIsHex);
1654
Patrick Benavoli68a91282011-08-31 11:23:23 +02001655 // Instantiate composer
1656 CXmlComposer xmlComposer(strFileName, strXmlSchemaFilePath, pConfigurableDomains->getKind(), xmlDomainSerializingContext);
1657
1658 // Open composer
1659 if (!xmlComposer.open()) {
1660
1661 return false;
1662 }
1663
1664 // Compose
Patrick Benavoli63499d42011-10-24 18:50:03 +02001665 xmlComposer.compose(pConfigurableDomains, "parameter-framework", getVersion());
Patrick Benavoli68a91282011-08-31 11:23:23 +02001666
1667 // Close composer
1668 if (!xmlComposer.close()) {
1669
1670 return false;
1671 }
1672
1673 return true;
1674}
1675
1676// Binary Import/Export
1677bool CParameterMgr::importDomainsBinary(const string& strFileName, string& strError)
1678{
1679 // Check tuning mode
1680 if (!checkTuningModeOn(strError)) {
1681
1682 return false;
1683 }
1684 // check path is absolute
1685 if (strFileName[0] != '/') {
1686
1687 strError = "Please provide absolute path";
1688
1689 return false;
1690 }
1691 // Root element
1692 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1693
1694 // Serialize in
1695 return pConfigurableDomains->serializeSettings(strFileName, false, _uiStructureChecksum, strError);
1696}
1697
1698bool CParameterMgr::exportDomainsBinary(const string& strFileName, string& strError)
1699{
1700 // check path is absolute
1701 if (strFileName[0] != '/') {
1702
1703 strError = "Please provide absolute path";
1704
1705 return false;
1706 }
Patrick Benavoli68a91282011-08-31 11:23:23 +02001707
Patrick Benavoli68a91282011-08-31 11:23:23 +02001708 // Root element
1709 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1710
1711 // Serialize out
1712 return pConfigurableDomains->serializeSettings(strFileName, true, _uiStructureChecksum, strError);
1713}
1714
1715// For tuning, check we're in tuning mode
1716bool CParameterMgr::checkTuningModeOn(string& strError) const
1717{
1718 // Tuning Mode on?
1719 if (!_bTuningModeIsOn) {
1720
1721 strError = "Tuning Mode must be on";
1722
1723 return false;
1724 }
1725 return true;
1726}
1727
Patrick Benavoli065264a2011-11-20 15:46:41 +01001728// Tuning mutex dynamic parameter handling
1729pthread_mutex_t* CParameterMgr::getBlackboardMutex()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001730{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001731 return &_blackboardMutex;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001732}
1733
Patrick Benavoli065264a2011-11-20 15:46:41 +01001734// Blackboard reference (dynamic parameter handling)
1735CParameterBlackboard* CParameterMgr::getParameterBlackboard()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001736{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001737 return _pMainParameterBlackboard;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001738}
1739
Patrick Benavoli68a91282011-08-31 11:23:23 +02001740// Dynamic creation library feeding
1741void CParameterMgr::feedElementLibraries()
1742{
1743 // Global Configuration handling
1744 CElementLibrary* pFrameworkConfigurationLibrary = new CElementLibrary;
1745
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001746 pFrameworkConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CParameterFrameworkConfiguration>("ParameterFrameworkConfiguration"));
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +01001747 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CSubsystemPlugins>("SubsystemPlugins"));
1748 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CPluginLocation>("Location"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001749 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("StructureDescriptionFileLocation"));
1750 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationGroup>("SettingsConfiguration"));
1751 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("ConfigurableDomainsFileLocation"));
1752 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("BinarySettingsFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001753
1754 _pElementLibrarySet->addElementLibrary(pFrameworkConfigurationLibrary);
1755
1756 // Parameter creation
1757 CElementLibrary* pParameterCreationLibrary = new CElementLibrary;
1758
1759 pParameterCreationLibrary->addElementBuilder(new CSubsystemElementBuilder(getSystemClass()->getSubsystemLibrary()));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001760 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CComponentType>("ComponentType"));
1761 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CComponentInstance>("Component"));
1762 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBitParameterType>("BitParameter"));
1763 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBitParameterBlockType>("BitParameterBlock"));
Patrick Benavoli1352ae52011-10-21 16:48:04 +02001764 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CStringParameterType>("StringParameter"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001765 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CParameterBlockType>("ParameterBlock"));
1766 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBooleanParameterType>("BooleanParameter"));
1767 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CIntegerParameterType>("IntegerParameter"));
Patrick Benavoliee65e6d2011-11-20 18:52:24 +01001768 pParameterCreationLibrary->addElementBuilder(new TElementBuilderTemplate<CLinearParameterAdaptation>("LinearAdaptation"));
Patrick Benavoli9fc3c0d2011-10-27 14:27:27 +02001769 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CEnumParameterType>("EnumParameter"));
Patrick Benavoli68808c62012-02-02 17:12:41 +01001770 pParameterCreationLibrary->addElementBuilder(new TElementBuilderTemplate<CEnumValuePair>("ValuePair"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001771 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CFixedPointParameterType>("FixedPointParameter"));
1772 pParameterCreationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CXmlFileIncluderElement>("SubsystemInclude"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001773
1774 _pElementLibrarySet->addElementLibrary(pParameterCreationLibrary);
1775
1776 // Parameter Configuration Domains creation
1777 CElementLibrary* pParameterConfigurationLibrary = new CElementLibrary;
1778
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001779 pParameterConfigurationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CConfigurableDomain>("ConfigurableDomain"));
1780 pParameterConfigurationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CDomainConfiguration>("Configuration"));
1781 pParameterConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CCompoundRule>("CompoundRule"));
1782 pParameterConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CSelectionCriterionRule>("SelectionCriterionRule"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001783
1784 _pElementLibrarySet->addElementLibrary(pParameterConfigurationLibrary);
1785}
1786
1787// Remote Processor Server connection handling
1788bool CParameterMgr::handleRemoteProcessingInterface(string& strError)
1789{
1790 CAutoLog autoLog(this, "Handling remote processing interface");
1791
1792 // Start server if tuning allowed
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001793 if (getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001794
1795 log("Loading remote processor library");
1796
1797 // Load library
1798 void* lib_handle = dlopen("libremote-processor.so", RTLD_NOW);
1799
1800 if (!lib_handle) {
1801
1802 // Return error
1803 const char* pcError = dlerror();
1804
1805 if (pcError) {
1806
1807 strError = pcError;
1808 } else {
1809
1810 strError = "Unable to load libremote-processor.so library";
1811 }
1812
1813 return false;
1814 }
1815
1816 CreateRemoteProcessorServer pfnCreateRemoteProcessorServer = (CreateRemoteProcessorServer)dlsym(lib_handle, "createRemoteProcessorServer");
1817
1818 if (!pfnCreateRemoteProcessorServer) {
1819
1820 strError = "libremote-process.so does not contain createRemoteProcessorServer symbol.";
1821
1822 return false;
1823 }
1824
1825 // Create server
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001826 _pRemoteProcessorServer = pfnCreateRemoteProcessorServer(getConstFrameworkConfiguration()->getServerPort(), _pCommandHandler);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001827
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001828 log("Starting remote processor server on port %d", getConstFrameworkConfiguration()->getServerPort());
Patrick Benavoli68a91282011-08-31 11:23:23 +02001829 // Start
1830 if (!_pRemoteProcessorServer->start()) {
1831
1832 strError = "Unable to start remote processor server";
1833
1834 return false;
1835 }
1836 }
1837
1838 return true;
1839}
1840
1841// Back synchronization
1842CBackSynchronizer* CParameterMgr::createBackSynchronizer(string& strError) const
1843{
1844#ifdef SIMULATION
1845 // In simulation, back synchronization of the blackboard won't probably work
1846 // We need to ensure though the blackboard is initialized with valid data
1847 return new CSimulatedBackSynchronizer(getConstSystemClass(), strError, _pMainParameterBlackboard);
1848#else
1849 // Real back synchronizer from subsystems
1850 return new CHardwareBackSynchronizer(getConstSystemClass(), strError, _pMainParameterBlackboard);
1851#endif
1852}
1853
1854// Children typwise access
1855CParameterFrameworkConfiguration* CParameterMgr::getFrameworkConfiguration()
1856{
1857 return static_cast<CParameterFrameworkConfiguration*>(getChild(EFrameworkConfiguration));
1858}
1859
1860const CParameterFrameworkConfiguration* CParameterMgr::getConstFrameworkConfiguration()
1861{
1862 return getFrameworkConfiguration();
1863}
1864
1865CSelectionCriteria* CParameterMgr::getSelectionCriteria()
1866{
1867 return static_cast<CSelectionCriteria*>(getChild(ESelectionCriteria));
1868}
1869
1870const CSelectionCriteria* CParameterMgr::getConstSelectionCriteria()
1871{
1872 return static_cast<const CSelectionCriteria*>(getChild(ESelectionCriteria));
1873}
1874
1875CSystemClass* CParameterMgr::getSystemClass()
1876{
1877 return static_cast<CSystemClass*>(getChild(ESystemClass));
1878}
1879
1880const CSystemClass* CParameterMgr::getConstSystemClass() const
1881{
1882 return static_cast<const CSystemClass*>(getChild(ESystemClass));
1883}
1884
1885// Configurable Domains
1886CConfigurableDomains* CParameterMgr::getConfigurableDomains()
1887{
1888 return static_cast<CConfigurableDomains*>(getChild(EConfigurableDomains));
1889}
1890
1891const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains()
1892{
1893 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
1894}
1895
1896const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains() const
1897{
1898 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
1899}