blob: 4e6e4dae683010d20fe0deacf45d7597d63c99b9 [file] [log] [blame]
Frédéric Boisnarddaaa63c2012-08-27 15:48:15 +02001/*
Patrick Benavoli68a91282011-08-31 11:23:23 +02002 * INTEL CONFIDENTIAL
3 * Copyright © 2011 Intel
4 * Corporation All Rights Reserved.
5 *
6 * The source code contained or described herein and all documents related to
7 * the source code ("Material") are owned by Intel Corporation or its suppliers
8 * or licensors. Title to the Material remains with Intel Corporation or its
9 * suppliers and licensors. The Material contains trade secrets and proprietary
10 * and confidential information of Intel or its suppliers and licensors. The
11 * Material is protected by worldwide copyright and trade secret laws and
12 * treaty provisions. No part of the Material may be used, copied, reproduced,
13 * modified, published, uploaded, posted, transmitted, distributed, or
14 * disclosed in any way without Intel’s prior express written permission.
15 *
16 * No license under any patent, copyright, trade secret or other intellectual
17 * property right is granted to or conferred upon you by disclosure or delivery
18 * of the Materials, either expressly, by implication, inducement, estoppel or
19 * otherwise. Any license under such intellectual property rights must be
20 * express and approved by Intel in writing.
21 *
Patrick Benavoli68a91282011-08-31 11:23:23 +020022 * CREATED: 2011-06-01
23 * UPDATED: 2011-07-27
Patrick Benavoli68a91282011-08-31 11:23:23 +020024 */
25#include "ParameterMgr.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020026#include "XmlParameterSerializingContext.h"
27#include "XmlElementSerializingContext.h"
28#include "SystemClass.h"
29#include "ElementLibrarySet.h"
30#include "SubsystemLibrary.h"
31#include "NamedElementBuilderTemplate.h"
32#include "KindElementBuilderTemplate.h"
33#include "ElementBuilderTemplate.h"
34#include "SelectionCriterionType.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020035#include "SubsystemElementBuilder.h"
36#include "SelectionCriteria.h"
37#include "ComponentType.h"
38#include "ComponentInstance.h"
39#include "ParameterBlockType.h"
40#include "BooleanParameterType.h"
41#include "IntegerParameterType.h"
42#include "FixedPointParameterType.h"
43#include "ParameterBlackboard.h"
44#include "Parameter.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020045#include "ParameterBlackboard.h"
46#include "ParameterAccessContext.h"
47#include "XmlFileIncluderElement.h"
48#include "ParameterFrameworkConfiguration.h"
49#include "FrameworkConfigurationGroup.h"
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +010050#include "PluginLocation.h"
51#include "SubsystemPlugins.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020052#include "FrameworkConfigurationLocation.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020053#include "ConfigurableDomains.h"
54#include "ConfigurableDomain.h"
55#include "DomainConfiguration.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020056#include "XmlDomainSerializingContext.h"
57#include "BitParameterBlockType.h"
58#include "BitParameterType.h"
Patrick Benavoli1352ae52011-10-21 16:48:04 +020059#include "StringParameterType.h"
Patrick Benavoli9fc3c0d2011-10-27 14:27:27 +020060#include "EnumParameterType.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020061#include "RemoteProcessorServerInterface.h"
62#include "ElementLocator.h"
63#include "AutoLog.h"
64#include "CompoundRule.h"
65#include "SelectionCriterionRule.h"
66#include "SimulatedBackSynchronizer.h"
67#include "HardwareBackSynchronizer.h"
Patrick Benavoli1387bda2011-08-31 11:23:24 +020068#include "AutoLock.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020069#include <strings.h>
70#include <dlfcn.h>
71#include <assert.h>
Patrick Benavoli065264a2011-11-20 15:46:41 +010072#include "ParameterHandle.h"
Patrick Benavoliee65e6d2011-11-20 18:52:24 +010073#include "LinearParameterAdaptation.h"
Patrick Benavoli68808c62012-02-02 17:12:41 +010074#include "EnumValuePair.h"
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020075#include "XmlFileDocSink.h"
76#include "XmlFileDocSource.h"
77#include "XmlStringDocSink.h"
78#include "XmlMemoryDocSink.h"
79#include "XmlMemoryDocSource.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020080
81#define base CElement
82
83// Used for remote processor server creation
84typedef IRemoteProcessorServerInterface* (*CreateRemoteProcessorServer)(uint16_t uiPort, IRemoteCommandHandler* pCommandHandler);
85
86// Global configuration file name (fixed)
87const char* gacParameterFrameworkConfigurationFileName = "ParameterFrameworkConfiguration.xml";
88const char* gacSystemSchemasSubFolder = "Schemas";
89
90// Config File System looks normally like this:
91// ---------------------------------------------
Patrick Benavoli95ac0342011-11-07 20:32:51 +010092//├── <ParameterFrameworkConfiguration>.xml
Patrick Benavoli68a91282011-08-31 11:23:23 +020093//├── Schemas
94//│ └── *.xsd
95//├── Settings
96//│ └── <SystemClassName folder>*
97//│ ├── <ConfigurableDomains>.xml
98//│ └── <Settings>.bin?
99//└── Structure
100// └── <SystemClassName folder>*
101// ├── <SystemClassName>Class.xml
102// └── <Subsystem>.xml*
103// --------------------------------------------
104
105
106// Remote command parser array
Patrick Benavoli592ae562011-09-05 16:53:58 +0200107const CParameterMgr::SRemoteCommandParserItem CParameterMgr::gastRemoteCommandParserItems[] = {
Patrick Benavoli592ae562011-09-05 16:53:58 +0200108 /// Version
109 { "version", &CParameterMgr::versionCommandProcess, 0, "", "Show version" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200110 /// Status
111 { "status", &CParameterMgr::statusCommandProcess, 0, "", "Show current status" },
112 /// Tuning Mode
113 { "setTuningMode", &CParameterMgr::setTuningModeCommmandProcess, 1, "on|off*", "Turn on or off Tuning Mode" },
114 { "getTuningMode", &CParameterMgr::getTuningModeCommmandProcess, 0, "", "Show Tuning Mode" },
115 /// Value Space
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200116 { "setValueSpace", &CParameterMgr::setValueSpaceCommmandProcess, 1, "raw|real*", "Assigns Value Space used for parameter value interpretation" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200117 { "getValueSpace", &CParameterMgr::getValueSpaceCommmandProcess, 0, "", "Show Value Space" },
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200118 /// Output Raw Format
119 { "setOutputRawFormat", &CParameterMgr::setOutputRawFormatCommmandProcess, 1, "dec*|hex", "Assigns format used to output parameter values when in raw Value Space" },
120 { "getOutputRawFormat", &CParameterMgr::getOutputRawFormatCommmandProcess, 0, "", "Show Output Raw Format" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200121 /// Sync
122 { "setAutoSync", &CParameterMgr::setAutoSyncCommmandProcess, 1, "on*|off", "Turn on or off automatic synchronization to hardware while in Tuning Mode" },
123 { "getAutoSync", &CParameterMgr::getAutoSyncCommmandProcess, 0, "", "Show Auto Sync state" },
124 { "sync", &CParameterMgr::syncCommmandProcess, 0, "", "Synchronize current settings to hardware while in Tuning Mode and Auto Sync off" },
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200125 /// Criteria
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200126 { "listCriteria", &CParameterMgr::listCriteriaCommmandProcess, 0, "", "List selection criteria" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200127 /// Domains
128 { "listDomains", &CParameterMgr::listDomainsCommmandProcess, 0, "", "List configurable domains" },
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100129 { "dumpDomains", &CParameterMgr::dumpDomainsCommmandProcess, 0, "", "Show all domains and configurations, including applicability conditions" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200130 { "createDomain", &CParameterMgr::createDomainCommmandProcess, 1, "<domain>", "Create new configurable domain" },
131 { "deleteDomain", &CParameterMgr::deleteDomainCommmandProcess, 1, "<domain>", "Delete configurable domain" },
Kevin Rocard170f0a42012-06-18 13:56:05 +0200132 { "deleteAllDomains", &CParameterMgr::deleteAllDomainsCommmandProcess, 0, "", "Delete all configurable domains" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200133 { "renameDomain", &CParameterMgr::renameDomainCommmandProcess, 2, "<domain> <new name>", "Rename configurable domain" },
Patrick Benavoli63499d42011-10-24 18:50:03 +0200134 { "setSequenceAwareness", &CParameterMgr::setSequenceAwarenessCommmandProcess, 1, "<domain> true|false*", "Set configurable domain sequence awareness" },
135 { "getSequenceAwareness", &CParameterMgr::getSequenceAwarenessCommmandProcess, 1, "<domain>", "Get configurable domain sequence awareness" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200136 { "listDomainElements", &CParameterMgr::listDomainElementsCommmandProcess, 1, "<domain>", "List elements associated to configurable domain" },
137 { "addElement", &CParameterMgr::addElementCommmandProcess, 2, "<domain> <elem path>", "Associate element at given path to configurable domain" },
138 { "removeElement", &CParameterMgr::removeElementCommmandProcess, 2, "<domain> <elem path>", "Dissociate element at given path from configurable domain" },
139 { "splitDomain", &CParameterMgr::splitDomainCommmandProcess, 2, "<domain> <elem path>", "Split configurable domain at given associated element path" },
140 /// Configurations
141 { "listConfigurations", &CParameterMgr::listConfigurationsCommmandProcess, 1, "<domain>", "List domain configurations" },
142 { "createConfiguration", &CParameterMgr::createConfigurationCommmandProcess, 2, "<domain> <configuration>", "Create new domain configuration" },
143 { "deleteConfiguration", &CParameterMgr::deleteConfigurationCommmandProcess, 2, "<domain> <configuration>", "Delete domain configuration" },
144 { "renameConfiguration", &CParameterMgr::renameConfigurationCommmandProcess, 3, "<domain> <configuration> <new name>", "Rename domain configuration" },
145 { "saveConfiguration", &CParameterMgr::saveConfigurationCommmandProcess, 2, "<domain> <configuration>", "Save current settings into configuration" },
146 { "restoreConfiguration", &CParameterMgr::restoreConfigurationCommmandProcess, 2, "<domain> <configuration>", "Restore current settings from configuration" },
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100147 { "setElementSequence", &CParameterMgr::setElementSequenceCommmandProcess, 3, "<domain> <configuration> <elem path list>", "Set element application order for configuration" },
Patrick Benavoli63499d42011-10-24 18:50:03 +0200148 { "getElementSequence", &CParameterMgr::getElementSequenceCommmandProcess, 2, "<domain> <configuration>", "Get element application order for configuration" },
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100149 { "setRule", &CParameterMgr::setRuleCommmandProcess, 3, "<domain> <configuration> <rule>", "Set configuration application rule" },
150 { "clearRule", &CParameterMgr::clearRuleCommmandProcess, 2, "<domain> <configuration>", "Clear configuration application rule" },
151 { "getRule", &CParameterMgr::getRuleCommmandProcess, 2, "<domain> <configuration>", "Get configuration application rule" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200152 /// Elements/Parameters
153 { "listElements", &CParameterMgr::listElementsCommmandProcess, 1, "<elem path>|/", "List elements under element at given path or root" },
Patrick Benavoli592ae562011-09-05 16:53:58 +0200154 { "listParameters", &CParameterMgr::listParametersCommmandProcess, 1, "<elem path>|/", "List parameters under element at given path or root" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200155 { "dumpElement", &CParameterMgr::dumpElementCommmandProcess, 1, "<elem path>", "Dump structure and content of element at given path" },
156 { "getElementSize", &CParameterMgr::getElementSizeCommmandProcess, 1, "<elem path>", "Show size of element at given path" },
Patrick Benavoli2ecf9002011-08-31 11:23:24 +0200157 { "showProperties", &CParameterMgr::showPropertiesCommmandProcess, 1, "<elem path>", "Show properties of element at given path" },
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200158 { "getParameter", &CParameterMgr::getParameterCommmandProcess, 1, "<param path>", "Get value for parameter at given path" },
Patrick Benavoli2ecf9002011-08-31 11:23:24 +0200159 { "setParameter", &CParameterMgr::setParameterCommmandProcess, 2, "<param path> <value>", "Set value for parameter at given path" },
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200160 { "listBelongingDomains", &CParameterMgr::listBelongingDomainsCommmandProcess, 1, "<elem path>", "List domain(s) element at given path belongs to" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200161 { "listAssociatedDomains", &CParameterMgr::listAssociatedDomainsCommmandProcess, 1, "<elem path>", "List domain(s) element at given path is associated to" },
162 /// Browse
163 { "listAssociatedElements", &CParameterMgr::listAssociatedElementsCommmandProcess, 0, "", "List element sub-trees associated to at least one configurable domain" },
164 { "listConflictingElements", &CParameterMgr::listConflictingElementsCommmandProcess, 0, "", "List element sub-trees contained in more than one configurable domain" },
165 { "listRogueElements", &CParameterMgr::listRogueElementsCommmandProcess, 0, "", "List element sub-trees owned by no configurable domain" },
166 /// Settings Import/Export
167 { "exportDomainsXML", &CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess, 1, "<file path> ", "Export domains to XML file" },
168 { "importDomainsXML", &CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess, 1, "<file path>", "Import domains from XML file" },
169 { "exportDomainsWithSettingsXML", &CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess, 1, "<file path> ", "Export domains including settings to XML file" },
170 { "importDomainsWithSettingsXML", &CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess, 1, "<file path>", "Import domains including settings from XML file" },
171 { "exportSettings", &CParameterMgr::exportSettingsCommmandProcess, 1, "<file path>", "Export settings to binary file" },
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200172 { "importSettings", &CParameterMgr::importSettingsCommmandProcess, 1, "<file path>", "Import settings from binary file" },
173 { "getDomainsXML", &CParameterMgr::getDomainsXMLCommmandProcess, 0 ,"", "Print domains including settings as XML" },
174 /// Structure Export
175 { "getSystemClassXML", &CParameterMgr::getSystemClassXMLCommmandProcess, 0 ,"", "Print parameter structure as XML" }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200176};
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 // Back-synchronize
Kevin Rocard57096bd2012-11-30 11:24:20 +0100336 {
337 CAutoLog autoLog(this, "Main blackboard back synchronization");
338
339 if (!pBackSynchronizer->sync()) {
340 // Get rid of back synchronizer
341 delete pBackSynchronizer;
342
343 strError = "Main blackboard back synchronization failed: " + strError;
344
345 return false;
346 }
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200347 // Get rid of back synchronizer
348 delete pBackSynchronizer;
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200349 }
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200350
351 // We're done loading the settings and back synchronizing
352 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
353
354 // We need to ensure all domains are valid
355 pConfigurableDomains->validate(_pMainParameterBlackboard);
356
357 // Ensure application of currently selected configurations
358 // Force-apply configurations
359 if (!pConfigurableDomains->apply(_pMainParameterBlackboard, true, strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200360
361 return false;
362 }
363
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200364 // Start remote processor server if appropriate
365 return handleRemoteProcessingInterface(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200366}
367
368bool CParameterMgr::loadFrameworkConfiguration(string& strError)
369{
370 CAutoLog autoLog(this, "Loading framework configuration");
371
Patrick Benavoli68a91282011-08-31 11:23:23 +0200372 // Parse Structure XML file
373 CXmlElementSerializingContext elementSerializingContext(strError);
374
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100375 if (!xmlParse(elementSerializingContext, getFrameworkConfiguration(), _strXmlConfigurationFilePath, _strXmlConfigurationFolderPath, EFrameworkConfigurationLibrary)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200376
377 return false;
378 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100379 // Set class name to system class and configurable domains
380 getSystemClass()->setName(getConstFrameworkConfiguration()->getSystemClassName());
381 getConfigurableDomains()->setName(getConstFrameworkConfiguration()->getSystemClassName());
382
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100383 // Get subsystem plugins elements
384 _pSubsystemPlugins = static_cast<const CSubsystemPlugins*>(getConstFrameworkConfiguration()->findChild("SubsystemPlugins"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200385
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100386 if (!_pSubsystemPlugins) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200387
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100388 strError = "Parameter Framework Configuration: couldn't find SubsystemPlugins element";
Patrick Benavoli68a91282011-08-31 11:23:23 +0200389
390 return false;
391 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200392
Patrick Benavoli68a91282011-08-31 11:23:23 +0200393 // Log tuning availability
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100394 log("Tuning %s", getConstFrameworkConfiguration()->isTuningAllowed() ? "allowed" : "prohibited");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200395
396 return true;
397}
398
399bool CParameterMgr::loadStructure(string& strError)
400{
401 // Retrieve system to load structure to
402 CSystemClass* pSystemClass = getSystemClass();
403
404 CAutoLog autoLog(this, "Loading " + pSystemClass->getName() + " system class structure");
405
406 // Get structure description element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100407 const CFrameworkConfigurationLocation* pStructureDescriptionFileLocation = static_cast<const CFrameworkConfigurationLocation*>(getConstFrameworkConfiguration()->findChildOfKind("StructureDescriptionFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200408
409 if (!pStructureDescriptionFileLocation) {
410
411 strError = "No StructureDescriptionFileLocation element found for SystemClass " + pSystemClass->getName();
412
413 return false;
414 }
415
416 // Get Xml structure folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100417 string strXmlStructureFolder = pStructureDescriptionFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200418
419 // Get Xml structure file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100420 string strXmlStructureFilePath = pStructureDescriptionFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200421
422 // Parse Structure XML file
423 CXmlParameterSerializingContext parameterBuildContext(strError);
424
Kevin Rocard57096bd2012-11-30 11:24:20 +0100425 CAutoLog autolog(pSystemClass, "Importing system structure from file " + strXmlStructureFilePath);
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200426
Patrick Benavoli68a91282011-08-31 11:23:23 +0200427 if (!xmlParse(parameterBuildContext, pSystemClass, strXmlStructureFilePath, strXmlStructureFolder, EParameterCreationLibrary)) {
428
429 return false;
430 }
431
432 // Initialize offsets
433 pSystemClass->setOffset(0);
434
435 // Initialize main blackboard's size
436 _pMainParameterBlackboard->setSize(pSystemClass->getFootPrint());
437
438 return true;
439}
440
441bool CParameterMgr::loadSettings(string& strError)
442{
443 CAutoLog autoLog(this, "Loading settings");
444
445 // Get settings configuration element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100446 const CFrameworkConfigurationGroup* pParameterConfigurationGroup = static_cast<const CFrameworkConfigurationGroup*>(getConstFrameworkConfiguration()->findChildOfKind("SettingsConfiguration"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200447
448 if (!pParameterConfigurationGroup) {
449
450 // No settings to load
451
452 return true;
453 }
454 // Get binary settings file location
455 const CFrameworkConfigurationLocation* pBinarySettingsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("BinarySettingsFileLocation"));
456
457 string strXmlBinarySettingsFilePath;
458
459 if (pBinarySettingsFileLocation) {
460
461 // Get Xml binary settings file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100462 strXmlBinarySettingsFilePath = pBinarySettingsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200463 }
464
465 // Get configurable domains element
466 const CFrameworkConfigurationLocation* pConfigurableDomainsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("ConfigurableDomainsFileLocation"));
467
468 if (!pConfigurableDomainsFileLocation) {
469
470 strError = "No ConfigurableDomainsFileLocation element found for SystemClass " + getSystemClass()->getName();
471
472 return false;
473 }
474 // Get destination root element
475 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
476
477 // Get Xml configuration domains file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100478 string strXmlConfigurationDomainsFilePath = pConfigurableDomainsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200479
480 // Get Xml configuration domains folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100481 string strXmlConfigurationDomainsFolder = pConfigurableDomainsFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200482
483 // Parse configuration domains XML file (ask to read settings from XML file if they are not provided as binary)
484 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, !pBinarySettingsFileLocation);
485
486 // Selection criteria definition for rule creation
487 xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
488
Patrick Benavoli63499d42011-10-24 18:50:03 +0200489 // Auto validation of configurations if no binary settings provided
490 xmlDomainSerializingContext.setAutoValidationRequired(!pBinarySettingsFileLocation);
491
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200492 log("Importing configurable domains from file %s %s settings", strXmlConfigurationDomainsFilePath.c_str(), pBinarySettingsFileLocation ? "without" : "with");
493
Patrick Benavoli68a91282011-08-31 11:23:23 +0200494 // Do parse
495 if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strXmlConfigurationDomainsFilePath, strXmlConfigurationDomainsFolder, EParameterConfigurationLibrary, "SystemClassName")) {
496
497 return false;
498 }
499 // We have loaded the whole system structure, compute checksum
500 const CSystemClass* pSystemClass = getConstSystemClass();
501 _uiStructureChecksum = pSystemClass->computeStructureChecksum() + getConfigurableDomains()->computeStructureChecksum() + getSelectionCriteria()->computeStructureChecksum();
502
503 // Load binary settings if any provided
504 if (pBinarySettingsFileLocation && !pConfigurableDomains->serializeSettings(strXmlBinarySettingsFilePath, false, _uiStructureChecksum, strError)) {
505
506 return false;
507 }
508
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200509 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200510}
511
512// XML parsing
513bool CParameterMgr::xmlParse(CXmlElementSerializingContext& elementSerializingContext, CElement* pRootElement, const string& strXmlFilePath, const string& strXmlFolder, CParameterMgr::ElementLibrary eElementLibrary, const string& strNameAttrituteName)
514{
515 // Init serializing context
516 elementSerializingContext.set(_pElementLibrarySet->getElementLibrary(eElementLibrary), strXmlFolder, _strSchemaFolderLocation);
517
518 // Get Schema file associated to root element
519 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pRootElement->getKind() + ".xsd";
520
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200521 CXmlFileDocSource fileDocSource(strXmlFilePath, strXmlSchemaFilePath, pRootElement->getKind(), pRootElement->getName(), strNameAttrituteName);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200522
523 // Start clean
524 pRootElement->clean();
525
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200526 CXmlMemoryDocSink memorySink(pRootElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200527
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200528 if (!memorySink.process(fileDocSource, elementSerializingContext)) {
529 //Cleanup
Patrick Benavoli68a91282011-08-31 11:23:23 +0200530 pRootElement->clean();
531
532 return false;
533 }
534
Patrick Benavoli68a91282011-08-31 11:23:23 +0200535 return true;
536}
537
538// Init
539bool CParameterMgr::init(string& strError)
540{
541 return base::init(strError);
542}
543
544// Selection criteria interface
545CSelectionCriterionType* CParameterMgr::createSelectionCriterionType(bool bIsInclusive)
546{
547 // Propagate
548 return getSelectionCriteria()->createSelectionCriterionType(bIsInclusive);
549}
550
551CSelectionCriterion* CParameterMgr::createSelectionCriterion(const string& strName, const CSelectionCriterionType* pSelectionCriterionType)
552{
553 // Propagate
554 return getSelectionCriteria()->createSelectionCriterion(strName, pSelectionCriterionType);
555}
556
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200557// Selection criterion retrieval
558CSelectionCriterion* CParameterMgr::getSelectionCriterion(const string& strName)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200559{
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200560 // Propagate
561 return getSelectionCriteria()->getSelectionCriterion(strName);
562}
563
564// Selection criteria changed event
565bool CParameterMgr::applyConfigurations(string& strError)
566{
567 CAutoLog autoLog(this, "Configuration application request");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200568
569 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +0100570 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200571
572 if (!_bTuningModeIsOn) {
573
574 // Apply configuration(s)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200575 if (!getConfigurableDomains()->apply(_pMainParameterBlackboard, false, strError)) {
576
577 log("Failed to apply configurations!");
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200578
579 return false;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200580 }
Frédéric Boisnarddaaa63c2012-08-27 15:48:15 +0200581
582 // Reset the modified status of the current criteria to indicate that a new configuration has been applied
583 getSelectionCriteria()->resetModifiedStatus();
584
585 } else {
586
587 log("Warning: Configurations were not applied because the TuningMode is on");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200588 }
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200589
590 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200591}
592
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200593// Dynamic parameter handling
Patrick Benavoli065264a2011-11-20 15:46:41 +0100594CParameterHandle* CParameterMgr::createParameterHandle(const string& strPath, string& strError)
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200595{
Patrick Benavoli065264a2011-11-20 15:46:41 +0100596 CPathNavigator pathNavigator(strPath);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200597
Patrick Benavoli065264a2011-11-20 15:46:41 +0100598 // Nagivate through system class
599 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
600
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100601 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100602 }
603
604 // Find element
605 const CElement* pElement = getConstSystemClass()->findDescendant(pathNavigator);
606
607 if (!pElement) {
608
609 strError = "Path not found";
610
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100611 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100612 }
613
614 // Check found element is a parameter
615 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pElement);
616
617 if (!pConfigurableElement->isParameter()) {
618
619 // Element is not parameter
620 strError = "Not a parameter";
621
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100622 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100623 }
624
625 // Convert as parameter and return new handle
626 return new CParameterHandle(static_cast<const CBaseParameter*>(pElement), this);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200627}
628
Patrick Benavoli68a91282011-08-31 11:23:23 +0200629/////////////////// Remote command parsers
Patrick Benavoli592ae562011-09-05 16:53:58 +0200630/// Version
Patrick Benavoli63499d42011-10-24 18:50:03 +0200631CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::versionCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli592ae562011-09-05 16:53:58 +0200632{
633 (void)remoteCommand;
634
Patrick Benavoli63499d42011-10-24 18:50:03 +0200635 // Show version
636 strResult = getVersion();
Patrick Benavoli592ae562011-09-05 16:53:58 +0200637
Patrick Benavoli63499d42011-10-24 18:50:03 +0200638 return CCommandHandler::ESucceeded;
Patrick Benavoli592ae562011-09-05 16:53:58 +0200639}
640
Patrick Benavoli68a91282011-08-31 11:23:23 +0200641/// Status
Patrick Benavoli63499d42011-10-24 18:50:03 +0200642CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::statusCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200643{
644 (void)remoteCommand;
645 // System class
646 const CSystemClass* pSystemClass = getSystemClass();
647
Patrick Benavoli68a91282011-08-31 11:23:23 +0200648 // Show status
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200649 /// General section
650 appendTitle(strResult, "General:");
651 // System class
Patrick Benavoli68a91282011-08-31 11:23:23 +0200652 strResult += "System Class: ";
653 strResult += pSystemClass->getName();
654 strResult += "\n";
655
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200656 // Tuning mode
Patrick Benavoli68a91282011-08-31 11:23:23 +0200657 strResult += "Tuning Mode: ";
658 strResult += tuningModeOn() ? "on" : "off";
659 strResult += "\n";
660
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200661 // Value space
Patrick Benavoli68a91282011-08-31 11:23:23 +0200662 strResult += "Value Space: ";
663 strResult += valueSpaceIsRaw() ? "raw" : "real";
664 strResult += "\n";
665
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200666 // Output raw format
667 strResult += "Output Raw Format: ";
668 strResult += outputRawFormatIsHex() ? "hex" : "dec";
669 strResult += "\n";
670
671 // Auto Sync
Patrick Benavoli68a91282011-08-31 11:23:23 +0200672 strResult += "Auto Sync: ";
673 strResult += autoSyncOn() ? "on" : "off";
674 strResult += "\n";
675
676 /// Subsystem list
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200677 appendTitle(strResult, "Subsystems:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200678 string strSubsystemList;
679 pSystemClass->listChildrenPaths(strSubsystemList);
680 strResult += strSubsystemList;
681
682 /// Last applied configurations
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200683 appendTitle(strResult, "Last Applied [Pending] Configurations:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200684 string strLastAppliedConfigurations;
685 getConfigurableDomains()->listLastAppliedConfigurations(strLastAppliedConfigurations);
686 strResult += strLastAppliedConfigurations;
687
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200688 /// Criteria states
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200689 appendTitle(strResult, "Selection Criteria:");
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200690 string strSelectionCriteria;
691 getSelectionCriteria()->listSelectionCriteria(strSelectionCriteria, false);
692 strResult += strSelectionCriteria;
693
Patrick Benavoli63499d42011-10-24 18:50:03 +0200694 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200695}
696
697/// Tuning Mode
Patrick Benavoli63499d42011-10-24 18:50:03 +0200698CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200699{
700 if (remoteCommand.getArgument(0) == "on") {
701
702 if (setTuningMode(true, strResult)) {
703
Patrick Benavoli63499d42011-10-24 18:50:03 +0200704 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200705 }
706 } else if (remoteCommand.getArgument(0) == "off") {
707
708 if (setTuningMode(false, strResult)) {
709
Patrick Benavoli63499d42011-10-24 18:50:03 +0200710 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200711 }
712 } else {
713 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200714 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200715 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200716 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200717}
718
Patrick Benavoli63499d42011-10-24 18:50:03 +0200719CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200720{
721 (void)remoteCommand;
722
723 strResult = tuningModeOn() ? "on" : "off";
724
Patrick Benavoli63499d42011-10-24 18:50:03 +0200725 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200726}
727
728/// Value Space
Patrick Benavoli63499d42011-10-24 18:50:03 +0200729CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200730{
731 (void)strResult;
732
733 if (remoteCommand.getArgument(0) == "raw") {
734
735 setValueSpace(true);
736
Patrick Benavoli63499d42011-10-24 18:50:03 +0200737 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200738
739 } else if (remoteCommand.getArgument(0) == "real") {
740
741 setValueSpace(false);
742
Patrick Benavoli63499d42011-10-24 18:50:03 +0200743 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200744
745 } else {
746 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200747 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200748 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200749 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200750}
751
Patrick Benavoli63499d42011-10-24 18:50:03 +0200752CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200753{
754 (void)remoteCommand;
755
756 strResult = valueSpaceIsRaw() ? "raw" : "real";
757
Patrick Benavoli63499d42011-10-24 18:50:03 +0200758 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200759}
760
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200761/// Output Raw Format
Patrick Benavoli63499d42011-10-24 18:50:03 +0200762CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200763{
764 (void)strResult;
765
766 if (remoteCommand.getArgument(0) == "hex") {
767
768 setOutputRawFormat(true);
769
Patrick Benavoli63499d42011-10-24 18:50:03 +0200770 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200771
772 } else if (remoteCommand.getArgument(0) == "dec") {
773
774 setOutputRawFormat(false);
775
Patrick Benavoli63499d42011-10-24 18:50:03 +0200776 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200777
778 } else {
779 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200780 return CCommandHandler::EShowUsage;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200781 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200782 return CCommandHandler::EFailed;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200783}
784
Patrick Benavoli63499d42011-10-24 18:50:03 +0200785CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200786{
787 (void)remoteCommand;
788
789 strResult = outputRawFormatIsHex() ? "hex" : "dec";
790
Patrick Benavoli63499d42011-10-24 18:50:03 +0200791 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200792}
793
Patrick Benavoli68a91282011-08-31 11:23:23 +0200794/// Sync
Patrick Benavoli63499d42011-10-24 18:50:03 +0200795CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200796{
797 if (remoteCommand.getArgument(0) == "on") {
798
799 if (setAutoSync(true, strResult)) {
800
Patrick Benavoli63499d42011-10-24 18:50:03 +0200801 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200802 }
803 } else if (remoteCommand.getArgument(0) == "off") {
804
805 if (setAutoSync(false, strResult)) {
806
Patrick Benavoli63499d42011-10-24 18:50:03 +0200807 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200808 }
809 } else {
810 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200811 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200812 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200813 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200814}
815
Patrick Benavoli63499d42011-10-24 18:50:03 +0200816CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200817{
818 (void)remoteCommand;
819
820 strResult = autoSyncOn() ? "on" : "off";
821
Patrick Benavoli63499d42011-10-24 18:50:03 +0200822 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200823}
824
Patrick Benavoli63499d42011-10-24 18:50:03 +0200825CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::syncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200826{
827 (void)remoteCommand;
828
Patrick Benavoli63499d42011-10-24 18:50:03 +0200829 return sync(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200830}
831
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200832/// Criteria
Patrick Benavoli63499d42011-10-24 18:50:03 +0200833CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listCriteriaCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200834{
835 (void)remoteCommand;
836
837 getSelectionCriteria()->listSelectionCriteria(strResult, true);
838
Patrick Benavoli63499d42011-10-24 18:50:03 +0200839 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200840}
Patrick Benavoli68a91282011-08-31 11:23:23 +0200841
842/// Domains
Patrick Benavoli63499d42011-10-24 18:50:03 +0200843CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200844{
845 (void)remoteCommand;
846
Patrick Benavoli63499d42011-10-24 18:50:03 +0200847 getConfigurableDomains()->listDomains(strResult);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200848
Patrick Benavoli63499d42011-10-24 18:50:03 +0200849 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200850}
851
Patrick Benavoli63499d42011-10-24 18:50:03 +0200852CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200853{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200854 return createDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200855}
856
Patrick Benavoli63499d42011-10-24 18:50:03 +0200857CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200858{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200859 return deleteDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200860}
861
Kevin Rocard170f0a42012-06-18 13:56:05 +0200862CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteAllDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
863{
864 (void)remoteCommand;
865
866 return deleteAllDomains(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
867}
868
Patrick Benavoli63499d42011-10-24 18:50:03 +0200869CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200870{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200871 return getConfigurableDomains()->renameDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200872}
873
Patrick Benavoli63499d42011-10-24 18:50:03 +0200874CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200875{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200876 // Check tuning mode
877 if (!checkTuningModeOn(strResult)) {
878
879 return CCommandHandler::EFailed;
880 }
881
882 // Set property
883 bool bSequenceAware;
884
885 if (remoteCommand.getArgument(1) == "true") {
886
887 bSequenceAware = true;
888
889 } else if (remoteCommand.getArgument(1) == "false") {
890
891 bSequenceAware = false;
892
893 } else {
894 // Show usage
895 return CCommandHandler::EShowUsage;
896 }
897
898 return getConfigurableDomains()->setSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200899}
900
Patrick Benavoli63499d42011-10-24 18:50:03 +0200901CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200902{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200903 // Get property
904 bool bSequenceAware;
905
906 if (!getConfigurableDomains()->getSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult)) {
907
908 return CCommandHandler::EFailed;
909 }
910
911 strResult = bSequenceAware ? "true" : "false";
912
913 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200914}
915
Patrick Benavoli63499d42011-10-24 18:50:03 +0200916CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200917{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200918 return getConfigurableDomains()->listDomainElements(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200919}
920
Patrick Benavoli63499d42011-10-24 18:50:03 +0200921CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::addElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200922{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200923 return addConfigurableElementToDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
924}
925
926CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::removeElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
927{
928 return removeConfigurableElementFromDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
929}
930
931CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::splitDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
932{
933 return split(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200934}
935
936/// Configurations
Patrick Benavoli63499d42011-10-24 18:50:03 +0200937CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConfigurationsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200938{
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100939 return getConstConfigurableDomains()->listConfigurations(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
940}
941
942CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
943{
944 (void)remoteCommand;
945
946 // Dummy error context
947 string strError;
948 CErrorContext errorContext(strError);
949
950 // Dump
951 getConstConfigurableDomains()->dumpContent(strResult, errorContext);
952
953 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200954}
955
Patrick Benavoli63499d42011-10-24 18:50:03 +0200956CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200957{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200958 return createConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200959}
960
Patrick Benavoli63499d42011-10-24 18:50:03 +0200961CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200962{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200963 return deleteConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200964}
965
Patrick Benavoli63499d42011-10-24 18:50:03 +0200966CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200967{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200968 return getConfigurableDomains()->renameConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200969}
970
Patrick Benavoli63499d42011-10-24 18:50:03 +0200971CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::saveConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200972{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200973 return saveConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200974}
975
Patrick Benavoli63499d42011-10-24 18:50:03 +0200976CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::restoreConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200977{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200978 return restoreConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
979}
980
981CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
982{
983 // Check tuning mode
984 if (!checkTuningModeOn(strResult)) {
985
986 return CCommandHandler::EFailed;
987 }
988
989 // Build configurable element path list
990 vector<string> astrNewElementSequence;
991
992 uint32_t uiArgument;
993
994 for (uiArgument = 2; uiArgument < remoteCommand.getArgumentCount(); uiArgument++) {
995
996 astrNewElementSequence.push_back(remoteCommand.getArgument(uiArgument));
997 }
998
999 // Delegate to configurable domains
1000 return getConfigurableDomains()->setElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), astrNewElementSequence, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1001}
1002
1003CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1004{
1005 // Delegate to configurable domains
1006 return getConfigurableDomains()->getElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001007}
1008
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001009CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1010{
1011 // Delegate to configurable domains
1012 return getConfigurableDomains()->setApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.packArguments(2, remoteCommand.getArgumentCount() - 2), getConstSelectionCriteria()->getSelectionCriteriaDefinition(), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1013}
1014
1015CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::clearRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1016{
1017 // Delegate to configurable domains
1018 return getConfigurableDomains()->clearApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1019}
1020
1021CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1022{
1023 // Delegate to configurable domains
1024 return getConfigurableDomains()->getApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
1025}
1026
Patrick Benavoli68a91282011-08-31 11:23:23 +02001027/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001028CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001029{
1030 CElementLocator elementLocator(getSystemClass(), false);
1031
1032 CElement* pLocatedElement = NULL;
1033
1034 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1035
Patrick Benavoli63499d42011-10-24 18:50:03 +02001036 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001037 }
1038
1039 strResult = string("\n");
1040
1041 if (!pLocatedElement) {
1042
1043 // List from root folder
1044
1045 // Return system class qualified name
1046 pLocatedElement = getSystemClass();
1047 }
1048
1049 // Return sub-elements
1050 strResult += pLocatedElement->listQualifiedPaths(false);
1051
Patrick Benavoli63499d42011-10-24 18:50:03 +02001052 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001053}
1054
1055/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001056CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listParametersCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001057{
1058 CElementLocator elementLocator(getSystemClass(), false);
1059
1060 CElement* pLocatedElement = NULL;
1061
1062 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1063
Patrick Benavoli63499d42011-10-24 18:50:03 +02001064 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001065 }
1066
1067 strResult = string("\n");
1068
1069 if (!pLocatedElement) {
1070
1071 // List from root folder
1072
1073 // Return system class qualified name
1074 pLocatedElement = getSystemClass();
1075 }
1076
1077 // Return sub-elements
1078 strResult += pLocatedElement->listQualifiedPaths(true);
1079
Patrick Benavoli63499d42011-10-24 18:50:03 +02001080 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001081}
1082
Patrick Benavoli63499d42011-10-24 18:50:03 +02001083CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001084{
1085 CElementLocator elementLocator(getSystemClass());
1086
1087 CElement* pLocatedElement = NULL;
1088
1089 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1090
Patrick Benavoli63499d42011-10-24 18:50:03 +02001091 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001092 }
1093
1094 string strError;
1095
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001096 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001097
1098 // Dump elements
1099 pLocatedElement->dumpContent(strResult, parameterAccessContext);
1100
Patrick Benavoli63499d42011-10-24 18:50:03 +02001101 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001102}
1103
Patrick Benavoli63499d42011-10-24 18:50:03 +02001104CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSizeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001105{
1106 CElementLocator elementLocator(getSystemClass());
1107
1108 CElement* pLocatedElement = NULL;
1109
1110 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1111
Patrick Benavoli63499d42011-10-24 18:50:03 +02001112 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001113 }
1114
1115 // Converted to actual sizable element
1116 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1117
1118 // Get size as string
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001119 strResult = pConfigurableElement->getFootprintAsString();
Patrick Benavoli68a91282011-08-31 11:23:23 +02001120
Patrick Benavoli63499d42011-10-24 18:50:03 +02001121 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001122}
1123
Patrick Benavoli63499d42011-10-24 18:50:03 +02001124CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showPropertiesCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001125{
1126 CElementLocator elementLocator(getSystemClass());
1127
1128 CElement* pLocatedElement = NULL;
1129
1130 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1131
Patrick Benavoli63499d42011-10-24 18:50:03 +02001132 return CCommandHandler::EFailed;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001133 }
1134
1135 // Convert element
1136 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1137
1138 // Return element properties
1139 pConfigurableElement->showProperties(strResult);
1140
Patrick Benavoli63499d42011-10-24 18:50:03 +02001141 return CCommandHandler::ESucceeded;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001142}
1143
Patrick Benavoli63499d42011-10-24 18:50:03 +02001144CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001145{
1146 string strValue;
1147
Patrick Benavoli065264a2011-11-20 15:46:41 +01001148 if (!accessValue(remoteCommand.getArgument(0), strValue, false, strResult)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001149
Patrick Benavoli63499d42011-10-24 18:50:03 +02001150 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001151 }
1152 // Succeeded
1153 strResult = strValue;
1154
Patrick Benavoli63499d42011-10-24 18:50:03 +02001155 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001156}
1157
Patrick Benavoli63499d42011-10-24 18:50:03 +02001158CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001159{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001160 // Check tuning mode
1161 if (!checkTuningModeOn(strResult)) {
1162
1163 return CCommandHandler::EFailed;
1164 }
1165 // Get value to set
1166 string strValue = remoteCommand.packArguments(1, remoteCommand.getArgumentCount() - 1);
1167
1168 return accessValue(remoteCommand.getArgument(0), strValue, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001169}
1170
Patrick Benavoli63499d42011-10-24 18:50:03 +02001171CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listBelongingDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001172{
1173 CElementLocator elementLocator(getSystemClass());
1174
1175 CElement* pLocatedElement = NULL;
1176
1177 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1178
Patrick Benavoli63499d42011-10-24 18:50:03 +02001179 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001180 }
1181
1182 // Convert element
1183 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1184
1185 // Return element belonging domains
1186 pConfigurableElement->listBelongingDomains(strResult);
1187
Patrick Benavoli63499d42011-10-24 18:50:03 +02001188 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001189}
1190
Patrick Benavoli63499d42011-10-24 18:50:03 +02001191CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001192{
1193 CElementLocator elementLocator(getSystemClass());
1194
1195 CElement* pLocatedElement = NULL;
1196
1197 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1198
Patrick Benavoli63499d42011-10-24 18:50:03 +02001199 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001200 }
1201
1202 // Convert element
1203 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1204
1205 // Return element belonging domains
1206 pConfigurableElement->listAssociatedDomains(strResult);
1207
Patrick Benavoli63499d42011-10-24 18:50:03 +02001208 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001209}
1210
Patrick Benavoli63499d42011-10-24 18:50:03 +02001211CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001212{
1213 (void)remoteCommand;
1214
1215 getConfigurableDomains()->listAssociatedElements(strResult);
1216
Patrick Benavoli63499d42011-10-24 18:50:03 +02001217 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001218}
1219
Patrick Benavoli63499d42011-10-24 18:50:03 +02001220CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConflictingElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001221{
1222 (void)remoteCommand;
1223
1224 getConfigurableDomains()->listConflictingElements(strResult);
1225
Patrick Benavoli63499d42011-10-24 18:50:03 +02001226 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001227}
1228
Patrick Benavoli63499d42011-10-24 18:50:03 +02001229CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listRogueElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001230{
1231 (void)remoteCommand;
1232
1233 getSystemClass()->listRogueElements(strResult);
1234
Patrick Benavoli63499d42011-10-24 18:50:03 +02001235 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001236}
1237
1238/// Settings Import/Export
Patrick Benavoli63499d42011-10-24 18:50:03 +02001239CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001240{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001241 return exportDomainsXml(remoteCommand.getArgument(0), false, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001242}
1243
Patrick Benavoli63499d42011-10-24 18:50:03 +02001244CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001245{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001246 return importDomainsXml(remoteCommand.getArgument(0), false, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001247}
1248
Patrick Benavoli63499d42011-10-24 18:50:03 +02001249CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001250{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001251 return exportDomainsXml(remoteCommand.getArgument(0), true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001252}
1253
Patrick Benavoli63499d42011-10-24 18:50:03 +02001254CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001255{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001256 return importDomainsXml(remoteCommand.getArgument(0), true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001257}
1258
Patrick Benavoli63499d42011-10-24 18:50:03 +02001259CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001260{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001261 return exportDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001262}
1263
Patrick Benavoli63499d42011-10-24 18:50:03 +02001264CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001265{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001266 return importDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001267}
1268
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001269/// GUI commands
1270
1271CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getDomainsXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1272{
1273 (void)remoteCommand;
1274
1275 if (!getDomainsXMLString(strResult, true)) {
1276
1277 return CCommandHandler::EFailed;
1278 }
1279 // Succeeded
1280 return CCommandHandler::ESucceeded;
1281}
1282
1283CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getSystemClassXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1284{
1285 (void)remoteCommand;
1286
1287 if (!getSystemClassXMLString(strResult)) {
1288
1289 return CCommandHandler::EFailed;
1290 }
1291 // Succeeded
1292 return CCommandHandler::ESucceeded;
1293}
1294
Patrick Benavoli68a91282011-08-31 11:23:23 +02001295// User set/get parameters
Patrick Benavoli065264a2011-11-20 15:46:41 +01001296bool CParameterMgr::accessValue(const string& strPath, string& strValue, bool bSet, string& strError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001297{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001298 // Lock state
1299 CAutoLock autoLock(&_blackboardMutex);
1300
1301 CPathNavigator pathNavigator(strPath);
1302
1303 // Nagivate through system class
1304 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001305
1306 return false;
1307 }
1308
Patrick Benavoli065264a2011-11-20 15:46:41 +01001309 // Define context
1310 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001311
Patrick Benavoli68808c62012-02-02 17:12:41 +01001312 // Auto Sync
1313 if (bSet) {
1314
1315 parameterAccessContext.setAutoSync(_bAutoSyncOn);
1316 }
1317
Patrick Benavoli065264a2011-11-20 15:46:41 +01001318 // Do the get
1319 return getConstSystemClass()->accessValue(pathNavigator, strValue, bSet, parameterAccessContext);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001320}
1321
1322// Tuning mode
1323bool CParameterMgr::setTuningMode(bool bOn, string& strError)
1324{
1325 // Tuning allowed?
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001326 if (bOn && !getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001327
1328 strError = "Tuning prohibited";
1329
1330 return false;
1331 }
1332 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +01001333 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001334
1335 // Warn domains about exiting tuning mode
1336 if (!bOn && _bTuningModeIsOn) {
1337
1338 // Ensure application of currently selected configurations
Patrick Benavoli1387bda2011-08-31 11:23:24 +02001339 // Force-apply configurations
Patrick Benavoli68a91282011-08-31 11:23:23 +02001340 if (!getConfigurableDomains()->apply(_pMainParameterBlackboard, true, strError)) {
1341
1342 return false;
1343 }
1344 // Turn auto sync back on
1345 _bAutoSyncOn = true;
1346 }
1347
1348 // Store
1349 _bTuningModeIsOn = bOn;
1350
Patrick Benavoli68a91282011-08-31 11:23:23 +02001351 return true;
1352}
1353
1354bool CParameterMgr::tuningModeOn() const
1355{
1356 return _bTuningModeIsOn;
1357}
1358
1359// Current value space for user set/get value interpretation
1360void CParameterMgr::setValueSpace(bool bIsRaw)
1361{
1362 _bValueSpaceIsRaw = bIsRaw;
1363}
1364
1365bool CParameterMgr::valueSpaceIsRaw()
1366{
1367 return _bValueSpaceIsRaw;
1368}
1369
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001370// Current Output Raw Format for user get value interpretation
1371void CParameterMgr::setOutputRawFormat(bool bIsHex)
1372{
1373 _bOutputRawFormatIsHex = bIsHex;
1374}
1375
1376bool CParameterMgr::outputRawFormatIsHex()
1377{
1378 return _bOutputRawFormatIsHex;
1379}
1380
Patrick Benavoli68a91282011-08-31 11:23:23 +02001381/// Sync
1382// Automatic hardware synchronization control (during tuning session)
1383bool CParameterMgr::setAutoSync(bool bAutoSyncOn, string& strError)
1384{
1385 // Check tuning mode
1386 if (!checkTuningModeOn(strError)) {
1387
1388 return false;
1389 }
1390 // Warn domains about turning auto sync back on
1391 if (bAutoSyncOn && !_bAutoSyncOn) {
1392
Patrick Benavoli592ae562011-09-05 16:53:58 +02001393 // Do the synchronization at system class level (could be optimized by keeping track of all modified parameters)
1394 if (!sync(strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001395
1396 return false;
1397 }
1398 }
1399
1400 // Set Auto sync
1401 _bAutoSyncOn = bAutoSyncOn;
1402
1403 return true;
1404}
1405
1406bool CParameterMgr::autoSyncOn() const
1407{
1408 return _bAutoSyncOn;
1409}
1410
1411// Manual hardware synchronization control (during tuning session)
1412bool CParameterMgr::sync(string& strError)
1413{
1414 // Check tuning mode
1415 if (!checkTuningModeOn(strError)) {
1416
1417 return false;
1418 }
1419 // Warn domains about turning auto sync back on
1420 if (_bAutoSyncOn) {
1421
1422 strError = "Feature unavailable when Auto Sync is on";
1423
1424 return false;
1425 }
1426
1427 // Get syncer set
1428 CSyncerSet syncerSet;
1429 // ... from system class
1430 getConstSystemClass()->fillSyncerSet(syncerSet);
1431 // Sync
1432 return syncerSet.sync(*_pMainParameterBlackboard, false, strError);
1433}
1434
1435// Content dump
1436void CParameterMgr::logStructureContent(string& strContent) const
1437{
1438 string strError;
1439
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001440 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001441
1442 dumpContent(strContent, parameterAccessContext);
1443}
1444
1445// Configuration/Domains handling
1446bool CParameterMgr::createDomain(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()->createDomain(strName, strError);
1456}
1457
1458bool CParameterMgr::deleteDomain(const string& strName, string& strError)
1459{
1460 // Check tuning mode
1461 if (!checkTuningModeOn(strError)) {
1462
1463 return false;
1464 }
1465
1466 // Delegate to configurable domains
1467 return getConfigurableDomains()->deleteDomain(strName, strError);
1468}
1469
Kevin Rocard170f0a42012-06-18 13:56:05 +02001470bool CParameterMgr::deleteAllDomains(string& strError)
1471{
1472 // Check tuning mode
1473 if (!checkTuningModeOn(strError)) {
1474
1475 return false;
1476 }
1477
1478 // Delegate to configurable domains
1479 getConfigurableDomains()->deleteAllDomains();
1480
1481 return true;
1482}
1483
Patrick Benavoli68a91282011-08-31 11:23:23 +02001484bool CParameterMgr::createConfiguration(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()->createConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1494}
1495
1496bool CParameterMgr::deleteConfiguration(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
1505 return getConfigurableDomains()->deleteConfiguration(strDomain, strConfiguration, strError);
1506}
1507
1508bool CParameterMgr::restoreConfiguration(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
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001517 return getConstConfigurableDomains()->restoreConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001518}
1519
1520bool CParameterMgr::saveConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1521{
1522 // Check tuning mode
1523 if (!checkTuningModeOn(strError)) {
1524
1525 return false;
1526 }
1527
1528 // Delegate to configurable domains
1529 return getConfigurableDomains()->saveConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1530}
1531
1532// Configurable element - domain association
1533bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1534{
1535 // Check tuning mode
1536 if (!checkTuningModeOn(strError)) {
1537
1538 return false;
1539 }
1540
1541 CElementLocator elementLocator(getSystemClass());
1542
1543 CElement* pLocatedElement = NULL;
1544
1545 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1546
1547 return false;
1548 }
1549
1550 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001551 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001552
1553 // Delegate
1554 return getConfigurableDomains()->addConfigurableElementToDomain(strDomain, pConfigurableElement, _pMainParameterBlackboard, strError);
1555}
1556
1557bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1558{
1559 // Check tuning mode
1560 if (!checkTuningModeOn(strError)) {
1561
1562 return false;
1563 }
1564
1565 CElementLocator elementLocator(getSystemClass());
1566
1567 CElement* pLocatedElement = NULL;
1568
1569 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1570
Patrick Benavoli63499d42011-10-24 18:50:03 +02001571 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001572 }
1573
1574 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001575 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001576
1577 // Delegate
1578 return getConfigurableDomains()->removeConfigurableElementFromDomain(strDomain, pConfigurableElement, strError);
1579}
1580
1581bool CParameterMgr::split(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1582{
1583 // Check tuning mode
1584 if (!checkTuningModeOn(strError)) {
1585
1586 return false;
1587 }
1588
1589 CElementLocator elementLocator(getSystemClass());
1590
1591 CElement* pLocatedElement = NULL;
1592
1593 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1594
Patrick Benavoli63499d42011-10-24 18:50:03 +02001595 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001596 }
1597
1598 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001599 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001600
1601 // Delegate
1602 return getConfigurableDomains()->split(strDomain, pConfigurableElement, strError);
1603}
1604
1605// XML Import/Export
1606bool CParameterMgr::importDomainsXml(const string& strFileName, bool bWithSettings, string& strError)
1607{
1608 // Check tuning mode
1609 if (!checkTuningModeOn(strError)) {
1610
1611 return false;
1612 }
1613
1614 // check path is absolute
1615 if (strFileName[0] != '/') {
1616
1617 strError = "Please provide absolute path";
1618
1619 return false;
1620 }
1621 // Root element
1622 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1623
1624 // Context
1625 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1626
1627 // Secltion criteria definition for rule creation
1628 xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
1629
1630 // Parse
1631 if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strFileName, "", EParameterConfigurationLibrary, "SystemClassName")) {
1632
1633 return false;
1634 }
1635
1636 // Validate domains after XML import
1637 pConfigurableDomains->validate(_pMainParameterBlackboard);
1638
1639 return true;
1640}
1641
1642bool CParameterMgr::exportDomainsXml(const string& strFileName, bool bWithSettings, string& strError) const
1643{
1644 // check path is absolute
1645 if (strFileName[0] != '/') {
1646
1647 strError = "Please provide absolute path";
1648
1649 return false;
1650 }
1651
1652 // Root element
1653 const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains();
1654
1655 // Get Schema file associated to root element
1656 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pConfigurableDomains->getKind() + ".xsd";
1657
1658 // Context
1659 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1660
1661 // Value space
1662 xmlDomainSerializingContext.setValueSpaceRaw(_bValueSpaceIsRaw);
1663
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001664 // Output raw format
1665 xmlDomainSerializingContext.setOutputRawFormat(_bOutputRawFormatIsHex);
1666
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001667 // Use a doc source by loading data from instantiated Configurable Domains
1668 CXmlMemoryDocSource memorySource(pConfigurableDomains, pConfigurableDomains->getKind(), strXmlSchemaFilePath, "parameter-framework", getVersion());
Patrick Benavoli68a91282011-08-31 11:23:23 +02001669
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001670 // Use a doc sink to write the doc data in a file
1671 CXmlFileDocSink fileSink(strFileName);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001672
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001673 if (!fileSink.process(memorySource, xmlDomainSerializingContext)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001674 return false;
1675 }
1676
1677 return true;
1678}
1679
1680// Binary Import/Export
1681bool CParameterMgr::importDomainsBinary(const string& strFileName, string& strError)
1682{
1683 // Check tuning mode
1684 if (!checkTuningModeOn(strError)) {
1685
1686 return false;
1687 }
1688 // check path is absolute
1689 if (strFileName[0] != '/') {
1690
1691 strError = "Please provide absolute path";
1692
1693 return false;
1694 }
1695 // Root element
1696 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1697
1698 // Serialize in
1699 return pConfigurableDomains->serializeSettings(strFileName, false, _uiStructureChecksum, strError);
1700}
1701
1702bool CParameterMgr::exportDomainsBinary(const string& strFileName, string& strError)
1703{
1704 // check path is absolute
1705 if (strFileName[0] != '/') {
1706
1707 strError = "Please provide absolute path";
1708
1709 return false;
1710 }
Patrick Benavoli68a91282011-08-31 11:23:23 +02001711
Patrick Benavoli68a91282011-08-31 11:23:23 +02001712 // Root element
1713 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1714
1715 // Serialize out
1716 return pConfigurableDomains->serializeSettings(strFileName, true, _uiStructureChecksum, strError);
1717}
1718
1719// For tuning, check we're in tuning mode
1720bool CParameterMgr::checkTuningModeOn(string& strError) const
1721{
1722 // Tuning Mode on?
1723 if (!_bTuningModeIsOn) {
1724
1725 strError = "Tuning Mode must be on";
1726
1727 return false;
1728 }
1729 return true;
1730}
1731
Patrick Benavoli065264a2011-11-20 15:46:41 +01001732// Tuning mutex dynamic parameter handling
1733pthread_mutex_t* CParameterMgr::getBlackboardMutex()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001734{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001735 return &_blackboardMutex;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001736}
1737
Patrick Benavoli065264a2011-11-20 15:46:41 +01001738// Blackboard reference (dynamic parameter handling)
1739CParameterBlackboard* CParameterMgr::getParameterBlackboard()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001740{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001741 return _pMainParameterBlackboard;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001742}
1743
Patrick Benavoli68a91282011-08-31 11:23:23 +02001744// Dynamic creation library feeding
1745void CParameterMgr::feedElementLibraries()
1746{
1747 // Global Configuration handling
1748 CElementLibrary* pFrameworkConfigurationLibrary = new CElementLibrary;
1749
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001750 pFrameworkConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CParameterFrameworkConfiguration>("ParameterFrameworkConfiguration"));
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +01001751 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CSubsystemPlugins>("SubsystemPlugins"));
1752 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CPluginLocation>("Location"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001753 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("StructureDescriptionFileLocation"));
1754 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationGroup>("SettingsConfiguration"));
1755 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("ConfigurableDomainsFileLocation"));
1756 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("BinarySettingsFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001757
1758 _pElementLibrarySet->addElementLibrary(pFrameworkConfigurationLibrary);
1759
1760 // Parameter creation
1761 CElementLibrary* pParameterCreationLibrary = new CElementLibrary;
1762
1763 pParameterCreationLibrary->addElementBuilder(new CSubsystemElementBuilder(getSystemClass()->getSubsystemLibrary()));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001764 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CComponentType>("ComponentType"));
1765 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CComponentInstance>("Component"));
1766 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBitParameterType>("BitParameter"));
1767 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBitParameterBlockType>("BitParameterBlock"));
Patrick Benavoli1352ae52011-10-21 16:48:04 +02001768 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CStringParameterType>("StringParameter"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001769 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CParameterBlockType>("ParameterBlock"));
1770 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBooleanParameterType>("BooleanParameter"));
1771 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CIntegerParameterType>("IntegerParameter"));
Patrick Benavoliee65e6d2011-11-20 18:52:24 +01001772 pParameterCreationLibrary->addElementBuilder(new TElementBuilderTemplate<CLinearParameterAdaptation>("LinearAdaptation"));
Patrick Benavoli9fc3c0d2011-10-27 14:27:27 +02001773 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CEnumParameterType>("EnumParameter"));
Patrick Benavoli68808c62012-02-02 17:12:41 +01001774 pParameterCreationLibrary->addElementBuilder(new TElementBuilderTemplate<CEnumValuePair>("ValuePair"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001775 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CFixedPointParameterType>("FixedPointParameter"));
1776 pParameterCreationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CXmlFileIncluderElement>("SubsystemInclude"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001777
1778 _pElementLibrarySet->addElementLibrary(pParameterCreationLibrary);
1779
1780 // Parameter Configuration Domains creation
1781 CElementLibrary* pParameterConfigurationLibrary = new CElementLibrary;
1782
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001783 pParameterConfigurationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CConfigurableDomain>("ConfigurableDomain"));
1784 pParameterConfigurationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CDomainConfiguration>("Configuration"));
1785 pParameterConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CCompoundRule>("CompoundRule"));
1786 pParameterConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CSelectionCriterionRule>("SelectionCriterionRule"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001787
1788 _pElementLibrarySet->addElementLibrary(pParameterConfigurationLibrary);
1789}
1790
1791// Remote Processor Server connection handling
1792bool CParameterMgr::handleRemoteProcessingInterface(string& strError)
1793{
1794 CAutoLog autoLog(this, "Handling remote processing interface");
1795
1796 // Start server if tuning allowed
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001797 if (getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001798
1799 log("Loading remote processor library");
1800
1801 // Load library
1802 void* lib_handle = dlopen("libremote-processor.so", RTLD_NOW);
1803
1804 if (!lib_handle) {
1805
1806 // Return error
1807 const char* pcError = dlerror();
1808
1809 if (pcError) {
1810
1811 strError = pcError;
1812 } else {
1813
1814 strError = "Unable to load libremote-processor.so library";
1815 }
1816
1817 return false;
1818 }
1819
1820 CreateRemoteProcessorServer pfnCreateRemoteProcessorServer = (CreateRemoteProcessorServer)dlsym(lib_handle, "createRemoteProcessorServer");
1821
1822 if (!pfnCreateRemoteProcessorServer) {
1823
1824 strError = "libremote-process.so does not contain createRemoteProcessorServer symbol.";
1825
1826 return false;
1827 }
1828
1829 // Create server
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001830 _pRemoteProcessorServer = pfnCreateRemoteProcessorServer(getConstFrameworkConfiguration()->getServerPort(), _pCommandHandler);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001831
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001832 log("Starting remote processor server on port %d", getConstFrameworkConfiguration()->getServerPort());
Patrick Benavoli68a91282011-08-31 11:23:23 +02001833 // Start
1834 if (!_pRemoteProcessorServer->start()) {
1835
1836 strError = "Unable to start remote processor server";
1837
1838 return false;
1839 }
1840 }
1841
1842 return true;
1843}
1844
1845// Back synchronization
1846CBackSynchronizer* CParameterMgr::createBackSynchronizer(string& strError) const
1847{
1848#ifdef SIMULATION
1849 // In simulation, back synchronization of the blackboard won't probably work
1850 // We need to ensure though the blackboard is initialized with valid data
1851 return new CSimulatedBackSynchronizer(getConstSystemClass(), strError, _pMainParameterBlackboard);
1852#else
1853 // Real back synchronizer from subsystems
1854 return new CHardwareBackSynchronizer(getConstSystemClass(), strError, _pMainParameterBlackboard);
1855#endif
1856}
1857
1858// Children typwise access
1859CParameterFrameworkConfiguration* CParameterMgr::getFrameworkConfiguration()
1860{
1861 return static_cast<CParameterFrameworkConfiguration*>(getChild(EFrameworkConfiguration));
1862}
1863
1864const CParameterFrameworkConfiguration* CParameterMgr::getConstFrameworkConfiguration()
1865{
1866 return getFrameworkConfiguration();
1867}
1868
1869CSelectionCriteria* CParameterMgr::getSelectionCriteria()
1870{
1871 return static_cast<CSelectionCriteria*>(getChild(ESelectionCriteria));
1872}
1873
1874const CSelectionCriteria* CParameterMgr::getConstSelectionCriteria()
1875{
1876 return static_cast<const CSelectionCriteria*>(getChild(ESelectionCriteria));
1877}
1878
1879CSystemClass* CParameterMgr::getSystemClass()
1880{
1881 return static_cast<CSystemClass*>(getChild(ESystemClass));
1882}
1883
1884const CSystemClass* CParameterMgr::getConstSystemClass() const
1885{
1886 return static_cast<const CSystemClass*>(getChild(ESystemClass));
1887}
1888
1889// Configurable Domains
1890CConfigurableDomains* CParameterMgr::getConfigurableDomains()
1891{
1892 return static_cast<CConfigurableDomains*>(getChild(EConfigurableDomains));
1893}
1894
1895const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains()
1896{
1897 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
1898}
1899
1900const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains() const
1901{
1902 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
1903}
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001904
1905/// GUI commands functions
1906
1907bool CParameterMgr::getDomainsXMLString(string& strResult, bool bWithSettings)
1908{
1909
1910 // Root element
1911 const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains();
1912
1913 // Get Schema file associated to root element
1914 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pConfigurableDomains->getKind() + ".xsd";
1915
1916 string strError;
1917
1918 // Context
1919 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1920
1921 // Value space
1922 xmlDomainSerializingContext.setValueSpaceRaw(_bValueSpaceIsRaw);
1923
1924 // Output raw format
1925 xmlDomainSerializingContext.setOutputRawFormat(_bOutputRawFormatIsHex);
1926
1927 // Use a doc source by loading data from instantiated Configurable Domains
1928 CXmlMemoryDocSource memorySource(pConfigurableDomains, pConfigurableDomains->getKind(), strXmlSchemaFilePath, "parameter-framework", getVersion());
1929
1930 // Use a doc sink the write the doc data in a string
1931 CXmlStringDocSink stringSink(strResult);
1932
1933 if (!stringSink.process(memorySource, xmlDomainSerializingContext)) {
1934 strResult = strError;
1935
1936 return false;
1937 }
1938
1939 return true;
1940}
1941
1942bool CParameterMgr::getSystemClassXMLString(string& strResult)
1943{
1944 // Root element
1945 const CSystemClass* pSystemClass = getSystemClass();
1946
1947 string strError;
1948
1949 CXmlSerializingContext xmlSerializingContext(strError);
1950
1951 // Use a doc source by loading data from instantiated Configurable Domains
1952 CXmlMemoryDocSource memorySource(pSystemClass, pSystemClass->getKind());
1953
1954 // Use a doc sink that write the doc data in a string
1955 CXmlStringDocSink stringSink(strResult);
1956
1957 if (!stringSink.process(memorySource, xmlSerializingContext)) {
1958 strResult = strError;
1959 return false;
1960 }
1961
1962 return true;
1963}