blob: 484687ac65e0b73406baae0dcf378b065154def9 [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
Kevin Rocard7f265822012-12-07 18:51:22 +0100358 // Log selection criterion states
359 {
360 CAutoLog autoLog(this, "Criterion states");
361
362 const CSelectionCriteria* selectionCriteria = getConstSelectionCriteria();
363
364 list<string> lstrSelectionCriteron;
365 selectionCriteria->listSelectionCriteria(lstrSelectionCriteron, true, false);
366
367 string strSelectionCriteron;
368 CUtility::concatenate(lstrSelectionCriteron, strSelectionCriteron);
369
370 log_info("%s", strSelectionCriteron.c_str());
371 }
372
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100373 // At initialization, check subsystems that need resync
374 doApplyConfigurations(true);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200375
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200376 // Start remote processor server if appropriate
377 return handleRemoteProcessingInterface(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200378}
379
380bool CParameterMgr::loadFrameworkConfiguration(string& strError)
381{
382 CAutoLog autoLog(this, "Loading framework configuration");
383
Patrick Benavoli68a91282011-08-31 11:23:23 +0200384 // Parse Structure XML file
385 CXmlElementSerializingContext elementSerializingContext(strError);
386
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100387 if (!xmlParse(elementSerializingContext, getFrameworkConfiguration(), _strXmlConfigurationFilePath, _strXmlConfigurationFolderPath, EFrameworkConfigurationLibrary)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200388
389 return false;
390 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100391 // Set class name to system class and configurable domains
392 getSystemClass()->setName(getConstFrameworkConfiguration()->getSystemClassName());
393 getConfigurableDomains()->setName(getConstFrameworkConfiguration()->getSystemClassName());
394
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100395 // Get subsystem plugins elements
396 _pSubsystemPlugins = static_cast<const CSubsystemPlugins*>(getConstFrameworkConfiguration()->findChild("SubsystemPlugins"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200397
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100398 if (!_pSubsystemPlugins) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200399
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100400 strError = "Parameter Framework Configuration: couldn't find SubsystemPlugins element";
Patrick Benavoli68a91282011-08-31 11:23:23 +0200401
402 return false;
403 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200404
Patrick Benavoli68a91282011-08-31 11:23:23 +0200405 // Log tuning availability
Kevin Rocardace81f82012-12-11 16:19:17 +0100406 log_info("Tuning %s", getConstFrameworkConfiguration()->isTuningAllowed() ? "allowed" : "prohibited");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200407
408 return true;
409}
410
411bool CParameterMgr::loadStructure(string& strError)
412{
413 // Retrieve system to load structure to
414 CSystemClass* pSystemClass = getSystemClass();
415
416 CAutoLog autoLog(this, "Loading " + pSystemClass->getName() + " system class structure");
417
418 // Get structure description element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100419 const CFrameworkConfigurationLocation* pStructureDescriptionFileLocation = static_cast<const CFrameworkConfigurationLocation*>(getConstFrameworkConfiguration()->findChildOfKind("StructureDescriptionFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200420
421 if (!pStructureDescriptionFileLocation) {
422
423 strError = "No StructureDescriptionFileLocation element found for SystemClass " + pSystemClass->getName();
424
425 return false;
426 }
427
428 // Get Xml structure folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100429 string strXmlStructureFolder = pStructureDescriptionFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200430
431 // Get Xml structure file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100432 string strXmlStructureFilePath = pStructureDescriptionFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200433
434 // Parse Structure XML file
435 CXmlParameterSerializingContext parameterBuildContext(strError);
436
Kevin Rocard57096bd2012-11-30 11:24:20 +0100437 CAutoLog autolog(pSystemClass, "Importing system structure from file " + strXmlStructureFilePath);
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200438
Patrick Benavoli68a91282011-08-31 11:23:23 +0200439 if (!xmlParse(parameterBuildContext, pSystemClass, strXmlStructureFilePath, strXmlStructureFolder, EParameterCreationLibrary)) {
440
441 return false;
442 }
443
444 // Initialize offsets
445 pSystemClass->setOffset(0);
446
447 // Initialize main blackboard's size
448 _pMainParameterBlackboard->setSize(pSystemClass->getFootPrint());
449
450 return true;
451}
452
453bool CParameterMgr::loadSettings(string& strError)
454{
455 CAutoLog autoLog(this, "Loading settings");
456
457 // Get settings configuration element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100458 const CFrameworkConfigurationGroup* pParameterConfigurationGroup = static_cast<const CFrameworkConfigurationGroup*>(getConstFrameworkConfiguration()->findChildOfKind("SettingsConfiguration"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200459
460 if (!pParameterConfigurationGroup) {
461
462 // No settings to load
463
464 return true;
465 }
466 // Get binary settings file location
467 const CFrameworkConfigurationLocation* pBinarySettingsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("BinarySettingsFileLocation"));
468
469 string strXmlBinarySettingsFilePath;
470
471 if (pBinarySettingsFileLocation) {
472
473 // Get Xml binary settings file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100474 strXmlBinarySettingsFilePath = pBinarySettingsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200475 }
476
477 // Get configurable domains element
478 const CFrameworkConfigurationLocation* pConfigurableDomainsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("ConfigurableDomainsFileLocation"));
479
480 if (!pConfigurableDomainsFileLocation) {
481
482 strError = "No ConfigurableDomainsFileLocation element found for SystemClass " + getSystemClass()->getName();
483
484 return false;
485 }
486 // Get destination root element
487 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
488
489 // Get Xml configuration domains file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100490 string strXmlConfigurationDomainsFilePath = pConfigurableDomainsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200491
492 // Get Xml configuration domains folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100493 string strXmlConfigurationDomainsFolder = pConfigurableDomainsFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200494
495 // Parse configuration domains XML file (ask to read settings from XML file if they are not provided as binary)
496 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, !pBinarySettingsFileLocation);
497
498 // Selection criteria definition for rule creation
499 xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
500
Patrick Benavoli63499d42011-10-24 18:50:03 +0200501 // Auto validation of configurations if no binary settings provided
502 xmlDomainSerializingContext.setAutoValidationRequired(!pBinarySettingsFileLocation);
503
Kevin Rocardace81f82012-12-11 16:19:17 +0100504 log_info("Importing configurable domains from file %s %s settings", strXmlConfigurationDomainsFilePath.c_str(), pBinarySettingsFileLocation ? "without" : "with");
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200505
Patrick Benavoli68a91282011-08-31 11:23:23 +0200506 // Do parse
507 if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strXmlConfigurationDomainsFilePath, strXmlConfigurationDomainsFolder, EParameterConfigurationLibrary, "SystemClassName")) {
508
509 return false;
510 }
511 // We have loaded the whole system structure, compute checksum
512 const CSystemClass* pSystemClass = getConstSystemClass();
513 _uiStructureChecksum = pSystemClass->computeStructureChecksum() + getConfigurableDomains()->computeStructureChecksum() + getSelectionCriteria()->computeStructureChecksum();
514
515 // Load binary settings if any provided
516 if (pBinarySettingsFileLocation && !pConfigurableDomains->serializeSettings(strXmlBinarySettingsFilePath, false, _uiStructureChecksum, strError)) {
517
518 return false;
519 }
520
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200521 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200522}
523
524// XML parsing
525bool CParameterMgr::xmlParse(CXmlElementSerializingContext& elementSerializingContext, CElement* pRootElement, const string& strXmlFilePath, const string& strXmlFolder, CParameterMgr::ElementLibrary eElementLibrary, const string& strNameAttrituteName)
526{
527 // Init serializing context
528 elementSerializingContext.set(_pElementLibrarySet->getElementLibrary(eElementLibrary), strXmlFolder, _strSchemaFolderLocation);
529
530 // Get Schema file associated to root element
531 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pRootElement->getKind() + ".xsd";
532
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200533 CXmlFileDocSource fileDocSource(strXmlFilePath, strXmlSchemaFilePath, pRootElement->getKind(), pRootElement->getName(), strNameAttrituteName);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200534
535 // Start clean
536 pRootElement->clean();
537
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200538 CXmlMemoryDocSink memorySink(pRootElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200539
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200540 if (!memorySink.process(fileDocSource, elementSerializingContext)) {
541 //Cleanup
Patrick Benavoli68a91282011-08-31 11:23:23 +0200542 pRootElement->clean();
543
544 return false;
545 }
546
Patrick Benavoli68a91282011-08-31 11:23:23 +0200547 return true;
548}
549
550// Init
551bool CParameterMgr::init(string& strError)
552{
553 return base::init(strError);
554}
555
556// Selection criteria interface
557CSelectionCriterionType* CParameterMgr::createSelectionCriterionType(bool bIsInclusive)
558{
559 // Propagate
560 return getSelectionCriteria()->createSelectionCriterionType(bIsInclusive);
561}
562
563CSelectionCriterion* CParameterMgr::createSelectionCriterion(const string& strName, const CSelectionCriterionType* pSelectionCriterionType)
564{
565 // Propagate
566 return getSelectionCriteria()->createSelectionCriterion(strName, pSelectionCriterionType);
567}
568
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200569// Selection criterion retrieval
570CSelectionCriterion* CParameterMgr::getSelectionCriterion(const string& strName)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200571{
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200572 // Propagate
573 return getSelectionCriteria()->getSelectionCriterion(strName);
574}
575
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100576// Configuration application
Kevin Rocardace81f82012-12-11 16:19:17 +0100577void CParameterMgr::applyConfigurations()
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200578{
579 CAutoLog autoLog(this, "Configuration application request");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200580
581 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +0100582 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200583
584 if (!_bTuningModeIsOn) {
585
586 // Apply configuration(s)
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100587 doApplyConfigurations(false);
Frédéric Boisnarddaaa63c2012-08-27 15:48:15 +0200588 } else {
589
Kevin Rocardace81f82012-12-11 16:19:17 +0100590 log_warning("Configurations were not applied because the TuningMode is on");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200591 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200592}
593
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200594// Dynamic parameter handling
Patrick Benavoli065264a2011-11-20 15:46:41 +0100595CParameterHandle* CParameterMgr::createParameterHandle(const string& strPath, string& strError)
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200596{
Patrick Benavoli065264a2011-11-20 15:46:41 +0100597 CPathNavigator pathNavigator(strPath);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200598
Patrick Benavoli065264a2011-11-20 15:46:41 +0100599 // Nagivate through system class
600 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
601
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100602 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100603 }
604
605 // Find element
606 const CElement* pElement = getConstSystemClass()->findDescendant(pathNavigator);
607
608 if (!pElement) {
609
610 strError = "Path not found";
611
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100612 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100613 }
614
615 // Check found element is a parameter
616 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pElement);
617
618 if (!pConfigurableElement->isParameter()) {
619
620 // Element is not parameter
621 strError = "Not a parameter";
622
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100623 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100624 }
625
626 // Convert as parameter and return new handle
627 return new CParameterHandle(static_cast<const CBaseParameter*>(pElement), this);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200628}
629
Patrick Benavoli68a91282011-08-31 11:23:23 +0200630/////////////////// Remote command parsers
Patrick Benavoli592ae562011-09-05 16:53:58 +0200631/// Version
Patrick Benavoli63499d42011-10-24 18:50:03 +0200632CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::versionCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli592ae562011-09-05 16:53:58 +0200633{
634 (void)remoteCommand;
635
Patrick Benavoli63499d42011-10-24 18:50:03 +0200636 // Show version
637 strResult = getVersion();
Patrick Benavoli592ae562011-09-05 16:53:58 +0200638
Patrick Benavoli63499d42011-10-24 18:50:03 +0200639 return CCommandHandler::ESucceeded;
Patrick Benavoli592ae562011-09-05 16:53:58 +0200640}
641
Patrick Benavoli68a91282011-08-31 11:23:23 +0200642/// Status
Patrick Benavoli63499d42011-10-24 18:50:03 +0200643CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::statusCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200644{
645 (void)remoteCommand;
646 // System class
647 const CSystemClass* pSystemClass = getSystemClass();
648
Patrick Benavoli68a91282011-08-31 11:23:23 +0200649 // Show status
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200650 /// General section
651 appendTitle(strResult, "General:");
652 // System class
Patrick Benavoli68a91282011-08-31 11:23:23 +0200653 strResult += "System Class: ";
654 strResult += pSystemClass->getName();
655 strResult += "\n";
656
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200657 // Tuning mode
Patrick Benavoli68a91282011-08-31 11:23:23 +0200658 strResult += "Tuning Mode: ";
659 strResult += tuningModeOn() ? "on" : "off";
660 strResult += "\n";
661
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200662 // Value space
Patrick Benavoli68a91282011-08-31 11:23:23 +0200663 strResult += "Value Space: ";
664 strResult += valueSpaceIsRaw() ? "raw" : "real";
665 strResult += "\n";
666
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200667 // Output raw format
668 strResult += "Output Raw Format: ";
669 strResult += outputRawFormatIsHex() ? "hex" : "dec";
670 strResult += "\n";
671
672 // Auto Sync
Patrick Benavoli68a91282011-08-31 11:23:23 +0200673 strResult += "Auto Sync: ";
674 strResult += autoSyncOn() ? "on" : "off";
675 strResult += "\n";
676
677 /// Subsystem list
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200678 appendTitle(strResult, "Subsystems:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200679 string strSubsystemList;
680 pSystemClass->listChildrenPaths(strSubsystemList);
681 strResult += strSubsystemList;
682
683 /// Last applied configurations
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200684 appendTitle(strResult, "Last Applied [Pending] Configurations:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200685 string strLastAppliedConfigurations;
686 getConfigurableDomains()->listLastAppliedConfigurations(strLastAppliedConfigurations);
687 strResult += strLastAppliedConfigurations;
688
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200689 /// Criteria states
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200690 appendTitle(strResult, "Selection Criteria:");
Kevin Rocard7f265822012-12-07 18:51:22 +0100691 list<string> lstrSelectionCriteria;
692 getSelectionCriteria()->listSelectionCriteria(lstrSelectionCriteria, false, true);
693 // Concatenate the criterion list as the command result
694 CUtility::concatenate(lstrSelectionCriteria, strResult);
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200695
Patrick Benavoli63499d42011-10-24 18:50:03 +0200696 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200697}
698
699/// Tuning Mode
Patrick Benavoli63499d42011-10-24 18:50:03 +0200700CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200701{
702 if (remoteCommand.getArgument(0) == "on") {
703
704 if (setTuningMode(true, strResult)) {
705
Patrick Benavoli63499d42011-10-24 18:50:03 +0200706 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200707 }
708 } else if (remoteCommand.getArgument(0) == "off") {
709
710 if (setTuningMode(false, strResult)) {
711
Patrick Benavoli63499d42011-10-24 18:50:03 +0200712 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200713 }
714 } else {
715 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200716 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200717 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200718 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200719}
720
Patrick Benavoli63499d42011-10-24 18:50:03 +0200721CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200722{
723 (void)remoteCommand;
724
725 strResult = tuningModeOn() ? "on" : "off";
726
Patrick Benavoli63499d42011-10-24 18:50:03 +0200727 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200728}
729
730/// Value Space
Patrick Benavoli63499d42011-10-24 18:50:03 +0200731CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200732{
733 (void)strResult;
734
735 if (remoteCommand.getArgument(0) == "raw") {
736
737 setValueSpace(true);
738
Patrick Benavoli63499d42011-10-24 18:50:03 +0200739 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200740
741 } else if (remoteCommand.getArgument(0) == "real") {
742
743 setValueSpace(false);
744
Patrick Benavoli63499d42011-10-24 18:50:03 +0200745 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200746
747 } else {
748 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200749 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200750 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200751 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200752}
753
Patrick Benavoli63499d42011-10-24 18:50:03 +0200754CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200755{
756 (void)remoteCommand;
757
758 strResult = valueSpaceIsRaw() ? "raw" : "real";
759
Patrick Benavoli63499d42011-10-24 18:50:03 +0200760 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200761}
762
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200763/// Output Raw Format
Patrick Benavoli63499d42011-10-24 18:50:03 +0200764CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200765{
766 (void)strResult;
767
768 if (remoteCommand.getArgument(0) == "hex") {
769
770 setOutputRawFormat(true);
771
Patrick Benavoli63499d42011-10-24 18:50:03 +0200772 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200773
774 } else if (remoteCommand.getArgument(0) == "dec") {
775
776 setOutputRawFormat(false);
777
Patrick Benavoli63499d42011-10-24 18:50:03 +0200778 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200779
780 } else {
781 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200782 return CCommandHandler::EShowUsage;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200783 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200784 return CCommandHandler::EFailed;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200785}
786
Patrick Benavoli63499d42011-10-24 18:50:03 +0200787CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200788{
789 (void)remoteCommand;
790
791 strResult = outputRawFormatIsHex() ? "hex" : "dec";
792
Patrick Benavoli63499d42011-10-24 18:50:03 +0200793 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200794}
795
Patrick Benavoli68a91282011-08-31 11:23:23 +0200796/// Sync
Patrick Benavoli63499d42011-10-24 18:50:03 +0200797CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200798{
799 if (remoteCommand.getArgument(0) == "on") {
800
801 if (setAutoSync(true, strResult)) {
802
Patrick Benavoli63499d42011-10-24 18:50:03 +0200803 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200804 }
805 } else if (remoteCommand.getArgument(0) == "off") {
806
807 if (setAutoSync(false, strResult)) {
808
Patrick Benavoli63499d42011-10-24 18:50:03 +0200809 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200810 }
811 } else {
812 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200813 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200814 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200815 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200816}
817
Patrick Benavoli63499d42011-10-24 18:50:03 +0200818CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200819{
820 (void)remoteCommand;
821
822 strResult = autoSyncOn() ? "on" : "off";
823
Patrick Benavoli63499d42011-10-24 18:50:03 +0200824 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200825}
826
Patrick Benavoli63499d42011-10-24 18:50:03 +0200827CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::syncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200828{
829 (void)remoteCommand;
830
Patrick Benavoli63499d42011-10-24 18:50:03 +0200831 return sync(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200832}
833
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200834/// Criteria
Patrick Benavoli63499d42011-10-24 18:50:03 +0200835CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listCriteriaCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200836{
837 (void)remoteCommand;
838
Kevin Rocard7f265822012-12-07 18:51:22 +0100839 list<string> lstrResult;
840
841 getSelectionCriteria()->listSelectionCriteria(lstrResult, true, true);
842
843 // Concatenate the criterion list as the command result
844 CUtility::concatenate(lstrResult, strResult);
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200845
Patrick Benavoli63499d42011-10-24 18:50:03 +0200846 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200847}
Patrick Benavoli68a91282011-08-31 11:23:23 +0200848
849/// Domains
Patrick Benavoli63499d42011-10-24 18:50:03 +0200850CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200851{
852 (void)remoteCommand;
853
Patrick Benavoli63499d42011-10-24 18:50:03 +0200854 getConfigurableDomains()->listDomains(strResult);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200855
Patrick Benavoli63499d42011-10-24 18:50:03 +0200856 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200857}
858
Patrick Benavoli63499d42011-10-24 18:50:03 +0200859CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200860{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200861 return createDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200862}
863
Patrick Benavoli63499d42011-10-24 18:50:03 +0200864CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200865{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200866 return deleteDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200867}
868
Kevin Rocard170f0a42012-06-18 13:56:05 +0200869CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteAllDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
870{
871 (void)remoteCommand;
872
873 return deleteAllDomains(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
874}
875
Patrick Benavoli63499d42011-10-24 18:50:03 +0200876CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200877{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200878 return getConfigurableDomains()->renameDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200879}
880
Patrick Benavoli63499d42011-10-24 18:50:03 +0200881CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200882{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200883 // Check tuning mode
884 if (!checkTuningModeOn(strResult)) {
885
886 return CCommandHandler::EFailed;
887 }
888
889 // Set property
890 bool bSequenceAware;
891
892 if (remoteCommand.getArgument(1) == "true") {
893
894 bSequenceAware = true;
895
896 } else if (remoteCommand.getArgument(1) == "false") {
897
898 bSequenceAware = false;
899
900 } else {
901 // Show usage
902 return CCommandHandler::EShowUsage;
903 }
904
905 return getConfigurableDomains()->setSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200906}
907
Patrick Benavoli63499d42011-10-24 18:50:03 +0200908CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200909{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200910 // Get property
911 bool bSequenceAware;
912
913 if (!getConfigurableDomains()->getSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult)) {
914
915 return CCommandHandler::EFailed;
916 }
917
918 strResult = bSequenceAware ? "true" : "false";
919
920 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200921}
922
Patrick Benavoli63499d42011-10-24 18:50:03 +0200923CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200924{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200925 return getConfigurableDomains()->listDomainElements(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200926}
927
Patrick Benavoli63499d42011-10-24 18:50:03 +0200928CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::addElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200929{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200930 return addConfigurableElementToDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
931}
932
933CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::removeElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
934{
935 return removeConfigurableElementFromDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
936}
937
938CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::splitDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
939{
940 return split(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200941}
942
943/// Configurations
Patrick Benavoli63499d42011-10-24 18:50:03 +0200944CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConfigurationsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200945{
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100946 return getConstConfigurableDomains()->listConfigurations(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
947}
948
949CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
950{
951 (void)remoteCommand;
952
953 // Dummy error context
954 string strError;
955 CErrorContext errorContext(strError);
956
957 // Dump
958 getConstConfigurableDomains()->dumpContent(strResult, errorContext);
959
960 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200961}
962
Patrick Benavoli63499d42011-10-24 18:50:03 +0200963CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200964{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200965 return createConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200966}
967
Patrick Benavoli63499d42011-10-24 18:50:03 +0200968CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200969{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200970 return deleteConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200971}
972
Patrick Benavoli63499d42011-10-24 18:50:03 +0200973CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200974{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200975 return getConfigurableDomains()->renameConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200976}
977
Patrick Benavoli63499d42011-10-24 18:50:03 +0200978CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::saveConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200979{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200980 return saveConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200981}
982
Patrick Benavoli63499d42011-10-24 18:50:03 +0200983CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::restoreConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200984{
Kevin Rocardace81f82012-12-11 16:19:17 +0100985 list<string> lstrResult;
986 if (!restoreConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), lstrResult)) {
987 //Concatenate the error list as the command result
988 CUtility::concatenate(lstrResult, strResult);
989
990 return CCommandHandler::EFailed;
991 }
992 return CCommandHandler::EDone;
Patrick Benavoli63499d42011-10-24 18:50:03 +0200993}
994
995CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
996{
997 // Check tuning mode
998 if (!checkTuningModeOn(strResult)) {
999
1000 return CCommandHandler::EFailed;
1001 }
1002
1003 // Build configurable element path list
1004 vector<string> astrNewElementSequence;
1005
1006 uint32_t uiArgument;
1007
1008 for (uiArgument = 2; uiArgument < remoteCommand.getArgumentCount(); uiArgument++) {
1009
1010 astrNewElementSequence.push_back(remoteCommand.getArgument(uiArgument));
1011 }
1012
1013 // Delegate to configurable domains
1014 return getConfigurableDomains()->setElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), astrNewElementSequence, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1015}
1016
1017CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1018{
1019 // Delegate to configurable domains
1020 return getConfigurableDomains()->getElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001021}
1022
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001023CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1024{
1025 // Delegate to configurable domains
1026 return getConfigurableDomains()->setApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.packArguments(2, remoteCommand.getArgumentCount() - 2), getConstSelectionCriteria()->getSelectionCriteriaDefinition(), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1027}
1028
1029CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::clearRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1030{
1031 // Delegate to configurable domains
1032 return getConfigurableDomains()->clearApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1033}
1034
1035CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1036{
1037 // Delegate to configurable domains
1038 return getConfigurableDomains()->getApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
1039}
1040
Patrick Benavoli68a91282011-08-31 11:23:23 +02001041/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001042CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001043{
1044 CElementLocator elementLocator(getSystemClass(), false);
1045
1046 CElement* pLocatedElement = NULL;
1047
1048 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1049
Patrick Benavoli63499d42011-10-24 18:50:03 +02001050 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001051 }
1052
1053 strResult = string("\n");
1054
1055 if (!pLocatedElement) {
1056
1057 // List from root folder
1058
1059 // Return system class qualified name
1060 pLocatedElement = getSystemClass();
1061 }
1062
1063 // Return sub-elements
1064 strResult += pLocatedElement->listQualifiedPaths(false);
1065
Patrick Benavoli63499d42011-10-24 18:50:03 +02001066 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001067}
1068
1069/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001070CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listParametersCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001071{
1072 CElementLocator elementLocator(getSystemClass(), false);
1073
1074 CElement* pLocatedElement = NULL;
1075
1076 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1077
Patrick Benavoli63499d42011-10-24 18:50:03 +02001078 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001079 }
1080
1081 strResult = string("\n");
1082
1083 if (!pLocatedElement) {
1084
1085 // List from root folder
1086
1087 // Return system class qualified name
1088 pLocatedElement = getSystemClass();
1089 }
1090
1091 // Return sub-elements
1092 strResult += pLocatedElement->listQualifiedPaths(true);
1093
Patrick Benavoli63499d42011-10-24 18:50:03 +02001094 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001095}
1096
Patrick Benavoli63499d42011-10-24 18:50:03 +02001097CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001098{
1099 CElementLocator elementLocator(getSystemClass());
1100
1101 CElement* pLocatedElement = NULL;
1102
1103 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1104
Patrick Benavoli63499d42011-10-24 18:50:03 +02001105 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001106 }
1107
1108 string strError;
1109
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001110 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001111
1112 // Dump elements
1113 pLocatedElement->dumpContent(strResult, parameterAccessContext);
1114
Patrick Benavoli63499d42011-10-24 18:50:03 +02001115 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001116}
1117
Patrick Benavoli63499d42011-10-24 18:50:03 +02001118CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSizeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001119{
1120 CElementLocator elementLocator(getSystemClass());
1121
1122 CElement* pLocatedElement = NULL;
1123
1124 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1125
Patrick Benavoli63499d42011-10-24 18:50:03 +02001126 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001127 }
1128
1129 // Converted to actual sizable element
1130 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1131
1132 // Get size as string
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001133 strResult = pConfigurableElement->getFootprintAsString();
Patrick Benavoli68a91282011-08-31 11:23:23 +02001134
Patrick Benavoli63499d42011-10-24 18:50:03 +02001135 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001136}
1137
Patrick Benavoli63499d42011-10-24 18:50:03 +02001138CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showPropertiesCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001139{
1140 CElementLocator elementLocator(getSystemClass());
1141
1142 CElement* pLocatedElement = NULL;
1143
1144 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1145
Patrick Benavoli63499d42011-10-24 18:50:03 +02001146 return CCommandHandler::EFailed;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001147 }
1148
1149 // Convert element
1150 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1151
1152 // Return element properties
1153 pConfigurableElement->showProperties(strResult);
1154
Patrick Benavoli63499d42011-10-24 18:50:03 +02001155 return CCommandHandler::ESucceeded;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001156}
1157
Patrick Benavoli63499d42011-10-24 18:50:03 +02001158CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001159{
1160 string strValue;
1161
Patrick Benavoli065264a2011-11-20 15:46:41 +01001162 if (!accessValue(remoteCommand.getArgument(0), strValue, false, strResult)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001163
Patrick Benavoli63499d42011-10-24 18:50:03 +02001164 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001165 }
1166 // Succeeded
1167 strResult = strValue;
1168
Patrick Benavoli63499d42011-10-24 18:50:03 +02001169 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001170}
1171
Patrick Benavoli63499d42011-10-24 18:50:03 +02001172CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001173{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001174 // Check tuning mode
1175 if (!checkTuningModeOn(strResult)) {
1176
1177 return CCommandHandler::EFailed;
1178 }
1179 // Get value to set
1180 string strValue = remoteCommand.packArguments(1, remoteCommand.getArgumentCount() - 1);
1181
1182 return accessValue(remoteCommand.getArgument(0), strValue, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001183}
1184
Patrick Benavoli63499d42011-10-24 18:50:03 +02001185CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listBelongingDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001186{
1187 CElementLocator elementLocator(getSystemClass());
1188
1189 CElement* pLocatedElement = NULL;
1190
1191 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1192
Patrick Benavoli63499d42011-10-24 18:50:03 +02001193 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001194 }
1195
1196 // Convert element
1197 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1198
1199 // Return element belonging domains
1200 pConfigurableElement->listBelongingDomains(strResult);
1201
Patrick Benavoli63499d42011-10-24 18:50:03 +02001202 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001203}
1204
Patrick Benavoli63499d42011-10-24 18:50:03 +02001205CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001206{
1207 CElementLocator elementLocator(getSystemClass());
1208
1209 CElement* pLocatedElement = NULL;
1210
1211 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1212
Patrick Benavoli63499d42011-10-24 18:50:03 +02001213 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001214 }
1215
1216 // Convert element
1217 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1218
1219 // Return element belonging domains
1220 pConfigurableElement->listAssociatedDomains(strResult);
1221
Patrick Benavoli63499d42011-10-24 18:50:03 +02001222 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001223}
1224
Patrick Benavoli63499d42011-10-24 18:50:03 +02001225CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001226{
1227 (void)remoteCommand;
1228
1229 getConfigurableDomains()->listAssociatedElements(strResult);
1230
Patrick Benavoli63499d42011-10-24 18:50:03 +02001231 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001232}
1233
Patrick Benavoli63499d42011-10-24 18:50:03 +02001234CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConflictingElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001235{
1236 (void)remoteCommand;
1237
1238 getConfigurableDomains()->listConflictingElements(strResult);
1239
Patrick Benavoli63499d42011-10-24 18:50:03 +02001240 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001241}
1242
Patrick Benavoli63499d42011-10-24 18:50:03 +02001243CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listRogueElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001244{
1245 (void)remoteCommand;
1246
1247 getSystemClass()->listRogueElements(strResult);
1248
Patrick Benavoli63499d42011-10-24 18:50:03 +02001249 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001250}
1251
1252/// Settings Import/Export
Patrick Benavoli63499d42011-10-24 18:50:03 +02001253CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001254{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001255 return exportDomainsXml(remoteCommand.getArgument(0), false, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001256}
1257
Patrick Benavoli63499d42011-10-24 18:50:03 +02001258CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001259{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001260 return importDomainsXml(remoteCommand.getArgument(0), false, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001261}
1262
Patrick Benavoli63499d42011-10-24 18:50:03 +02001263CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001264{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001265 return exportDomainsXml(remoteCommand.getArgument(0), true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001266}
1267
Patrick Benavoli63499d42011-10-24 18:50:03 +02001268CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001269{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001270 return importDomainsXml(remoteCommand.getArgument(0), true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001271}
1272
Patrick Benavoli63499d42011-10-24 18:50:03 +02001273CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001274{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001275 return exportDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001276}
1277
Patrick Benavoli63499d42011-10-24 18:50:03 +02001278CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001279{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001280 return importDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001281}
1282
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001283/// GUI commands
1284
1285CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getDomainsXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1286{
1287 (void)remoteCommand;
1288
1289 if (!getDomainsXMLString(strResult, true)) {
1290
1291 return CCommandHandler::EFailed;
1292 }
1293 // Succeeded
1294 return CCommandHandler::ESucceeded;
1295}
1296
1297CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getSystemClassXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1298{
1299 (void)remoteCommand;
1300
1301 if (!getSystemClassXMLString(strResult)) {
1302
1303 return CCommandHandler::EFailed;
1304 }
1305 // Succeeded
1306 return CCommandHandler::ESucceeded;
1307}
1308
Patrick Benavoli68a91282011-08-31 11:23:23 +02001309// User set/get parameters
Patrick Benavoli065264a2011-11-20 15:46:41 +01001310bool CParameterMgr::accessValue(const string& strPath, string& strValue, bool bSet, string& strError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001311{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001312 // Lock state
1313 CAutoLock autoLock(&_blackboardMutex);
1314
1315 CPathNavigator pathNavigator(strPath);
1316
1317 // Nagivate through system class
1318 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001319
1320 return false;
1321 }
1322
Patrick Benavoli065264a2011-11-20 15:46:41 +01001323 // Define context
1324 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001325
Patrick Benavoli68808c62012-02-02 17:12:41 +01001326 // Auto Sync
1327 if (bSet) {
1328
1329 parameterAccessContext.setAutoSync(_bAutoSyncOn);
1330 }
1331
Patrick Benavoli065264a2011-11-20 15:46:41 +01001332 // Do the get
1333 return getConstSystemClass()->accessValue(pathNavigator, strValue, bSet, parameterAccessContext);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001334}
1335
1336// Tuning mode
1337bool CParameterMgr::setTuningMode(bool bOn, string& strError)
1338{
1339 // Tuning allowed?
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001340 if (bOn && !getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001341
1342 strError = "Tuning prohibited";
1343
1344 return false;
1345 }
1346 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +01001347 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001348
1349 // Warn domains about exiting tuning mode
1350 if (!bOn && _bTuningModeIsOn) {
1351
1352 // Ensure application of currently selected configurations
Patrick Benavoli1387bda2011-08-31 11:23:24 +02001353 // Force-apply configurations
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01001354 doApplyConfigurations(true);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001355
Patrick Benavoli68a91282011-08-31 11:23:23 +02001356 // Turn auto sync back on
1357 _bAutoSyncOn = true;
1358 }
1359
1360 // Store
1361 _bTuningModeIsOn = bOn;
1362
Patrick Benavoli68a91282011-08-31 11:23:23 +02001363 return true;
1364}
1365
1366bool CParameterMgr::tuningModeOn() const
1367{
1368 return _bTuningModeIsOn;
1369}
1370
1371// Current value space for user set/get value interpretation
1372void CParameterMgr::setValueSpace(bool bIsRaw)
1373{
1374 _bValueSpaceIsRaw = bIsRaw;
1375}
1376
1377bool CParameterMgr::valueSpaceIsRaw()
1378{
1379 return _bValueSpaceIsRaw;
1380}
1381
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001382// Current Output Raw Format for user get value interpretation
1383void CParameterMgr::setOutputRawFormat(bool bIsHex)
1384{
1385 _bOutputRawFormatIsHex = bIsHex;
1386}
1387
1388bool CParameterMgr::outputRawFormatIsHex()
1389{
1390 return _bOutputRawFormatIsHex;
1391}
1392
Patrick Benavoli68a91282011-08-31 11:23:23 +02001393/// Sync
1394// Automatic hardware synchronization control (during tuning session)
1395bool CParameterMgr::setAutoSync(bool bAutoSyncOn, string& strError)
1396{
1397 // Check tuning mode
1398 if (!checkTuningModeOn(strError)) {
1399
1400 return false;
1401 }
1402 // Warn domains about turning auto sync back on
1403 if (bAutoSyncOn && !_bAutoSyncOn) {
1404
Patrick Benavoli592ae562011-09-05 16:53:58 +02001405 // Do the synchronization at system class level (could be optimized by keeping track of all modified parameters)
1406 if (!sync(strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001407
1408 return false;
1409 }
1410 }
1411
1412 // Set Auto sync
1413 _bAutoSyncOn = bAutoSyncOn;
1414
1415 return true;
1416}
1417
1418bool CParameterMgr::autoSyncOn() const
1419{
1420 return _bAutoSyncOn;
1421}
1422
1423// Manual hardware synchronization control (during tuning session)
1424bool CParameterMgr::sync(string& strError)
1425{
1426 // Check tuning mode
1427 if (!checkTuningModeOn(strError)) {
1428
1429 return false;
1430 }
1431 // Warn domains about turning auto sync back on
1432 if (_bAutoSyncOn) {
1433
1434 strError = "Feature unavailable when Auto Sync is on";
1435
1436 return false;
1437 }
1438
1439 // Get syncer set
1440 CSyncerSet syncerSet;
1441 // ... from system class
1442 getConstSystemClass()->fillSyncerSet(syncerSet);
Kevin Rocardace81f82012-12-11 16:19:17 +01001443
Patrick Benavoli68a91282011-08-31 11:23:23 +02001444 // Sync
Kevin Rocardace81f82012-12-11 16:19:17 +01001445 list<string> lstrError;
1446 if (! syncerSet.sync(*_pMainParameterBlackboard, false, &lstrError)){
1447
1448 CUtility::concatenate(lstrError, strError);
1449 return false;
1450 };
1451
1452 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001453}
1454
1455// Content dump
1456void CParameterMgr::logStructureContent(string& strContent) const
1457{
1458 string strError;
1459
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001460 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001461
1462 dumpContent(strContent, parameterAccessContext);
1463}
1464
1465// Configuration/Domains handling
1466bool CParameterMgr::createDomain(const string& strName, string& strError)
1467{
1468 // Check tuning mode
1469 if (!checkTuningModeOn(strError)) {
1470
1471 return false;
1472 }
1473
1474 // Delegate to configurable domains
1475 return getConfigurableDomains()->createDomain(strName, strError);
1476}
1477
1478bool CParameterMgr::deleteDomain(const string& strName, string& strError)
1479{
1480 // Check tuning mode
1481 if (!checkTuningModeOn(strError)) {
1482
1483 return false;
1484 }
1485
1486 // Delegate to configurable domains
1487 return getConfigurableDomains()->deleteDomain(strName, strError);
1488}
1489
Kevin Rocard170f0a42012-06-18 13:56:05 +02001490bool CParameterMgr::deleteAllDomains(string& strError)
1491{
1492 // Check tuning mode
1493 if (!checkTuningModeOn(strError)) {
1494
1495 return false;
1496 }
1497
1498 // Delegate to configurable domains
1499 getConfigurableDomains()->deleteAllDomains();
1500
1501 return true;
1502}
1503
Patrick Benavoli68a91282011-08-31 11:23:23 +02001504bool CParameterMgr::createConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1505{
1506 // Check tuning mode
1507 if (!checkTuningModeOn(strError)) {
1508
1509 return false;
1510 }
1511
1512 // Delegate to configurable domains
1513 return getConfigurableDomains()->createConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1514}
1515
1516bool CParameterMgr::deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1517{
1518 // Check tuning mode
1519 if (!checkTuningModeOn(strError)) {
1520
1521 return false;
1522 }
1523
1524 // Delegate to configurable domains
1525 return getConfigurableDomains()->deleteConfiguration(strDomain, strConfiguration, strError);
1526}
1527
Kevin Rocardace81f82012-12-11 16:19:17 +01001528bool CParameterMgr::restoreConfiguration(const string& strDomain, const string& strConfiguration, list<string>& lstrError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001529{
Kevin Rocardace81f82012-12-11 16:19:17 +01001530 string strError;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001531 // Check tuning mode
1532 if (!checkTuningModeOn(strError)) {
1533
Kevin Rocardace81f82012-12-11 16:19:17 +01001534 lstrError.push_back(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001535 return false;
1536 }
1537
1538 // Delegate to configurable domains
Kevin Rocardace81f82012-12-11 16:19:17 +01001539 return getConstConfigurableDomains()->restoreConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, lstrError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001540}
1541
1542bool CParameterMgr::saveConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1543{
1544 // Check tuning mode
1545 if (!checkTuningModeOn(strError)) {
1546
1547 return false;
1548 }
1549
1550 // Delegate to configurable domains
1551 return getConfigurableDomains()->saveConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1552}
1553
1554// Configurable element - domain association
1555bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1556{
1557 // Check tuning mode
1558 if (!checkTuningModeOn(strError)) {
1559
1560 return false;
1561 }
1562
1563 CElementLocator elementLocator(getSystemClass());
1564
1565 CElement* pLocatedElement = NULL;
1566
1567 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1568
1569 return false;
1570 }
1571
1572 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001573 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001574
1575 // Delegate
1576 return getConfigurableDomains()->addConfigurableElementToDomain(strDomain, pConfigurableElement, _pMainParameterBlackboard, strError);
1577}
1578
1579bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1580{
1581 // Check tuning mode
1582 if (!checkTuningModeOn(strError)) {
1583
1584 return false;
1585 }
1586
1587 CElementLocator elementLocator(getSystemClass());
1588
1589 CElement* pLocatedElement = NULL;
1590
1591 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1592
Patrick Benavoli63499d42011-10-24 18:50:03 +02001593 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001594 }
1595
1596 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001597 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001598
1599 // Delegate
1600 return getConfigurableDomains()->removeConfigurableElementFromDomain(strDomain, pConfigurableElement, strError);
1601}
1602
1603bool CParameterMgr::split(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1604{
1605 // Check tuning mode
1606 if (!checkTuningModeOn(strError)) {
1607
1608 return false;
1609 }
1610
1611 CElementLocator elementLocator(getSystemClass());
1612
1613 CElement* pLocatedElement = NULL;
1614
1615 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1616
Patrick Benavoli63499d42011-10-24 18:50:03 +02001617 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001618 }
1619
1620 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001621 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001622
1623 // Delegate
1624 return getConfigurableDomains()->split(strDomain, pConfigurableElement, strError);
1625}
1626
1627// XML Import/Export
1628bool CParameterMgr::importDomainsXml(const string& strFileName, bool bWithSettings, string& strError)
1629{
1630 // Check tuning mode
1631 if (!checkTuningModeOn(strError)) {
1632
1633 return false;
1634 }
1635
1636 // check path is absolute
1637 if (strFileName[0] != '/') {
1638
1639 strError = "Please provide absolute path";
1640
1641 return false;
1642 }
1643 // Root element
1644 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1645
1646 // Context
1647 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1648
1649 // Secltion criteria definition for rule creation
1650 xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
1651
1652 // Parse
1653 if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strFileName, "", EParameterConfigurationLibrary, "SystemClassName")) {
1654
1655 return false;
1656 }
1657
1658 // Validate domains after XML import
1659 pConfigurableDomains->validate(_pMainParameterBlackboard);
1660
1661 return true;
1662}
1663
1664bool CParameterMgr::exportDomainsXml(const string& strFileName, bool bWithSettings, string& strError) const
1665{
1666 // check path is absolute
1667 if (strFileName[0] != '/') {
1668
1669 strError = "Please provide absolute path";
1670
1671 return false;
1672 }
1673
1674 // Root element
1675 const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains();
1676
1677 // Get Schema file associated to root element
1678 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pConfigurableDomains->getKind() + ".xsd";
1679
1680 // Context
1681 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1682
1683 // Value space
1684 xmlDomainSerializingContext.setValueSpaceRaw(_bValueSpaceIsRaw);
1685
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001686 // Output raw format
1687 xmlDomainSerializingContext.setOutputRawFormat(_bOutputRawFormatIsHex);
1688
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001689 // Use a doc source by loading data from instantiated Configurable Domains
1690 CXmlMemoryDocSource memorySource(pConfigurableDomains, pConfigurableDomains->getKind(), strXmlSchemaFilePath, "parameter-framework", getVersion());
Patrick Benavoli68a91282011-08-31 11:23:23 +02001691
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001692 // Use a doc sink to write the doc data in a file
1693 CXmlFileDocSink fileSink(strFileName);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001694
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001695 if (!fileSink.process(memorySource, xmlDomainSerializingContext)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001696 return false;
1697 }
1698
1699 return true;
1700}
1701
1702// Binary Import/Export
1703bool CParameterMgr::importDomainsBinary(const string& strFileName, string& strError)
1704{
1705 // Check tuning mode
1706 if (!checkTuningModeOn(strError)) {
1707
1708 return false;
1709 }
1710 // check path is absolute
1711 if (strFileName[0] != '/') {
1712
1713 strError = "Please provide absolute path";
1714
1715 return false;
1716 }
1717 // Root element
1718 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1719
1720 // Serialize in
1721 return pConfigurableDomains->serializeSettings(strFileName, false, _uiStructureChecksum, strError);
1722}
1723
1724bool CParameterMgr::exportDomainsBinary(const string& strFileName, string& strError)
1725{
1726 // check path is absolute
1727 if (strFileName[0] != '/') {
1728
1729 strError = "Please provide absolute path";
1730
1731 return false;
1732 }
Patrick Benavoli68a91282011-08-31 11:23:23 +02001733
Patrick Benavoli68a91282011-08-31 11:23:23 +02001734 // Root element
1735 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1736
1737 // Serialize out
1738 return pConfigurableDomains->serializeSettings(strFileName, true, _uiStructureChecksum, strError);
1739}
1740
1741// For tuning, check we're in tuning mode
1742bool CParameterMgr::checkTuningModeOn(string& strError) const
1743{
1744 // Tuning Mode on?
1745 if (!_bTuningModeIsOn) {
1746
1747 strError = "Tuning Mode must be on";
1748
1749 return false;
1750 }
1751 return true;
1752}
1753
Patrick Benavoli065264a2011-11-20 15:46:41 +01001754// Tuning mutex dynamic parameter handling
1755pthread_mutex_t* CParameterMgr::getBlackboardMutex()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001756{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001757 return &_blackboardMutex;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001758}
1759
Patrick Benavoli065264a2011-11-20 15:46:41 +01001760// Blackboard reference (dynamic parameter handling)
1761CParameterBlackboard* CParameterMgr::getParameterBlackboard()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001762{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001763 return _pMainParameterBlackboard;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001764}
1765
Patrick Benavoli68a91282011-08-31 11:23:23 +02001766// Dynamic creation library feeding
1767void CParameterMgr::feedElementLibraries()
1768{
1769 // Global Configuration handling
1770 CElementLibrary* pFrameworkConfigurationLibrary = new CElementLibrary;
1771
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001772 pFrameworkConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CParameterFrameworkConfiguration>("ParameterFrameworkConfiguration"));
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +01001773 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CSubsystemPlugins>("SubsystemPlugins"));
1774 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CPluginLocation>("Location"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001775 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("StructureDescriptionFileLocation"));
1776 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationGroup>("SettingsConfiguration"));
1777 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("ConfigurableDomainsFileLocation"));
1778 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("BinarySettingsFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001779
1780 _pElementLibrarySet->addElementLibrary(pFrameworkConfigurationLibrary);
1781
1782 // Parameter creation
1783 CElementLibrary* pParameterCreationLibrary = new CElementLibrary;
1784
1785 pParameterCreationLibrary->addElementBuilder(new CSubsystemElementBuilder(getSystemClass()->getSubsystemLibrary()));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001786 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CComponentType>("ComponentType"));
1787 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CComponentInstance>("Component"));
1788 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBitParameterType>("BitParameter"));
1789 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBitParameterBlockType>("BitParameterBlock"));
Patrick Benavoli1352ae52011-10-21 16:48:04 +02001790 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CStringParameterType>("StringParameter"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001791 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CParameterBlockType>("ParameterBlock"));
1792 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBooleanParameterType>("BooleanParameter"));
1793 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CIntegerParameterType>("IntegerParameter"));
Patrick Benavoliee65e6d2011-11-20 18:52:24 +01001794 pParameterCreationLibrary->addElementBuilder(new TElementBuilderTemplate<CLinearParameterAdaptation>("LinearAdaptation"));
Patrick Benavoli9fc3c0d2011-10-27 14:27:27 +02001795 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CEnumParameterType>("EnumParameter"));
Patrick Benavoli68808c62012-02-02 17:12:41 +01001796 pParameterCreationLibrary->addElementBuilder(new TElementBuilderTemplate<CEnumValuePair>("ValuePair"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001797 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CFixedPointParameterType>("FixedPointParameter"));
1798 pParameterCreationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CXmlFileIncluderElement>("SubsystemInclude"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001799
1800 _pElementLibrarySet->addElementLibrary(pParameterCreationLibrary);
1801
1802 // Parameter Configuration Domains creation
1803 CElementLibrary* pParameterConfigurationLibrary = new CElementLibrary;
1804
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001805 pParameterConfigurationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CConfigurableDomain>("ConfigurableDomain"));
1806 pParameterConfigurationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CDomainConfiguration>("Configuration"));
1807 pParameterConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CCompoundRule>("CompoundRule"));
1808 pParameterConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CSelectionCriterionRule>("SelectionCriterionRule"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001809
1810 _pElementLibrarySet->addElementLibrary(pParameterConfigurationLibrary);
1811}
1812
1813// Remote Processor Server connection handling
1814bool CParameterMgr::handleRemoteProcessingInterface(string& strError)
1815{
1816 CAutoLog autoLog(this, "Handling remote processing interface");
1817
1818 // Start server if tuning allowed
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001819 if (getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001820
Kevin Rocardace81f82012-12-11 16:19:17 +01001821 log_info("Loading remote processor library");
Patrick Benavoli68a91282011-08-31 11:23:23 +02001822
1823 // Load library
1824 void* lib_handle = dlopen("libremote-processor.so", RTLD_NOW);
1825
1826 if (!lib_handle) {
1827
1828 // Return error
1829 const char* pcError = dlerror();
1830
1831 if (pcError) {
1832
1833 strError = pcError;
1834 } else {
1835
1836 strError = "Unable to load libremote-processor.so library";
1837 }
1838
1839 return false;
1840 }
1841
1842 CreateRemoteProcessorServer pfnCreateRemoteProcessorServer = (CreateRemoteProcessorServer)dlsym(lib_handle, "createRemoteProcessorServer");
1843
1844 if (!pfnCreateRemoteProcessorServer) {
1845
1846 strError = "libremote-process.so does not contain createRemoteProcessorServer symbol.";
1847
1848 return false;
1849 }
1850
1851 // Create server
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001852 _pRemoteProcessorServer = pfnCreateRemoteProcessorServer(getConstFrameworkConfiguration()->getServerPort(), _pCommandHandler);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001853
Kevin Rocardace81f82012-12-11 16:19:17 +01001854 log_info("Starting remote processor server on port %d", getConstFrameworkConfiguration()->getServerPort());
Patrick Benavoli68a91282011-08-31 11:23:23 +02001855 // Start
1856 if (!_pRemoteProcessorServer->start()) {
1857
1858 strError = "Unable to start remote processor server";
1859
1860 return false;
1861 }
1862 }
1863
1864 return true;
1865}
1866
1867// Back synchronization
Kevin Rocardace81f82012-12-11 16:19:17 +01001868CBackSynchronizer* CParameterMgr::createBackSynchronizer() const
Patrick Benavoli68a91282011-08-31 11:23:23 +02001869{
1870#ifdef SIMULATION
1871 // In simulation, back synchronization of the blackboard won't probably work
1872 // We need to ensure though the blackboard is initialized with valid data
Kevin Rocardace81f82012-12-11 16:19:17 +01001873 return new CSimulatedBackSynchronizer(getConstSystemClass(), _pMainParameterBlackboard);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001874#else
1875 // Real back synchronizer from subsystems
Kevin Rocardace81f82012-12-11 16:19:17 +01001876 return new CHardwareBackSynchronizer(getConstSystemClass(), _pMainParameterBlackboard);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001877#endif
1878}
1879
1880// Children typwise access
1881CParameterFrameworkConfiguration* CParameterMgr::getFrameworkConfiguration()
1882{
1883 return static_cast<CParameterFrameworkConfiguration*>(getChild(EFrameworkConfiguration));
1884}
1885
1886const CParameterFrameworkConfiguration* CParameterMgr::getConstFrameworkConfiguration()
1887{
1888 return getFrameworkConfiguration();
1889}
1890
1891CSelectionCriteria* CParameterMgr::getSelectionCriteria()
1892{
1893 return static_cast<CSelectionCriteria*>(getChild(ESelectionCriteria));
1894}
1895
1896const CSelectionCriteria* CParameterMgr::getConstSelectionCriteria()
1897{
1898 return static_cast<const CSelectionCriteria*>(getChild(ESelectionCriteria));
1899}
1900
1901CSystemClass* CParameterMgr::getSystemClass()
1902{
1903 return static_cast<CSystemClass*>(getChild(ESystemClass));
1904}
1905
1906const CSystemClass* CParameterMgr::getConstSystemClass() const
1907{
1908 return static_cast<const CSystemClass*>(getChild(ESystemClass));
1909}
1910
1911// Configurable Domains
1912CConfigurableDomains* CParameterMgr::getConfigurableDomains()
1913{
1914 return static_cast<CConfigurableDomains*>(getChild(EConfigurableDomains));
1915}
1916
1917const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains()
1918{
1919 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
1920}
1921
1922const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains() const
1923{
1924 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
1925}
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001926
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01001927// Apply configurations
1928void CParameterMgr::doApplyConfigurations(bool bForce)
1929{
1930 CSyncerSet syncerSet;
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001931
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01001932 // Check subsystems that need resync
1933 getSystemClass()->checkForSubsystemsToResync(syncerSet);
1934
1935 // Ensure application of currently selected configurations
1936 getConfigurableDomains()->apply(_pMainParameterBlackboard, syncerSet, bForce);
1937
1938 // Reset the modified status of the current criteria to indicate that a new configuration has been applied
1939 getSelectionCriteria()->resetModifiedStatus();
1940}
1941
1942/// GUI commands functions
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001943bool CParameterMgr::getDomainsXMLString(string& strResult, bool bWithSettings)
1944{
1945
1946 // Root element
1947 const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains();
1948
1949 // Get Schema file associated to root element
1950 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pConfigurableDomains->getKind() + ".xsd";
1951
1952 string strError;
1953
1954 // Context
1955 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1956
1957 // Value space
1958 xmlDomainSerializingContext.setValueSpaceRaw(_bValueSpaceIsRaw);
1959
1960 // Output raw format
1961 xmlDomainSerializingContext.setOutputRawFormat(_bOutputRawFormatIsHex);
1962
1963 // Use a doc source by loading data from instantiated Configurable Domains
1964 CXmlMemoryDocSource memorySource(pConfigurableDomains, pConfigurableDomains->getKind(), strXmlSchemaFilePath, "parameter-framework", getVersion());
1965
1966 // Use a doc sink the write the doc data in a string
1967 CXmlStringDocSink stringSink(strResult);
1968
1969 if (!stringSink.process(memorySource, xmlDomainSerializingContext)) {
1970 strResult = strError;
1971
1972 return false;
1973 }
1974
1975 return true;
1976}
1977
1978bool CParameterMgr::getSystemClassXMLString(string& strResult)
1979{
1980 // Root element
1981 const CSystemClass* pSystemClass = getSystemClass();
1982
1983 string strError;
1984
1985 CXmlSerializingContext xmlSerializingContext(strError);
1986
1987 // Use a doc source by loading data from instantiated Configurable Domains
1988 CXmlMemoryDocSource memorySource(pSystemClass, pSystemClass->getKind());
1989
1990 // Use a doc sink that write the doc data in a string
1991 CXmlStringDocSink stringSink(strResult);
1992
1993 if (!stringSink.process(memorySource, xmlSerializingContext)) {
1994 strResult = strError;
1995 return false;
1996 }
1997
1998 return true;
1999}