blob: 9f1d16048ffa0d0e673166311017568437e0301e [file] [log] [blame]
Kevin Rocard93250d12012-07-19 17:48:30 +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 }
579 }
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200580
581 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200582}
583
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200584// Dynamic parameter handling
Patrick Benavoli065264a2011-11-20 15:46:41 +0100585CParameterHandle* CParameterMgr::createParameterHandle(const string& strPath, string& strError)
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200586{
Patrick Benavoli065264a2011-11-20 15:46:41 +0100587 CPathNavigator pathNavigator(strPath);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200588
Patrick Benavoli065264a2011-11-20 15:46:41 +0100589 // Nagivate through system class
590 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
591
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100592 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100593 }
594
595 // Find element
596 const CElement* pElement = getConstSystemClass()->findDescendant(pathNavigator);
597
598 if (!pElement) {
599
600 strError = "Path not found";
601
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100602 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100603 }
604
605 // Check found element is a parameter
606 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pElement);
607
608 if (!pConfigurableElement->isParameter()) {
609
610 // Element is not parameter
611 strError = "Not a parameter";
612
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100613 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100614 }
615
616 // Convert as parameter and return new handle
617 return new CParameterHandle(static_cast<const CBaseParameter*>(pElement), this);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200618}
619
Patrick Benavoli68a91282011-08-31 11:23:23 +0200620/////////////////// Remote command parsers
Patrick Benavoli592ae562011-09-05 16:53:58 +0200621/// Version
Patrick Benavoli63499d42011-10-24 18:50:03 +0200622CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::versionCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli592ae562011-09-05 16:53:58 +0200623{
624 (void)remoteCommand;
625
Patrick Benavoli63499d42011-10-24 18:50:03 +0200626 // Show version
627 strResult = getVersion();
Patrick Benavoli592ae562011-09-05 16:53:58 +0200628
Patrick Benavoli63499d42011-10-24 18:50:03 +0200629 return CCommandHandler::ESucceeded;
Patrick Benavoli592ae562011-09-05 16:53:58 +0200630}
631
Patrick Benavoli68a91282011-08-31 11:23:23 +0200632/// Status
Patrick Benavoli63499d42011-10-24 18:50:03 +0200633CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::statusCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200634{
635 (void)remoteCommand;
636 // System class
637 const CSystemClass* pSystemClass = getSystemClass();
638
Patrick Benavoli68a91282011-08-31 11:23:23 +0200639 // Show status
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200640 /// General section
641 appendTitle(strResult, "General:");
642 // System class
Patrick Benavoli68a91282011-08-31 11:23:23 +0200643 strResult += "System Class: ";
644 strResult += pSystemClass->getName();
645 strResult += "\n";
646
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200647 // Tuning mode
Patrick Benavoli68a91282011-08-31 11:23:23 +0200648 strResult += "Tuning Mode: ";
649 strResult += tuningModeOn() ? "on" : "off";
650 strResult += "\n";
651
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200652 // Value space
Patrick Benavoli68a91282011-08-31 11:23:23 +0200653 strResult += "Value Space: ";
654 strResult += valueSpaceIsRaw() ? "raw" : "real";
655 strResult += "\n";
656
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200657 // Output raw format
658 strResult += "Output Raw Format: ";
659 strResult += outputRawFormatIsHex() ? "hex" : "dec";
660 strResult += "\n";
661
662 // Auto Sync
Patrick Benavoli68a91282011-08-31 11:23:23 +0200663 strResult += "Auto Sync: ";
664 strResult += autoSyncOn() ? "on" : "off";
665 strResult += "\n";
666
667 /// Subsystem list
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200668 appendTitle(strResult, "Subsystems:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200669 string strSubsystemList;
670 pSystemClass->listChildrenPaths(strSubsystemList);
671 strResult += strSubsystemList;
672
673 /// Last applied configurations
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200674 appendTitle(strResult, "Last applied configurations:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200675 string strLastAppliedConfigurations;
676 getConfigurableDomains()->listLastAppliedConfigurations(strLastAppliedConfigurations);
677 strResult += strLastAppliedConfigurations;
678
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200679 /// Criteria states
680 appendTitle(strResult, "Selection criteria:");
681 string strSelectionCriteria;
682 getSelectionCriteria()->listSelectionCriteria(strSelectionCriteria, false);
683 strResult += strSelectionCriteria;
684
Patrick Benavoli63499d42011-10-24 18:50:03 +0200685 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200686}
687
688/// Tuning Mode
Patrick Benavoli63499d42011-10-24 18:50:03 +0200689CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200690{
691 if (remoteCommand.getArgument(0) == "on") {
692
693 if (setTuningMode(true, strResult)) {
694
Patrick Benavoli63499d42011-10-24 18:50:03 +0200695 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200696 }
697 } else if (remoteCommand.getArgument(0) == "off") {
698
699 if (setTuningMode(false, strResult)) {
700
Patrick Benavoli63499d42011-10-24 18:50:03 +0200701 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200702 }
703 } else {
704 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200705 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200706 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200707 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200708}
709
Patrick Benavoli63499d42011-10-24 18:50:03 +0200710CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200711{
712 (void)remoteCommand;
713
714 strResult = tuningModeOn() ? "on" : "off";
715
Patrick Benavoli63499d42011-10-24 18:50:03 +0200716 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200717}
718
719/// Value Space
Patrick Benavoli63499d42011-10-24 18:50:03 +0200720CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200721{
722 (void)strResult;
723
724 if (remoteCommand.getArgument(0) == "raw") {
725
726 setValueSpace(true);
727
Patrick Benavoli63499d42011-10-24 18:50:03 +0200728 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200729
730 } else if (remoteCommand.getArgument(0) == "real") {
731
732 setValueSpace(false);
733
Patrick Benavoli63499d42011-10-24 18:50:03 +0200734 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200735
736 } else {
737 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200738 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200739 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200740 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200741}
742
Patrick Benavoli63499d42011-10-24 18:50:03 +0200743CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200744{
745 (void)remoteCommand;
746
747 strResult = valueSpaceIsRaw() ? "raw" : "real";
748
Patrick Benavoli63499d42011-10-24 18:50:03 +0200749 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200750}
751
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200752/// Output Raw Format
Patrick Benavoli63499d42011-10-24 18:50:03 +0200753CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200754{
755 (void)strResult;
756
757 if (remoteCommand.getArgument(0) == "hex") {
758
759 setOutputRawFormat(true);
760
Patrick Benavoli63499d42011-10-24 18:50:03 +0200761 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200762
763 } else if (remoteCommand.getArgument(0) == "dec") {
764
765 setOutputRawFormat(false);
766
Patrick Benavoli63499d42011-10-24 18:50:03 +0200767 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200768
769 } else {
770 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200771 return CCommandHandler::EShowUsage;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200772 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200773 return CCommandHandler::EFailed;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200774}
775
Patrick Benavoli63499d42011-10-24 18:50:03 +0200776CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200777{
778 (void)remoteCommand;
779
780 strResult = outputRawFormatIsHex() ? "hex" : "dec";
781
Patrick Benavoli63499d42011-10-24 18:50:03 +0200782 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200783}
784
Patrick Benavoli68a91282011-08-31 11:23:23 +0200785/// Sync
Patrick Benavoli63499d42011-10-24 18:50:03 +0200786CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200787{
788 if (remoteCommand.getArgument(0) == "on") {
789
790 if (setAutoSync(true, strResult)) {
791
Patrick Benavoli63499d42011-10-24 18:50:03 +0200792 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200793 }
794 } else if (remoteCommand.getArgument(0) == "off") {
795
796 if (setAutoSync(false, strResult)) {
797
Patrick Benavoli63499d42011-10-24 18:50:03 +0200798 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200799 }
800 } else {
801 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200802 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200803 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200804 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200805}
806
Patrick Benavoli63499d42011-10-24 18:50:03 +0200807CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200808{
809 (void)remoteCommand;
810
811 strResult = autoSyncOn() ? "on" : "off";
812
Patrick Benavoli63499d42011-10-24 18:50:03 +0200813 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200814}
815
Patrick Benavoli63499d42011-10-24 18:50:03 +0200816CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::syncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200817{
818 (void)remoteCommand;
819
Patrick Benavoli63499d42011-10-24 18:50:03 +0200820 return sync(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200821}
822
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200823/// Criteria
Patrick Benavoli63499d42011-10-24 18:50:03 +0200824CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listCriteriaCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200825{
826 (void)remoteCommand;
827
828 getSelectionCriteria()->listSelectionCriteria(strResult, true);
829
Patrick Benavoli63499d42011-10-24 18:50:03 +0200830 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200831}
Patrick Benavoli68a91282011-08-31 11:23:23 +0200832
833/// Domains
Patrick Benavoli63499d42011-10-24 18:50:03 +0200834CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200835{
836 (void)remoteCommand;
837
Patrick Benavoli63499d42011-10-24 18:50:03 +0200838 getConfigurableDomains()->listDomains(strResult);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200839
Patrick Benavoli63499d42011-10-24 18:50:03 +0200840 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200841}
842
Patrick Benavoli63499d42011-10-24 18:50:03 +0200843CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200844{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200845 return createDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200846}
847
Patrick Benavoli63499d42011-10-24 18:50:03 +0200848CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200849{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200850 return deleteDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200851}
852
Kevin Rocard170f0a42012-06-18 13:56:05 +0200853CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteAllDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
854{
855 (void)remoteCommand;
856
857 return deleteAllDomains(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
858}
859
Patrick Benavoli63499d42011-10-24 18:50:03 +0200860CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200861{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200862 return getConfigurableDomains()->renameDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200863}
864
Patrick Benavoli63499d42011-10-24 18:50:03 +0200865CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200866{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200867 // Check tuning mode
868 if (!checkTuningModeOn(strResult)) {
869
870 return CCommandHandler::EFailed;
871 }
872
873 // Set property
874 bool bSequenceAware;
875
876 if (remoteCommand.getArgument(1) == "true") {
877
878 bSequenceAware = true;
879
880 } else if (remoteCommand.getArgument(1) == "false") {
881
882 bSequenceAware = false;
883
884 } else {
885 // Show usage
886 return CCommandHandler::EShowUsage;
887 }
888
889 return getConfigurableDomains()->setSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200890}
891
Patrick Benavoli63499d42011-10-24 18:50:03 +0200892CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200893{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200894 // Get property
895 bool bSequenceAware;
896
897 if (!getConfigurableDomains()->getSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult)) {
898
899 return CCommandHandler::EFailed;
900 }
901
902 strResult = bSequenceAware ? "true" : "false";
903
904 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200905}
906
Patrick Benavoli63499d42011-10-24 18:50:03 +0200907CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200908{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200909 return getConfigurableDomains()->listDomainElements(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200910}
911
Patrick Benavoli63499d42011-10-24 18:50:03 +0200912CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::addElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200913{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200914 return addConfigurableElementToDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
915}
916
917CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::removeElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
918{
919 return removeConfigurableElementFromDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
920}
921
922CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::splitDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
923{
924 return split(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200925}
926
927/// Configurations
Patrick Benavoli63499d42011-10-24 18:50:03 +0200928CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConfigurationsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200929{
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100930 return getConstConfigurableDomains()->listConfigurations(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
931}
932
933CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
934{
935 (void)remoteCommand;
936
937 // Dummy error context
938 string strError;
939 CErrorContext errorContext(strError);
940
941 // Dump
942 getConstConfigurableDomains()->dumpContent(strResult, errorContext);
943
944 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200945}
946
Patrick Benavoli63499d42011-10-24 18:50:03 +0200947CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200948{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200949 return createConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200950}
951
Patrick Benavoli63499d42011-10-24 18:50:03 +0200952CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200953{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200954 return deleteConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200955}
956
Patrick Benavoli63499d42011-10-24 18:50:03 +0200957CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200958{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200959 return getConfigurableDomains()->renameConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200960}
961
Patrick Benavoli63499d42011-10-24 18:50:03 +0200962CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::saveConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200963{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200964 return saveConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200965}
966
Patrick Benavoli63499d42011-10-24 18:50:03 +0200967CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::restoreConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200968{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200969 return restoreConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
970}
971
972CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
973{
974 // Check tuning mode
975 if (!checkTuningModeOn(strResult)) {
976
977 return CCommandHandler::EFailed;
978 }
979
980 // Build configurable element path list
981 vector<string> astrNewElementSequence;
982
983 uint32_t uiArgument;
984
985 for (uiArgument = 2; uiArgument < remoteCommand.getArgumentCount(); uiArgument++) {
986
987 astrNewElementSequence.push_back(remoteCommand.getArgument(uiArgument));
988 }
989
990 // Delegate to configurable domains
991 return getConfigurableDomains()->setElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), astrNewElementSequence, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
992}
993
994CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
995{
996 // Delegate to configurable domains
997 return getConfigurableDomains()->getElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200998}
999
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001000CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1001{
1002 // Delegate to configurable domains
1003 return getConfigurableDomains()->setApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.packArguments(2, remoteCommand.getArgumentCount() - 2), getConstSelectionCriteria()->getSelectionCriteriaDefinition(), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1004}
1005
1006CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::clearRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1007{
1008 // Delegate to configurable domains
1009 return getConfigurableDomains()->clearApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1010}
1011
1012CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1013{
1014 // Delegate to configurable domains
1015 return getConfigurableDomains()->getApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
1016}
1017
Patrick Benavoli68a91282011-08-31 11:23:23 +02001018/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001019CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001020{
1021 CElementLocator elementLocator(getSystemClass(), false);
1022
1023 CElement* pLocatedElement = NULL;
1024
1025 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1026
Patrick Benavoli63499d42011-10-24 18:50:03 +02001027 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001028 }
1029
1030 strResult = string("\n");
1031
1032 if (!pLocatedElement) {
1033
1034 // List from root folder
1035
1036 // Return system class qualified name
1037 pLocatedElement = getSystemClass();
1038 }
1039
1040 // Return sub-elements
1041 strResult += pLocatedElement->listQualifiedPaths(false);
1042
Patrick Benavoli63499d42011-10-24 18:50:03 +02001043 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001044}
1045
1046/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001047CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listParametersCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001048{
1049 CElementLocator elementLocator(getSystemClass(), false);
1050
1051 CElement* pLocatedElement = NULL;
1052
1053 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1054
Patrick Benavoli63499d42011-10-24 18:50:03 +02001055 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001056 }
1057
1058 strResult = string("\n");
1059
1060 if (!pLocatedElement) {
1061
1062 // List from root folder
1063
1064 // Return system class qualified name
1065 pLocatedElement = getSystemClass();
1066 }
1067
1068 // Return sub-elements
1069 strResult += pLocatedElement->listQualifiedPaths(true);
1070
Patrick Benavoli63499d42011-10-24 18:50:03 +02001071 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001072}
1073
Patrick Benavoli63499d42011-10-24 18:50:03 +02001074CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001075{
1076 CElementLocator elementLocator(getSystemClass());
1077
1078 CElement* pLocatedElement = NULL;
1079
1080 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1081
Patrick Benavoli63499d42011-10-24 18:50:03 +02001082 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001083 }
1084
1085 string strError;
1086
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001087 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001088
1089 // Dump elements
1090 pLocatedElement->dumpContent(strResult, parameterAccessContext);
1091
Patrick Benavoli63499d42011-10-24 18:50:03 +02001092 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001093}
1094
Patrick Benavoli63499d42011-10-24 18:50:03 +02001095CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSizeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001096{
1097 CElementLocator elementLocator(getSystemClass());
1098
1099 CElement* pLocatedElement = NULL;
1100
1101 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1102
Patrick Benavoli63499d42011-10-24 18:50:03 +02001103 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001104 }
1105
1106 // Converted to actual sizable element
1107 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1108
1109 // Get size as string
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001110 strResult = pConfigurableElement->getFootprintAsString();
Patrick Benavoli68a91282011-08-31 11:23:23 +02001111
Patrick Benavoli63499d42011-10-24 18:50:03 +02001112 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001113}
1114
Patrick Benavoli63499d42011-10-24 18:50:03 +02001115CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showPropertiesCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001116{
1117 CElementLocator elementLocator(getSystemClass());
1118
1119 CElement* pLocatedElement = NULL;
1120
1121 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1122
Patrick Benavoli63499d42011-10-24 18:50:03 +02001123 return CCommandHandler::EFailed;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001124 }
1125
1126 // Convert element
1127 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1128
1129 // Return element properties
1130 pConfigurableElement->showProperties(strResult);
1131
Patrick Benavoli63499d42011-10-24 18:50:03 +02001132 return CCommandHandler::ESucceeded;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001133}
1134
Patrick Benavoli63499d42011-10-24 18:50:03 +02001135CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001136{
1137 string strValue;
1138
Patrick Benavoli065264a2011-11-20 15:46:41 +01001139 if (!accessValue(remoteCommand.getArgument(0), strValue, false, strResult)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001140
Patrick Benavoli63499d42011-10-24 18:50:03 +02001141 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001142 }
1143 // Succeeded
1144 strResult = strValue;
1145
Patrick Benavoli63499d42011-10-24 18:50:03 +02001146 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001147}
1148
Patrick Benavoli63499d42011-10-24 18:50:03 +02001149CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001150{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001151 // Check tuning mode
1152 if (!checkTuningModeOn(strResult)) {
1153
1154 return CCommandHandler::EFailed;
1155 }
1156 // Get value to set
1157 string strValue = remoteCommand.packArguments(1, remoteCommand.getArgumentCount() - 1);
1158
1159 return accessValue(remoteCommand.getArgument(0), strValue, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001160}
1161
Patrick Benavoli63499d42011-10-24 18:50:03 +02001162CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listBelongingDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001163{
1164 CElementLocator elementLocator(getSystemClass());
1165
1166 CElement* pLocatedElement = NULL;
1167
1168 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1169
Patrick Benavoli63499d42011-10-24 18:50:03 +02001170 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001171 }
1172
1173 // Convert element
1174 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1175
1176 // Return element belonging domains
1177 pConfigurableElement->listBelongingDomains(strResult);
1178
Patrick Benavoli63499d42011-10-24 18:50:03 +02001179 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001180}
1181
Patrick Benavoli63499d42011-10-24 18:50:03 +02001182CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001183{
1184 CElementLocator elementLocator(getSystemClass());
1185
1186 CElement* pLocatedElement = NULL;
1187
1188 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1189
Patrick Benavoli63499d42011-10-24 18:50:03 +02001190 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001191 }
1192
1193 // Convert element
1194 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1195
1196 // Return element belonging domains
1197 pConfigurableElement->listAssociatedDomains(strResult);
1198
Patrick Benavoli63499d42011-10-24 18:50:03 +02001199 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001200}
1201
Patrick Benavoli63499d42011-10-24 18:50:03 +02001202CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001203{
1204 (void)remoteCommand;
1205
1206 getConfigurableDomains()->listAssociatedElements(strResult);
1207
Patrick Benavoli63499d42011-10-24 18:50:03 +02001208 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001209}
1210
Patrick Benavoli63499d42011-10-24 18:50:03 +02001211CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConflictingElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001212{
1213 (void)remoteCommand;
1214
1215 getConfigurableDomains()->listConflictingElements(strResult);
1216
Patrick Benavoli63499d42011-10-24 18:50:03 +02001217 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001218}
1219
Patrick Benavoli63499d42011-10-24 18:50:03 +02001220CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listRogueElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001221{
1222 (void)remoteCommand;
1223
1224 getSystemClass()->listRogueElements(strResult);
1225
Patrick Benavoli63499d42011-10-24 18:50:03 +02001226 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001227}
1228
1229/// Settings Import/Export
Patrick Benavoli63499d42011-10-24 18:50:03 +02001230CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001231{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001232 return exportDomainsXml(remoteCommand.getArgument(0), false, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001233}
1234
Patrick Benavoli63499d42011-10-24 18:50:03 +02001235CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001236{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001237 return importDomainsXml(remoteCommand.getArgument(0), false, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001238}
1239
Patrick Benavoli63499d42011-10-24 18:50:03 +02001240CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001241{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001242 return exportDomainsXml(remoteCommand.getArgument(0), true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001243}
1244
Patrick Benavoli63499d42011-10-24 18:50:03 +02001245CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001246{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001247 return importDomainsXml(remoteCommand.getArgument(0), true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001248}
1249
Patrick Benavoli63499d42011-10-24 18:50:03 +02001250CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001251{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001252 return exportDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001253}
1254
Patrick Benavoli63499d42011-10-24 18:50:03 +02001255CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001256{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001257 return importDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001258}
1259
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001260/// GUI commands
1261
1262CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getDomainsXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1263{
1264 (void)remoteCommand;
1265
1266 if (!getDomainsXMLString(strResult, true)) {
1267
1268 return CCommandHandler::EFailed;
1269 }
1270 // Succeeded
1271 return CCommandHandler::ESucceeded;
1272}
1273
1274CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getSystemClassXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1275{
1276 (void)remoteCommand;
1277
1278 if (!getSystemClassXMLString(strResult)) {
1279
1280 return CCommandHandler::EFailed;
1281 }
1282 // Succeeded
1283 return CCommandHandler::ESucceeded;
1284}
1285
Patrick Benavoli68a91282011-08-31 11:23:23 +02001286// User set/get parameters
Patrick Benavoli065264a2011-11-20 15:46:41 +01001287bool CParameterMgr::accessValue(const string& strPath, string& strValue, bool bSet, string& strError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001288{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001289 // Lock state
1290 CAutoLock autoLock(&_blackboardMutex);
1291
1292 CPathNavigator pathNavigator(strPath);
1293
1294 // Nagivate through system class
1295 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001296
1297 return false;
1298 }
1299
Patrick Benavoli065264a2011-11-20 15:46:41 +01001300 // Define context
1301 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001302
Patrick Benavoli68808c62012-02-02 17:12:41 +01001303 // Auto Sync
1304 if (bSet) {
1305
1306 parameterAccessContext.setAutoSync(_bAutoSyncOn);
1307 }
1308
Patrick Benavoli065264a2011-11-20 15:46:41 +01001309 // Do the get
1310 return getConstSystemClass()->accessValue(pathNavigator, strValue, bSet, parameterAccessContext);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001311}
1312
1313// Tuning mode
1314bool CParameterMgr::setTuningMode(bool bOn, string& strError)
1315{
1316 // Tuning allowed?
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001317 if (bOn && !getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001318
1319 strError = "Tuning prohibited";
1320
1321 return false;
1322 }
1323 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +01001324 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001325
1326 // Warn domains about exiting tuning mode
1327 if (!bOn && _bTuningModeIsOn) {
1328
1329 // Ensure application of currently selected configurations
Patrick Benavoli1387bda2011-08-31 11:23:24 +02001330 // Force-apply configurations
Patrick Benavoli68a91282011-08-31 11:23:23 +02001331 if (!getConfigurableDomains()->apply(_pMainParameterBlackboard, true, strError)) {
1332
1333 return false;
1334 }
1335 // Turn auto sync back on
1336 _bAutoSyncOn = true;
1337 }
1338
1339 // Store
1340 _bTuningModeIsOn = bOn;
1341
Patrick Benavoli68a91282011-08-31 11:23:23 +02001342 return true;
1343}
1344
1345bool CParameterMgr::tuningModeOn() const
1346{
1347 return _bTuningModeIsOn;
1348}
1349
1350// Current value space for user set/get value interpretation
1351void CParameterMgr::setValueSpace(bool bIsRaw)
1352{
1353 _bValueSpaceIsRaw = bIsRaw;
1354}
1355
1356bool CParameterMgr::valueSpaceIsRaw()
1357{
1358 return _bValueSpaceIsRaw;
1359}
1360
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001361// Current Output Raw Format for user get value interpretation
1362void CParameterMgr::setOutputRawFormat(bool bIsHex)
1363{
1364 _bOutputRawFormatIsHex = bIsHex;
1365}
1366
1367bool CParameterMgr::outputRawFormatIsHex()
1368{
1369 return _bOutputRawFormatIsHex;
1370}
1371
Patrick Benavoli68a91282011-08-31 11:23:23 +02001372/// Sync
1373// Automatic hardware synchronization control (during tuning session)
1374bool CParameterMgr::setAutoSync(bool bAutoSyncOn, string& strError)
1375{
1376 // Check tuning mode
1377 if (!checkTuningModeOn(strError)) {
1378
1379 return false;
1380 }
1381 // Warn domains about turning auto sync back on
1382 if (bAutoSyncOn && !_bAutoSyncOn) {
1383
Patrick Benavoli592ae562011-09-05 16:53:58 +02001384 // Do the synchronization at system class level (could be optimized by keeping track of all modified parameters)
1385 if (!sync(strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001386
1387 return false;
1388 }
1389 }
1390
1391 // Set Auto sync
1392 _bAutoSyncOn = bAutoSyncOn;
1393
1394 return true;
1395}
1396
1397bool CParameterMgr::autoSyncOn() const
1398{
1399 return _bAutoSyncOn;
1400}
1401
1402// Manual hardware synchronization control (during tuning session)
1403bool CParameterMgr::sync(string& strError)
1404{
1405 // Check tuning mode
1406 if (!checkTuningModeOn(strError)) {
1407
1408 return false;
1409 }
1410 // Warn domains about turning auto sync back on
1411 if (_bAutoSyncOn) {
1412
1413 strError = "Feature unavailable when Auto Sync is on";
1414
1415 return false;
1416 }
1417
1418 // Get syncer set
1419 CSyncerSet syncerSet;
1420 // ... from system class
1421 getConstSystemClass()->fillSyncerSet(syncerSet);
1422 // Sync
1423 return syncerSet.sync(*_pMainParameterBlackboard, false, strError);
1424}
1425
1426// Content dump
1427void CParameterMgr::logStructureContent(string& strContent) const
1428{
1429 string strError;
1430
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001431 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001432
1433 dumpContent(strContent, parameterAccessContext);
1434}
1435
1436// Configuration/Domains handling
1437bool CParameterMgr::createDomain(const string& strName, string& strError)
1438{
1439 // Check tuning mode
1440 if (!checkTuningModeOn(strError)) {
1441
1442 return false;
1443 }
1444
1445 // Delegate to configurable domains
1446 return getConfigurableDomains()->createDomain(strName, strError);
1447}
1448
1449bool CParameterMgr::deleteDomain(const string& strName, string& strError)
1450{
1451 // Check tuning mode
1452 if (!checkTuningModeOn(strError)) {
1453
1454 return false;
1455 }
1456
1457 // Delegate to configurable domains
1458 return getConfigurableDomains()->deleteDomain(strName, strError);
1459}
1460
Kevin Rocard170f0a42012-06-18 13:56:05 +02001461bool CParameterMgr::deleteAllDomains(string& strError)
1462{
1463 // Check tuning mode
1464 if (!checkTuningModeOn(strError)) {
1465
1466 return false;
1467 }
1468
1469 // Delegate to configurable domains
1470 getConfigurableDomains()->deleteAllDomains();
1471
1472 return true;
1473}
1474
Patrick Benavoli68a91282011-08-31 11:23:23 +02001475bool CParameterMgr::createConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1476{
1477 // Check tuning mode
1478 if (!checkTuningModeOn(strError)) {
1479
1480 return false;
1481 }
1482
1483 // Delegate to configurable domains
1484 return getConfigurableDomains()->createConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1485}
1486
1487bool CParameterMgr::deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1488{
1489 // Check tuning mode
1490 if (!checkTuningModeOn(strError)) {
1491
1492 return false;
1493 }
1494
1495 // Delegate to configurable domains
1496 return getConfigurableDomains()->deleteConfiguration(strDomain, strConfiguration, strError);
1497}
1498
1499bool CParameterMgr::restoreConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1500{
1501 // Check tuning mode
1502 if (!checkTuningModeOn(strError)) {
1503
1504 return false;
1505 }
1506
1507 // Delegate to configurable domains
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001508 return getConstConfigurableDomains()->restoreConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001509}
1510
1511bool CParameterMgr::saveConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1512{
1513 // Check tuning mode
1514 if (!checkTuningModeOn(strError)) {
1515
1516 return false;
1517 }
1518
1519 // Delegate to configurable domains
1520 return getConfigurableDomains()->saveConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1521}
1522
1523// Configurable element - domain association
1524bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1525{
1526 // Check tuning mode
1527 if (!checkTuningModeOn(strError)) {
1528
1529 return false;
1530 }
1531
1532 CElementLocator elementLocator(getSystemClass());
1533
1534 CElement* pLocatedElement = NULL;
1535
1536 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1537
1538 return false;
1539 }
1540
1541 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001542 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001543
1544 // Delegate
1545 return getConfigurableDomains()->addConfigurableElementToDomain(strDomain, pConfigurableElement, _pMainParameterBlackboard, strError);
1546}
1547
1548bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1549{
1550 // Check tuning mode
1551 if (!checkTuningModeOn(strError)) {
1552
1553 return false;
1554 }
1555
1556 CElementLocator elementLocator(getSystemClass());
1557
1558 CElement* pLocatedElement = NULL;
1559
1560 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1561
Patrick Benavoli63499d42011-10-24 18:50:03 +02001562 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001563 }
1564
1565 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001566 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001567
1568 // Delegate
1569 return getConfigurableDomains()->removeConfigurableElementFromDomain(strDomain, pConfigurableElement, strError);
1570}
1571
1572bool CParameterMgr::split(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1573{
1574 // Check tuning mode
1575 if (!checkTuningModeOn(strError)) {
1576
1577 return false;
1578 }
1579
1580 CElementLocator elementLocator(getSystemClass());
1581
1582 CElement* pLocatedElement = NULL;
1583
1584 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1585
Patrick Benavoli63499d42011-10-24 18:50:03 +02001586 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001587 }
1588
1589 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001590 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001591
1592 // Delegate
1593 return getConfigurableDomains()->split(strDomain, pConfigurableElement, strError);
1594}
1595
1596// XML Import/Export
1597bool CParameterMgr::importDomainsXml(const string& strFileName, bool bWithSettings, string& strError)
1598{
1599 // Check tuning mode
1600 if (!checkTuningModeOn(strError)) {
1601
1602 return false;
1603 }
1604
1605 // check path is absolute
1606 if (strFileName[0] != '/') {
1607
1608 strError = "Please provide absolute path";
1609
1610 return false;
1611 }
1612 // Root element
1613 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1614
1615 // Context
1616 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1617
1618 // Secltion criteria definition for rule creation
1619 xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
1620
1621 // Parse
1622 if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strFileName, "", EParameterConfigurationLibrary, "SystemClassName")) {
1623
1624 return false;
1625 }
1626
1627 // Validate domains after XML import
1628 pConfigurableDomains->validate(_pMainParameterBlackboard);
1629
1630 return true;
1631}
1632
1633bool CParameterMgr::exportDomainsXml(const string& strFileName, bool bWithSettings, string& strError) const
1634{
1635 // check path is absolute
1636 if (strFileName[0] != '/') {
1637
1638 strError = "Please provide absolute path";
1639
1640 return false;
1641 }
1642
1643 // Root element
1644 const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains();
1645
1646 // Get Schema file associated to root element
1647 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pConfigurableDomains->getKind() + ".xsd";
1648
1649 // Context
1650 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1651
1652 // Value space
1653 xmlDomainSerializingContext.setValueSpaceRaw(_bValueSpaceIsRaw);
1654
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001655 // Output raw format
1656 xmlDomainSerializingContext.setOutputRawFormat(_bOutputRawFormatIsHex);
1657
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001658 // Use a doc source by loading data from instantiated Configurable Domains
1659 CXmlMemoryDocSource memorySource(pConfigurableDomains, pConfigurableDomains->getKind(), strXmlSchemaFilePath, "parameter-framework", getVersion());
Patrick Benavoli68a91282011-08-31 11:23:23 +02001660
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001661 // Use a doc sink to write the doc data in a file
1662 CXmlFileDocSink fileSink(strFileName);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001663
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001664 if (!fileSink.process(memorySource, xmlDomainSerializingContext)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001665 return false;
1666 }
1667
1668 return true;
1669}
1670
1671// Binary Import/Export
1672bool CParameterMgr::importDomainsBinary(const string& strFileName, string& strError)
1673{
1674 // Check tuning mode
1675 if (!checkTuningModeOn(strError)) {
1676
1677 return false;
1678 }
1679 // check path is absolute
1680 if (strFileName[0] != '/') {
1681
1682 strError = "Please provide absolute path";
1683
1684 return false;
1685 }
1686 // Root element
1687 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1688
1689 // Serialize in
1690 return pConfigurableDomains->serializeSettings(strFileName, false, _uiStructureChecksum, strError);
1691}
1692
1693bool CParameterMgr::exportDomainsBinary(const string& strFileName, string& strError)
1694{
1695 // check path is absolute
1696 if (strFileName[0] != '/') {
1697
1698 strError = "Please provide absolute path";
1699
1700 return false;
1701 }
Patrick Benavoli68a91282011-08-31 11:23:23 +02001702
Patrick Benavoli68a91282011-08-31 11:23:23 +02001703 // Root element
1704 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1705
1706 // Serialize out
1707 return pConfigurableDomains->serializeSettings(strFileName, true, _uiStructureChecksum, strError);
1708}
1709
1710// For tuning, check we're in tuning mode
1711bool CParameterMgr::checkTuningModeOn(string& strError) const
1712{
1713 // Tuning Mode on?
1714 if (!_bTuningModeIsOn) {
1715
1716 strError = "Tuning Mode must be on";
1717
1718 return false;
1719 }
1720 return true;
1721}
1722
Patrick Benavoli065264a2011-11-20 15:46:41 +01001723// Tuning mutex dynamic parameter handling
1724pthread_mutex_t* CParameterMgr::getBlackboardMutex()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001725{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001726 return &_blackboardMutex;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001727}
1728
Patrick Benavoli065264a2011-11-20 15:46:41 +01001729// Blackboard reference (dynamic parameter handling)
1730CParameterBlackboard* CParameterMgr::getParameterBlackboard()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001731{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001732 return _pMainParameterBlackboard;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001733}
1734
Patrick Benavoli68a91282011-08-31 11:23:23 +02001735// Dynamic creation library feeding
1736void CParameterMgr::feedElementLibraries()
1737{
1738 // Global Configuration handling
1739 CElementLibrary* pFrameworkConfigurationLibrary = new CElementLibrary;
1740
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001741 pFrameworkConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CParameterFrameworkConfiguration>("ParameterFrameworkConfiguration"));
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +01001742 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CSubsystemPlugins>("SubsystemPlugins"));
1743 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CPluginLocation>("Location"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001744 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("StructureDescriptionFileLocation"));
1745 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationGroup>("SettingsConfiguration"));
1746 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("ConfigurableDomainsFileLocation"));
1747 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("BinarySettingsFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001748
1749 _pElementLibrarySet->addElementLibrary(pFrameworkConfigurationLibrary);
1750
1751 // Parameter creation
1752 CElementLibrary* pParameterCreationLibrary = new CElementLibrary;
1753
1754 pParameterCreationLibrary->addElementBuilder(new CSubsystemElementBuilder(getSystemClass()->getSubsystemLibrary()));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001755 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CComponentType>("ComponentType"));
1756 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CComponentInstance>("Component"));
1757 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBitParameterType>("BitParameter"));
1758 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBitParameterBlockType>("BitParameterBlock"));
Patrick Benavoli1352ae52011-10-21 16:48:04 +02001759 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CStringParameterType>("StringParameter"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001760 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CParameterBlockType>("ParameterBlock"));
1761 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBooleanParameterType>("BooleanParameter"));
1762 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CIntegerParameterType>("IntegerParameter"));
Patrick Benavoliee65e6d2011-11-20 18:52:24 +01001763 pParameterCreationLibrary->addElementBuilder(new TElementBuilderTemplate<CLinearParameterAdaptation>("LinearAdaptation"));
Patrick Benavoli9fc3c0d2011-10-27 14:27:27 +02001764 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CEnumParameterType>("EnumParameter"));
Patrick Benavoli68808c62012-02-02 17:12:41 +01001765 pParameterCreationLibrary->addElementBuilder(new TElementBuilderTemplate<CEnumValuePair>("ValuePair"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001766 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CFixedPointParameterType>("FixedPointParameter"));
1767 pParameterCreationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CXmlFileIncluderElement>("SubsystemInclude"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001768
1769 _pElementLibrarySet->addElementLibrary(pParameterCreationLibrary);
1770
1771 // Parameter Configuration Domains creation
1772 CElementLibrary* pParameterConfigurationLibrary = new CElementLibrary;
1773
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001774 pParameterConfigurationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CConfigurableDomain>("ConfigurableDomain"));
1775 pParameterConfigurationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CDomainConfiguration>("Configuration"));
1776 pParameterConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CCompoundRule>("CompoundRule"));
1777 pParameterConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CSelectionCriterionRule>("SelectionCriterionRule"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001778
1779 _pElementLibrarySet->addElementLibrary(pParameterConfigurationLibrary);
1780}
1781
1782// Remote Processor Server connection handling
1783bool CParameterMgr::handleRemoteProcessingInterface(string& strError)
1784{
1785 CAutoLog autoLog(this, "Handling remote processing interface");
1786
1787 // Start server if tuning allowed
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001788 if (getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001789
1790 log("Loading remote processor library");
1791
1792 // Load library
1793 void* lib_handle = dlopen("libremote-processor.so", RTLD_NOW);
1794
1795 if (!lib_handle) {
1796
1797 // Return error
1798 const char* pcError = dlerror();
1799
1800 if (pcError) {
1801
1802 strError = pcError;
1803 } else {
1804
1805 strError = "Unable to load libremote-processor.so library";
1806 }
1807
1808 return false;
1809 }
1810
1811 CreateRemoteProcessorServer pfnCreateRemoteProcessorServer = (CreateRemoteProcessorServer)dlsym(lib_handle, "createRemoteProcessorServer");
1812
1813 if (!pfnCreateRemoteProcessorServer) {
1814
1815 strError = "libremote-process.so does not contain createRemoteProcessorServer symbol.";
1816
1817 return false;
1818 }
1819
1820 // Create server
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001821 _pRemoteProcessorServer = pfnCreateRemoteProcessorServer(getConstFrameworkConfiguration()->getServerPort(), _pCommandHandler);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001822
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001823 log("Starting remote processor server on port %d", getConstFrameworkConfiguration()->getServerPort());
Patrick Benavoli68a91282011-08-31 11:23:23 +02001824 // Start
1825 if (!_pRemoteProcessorServer->start()) {
1826
1827 strError = "Unable to start remote processor server";
1828
1829 return false;
1830 }
1831 }
1832
1833 return true;
1834}
1835
1836// Back synchronization
1837CBackSynchronizer* CParameterMgr::createBackSynchronizer(string& strError) const
1838{
1839#ifdef SIMULATION
1840 // In simulation, back synchronization of the blackboard won't probably work
1841 // We need to ensure though the blackboard is initialized with valid data
1842 return new CSimulatedBackSynchronizer(getConstSystemClass(), strError, _pMainParameterBlackboard);
1843#else
1844 // Real back synchronizer from subsystems
1845 return new CHardwareBackSynchronizer(getConstSystemClass(), strError, _pMainParameterBlackboard);
1846#endif
1847}
1848
1849// Children typwise access
1850CParameterFrameworkConfiguration* CParameterMgr::getFrameworkConfiguration()
1851{
1852 return static_cast<CParameterFrameworkConfiguration*>(getChild(EFrameworkConfiguration));
1853}
1854
1855const CParameterFrameworkConfiguration* CParameterMgr::getConstFrameworkConfiguration()
1856{
1857 return getFrameworkConfiguration();
1858}
1859
1860CSelectionCriteria* CParameterMgr::getSelectionCriteria()
1861{
1862 return static_cast<CSelectionCriteria*>(getChild(ESelectionCriteria));
1863}
1864
1865const CSelectionCriteria* CParameterMgr::getConstSelectionCriteria()
1866{
1867 return static_cast<const CSelectionCriteria*>(getChild(ESelectionCriteria));
1868}
1869
1870CSystemClass* CParameterMgr::getSystemClass()
1871{
1872 return static_cast<CSystemClass*>(getChild(ESystemClass));
1873}
1874
1875const CSystemClass* CParameterMgr::getConstSystemClass() const
1876{
1877 return static_cast<const CSystemClass*>(getChild(ESystemClass));
1878}
1879
1880// Configurable Domains
1881CConfigurableDomains* CParameterMgr::getConfigurableDomains()
1882{
1883 return static_cast<CConfigurableDomains*>(getChild(EConfigurableDomains));
1884}
1885
1886const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains()
1887{
1888 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
1889}
1890
1891const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains() const
1892{
1893 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
1894}
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001895
1896/// GUI commands functions
1897
1898bool CParameterMgr::getDomainsXMLString(string& strResult, bool bWithSettings)
1899{
1900
1901 // Root element
1902 const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains();
1903
1904 // Get Schema file associated to root element
1905 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pConfigurableDomains->getKind() + ".xsd";
1906
1907 string strError;
1908
1909 // Context
1910 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1911
1912 // Value space
1913 xmlDomainSerializingContext.setValueSpaceRaw(_bValueSpaceIsRaw);
1914
1915 // Output raw format
1916 xmlDomainSerializingContext.setOutputRawFormat(_bOutputRawFormatIsHex);
1917
1918 // Use a doc source by loading data from instantiated Configurable Domains
1919 CXmlMemoryDocSource memorySource(pConfigurableDomains, pConfigurableDomains->getKind(), strXmlSchemaFilePath, "parameter-framework", getVersion());
1920
1921 // Use a doc sink the write the doc data in a string
1922 CXmlStringDocSink stringSink(strResult);
1923
1924 if (!stringSink.process(memorySource, xmlDomainSerializingContext)) {
1925 strResult = strError;
1926
1927 return false;
1928 }
1929
1930 return true;
1931}
1932
1933bool CParameterMgr::getSystemClassXMLString(string& strResult)
1934{
1935 // Root element
1936 const CSystemClass* pSystemClass = getSystemClass();
1937
1938 string strError;
1939
1940 CXmlSerializingContext xmlSerializingContext(strError);
1941
1942 // Use a doc source by loading data from instantiated Configurable Domains
1943 CXmlMemoryDocSource memorySource(pSystemClass, pSystemClass->getKind());
1944
1945 // Use a doc sink that write the doc data in a string
1946 CXmlStringDocSink stringSink(strResult);
1947
1948 if (!stringSink.process(memorySource, xmlSerializingContext)) {
1949 strResult = strError;
1950 return false;
1951 }
1952
1953 return true;
1954}