blob: 4116dbec0fc570012331af1b107dbbf967359124 [file] [log] [blame]
Frédéric Boisnarddaaa63c2012-08-27 15:48:15 +02001/*
Patrick Benavoli68a91282011-08-31 11:23:23 +02002 * INTEL CONFIDENTIAL
3 * Copyright © 2011 Intel
4 * Corporation All Rights Reserved.
5 *
6 * The source code contained or described herein and all documents related to
7 * the source code ("Material") are owned by Intel Corporation or its suppliers
8 * or licensors. Title to the Material remains with Intel Corporation or its
9 * suppliers and licensors. The Material contains trade secrets and proprietary
10 * and confidential information of Intel or its suppliers and licensors. The
11 * Material is protected by worldwide copyright and trade secret laws and
12 * treaty provisions. No part of the Material may be used, copied, reproduced,
13 * modified, published, uploaded, posted, transmitted, distributed, or
14 * disclosed in any way without Intel’s prior express written permission.
15 *
16 * No license under any patent, copyright, trade secret or other intellectual
17 * property right is granted to or conferred upon you by disclosure or delivery
18 * of the Materials, either expressly, by implication, inducement, estoppel or
19 * otherwise. Any license under such intellectual property rights must be
20 * express and approved by Intel in writing.
21 *
Patrick Benavoli68a91282011-08-31 11:23:23 +020022 * CREATED: 2011-06-01
23 * UPDATED: 2011-07-27
Patrick Benavoli68a91282011-08-31 11:23:23 +020024 */
25#include "ParameterMgr.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020026#include "XmlParameterSerializingContext.h"
27#include "XmlElementSerializingContext.h"
28#include "SystemClass.h"
29#include "ElementLibrarySet.h"
30#include "SubsystemLibrary.h"
31#include "NamedElementBuilderTemplate.h"
32#include "KindElementBuilderTemplate.h"
33#include "ElementBuilderTemplate.h"
34#include "SelectionCriterionType.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020035#include "SubsystemElementBuilder.h"
36#include "SelectionCriteria.h"
37#include "ComponentType.h"
38#include "ComponentInstance.h"
39#include "ParameterBlockType.h"
40#include "BooleanParameterType.h"
41#include "IntegerParameterType.h"
42#include "FixedPointParameterType.h"
43#include "ParameterBlackboard.h"
44#include "Parameter.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020045#include "ParameterBlackboard.h"
46#include "ParameterAccessContext.h"
47#include "XmlFileIncluderElement.h"
48#include "ParameterFrameworkConfiguration.h"
49#include "FrameworkConfigurationGroup.h"
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +010050#include "PluginLocation.h"
51#include "SubsystemPlugins.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020052#include "FrameworkConfigurationLocation.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020053#include "ConfigurableDomains.h"
54#include "ConfigurableDomain.h"
55#include "DomainConfiguration.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020056#include "XmlDomainSerializingContext.h"
57#include "BitParameterBlockType.h"
58#include "BitParameterType.h"
Patrick Benavoli1352ae52011-10-21 16:48:04 +020059#include "StringParameterType.h"
Patrick Benavoli9fc3c0d2011-10-27 14:27:27 +020060#include "EnumParameterType.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020061#include "RemoteProcessorServerInterface.h"
62#include "ElementLocator.h"
63#include "AutoLog.h"
64#include "CompoundRule.h"
65#include "SelectionCriterionRule.h"
66#include "SimulatedBackSynchronizer.h"
67#include "HardwareBackSynchronizer.h"
Patrick Benavoli1387bda2011-08-31 11:23:24 +020068#include "AutoLock.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020069#include <strings.h>
70#include <dlfcn.h>
71#include <assert.h>
Patrick Benavoli065264a2011-11-20 15:46:41 +010072#include "ParameterHandle.h"
Patrick Benavoliee65e6d2011-11-20 18:52:24 +010073#include "LinearParameterAdaptation.h"
Patrick Benavoli68808c62012-02-02 17:12:41 +010074#include "EnumValuePair.h"
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020075#include "XmlFileDocSink.h"
76#include "XmlFileDocSource.h"
77#include "XmlStringDocSink.h"
78#include "XmlMemoryDocSink.h"
79#include "XmlMemoryDocSource.h"
Kevin Rocardace81f82012-12-11 16:19:17 +010080#include "Utility.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020081
82#define base CElement
83
84// Used for remote processor server creation
85typedef IRemoteProcessorServerInterface* (*CreateRemoteProcessorServer)(uint16_t uiPort, IRemoteCommandHandler* pCommandHandler);
86
87// Global configuration file name (fixed)
88const char* gacParameterFrameworkConfigurationFileName = "ParameterFrameworkConfiguration.xml";
89const char* gacSystemSchemasSubFolder = "Schemas";
90
91// Config File System looks normally like this:
92// ---------------------------------------------
Patrick Benavoli95ac0342011-11-07 20:32:51 +010093//├── <ParameterFrameworkConfiguration>.xml
Patrick Benavoli68a91282011-08-31 11:23:23 +020094//├── Schemas
95//│ └── *.xsd
96//├── Settings
97//│ └── <SystemClassName folder>*
98//│ ├── <ConfigurableDomains>.xml
99//│ └── <Settings>.bin?
100//└── Structure
101// └── <SystemClassName folder>*
102// ├── <SystemClassName>Class.xml
103// └── <Subsystem>.xml*
104// --------------------------------------------
105
106
107// Remote command parser array
Patrick Benavoli592ae562011-09-05 16:53:58 +0200108const CParameterMgr::SRemoteCommandParserItem CParameterMgr::gastRemoteCommandParserItems[] = {
Patrick Benavoli592ae562011-09-05 16:53:58 +0200109 /// Version
110 { "version", &CParameterMgr::versionCommandProcess, 0, "", "Show version" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200111 /// Status
112 { "status", &CParameterMgr::statusCommandProcess, 0, "", "Show current status" },
113 /// Tuning Mode
114 { "setTuningMode", &CParameterMgr::setTuningModeCommmandProcess, 1, "on|off*", "Turn on or off Tuning Mode" },
115 { "getTuningMode", &CParameterMgr::getTuningModeCommmandProcess, 0, "", "Show Tuning Mode" },
116 /// Value Space
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200117 { "setValueSpace", &CParameterMgr::setValueSpaceCommmandProcess, 1, "raw|real*", "Assigns Value Space used for parameter value interpretation" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200118 { "getValueSpace", &CParameterMgr::getValueSpaceCommmandProcess, 0, "", "Show Value Space" },
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200119 /// Output Raw Format
120 { "setOutputRawFormat", &CParameterMgr::setOutputRawFormatCommmandProcess, 1, "dec*|hex", "Assigns format used to output parameter values when in raw Value Space" },
121 { "getOutputRawFormat", &CParameterMgr::getOutputRawFormatCommmandProcess, 0, "", "Show Output Raw Format" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200122 /// Sync
123 { "setAutoSync", &CParameterMgr::setAutoSyncCommmandProcess, 1, "on*|off", "Turn on or off automatic synchronization to hardware while in Tuning Mode" },
124 { "getAutoSync", &CParameterMgr::getAutoSyncCommmandProcess, 0, "", "Show Auto Sync state" },
125 { "sync", &CParameterMgr::syncCommmandProcess, 0, "", "Synchronize current settings to hardware while in Tuning Mode and Auto Sync off" },
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200126 /// Criteria
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200127 { "listCriteria", &CParameterMgr::listCriteriaCommmandProcess, 0, "", "List selection criteria" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200128 /// Domains
129 { "listDomains", &CParameterMgr::listDomainsCommmandProcess, 0, "", "List configurable domains" },
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100130 { "dumpDomains", &CParameterMgr::dumpDomainsCommmandProcess, 0, "", "Show all domains and configurations, including applicability conditions" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200131 { "createDomain", &CParameterMgr::createDomainCommmandProcess, 1, "<domain>", "Create new configurable domain" },
132 { "deleteDomain", &CParameterMgr::deleteDomainCommmandProcess, 1, "<domain>", "Delete configurable domain" },
Kevin Rocard170f0a42012-06-18 13:56:05 +0200133 { "deleteAllDomains", &CParameterMgr::deleteAllDomainsCommmandProcess, 0, "", "Delete all configurable domains" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200134 { "renameDomain", &CParameterMgr::renameDomainCommmandProcess, 2, "<domain> <new name>", "Rename configurable domain" },
Patrick Benavoli63499d42011-10-24 18:50:03 +0200135 { "setSequenceAwareness", &CParameterMgr::setSequenceAwarenessCommmandProcess, 1, "<domain> true|false*", "Set configurable domain sequence awareness" },
136 { "getSequenceAwareness", &CParameterMgr::getSequenceAwarenessCommmandProcess, 1, "<domain>", "Get configurable domain sequence awareness" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200137 { "listDomainElements", &CParameterMgr::listDomainElementsCommmandProcess, 1, "<domain>", "List elements associated to configurable domain" },
138 { "addElement", &CParameterMgr::addElementCommmandProcess, 2, "<domain> <elem path>", "Associate element at given path to configurable domain" },
139 { "removeElement", &CParameterMgr::removeElementCommmandProcess, 2, "<domain> <elem path>", "Dissociate element at given path from configurable domain" },
140 { "splitDomain", &CParameterMgr::splitDomainCommmandProcess, 2, "<domain> <elem path>", "Split configurable domain at given associated element path" },
141 /// Configurations
142 { "listConfigurations", &CParameterMgr::listConfigurationsCommmandProcess, 1, "<domain>", "List domain configurations" },
143 { "createConfiguration", &CParameterMgr::createConfigurationCommmandProcess, 2, "<domain> <configuration>", "Create new domain configuration" },
144 { "deleteConfiguration", &CParameterMgr::deleteConfigurationCommmandProcess, 2, "<domain> <configuration>", "Delete domain configuration" },
145 { "renameConfiguration", &CParameterMgr::renameConfigurationCommmandProcess, 3, "<domain> <configuration> <new name>", "Rename domain configuration" },
146 { "saveConfiguration", &CParameterMgr::saveConfigurationCommmandProcess, 2, "<domain> <configuration>", "Save current settings into configuration" },
147 { "restoreConfiguration", &CParameterMgr::restoreConfigurationCommmandProcess, 2, "<domain> <configuration>", "Restore current settings from configuration" },
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100148 { "setElementSequence", &CParameterMgr::setElementSequenceCommmandProcess, 3, "<domain> <configuration> <elem path list>", "Set element application order for configuration" },
Patrick Benavoli63499d42011-10-24 18:50:03 +0200149 { "getElementSequence", &CParameterMgr::getElementSequenceCommmandProcess, 2, "<domain> <configuration>", "Get element application order for configuration" },
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100150 { "setRule", &CParameterMgr::setRuleCommmandProcess, 3, "<domain> <configuration> <rule>", "Set configuration application rule" },
151 { "clearRule", &CParameterMgr::clearRuleCommmandProcess, 2, "<domain> <configuration>", "Clear configuration application rule" },
152 { "getRule", &CParameterMgr::getRuleCommmandProcess, 2, "<domain> <configuration>", "Get configuration application rule" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200153 /// Elements/Parameters
154 { "listElements", &CParameterMgr::listElementsCommmandProcess, 1, "<elem path>|/", "List elements under element at given path or root" },
Patrick Benavoli592ae562011-09-05 16:53:58 +0200155 { "listParameters", &CParameterMgr::listParametersCommmandProcess, 1, "<elem path>|/", "List parameters under element at given path or root" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200156 { "dumpElement", &CParameterMgr::dumpElementCommmandProcess, 1, "<elem path>", "Dump structure and content of element at given path" },
157 { "getElementSize", &CParameterMgr::getElementSizeCommmandProcess, 1, "<elem path>", "Show size of element at given path" },
Patrick Benavoli2ecf9002011-08-31 11:23:24 +0200158 { "showProperties", &CParameterMgr::showPropertiesCommmandProcess, 1, "<elem path>", "Show properties of element at given path" },
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200159 { "getParameter", &CParameterMgr::getParameterCommmandProcess, 1, "<param path>", "Get value for parameter at given path" },
Patrick Benavoli2ecf9002011-08-31 11:23:24 +0200160 { "setParameter", &CParameterMgr::setParameterCommmandProcess, 2, "<param path> <value>", "Set value for parameter at given path" },
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200161 { "listBelongingDomains", &CParameterMgr::listBelongingDomainsCommmandProcess, 1, "<elem path>", "List domain(s) element at given path belongs to" },
Patrick Benavoli68a91282011-08-31 11:23:23 +0200162 { "listAssociatedDomains", &CParameterMgr::listAssociatedDomainsCommmandProcess, 1, "<elem path>", "List domain(s) element at given path is associated to" },
163 /// Browse
164 { "listAssociatedElements", &CParameterMgr::listAssociatedElementsCommmandProcess, 0, "", "List element sub-trees associated to at least one configurable domain" },
165 { "listConflictingElements", &CParameterMgr::listConflictingElementsCommmandProcess, 0, "", "List element sub-trees contained in more than one configurable domain" },
166 { "listRogueElements", &CParameterMgr::listRogueElementsCommmandProcess, 0, "", "List element sub-trees owned by no configurable domain" },
167 /// Settings Import/Export
168 { "exportDomainsXML", &CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess, 1, "<file path> ", "Export domains to XML file" },
169 { "importDomainsXML", &CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess, 1, "<file path>", "Import domains from XML file" },
170 { "exportDomainsWithSettingsXML", &CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess, 1, "<file path> ", "Export domains including settings to XML file" },
171 { "importDomainsWithSettingsXML", &CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess, 1, "<file path>", "Import domains including settings from XML file" },
172 { "exportSettings", &CParameterMgr::exportSettingsCommmandProcess, 1, "<file path>", "Export settings to binary file" },
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200173 { "importSettings", &CParameterMgr::importSettingsCommmandProcess, 1, "<file path>", "Import settings from binary file" },
174 { "getDomainsXML", &CParameterMgr::getDomainsXMLCommmandProcess, 0 ,"", "Print domains including settings as XML" },
175 /// Structure Export
176 { "getSystemClassXML", &CParameterMgr::getSystemClassXMLCommmandProcess, 0 ,"", "Print parameter structure as XML" }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200177};
178// Remote command parsers array Size
Patrick Benavoli592ae562011-09-05 16:53:58 +0200179const uint32_t CParameterMgr::guiNbRemoteCommandParserItems = sizeof(gastRemoteCommandParserItems) / sizeof(gastRemoteCommandParserItems[0]);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200180
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100181CParameterMgr::CParameterMgr(const string& strConfigurationFilePath) :
Patrick Benavoli68a91282011-08-31 11:23:23 +0200182 _bTuningModeIsOn(false),
183 _bValueSpaceIsRaw(false),
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200184 _bOutputRawFormatIsHex(false),
Patrick Benavoli68a91282011-08-31 11:23:23 +0200185 _bAutoSyncOn(true),
186 _pMainParameterBlackboard(new CParameterBlackboard),
187 _pElementLibrarySet(new CElementLibrarySet),
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100188 _strXmlConfigurationFilePath(strConfigurationFilePath),
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100189 _pSubsystemPlugins(NULL),
Patrick Benavoli68a91282011-08-31 11:23:23 +0200190 _uiStructureChecksum(0),
191 _pRemoteProcessorServer(NULL),
192 _uiMaxCommandUsageLength(0),
193 _pLogger(NULL),
194 _uiLogDepth(0)
195{
196 // Tuning Mode Mutex
Patrick Benavoli065264a2011-11-20 15:46:41 +0100197 bzero(&_blackboardMutex, sizeof(_blackboardMutex));
198 pthread_mutex_init(&_blackboardMutex, NULL);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200199
200 // Deal with children
201 addChild(new CParameterFrameworkConfiguration);
202 addChild(new CSelectionCriteria);
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100203 addChild(new CSystemClass);
204 addChild(new CConfigurableDomains);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200205
206 // Feed element library
207 feedElementLibraries();
Patrick Benavoli63499d42011-10-24 18:50:03 +0200208
209 _pCommandHandler = new CCommandHandler(this);
210
211 // Add command parsers
212 uint32_t uiRemoteCommandParserItem;
213
214 for (uiRemoteCommandParserItem = 0; uiRemoteCommandParserItem < guiNbRemoteCommandParserItems; uiRemoteCommandParserItem++) {
215
216 const SRemoteCommandParserItem* pRemoteCommandParserItem = &gastRemoteCommandParserItems[uiRemoteCommandParserItem];
217
218 _pCommandHandler->addCommandParser(pRemoteCommandParserItem->_pcCommandName,
219 pRemoteCommandParserItem->_pfnParser,
220 pRemoteCommandParserItem->_uiMinArgumentCount,
221 pRemoteCommandParserItem->_pcHelp,
222 pRemoteCommandParserItem->_pcDescription);
223 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100224
225 // Configuration file folder
226 uint32_t uiSlashPos = _strXmlConfigurationFilePath.rfind('/', -1);
227
228 assert(uiSlashPos != (uint32_t)-1);
229
230 _strXmlConfigurationFolderPath = _strXmlConfigurationFilePath.substr(0, uiSlashPos);
231
232 // Schema absolute folder location
233 _strSchemaFolderLocation = _strXmlConfigurationFolderPath + "/" + gacSystemSchemasSubFolder;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200234}
235
236CParameterMgr::~CParameterMgr()
237{
238 // Children
239 delete _pRemoteProcessorServer;
Frederic Boisnard31242302012-04-26 17:07:34 +0200240 delete _pCommandHandler;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200241 delete _pMainParameterBlackboard;
242 delete _pElementLibrarySet;
243
244 // Tuning Mode Mutex
Patrick Benavoli065264a2011-11-20 15:46:41 +0100245 pthread_mutex_destroy(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200246}
247
248string CParameterMgr::getKind() const
249{
250 return "ParameterMgr";
251}
252
253// Logging
254void CParameterMgr::setLogger(CParameterMgr::ILogger* pLogger)
255{
256 _pLogger = pLogger;
257}
258
259// Logging
Kevin Rocardace81f82012-12-11 16:19:17 +0100260void CParameterMgr::doLog(bool bIsWarning, const string& strLog) const
Patrick Benavoli68a91282011-08-31 11:23:23 +0200261{
262 if (_pLogger) {
263
264 // Nest
265 string strIndent;
266
267 // Level
268 uint32_t uiNbIndents = _uiLogDepth;
269
270 while (uiNbIndents--) {
271
272 strIndent += " ";
273 }
274
275 // Log
Kevin Rocardace81f82012-12-11 16:19:17 +0100276 _pLogger->log(bIsWarning, strIndent + strLog);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200277 }
278}
279
280void CParameterMgr::nestLog() const
281{
Patrick Benavoli592ae562011-09-05 16:53:58 +0200282 _uiLogDepth++;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200283}
284
285void CParameterMgr::unnestLog() const
286{
Patrick Benavoli592ae562011-09-05 16:53:58 +0200287 _uiLogDepth--;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200288}
289
Patrick Benavoli63499d42011-10-24 18:50:03 +0200290// Version
291string CParameterMgr::getVersion() const
292{
293 string strVersion;
294
295 // Major
296 strVersion = toString(guiEditionMajor) + ".";
297 // Minor
298 strVersion += toString(guiEditionMinor) + ".";
299 // Revision
300 strVersion += toString(guiRevision);
301
302 return strVersion;
303}
304
Patrick Benavoli68a91282011-08-31 11:23:23 +0200305bool CParameterMgr::load(string& strError)
306{
307 CAutoLog autoLog(this, "Loading");
308
309 // Load Framework configuration
310 if (!loadFrameworkConfiguration(strError)) {
311
312 return false;
313 }
314
315 // Load subsystems
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100316 if (!getSystemClass()->loadSubsystems(strError, _pSubsystemPlugins)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200317
318 return false;
319 }
320
321 // Load structure
322 if (!loadStructure(strError)) {
323
324 return false;
325 }
326
327 // Load settings
328 if (!loadSettings(strError)) {
329
330 return false;
331 }
332
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200333 // Back synchronization for areas in parameter blackboard not covered by any domain
Kevin Rocardace81f82012-12-11 16:19:17 +0100334 CBackSynchronizer* pBackSynchronizer = createBackSynchronizer();
Patrick Benavoli68a91282011-08-31 11:23:23 +0200335
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200336 // Back-synchronize
Kevin Rocard57096bd2012-11-30 11:24:20 +0100337 {
338 CAutoLog autoLog(this, "Main blackboard back synchronization");
339
340 if (!pBackSynchronizer->sync()) {
341 // Get rid of back synchronizer
342 delete pBackSynchronizer;
343
Kevin Rocardace81f82012-12-11 16:19:17 +0100344 strError = "Main blackboard back synchronization failed";
Kevin Rocard57096bd2012-11-30 11:24:20 +0100345
346 return false;
347 }
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200348 // Get rid of back synchronizer
349 delete pBackSynchronizer;
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200350 }
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200351
352 // We're done loading the settings and back synchronizing
353 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
354
355 // We need to ensure all domains are valid
356 pConfigurableDomains->validate(_pMainParameterBlackboard);
357
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100358 // At initialization, check subsystems that need resync
359 doApplyConfigurations(true);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200360
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200361 // Start remote processor server if appropriate
362 return handleRemoteProcessingInterface(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200363}
364
365bool CParameterMgr::loadFrameworkConfiguration(string& strError)
366{
367 CAutoLog autoLog(this, "Loading framework configuration");
368
Patrick Benavoli68a91282011-08-31 11:23:23 +0200369 // Parse Structure XML file
370 CXmlElementSerializingContext elementSerializingContext(strError);
371
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100372 if (!xmlParse(elementSerializingContext, getFrameworkConfiguration(), _strXmlConfigurationFilePath, _strXmlConfigurationFolderPath, EFrameworkConfigurationLibrary)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200373
374 return false;
375 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100376 // Set class name to system class and configurable domains
377 getSystemClass()->setName(getConstFrameworkConfiguration()->getSystemClassName());
378 getConfigurableDomains()->setName(getConstFrameworkConfiguration()->getSystemClassName());
379
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100380 // Get subsystem plugins elements
381 _pSubsystemPlugins = static_cast<const CSubsystemPlugins*>(getConstFrameworkConfiguration()->findChild("SubsystemPlugins"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200382
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100383 if (!_pSubsystemPlugins) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200384
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100385 strError = "Parameter Framework Configuration: couldn't find SubsystemPlugins element";
Patrick Benavoli68a91282011-08-31 11:23:23 +0200386
387 return false;
388 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200389
Patrick Benavoli68a91282011-08-31 11:23:23 +0200390 // Log tuning availability
Kevin Rocardace81f82012-12-11 16:19:17 +0100391 log_info("Tuning %s", getConstFrameworkConfiguration()->isTuningAllowed() ? "allowed" : "prohibited");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200392
393 return true;
394}
395
396bool CParameterMgr::loadStructure(string& strError)
397{
398 // Retrieve system to load structure to
399 CSystemClass* pSystemClass = getSystemClass();
400
401 CAutoLog autoLog(this, "Loading " + pSystemClass->getName() + " system class structure");
402
403 // Get structure description element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100404 const CFrameworkConfigurationLocation* pStructureDescriptionFileLocation = static_cast<const CFrameworkConfigurationLocation*>(getConstFrameworkConfiguration()->findChildOfKind("StructureDescriptionFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200405
406 if (!pStructureDescriptionFileLocation) {
407
408 strError = "No StructureDescriptionFileLocation element found for SystemClass " + pSystemClass->getName();
409
410 return false;
411 }
412
413 // Get Xml structure folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100414 string strXmlStructureFolder = pStructureDescriptionFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200415
416 // Get Xml structure file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100417 string strXmlStructureFilePath = pStructureDescriptionFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200418
419 // Parse Structure XML file
420 CXmlParameterSerializingContext parameterBuildContext(strError);
421
Kevin Rocard57096bd2012-11-30 11:24:20 +0100422 CAutoLog autolog(pSystemClass, "Importing system structure from file " + strXmlStructureFilePath);
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200423
Patrick Benavoli68a91282011-08-31 11:23:23 +0200424 if (!xmlParse(parameterBuildContext, pSystemClass, strXmlStructureFilePath, strXmlStructureFolder, EParameterCreationLibrary)) {
425
426 return false;
427 }
428
429 // Initialize offsets
430 pSystemClass->setOffset(0);
431
432 // Initialize main blackboard's size
433 _pMainParameterBlackboard->setSize(pSystemClass->getFootPrint());
434
435 return true;
436}
437
438bool CParameterMgr::loadSettings(string& strError)
439{
440 CAutoLog autoLog(this, "Loading settings");
441
442 // Get settings configuration element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100443 const CFrameworkConfigurationGroup* pParameterConfigurationGroup = static_cast<const CFrameworkConfigurationGroup*>(getConstFrameworkConfiguration()->findChildOfKind("SettingsConfiguration"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200444
445 if (!pParameterConfigurationGroup) {
446
447 // No settings to load
448
449 return true;
450 }
451 // Get binary settings file location
452 const CFrameworkConfigurationLocation* pBinarySettingsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("BinarySettingsFileLocation"));
453
454 string strXmlBinarySettingsFilePath;
455
456 if (pBinarySettingsFileLocation) {
457
458 // Get Xml binary settings file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100459 strXmlBinarySettingsFilePath = pBinarySettingsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200460 }
461
462 // Get configurable domains element
463 const CFrameworkConfigurationLocation* pConfigurableDomainsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("ConfigurableDomainsFileLocation"));
464
465 if (!pConfigurableDomainsFileLocation) {
466
467 strError = "No ConfigurableDomainsFileLocation element found for SystemClass " + getSystemClass()->getName();
468
469 return false;
470 }
471 // Get destination root element
472 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
473
474 // Get Xml configuration domains file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100475 string strXmlConfigurationDomainsFilePath = pConfigurableDomainsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200476
477 // Get Xml configuration domains folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100478 string strXmlConfigurationDomainsFolder = pConfigurableDomainsFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200479
480 // Parse configuration domains XML file (ask to read settings from XML file if they are not provided as binary)
481 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, !pBinarySettingsFileLocation);
482
483 // Selection criteria definition for rule creation
484 xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
485
Patrick Benavoli63499d42011-10-24 18:50:03 +0200486 // Auto validation of configurations if no binary settings provided
487 xmlDomainSerializingContext.setAutoValidationRequired(!pBinarySettingsFileLocation);
488
Kevin Rocardace81f82012-12-11 16:19:17 +0100489 log_info("Importing configurable domains from file %s %s settings", strXmlConfigurationDomainsFilePath.c_str(), pBinarySettingsFileLocation ? "without" : "with");
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200490
Patrick Benavoli68a91282011-08-31 11:23:23 +0200491 // Do parse
492 if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strXmlConfigurationDomainsFilePath, strXmlConfigurationDomainsFolder, EParameterConfigurationLibrary, "SystemClassName")) {
493
494 return false;
495 }
496 // We have loaded the whole system structure, compute checksum
497 const CSystemClass* pSystemClass = getConstSystemClass();
498 _uiStructureChecksum = pSystemClass->computeStructureChecksum() + getConfigurableDomains()->computeStructureChecksum() + getSelectionCriteria()->computeStructureChecksum();
499
500 // Load binary settings if any provided
501 if (pBinarySettingsFileLocation && !pConfigurableDomains->serializeSettings(strXmlBinarySettingsFilePath, false, _uiStructureChecksum, strError)) {
502
503 return false;
504 }
505
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200506 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200507}
508
509// XML parsing
510bool CParameterMgr::xmlParse(CXmlElementSerializingContext& elementSerializingContext, CElement* pRootElement, const string& strXmlFilePath, const string& strXmlFolder, CParameterMgr::ElementLibrary eElementLibrary, const string& strNameAttrituteName)
511{
512 // Init serializing context
513 elementSerializingContext.set(_pElementLibrarySet->getElementLibrary(eElementLibrary), strXmlFolder, _strSchemaFolderLocation);
514
515 // Get Schema file associated to root element
516 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pRootElement->getKind() + ".xsd";
517
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200518 CXmlFileDocSource fileDocSource(strXmlFilePath, strXmlSchemaFilePath, pRootElement->getKind(), pRootElement->getName(), strNameAttrituteName);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200519
520 // Start clean
521 pRootElement->clean();
522
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200523 CXmlMemoryDocSink memorySink(pRootElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200524
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200525 if (!memorySink.process(fileDocSource, elementSerializingContext)) {
526 //Cleanup
Patrick Benavoli68a91282011-08-31 11:23:23 +0200527 pRootElement->clean();
528
529 return false;
530 }
531
Patrick Benavoli68a91282011-08-31 11:23:23 +0200532 return true;
533}
534
535// Init
536bool CParameterMgr::init(string& strError)
537{
538 return base::init(strError);
539}
540
541// Selection criteria interface
542CSelectionCriterionType* CParameterMgr::createSelectionCriterionType(bool bIsInclusive)
543{
544 // Propagate
545 return getSelectionCriteria()->createSelectionCriterionType(bIsInclusive);
546}
547
548CSelectionCriterion* CParameterMgr::createSelectionCriterion(const string& strName, const CSelectionCriterionType* pSelectionCriterionType)
549{
550 // Propagate
551 return getSelectionCriteria()->createSelectionCriterion(strName, pSelectionCriterionType);
552}
553
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200554// Selection criterion retrieval
555CSelectionCriterion* CParameterMgr::getSelectionCriterion(const string& strName)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200556{
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200557 // Propagate
558 return getSelectionCriteria()->getSelectionCriterion(strName);
559}
560
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100561// Configuration application
Kevin Rocardace81f82012-12-11 16:19:17 +0100562void CParameterMgr::applyConfigurations()
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200563{
564 CAutoLog autoLog(this, "Configuration application request");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200565
566 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +0100567 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200568
569 if (!_bTuningModeIsOn) {
570
571 // Apply configuration(s)
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100572 doApplyConfigurations(false);
Frédéric Boisnarddaaa63c2012-08-27 15:48:15 +0200573 } else {
574
Kevin Rocardace81f82012-12-11 16:19:17 +0100575 log_warning("Configurations were not applied because the TuningMode is on");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200576 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200577}
578
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200579// Dynamic parameter handling
Patrick Benavoli065264a2011-11-20 15:46:41 +0100580CParameterHandle* CParameterMgr::createParameterHandle(const string& strPath, string& strError)
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200581{
Patrick Benavoli065264a2011-11-20 15:46:41 +0100582 CPathNavigator pathNavigator(strPath);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200583
Patrick Benavoli065264a2011-11-20 15:46:41 +0100584 // Nagivate through system class
585 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
586
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100587 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100588 }
589
590 // Find element
591 const CElement* pElement = getConstSystemClass()->findDescendant(pathNavigator);
592
593 if (!pElement) {
594
595 strError = "Path not found";
596
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100597 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100598 }
599
600 // Check found element is a parameter
601 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pElement);
602
603 if (!pConfigurableElement->isParameter()) {
604
605 // Element is not parameter
606 strError = "Not a parameter";
607
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100608 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100609 }
610
611 // Convert as parameter and return new handle
612 return new CParameterHandle(static_cast<const CBaseParameter*>(pElement), this);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200613}
614
Patrick Benavoli68a91282011-08-31 11:23:23 +0200615/////////////////// Remote command parsers
Patrick Benavoli592ae562011-09-05 16:53:58 +0200616/// Version
Patrick Benavoli63499d42011-10-24 18:50:03 +0200617CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::versionCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli592ae562011-09-05 16:53:58 +0200618{
619 (void)remoteCommand;
620
Patrick Benavoli63499d42011-10-24 18:50:03 +0200621 // Show version
622 strResult = getVersion();
Patrick Benavoli592ae562011-09-05 16:53:58 +0200623
Patrick Benavoli63499d42011-10-24 18:50:03 +0200624 return CCommandHandler::ESucceeded;
Patrick Benavoli592ae562011-09-05 16:53:58 +0200625}
626
Patrick Benavoli68a91282011-08-31 11:23:23 +0200627/// Status
Patrick Benavoli63499d42011-10-24 18:50:03 +0200628CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::statusCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200629{
630 (void)remoteCommand;
631 // System class
632 const CSystemClass* pSystemClass = getSystemClass();
633
Patrick Benavoli68a91282011-08-31 11:23:23 +0200634 // Show status
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200635 /// General section
636 appendTitle(strResult, "General:");
637 // System class
Patrick Benavoli68a91282011-08-31 11:23:23 +0200638 strResult += "System Class: ";
639 strResult += pSystemClass->getName();
640 strResult += "\n";
641
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200642 // Tuning mode
Patrick Benavoli68a91282011-08-31 11:23:23 +0200643 strResult += "Tuning Mode: ";
644 strResult += tuningModeOn() ? "on" : "off";
645 strResult += "\n";
646
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200647 // Value space
Patrick Benavoli68a91282011-08-31 11:23:23 +0200648 strResult += "Value Space: ";
649 strResult += valueSpaceIsRaw() ? "raw" : "real";
650 strResult += "\n";
651
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200652 // Output raw format
653 strResult += "Output Raw Format: ";
654 strResult += outputRawFormatIsHex() ? "hex" : "dec";
655 strResult += "\n";
656
657 // Auto Sync
Patrick Benavoli68a91282011-08-31 11:23:23 +0200658 strResult += "Auto Sync: ";
659 strResult += autoSyncOn() ? "on" : "off";
660 strResult += "\n";
661
662 /// Subsystem list
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200663 appendTitle(strResult, "Subsystems:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200664 string strSubsystemList;
665 pSystemClass->listChildrenPaths(strSubsystemList);
666 strResult += strSubsystemList;
667
668 /// Last applied configurations
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200669 appendTitle(strResult, "Last Applied [Pending] Configurations:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200670 string strLastAppliedConfigurations;
671 getConfigurableDomains()->listLastAppliedConfigurations(strLastAppliedConfigurations);
672 strResult += strLastAppliedConfigurations;
673
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200674 /// Criteria states
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200675 appendTitle(strResult, "Selection Criteria:");
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200676 string strSelectionCriteria;
677 getSelectionCriteria()->listSelectionCriteria(strSelectionCriteria, false);
678 strResult += strSelectionCriteria;
679
Patrick Benavoli63499d42011-10-24 18:50:03 +0200680 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200681}
682
683/// Tuning Mode
Patrick Benavoli63499d42011-10-24 18:50:03 +0200684CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200685{
686 if (remoteCommand.getArgument(0) == "on") {
687
688 if (setTuningMode(true, strResult)) {
689
Patrick Benavoli63499d42011-10-24 18:50:03 +0200690 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200691 }
692 } else if (remoteCommand.getArgument(0) == "off") {
693
694 if (setTuningMode(false, strResult)) {
695
Patrick Benavoli63499d42011-10-24 18:50:03 +0200696 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200697 }
698 } else {
699 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200700 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200701 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200702 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200703}
704
Patrick Benavoli63499d42011-10-24 18:50:03 +0200705CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200706{
707 (void)remoteCommand;
708
709 strResult = tuningModeOn() ? "on" : "off";
710
Patrick Benavoli63499d42011-10-24 18:50:03 +0200711 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200712}
713
714/// Value Space
Patrick Benavoli63499d42011-10-24 18:50:03 +0200715CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200716{
717 (void)strResult;
718
719 if (remoteCommand.getArgument(0) == "raw") {
720
721 setValueSpace(true);
722
Patrick Benavoli63499d42011-10-24 18:50:03 +0200723 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200724
725 } else if (remoteCommand.getArgument(0) == "real") {
726
727 setValueSpace(false);
728
Patrick Benavoli63499d42011-10-24 18:50:03 +0200729 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200730
731 } else {
732 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200733 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200734 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200735 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200736}
737
Patrick Benavoli63499d42011-10-24 18:50:03 +0200738CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200739{
740 (void)remoteCommand;
741
742 strResult = valueSpaceIsRaw() ? "raw" : "real";
743
Patrick Benavoli63499d42011-10-24 18:50:03 +0200744 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200745}
746
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200747/// Output Raw Format
Patrick Benavoli63499d42011-10-24 18:50:03 +0200748CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200749{
750 (void)strResult;
751
752 if (remoteCommand.getArgument(0) == "hex") {
753
754 setOutputRawFormat(true);
755
Patrick Benavoli63499d42011-10-24 18:50:03 +0200756 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200757
758 } else if (remoteCommand.getArgument(0) == "dec") {
759
760 setOutputRawFormat(false);
761
Patrick Benavoli63499d42011-10-24 18:50:03 +0200762 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200763
764 } else {
765 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200766 return CCommandHandler::EShowUsage;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200767 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200768 return CCommandHandler::EFailed;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200769}
770
Patrick Benavoli63499d42011-10-24 18:50:03 +0200771CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200772{
773 (void)remoteCommand;
774
775 strResult = outputRawFormatIsHex() ? "hex" : "dec";
776
Patrick Benavoli63499d42011-10-24 18:50:03 +0200777 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200778}
779
Patrick Benavoli68a91282011-08-31 11:23:23 +0200780/// Sync
Patrick Benavoli63499d42011-10-24 18:50:03 +0200781CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200782{
783 if (remoteCommand.getArgument(0) == "on") {
784
785 if (setAutoSync(true, strResult)) {
786
Patrick Benavoli63499d42011-10-24 18:50:03 +0200787 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200788 }
789 } else if (remoteCommand.getArgument(0) == "off") {
790
791 if (setAutoSync(false, strResult)) {
792
Patrick Benavoli63499d42011-10-24 18:50:03 +0200793 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200794 }
795 } else {
796 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200797 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200798 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200799 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200800}
801
Patrick Benavoli63499d42011-10-24 18:50:03 +0200802CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200803{
804 (void)remoteCommand;
805
806 strResult = autoSyncOn() ? "on" : "off";
807
Patrick Benavoli63499d42011-10-24 18:50:03 +0200808 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200809}
810
Patrick Benavoli63499d42011-10-24 18:50:03 +0200811CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::syncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200812{
813 (void)remoteCommand;
814
Patrick Benavoli63499d42011-10-24 18:50:03 +0200815 return sync(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200816}
817
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200818/// Criteria
Patrick Benavoli63499d42011-10-24 18:50:03 +0200819CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listCriteriaCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200820{
821 (void)remoteCommand;
822
823 getSelectionCriteria()->listSelectionCriteria(strResult, true);
824
Patrick Benavoli63499d42011-10-24 18:50:03 +0200825 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200826}
Patrick Benavoli68a91282011-08-31 11:23:23 +0200827
828/// Domains
Patrick Benavoli63499d42011-10-24 18:50:03 +0200829CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200830{
831 (void)remoteCommand;
832
Patrick Benavoli63499d42011-10-24 18:50:03 +0200833 getConfigurableDomains()->listDomains(strResult);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200834
Patrick Benavoli63499d42011-10-24 18:50:03 +0200835 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200836}
837
Patrick Benavoli63499d42011-10-24 18:50:03 +0200838CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200839{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200840 return createDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200841}
842
Patrick Benavoli63499d42011-10-24 18:50:03 +0200843CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200844{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200845 return deleteDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200846}
847
Kevin Rocard170f0a42012-06-18 13:56:05 +0200848CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteAllDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
849{
850 (void)remoteCommand;
851
852 return deleteAllDomains(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
853}
854
Patrick Benavoli63499d42011-10-24 18:50:03 +0200855CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200856{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200857 return getConfigurableDomains()->renameDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200858}
859
Patrick Benavoli63499d42011-10-24 18:50:03 +0200860CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200861{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200862 // Check tuning mode
863 if (!checkTuningModeOn(strResult)) {
864
865 return CCommandHandler::EFailed;
866 }
867
868 // Set property
869 bool bSequenceAware;
870
871 if (remoteCommand.getArgument(1) == "true") {
872
873 bSequenceAware = true;
874
875 } else if (remoteCommand.getArgument(1) == "false") {
876
877 bSequenceAware = false;
878
879 } else {
880 // Show usage
881 return CCommandHandler::EShowUsage;
882 }
883
884 return getConfigurableDomains()->setSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200885}
886
Patrick Benavoli63499d42011-10-24 18:50:03 +0200887CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200888{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200889 // Get property
890 bool bSequenceAware;
891
892 if (!getConfigurableDomains()->getSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult)) {
893
894 return CCommandHandler::EFailed;
895 }
896
897 strResult = bSequenceAware ? "true" : "false";
898
899 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200900}
901
Patrick Benavoli63499d42011-10-24 18:50:03 +0200902CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200903{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200904 return getConfigurableDomains()->listDomainElements(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200905}
906
Patrick Benavoli63499d42011-10-24 18:50:03 +0200907CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::addElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200908{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200909 return addConfigurableElementToDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
910}
911
912CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::removeElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
913{
914 return removeConfigurableElementFromDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
915}
916
917CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::splitDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
918{
919 return split(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200920}
921
922/// Configurations
Patrick Benavoli63499d42011-10-24 18:50:03 +0200923CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConfigurationsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200924{
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100925 return getConstConfigurableDomains()->listConfigurations(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
926}
927
928CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
929{
930 (void)remoteCommand;
931
932 // Dummy error context
933 string strError;
934 CErrorContext errorContext(strError);
935
936 // Dump
937 getConstConfigurableDomains()->dumpContent(strResult, errorContext);
938
939 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200940}
941
Patrick Benavoli63499d42011-10-24 18:50:03 +0200942CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200943{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200944 return createConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200945}
946
Patrick Benavoli63499d42011-10-24 18:50:03 +0200947CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200948{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200949 return deleteConfiguration(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::renameConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200953{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200954 return getConfigurableDomains()->renameConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), 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::saveConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200958{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200959 return saveConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), 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::restoreConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200963{
Kevin Rocardace81f82012-12-11 16:19:17 +0100964 list<string> lstrResult;
965 if (!restoreConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), lstrResult)) {
966 //Concatenate the error list as the command result
967 CUtility::concatenate(lstrResult, strResult);
968
969 return CCommandHandler::EFailed;
970 }
971 return CCommandHandler::EDone;
Patrick Benavoli63499d42011-10-24 18:50:03 +0200972}
973
974CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
975{
976 // Check tuning mode
977 if (!checkTuningModeOn(strResult)) {
978
979 return CCommandHandler::EFailed;
980 }
981
982 // Build configurable element path list
983 vector<string> astrNewElementSequence;
984
985 uint32_t uiArgument;
986
987 for (uiArgument = 2; uiArgument < remoteCommand.getArgumentCount(); uiArgument++) {
988
989 astrNewElementSequence.push_back(remoteCommand.getArgument(uiArgument));
990 }
991
992 // Delegate to configurable domains
993 return getConfigurableDomains()->setElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), astrNewElementSequence, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
994}
995
996CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
997{
998 // Delegate to configurable domains
999 return getConfigurableDomains()->getElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001000}
1001
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001002CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1003{
1004 // Delegate to configurable domains
1005 return getConfigurableDomains()->setApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.packArguments(2, remoteCommand.getArgumentCount() - 2), getConstSelectionCriteria()->getSelectionCriteriaDefinition(), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1006}
1007
1008CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::clearRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1009{
1010 // Delegate to configurable domains
1011 return getConfigurableDomains()->clearApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1012}
1013
1014CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1015{
1016 // Delegate to configurable domains
1017 return getConfigurableDomains()->getApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
1018}
1019
Patrick Benavoli68a91282011-08-31 11:23:23 +02001020/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001021CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001022{
1023 CElementLocator elementLocator(getSystemClass(), false);
1024
1025 CElement* pLocatedElement = NULL;
1026
1027 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1028
Patrick Benavoli63499d42011-10-24 18:50:03 +02001029 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001030 }
1031
1032 strResult = string("\n");
1033
1034 if (!pLocatedElement) {
1035
1036 // List from root folder
1037
1038 // Return system class qualified name
1039 pLocatedElement = getSystemClass();
1040 }
1041
1042 // Return sub-elements
1043 strResult += pLocatedElement->listQualifiedPaths(false);
1044
Patrick Benavoli63499d42011-10-24 18:50:03 +02001045 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001046}
1047
1048/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001049CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listParametersCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001050{
1051 CElementLocator elementLocator(getSystemClass(), false);
1052
1053 CElement* pLocatedElement = NULL;
1054
1055 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1056
Patrick Benavoli63499d42011-10-24 18:50:03 +02001057 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001058 }
1059
1060 strResult = string("\n");
1061
1062 if (!pLocatedElement) {
1063
1064 // List from root folder
1065
1066 // Return system class qualified name
1067 pLocatedElement = getSystemClass();
1068 }
1069
1070 // Return sub-elements
1071 strResult += pLocatedElement->listQualifiedPaths(true);
1072
Patrick Benavoli63499d42011-10-24 18:50:03 +02001073 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001074}
1075
Patrick Benavoli63499d42011-10-24 18:50:03 +02001076CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001077{
1078 CElementLocator elementLocator(getSystemClass());
1079
1080 CElement* pLocatedElement = NULL;
1081
1082 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1083
Patrick Benavoli63499d42011-10-24 18:50:03 +02001084 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001085 }
1086
1087 string strError;
1088
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001089 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001090
1091 // Dump elements
1092 pLocatedElement->dumpContent(strResult, parameterAccessContext);
1093
Patrick Benavoli63499d42011-10-24 18:50:03 +02001094 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001095}
1096
Patrick Benavoli63499d42011-10-24 18:50:03 +02001097CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSizeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001098{
1099 CElementLocator elementLocator(getSystemClass());
1100
1101 CElement* pLocatedElement = NULL;
1102
1103 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1104
Patrick Benavoli63499d42011-10-24 18:50:03 +02001105 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001106 }
1107
1108 // Converted to actual sizable element
1109 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1110
1111 // Get size as string
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001112 strResult = pConfigurableElement->getFootprintAsString();
Patrick Benavoli68a91282011-08-31 11:23:23 +02001113
Patrick Benavoli63499d42011-10-24 18:50:03 +02001114 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001115}
1116
Patrick Benavoli63499d42011-10-24 18:50:03 +02001117CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showPropertiesCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001118{
1119 CElementLocator elementLocator(getSystemClass());
1120
1121 CElement* pLocatedElement = NULL;
1122
1123 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1124
Patrick Benavoli63499d42011-10-24 18:50:03 +02001125 return CCommandHandler::EFailed;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001126 }
1127
1128 // Convert element
1129 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1130
1131 // Return element properties
1132 pConfigurableElement->showProperties(strResult);
1133
Patrick Benavoli63499d42011-10-24 18:50:03 +02001134 return CCommandHandler::ESucceeded;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001135}
1136
Patrick Benavoli63499d42011-10-24 18:50:03 +02001137CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001138{
1139 string strValue;
1140
Patrick Benavoli065264a2011-11-20 15:46:41 +01001141 if (!accessValue(remoteCommand.getArgument(0), strValue, false, strResult)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001142
Patrick Benavoli63499d42011-10-24 18:50:03 +02001143 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001144 }
1145 // Succeeded
1146 strResult = strValue;
1147
Patrick Benavoli63499d42011-10-24 18:50:03 +02001148 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001149}
1150
Patrick Benavoli63499d42011-10-24 18:50:03 +02001151CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001152{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001153 // Check tuning mode
1154 if (!checkTuningModeOn(strResult)) {
1155
1156 return CCommandHandler::EFailed;
1157 }
1158 // Get value to set
1159 string strValue = remoteCommand.packArguments(1, remoteCommand.getArgumentCount() - 1);
1160
1161 return accessValue(remoteCommand.getArgument(0), strValue, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001162}
1163
Patrick Benavoli63499d42011-10-24 18:50:03 +02001164CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listBelongingDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001165{
1166 CElementLocator elementLocator(getSystemClass());
1167
1168 CElement* pLocatedElement = NULL;
1169
1170 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1171
Patrick Benavoli63499d42011-10-24 18:50:03 +02001172 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001173 }
1174
1175 // Convert element
1176 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1177
1178 // Return element belonging domains
1179 pConfigurableElement->listBelongingDomains(strResult);
1180
Patrick Benavoli63499d42011-10-24 18:50:03 +02001181 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001182}
1183
Patrick Benavoli63499d42011-10-24 18:50:03 +02001184CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001185{
1186 CElementLocator elementLocator(getSystemClass());
1187
1188 CElement* pLocatedElement = NULL;
1189
1190 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1191
Patrick Benavoli63499d42011-10-24 18:50:03 +02001192 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001193 }
1194
1195 // Convert element
1196 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1197
1198 // Return element belonging domains
1199 pConfigurableElement->listAssociatedDomains(strResult);
1200
Patrick Benavoli63499d42011-10-24 18:50:03 +02001201 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001202}
1203
Patrick Benavoli63499d42011-10-24 18:50:03 +02001204CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001205{
1206 (void)remoteCommand;
1207
1208 getConfigurableDomains()->listAssociatedElements(strResult);
1209
Patrick Benavoli63499d42011-10-24 18:50:03 +02001210 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001211}
1212
Patrick Benavoli63499d42011-10-24 18:50:03 +02001213CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConflictingElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001214{
1215 (void)remoteCommand;
1216
1217 getConfigurableDomains()->listConflictingElements(strResult);
1218
Patrick Benavoli63499d42011-10-24 18:50:03 +02001219 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001220}
1221
Patrick Benavoli63499d42011-10-24 18:50:03 +02001222CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listRogueElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001223{
1224 (void)remoteCommand;
1225
1226 getSystemClass()->listRogueElements(strResult);
1227
Patrick Benavoli63499d42011-10-24 18:50:03 +02001228 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001229}
1230
1231/// Settings Import/Export
Patrick Benavoli63499d42011-10-24 18:50:03 +02001232CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001233{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001234 return exportDomainsXml(remoteCommand.getArgument(0), false, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001235}
1236
Patrick Benavoli63499d42011-10-24 18:50:03 +02001237CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001238{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001239 return importDomainsXml(remoteCommand.getArgument(0), false, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001240}
1241
Patrick Benavoli63499d42011-10-24 18:50:03 +02001242CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001243{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001244 return exportDomainsXml(remoteCommand.getArgument(0), true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001245}
1246
Patrick Benavoli63499d42011-10-24 18:50:03 +02001247CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001248{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001249 return importDomainsXml(remoteCommand.getArgument(0), true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001250}
1251
Patrick Benavoli63499d42011-10-24 18:50:03 +02001252CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001253{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001254 return exportDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001255}
1256
Patrick Benavoli63499d42011-10-24 18:50:03 +02001257CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001258{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001259 return importDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001260}
1261
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001262/// GUI commands
1263
1264CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getDomainsXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1265{
1266 (void)remoteCommand;
1267
1268 if (!getDomainsXMLString(strResult, true)) {
1269
1270 return CCommandHandler::EFailed;
1271 }
1272 // Succeeded
1273 return CCommandHandler::ESucceeded;
1274}
1275
1276CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getSystemClassXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1277{
1278 (void)remoteCommand;
1279
1280 if (!getSystemClassXMLString(strResult)) {
1281
1282 return CCommandHandler::EFailed;
1283 }
1284 // Succeeded
1285 return CCommandHandler::ESucceeded;
1286}
1287
Patrick Benavoli68a91282011-08-31 11:23:23 +02001288// User set/get parameters
Patrick Benavoli065264a2011-11-20 15:46:41 +01001289bool CParameterMgr::accessValue(const string& strPath, string& strValue, bool bSet, string& strError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001290{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001291 // Lock state
1292 CAutoLock autoLock(&_blackboardMutex);
1293
1294 CPathNavigator pathNavigator(strPath);
1295
1296 // Nagivate through system class
1297 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001298
1299 return false;
1300 }
1301
Patrick Benavoli065264a2011-11-20 15:46:41 +01001302 // Define context
1303 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001304
Patrick Benavoli68808c62012-02-02 17:12:41 +01001305 // Auto Sync
1306 if (bSet) {
1307
1308 parameterAccessContext.setAutoSync(_bAutoSyncOn);
1309 }
1310
Patrick Benavoli065264a2011-11-20 15:46:41 +01001311 // Do the get
1312 return getConstSystemClass()->accessValue(pathNavigator, strValue, bSet, parameterAccessContext);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001313}
1314
1315// Tuning mode
1316bool CParameterMgr::setTuningMode(bool bOn, string& strError)
1317{
1318 // Tuning allowed?
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001319 if (bOn && !getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001320
1321 strError = "Tuning prohibited";
1322
1323 return false;
1324 }
1325 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +01001326 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001327
1328 // Warn domains about exiting tuning mode
1329 if (!bOn && _bTuningModeIsOn) {
1330
1331 // Ensure application of currently selected configurations
Patrick Benavoli1387bda2011-08-31 11:23:24 +02001332 // Force-apply configurations
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01001333 doApplyConfigurations(true);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001334
Patrick Benavoli68a91282011-08-31 11:23:23 +02001335 // 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);
Kevin Rocardace81f82012-12-11 16:19:17 +01001422
Patrick Benavoli68a91282011-08-31 11:23:23 +02001423 // Sync
Kevin Rocardace81f82012-12-11 16:19:17 +01001424 list<string> lstrError;
1425 if (! syncerSet.sync(*_pMainParameterBlackboard, false, &lstrError)){
1426
1427 CUtility::concatenate(lstrError, strError);
1428 return false;
1429 };
1430
1431 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001432}
1433
1434// Content dump
1435void CParameterMgr::logStructureContent(string& strContent) const
1436{
1437 string strError;
1438
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001439 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001440
1441 dumpContent(strContent, parameterAccessContext);
1442}
1443
1444// Configuration/Domains handling
1445bool CParameterMgr::createDomain(const string& strName, string& strError)
1446{
1447 // Check tuning mode
1448 if (!checkTuningModeOn(strError)) {
1449
1450 return false;
1451 }
1452
1453 // Delegate to configurable domains
1454 return getConfigurableDomains()->createDomain(strName, strError);
1455}
1456
1457bool CParameterMgr::deleteDomain(const string& strName, string& strError)
1458{
1459 // Check tuning mode
1460 if (!checkTuningModeOn(strError)) {
1461
1462 return false;
1463 }
1464
1465 // Delegate to configurable domains
1466 return getConfigurableDomains()->deleteDomain(strName, strError);
1467}
1468
Kevin Rocard170f0a42012-06-18 13:56:05 +02001469bool CParameterMgr::deleteAllDomains(string& strError)
1470{
1471 // Check tuning mode
1472 if (!checkTuningModeOn(strError)) {
1473
1474 return false;
1475 }
1476
1477 // Delegate to configurable domains
1478 getConfigurableDomains()->deleteAllDomains();
1479
1480 return true;
1481}
1482
Patrick Benavoli68a91282011-08-31 11:23:23 +02001483bool CParameterMgr::createConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1484{
1485 // Check tuning mode
1486 if (!checkTuningModeOn(strError)) {
1487
1488 return false;
1489 }
1490
1491 // Delegate to configurable domains
1492 return getConfigurableDomains()->createConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1493}
1494
1495bool CParameterMgr::deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1496{
1497 // Check tuning mode
1498 if (!checkTuningModeOn(strError)) {
1499
1500 return false;
1501 }
1502
1503 // Delegate to configurable domains
1504 return getConfigurableDomains()->deleteConfiguration(strDomain, strConfiguration, strError);
1505}
1506
Kevin Rocardace81f82012-12-11 16:19:17 +01001507bool CParameterMgr::restoreConfiguration(const string& strDomain, const string& strConfiguration, list<string>& lstrError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001508{
Kevin Rocardace81f82012-12-11 16:19:17 +01001509 string strError;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001510 // Check tuning mode
1511 if (!checkTuningModeOn(strError)) {
1512
Kevin Rocardace81f82012-12-11 16:19:17 +01001513 lstrError.push_back(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001514 return false;
1515 }
1516
1517 // Delegate to configurable domains
Kevin Rocardace81f82012-12-11 16:19:17 +01001518 return getConstConfigurableDomains()->restoreConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, lstrError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001519}
1520
1521bool CParameterMgr::saveConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1522{
1523 // Check tuning mode
1524 if (!checkTuningModeOn(strError)) {
1525
1526 return false;
1527 }
1528
1529 // Delegate to configurable domains
1530 return getConfigurableDomains()->saveConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1531}
1532
1533// Configurable element - domain association
1534bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1535{
1536 // Check tuning mode
1537 if (!checkTuningModeOn(strError)) {
1538
1539 return false;
1540 }
1541
1542 CElementLocator elementLocator(getSystemClass());
1543
1544 CElement* pLocatedElement = NULL;
1545
1546 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1547
1548 return false;
1549 }
1550
1551 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001552 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001553
1554 // Delegate
1555 return getConfigurableDomains()->addConfigurableElementToDomain(strDomain, pConfigurableElement, _pMainParameterBlackboard, strError);
1556}
1557
1558bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1559{
1560 // Check tuning mode
1561 if (!checkTuningModeOn(strError)) {
1562
1563 return false;
1564 }
1565
1566 CElementLocator elementLocator(getSystemClass());
1567
1568 CElement* pLocatedElement = NULL;
1569
1570 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1571
Patrick Benavoli63499d42011-10-24 18:50:03 +02001572 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001573 }
1574
1575 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001576 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001577
1578 // Delegate
1579 return getConfigurableDomains()->removeConfigurableElementFromDomain(strDomain, pConfigurableElement, strError);
1580}
1581
1582bool CParameterMgr::split(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1583{
1584 // Check tuning mode
1585 if (!checkTuningModeOn(strError)) {
1586
1587 return false;
1588 }
1589
1590 CElementLocator elementLocator(getSystemClass());
1591
1592 CElement* pLocatedElement = NULL;
1593
1594 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1595
Patrick Benavoli63499d42011-10-24 18:50:03 +02001596 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001597 }
1598
1599 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001600 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001601
1602 // Delegate
1603 return getConfigurableDomains()->split(strDomain, pConfigurableElement, strError);
1604}
1605
1606// XML Import/Export
1607bool CParameterMgr::importDomainsXml(const string& strFileName, bool bWithSettings, string& strError)
1608{
1609 // Check tuning mode
1610 if (!checkTuningModeOn(strError)) {
1611
1612 return false;
1613 }
1614
1615 // check path is absolute
1616 if (strFileName[0] != '/') {
1617
1618 strError = "Please provide absolute path";
1619
1620 return false;
1621 }
1622 // Root element
1623 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1624
1625 // Context
1626 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1627
1628 // Secltion criteria definition for rule creation
1629 xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
1630
1631 // Parse
1632 if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strFileName, "", EParameterConfigurationLibrary, "SystemClassName")) {
1633
1634 return false;
1635 }
1636
1637 // Validate domains after XML import
1638 pConfigurableDomains->validate(_pMainParameterBlackboard);
1639
1640 return true;
1641}
1642
1643bool CParameterMgr::exportDomainsXml(const string& strFileName, bool bWithSettings, string& strError) const
1644{
1645 // check path is absolute
1646 if (strFileName[0] != '/') {
1647
1648 strError = "Please provide absolute path";
1649
1650 return false;
1651 }
1652
1653 // Root element
1654 const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains();
1655
1656 // Get Schema file associated to root element
1657 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pConfigurableDomains->getKind() + ".xsd";
1658
1659 // Context
1660 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1661
1662 // Value space
1663 xmlDomainSerializingContext.setValueSpaceRaw(_bValueSpaceIsRaw);
1664
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001665 // Output raw format
1666 xmlDomainSerializingContext.setOutputRawFormat(_bOutputRawFormatIsHex);
1667
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001668 // Use a doc source by loading data from instantiated Configurable Domains
1669 CXmlMemoryDocSource memorySource(pConfigurableDomains, pConfigurableDomains->getKind(), strXmlSchemaFilePath, "parameter-framework", getVersion());
Patrick Benavoli68a91282011-08-31 11:23:23 +02001670
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001671 // Use a doc sink to write the doc data in a file
1672 CXmlFileDocSink fileSink(strFileName);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001673
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001674 if (!fileSink.process(memorySource, xmlDomainSerializingContext)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001675 return false;
1676 }
1677
1678 return true;
1679}
1680
1681// Binary Import/Export
1682bool CParameterMgr::importDomainsBinary(const string& strFileName, string& strError)
1683{
1684 // Check tuning mode
1685 if (!checkTuningModeOn(strError)) {
1686
1687 return false;
1688 }
1689 // check path is absolute
1690 if (strFileName[0] != '/') {
1691
1692 strError = "Please provide absolute path";
1693
1694 return false;
1695 }
1696 // Root element
1697 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1698
1699 // Serialize in
1700 return pConfigurableDomains->serializeSettings(strFileName, false, _uiStructureChecksum, strError);
1701}
1702
1703bool CParameterMgr::exportDomainsBinary(const string& strFileName, string& strError)
1704{
1705 // check path is absolute
1706 if (strFileName[0] != '/') {
1707
1708 strError = "Please provide absolute path";
1709
1710 return false;
1711 }
Patrick Benavoli68a91282011-08-31 11:23:23 +02001712
Patrick Benavoli68a91282011-08-31 11:23:23 +02001713 // Root element
1714 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1715
1716 // Serialize out
1717 return pConfigurableDomains->serializeSettings(strFileName, true, _uiStructureChecksum, strError);
1718}
1719
1720// For tuning, check we're in tuning mode
1721bool CParameterMgr::checkTuningModeOn(string& strError) const
1722{
1723 // Tuning Mode on?
1724 if (!_bTuningModeIsOn) {
1725
1726 strError = "Tuning Mode must be on";
1727
1728 return false;
1729 }
1730 return true;
1731}
1732
Patrick Benavoli065264a2011-11-20 15:46:41 +01001733// Tuning mutex dynamic parameter handling
1734pthread_mutex_t* CParameterMgr::getBlackboardMutex()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001735{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001736 return &_blackboardMutex;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001737}
1738
Patrick Benavoli065264a2011-11-20 15:46:41 +01001739// Blackboard reference (dynamic parameter handling)
1740CParameterBlackboard* CParameterMgr::getParameterBlackboard()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001741{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001742 return _pMainParameterBlackboard;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001743}
1744
Patrick Benavoli68a91282011-08-31 11:23:23 +02001745// Dynamic creation library feeding
1746void CParameterMgr::feedElementLibraries()
1747{
1748 // Global Configuration handling
1749 CElementLibrary* pFrameworkConfigurationLibrary = new CElementLibrary;
1750
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001751 pFrameworkConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CParameterFrameworkConfiguration>("ParameterFrameworkConfiguration"));
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +01001752 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CSubsystemPlugins>("SubsystemPlugins"));
1753 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CPluginLocation>("Location"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001754 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("StructureDescriptionFileLocation"));
1755 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationGroup>("SettingsConfiguration"));
1756 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("ConfigurableDomainsFileLocation"));
1757 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("BinarySettingsFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001758
1759 _pElementLibrarySet->addElementLibrary(pFrameworkConfigurationLibrary);
1760
1761 // Parameter creation
1762 CElementLibrary* pParameterCreationLibrary = new CElementLibrary;
1763
1764 pParameterCreationLibrary->addElementBuilder(new CSubsystemElementBuilder(getSystemClass()->getSubsystemLibrary()));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001765 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CComponentType>("ComponentType"));
1766 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CComponentInstance>("Component"));
1767 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBitParameterType>("BitParameter"));
1768 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBitParameterBlockType>("BitParameterBlock"));
Patrick Benavoli1352ae52011-10-21 16:48:04 +02001769 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CStringParameterType>("StringParameter"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001770 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CParameterBlockType>("ParameterBlock"));
1771 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBooleanParameterType>("BooleanParameter"));
1772 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CIntegerParameterType>("IntegerParameter"));
Patrick Benavoliee65e6d2011-11-20 18:52:24 +01001773 pParameterCreationLibrary->addElementBuilder(new TElementBuilderTemplate<CLinearParameterAdaptation>("LinearAdaptation"));
Patrick Benavoli9fc3c0d2011-10-27 14:27:27 +02001774 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CEnumParameterType>("EnumParameter"));
Patrick Benavoli68808c62012-02-02 17:12:41 +01001775 pParameterCreationLibrary->addElementBuilder(new TElementBuilderTemplate<CEnumValuePair>("ValuePair"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001776 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CFixedPointParameterType>("FixedPointParameter"));
1777 pParameterCreationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CXmlFileIncluderElement>("SubsystemInclude"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001778
1779 _pElementLibrarySet->addElementLibrary(pParameterCreationLibrary);
1780
1781 // Parameter Configuration Domains creation
1782 CElementLibrary* pParameterConfigurationLibrary = new CElementLibrary;
1783
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001784 pParameterConfigurationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CConfigurableDomain>("ConfigurableDomain"));
1785 pParameterConfigurationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CDomainConfiguration>("Configuration"));
1786 pParameterConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CCompoundRule>("CompoundRule"));
1787 pParameterConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CSelectionCriterionRule>("SelectionCriterionRule"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001788
1789 _pElementLibrarySet->addElementLibrary(pParameterConfigurationLibrary);
1790}
1791
1792// Remote Processor Server connection handling
1793bool CParameterMgr::handleRemoteProcessingInterface(string& strError)
1794{
1795 CAutoLog autoLog(this, "Handling remote processing interface");
1796
1797 // Start server if tuning allowed
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001798 if (getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001799
Kevin Rocardace81f82012-12-11 16:19:17 +01001800 log_info("Loading remote processor library");
Patrick Benavoli68a91282011-08-31 11:23:23 +02001801
1802 // Load library
1803 void* lib_handle = dlopen("libremote-processor.so", RTLD_NOW);
1804
1805 if (!lib_handle) {
1806
1807 // Return error
1808 const char* pcError = dlerror();
1809
1810 if (pcError) {
1811
1812 strError = pcError;
1813 } else {
1814
1815 strError = "Unable to load libremote-processor.so library";
1816 }
1817
1818 return false;
1819 }
1820
1821 CreateRemoteProcessorServer pfnCreateRemoteProcessorServer = (CreateRemoteProcessorServer)dlsym(lib_handle, "createRemoteProcessorServer");
1822
1823 if (!pfnCreateRemoteProcessorServer) {
1824
1825 strError = "libremote-process.so does not contain createRemoteProcessorServer symbol.";
1826
1827 return false;
1828 }
1829
1830 // Create server
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001831 _pRemoteProcessorServer = pfnCreateRemoteProcessorServer(getConstFrameworkConfiguration()->getServerPort(), _pCommandHandler);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001832
Kevin Rocardace81f82012-12-11 16:19:17 +01001833 log_info("Starting remote processor server on port %d", getConstFrameworkConfiguration()->getServerPort());
Patrick Benavoli68a91282011-08-31 11:23:23 +02001834 // Start
1835 if (!_pRemoteProcessorServer->start()) {
1836
1837 strError = "Unable to start remote processor server";
1838
1839 return false;
1840 }
1841 }
1842
1843 return true;
1844}
1845
1846// Back synchronization
Kevin Rocardace81f82012-12-11 16:19:17 +01001847CBackSynchronizer* CParameterMgr::createBackSynchronizer() const
Patrick Benavoli68a91282011-08-31 11:23:23 +02001848{
1849#ifdef SIMULATION
1850 // In simulation, back synchronization of the blackboard won't probably work
1851 // We need to ensure though the blackboard is initialized with valid data
Kevin Rocardace81f82012-12-11 16:19:17 +01001852 return new CSimulatedBackSynchronizer(getConstSystemClass(), _pMainParameterBlackboard);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001853#else
1854 // Real back synchronizer from subsystems
Kevin Rocardace81f82012-12-11 16:19:17 +01001855 return new CHardwareBackSynchronizer(getConstSystemClass(), _pMainParameterBlackboard);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001856#endif
1857}
1858
1859// Children typwise access
1860CParameterFrameworkConfiguration* CParameterMgr::getFrameworkConfiguration()
1861{
1862 return static_cast<CParameterFrameworkConfiguration*>(getChild(EFrameworkConfiguration));
1863}
1864
1865const CParameterFrameworkConfiguration* CParameterMgr::getConstFrameworkConfiguration()
1866{
1867 return getFrameworkConfiguration();
1868}
1869
1870CSelectionCriteria* CParameterMgr::getSelectionCriteria()
1871{
1872 return static_cast<CSelectionCriteria*>(getChild(ESelectionCriteria));
1873}
1874
1875const CSelectionCriteria* CParameterMgr::getConstSelectionCriteria()
1876{
1877 return static_cast<const CSelectionCriteria*>(getChild(ESelectionCriteria));
1878}
1879
1880CSystemClass* CParameterMgr::getSystemClass()
1881{
1882 return static_cast<CSystemClass*>(getChild(ESystemClass));
1883}
1884
1885const CSystemClass* CParameterMgr::getConstSystemClass() const
1886{
1887 return static_cast<const CSystemClass*>(getChild(ESystemClass));
1888}
1889
1890// Configurable Domains
1891CConfigurableDomains* CParameterMgr::getConfigurableDomains()
1892{
1893 return static_cast<CConfigurableDomains*>(getChild(EConfigurableDomains));
1894}
1895
1896const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains()
1897{
1898 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
1899}
1900
1901const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains() const
1902{
1903 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
1904}
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001905
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01001906// Apply configurations
1907void CParameterMgr::doApplyConfigurations(bool bForce)
1908{
1909 CSyncerSet syncerSet;
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001910
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01001911 // Check subsystems that need resync
1912 getSystemClass()->checkForSubsystemsToResync(syncerSet);
1913
1914 // Ensure application of currently selected configurations
1915 getConfigurableDomains()->apply(_pMainParameterBlackboard, syncerSet, bForce);
1916
1917 // Reset the modified status of the current criteria to indicate that a new configuration has been applied
1918 getSelectionCriteria()->resetModifiedStatus();
1919}
1920
1921/// GUI commands functions
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001922bool CParameterMgr::getDomainsXMLString(string& strResult, bool bWithSettings)
1923{
1924
1925 // Root element
1926 const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains();
1927
1928 // Get Schema file associated to root element
1929 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pConfigurableDomains->getKind() + ".xsd";
1930
1931 string strError;
1932
1933 // Context
1934 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1935
1936 // Value space
1937 xmlDomainSerializingContext.setValueSpaceRaw(_bValueSpaceIsRaw);
1938
1939 // Output raw format
1940 xmlDomainSerializingContext.setOutputRawFormat(_bOutputRawFormatIsHex);
1941
1942 // Use a doc source by loading data from instantiated Configurable Domains
1943 CXmlMemoryDocSource memorySource(pConfigurableDomains, pConfigurableDomains->getKind(), strXmlSchemaFilePath, "parameter-framework", getVersion());
1944
1945 // Use a doc sink the write the doc data in a string
1946 CXmlStringDocSink stringSink(strResult);
1947
1948 if (!stringSink.process(memorySource, xmlDomainSerializingContext)) {
1949 strResult = strError;
1950
1951 return false;
1952 }
1953
1954 return true;
1955}
1956
1957bool CParameterMgr::getSystemClassXMLString(string& strResult)
1958{
1959 // Root element
1960 const CSystemClass* pSystemClass = getSystemClass();
1961
1962 string strError;
1963
1964 CXmlSerializingContext xmlSerializingContext(strError);
1965
1966 // Use a doc source by loading data from instantiated Configurable Domains
1967 CXmlMemoryDocSource memorySource(pSystemClass, pSystemClass->getKind());
1968
1969 // Use a doc sink that write the doc data in a string
1970 CXmlStringDocSink stringSink(strResult);
1971
1972 if (!stringSink.process(memorySource, xmlSerializingContext)) {
1973 strResult = strError;
1974 return false;
1975 }
1976
1977 return true;
1978}