blob: 14a5b4b0aec24c475043cb645991b96074d368fb [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 log("Main blackboard back synchronization");
336
337 // Back-synchronize
338 if (!pBackSynchronizer->sync()) {
339 // Get rid of back synchronizer
340 delete pBackSynchronizer;
341
342 strError = "Main blackboard back synchronization failed: " + strError;
343
344 return false;
345 }
346 // Get rif of back synchronizer
347 delete pBackSynchronizer;
348
349 // We're done loading the settings and back synchronizing
350 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
351
352 // We need to ensure all domains are valid
353 pConfigurableDomains->validate(_pMainParameterBlackboard);
354
355 // Ensure application of currently selected configurations
356 // Force-apply configurations
357 if (!pConfigurableDomains->apply(_pMainParameterBlackboard, true, strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200358
359 return false;
360 }
361
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200362 // Start remote processor server if appropriate
363 return handleRemoteProcessingInterface(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200364}
365
366bool CParameterMgr::loadFrameworkConfiguration(string& strError)
367{
368 CAutoLog autoLog(this, "Loading framework configuration");
369
Patrick Benavoli68a91282011-08-31 11:23:23 +0200370 // Parse Structure XML file
371 CXmlElementSerializingContext elementSerializingContext(strError);
372
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100373 if (!xmlParse(elementSerializingContext, getFrameworkConfiguration(), _strXmlConfigurationFilePath, _strXmlConfigurationFolderPath, EFrameworkConfigurationLibrary)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200374
375 return false;
376 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100377 // Set class name to system class and configurable domains
378 getSystemClass()->setName(getConstFrameworkConfiguration()->getSystemClassName());
379 getConfigurableDomains()->setName(getConstFrameworkConfiguration()->getSystemClassName());
380
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100381 // Get subsystem plugins elements
382 _pSubsystemPlugins = static_cast<const CSubsystemPlugins*>(getConstFrameworkConfiguration()->findChild("SubsystemPlugins"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200383
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100384 if (!_pSubsystemPlugins) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200385
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100386 strError = "Parameter Framework Configuration: couldn't find SubsystemPlugins element";
Patrick Benavoli68a91282011-08-31 11:23:23 +0200387
388 return false;
389 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200390
Patrick Benavoli68a91282011-08-31 11:23:23 +0200391 // Log tuning availability
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100392 log("Tuning %s", getConstFrameworkConfiguration()->isTuningAllowed() ? "allowed" : "prohibited");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200393
394 return true;
395}
396
397bool CParameterMgr::loadStructure(string& strError)
398{
399 // Retrieve system to load structure to
400 CSystemClass* pSystemClass = getSystemClass();
401
402 CAutoLog autoLog(this, "Loading " + pSystemClass->getName() + " system class structure");
403
404 // Get structure description element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100405 const CFrameworkConfigurationLocation* pStructureDescriptionFileLocation = static_cast<const CFrameworkConfigurationLocation*>(getConstFrameworkConfiguration()->findChildOfKind("StructureDescriptionFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200406
407 if (!pStructureDescriptionFileLocation) {
408
409 strError = "No StructureDescriptionFileLocation element found for SystemClass " + pSystemClass->getName();
410
411 return false;
412 }
413
414 // Get Xml structure folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100415 string strXmlStructureFolder = pStructureDescriptionFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200416
417 // Get Xml structure file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100418 string strXmlStructureFilePath = pStructureDescriptionFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200419
420 // Parse Structure XML file
421 CXmlParameterSerializingContext parameterBuildContext(strError);
422
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200423 log("Importing system structure from file %s", strXmlStructureFilePath.c_str());
424
Patrick Benavoli68a91282011-08-31 11:23:23 +0200425 if (!xmlParse(parameterBuildContext, pSystemClass, strXmlStructureFilePath, strXmlStructureFolder, EParameterCreationLibrary)) {
426
427 return false;
428 }
429
430 // Initialize offsets
431 pSystemClass->setOffset(0);
432
433 // Initialize main blackboard's size
434 _pMainParameterBlackboard->setSize(pSystemClass->getFootPrint());
435
436 return true;
437}
438
439bool CParameterMgr::loadSettings(string& strError)
440{
441 CAutoLog autoLog(this, "Loading settings");
442
443 // Get settings configuration element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100444 const CFrameworkConfigurationGroup* pParameterConfigurationGroup = static_cast<const CFrameworkConfigurationGroup*>(getConstFrameworkConfiguration()->findChildOfKind("SettingsConfiguration"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200445
446 if (!pParameterConfigurationGroup) {
447
448 // No settings to load
449
450 return true;
451 }
452 // Get binary settings file location
453 const CFrameworkConfigurationLocation* pBinarySettingsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("BinarySettingsFileLocation"));
454
455 string strXmlBinarySettingsFilePath;
456
457 if (pBinarySettingsFileLocation) {
458
459 // Get Xml binary settings file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100460 strXmlBinarySettingsFilePath = pBinarySettingsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200461 }
462
463 // Get configurable domains element
464 const CFrameworkConfigurationLocation* pConfigurableDomainsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("ConfigurableDomainsFileLocation"));
465
466 if (!pConfigurableDomainsFileLocation) {
467
468 strError = "No ConfigurableDomainsFileLocation element found for SystemClass " + getSystemClass()->getName();
469
470 return false;
471 }
472 // Get destination root element
473 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
474
475 // Get Xml configuration domains file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100476 string strXmlConfigurationDomainsFilePath = pConfigurableDomainsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200477
478 // Get Xml configuration domains folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100479 string strXmlConfigurationDomainsFolder = pConfigurableDomainsFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200480
481 // Parse configuration domains XML file (ask to read settings from XML file if they are not provided as binary)
482 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, !pBinarySettingsFileLocation);
483
484 // Selection criteria definition for rule creation
485 xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
486
Patrick Benavoli63499d42011-10-24 18:50:03 +0200487 // Auto validation of configurations if no binary settings provided
488 xmlDomainSerializingContext.setAutoValidationRequired(!pBinarySettingsFileLocation);
489
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200490 log("Importing configurable domains from file %s %s settings", strXmlConfigurationDomainsFilePath.c_str(), pBinarySettingsFileLocation ? "without" : "with");
491
Patrick Benavoli68a91282011-08-31 11:23:23 +0200492 // Do parse
493 if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strXmlConfigurationDomainsFilePath, strXmlConfigurationDomainsFolder, EParameterConfigurationLibrary, "SystemClassName")) {
494
495 return false;
496 }
497 // We have loaded the whole system structure, compute checksum
498 const CSystemClass* pSystemClass = getConstSystemClass();
499 _uiStructureChecksum = pSystemClass->computeStructureChecksum() + getConfigurableDomains()->computeStructureChecksum() + getSelectionCriteria()->computeStructureChecksum();
500
501 // Load binary settings if any provided
502 if (pBinarySettingsFileLocation && !pConfigurableDomains->serializeSettings(strXmlBinarySettingsFilePath, false, _uiStructureChecksum, strError)) {
503
504 return false;
505 }
506
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200507 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200508}
509
510// XML parsing
511bool CParameterMgr::xmlParse(CXmlElementSerializingContext& elementSerializingContext, CElement* pRootElement, const string& strXmlFilePath, const string& strXmlFolder, CParameterMgr::ElementLibrary eElementLibrary, const string& strNameAttrituteName)
512{
513 // Init serializing context
514 elementSerializingContext.set(_pElementLibrarySet->getElementLibrary(eElementLibrary), strXmlFolder, _strSchemaFolderLocation);
515
516 // Get Schema file associated to root element
517 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pRootElement->getKind() + ".xsd";
518
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200519 CXmlFileDocSource fileDocSource(strXmlFilePath, strXmlSchemaFilePath, pRootElement->getKind(), pRootElement->getName(), strNameAttrituteName);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200520
521 // Start clean
522 pRootElement->clean();
523
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200524 CXmlMemoryDocSink memorySink(pRootElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200525
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200526 if (!memorySink.process(fileDocSource, elementSerializingContext)) {
527 //Cleanup
Patrick Benavoli68a91282011-08-31 11:23:23 +0200528 pRootElement->clean();
529
530 return false;
531 }
532
Patrick Benavoli68a91282011-08-31 11:23:23 +0200533 return true;
534}
535
536// Init
537bool CParameterMgr::init(string& strError)
538{
539 return base::init(strError);
540}
541
542// Selection criteria interface
543CSelectionCriterionType* CParameterMgr::createSelectionCriterionType(bool bIsInclusive)
544{
545 // Propagate
546 return getSelectionCriteria()->createSelectionCriterionType(bIsInclusive);
547}
548
549CSelectionCriterion* CParameterMgr::createSelectionCriterion(const string& strName, const CSelectionCriterionType* pSelectionCriterionType)
550{
551 // Propagate
552 return getSelectionCriteria()->createSelectionCriterion(strName, pSelectionCriterionType);
553}
554
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200555// Selection criterion retrieval
556CSelectionCriterion* CParameterMgr::getSelectionCriterion(const string& strName)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200557{
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200558 // Propagate
559 return getSelectionCriteria()->getSelectionCriterion(strName);
560}
561
562// Selection criteria changed event
563bool CParameterMgr::applyConfigurations(string& strError)
564{
565 CAutoLog autoLog(this, "Configuration application request");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200566
567 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +0100568 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200569
570 if (!_bTuningModeIsOn) {
571
572 // Apply configuration(s)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200573 if (!getConfigurableDomains()->apply(_pMainParameterBlackboard, false, strError)) {
574
575 log("Failed to apply configurations!");
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200576
577 return false;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200578 }
Frédéric Boisnarddaaa63c2012-08-27 15:48:15 +0200579
580 // Reset the modified status of the current criteria to indicate that a new configuration has been applied
581 getSelectionCriteria()->resetModifiedStatus();
582
583 } else {
584
585 log("Warning: Configurations were not applied because the TuningMode is on");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200586 }
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200587
588 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200589}
590
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200591// Dynamic parameter handling
Patrick Benavoli065264a2011-11-20 15:46:41 +0100592CParameterHandle* CParameterMgr::createParameterHandle(const string& strPath, string& strError)
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200593{
Patrick Benavoli065264a2011-11-20 15:46:41 +0100594 CPathNavigator pathNavigator(strPath);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200595
Patrick Benavoli065264a2011-11-20 15:46:41 +0100596 // Nagivate through system class
597 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
598
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100599 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100600 }
601
602 // Find element
603 const CElement* pElement = getConstSystemClass()->findDescendant(pathNavigator);
604
605 if (!pElement) {
606
607 strError = "Path not found";
608
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100609 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100610 }
611
612 // Check found element is a parameter
613 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pElement);
614
615 if (!pConfigurableElement->isParameter()) {
616
617 // Element is not parameter
618 strError = "Not a parameter";
619
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100620 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100621 }
622
623 // Convert as parameter and return new handle
624 return new CParameterHandle(static_cast<const CBaseParameter*>(pElement), this);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200625}
626
Patrick Benavoli68a91282011-08-31 11:23:23 +0200627/////////////////// Remote command parsers
Patrick Benavoli592ae562011-09-05 16:53:58 +0200628/// Version
Patrick Benavoli63499d42011-10-24 18:50:03 +0200629CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::versionCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli592ae562011-09-05 16:53:58 +0200630{
631 (void)remoteCommand;
632
Patrick Benavoli63499d42011-10-24 18:50:03 +0200633 // Show version
634 strResult = getVersion();
Patrick Benavoli592ae562011-09-05 16:53:58 +0200635
Patrick Benavoli63499d42011-10-24 18:50:03 +0200636 return CCommandHandler::ESucceeded;
Patrick Benavoli592ae562011-09-05 16:53:58 +0200637}
638
Patrick Benavoli68a91282011-08-31 11:23:23 +0200639/// Status
Patrick Benavoli63499d42011-10-24 18:50:03 +0200640CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::statusCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200641{
642 (void)remoteCommand;
643 // System class
644 const CSystemClass* pSystemClass = getSystemClass();
645
Patrick Benavoli68a91282011-08-31 11:23:23 +0200646 // Show status
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200647 /// General section
648 appendTitle(strResult, "General:");
649 // System class
Patrick Benavoli68a91282011-08-31 11:23:23 +0200650 strResult += "System Class: ";
651 strResult += pSystemClass->getName();
652 strResult += "\n";
653
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200654 // Tuning mode
Patrick Benavoli68a91282011-08-31 11:23:23 +0200655 strResult += "Tuning Mode: ";
656 strResult += tuningModeOn() ? "on" : "off";
657 strResult += "\n";
658
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200659 // Value space
Patrick Benavoli68a91282011-08-31 11:23:23 +0200660 strResult += "Value Space: ";
661 strResult += valueSpaceIsRaw() ? "raw" : "real";
662 strResult += "\n";
663
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200664 // Output raw format
665 strResult += "Output Raw Format: ";
666 strResult += outputRawFormatIsHex() ? "hex" : "dec";
667 strResult += "\n";
668
669 // Auto Sync
Patrick Benavoli68a91282011-08-31 11:23:23 +0200670 strResult += "Auto Sync: ";
671 strResult += autoSyncOn() ? "on" : "off";
672 strResult += "\n";
673
674 /// Subsystem list
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200675 appendTitle(strResult, "Subsystems:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200676 string strSubsystemList;
677 pSystemClass->listChildrenPaths(strSubsystemList);
678 strResult += strSubsystemList;
679
680 /// Last applied configurations
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200681 appendTitle(strResult, "Last applied configurations:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200682 string strLastAppliedConfigurations;
683 getConfigurableDomains()->listLastAppliedConfigurations(strLastAppliedConfigurations);
684 strResult += strLastAppliedConfigurations;
685
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200686 /// Criteria states
687 appendTitle(strResult, "Selection criteria:");
688 string strSelectionCriteria;
689 getSelectionCriteria()->listSelectionCriteria(strSelectionCriteria, false);
690 strResult += strSelectionCriteria;
691
Patrick Benavoli63499d42011-10-24 18:50:03 +0200692 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200693}
694
695/// Tuning Mode
Patrick Benavoli63499d42011-10-24 18:50:03 +0200696CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200697{
698 if (remoteCommand.getArgument(0) == "on") {
699
700 if (setTuningMode(true, strResult)) {
701
Patrick Benavoli63499d42011-10-24 18:50:03 +0200702 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200703 }
704 } else if (remoteCommand.getArgument(0) == "off") {
705
706 if (setTuningMode(false, strResult)) {
707
Patrick Benavoli63499d42011-10-24 18:50:03 +0200708 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200709 }
710 } else {
711 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200712 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200713 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200714 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200715}
716
Patrick Benavoli63499d42011-10-24 18:50:03 +0200717CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200718{
719 (void)remoteCommand;
720
721 strResult = tuningModeOn() ? "on" : "off";
722
Patrick Benavoli63499d42011-10-24 18:50:03 +0200723 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200724}
725
726/// Value Space
Patrick Benavoli63499d42011-10-24 18:50:03 +0200727CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200728{
729 (void)strResult;
730
731 if (remoteCommand.getArgument(0) == "raw") {
732
733 setValueSpace(true);
734
Patrick Benavoli63499d42011-10-24 18:50:03 +0200735 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200736
737 } else if (remoteCommand.getArgument(0) == "real") {
738
739 setValueSpace(false);
740
Patrick Benavoli63499d42011-10-24 18:50:03 +0200741 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200742
743 } else {
744 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200745 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200746 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200747 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200748}
749
Patrick Benavoli63499d42011-10-24 18:50:03 +0200750CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200751{
752 (void)remoteCommand;
753
754 strResult = valueSpaceIsRaw() ? "raw" : "real";
755
Patrick Benavoli63499d42011-10-24 18:50:03 +0200756 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200757}
758
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200759/// Output Raw Format
Patrick Benavoli63499d42011-10-24 18:50:03 +0200760CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200761{
762 (void)strResult;
763
764 if (remoteCommand.getArgument(0) == "hex") {
765
766 setOutputRawFormat(true);
767
Patrick Benavoli63499d42011-10-24 18:50:03 +0200768 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200769
770 } else if (remoteCommand.getArgument(0) == "dec") {
771
772 setOutputRawFormat(false);
773
Patrick Benavoli63499d42011-10-24 18:50:03 +0200774 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200775
776 } else {
777 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200778 return CCommandHandler::EShowUsage;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200779 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200780 return CCommandHandler::EFailed;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200781}
782
Patrick Benavoli63499d42011-10-24 18:50:03 +0200783CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200784{
785 (void)remoteCommand;
786
787 strResult = outputRawFormatIsHex() ? "hex" : "dec";
788
Patrick Benavoli63499d42011-10-24 18:50:03 +0200789 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200790}
791
Patrick Benavoli68a91282011-08-31 11:23:23 +0200792/// Sync
Patrick Benavoli63499d42011-10-24 18:50:03 +0200793CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200794{
795 if (remoteCommand.getArgument(0) == "on") {
796
797 if (setAutoSync(true, strResult)) {
798
Patrick Benavoli63499d42011-10-24 18:50:03 +0200799 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200800 }
801 } else if (remoteCommand.getArgument(0) == "off") {
802
803 if (setAutoSync(false, strResult)) {
804
Patrick Benavoli63499d42011-10-24 18:50:03 +0200805 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200806 }
807 } else {
808 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200809 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200810 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200811 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200812}
813
Patrick Benavoli63499d42011-10-24 18:50:03 +0200814CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200815{
816 (void)remoteCommand;
817
818 strResult = autoSyncOn() ? "on" : "off";
819
Patrick Benavoli63499d42011-10-24 18:50:03 +0200820 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200821}
822
Patrick Benavoli63499d42011-10-24 18:50:03 +0200823CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::syncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200824{
825 (void)remoteCommand;
826
Patrick Benavoli63499d42011-10-24 18:50:03 +0200827 return sync(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200828}
829
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200830/// Criteria
Patrick Benavoli63499d42011-10-24 18:50:03 +0200831CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listCriteriaCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200832{
833 (void)remoteCommand;
834
835 getSelectionCriteria()->listSelectionCriteria(strResult, true);
836
Patrick Benavoli63499d42011-10-24 18:50:03 +0200837 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200838}
Patrick Benavoli68a91282011-08-31 11:23:23 +0200839
840/// Domains
Patrick Benavoli63499d42011-10-24 18:50:03 +0200841CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200842{
843 (void)remoteCommand;
844
Patrick Benavoli63499d42011-10-24 18:50:03 +0200845 getConfigurableDomains()->listDomains(strResult);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200846
Patrick Benavoli63499d42011-10-24 18:50:03 +0200847 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200848}
849
Patrick Benavoli63499d42011-10-24 18:50:03 +0200850CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200851{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200852 return createDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200853}
854
Patrick Benavoli63499d42011-10-24 18:50:03 +0200855CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200856{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200857 return deleteDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200858}
859
Kevin Rocard170f0a42012-06-18 13:56:05 +0200860CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteAllDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
861{
862 (void)remoteCommand;
863
864 return deleteAllDomains(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
865}
866
Patrick Benavoli63499d42011-10-24 18:50:03 +0200867CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200868{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200869 return getConfigurableDomains()->renameDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200870}
871
Patrick Benavoli63499d42011-10-24 18:50:03 +0200872CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200873{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200874 // Check tuning mode
875 if (!checkTuningModeOn(strResult)) {
876
877 return CCommandHandler::EFailed;
878 }
879
880 // Set property
881 bool bSequenceAware;
882
883 if (remoteCommand.getArgument(1) == "true") {
884
885 bSequenceAware = true;
886
887 } else if (remoteCommand.getArgument(1) == "false") {
888
889 bSequenceAware = false;
890
891 } else {
892 // Show usage
893 return CCommandHandler::EShowUsage;
894 }
895
896 return getConfigurableDomains()->setSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200897}
898
Patrick Benavoli63499d42011-10-24 18:50:03 +0200899CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200900{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200901 // Get property
902 bool bSequenceAware;
903
904 if (!getConfigurableDomains()->getSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult)) {
905
906 return CCommandHandler::EFailed;
907 }
908
909 strResult = bSequenceAware ? "true" : "false";
910
911 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200912}
913
Patrick Benavoli63499d42011-10-24 18:50:03 +0200914CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200915{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200916 return getConfigurableDomains()->listDomainElements(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200917}
918
Patrick Benavoli63499d42011-10-24 18:50:03 +0200919CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::addElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200920{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200921 return addConfigurableElementToDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
922}
923
924CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::removeElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
925{
926 return removeConfigurableElementFromDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
927}
928
929CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::splitDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
930{
931 return split(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200932}
933
934/// Configurations
Patrick Benavoli63499d42011-10-24 18:50:03 +0200935CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConfigurationsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200936{
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100937 return getConstConfigurableDomains()->listConfigurations(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
938}
939
940CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
941{
942 (void)remoteCommand;
943
944 // Dummy error context
945 string strError;
946 CErrorContext errorContext(strError);
947
948 // Dump
949 getConstConfigurableDomains()->dumpContent(strResult, errorContext);
950
951 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200952}
953
Patrick Benavoli63499d42011-10-24 18:50:03 +0200954CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200955{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200956 return createConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200957}
958
Patrick Benavoli63499d42011-10-24 18:50:03 +0200959CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200960{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200961 return deleteConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200962}
963
Patrick Benavoli63499d42011-10-24 18:50:03 +0200964CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200965{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200966 return getConfigurableDomains()->renameConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200967}
968
Patrick Benavoli63499d42011-10-24 18:50:03 +0200969CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::saveConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200970{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200971 return saveConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200972}
973
Patrick Benavoli63499d42011-10-24 18:50:03 +0200974CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::restoreConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200975{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200976 return restoreConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
977}
978
979CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
980{
981 // Check tuning mode
982 if (!checkTuningModeOn(strResult)) {
983
984 return CCommandHandler::EFailed;
985 }
986
987 // Build configurable element path list
988 vector<string> astrNewElementSequence;
989
990 uint32_t uiArgument;
991
992 for (uiArgument = 2; uiArgument < remoteCommand.getArgumentCount(); uiArgument++) {
993
994 astrNewElementSequence.push_back(remoteCommand.getArgument(uiArgument));
995 }
996
997 // Delegate to configurable domains
998 return getConfigurableDomains()->setElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), astrNewElementSequence, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
999}
1000
1001CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1002{
1003 // Delegate to configurable domains
1004 return getConfigurableDomains()->getElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001005}
1006
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001007CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1008{
1009 // Delegate to configurable domains
1010 return getConfigurableDomains()->setApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.packArguments(2, remoteCommand.getArgumentCount() - 2), getConstSelectionCriteria()->getSelectionCriteriaDefinition(), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1011}
1012
1013CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::clearRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1014{
1015 // Delegate to configurable domains
1016 return getConfigurableDomains()->clearApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1017}
1018
1019CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1020{
1021 // Delegate to configurable domains
1022 return getConfigurableDomains()->getApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
1023}
1024
Patrick Benavoli68a91282011-08-31 11:23:23 +02001025/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001026CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001027{
1028 CElementLocator elementLocator(getSystemClass(), false);
1029
1030 CElement* pLocatedElement = NULL;
1031
1032 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1033
Patrick Benavoli63499d42011-10-24 18:50:03 +02001034 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001035 }
1036
1037 strResult = string("\n");
1038
1039 if (!pLocatedElement) {
1040
1041 // List from root folder
1042
1043 // Return system class qualified name
1044 pLocatedElement = getSystemClass();
1045 }
1046
1047 // Return sub-elements
1048 strResult += pLocatedElement->listQualifiedPaths(false);
1049
Patrick Benavoli63499d42011-10-24 18:50:03 +02001050 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001051}
1052
1053/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001054CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listParametersCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001055{
1056 CElementLocator elementLocator(getSystemClass(), false);
1057
1058 CElement* pLocatedElement = NULL;
1059
1060 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1061
Patrick Benavoli63499d42011-10-24 18:50:03 +02001062 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001063 }
1064
1065 strResult = string("\n");
1066
1067 if (!pLocatedElement) {
1068
1069 // List from root folder
1070
1071 // Return system class qualified name
1072 pLocatedElement = getSystemClass();
1073 }
1074
1075 // Return sub-elements
1076 strResult += pLocatedElement->listQualifiedPaths(true);
1077
Patrick Benavoli63499d42011-10-24 18:50:03 +02001078 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001079}
1080
Patrick Benavoli63499d42011-10-24 18:50:03 +02001081CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001082{
1083 CElementLocator elementLocator(getSystemClass());
1084
1085 CElement* pLocatedElement = NULL;
1086
1087 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1088
Patrick Benavoli63499d42011-10-24 18:50:03 +02001089 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001090 }
1091
1092 string strError;
1093
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001094 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001095
1096 // Dump elements
1097 pLocatedElement->dumpContent(strResult, parameterAccessContext);
1098
Patrick Benavoli63499d42011-10-24 18:50:03 +02001099 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001100}
1101
Patrick Benavoli63499d42011-10-24 18:50:03 +02001102CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSizeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001103{
1104 CElementLocator elementLocator(getSystemClass());
1105
1106 CElement* pLocatedElement = NULL;
1107
1108 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1109
Patrick Benavoli63499d42011-10-24 18:50:03 +02001110 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001111 }
1112
1113 // Converted to actual sizable element
1114 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1115
1116 // Get size as string
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001117 strResult = pConfigurableElement->getFootprintAsString();
Patrick Benavoli68a91282011-08-31 11:23:23 +02001118
Patrick Benavoli63499d42011-10-24 18:50:03 +02001119 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001120}
1121
Patrick Benavoli63499d42011-10-24 18:50:03 +02001122CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showPropertiesCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001123{
1124 CElementLocator elementLocator(getSystemClass());
1125
1126 CElement* pLocatedElement = NULL;
1127
1128 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1129
Patrick Benavoli63499d42011-10-24 18:50:03 +02001130 return CCommandHandler::EFailed;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001131 }
1132
1133 // Convert element
1134 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1135
1136 // Return element properties
1137 pConfigurableElement->showProperties(strResult);
1138
Patrick Benavoli63499d42011-10-24 18:50:03 +02001139 return CCommandHandler::ESucceeded;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001140}
1141
Patrick Benavoli63499d42011-10-24 18:50:03 +02001142CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001143{
1144 string strValue;
1145
Patrick Benavoli065264a2011-11-20 15:46:41 +01001146 if (!accessValue(remoteCommand.getArgument(0), strValue, false, strResult)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001147
Patrick Benavoli63499d42011-10-24 18:50:03 +02001148 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001149 }
1150 // Succeeded
1151 strResult = strValue;
1152
Patrick Benavoli63499d42011-10-24 18:50:03 +02001153 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001154}
1155
Patrick Benavoli63499d42011-10-24 18:50:03 +02001156CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001157{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001158 // Check tuning mode
1159 if (!checkTuningModeOn(strResult)) {
1160
1161 return CCommandHandler::EFailed;
1162 }
1163 // Get value to set
1164 string strValue = remoteCommand.packArguments(1, remoteCommand.getArgumentCount() - 1);
1165
1166 return accessValue(remoteCommand.getArgument(0), strValue, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001167}
1168
Patrick Benavoli63499d42011-10-24 18:50:03 +02001169CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listBelongingDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001170{
1171 CElementLocator elementLocator(getSystemClass());
1172
1173 CElement* pLocatedElement = NULL;
1174
1175 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1176
Patrick Benavoli63499d42011-10-24 18:50:03 +02001177 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001178 }
1179
1180 // Convert element
1181 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1182
1183 // Return element belonging domains
1184 pConfigurableElement->listBelongingDomains(strResult);
1185
Patrick Benavoli63499d42011-10-24 18:50:03 +02001186 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001187}
1188
Patrick Benavoli63499d42011-10-24 18:50:03 +02001189CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001190{
1191 CElementLocator elementLocator(getSystemClass());
1192
1193 CElement* pLocatedElement = NULL;
1194
1195 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1196
Patrick Benavoli63499d42011-10-24 18:50:03 +02001197 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001198 }
1199
1200 // Convert element
1201 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1202
1203 // Return element belonging domains
1204 pConfigurableElement->listAssociatedDomains(strResult);
1205
Patrick Benavoli63499d42011-10-24 18:50:03 +02001206 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001207}
1208
Patrick Benavoli63499d42011-10-24 18:50:03 +02001209CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001210{
1211 (void)remoteCommand;
1212
1213 getConfigurableDomains()->listAssociatedElements(strResult);
1214
Patrick Benavoli63499d42011-10-24 18:50:03 +02001215 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001216}
1217
Patrick Benavoli63499d42011-10-24 18:50:03 +02001218CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConflictingElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001219{
1220 (void)remoteCommand;
1221
1222 getConfigurableDomains()->listConflictingElements(strResult);
1223
Patrick Benavoli63499d42011-10-24 18:50:03 +02001224 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001225}
1226
Patrick Benavoli63499d42011-10-24 18:50:03 +02001227CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listRogueElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001228{
1229 (void)remoteCommand;
1230
1231 getSystemClass()->listRogueElements(strResult);
1232
Patrick Benavoli63499d42011-10-24 18:50:03 +02001233 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001234}
1235
1236/// Settings Import/Export
Patrick Benavoli63499d42011-10-24 18:50:03 +02001237CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001238{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001239 return exportDomainsXml(remoteCommand.getArgument(0), false, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001240}
1241
Patrick Benavoli63499d42011-10-24 18:50:03 +02001242CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001243{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001244 return importDomainsXml(remoteCommand.getArgument(0), false, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001245}
1246
Patrick Benavoli63499d42011-10-24 18:50:03 +02001247CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001248{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001249 return exportDomainsXml(remoteCommand.getArgument(0), true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001250}
1251
Patrick Benavoli63499d42011-10-24 18:50:03 +02001252CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001253{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001254 return importDomainsXml(remoteCommand.getArgument(0), true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001255}
1256
Patrick Benavoli63499d42011-10-24 18:50:03 +02001257CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001258{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001259 return exportDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001260}
1261
Patrick Benavoli63499d42011-10-24 18:50:03 +02001262CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001263{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001264 return importDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001265}
1266
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001267/// GUI commands
1268
1269CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getDomainsXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1270{
1271 (void)remoteCommand;
1272
1273 if (!getDomainsXMLString(strResult, true)) {
1274
1275 return CCommandHandler::EFailed;
1276 }
1277 // Succeeded
1278 return CCommandHandler::ESucceeded;
1279}
1280
1281CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getSystemClassXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1282{
1283 (void)remoteCommand;
1284
1285 if (!getSystemClassXMLString(strResult)) {
1286
1287 return CCommandHandler::EFailed;
1288 }
1289 // Succeeded
1290 return CCommandHandler::ESucceeded;
1291}
1292
Patrick Benavoli68a91282011-08-31 11:23:23 +02001293// User set/get parameters
Patrick Benavoli065264a2011-11-20 15:46:41 +01001294bool CParameterMgr::accessValue(const string& strPath, string& strValue, bool bSet, string& strError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001295{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001296 // Lock state
1297 CAutoLock autoLock(&_blackboardMutex);
1298
1299 CPathNavigator pathNavigator(strPath);
1300
1301 // Nagivate through system class
1302 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001303
1304 return false;
1305 }
1306
Patrick Benavoli065264a2011-11-20 15:46:41 +01001307 // Define context
1308 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001309
Patrick Benavoli68808c62012-02-02 17:12:41 +01001310 // Auto Sync
1311 if (bSet) {
1312
1313 parameterAccessContext.setAutoSync(_bAutoSyncOn);
1314 }
1315
Patrick Benavoli065264a2011-11-20 15:46:41 +01001316 // Do the get
1317 return getConstSystemClass()->accessValue(pathNavigator, strValue, bSet, parameterAccessContext);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001318}
1319
1320// Tuning mode
1321bool CParameterMgr::setTuningMode(bool bOn, string& strError)
1322{
1323 // Tuning allowed?
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001324 if (bOn && !getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001325
1326 strError = "Tuning prohibited";
1327
1328 return false;
1329 }
1330 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +01001331 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001332
1333 // Warn domains about exiting tuning mode
1334 if (!bOn && _bTuningModeIsOn) {
1335
1336 // Ensure application of currently selected configurations
Patrick Benavoli1387bda2011-08-31 11:23:24 +02001337 // Force-apply configurations
Patrick Benavoli68a91282011-08-31 11:23:23 +02001338 if (!getConfigurableDomains()->apply(_pMainParameterBlackboard, true, strError)) {
1339
1340 return false;
1341 }
1342 // Turn auto sync back on
1343 _bAutoSyncOn = true;
1344 }
1345
1346 // Store
1347 _bTuningModeIsOn = bOn;
1348
Patrick Benavoli68a91282011-08-31 11:23:23 +02001349 return true;
1350}
1351
1352bool CParameterMgr::tuningModeOn() const
1353{
1354 return _bTuningModeIsOn;
1355}
1356
1357// Current value space for user set/get value interpretation
1358void CParameterMgr::setValueSpace(bool bIsRaw)
1359{
1360 _bValueSpaceIsRaw = bIsRaw;
1361}
1362
1363bool CParameterMgr::valueSpaceIsRaw()
1364{
1365 return _bValueSpaceIsRaw;
1366}
1367
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001368// Current Output Raw Format for user get value interpretation
1369void CParameterMgr::setOutputRawFormat(bool bIsHex)
1370{
1371 _bOutputRawFormatIsHex = bIsHex;
1372}
1373
1374bool CParameterMgr::outputRawFormatIsHex()
1375{
1376 return _bOutputRawFormatIsHex;
1377}
1378
Patrick Benavoli68a91282011-08-31 11:23:23 +02001379/// Sync
1380// Automatic hardware synchronization control (during tuning session)
1381bool CParameterMgr::setAutoSync(bool bAutoSyncOn, string& strError)
1382{
1383 // Check tuning mode
1384 if (!checkTuningModeOn(strError)) {
1385
1386 return false;
1387 }
1388 // Warn domains about turning auto sync back on
1389 if (bAutoSyncOn && !_bAutoSyncOn) {
1390
Patrick Benavoli592ae562011-09-05 16:53:58 +02001391 // Do the synchronization at system class level (could be optimized by keeping track of all modified parameters)
1392 if (!sync(strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001393
1394 return false;
1395 }
1396 }
1397
1398 // Set Auto sync
1399 _bAutoSyncOn = bAutoSyncOn;
1400
1401 return true;
1402}
1403
1404bool CParameterMgr::autoSyncOn() const
1405{
1406 return _bAutoSyncOn;
1407}
1408
1409// Manual hardware synchronization control (during tuning session)
1410bool CParameterMgr::sync(string& strError)
1411{
1412 // Check tuning mode
1413 if (!checkTuningModeOn(strError)) {
1414
1415 return false;
1416 }
1417 // Warn domains about turning auto sync back on
1418 if (_bAutoSyncOn) {
1419
1420 strError = "Feature unavailable when Auto Sync is on";
1421
1422 return false;
1423 }
1424
1425 // Get syncer set
1426 CSyncerSet syncerSet;
1427 // ... from system class
1428 getConstSystemClass()->fillSyncerSet(syncerSet);
1429 // Sync
1430 return syncerSet.sync(*_pMainParameterBlackboard, false, strError);
1431}
1432
1433// Content dump
1434void CParameterMgr::logStructureContent(string& strContent) const
1435{
1436 string strError;
1437
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001438 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001439
1440 dumpContent(strContent, parameterAccessContext);
1441}
1442
1443// Configuration/Domains handling
1444bool CParameterMgr::createDomain(const string& strName, string& strError)
1445{
1446 // Check tuning mode
1447 if (!checkTuningModeOn(strError)) {
1448
1449 return false;
1450 }
1451
1452 // Delegate to configurable domains
1453 return getConfigurableDomains()->createDomain(strName, strError);
1454}
1455
1456bool CParameterMgr::deleteDomain(const string& strName, string& strError)
1457{
1458 // Check tuning mode
1459 if (!checkTuningModeOn(strError)) {
1460
1461 return false;
1462 }
1463
1464 // Delegate to configurable domains
1465 return getConfigurableDomains()->deleteDomain(strName, strError);
1466}
1467
Kevin Rocard170f0a42012-06-18 13:56:05 +02001468bool CParameterMgr::deleteAllDomains(string& strError)
1469{
1470 // Check tuning mode
1471 if (!checkTuningModeOn(strError)) {
1472
1473 return false;
1474 }
1475
1476 // Delegate to configurable domains
1477 getConfigurableDomains()->deleteAllDomains();
1478
1479 return true;
1480}
1481
Patrick Benavoli68a91282011-08-31 11:23:23 +02001482bool CParameterMgr::createConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1483{
1484 // Check tuning mode
1485 if (!checkTuningModeOn(strError)) {
1486
1487 return false;
1488 }
1489
1490 // Delegate to configurable domains
1491 return getConfigurableDomains()->createConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1492}
1493
1494bool CParameterMgr::deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1495{
1496 // Check tuning mode
1497 if (!checkTuningModeOn(strError)) {
1498
1499 return false;
1500 }
1501
1502 // Delegate to configurable domains
1503 return getConfigurableDomains()->deleteConfiguration(strDomain, strConfiguration, strError);
1504}
1505
1506bool CParameterMgr::restoreConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1507{
1508 // Check tuning mode
1509 if (!checkTuningModeOn(strError)) {
1510
1511 return false;
1512 }
1513
1514 // Delegate to configurable domains
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001515 return getConstConfigurableDomains()->restoreConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001516}
1517
1518bool CParameterMgr::saveConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1519{
1520 // Check tuning mode
1521 if (!checkTuningModeOn(strError)) {
1522
1523 return false;
1524 }
1525
1526 // Delegate to configurable domains
1527 return getConfigurableDomains()->saveConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1528}
1529
1530// Configurable element - domain association
1531bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1532{
1533 // Check tuning mode
1534 if (!checkTuningModeOn(strError)) {
1535
1536 return false;
1537 }
1538
1539 CElementLocator elementLocator(getSystemClass());
1540
1541 CElement* pLocatedElement = NULL;
1542
1543 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1544
1545 return false;
1546 }
1547
1548 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001549 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001550
1551 // Delegate
1552 return getConfigurableDomains()->addConfigurableElementToDomain(strDomain, pConfigurableElement, _pMainParameterBlackboard, strError);
1553}
1554
1555bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1556{
1557 // Check tuning mode
1558 if (!checkTuningModeOn(strError)) {
1559
1560 return false;
1561 }
1562
1563 CElementLocator elementLocator(getSystemClass());
1564
1565 CElement* pLocatedElement = NULL;
1566
1567 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1568
Patrick Benavoli63499d42011-10-24 18:50:03 +02001569 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001570 }
1571
1572 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001573 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001574
1575 // Delegate
1576 return getConfigurableDomains()->removeConfigurableElementFromDomain(strDomain, pConfigurableElement, strError);
1577}
1578
1579bool CParameterMgr::split(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1580{
1581 // Check tuning mode
1582 if (!checkTuningModeOn(strError)) {
1583
1584 return false;
1585 }
1586
1587 CElementLocator elementLocator(getSystemClass());
1588
1589 CElement* pLocatedElement = NULL;
1590
1591 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1592
Patrick Benavoli63499d42011-10-24 18:50:03 +02001593 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001594 }
1595
1596 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001597 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001598
1599 // Delegate
1600 return getConfigurableDomains()->split(strDomain, pConfigurableElement, strError);
1601}
1602
1603// XML Import/Export
1604bool CParameterMgr::importDomainsXml(const string& strFileName, bool bWithSettings, string& strError)
1605{
1606 // Check tuning mode
1607 if (!checkTuningModeOn(strError)) {
1608
1609 return false;
1610 }
1611
1612 // check path is absolute
1613 if (strFileName[0] != '/') {
1614
1615 strError = "Please provide absolute path";
1616
1617 return false;
1618 }
1619 // Root element
1620 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1621
1622 // Context
1623 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1624
1625 // Secltion criteria definition for rule creation
1626 xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
1627
1628 // Parse
1629 if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strFileName, "", EParameterConfigurationLibrary, "SystemClassName")) {
1630
1631 return false;
1632 }
1633
1634 // Validate domains after XML import
1635 pConfigurableDomains->validate(_pMainParameterBlackboard);
1636
1637 return true;
1638}
1639
1640bool CParameterMgr::exportDomainsXml(const string& strFileName, bool bWithSettings, string& strError) const
1641{
1642 // check path is absolute
1643 if (strFileName[0] != '/') {
1644
1645 strError = "Please provide absolute path";
1646
1647 return false;
1648 }
1649
1650 // Root element
1651 const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains();
1652
1653 // Get Schema file associated to root element
1654 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pConfigurableDomains->getKind() + ".xsd";
1655
1656 // Context
1657 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1658
1659 // Value space
1660 xmlDomainSerializingContext.setValueSpaceRaw(_bValueSpaceIsRaw);
1661
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001662 // Output raw format
1663 xmlDomainSerializingContext.setOutputRawFormat(_bOutputRawFormatIsHex);
1664
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001665 // Use a doc source by loading data from instantiated Configurable Domains
1666 CXmlMemoryDocSource memorySource(pConfigurableDomains, pConfigurableDomains->getKind(), strXmlSchemaFilePath, "parameter-framework", getVersion());
Patrick Benavoli68a91282011-08-31 11:23:23 +02001667
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001668 // Use a doc sink to write the doc data in a file
1669 CXmlFileDocSink fileSink(strFileName);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001670
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001671 if (!fileSink.process(memorySource, xmlDomainSerializingContext)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001672 return false;
1673 }
1674
1675 return true;
1676}
1677
1678// Binary Import/Export
1679bool CParameterMgr::importDomainsBinary(const string& strFileName, string& strError)
1680{
1681 // Check tuning mode
1682 if (!checkTuningModeOn(strError)) {
1683
1684 return false;
1685 }
1686 // check path is absolute
1687 if (strFileName[0] != '/') {
1688
1689 strError = "Please provide absolute path";
1690
1691 return false;
1692 }
1693 // Root element
1694 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1695
1696 // Serialize in
1697 return pConfigurableDomains->serializeSettings(strFileName, false, _uiStructureChecksum, strError);
1698}
1699
1700bool CParameterMgr::exportDomainsBinary(const string& strFileName, string& strError)
1701{
1702 // check path is absolute
1703 if (strFileName[0] != '/') {
1704
1705 strError = "Please provide absolute path";
1706
1707 return false;
1708 }
Patrick Benavoli68a91282011-08-31 11:23:23 +02001709
Patrick Benavoli68a91282011-08-31 11:23:23 +02001710 // Root element
1711 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1712
1713 // Serialize out
1714 return pConfigurableDomains->serializeSettings(strFileName, true, _uiStructureChecksum, strError);
1715}
1716
1717// For tuning, check we're in tuning mode
1718bool CParameterMgr::checkTuningModeOn(string& strError) const
1719{
1720 // Tuning Mode on?
1721 if (!_bTuningModeIsOn) {
1722
1723 strError = "Tuning Mode must be on";
1724
1725 return false;
1726 }
1727 return true;
1728}
1729
Patrick Benavoli065264a2011-11-20 15:46:41 +01001730// Tuning mutex dynamic parameter handling
1731pthread_mutex_t* CParameterMgr::getBlackboardMutex()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001732{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001733 return &_blackboardMutex;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001734}
1735
Patrick Benavoli065264a2011-11-20 15:46:41 +01001736// Blackboard reference (dynamic parameter handling)
1737CParameterBlackboard* CParameterMgr::getParameterBlackboard()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001738{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001739 return _pMainParameterBlackboard;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001740}
1741
Patrick Benavoli68a91282011-08-31 11:23:23 +02001742// Dynamic creation library feeding
1743void CParameterMgr::feedElementLibraries()
1744{
1745 // Global Configuration handling
1746 CElementLibrary* pFrameworkConfigurationLibrary = new CElementLibrary;
1747
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001748 pFrameworkConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CParameterFrameworkConfiguration>("ParameterFrameworkConfiguration"));
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +01001749 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CSubsystemPlugins>("SubsystemPlugins"));
1750 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CPluginLocation>("Location"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001751 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("StructureDescriptionFileLocation"));
1752 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationGroup>("SettingsConfiguration"));
1753 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("ConfigurableDomainsFileLocation"));
1754 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("BinarySettingsFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001755
1756 _pElementLibrarySet->addElementLibrary(pFrameworkConfigurationLibrary);
1757
1758 // Parameter creation
1759 CElementLibrary* pParameterCreationLibrary = new CElementLibrary;
1760
1761 pParameterCreationLibrary->addElementBuilder(new CSubsystemElementBuilder(getSystemClass()->getSubsystemLibrary()));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001762 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CComponentType>("ComponentType"));
1763 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CComponentInstance>("Component"));
1764 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBitParameterType>("BitParameter"));
1765 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBitParameterBlockType>("BitParameterBlock"));
Patrick Benavoli1352ae52011-10-21 16:48:04 +02001766 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CStringParameterType>("StringParameter"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001767 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CParameterBlockType>("ParameterBlock"));
1768 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBooleanParameterType>("BooleanParameter"));
1769 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CIntegerParameterType>("IntegerParameter"));
Patrick Benavoliee65e6d2011-11-20 18:52:24 +01001770 pParameterCreationLibrary->addElementBuilder(new TElementBuilderTemplate<CLinearParameterAdaptation>("LinearAdaptation"));
Patrick Benavoli9fc3c0d2011-10-27 14:27:27 +02001771 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CEnumParameterType>("EnumParameter"));
Patrick Benavoli68808c62012-02-02 17:12:41 +01001772 pParameterCreationLibrary->addElementBuilder(new TElementBuilderTemplate<CEnumValuePair>("ValuePair"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001773 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CFixedPointParameterType>("FixedPointParameter"));
1774 pParameterCreationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CXmlFileIncluderElement>("SubsystemInclude"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001775
1776 _pElementLibrarySet->addElementLibrary(pParameterCreationLibrary);
1777
1778 // Parameter Configuration Domains creation
1779 CElementLibrary* pParameterConfigurationLibrary = new CElementLibrary;
1780
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001781 pParameterConfigurationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CConfigurableDomain>("ConfigurableDomain"));
1782 pParameterConfigurationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CDomainConfiguration>("Configuration"));
1783 pParameterConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CCompoundRule>("CompoundRule"));
1784 pParameterConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CSelectionCriterionRule>("SelectionCriterionRule"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001785
1786 _pElementLibrarySet->addElementLibrary(pParameterConfigurationLibrary);
1787}
1788
1789// Remote Processor Server connection handling
1790bool CParameterMgr::handleRemoteProcessingInterface(string& strError)
1791{
1792 CAutoLog autoLog(this, "Handling remote processing interface");
1793
1794 // Start server if tuning allowed
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001795 if (getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001796
1797 log("Loading remote processor library");
1798
1799 // Load library
1800 void* lib_handle = dlopen("libremote-processor.so", RTLD_NOW);
1801
1802 if (!lib_handle) {
1803
1804 // Return error
1805 const char* pcError = dlerror();
1806
1807 if (pcError) {
1808
1809 strError = pcError;
1810 } else {
1811
1812 strError = "Unable to load libremote-processor.so library";
1813 }
1814
1815 return false;
1816 }
1817
1818 CreateRemoteProcessorServer pfnCreateRemoteProcessorServer = (CreateRemoteProcessorServer)dlsym(lib_handle, "createRemoteProcessorServer");
1819
1820 if (!pfnCreateRemoteProcessorServer) {
1821
1822 strError = "libremote-process.so does not contain createRemoteProcessorServer symbol.";
1823
1824 return false;
1825 }
1826
1827 // Create server
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001828 _pRemoteProcessorServer = pfnCreateRemoteProcessorServer(getConstFrameworkConfiguration()->getServerPort(), _pCommandHandler);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001829
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001830 log("Starting remote processor server on port %d", getConstFrameworkConfiguration()->getServerPort());
Patrick Benavoli68a91282011-08-31 11:23:23 +02001831 // Start
1832 if (!_pRemoteProcessorServer->start()) {
1833
1834 strError = "Unable to start remote processor server";
1835
1836 return false;
1837 }
1838 }
1839
1840 return true;
1841}
1842
1843// Back synchronization
1844CBackSynchronizer* CParameterMgr::createBackSynchronizer(string& strError) const
1845{
1846#ifdef SIMULATION
1847 // In simulation, back synchronization of the blackboard won't probably work
1848 // We need to ensure though the blackboard is initialized with valid data
1849 return new CSimulatedBackSynchronizer(getConstSystemClass(), strError, _pMainParameterBlackboard);
1850#else
1851 // Real back synchronizer from subsystems
1852 return new CHardwareBackSynchronizer(getConstSystemClass(), strError, _pMainParameterBlackboard);
1853#endif
1854}
1855
1856// Children typwise access
1857CParameterFrameworkConfiguration* CParameterMgr::getFrameworkConfiguration()
1858{
1859 return static_cast<CParameterFrameworkConfiguration*>(getChild(EFrameworkConfiguration));
1860}
1861
1862const CParameterFrameworkConfiguration* CParameterMgr::getConstFrameworkConfiguration()
1863{
1864 return getFrameworkConfiguration();
1865}
1866
1867CSelectionCriteria* CParameterMgr::getSelectionCriteria()
1868{
1869 return static_cast<CSelectionCriteria*>(getChild(ESelectionCriteria));
1870}
1871
1872const CSelectionCriteria* CParameterMgr::getConstSelectionCriteria()
1873{
1874 return static_cast<const CSelectionCriteria*>(getChild(ESelectionCriteria));
1875}
1876
1877CSystemClass* CParameterMgr::getSystemClass()
1878{
1879 return static_cast<CSystemClass*>(getChild(ESystemClass));
1880}
1881
1882const CSystemClass* CParameterMgr::getConstSystemClass() const
1883{
1884 return static_cast<const CSystemClass*>(getChild(ESystemClass));
1885}
1886
1887// Configurable Domains
1888CConfigurableDomains* CParameterMgr::getConfigurableDomains()
1889{
1890 return static_cast<CConfigurableDomains*>(getChild(EConfigurableDomains));
1891}
1892
1893const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains()
1894{
1895 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
1896}
1897
1898const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains() const
1899{
1900 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
1901}
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001902
1903/// GUI commands functions
1904
1905bool CParameterMgr::getDomainsXMLString(string& strResult, bool bWithSettings)
1906{
1907
1908 // Root element
1909 const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains();
1910
1911 // Get Schema file associated to root element
1912 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pConfigurableDomains->getKind() + ".xsd";
1913
1914 string strError;
1915
1916 // Context
1917 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1918
1919 // Value space
1920 xmlDomainSerializingContext.setValueSpaceRaw(_bValueSpaceIsRaw);
1921
1922 // Output raw format
1923 xmlDomainSerializingContext.setOutputRawFormat(_bOutputRawFormatIsHex);
1924
1925 // Use a doc source by loading data from instantiated Configurable Domains
1926 CXmlMemoryDocSource memorySource(pConfigurableDomains, pConfigurableDomains->getKind(), strXmlSchemaFilePath, "parameter-framework", getVersion());
1927
1928 // Use a doc sink the write the doc data in a string
1929 CXmlStringDocSink stringSink(strResult);
1930
1931 if (!stringSink.process(memorySource, xmlDomainSerializingContext)) {
1932 strResult = strError;
1933
1934 return false;
1935 }
1936
1937 return true;
1938}
1939
1940bool CParameterMgr::getSystemClassXMLString(string& strResult)
1941{
1942 // Root element
1943 const CSystemClass* pSystemClass = getSystemClass();
1944
1945 string strError;
1946
1947 CXmlSerializingContext xmlSerializingContext(strError);
1948
1949 // Use a doc source by loading data from instantiated Configurable Domains
1950 CXmlMemoryDocSource memorySource(pSystemClass, pSystemClass->getKind());
1951
1952 // Use a doc sink that write the doc data in a string
1953 CXmlStringDocSink stringSink(strResult);
1954
1955 if (!stringSink.process(memorySource, xmlSerializingContext)) {
1956 strResult = strError;
1957 return false;
1958 }
1959
1960 return true;
1961}