blob: 52441999c0a97e98ac5edab5c5a301f1534613ea [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
358 // Ensure application of currently selected configurations
359 // Force-apply configurations
Kevin Rocardace81f82012-12-11 16:19:17 +0100360 pConfigurableDomains->apply(_pMainParameterBlackboard, true);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200361
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200362 // Start remote processor server if appropriate
363 return handleRemoteProcessingInterface(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200364}
365
366bool CParameterMgr::loadFrameworkConfiguration(string& strError)
367{
368 CAutoLog autoLog(this, "Loading framework configuration");
369
Patrick Benavoli68a91282011-08-31 11:23:23 +0200370 // Parse Structure XML file
371 CXmlElementSerializingContext elementSerializingContext(strError);
372
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100373 if (!xmlParse(elementSerializingContext, getFrameworkConfiguration(), _strXmlConfigurationFilePath, _strXmlConfigurationFolderPath, EFrameworkConfigurationLibrary)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200374
375 return false;
376 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100377 // Set class name to system class and configurable domains
378 getSystemClass()->setName(getConstFrameworkConfiguration()->getSystemClassName());
379 getConfigurableDomains()->setName(getConstFrameworkConfiguration()->getSystemClassName());
380
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100381 // Get subsystem plugins elements
382 _pSubsystemPlugins = static_cast<const CSubsystemPlugins*>(getConstFrameworkConfiguration()->findChild("SubsystemPlugins"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200383
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100384 if (!_pSubsystemPlugins) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200385
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100386 strError = "Parameter Framework Configuration: couldn't find SubsystemPlugins element";
Patrick Benavoli68a91282011-08-31 11:23:23 +0200387
388 return false;
389 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200390
Patrick Benavoli68a91282011-08-31 11:23:23 +0200391 // Log tuning availability
Kevin Rocardace81f82012-12-11 16:19:17 +0100392 log_info("Tuning %s", getConstFrameworkConfiguration()->isTuningAllowed() ? "allowed" : "prohibited");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200393
394 return true;
395}
396
397bool CParameterMgr::loadStructure(string& strError)
398{
399 // Retrieve system to load structure to
400 CSystemClass* pSystemClass = getSystemClass();
401
402 CAutoLog autoLog(this, "Loading " + pSystemClass->getName() + " system class structure");
403
404 // Get structure description element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100405 const CFrameworkConfigurationLocation* pStructureDescriptionFileLocation = static_cast<const CFrameworkConfigurationLocation*>(getConstFrameworkConfiguration()->findChildOfKind("StructureDescriptionFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200406
407 if (!pStructureDescriptionFileLocation) {
408
409 strError = "No StructureDescriptionFileLocation element found for SystemClass " + pSystemClass->getName();
410
411 return false;
412 }
413
414 // Get Xml structure folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100415 string strXmlStructureFolder = pStructureDescriptionFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200416
417 // Get Xml structure file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100418 string strXmlStructureFilePath = pStructureDescriptionFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200419
420 // Parse Structure XML file
421 CXmlParameterSerializingContext parameterBuildContext(strError);
422
Kevin Rocard57096bd2012-11-30 11:24:20 +0100423 CAutoLog autolog(pSystemClass, "Importing system structure from file " + strXmlStructureFilePath);
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200424
Patrick Benavoli68a91282011-08-31 11:23:23 +0200425 if (!xmlParse(parameterBuildContext, pSystemClass, strXmlStructureFilePath, strXmlStructureFolder, EParameterCreationLibrary)) {
426
427 return false;
428 }
429
430 // Initialize offsets
431 pSystemClass->setOffset(0);
432
433 // Initialize main blackboard's size
434 _pMainParameterBlackboard->setSize(pSystemClass->getFootPrint());
435
436 return true;
437}
438
439bool CParameterMgr::loadSettings(string& strError)
440{
441 CAutoLog autoLog(this, "Loading settings");
442
443 // Get settings configuration element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100444 const CFrameworkConfigurationGroup* pParameterConfigurationGroup = static_cast<const CFrameworkConfigurationGroup*>(getConstFrameworkConfiguration()->findChildOfKind("SettingsConfiguration"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200445
446 if (!pParameterConfigurationGroup) {
447
448 // No settings to load
449
450 return true;
451 }
452 // Get binary settings file location
453 const CFrameworkConfigurationLocation* pBinarySettingsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("BinarySettingsFileLocation"));
454
455 string strXmlBinarySettingsFilePath;
456
457 if (pBinarySettingsFileLocation) {
458
459 // Get Xml binary settings file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100460 strXmlBinarySettingsFilePath = pBinarySettingsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200461 }
462
463 // Get configurable domains element
464 const CFrameworkConfigurationLocation* pConfigurableDomainsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("ConfigurableDomainsFileLocation"));
465
466 if (!pConfigurableDomainsFileLocation) {
467
468 strError = "No ConfigurableDomainsFileLocation element found for SystemClass " + getSystemClass()->getName();
469
470 return false;
471 }
472 // Get destination root element
473 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
474
475 // Get Xml configuration domains file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100476 string strXmlConfigurationDomainsFilePath = pConfigurableDomainsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200477
478 // Get Xml configuration domains folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100479 string strXmlConfigurationDomainsFolder = pConfigurableDomainsFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200480
481 // Parse configuration domains XML file (ask to read settings from XML file if they are not provided as binary)
482 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, !pBinarySettingsFileLocation);
483
484 // Selection criteria definition for rule creation
485 xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
486
Patrick Benavoli63499d42011-10-24 18:50:03 +0200487 // Auto validation of configurations if no binary settings provided
488 xmlDomainSerializingContext.setAutoValidationRequired(!pBinarySettingsFileLocation);
489
Kevin Rocardace81f82012-12-11 16:19:17 +0100490 log_info("Importing configurable domains from file %s %s settings", strXmlConfigurationDomainsFilePath.c_str(), pBinarySettingsFileLocation ? "without" : "with");
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200491
Patrick Benavoli68a91282011-08-31 11:23:23 +0200492 // Do parse
493 if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strXmlConfigurationDomainsFilePath, strXmlConfigurationDomainsFolder, EParameterConfigurationLibrary, "SystemClassName")) {
494
495 return false;
496 }
497 // We have loaded the whole system structure, compute checksum
498 const CSystemClass* pSystemClass = getConstSystemClass();
499 _uiStructureChecksum = pSystemClass->computeStructureChecksum() + getConfigurableDomains()->computeStructureChecksum() + getSelectionCriteria()->computeStructureChecksum();
500
501 // Load binary settings if any provided
502 if (pBinarySettingsFileLocation && !pConfigurableDomains->serializeSettings(strXmlBinarySettingsFilePath, false, _uiStructureChecksum, strError)) {
503
504 return false;
505 }
506
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200507 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200508}
509
510// XML parsing
511bool CParameterMgr::xmlParse(CXmlElementSerializingContext& elementSerializingContext, CElement* pRootElement, const string& strXmlFilePath, const string& strXmlFolder, CParameterMgr::ElementLibrary eElementLibrary, const string& strNameAttrituteName)
512{
513 // Init serializing context
514 elementSerializingContext.set(_pElementLibrarySet->getElementLibrary(eElementLibrary), strXmlFolder, _strSchemaFolderLocation);
515
516 // Get Schema file associated to root element
517 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pRootElement->getKind() + ".xsd";
518
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200519 CXmlFileDocSource fileDocSource(strXmlFilePath, strXmlSchemaFilePath, pRootElement->getKind(), pRootElement->getName(), strNameAttrituteName);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200520
521 // Start clean
522 pRootElement->clean();
523
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200524 CXmlMemoryDocSink memorySink(pRootElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200525
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200526 if (!memorySink.process(fileDocSource, elementSerializingContext)) {
527 //Cleanup
Patrick Benavoli68a91282011-08-31 11:23:23 +0200528 pRootElement->clean();
529
530 return false;
531 }
532
Patrick Benavoli68a91282011-08-31 11:23:23 +0200533 return true;
534}
535
536// Init
537bool CParameterMgr::init(string& strError)
538{
539 return base::init(strError);
540}
541
542// Selection criteria interface
543CSelectionCriterionType* CParameterMgr::createSelectionCriterionType(bool bIsInclusive)
544{
545 // Propagate
546 return getSelectionCriteria()->createSelectionCriterionType(bIsInclusive);
547}
548
549CSelectionCriterion* CParameterMgr::createSelectionCriterion(const string& strName, const CSelectionCriterionType* pSelectionCriterionType)
550{
551 // Propagate
552 return getSelectionCriteria()->createSelectionCriterion(strName, pSelectionCriterionType);
553}
554
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200555// Selection criterion retrieval
556CSelectionCriterion* CParameterMgr::getSelectionCriterion(const string& strName)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200557{
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200558 // Propagate
559 return getSelectionCriteria()->getSelectionCriterion(strName);
560}
561
562// Selection criteria changed event
Kevin Rocardace81f82012-12-11 16:19:17 +0100563void CParameterMgr::applyConfigurations()
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200564{
565 CAutoLog autoLog(this, "Configuration application request");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200566
567 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +0100568 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200569
570 if (!_bTuningModeIsOn) {
571
572 // Apply configuration(s)
Kevin Rocardace81f82012-12-11 16:19:17 +0100573 getConfigurableDomains()->apply(_pMainParameterBlackboard, false);
Frédéric Boisnarddaaa63c2012-08-27 15:48:15 +0200574
575 // Reset the modified status of the current criteria to indicate that a new configuration has been applied
576 getSelectionCriteria()->resetModifiedStatus();
577
578 } else {
579
Kevin Rocardace81f82012-12-11 16:19:17 +0100580 log_warning("Configurations were not applied because the TuningMode is on");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200581 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200582}
583
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200584// Dynamic parameter handling
Patrick Benavoli065264a2011-11-20 15:46:41 +0100585CParameterHandle* CParameterMgr::createParameterHandle(const string& strPath, string& strError)
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200586{
Patrick Benavoli065264a2011-11-20 15:46:41 +0100587 CPathNavigator pathNavigator(strPath);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200588
Patrick Benavoli065264a2011-11-20 15:46:41 +0100589 // Nagivate through system class
590 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
591
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100592 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100593 }
594
595 // Find element
596 const CElement* pElement = getConstSystemClass()->findDescendant(pathNavigator);
597
598 if (!pElement) {
599
600 strError = "Path not found";
601
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100602 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100603 }
604
605 // Check found element is a parameter
606 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pElement);
607
608 if (!pConfigurableElement->isParameter()) {
609
610 // Element is not parameter
611 strError = "Not a parameter";
612
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100613 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100614 }
615
616 // Convert as parameter and return new handle
617 return new CParameterHandle(static_cast<const CBaseParameter*>(pElement), this);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200618}
619
Patrick Benavoli68a91282011-08-31 11:23:23 +0200620/////////////////// Remote command parsers
Patrick Benavoli592ae562011-09-05 16:53:58 +0200621/// Version
Patrick Benavoli63499d42011-10-24 18:50:03 +0200622CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::versionCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli592ae562011-09-05 16:53:58 +0200623{
624 (void)remoteCommand;
625
Patrick Benavoli63499d42011-10-24 18:50:03 +0200626 // Show version
627 strResult = getVersion();
Patrick Benavoli592ae562011-09-05 16:53:58 +0200628
Patrick Benavoli63499d42011-10-24 18:50:03 +0200629 return CCommandHandler::ESucceeded;
Patrick Benavoli592ae562011-09-05 16:53:58 +0200630}
631
Patrick Benavoli68a91282011-08-31 11:23:23 +0200632/// Status
Patrick Benavoli63499d42011-10-24 18:50:03 +0200633CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::statusCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200634{
635 (void)remoteCommand;
636 // System class
637 const CSystemClass* pSystemClass = getSystemClass();
638
Patrick Benavoli68a91282011-08-31 11:23:23 +0200639 // Show status
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200640 /// General section
641 appendTitle(strResult, "General:");
642 // System class
Patrick Benavoli68a91282011-08-31 11:23:23 +0200643 strResult += "System Class: ";
644 strResult += pSystemClass->getName();
645 strResult += "\n";
646
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200647 // Tuning mode
Patrick Benavoli68a91282011-08-31 11:23:23 +0200648 strResult += "Tuning Mode: ";
649 strResult += tuningModeOn() ? "on" : "off";
650 strResult += "\n";
651
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200652 // Value space
Patrick Benavoli68a91282011-08-31 11:23:23 +0200653 strResult += "Value Space: ";
654 strResult += valueSpaceIsRaw() ? "raw" : "real";
655 strResult += "\n";
656
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200657 // Output raw format
658 strResult += "Output Raw Format: ";
659 strResult += outputRawFormatIsHex() ? "hex" : "dec";
660 strResult += "\n";
661
662 // Auto Sync
Patrick Benavoli68a91282011-08-31 11:23:23 +0200663 strResult += "Auto Sync: ";
664 strResult += autoSyncOn() ? "on" : "off";
665 strResult += "\n";
666
667 /// Subsystem list
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200668 appendTitle(strResult, "Subsystems:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200669 string strSubsystemList;
670 pSystemClass->listChildrenPaths(strSubsystemList);
671 strResult += strSubsystemList;
672
673 /// Last applied configurations
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200674 appendTitle(strResult, "Last Applied [Pending] Configurations:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200675 string strLastAppliedConfigurations;
676 getConfigurableDomains()->listLastAppliedConfigurations(strLastAppliedConfigurations);
677 strResult += strLastAppliedConfigurations;
678
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200679 /// Criteria states
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200680 appendTitle(strResult, "Selection Criteria:");
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200681 string strSelectionCriteria;
682 getSelectionCriteria()->listSelectionCriteria(strSelectionCriteria, false);
683 strResult += strSelectionCriteria;
684
Patrick Benavoli63499d42011-10-24 18:50:03 +0200685 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200686}
687
688/// Tuning Mode
Patrick Benavoli63499d42011-10-24 18:50:03 +0200689CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200690{
691 if (remoteCommand.getArgument(0) == "on") {
692
693 if (setTuningMode(true, strResult)) {
694
Patrick Benavoli63499d42011-10-24 18:50:03 +0200695 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200696 }
697 } else if (remoteCommand.getArgument(0) == "off") {
698
699 if (setTuningMode(false, strResult)) {
700
Patrick Benavoli63499d42011-10-24 18:50:03 +0200701 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200702 }
703 } else {
704 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200705 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200706 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200707 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200708}
709
Patrick Benavoli63499d42011-10-24 18:50:03 +0200710CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200711{
712 (void)remoteCommand;
713
714 strResult = tuningModeOn() ? "on" : "off";
715
Patrick Benavoli63499d42011-10-24 18:50:03 +0200716 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200717}
718
719/// Value Space
Patrick Benavoli63499d42011-10-24 18:50:03 +0200720CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200721{
722 (void)strResult;
723
724 if (remoteCommand.getArgument(0) == "raw") {
725
726 setValueSpace(true);
727
Patrick Benavoli63499d42011-10-24 18:50:03 +0200728 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200729
730 } else if (remoteCommand.getArgument(0) == "real") {
731
732 setValueSpace(false);
733
Patrick Benavoli63499d42011-10-24 18:50:03 +0200734 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200735
736 } else {
737 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200738 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200739 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200740 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200741}
742
Patrick Benavoli63499d42011-10-24 18:50:03 +0200743CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200744{
745 (void)remoteCommand;
746
747 strResult = valueSpaceIsRaw() ? "raw" : "real";
748
Patrick Benavoli63499d42011-10-24 18:50:03 +0200749 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200750}
751
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200752/// Output Raw Format
Patrick Benavoli63499d42011-10-24 18:50:03 +0200753CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200754{
755 (void)strResult;
756
757 if (remoteCommand.getArgument(0) == "hex") {
758
759 setOutputRawFormat(true);
760
Patrick Benavoli63499d42011-10-24 18:50:03 +0200761 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200762
763 } else if (remoteCommand.getArgument(0) == "dec") {
764
765 setOutputRawFormat(false);
766
Patrick Benavoli63499d42011-10-24 18:50:03 +0200767 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200768
769 } else {
770 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200771 return CCommandHandler::EShowUsage;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200772 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200773 return CCommandHandler::EFailed;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200774}
775
Patrick Benavoli63499d42011-10-24 18:50:03 +0200776CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200777{
778 (void)remoteCommand;
779
780 strResult = outputRawFormatIsHex() ? "hex" : "dec";
781
Patrick Benavoli63499d42011-10-24 18:50:03 +0200782 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200783}
784
Patrick Benavoli68a91282011-08-31 11:23:23 +0200785/// Sync
Patrick Benavoli63499d42011-10-24 18:50:03 +0200786CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200787{
788 if (remoteCommand.getArgument(0) == "on") {
789
790 if (setAutoSync(true, strResult)) {
791
Patrick Benavoli63499d42011-10-24 18:50:03 +0200792 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200793 }
794 } else if (remoteCommand.getArgument(0) == "off") {
795
796 if (setAutoSync(false, strResult)) {
797
Patrick Benavoli63499d42011-10-24 18:50:03 +0200798 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200799 }
800 } else {
801 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200802 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200803 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200804 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200805}
806
Patrick Benavoli63499d42011-10-24 18:50:03 +0200807CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200808{
809 (void)remoteCommand;
810
811 strResult = autoSyncOn() ? "on" : "off";
812
Patrick Benavoli63499d42011-10-24 18:50:03 +0200813 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200814}
815
Patrick Benavoli63499d42011-10-24 18:50:03 +0200816CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::syncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200817{
818 (void)remoteCommand;
819
Patrick Benavoli63499d42011-10-24 18:50:03 +0200820 return sync(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200821}
822
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200823/// Criteria
Patrick Benavoli63499d42011-10-24 18:50:03 +0200824CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listCriteriaCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200825{
826 (void)remoteCommand;
827
828 getSelectionCriteria()->listSelectionCriteria(strResult, true);
829
Patrick Benavoli63499d42011-10-24 18:50:03 +0200830 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200831}
Patrick Benavoli68a91282011-08-31 11:23:23 +0200832
833/// Domains
Patrick Benavoli63499d42011-10-24 18:50:03 +0200834CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200835{
836 (void)remoteCommand;
837
Patrick Benavoli63499d42011-10-24 18:50:03 +0200838 getConfigurableDomains()->listDomains(strResult);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200839
Patrick Benavoli63499d42011-10-24 18:50:03 +0200840 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200841}
842
Patrick Benavoli63499d42011-10-24 18:50:03 +0200843CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200844{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200845 return createDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200846}
847
Patrick Benavoli63499d42011-10-24 18:50:03 +0200848CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200849{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200850 return deleteDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200851}
852
Kevin Rocard170f0a42012-06-18 13:56:05 +0200853CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteAllDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
854{
855 (void)remoteCommand;
856
857 return deleteAllDomains(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
858}
859
Patrick Benavoli63499d42011-10-24 18:50:03 +0200860CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200861{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200862 return getConfigurableDomains()->renameDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200863}
864
Patrick Benavoli63499d42011-10-24 18:50:03 +0200865CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200866{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200867 // Check tuning mode
868 if (!checkTuningModeOn(strResult)) {
869
870 return CCommandHandler::EFailed;
871 }
872
873 // Set property
874 bool bSequenceAware;
875
876 if (remoteCommand.getArgument(1) == "true") {
877
878 bSequenceAware = true;
879
880 } else if (remoteCommand.getArgument(1) == "false") {
881
882 bSequenceAware = false;
883
884 } else {
885 // Show usage
886 return CCommandHandler::EShowUsage;
887 }
888
889 return getConfigurableDomains()->setSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200890}
891
Patrick Benavoli63499d42011-10-24 18:50:03 +0200892CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200893{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200894 // Get property
895 bool bSequenceAware;
896
897 if (!getConfigurableDomains()->getSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult)) {
898
899 return CCommandHandler::EFailed;
900 }
901
902 strResult = bSequenceAware ? "true" : "false";
903
904 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200905}
906
Patrick Benavoli63499d42011-10-24 18:50:03 +0200907CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200908{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200909 return getConfigurableDomains()->listDomainElements(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200910}
911
Patrick Benavoli63499d42011-10-24 18:50:03 +0200912CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::addElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200913{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200914 return addConfigurableElementToDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
915}
916
917CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::removeElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
918{
919 return removeConfigurableElementFromDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
920}
921
922CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::splitDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
923{
924 return split(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200925}
926
927/// Configurations
Patrick Benavoli63499d42011-10-24 18:50:03 +0200928CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConfigurationsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200929{
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100930 return getConstConfigurableDomains()->listConfigurations(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
931}
932
933CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
934{
935 (void)remoteCommand;
936
937 // Dummy error context
938 string strError;
939 CErrorContext errorContext(strError);
940
941 // Dump
942 getConstConfigurableDomains()->dumpContent(strResult, errorContext);
943
944 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200945}
946
Patrick Benavoli63499d42011-10-24 18:50:03 +0200947CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200948{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200949 return createConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200950}
951
Patrick Benavoli63499d42011-10-24 18:50:03 +0200952CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200953{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200954 return deleteConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200955}
956
Patrick Benavoli63499d42011-10-24 18:50:03 +0200957CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200958{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200959 return getConfigurableDomains()->renameConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200960}
961
Patrick Benavoli63499d42011-10-24 18:50:03 +0200962CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::saveConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200963{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200964 return saveConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200965}
966
Patrick Benavoli63499d42011-10-24 18:50:03 +0200967CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::restoreConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200968{
Kevin Rocardace81f82012-12-11 16:19:17 +0100969 list<string> lstrResult;
970 if (!restoreConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), lstrResult)) {
971 //Concatenate the error list as the command result
972 CUtility::concatenate(lstrResult, strResult);
973
974 return CCommandHandler::EFailed;
975 }
976 return CCommandHandler::EDone;
Patrick Benavoli63499d42011-10-24 18:50:03 +0200977}
978
979CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
980{
981 // Check tuning mode
982 if (!checkTuningModeOn(strResult)) {
983
984 return CCommandHandler::EFailed;
985 }
986
987 // Build configurable element path list
988 vector<string> astrNewElementSequence;
989
990 uint32_t uiArgument;
991
992 for (uiArgument = 2; uiArgument < remoteCommand.getArgumentCount(); uiArgument++) {
993
994 astrNewElementSequence.push_back(remoteCommand.getArgument(uiArgument));
995 }
996
997 // Delegate to configurable domains
998 return getConfigurableDomains()->setElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), astrNewElementSequence, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
999}
1000
1001CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1002{
1003 // Delegate to configurable domains
1004 return getConfigurableDomains()->getElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001005}
1006
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001007CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1008{
1009 // Delegate to configurable domains
1010 return getConfigurableDomains()->setApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.packArguments(2, remoteCommand.getArgumentCount() - 2), getConstSelectionCriteria()->getSelectionCriteriaDefinition(), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1011}
1012
1013CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::clearRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1014{
1015 // Delegate to configurable domains
1016 return getConfigurableDomains()->clearApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1017}
1018
1019CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1020{
1021 // Delegate to configurable domains
1022 return getConfigurableDomains()->getApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
1023}
1024
Patrick Benavoli68a91282011-08-31 11:23:23 +02001025/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001026CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001027{
1028 CElementLocator elementLocator(getSystemClass(), false);
1029
1030 CElement* pLocatedElement = NULL;
1031
1032 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1033
Patrick Benavoli63499d42011-10-24 18:50:03 +02001034 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001035 }
1036
1037 strResult = string("\n");
1038
1039 if (!pLocatedElement) {
1040
1041 // List from root folder
1042
1043 // Return system class qualified name
1044 pLocatedElement = getSystemClass();
1045 }
1046
1047 // Return sub-elements
1048 strResult += pLocatedElement->listQualifiedPaths(false);
1049
Patrick Benavoli63499d42011-10-24 18:50:03 +02001050 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001051}
1052
1053/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001054CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listParametersCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001055{
1056 CElementLocator elementLocator(getSystemClass(), false);
1057
1058 CElement* pLocatedElement = NULL;
1059
1060 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1061
Patrick Benavoli63499d42011-10-24 18:50:03 +02001062 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001063 }
1064
1065 strResult = string("\n");
1066
1067 if (!pLocatedElement) {
1068
1069 // List from root folder
1070
1071 // Return system class qualified name
1072 pLocatedElement = getSystemClass();
1073 }
1074
1075 // Return sub-elements
1076 strResult += pLocatedElement->listQualifiedPaths(true);
1077
Patrick Benavoli63499d42011-10-24 18:50:03 +02001078 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001079}
1080
Patrick Benavoli63499d42011-10-24 18:50:03 +02001081CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001082{
1083 CElementLocator elementLocator(getSystemClass());
1084
1085 CElement* pLocatedElement = NULL;
1086
1087 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1088
Patrick Benavoli63499d42011-10-24 18:50:03 +02001089 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001090 }
1091
1092 string strError;
1093
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001094 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001095
1096 // Dump elements
1097 pLocatedElement->dumpContent(strResult, parameterAccessContext);
1098
Patrick Benavoli63499d42011-10-24 18:50:03 +02001099 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001100}
1101
Patrick Benavoli63499d42011-10-24 18:50:03 +02001102CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSizeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001103{
1104 CElementLocator elementLocator(getSystemClass());
1105
1106 CElement* pLocatedElement = NULL;
1107
1108 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1109
Patrick Benavoli63499d42011-10-24 18:50:03 +02001110 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001111 }
1112
1113 // Converted to actual sizable element
1114 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1115
1116 // Get size as string
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001117 strResult = pConfigurableElement->getFootprintAsString();
Patrick Benavoli68a91282011-08-31 11:23:23 +02001118
Patrick Benavoli63499d42011-10-24 18:50:03 +02001119 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001120}
1121
Patrick Benavoli63499d42011-10-24 18:50:03 +02001122CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showPropertiesCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001123{
1124 CElementLocator elementLocator(getSystemClass());
1125
1126 CElement* pLocatedElement = NULL;
1127
1128 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1129
Patrick Benavoli63499d42011-10-24 18:50:03 +02001130 return CCommandHandler::EFailed;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001131 }
1132
1133 // Convert element
1134 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1135
1136 // Return element properties
1137 pConfigurableElement->showProperties(strResult);
1138
Patrick Benavoli63499d42011-10-24 18:50:03 +02001139 return CCommandHandler::ESucceeded;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001140}
1141
Patrick Benavoli63499d42011-10-24 18:50:03 +02001142CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001143{
1144 string strValue;
1145
Patrick Benavoli065264a2011-11-20 15:46:41 +01001146 if (!accessValue(remoteCommand.getArgument(0), strValue, false, strResult)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001147
Patrick Benavoli63499d42011-10-24 18:50:03 +02001148 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001149 }
1150 // Succeeded
1151 strResult = strValue;
1152
Patrick Benavoli63499d42011-10-24 18:50:03 +02001153 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001154}
1155
Patrick Benavoli63499d42011-10-24 18:50:03 +02001156CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001157{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001158 // Check tuning mode
1159 if (!checkTuningModeOn(strResult)) {
1160
1161 return CCommandHandler::EFailed;
1162 }
1163 // Get value to set
1164 string strValue = remoteCommand.packArguments(1, remoteCommand.getArgumentCount() - 1);
1165
1166 return accessValue(remoteCommand.getArgument(0), strValue, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001167}
1168
Patrick Benavoli63499d42011-10-24 18:50:03 +02001169CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listBelongingDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001170{
1171 CElementLocator elementLocator(getSystemClass());
1172
1173 CElement* pLocatedElement = NULL;
1174
1175 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1176
Patrick Benavoli63499d42011-10-24 18:50:03 +02001177 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001178 }
1179
1180 // Convert element
1181 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1182
1183 // Return element belonging domains
1184 pConfigurableElement->listBelongingDomains(strResult);
1185
Patrick Benavoli63499d42011-10-24 18:50:03 +02001186 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001187}
1188
Patrick Benavoli63499d42011-10-24 18:50:03 +02001189CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001190{
1191 CElementLocator elementLocator(getSystemClass());
1192
1193 CElement* pLocatedElement = NULL;
1194
1195 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1196
Patrick Benavoli63499d42011-10-24 18:50:03 +02001197 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001198 }
1199
1200 // Convert element
1201 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1202
1203 // Return element belonging domains
1204 pConfigurableElement->listAssociatedDomains(strResult);
1205
Patrick Benavoli63499d42011-10-24 18:50:03 +02001206 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001207}
1208
Patrick Benavoli63499d42011-10-24 18:50:03 +02001209CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001210{
1211 (void)remoteCommand;
1212
1213 getConfigurableDomains()->listAssociatedElements(strResult);
1214
Patrick Benavoli63499d42011-10-24 18:50:03 +02001215 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001216}
1217
Patrick Benavoli63499d42011-10-24 18:50:03 +02001218CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConflictingElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001219{
1220 (void)remoteCommand;
1221
1222 getConfigurableDomains()->listConflictingElements(strResult);
1223
Patrick Benavoli63499d42011-10-24 18:50:03 +02001224 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001225}
1226
Patrick Benavoli63499d42011-10-24 18:50:03 +02001227CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listRogueElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001228{
1229 (void)remoteCommand;
1230
1231 getSystemClass()->listRogueElements(strResult);
1232
Patrick Benavoli63499d42011-10-24 18:50:03 +02001233 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001234}
1235
1236/// Settings Import/Export
Patrick Benavoli63499d42011-10-24 18:50:03 +02001237CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001238{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001239 return exportDomainsXml(remoteCommand.getArgument(0), false, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001240}
1241
Patrick Benavoli63499d42011-10-24 18:50:03 +02001242CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001243{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001244 return importDomainsXml(remoteCommand.getArgument(0), false, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001245}
1246
Patrick Benavoli63499d42011-10-24 18:50:03 +02001247CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001248{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001249 return exportDomainsXml(remoteCommand.getArgument(0), true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001250}
1251
Patrick Benavoli63499d42011-10-24 18:50:03 +02001252CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001253{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001254 return importDomainsXml(remoteCommand.getArgument(0), true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001255}
1256
Patrick Benavoli63499d42011-10-24 18:50:03 +02001257CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001258{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001259 return exportDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001260}
1261
Patrick Benavoli63499d42011-10-24 18:50:03 +02001262CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001263{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001264 return importDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001265}
1266
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001267/// GUI commands
1268
1269CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getDomainsXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1270{
1271 (void)remoteCommand;
1272
1273 if (!getDomainsXMLString(strResult, true)) {
1274
1275 return CCommandHandler::EFailed;
1276 }
1277 // Succeeded
1278 return CCommandHandler::ESucceeded;
1279}
1280
1281CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getSystemClassXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1282{
1283 (void)remoteCommand;
1284
1285 if (!getSystemClassXMLString(strResult)) {
1286
1287 return CCommandHandler::EFailed;
1288 }
1289 // Succeeded
1290 return CCommandHandler::ESucceeded;
1291}
1292
Patrick Benavoli68a91282011-08-31 11:23:23 +02001293// User set/get parameters
Patrick Benavoli065264a2011-11-20 15:46:41 +01001294bool CParameterMgr::accessValue(const string& strPath, string& strValue, bool bSet, string& strError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001295{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001296 // Lock state
1297 CAutoLock autoLock(&_blackboardMutex);
1298
1299 CPathNavigator pathNavigator(strPath);
1300
1301 // Nagivate through system class
1302 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001303
1304 return false;
1305 }
1306
Patrick Benavoli065264a2011-11-20 15:46:41 +01001307 // Define context
1308 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001309
Patrick Benavoli68808c62012-02-02 17:12:41 +01001310 // Auto Sync
1311 if (bSet) {
1312
1313 parameterAccessContext.setAutoSync(_bAutoSyncOn);
1314 }
1315
Patrick Benavoli065264a2011-11-20 15:46:41 +01001316 // Do the get
1317 return getConstSystemClass()->accessValue(pathNavigator, strValue, bSet, parameterAccessContext);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001318}
1319
1320// Tuning mode
1321bool CParameterMgr::setTuningMode(bool bOn, string& strError)
1322{
1323 // Tuning allowed?
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001324 if (bOn && !getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001325
1326 strError = "Tuning prohibited";
1327
1328 return false;
1329 }
1330 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +01001331 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001332
1333 // Warn domains about exiting tuning mode
1334 if (!bOn && _bTuningModeIsOn) {
1335
1336 // Ensure application of currently selected configurations
Patrick Benavoli1387bda2011-08-31 11:23:24 +02001337 // Force-apply configurations
Kevin Rocardace81f82012-12-11 16:19:17 +01001338 getConfigurableDomains()->apply(_pMainParameterBlackboard, true);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001339
Patrick Benavoli68a91282011-08-31 11:23:23 +02001340 // Turn auto sync back on
1341 _bAutoSyncOn = true;
1342 }
1343
1344 // Store
1345 _bTuningModeIsOn = bOn;
1346
Patrick Benavoli68a91282011-08-31 11:23:23 +02001347 return true;
1348}
1349
1350bool CParameterMgr::tuningModeOn() const
1351{
1352 return _bTuningModeIsOn;
1353}
1354
1355// Current value space for user set/get value interpretation
1356void CParameterMgr::setValueSpace(bool bIsRaw)
1357{
1358 _bValueSpaceIsRaw = bIsRaw;
1359}
1360
1361bool CParameterMgr::valueSpaceIsRaw()
1362{
1363 return _bValueSpaceIsRaw;
1364}
1365
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001366// Current Output Raw Format for user get value interpretation
1367void CParameterMgr::setOutputRawFormat(bool bIsHex)
1368{
1369 _bOutputRawFormatIsHex = bIsHex;
1370}
1371
1372bool CParameterMgr::outputRawFormatIsHex()
1373{
1374 return _bOutputRawFormatIsHex;
1375}
1376
Patrick Benavoli68a91282011-08-31 11:23:23 +02001377/// Sync
1378// Automatic hardware synchronization control (during tuning session)
1379bool CParameterMgr::setAutoSync(bool bAutoSyncOn, string& strError)
1380{
1381 // Check tuning mode
1382 if (!checkTuningModeOn(strError)) {
1383
1384 return false;
1385 }
1386 // Warn domains about turning auto sync back on
1387 if (bAutoSyncOn && !_bAutoSyncOn) {
1388
Patrick Benavoli592ae562011-09-05 16:53:58 +02001389 // Do the synchronization at system class level (could be optimized by keeping track of all modified parameters)
1390 if (!sync(strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001391
1392 return false;
1393 }
1394 }
1395
1396 // Set Auto sync
1397 _bAutoSyncOn = bAutoSyncOn;
1398
1399 return true;
1400}
1401
1402bool CParameterMgr::autoSyncOn() const
1403{
1404 return _bAutoSyncOn;
1405}
1406
1407// Manual hardware synchronization control (during tuning session)
1408bool CParameterMgr::sync(string& strError)
1409{
1410 // Check tuning mode
1411 if (!checkTuningModeOn(strError)) {
1412
1413 return false;
1414 }
1415 // Warn domains about turning auto sync back on
1416 if (_bAutoSyncOn) {
1417
1418 strError = "Feature unavailable when Auto Sync is on";
1419
1420 return false;
1421 }
1422
1423 // Get syncer set
1424 CSyncerSet syncerSet;
1425 // ... from system class
1426 getConstSystemClass()->fillSyncerSet(syncerSet);
Kevin Rocardace81f82012-12-11 16:19:17 +01001427
Patrick Benavoli68a91282011-08-31 11:23:23 +02001428 // Sync
Kevin Rocardace81f82012-12-11 16:19:17 +01001429 list<string> lstrError;
1430 if (! syncerSet.sync(*_pMainParameterBlackboard, false, &lstrError)){
1431
1432 CUtility::concatenate(lstrError, strError);
1433 return false;
1434 };
1435
1436 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001437}
1438
1439// Content dump
1440void CParameterMgr::logStructureContent(string& strContent) const
1441{
1442 string strError;
1443
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001444 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001445
1446 dumpContent(strContent, parameterAccessContext);
1447}
1448
1449// Configuration/Domains handling
1450bool CParameterMgr::createDomain(const string& strName, string& strError)
1451{
1452 // Check tuning mode
1453 if (!checkTuningModeOn(strError)) {
1454
1455 return false;
1456 }
1457
1458 // Delegate to configurable domains
1459 return getConfigurableDomains()->createDomain(strName, strError);
1460}
1461
1462bool CParameterMgr::deleteDomain(const string& strName, string& strError)
1463{
1464 // Check tuning mode
1465 if (!checkTuningModeOn(strError)) {
1466
1467 return false;
1468 }
1469
1470 // Delegate to configurable domains
1471 return getConfigurableDomains()->deleteDomain(strName, strError);
1472}
1473
Kevin Rocard170f0a42012-06-18 13:56:05 +02001474bool CParameterMgr::deleteAllDomains(string& strError)
1475{
1476 // Check tuning mode
1477 if (!checkTuningModeOn(strError)) {
1478
1479 return false;
1480 }
1481
1482 // Delegate to configurable domains
1483 getConfigurableDomains()->deleteAllDomains();
1484
1485 return true;
1486}
1487
Patrick Benavoli68a91282011-08-31 11:23:23 +02001488bool CParameterMgr::createConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1489{
1490 // Check tuning mode
1491 if (!checkTuningModeOn(strError)) {
1492
1493 return false;
1494 }
1495
1496 // Delegate to configurable domains
1497 return getConfigurableDomains()->createConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1498}
1499
1500bool CParameterMgr::deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1501{
1502 // Check tuning mode
1503 if (!checkTuningModeOn(strError)) {
1504
1505 return false;
1506 }
1507
1508 // Delegate to configurable domains
1509 return getConfigurableDomains()->deleteConfiguration(strDomain, strConfiguration, strError);
1510}
1511
Kevin Rocardace81f82012-12-11 16:19:17 +01001512bool CParameterMgr::restoreConfiguration(const string& strDomain, const string& strConfiguration, list<string>& lstrError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001513{
Kevin Rocardace81f82012-12-11 16:19:17 +01001514 string strError;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001515 // Check tuning mode
1516 if (!checkTuningModeOn(strError)) {
1517
Kevin Rocardace81f82012-12-11 16:19:17 +01001518 lstrError.push_back(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001519 return false;
1520 }
1521
1522 // Delegate to configurable domains
Kevin Rocardace81f82012-12-11 16:19:17 +01001523 return getConstConfigurableDomains()->restoreConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, lstrError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001524}
1525
1526bool CParameterMgr::saveConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1527{
1528 // Check tuning mode
1529 if (!checkTuningModeOn(strError)) {
1530
1531 return false;
1532 }
1533
1534 // Delegate to configurable domains
1535 return getConfigurableDomains()->saveConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1536}
1537
1538// Configurable element - domain association
1539bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1540{
1541 // Check tuning mode
1542 if (!checkTuningModeOn(strError)) {
1543
1544 return false;
1545 }
1546
1547 CElementLocator elementLocator(getSystemClass());
1548
1549 CElement* pLocatedElement = NULL;
1550
1551 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1552
1553 return false;
1554 }
1555
1556 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001557 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001558
1559 // Delegate
1560 return getConfigurableDomains()->addConfigurableElementToDomain(strDomain, pConfigurableElement, _pMainParameterBlackboard, strError);
1561}
1562
1563bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1564{
1565 // Check tuning mode
1566 if (!checkTuningModeOn(strError)) {
1567
1568 return false;
1569 }
1570
1571 CElementLocator elementLocator(getSystemClass());
1572
1573 CElement* pLocatedElement = NULL;
1574
1575 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1576
Patrick Benavoli63499d42011-10-24 18:50:03 +02001577 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001578 }
1579
1580 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001581 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001582
1583 // Delegate
1584 return getConfigurableDomains()->removeConfigurableElementFromDomain(strDomain, pConfigurableElement, strError);
1585}
1586
1587bool CParameterMgr::split(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1588{
1589 // Check tuning mode
1590 if (!checkTuningModeOn(strError)) {
1591
1592 return false;
1593 }
1594
1595 CElementLocator elementLocator(getSystemClass());
1596
1597 CElement* pLocatedElement = NULL;
1598
1599 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1600
Patrick Benavoli63499d42011-10-24 18:50:03 +02001601 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001602 }
1603
1604 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001605 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001606
1607 // Delegate
1608 return getConfigurableDomains()->split(strDomain, pConfigurableElement, strError);
1609}
1610
1611// XML Import/Export
1612bool CParameterMgr::importDomainsXml(const string& strFileName, bool bWithSettings, string& strError)
1613{
1614 // Check tuning mode
1615 if (!checkTuningModeOn(strError)) {
1616
1617 return false;
1618 }
1619
1620 // check path is absolute
1621 if (strFileName[0] != '/') {
1622
1623 strError = "Please provide absolute path";
1624
1625 return false;
1626 }
1627 // Root element
1628 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1629
1630 // Context
1631 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1632
1633 // Secltion criteria definition for rule creation
1634 xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
1635
1636 // Parse
1637 if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strFileName, "", EParameterConfigurationLibrary, "SystemClassName")) {
1638
1639 return false;
1640 }
1641
1642 // Validate domains after XML import
1643 pConfigurableDomains->validate(_pMainParameterBlackboard);
1644
1645 return true;
1646}
1647
1648bool CParameterMgr::exportDomainsXml(const string& strFileName, bool bWithSettings, string& strError) const
1649{
1650 // check path is absolute
1651 if (strFileName[0] != '/') {
1652
1653 strError = "Please provide absolute path";
1654
1655 return false;
1656 }
1657
1658 // Root element
1659 const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains();
1660
1661 // Get Schema file associated to root element
1662 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pConfigurableDomains->getKind() + ".xsd";
1663
1664 // Context
1665 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1666
1667 // Value space
1668 xmlDomainSerializingContext.setValueSpaceRaw(_bValueSpaceIsRaw);
1669
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001670 // Output raw format
1671 xmlDomainSerializingContext.setOutputRawFormat(_bOutputRawFormatIsHex);
1672
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001673 // Use a doc source by loading data from instantiated Configurable Domains
1674 CXmlMemoryDocSource memorySource(pConfigurableDomains, pConfigurableDomains->getKind(), strXmlSchemaFilePath, "parameter-framework", getVersion());
Patrick Benavoli68a91282011-08-31 11:23:23 +02001675
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001676 // Use a doc sink to write the doc data in a file
1677 CXmlFileDocSink fileSink(strFileName);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001678
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001679 if (!fileSink.process(memorySource, xmlDomainSerializingContext)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001680 return false;
1681 }
1682
1683 return true;
1684}
1685
1686// Binary Import/Export
1687bool CParameterMgr::importDomainsBinary(const string& strFileName, string& strError)
1688{
1689 // Check tuning mode
1690 if (!checkTuningModeOn(strError)) {
1691
1692 return false;
1693 }
1694 // check path is absolute
1695 if (strFileName[0] != '/') {
1696
1697 strError = "Please provide absolute path";
1698
1699 return false;
1700 }
1701 // Root element
1702 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1703
1704 // Serialize in
1705 return pConfigurableDomains->serializeSettings(strFileName, false, _uiStructureChecksum, strError);
1706}
1707
1708bool CParameterMgr::exportDomainsBinary(const string& strFileName, string& strError)
1709{
1710 // check path is absolute
1711 if (strFileName[0] != '/') {
1712
1713 strError = "Please provide absolute path";
1714
1715 return false;
1716 }
Patrick Benavoli68a91282011-08-31 11:23:23 +02001717
Patrick Benavoli68a91282011-08-31 11:23:23 +02001718 // Root element
1719 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1720
1721 // Serialize out
1722 return pConfigurableDomains->serializeSettings(strFileName, true, _uiStructureChecksum, strError);
1723}
1724
1725// For tuning, check we're in tuning mode
1726bool CParameterMgr::checkTuningModeOn(string& strError) const
1727{
1728 // Tuning Mode on?
1729 if (!_bTuningModeIsOn) {
1730
1731 strError = "Tuning Mode must be on";
1732
1733 return false;
1734 }
1735 return true;
1736}
1737
Patrick Benavoli065264a2011-11-20 15:46:41 +01001738// Tuning mutex dynamic parameter handling
1739pthread_mutex_t* CParameterMgr::getBlackboardMutex()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001740{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001741 return &_blackboardMutex;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001742}
1743
Patrick Benavoli065264a2011-11-20 15:46:41 +01001744// Blackboard reference (dynamic parameter handling)
1745CParameterBlackboard* CParameterMgr::getParameterBlackboard()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001746{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001747 return _pMainParameterBlackboard;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001748}
1749
Patrick Benavoli68a91282011-08-31 11:23:23 +02001750// Dynamic creation library feeding
1751void CParameterMgr::feedElementLibraries()
1752{
1753 // Global Configuration handling
1754 CElementLibrary* pFrameworkConfigurationLibrary = new CElementLibrary;
1755
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001756 pFrameworkConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CParameterFrameworkConfiguration>("ParameterFrameworkConfiguration"));
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +01001757 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CSubsystemPlugins>("SubsystemPlugins"));
1758 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CPluginLocation>("Location"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001759 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("StructureDescriptionFileLocation"));
1760 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationGroup>("SettingsConfiguration"));
1761 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("ConfigurableDomainsFileLocation"));
1762 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("BinarySettingsFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001763
1764 _pElementLibrarySet->addElementLibrary(pFrameworkConfigurationLibrary);
1765
1766 // Parameter creation
1767 CElementLibrary* pParameterCreationLibrary = new CElementLibrary;
1768
1769 pParameterCreationLibrary->addElementBuilder(new CSubsystemElementBuilder(getSystemClass()->getSubsystemLibrary()));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001770 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CComponentType>("ComponentType"));
1771 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CComponentInstance>("Component"));
1772 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBitParameterType>("BitParameter"));
1773 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBitParameterBlockType>("BitParameterBlock"));
Patrick Benavoli1352ae52011-10-21 16:48:04 +02001774 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CStringParameterType>("StringParameter"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001775 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CParameterBlockType>("ParameterBlock"));
1776 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBooleanParameterType>("BooleanParameter"));
1777 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CIntegerParameterType>("IntegerParameter"));
Patrick Benavoliee65e6d2011-11-20 18:52:24 +01001778 pParameterCreationLibrary->addElementBuilder(new TElementBuilderTemplate<CLinearParameterAdaptation>("LinearAdaptation"));
Patrick Benavoli9fc3c0d2011-10-27 14:27:27 +02001779 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CEnumParameterType>("EnumParameter"));
Patrick Benavoli68808c62012-02-02 17:12:41 +01001780 pParameterCreationLibrary->addElementBuilder(new TElementBuilderTemplate<CEnumValuePair>("ValuePair"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001781 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CFixedPointParameterType>("FixedPointParameter"));
1782 pParameterCreationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CXmlFileIncluderElement>("SubsystemInclude"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001783
1784 _pElementLibrarySet->addElementLibrary(pParameterCreationLibrary);
1785
1786 // Parameter Configuration Domains creation
1787 CElementLibrary* pParameterConfigurationLibrary = new CElementLibrary;
1788
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001789 pParameterConfigurationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CConfigurableDomain>("ConfigurableDomain"));
1790 pParameterConfigurationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CDomainConfiguration>("Configuration"));
1791 pParameterConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CCompoundRule>("CompoundRule"));
1792 pParameterConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CSelectionCriterionRule>("SelectionCriterionRule"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001793
1794 _pElementLibrarySet->addElementLibrary(pParameterConfigurationLibrary);
1795}
1796
1797// Remote Processor Server connection handling
1798bool CParameterMgr::handleRemoteProcessingInterface(string& strError)
1799{
1800 CAutoLog autoLog(this, "Handling remote processing interface");
1801
1802 // Start server if tuning allowed
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001803 if (getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001804
Kevin Rocardace81f82012-12-11 16:19:17 +01001805 log_info("Loading remote processor library");
Patrick Benavoli68a91282011-08-31 11:23:23 +02001806
1807 // Load library
1808 void* lib_handle = dlopen("libremote-processor.so", RTLD_NOW);
1809
1810 if (!lib_handle) {
1811
1812 // Return error
1813 const char* pcError = dlerror();
1814
1815 if (pcError) {
1816
1817 strError = pcError;
1818 } else {
1819
1820 strError = "Unable to load libremote-processor.so library";
1821 }
1822
1823 return false;
1824 }
1825
1826 CreateRemoteProcessorServer pfnCreateRemoteProcessorServer = (CreateRemoteProcessorServer)dlsym(lib_handle, "createRemoteProcessorServer");
1827
1828 if (!pfnCreateRemoteProcessorServer) {
1829
1830 strError = "libremote-process.so does not contain createRemoteProcessorServer symbol.";
1831
1832 return false;
1833 }
1834
1835 // Create server
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001836 _pRemoteProcessorServer = pfnCreateRemoteProcessorServer(getConstFrameworkConfiguration()->getServerPort(), _pCommandHandler);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001837
Kevin Rocardace81f82012-12-11 16:19:17 +01001838 log_info("Starting remote processor server on port %d", getConstFrameworkConfiguration()->getServerPort());
Patrick Benavoli68a91282011-08-31 11:23:23 +02001839 // Start
1840 if (!_pRemoteProcessorServer->start()) {
1841
1842 strError = "Unable to start remote processor server";
1843
1844 return false;
1845 }
1846 }
1847
1848 return true;
1849}
1850
1851// Back synchronization
Kevin Rocardace81f82012-12-11 16:19:17 +01001852CBackSynchronizer* CParameterMgr::createBackSynchronizer() const
Patrick Benavoli68a91282011-08-31 11:23:23 +02001853{
1854#ifdef SIMULATION
1855 // In simulation, back synchronization of the blackboard won't probably work
1856 // We need to ensure though the blackboard is initialized with valid data
Kevin Rocardace81f82012-12-11 16:19:17 +01001857 return new CSimulatedBackSynchronizer(getConstSystemClass(), _pMainParameterBlackboard);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001858#else
1859 // Real back synchronizer from subsystems
Kevin Rocardace81f82012-12-11 16:19:17 +01001860 return new CHardwareBackSynchronizer(getConstSystemClass(), _pMainParameterBlackboard);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001861#endif
1862}
1863
1864// Children typwise access
1865CParameterFrameworkConfiguration* CParameterMgr::getFrameworkConfiguration()
1866{
1867 return static_cast<CParameterFrameworkConfiguration*>(getChild(EFrameworkConfiguration));
1868}
1869
1870const CParameterFrameworkConfiguration* CParameterMgr::getConstFrameworkConfiguration()
1871{
1872 return getFrameworkConfiguration();
1873}
1874
1875CSelectionCriteria* CParameterMgr::getSelectionCriteria()
1876{
1877 return static_cast<CSelectionCriteria*>(getChild(ESelectionCriteria));
1878}
1879
1880const CSelectionCriteria* CParameterMgr::getConstSelectionCriteria()
1881{
1882 return static_cast<const CSelectionCriteria*>(getChild(ESelectionCriteria));
1883}
1884
1885CSystemClass* CParameterMgr::getSystemClass()
1886{
1887 return static_cast<CSystemClass*>(getChild(ESystemClass));
1888}
1889
1890const CSystemClass* CParameterMgr::getConstSystemClass() const
1891{
1892 return static_cast<const CSystemClass*>(getChild(ESystemClass));
1893}
1894
1895// Configurable Domains
1896CConfigurableDomains* CParameterMgr::getConfigurableDomains()
1897{
1898 return static_cast<CConfigurableDomains*>(getChild(EConfigurableDomains));
1899}
1900
1901const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains()
1902{
1903 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
1904}
1905
1906const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains() const
1907{
1908 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
1909}
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001910
1911/// GUI commands functions
1912
1913bool CParameterMgr::getDomainsXMLString(string& strResult, bool bWithSettings)
1914{
1915
1916 // Root element
1917 const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains();
1918
1919 // Get Schema file associated to root element
1920 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pConfigurableDomains->getKind() + ".xsd";
1921
1922 string strError;
1923
1924 // Context
1925 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1926
1927 // Value space
1928 xmlDomainSerializingContext.setValueSpaceRaw(_bValueSpaceIsRaw);
1929
1930 // Output raw format
1931 xmlDomainSerializingContext.setOutputRawFormat(_bOutputRawFormatIsHex);
1932
1933 // Use a doc source by loading data from instantiated Configurable Domains
1934 CXmlMemoryDocSource memorySource(pConfigurableDomains, pConfigurableDomains->getKind(), strXmlSchemaFilePath, "parameter-framework", getVersion());
1935
1936 // Use a doc sink the write the doc data in a string
1937 CXmlStringDocSink stringSink(strResult);
1938
1939 if (!stringSink.process(memorySource, xmlDomainSerializingContext)) {
1940 strResult = strError;
1941
1942 return false;
1943 }
1944
1945 return true;
1946}
1947
1948bool CParameterMgr::getSystemClassXMLString(string& strResult)
1949{
1950 // Root element
1951 const CSystemClass* pSystemClass = getSystemClass();
1952
1953 string strError;
1954
1955 CXmlSerializingContext xmlSerializingContext(strError);
1956
1957 // Use a doc source by loading data from instantiated Configurable Domains
1958 CXmlMemoryDocSource memorySource(pSystemClass, pSystemClass->getKind());
1959
1960 // Use a doc sink that write the doc data in a string
1961 CXmlStringDocSink stringSink(strResult);
1962
1963 if (!stringSink.process(memorySource, xmlSerializingContext)) {
1964 strResult = strError;
1965 return false;
1966 }
1967
1968 return true;
1969}