blob: 90d78849f79ce1564b1d45fca10ffcc3f33a30e5 [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
Kevin Rocard5d6e05a2013-01-21 15:57:45 +0100340 pBackSynchronizer->sync();
Kevin Rocard57096bd2012-11-30 11:24:20 +0100341
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200342 // Get rid of back synchronizer
343 delete pBackSynchronizer;
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200344 }
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200345
346 // We're done loading the settings and back synchronizing
347 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
348
349 // We need to ensure all domains are valid
350 pConfigurableDomains->validate(_pMainParameterBlackboard);
351
Kevin Rocard7f265822012-12-07 18:51:22 +0100352 // Log selection criterion states
353 {
354 CAutoLog autoLog(this, "Criterion states");
355
356 const CSelectionCriteria* selectionCriteria = getConstSelectionCriteria();
357
358 list<string> lstrSelectionCriteron;
359 selectionCriteria->listSelectionCriteria(lstrSelectionCriteron, true, false);
360
361 string strSelectionCriteron;
362 CUtility::concatenate(lstrSelectionCriteron, strSelectionCriteron);
363
364 log_info("%s", strSelectionCriteron.c_str());
365 }
366
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100367 // At initialization, check subsystems that need resync
368 doApplyConfigurations(true);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200369
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200370 // Start remote processor server if appropriate
371 return handleRemoteProcessingInterface(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200372}
373
374bool CParameterMgr::loadFrameworkConfiguration(string& strError)
375{
376 CAutoLog autoLog(this, "Loading framework configuration");
377
Patrick Benavoli68a91282011-08-31 11:23:23 +0200378 // Parse Structure XML file
379 CXmlElementSerializingContext elementSerializingContext(strError);
380
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100381 if (!xmlParse(elementSerializingContext, getFrameworkConfiguration(), _strXmlConfigurationFilePath, _strXmlConfigurationFolderPath, EFrameworkConfigurationLibrary)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200382
383 return false;
384 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100385 // Set class name to system class and configurable domains
386 getSystemClass()->setName(getConstFrameworkConfiguration()->getSystemClassName());
387 getConfigurableDomains()->setName(getConstFrameworkConfiguration()->getSystemClassName());
388
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100389 // Get subsystem plugins elements
390 _pSubsystemPlugins = static_cast<const CSubsystemPlugins*>(getConstFrameworkConfiguration()->findChild("SubsystemPlugins"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200391
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100392 if (!_pSubsystemPlugins) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200393
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100394 strError = "Parameter Framework Configuration: couldn't find SubsystemPlugins element";
Patrick Benavoli68a91282011-08-31 11:23:23 +0200395
396 return false;
397 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200398
Patrick Benavoli68a91282011-08-31 11:23:23 +0200399 // Log tuning availability
Kevin Rocardace81f82012-12-11 16:19:17 +0100400 log_info("Tuning %s", getConstFrameworkConfiguration()->isTuningAllowed() ? "allowed" : "prohibited");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200401
402 return true;
403}
404
405bool CParameterMgr::loadStructure(string& strError)
406{
407 // Retrieve system to load structure to
408 CSystemClass* pSystemClass = getSystemClass();
409
410 CAutoLog autoLog(this, "Loading " + pSystemClass->getName() + " system class structure");
411
412 // Get structure description element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100413 const CFrameworkConfigurationLocation* pStructureDescriptionFileLocation = static_cast<const CFrameworkConfigurationLocation*>(getConstFrameworkConfiguration()->findChildOfKind("StructureDescriptionFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200414
415 if (!pStructureDescriptionFileLocation) {
416
417 strError = "No StructureDescriptionFileLocation element found for SystemClass " + pSystemClass->getName();
418
419 return false;
420 }
421
422 // Get Xml structure folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100423 string strXmlStructureFolder = pStructureDescriptionFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200424
425 // Get Xml structure file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100426 string strXmlStructureFilePath = pStructureDescriptionFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200427
428 // Parse Structure XML file
429 CXmlParameterSerializingContext parameterBuildContext(strError);
430
Kevin Rocard57096bd2012-11-30 11:24:20 +0100431 CAutoLog autolog(pSystemClass, "Importing system structure from file " + strXmlStructureFilePath);
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200432
Patrick Benavoli68a91282011-08-31 11:23:23 +0200433 if (!xmlParse(parameterBuildContext, pSystemClass, strXmlStructureFilePath, strXmlStructureFolder, EParameterCreationLibrary)) {
434
435 return false;
436 }
437
438 // Initialize offsets
439 pSystemClass->setOffset(0);
440
441 // Initialize main blackboard's size
442 _pMainParameterBlackboard->setSize(pSystemClass->getFootPrint());
443
444 return true;
445}
446
447bool CParameterMgr::loadSettings(string& strError)
448{
449 CAutoLog autoLog(this, "Loading settings");
450
451 // Get settings configuration element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100452 const CFrameworkConfigurationGroup* pParameterConfigurationGroup = static_cast<const CFrameworkConfigurationGroup*>(getConstFrameworkConfiguration()->findChildOfKind("SettingsConfiguration"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200453
454 if (!pParameterConfigurationGroup) {
455
456 // No settings to load
457
458 return true;
459 }
460 // Get binary settings file location
461 const CFrameworkConfigurationLocation* pBinarySettingsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("BinarySettingsFileLocation"));
462
463 string strXmlBinarySettingsFilePath;
464
465 if (pBinarySettingsFileLocation) {
466
467 // Get Xml binary settings file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100468 strXmlBinarySettingsFilePath = pBinarySettingsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200469 }
470
471 // Get configurable domains element
472 const CFrameworkConfigurationLocation* pConfigurableDomainsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("ConfigurableDomainsFileLocation"));
473
474 if (!pConfigurableDomainsFileLocation) {
475
476 strError = "No ConfigurableDomainsFileLocation element found for SystemClass " + getSystemClass()->getName();
477
478 return false;
479 }
480 // Get destination root element
481 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
482
483 // Get Xml configuration domains file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100484 string strXmlConfigurationDomainsFilePath = pConfigurableDomainsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200485
486 // Get Xml configuration domains folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100487 string strXmlConfigurationDomainsFolder = pConfigurableDomainsFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200488
489 // Parse configuration domains XML file (ask to read settings from XML file if they are not provided as binary)
490 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, !pBinarySettingsFileLocation);
491
492 // Selection criteria definition for rule creation
493 xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
494
Patrick Benavoli63499d42011-10-24 18:50:03 +0200495 // Auto validation of configurations if no binary settings provided
496 xmlDomainSerializingContext.setAutoValidationRequired(!pBinarySettingsFileLocation);
497
Kevin Rocardace81f82012-12-11 16:19:17 +0100498 log_info("Importing configurable domains from file %s %s settings", strXmlConfigurationDomainsFilePath.c_str(), pBinarySettingsFileLocation ? "without" : "with");
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200499
Patrick Benavoli68a91282011-08-31 11:23:23 +0200500 // Do parse
501 if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strXmlConfigurationDomainsFilePath, strXmlConfigurationDomainsFolder, EParameterConfigurationLibrary, "SystemClassName")) {
502
503 return false;
504 }
505 // We have loaded the whole system structure, compute checksum
506 const CSystemClass* pSystemClass = getConstSystemClass();
507 _uiStructureChecksum = pSystemClass->computeStructureChecksum() + getConfigurableDomains()->computeStructureChecksum() + getSelectionCriteria()->computeStructureChecksum();
508
509 // Load binary settings if any provided
510 if (pBinarySettingsFileLocation && !pConfigurableDomains->serializeSettings(strXmlBinarySettingsFilePath, false, _uiStructureChecksum, strError)) {
511
512 return false;
513 }
514
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200515 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200516}
517
518// XML parsing
519bool CParameterMgr::xmlParse(CXmlElementSerializingContext& elementSerializingContext, CElement* pRootElement, const string& strXmlFilePath, const string& strXmlFolder, CParameterMgr::ElementLibrary eElementLibrary, const string& strNameAttrituteName)
520{
521 // Init serializing context
522 elementSerializingContext.set(_pElementLibrarySet->getElementLibrary(eElementLibrary), strXmlFolder, _strSchemaFolderLocation);
523
524 // Get Schema file associated to root element
525 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pRootElement->getKind() + ".xsd";
526
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200527 CXmlFileDocSource fileDocSource(strXmlFilePath, strXmlSchemaFilePath, pRootElement->getKind(), pRootElement->getName(), strNameAttrituteName);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200528
529 // Start clean
530 pRootElement->clean();
531
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200532 CXmlMemoryDocSink memorySink(pRootElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200533
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200534 if (!memorySink.process(fileDocSource, elementSerializingContext)) {
535 //Cleanup
Patrick Benavoli68a91282011-08-31 11:23:23 +0200536 pRootElement->clean();
537
538 return false;
539 }
540
Patrick Benavoli68a91282011-08-31 11:23:23 +0200541 return true;
542}
543
544// Init
545bool CParameterMgr::init(string& strError)
546{
547 return base::init(strError);
548}
549
550// Selection criteria interface
551CSelectionCriterionType* CParameterMgr::createSelectionCriterionType(bool bIsInclusive)
552{
553 // Propagate
554 return getSelectionCriteria()->createSelectionCriterionType(bIsInclusive);
555}
556
557CSelectionCriterion* CParameterMgr::createSelectionCriterion(const string& strName, const CSelectionCriterionType* pSelectionCriterionType)
558{
559 // Propagate
560 return getSelectionCriteria()->createSelectionCriterion(strName, pSelectionCriterionType);
561}
562
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200563// Selection criterion retrieval
564CSelectionCriterion* CParameterMgr::getSelectionCriterion(const string& strName)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200565{
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200566 // Propagate
567 return getSelectionCriteria()->getSelectionCriterion(strName);
568}
569
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100570// Configuration application
Kevin Rocardace81f82012-12-11 16:19:17 +0100571void CParameterMgr::applyConfigurations()
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200572{
573 CAutoLog autoLog(this, "Configuration application request");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200574
575 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +0100576 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200577
578 if (!_bTuningModeIsOn) {
579
580 // Apply configuration(s)
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100581 doApplyConfigurations(false);
Frédéric Boisnarddaaa63c2012-08-27 15:48:15 +0200582 } else {
583
Kevin Rocardace81f82012-12-11 16:19:17 +0100584 log_warning("Configurations were not applied because the TuningMode is on");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200585 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200586}
587
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200588// Dynamic parameter handling
Patrick Benavoli065264a2011-11-20 15:46:41 +0100589CParameterHandle* CParameterMgr::createParameterHandle(const string& strPath, string& strError)
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200590{
Patrick Benavoli065264a2011-11-20 15:46:41 +0100591 CPathNavigator pathNavigator(strPath);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200592
Patrick Benavoli065264a2011-11-20 15:46:41 +0100593 // Nagivate through system class
594 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
595
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100596 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100597 }
598
599 // Find element
600 const CElement* pElement = getConstSystemClass()->findDescendant(pathNavigator);
601
602 if (!pElement) {
603
604 strError = "Path not found";
605
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100606 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100607 }
608
609 // Check found element is a parameter
610 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pElement);
611
612 if (!pConfigurableElement->isParameter()) {
613
614 // Element is not parameter
615 strError = "Not a parameter";
616
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100617 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100618 }
619
620 // Convert as parameter and return new handle
621 return new CParameterHandle(static_cast<const CBaseParameter*>(pElement), this);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200622}
623
Patrick Benavoli68a91282011-08-31 11:23:23 +0200624/////////////////// Remote command parsers
Patrick Benavoli592ae562011-09-05 16:53:58 +0200625/// Version
Patrick Benavoli63499d42011-10-24 18:50:03 +0200626CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::versionCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli592ae562011-09-05 16:53:58 +0200627{
628 (void)remoteCommand;
629
Patrick Benavoli63499d42011-10-24 18:50:03 +0200630 // Show version
631 strResult = getVersion();
Patrick Benavoli592ae562011-09-05 16:53:58 +0200632
Patrick Benavoli63499d42011-10-24 18:50:03 +0200633 return CCommandHandler::ESucceeded;
Patrick Benavoli592ae562011-09-05 16:53:58 +0200634}
635
Patrick Benavoli68a91282011-08-31 11:23:23 +0200636/// Status
Patrick Benavoli63499d42011-10-24 18:50:03 +0200637CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::statusCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200638{
639 (void)remoteCommand;
640 // System class
641 const CSystemClass* pSystemClass = getSystemClass();
642
Patrick Benavoli68a91282011-08-31 11:23:23 +0200643 // Show status
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200644 /// General section
645 appendTitle(strResult, "General:");
646 // System class
Patrick Benavoli68a91282011-08-31 11:23:23 +0200647 strResult += "System Class: ";
648 strResult += pSystemClass->getName();
649 strResult += "\n";
650
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200651 // Tuning mode
Patrick Benavoli68a91282011-08-31 11:23:23 +0200652 strResult += "Tuning Mode: ";
653 strResult += tuningModeOn() ? "on" : "off";
654 strResult += "\n";
655
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200656 // Value space
Patrick Benavoli68a91282011-08-31 11:23:23 +0200657 strResult += "Value Space: ";
658 strResult += valueSpaceIsRaw() ? "raw" : "real";
659 strResult += "\n";
660
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200661 // Output raw format
662 strResult += "Output Raw Format: ";
663 strResult += outputRawFormatIsHex() ? "hex" : "dec";
664 strResult += "\n";
665
666 // Auto Sync
Patrick Benavoli68a91282011-08-31 11:23:23 +0200667 strResult += "Auto Sync: ";
668 strResult += autoSyncOn() ? "on" : "off";
669 strResult += "\n";
670
671 /// Subsystem list
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200672 appendTitle(strResult, "Subsystems:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200673 string strSubsystemList;
674 pSystemClass->listChildrenPaths(strSubsystemList);
675 strResult += strSubsystemList;
676
677 /// Last applied configurations
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200678 appendTitle(strResult, "Last Applied [Pending] Configurations:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200679 string strLastAppliedConfigurations;
680 getConfigurableDomains()->listLastAppliedConfigurations(strLastAppliedConfigurations);
681 strResult += strLastAppliedConfigurations;
682
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200683 /// Criteria states
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200684 appendTitle(strResult, "Selection Criteria:");
Kevin Rocard7f265822012-12-07 18:51:22 +0100685 list<string> lstrSelectionCriteria;
686 getSelectionCriteria()->listSelectionCriteria(lstrSelectionCriteria, false, true);
687 // Concatenate the criterion list as the command result
688 CUtility::concatenate(lstrSelectionCriteria, strResult);
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200689
Patrick Benavoli63499d42011-10-24 18:50:03 +0200690 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200691}
692
693/// Tuning Mode
Patrick Benavoli63499d42011-10-24 18:50:03 +0200694CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200695{
696 if (remoteCommand.getArgument(0) == "on") {
697
698 if (setTuningMode(true, strResult)) {
699
Patrick Benavoli63499d42011-10-24 18:50:03 +0200700 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200701 }
702 } else if (remoteCommand.getArgument(0) == "off") {
703
704 if (setTuningMode(false, strResult)) {
705
Patrick Benavoli63499d42011-10-24 18:50:03 +0200706 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200707 }
708 } else {
709 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200710 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200711 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200712 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200713}
714
Patrick Benavoli63499d42011-10-24 18:50:03 +0200715CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200716{
717 (void)remoteCommand;
718
719 strResult = tuningModeOn() ? "on" : "off";
720
Patrick Benavoli63499d42011-10-24 18:50:03 +0200721 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200722}
723
724/// Value Space
Patrick Benavoli63499d42011-10-24 18:50:03 +0200725CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200726{
727 (void)strResult;
728
729 if (remoteCommand.getArgument(0) == "raw") {
730
731 setValueSpace(true);
732
Patrick Benavoli63499d42011-10-24 18:50:03 +0200733 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200734
735 } else if (remoteCommand.getArgument(0) == "real") {
736
737 setValueSpace(false);
738
Patrick Benavoli63499d42011-10-24 18:50:03 +0200739 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200740
741 } else {
742 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200743 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200744 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200745 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200746}
747
Patrick Benavoli63499d42011-10-24 18:50:03 +0200748CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200749{
750 (void)remoteCommand;
751
752 strResult = valueSpaceIsRaw() ? "raw" : "real";
753
Patrick Benavoli63499d42011-10-24 18:50:03 +0200754 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200755}
756
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200757/// Output Raw Format
Patrick Benavoli63499d42011-10-24 18:50:03 +0200758CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200759{
760 (void)strResult;
761
762 if (remoteCommand.getArgument(0) == "hex") {
763
764 setOutputRawFormat(true);
765
Patrick Benavoli63499d42011-10-24 18:50:03 +0200766 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200767
768 } else if (remoteCommand.getArgument(0) == "dec") {
769
770 setOutputRawFormat(false);
771
Patrick Benavoli63499d42011-10-24 18:50:03 +0200772 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200773
774 } else {
775 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200776 return CCommandHandler::EShowUsage;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200777 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200778 return CCommandHandler::EFailed;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200779}
780
Patrick Benavoli63499d42011-10-24 18:50:03 +0200781CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200782{
783 (void)remoteCommand;
784
785 strResult = outputRawFormatIsHex() ? "hex" : "dec";
786
Patrick Benavoli63499d42011-10-24 18:50:03 +0200787 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200788}
789
Patrick Benavoli68a91282011-08-31 11:23:23 +0200790/// Sync
Patrick Benavoli63499d42011-10-24 18:50:03 +0200791CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200792{
793 if (remoteCommand.getArgument(0) == "on") {
794
795 if (setAutoSync(true, strResult)) {
796
Patrick Benavoli63499d42011-10-24 18:50:03 +0200797 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200798 }
799 } else if (remoteCommand.getArgument(0) == "off") {
800
801 if (setAutoSync(false, strResult)) {
802
Patrick Benavoli63499d42011-10-24 18:50:03 +0200803 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200804 }
805 } else {
806 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200807 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200808 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200809 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200810}
811
Patrick Benavoli63499d42011-10-24 18:50:03 +0200812CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200813{
814 (void)remoteCommand;
815
816 strResult = autoSyncOn() ? "on" : "off";
817
Patrick Benavoli63499d42011-10-24 18:50:03 +0200818 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200819}
820
Patrick Benavoli63499d42011-10-24 18:50:03 +0200821CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::syncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200822{
823 (void)remoteCommand;
824
Patrick Benavoli63499d42011-10-24 18:50:03 +0200825 return sync(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200826}
827
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200828/// Criteria
Patrick Benavoli63499d42011-10-24 18:50:03 +0200829CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listCriteriaCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200830{
831 (void)remoteCommand;
832
Kevin Rocard7f265822012-12-07 18:51:22 +0100833 list<string> lstrResult;
834
835 getSelectionCriteria()->listSelectionCriteria(lstrResult, true, true);
836
837 // Concatenate the criterion list as the command result
838 CUtility::concatenate(lstrResult, strResult);
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200839
Patrick Benavoli63499d42011-10-24 18:50:03 +0200840 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200841}
Patrick Benavoli68a91282011-08-31 11:23:23 +0200842
843/// Domains
Patrick Benavoli63499d42011-10-24 18:50:03 +0200844CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200845{
846 (void)remoteCommand;
847
Patrick Benavoli63499d42011-10-24 18:50:03 +0200848 getConfigurableDomains()->listDomains(strResult);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200849
Patrick Benavoli63499d42011-10-24 18:50:03 +0200850 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200851}
852
Patrick Benavoli63499d42011-10-24 18:50:03 +0200853CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200854{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200855 return createDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200856}
857
Patrick Benavoli63499d42011-10-24 18:50:03 +0200858CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200859{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200860 return deleteDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200861}
862
Kevin Rocard170f0a42012-06-18 13:56:05 +0200863CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteAllDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
864{
865 (void)remoteCommand;
866
867 return deleteAllDomains(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
868}
869
Patrick Benavoli63499d42011-10-24 18:50:03 +0200870CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200871{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200872 return getConfigurableDomains()->renameDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200873}
874
Patrick Benavoli63499d42011-10-24 18:50:03 +0200875CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200876{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200877 // Check tuning mode
878 if (!checkTuningModeOn(strResult)) {
879
880 return CCommandHandler::EFailed;
881 }
882
883 // Set property
884 bool bSequenceAware;
885
886 if (remoteCommand.getArgument(1) == "true") {
887
888 bSequenceAware = true;
889
890 } else if (remoteCommand.getArgument(1) == "false") {
891
892 bSequenceAware = false;
893
894 } else {
895 // Show usage
896 return CCommandHandler::EShowUsage;
897 }
898
899 return getConfigurableDomains()->setSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200900}
901
Patrick Benavoli63499d42011-10-24 18:50:03 +0200902CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200903{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200904 // Get property
905 bool bSequenceAware;
906
907 if (!getConfigurableDomains()->getSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult)) {
908
909 return CCommandHandler::EFailed;
910 }
911
912 strResult = bSequenceAware ? "true" : "false";
913
914 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200915}
916
Patrick Benavoli63499d42011-10-24 18:50:03 +0200917CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200918{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200919 return getConfigurableDomains()->listDomainElements(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200920}
921
Patrick Benavoli63499d42011-10-24 18:50:03 +0200922CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::addElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200923{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200924 return addConfigurableElementToDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
925}
926
927CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::removeElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
928{
929 return removeConfigurableElementFromDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
930}
931
932CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::splitDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
933{
934 return split(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200935}
936
937/// Configurations
Patrick Benavoli63499d42011-10-24 18:50:03 +0200938CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConfigurationsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200939{
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100940 return getConstConfigurableDomains()->listConfigurations(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
941}
942
943CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
944{
945 (void)remoteCommand;
946
947 // Dummy error context
948 string strError;
949 CErrorContext errorContext(strError);
950
951 // Dump
952 getConstConfigurableDomains()->dumpContent(strResult, errorContext);
953
954 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200955}
956
Patrick Benavoli63499d42011-10-24 18:50:03 +0200957CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200958{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200959 return createConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200960}
961
Patrick Benavoli63499d42011-10-24 18:50:03 +0200962CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200963{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200964 return deleteConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200965}
966
Patrick Benavoli63499d42011-10-24 18:50:03 +0200967CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200968{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200969 return getConfigurableDomains()->renameConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200970}
971
Patrick Benavoli63499d42011-10-24 18:50:03 +0200972CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::saveConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200973{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200974 return saveConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200975}
976
Patrick Benavoli63499d42011-10-24 18:50:03 +0200977CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::restoreConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200978{
Kevin Rocardace81f82012-12-11 16:19:17 +0100979 list<string> lstrResult;
980 if (!restoreConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), lstrResult)) {
981 //Concatenate the error list as the command result
982 CUtility::concatenate(lstrResult, strResult);
983
984 return CCommandHandler::EFailed;
985 }
986 return CCommandHandler::EDone;
Patrick Benavoli63499d42011-10-24 18:50:03 +0200987}
988
989CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
990{
991 // Check tuning mode
992 if (!checkTuningModeOn(strResult)) {
993
994 return CCommandHandler::EFailed;
995 }
996
997 // Build configurable element path list
998 vector<string> astrNewElementSequence;
999
1000 uint32_t uiArgument;
1001
1002 for (uiArgument = 2; uiArgument < remoteCommand.getArgumentCount(); uiArgument++) {
1003
1004 astrNewElementSequence.push_back(remoteCommand.getArgument(uiArgument));
1005 }
1006
1007 // Delegate to configurable domains
1008 return getConfigurableDomains()->setElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), astrNewElementSequence, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1009}
1010
1011CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1012{
1013 // Delegate to configurable domains
1014 return getConfigurableDomains()->getElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001015}
1016
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001017CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1018{
1019 // Delegate to configurable domains
1020 return getConfigurableDomains()->setApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.packArguments(2, remoteCommand.getArgumentCount() - 2), getConstSelectionCriteria()->getSelectionCriteriaDefinition(), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1021}
1022
1023CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::clearRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1024{
1025 // Delegate to configurable domains
1026 return getConfigurableDomains()->clearApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1027}
1028
1029CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1030{
1031 // Delegate to configurable domains
1032 return getConfigurableDomains()->getApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
1033}
1034
Patrick Benavoli68a91282011-08-31 11:23:23 +02001035/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001036CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001037{
1038 CElementLocator elementLocator(getSystemClass(), false);
1039
1040 CElement* pLocatedElement = NULL;
1041
1042 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1043
Patrick Benavoli63499d42011-10-24 18:50:03 +02001044 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001045 }
1046
1047 strResult = string("\n");
1048
1049 if (!pLocatedElement) {
1050
1051 // List from root folder
1052
1053 // Return system class qualified name
1054 pLocatedElement = getSystemClass();
1055 }
1056
1057 // Return sub-elements
1058 strResult += pLocatedElement->listQualifiedPaths(false);
1059
Patrick Benavoli63499d42011-10-24 18:50:03 +02001060 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001061}
1062
1063/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001064CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listParametersCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001065{
1066 CElementLocator elementLocator(getSystemClass(), false);
1067
1068 CElement* pLocatedElement = NULL;
1069
1070 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1071
Patrick Benavoli63499d42011-10-24 18:50:03 +02001072 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001073 }
1074
1075 strResult = string("\n");
1076
1077 if (!pLocatedElement) {
1078
1079 // List from root folder
1080
1081 // Return system class qualified name
1082 pLocatedElement = getSystemClass();
1083 }
1084
1085 // Return sub-elements
1086 strResult += pLocatedElement->listQualifiedPaths(true);
1087
Patrick Benavoli63499d42011-10-24 18:50:03 +02001088 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001089}
1090
Patrick Benavoli63499d42011-10-24 18:50:03 +02001091CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001092{
1093 CElementLocator elementLocator(getSystemClass());
1094
1095 CElement* pLocatedElement = NULL;
1096
1097 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1098
Patrick Benavoli63499d42011-10-24 18:50:03 +02001099 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001100 }
1101
1102 string strError;
1103
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001104 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001105
1106 // Dump elements
1107 pLocatedElement->dumpContent(strResult, parameterAccessContext);
1108
Patrick Benavoli63499d42011-10-24 18:50:03 +02001109 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001110}
1111
Patrick Benavoli63499d42011-10-24 18:50:03 +02001112CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSizeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001113{
1114 CElementLocator elementLocator(getSystemClass());
1115
1116 CElement* pLocatedElement = NULL;
1117
1118 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1119
Patrick Benavoli63499d42011-10-24 18:50:03 +02001120 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001121 }
1122
1123 // Converted to actual sizable element
1124 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1125
1126 // Get size as string
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001127 strResult = pConfigurableElement->getFootprintAsString();
Patrick Benavoli68a91282011-08-31 11:23:23 +02001128
Patrick Benavoli63499d42011-10-24 18:50:03 +02001129 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001130}
1131
Patrick Benavoli63499d42011-10-24 18:50:03 +02001132CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showPropertiesCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001133{
1134 CElementLocator elementLocator(getSystemClass());
1135
1136 CElement* pLocatedElement = NULL;
1137
1138 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1139
Patrick Benavoli63499d42011-10-24 18:50:03 +02001140 return CCommandHandler::EFailed;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001141 }
1142
1143 // Convert element
1144 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1145
1146 // Return element properties
1147 pConfigurableElement->showProperties(strResult);
1148
Patrick Benavoli63499d42011-10-24 18:50:03 +02001149 return CCommandHandler::ESucceeded;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001150}
1151
Patrick Benavoli63499d42011-10-24 18:50:03 +02001152CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001153{
1154 string strValue;
1155
Patrick Benavoli065264a2011-11-20 15:46:41 +01001156 if (!accessValue(remoteCommand.getArgument(0), strValue, false, strResult)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001157
Patrick Benavoli63499d42011-10-24 18:50:03 +02001158 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001159 }
1160 // Succeeded
1161 strResult = strValue;
1162
Patrick Benavoli63499d42011-10-24 18:50:03 +02001163 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001164}
1165
Patrick Benavoli63499d42011-10-24 18:50:03 +02001166CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001167{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001168 // Check tuning mode
1169 if (!checkTuningModeOn(strResult)) {
1170
1171 return CCommandHandler::EFailed;
1172 }
1173 // Get value to set
1174 string strValue = remoteCommand.packArguments(1, remoteCommand.getArgumentCount() - 1);
1175
1176 return accessValue(remoteCommand.getArgument(0), strValue, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001177}
1178
Patrick Benavoli63499d42011-10-24 18:50:03 +02001179CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listBelongingDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001180{
1181 CElementLocator elementLocator(getSystemClass());
1182
1183 CElement* pLocatedElement = NULL;
1184
1185 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1186
Patrick Benavoli63499d42011-10-24 18:50:03 +02001187 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001188 }
1189
1190 // Convert element
1191 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1192
1193 // Return element belonging domains
1194 pConfigurableElement->listBelongingDomains(strResult);
1195
Patrick Benavoli63499d42011-10-24 18:50:03 +02001196 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001197}
1198
Patrick Benavoli63499d42011-10-24 18:50:03 +02001199CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001200{
1201 CElementLocator elementLocator(getSystemClass());
1202
1203 CElement* pLocatedElement = NULL;
1204
1205 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1206
Patrick Benavoli63499d42011-10-24 18:50:03 +02001207 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001208 }
1209
1210 // Convert element
1211 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1212
1213 // Return element belonging domains
1214 pConfigurableElement->listAssociatedDomains(strResult);
1215
Patrick Benavoli63499d42011-10-24 18:50:03 +02001216 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001217}
1218
Patrick Benavoli63499d42011-10-24 18:50:03 +02001219CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001220{
1221 (void)remoteCommand;
1222
1223 getConfigurableDomains()->listAssociatedElements(strResult);
1224
Patrick Benavoli63499d42011-10-24 18:50:03 +02001225 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001226}
1227
Patrick Benavoli63499d42011-10-24 18:50:03 +02001228CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConflictingElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001229{
1230 (void)remoteCommand;
1231
1232 getConfigurableDomains()->listConflictingElements(strResult);
1233
Patrick Benavoli63499d42011-10-24 18:50:03 +02001234 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001235}
1236
Patrick Benavoli63499d42011-10-24 18:50:03 +02001237CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listRogueElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001238{
1239 (void)remoteCommand;
1240
1241 getSystemClass()->listRogueElements(strResult);
1242
Patrick Benavoli63499d42011-10-24 18:50:03 +02001243 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001244}
1245
1246/// Settings Import/Export
Patrick Benavoli63499d42011-10-24 18:50:03 +02001247CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001248{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001249 return exportDomainsXml(remoteCommand.getArgument(0), false, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001250}
1251
Patrick Benavoli63499d42011-10-24 18:50:03 +02001252CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001253{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001254 return importDomainsXml(remoteCommand.getArgument(0), false, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001255}
1256
Patrick Benavoli63499d42011-10-24 18:50:03 +02001257CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001258{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001259 return exportDomainsXml(remoteCommand.getArgument(0), true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001260}
1261
Patrick Benavoli63499d42011-10-24 18:50:03 +02001262CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001263{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001264 return importDomainsXml(remoteCommand.getArgument(0), true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001265}
1266
Patrick Benavoli63499d42011-10-24 18:50:03 +02001267CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001268{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001269 return exportDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001270}
1271
Patrick Benavoli63499d42011-10-24 18:50:03 +02001272CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001273{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001274 return importDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001275}
1276
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001277/// GUI commands
1278
1279CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getDomainsXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1280{
1281 (void)remoteCommand;
1282
1283 if (!getDomainsXMLString(strResult, true)) {
1284
1285 return CCommandHandler::EFailed;
1286 }
1287 // Succeeded
1288 return CCommandHandler::ESucceeded;
1289}
1290
1291CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getSystemClassXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1292{
1293 (void)remoteCommand;
1294
1295 if (!getSystemClassXMLString(strResult)) {
1296
1297 return CCommandHandler::EFailed;
1298 }
1299 // Succeeded
1300 return CCommandHandler::ESucceeded;
1301}
1302
Patrick Benavoli68a91282011-08-31 11:23:23 +02001303// User set/get parameters
Patrick Benavoli065264a2011-11-20 15:46:41 +01001304bool CParameterMgr::accessValue(const string& strPath, string& strValue, bool bSet, string& strError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001305{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001306 // Lock state
1307 CAutoLock autoLock(&_blackboardMutex);
1308
1309 CPathNavigator pathNavigator(strPath);
1310
1311 // Nagivate through system class
1312 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001313
1314 return false;
1315 }
1316
Patrick Benavoli065264a2011-11-20 15:46:41 +01001317 // Define context
1318 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001319
Patrick Benavoli68808c62012-02-02 17:12:41 +01001320 // Auto Sync
1321 if (bSet) {
1322
1323 parameterAccessContext.setAutoSync(_bAutoSyncOn);
1324 }
1325
Patrick Benavoli065264a2011-11-20 15:46:41 +01001326 // Do the get
1327 return getConstSystemClass()->accessValue(pathNavigator, strValue, bSet, parameterAccessContext);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001328}
1329
1330// Tuning mode
1331bool CParameterMgr::setTuningMode(bool bOn, string& strError)
1332{
1333 // Tuning allowed?
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001334 if (bOn && !getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001335
1336 strError = "Tuning prohibited";
1337
1338 return false;
1339 }
1340 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +01001341 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001342
1343 // Warn domains about exiting tuning mode
1344 if (!bOn && _bTuningModeIsOn) {
1345
1346 // Ensure application of currently selected configurations
Patrick Benavoli1387bda2011-08-31 11:23:24 +02001347 // Force-apply configurations
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01001348 doApplyConfigurations(true);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001349
Patrick Benavoli68a91282011-08-31 11:23:23 +02001350 // Turn auto sync back on
1351 _bAutoSyncOn = true;
1352 }
1353
1354 // Store
1355 _bTuningModeIsOn = bOn;
1356
Patrick Benavoli68a91282011-08-31 11:23:23 +02001357 return true;
1358}
1359
1360bool CParameterMgr::tuningModeOn() const
1361{
1362 return _bTuningModeIsOn;
1363}
1364
1365// Current value space for user set/get value interpretation
1366void CParameterMgr::setValueSpace(bool bIsRaw)
1367{
1368 _bValueSpaceIsRaw = bIsRaw;
1369}
1370
1371bool CParameterMgr::valueSpaceIsRaw()
1372{
1373 return _bValueSpaceIsRaw;
1374}
1375
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001376// Current Output Raw Format for user get value interpretation
1377void CParameterMgr::setOutputRawFormat(bool bIsHex)
1378{
1379 _bOutputRawFormatIsHex = bIsHex;
1380}
1381
1382bool CParameterMgr::outputRawFormatIsHex()
1383{
1384 return _bOutputRawFormatIsHex;
1385}
1386
Patrick Benavoli68a91282011-08-31 11:23:23 +02001387/// Sync
1388// Automatic hardware synchronization control (during tuning session)
1389bool CParameterMgr::setAutoSync(bool bAutoSyncOn, string& strError)
1390{
1391 // Check tuning mode
1392 if (!checkTuningModeOn(strError)) {
1393
1394 return false;
1395 }
1396 // Warn domains about turning auto sync back on
1397 if (bAutoSyncOn && !_bAutoSyncOn) {
1398
Patrick Benavoli592ae562011-09-05 16:53:58 +02001399 // Do the synchronization at system class level (could be optimized by keeping track of all modified parameters)
1400 if (!sync(strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001401
1402 return false;
1403 }
1404 }
1405
1406 // Set Auto sync
1407 _bAutoSyncOn = bAutoSyncOn;
1408
1409 return true;
1410}
1411
1412bool CParameterMgr::autoSyncOn() const
1413{
1414 return _bAutoSyncOn;
1415}
1416
1417// Manual hardware synchronization control (during tuning session)
1418bool CParameterMgr::sync(string& strError)
1419{
1420 // Check tuning mode
1421 if (!checkTuningModeOn(strError)) {
1422
1423 return false;
1424 }
1425 // Warn domains about turning auto sync back on
1426 if (_bAutoSyncOn) {
1427
1428 strError = "Feature unavailable when Auto Sync is on";
1429
1430 return false;
1431 }
1432
1433 // Get syncer set
1434 CSyncerSet syncerSet;
1435 // ... from system class
1436 getConstSystemClass()->fillSyncerSet(syncerSet);
Kevin Rocardace81f82012-12-11 16:19:17 +01001437
Patrick Benavoli68a91282011-08-31 11:23:23 +02001438 // Sync
Kevin Rocardace81f82012-12-11 16:19:17 +01001439 list<string> lstrError;
1440 if (! syncerSet.sync(*_pMainParameterBlackboard, false, &lstrError)){
1441
1442 CUtility::concatenate(lstrError, strError);
1443 return false;
1444 };
1445
1446 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001447}
1448
1449// Content dump
1450void CParameterMgr::logStructureContent(string& strContent) const
1451{
1452 string strError;
1453
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001454 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001455
1456 dumpContent(strContent, parameterAccessContext);
1457}
1458
1459// Configuration/Domains handling
1460bool CParameterMgr::createDomain(const string& strName, string& strError)
1461{
1462 // Check tuning mode
1463 if (!checkTuningModeOn(strError)) {
1464
1465 return false;
1466 }
1467
1468 // Delegate to configurable domains
1469 return getConfigurableDomains()->createDomain(strName, strError);
1470}
1471
1472bool CParameterMgr::deleteDomain(const string& strName, string& strError)
1473{
1474 // Check tuning mode
1475 if (!checkTuningModeOn(strError)) {
1476
1477 return false;
1478 }
1479
1480 // Delegate to configurable domains
1481 return getConfigurableDomains()->deleteDomain(strName, strError);
1482}
1483
Kevin Rocard170f0a42012-06-18 13:56:05 +02001484bool CParameterMgr::deleteAllDomains(string& strError)
1485{
1486 // Check tuning mode
1487 if (!checkTuningModeOn(strError)) {
1488
1489 return false;
1490 }
1491
1492 // Delegate to configurable domains
1493 getConfigurableDomains()->deleteAllDomains();
1494
1495 return true;
1496}
1497
Patrick Benavoli68a91282011-08-31 11:23:23 +02001498bool CParameterMgr::createConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1499{
1500 // Check tuning mode
1501 if (!checkTuningModeOn(strError)) {
1502
1503 return false;
1504 }
1505
1506 // Delegate to configurable domains
1507 return getConfigurableDomains()->createConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1508}
1509
1510bool CParameterMgr::deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1511{
1512 // Check tuning mode
1513 if (!checkTuningModeOn(strError)) {
1514
1515 return false;
1516 }
1517
1518 // Delegate to configurable domains
1519 return getConfigurableDomains()->deleteConfiguration(strDomain, strConfiguration, strError);
1520}
1521
Kevin Rocardace81f82012-12-11 16:19:17 +01001522bool CParameterMgr::restoreConfiguration(const string& strDomain, const string& strConfiguration, list<string>& lstrError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001523{
Kevin Rocardace81f82012-12-11 16:19:17 +01001524 string strError;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001525 // Check tuning mode
1526 if (!checkTuningModeOn(strError)) {
1527
Kevin Rocardace81f82012-12-11 16:19:17 +01001528 lstrError.push_back(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001529 return false;
1530 }
1531
1532 // Delegate to configurable domains
Kevin Rocardace81f82012-12-11 16:19:17 +01001533 return getConstConfigurableDomains()->restoreConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, lstrError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001534}
1535
1536bool CParameterMgr::saveConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1537{
1538 // Check tuning mode
1539 if (!checkTuningModeOn(strError)) {
1540
1541 return false;
1542 }
1543
1544 // Delegate to configurable domains
1545 return getConfigurableDomains()->saveConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1546}
1547
1548// Configurable element - domain association
1549bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1550{
1551 // Check tuning mode
1552 if (!checkTuningModeOn(strError)) {
1553
1554 return false;
1555 }
1556
1557 CElementLocator elementLocator(getSystemClass());
1558
1559 CElement* pLocatedElement = NULL;
1560
1561 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1562
1563 return false;
1564 }
1565
1566 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001567 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001568
1569 // Delegate
1570 return getConfigurableDomains()->addConfigurableElementToDomain(strDomain, pConfigurableElement, _pMainParameterBlackboard, strError);
1571}
1572
1573bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1574{
1575 // Check tuning mode
1576 if (!checkTuningModeOn(strError)) {
1577
1578 return false;
1579 }
1580
1581 CElementLocator elementLocator(getSystemClass());
1582
1583 CElement* pLocatedElement = NULL;
1584
1585 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1586
Patrick Benavoli63499d42011-10-24 18:50:03 +02001587 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001588 }
1589
1590 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001591 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001592
1593 // Delegate
1594 return getConfigurableDomains()->removeConfigurableElementFromDomain(strDomain, pConfigurableElement, strError);
1595}
1596
1597bool CParameterMgr::split(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1598{
1599 // Check tuning mode
1600 if (!checkTuningModeOn(strError)) {
1601
1602 return false;
1603 }
1604
1605 CElementLocator elementLocator(getSystemClass());
1606
1607 CElement* pLocatedElement = NULL;
1608
1609 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1610
Patrick Benavoli63499d42011-10-24 18:50:03 +02001611 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001612 }
1613
1614 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001615 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001616
1617 // Delegate
1618 return getConfigurableDomains()->split(strDomain, pConfigurableElement, strError);
1619}
1620
1621// XML Import/Export
1622bool CParameterMgr::importDomainsXml(const string& strFileName, bool bWithSettings, string& strError)
1623{
1624 // Check tuning mode
1625 if (!checkTuningModeOn(strError)) {
1626
1627 return false;
1628 }
1629
1630 // check path is absolute
1631 if (strFileName[0] != '/') {
1632
1633 strError = "Please provide absolute path";
1634
1635 return false;
1636 }
1637 // Root element
1638 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1639
1640 // Context
1641 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1642
1643 // Secltion criteria definition for rule creation
1644 xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
1645
1646 // Parse
1647 if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strFileName, "", EParameterConfigurationLibrary, "SystemClassName")) {
1648
1649 return false;
1650 }
1651
1652 // Validate domains after XML import
1653 pConfigurableDomains->validate(_pMainParameterBlackboard);
1654
1655 return true;
1656}
1657
1658bool CParameterMgr::exportDomainsXml(const string& strFileName, bool bWithSettings, string& strError) const
1659{
1660 // check path is absolute
1661 if (strFileName[0] != '/') {
1662
1663 strError = "Please provide absolute path";
1664
1665 return false;
1666 }
1667
1668 // Root element
1669 const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains();
1670
1671 // Get Schema file associated to root element
1672 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pConfigurableDomains->getKind() + ".xsd";
1673
1674 // Context
1675 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1676
1677 // Value space
1678 xmlDomainSerializingContext.setValueSpaceRaw(_bValueSpaceIsRaw);
1679
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001680 // Output raw format
1681 xmlDomainSerializingContext.setOutputRawFormat(_bOutputRawFormatIsHex);
1682
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001683 // Use a doc source by loading data from instantiated Configurable Domains
1684 CXmlMemoryDocSource memorySource(pConfigurableDomains, pConfigurableDomains->getKind(), strXmlSchemaFilePath, "parameter-framework", getVersion());
Patrick Benavoli68a91282011-08-31 11:23:23 +02001685
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001686 // Use a doc sink to write the doc data in a file
1687 CXmlFileDocSink fileSink(strFileName);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001688
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001689 if (!fileSink.process(memorySource, xmlDomainSerializingContext)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001690 return false;
1691 }
1692
1693 return true;
1694}
1695
1696// Binary Import/Export
1697bool CParameterMgr::importDomainsBinary(const string& strFileName, string& strError)
1698{
1699 // Check tuning mode
1700 if (!checkTuningModeOn(strError)) {
1701
1702 return false;
1703 }
1704 // check path is absolute
1705 if (strFileName[0] != '/') {
1706
1707 strError = "Please provide absolute path";
1708
1709 return false;
1710 }
1711 // Root element
1712 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1713
1714 // Serialize in
1715 return pConfigurableDomains->serializeSettings(strFileName, false, _uiStructureChecksum, strError);
1716}
1717
1718bool CParameterMgr::exportDomainsBinary(const string& strFileName, string& strError)
1719{
1720 // check path is absolute
1721 if (strFileName[0] != '/') {
1722
1723 strError = "Please provide absolute path";
1724
1725 return false;
1726 }
Patrick Benavoli68a91282011-08-31 11:23:23 +02001727
Patrick Benavoli68a91282011-08-31 11:23:23 +02001728 // Root element
1729 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1730
1731 // Serialize out
1732 return pConfigurableDomains->serializeSettings(strFileName, true, _uiStructureChecksum, strError);
1733}
1734
1735// For tuning, check we're in tuning mode
1736bool CParameterMgr::checkTuningModeOn(string& strError) const
1737{
1738 // Tuning Mode on?
1739 if (!_bTuningModeIsOn) {
1740
1741 strError = "Tuning Mode must be on";
1742
1743 return false;
1744 }
1745 return true;
1746}
1747
Patrick Benavoli065264a2011-11-20 15:46:41 +01001748// Tuning mutex dynamic parameter handling
1749pthread_mutex_t* CParameterMgr::getBlackboardMutex()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001750{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001751 return &_blackboardMutex;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001752}
1753
Patrick Benavoli065264a2011-11-20 15:46:41 +01001754// Blackboard reference (dynamic parameter handling)
1755CParameterBlackboard* CParameterMgr::getParameterBlackboard()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001756{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001757 return _pMainParameterBlackboard;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001758}
1759
Patrick Benavoli68a91282011-08-31 11:23:23 +02001760// Dynamic creation library feeding
1761void CParameterMgr::feedElementLibraries()
1762{
1763 // Global Configuration handling
1764 CElementLibrary* pFrameworkConfigurationLibrary = new CElementLibrary;
1765
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001766 pFrameworkConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CParameterFrameworkConfiguration>("ParameterFrameworkConfiguration"));
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +01001767 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CSubsystemPlugins>("SubsystemPlugins"));
1768 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CPluginLocation>("Location"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001769 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("StructureDescriptionFileLocation"));
1770 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationGroup>("SettingsConfiguration"));
1771 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("ConfigurableDomainsFileLocation"));
1772 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("BinarySettingsFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001773
1774 _pElementLibrarySet->addElementLibrary(pFrameworkConfigurationLibrary);
1775
1776 // Parameter creation
1777 CElementLibrary* pParameterCreationLibrary = new CElementLibrary;
1778
1779 pParameterCreationLibrary->addElementBuilder(new CSubsystemElementBuilder(getSystemClass()->getSubsystemLibrary()));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001780 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CComponentType>("ComponentType"));
1781 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CComponentInstance>("Component"));
1782 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBitParameterType>("BitParameter"));
1783 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBitParameterBlockType>("BitParameterBlock"));
Patrick Benavoli1352ae52011-10-21 16:48:04 +02001784 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CStringParameterType>("StringParameter"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001785 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CParameterBlockType>("ParameterBlock"));
1786 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBooleanParameterType>("BooleanParameter"));
1787 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CIntegerParameterType>("IntegerParameter"));
Patrick Benavoliee65e6d2011-11-20 18:52:24 +01001788 pParameterCreationLibrary->addElementBuilder(new TElementBuilderTemplate<CLinearParameterAdaptation>("LinearAdaptation"));
Patrick Benavoli9fc3c0d2011-10-27 14:27:27 +02001789 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CEnumParameterType>("EnumParameter"));
Patrick Benavoli68808c62012-02-02 17:12:41 +01001790 pParameterCreationLibrary->addElementBuilder(new TElementBuilderTemplate<CEnumValuePair>("ValuePair"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001791 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CFixedPointParameterType>("FixedPointParameter"));
1792 pParameterCreationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CXmlFileIncluderElement>("SubsystemInclude"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001793
1794 _pElementLibrarySet->addElementLibrary(pParameterCreationLibrary);
1795
1796 // Parameter Configuration Domains creation
1797 CElementLibrary* pParameterConfigurationLibrary = new CElementLibrary;
1798
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001799 pParameterConfigurationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CConfigurableDomain>("ConfigurableDomain"));
1800 pParameterConfigurationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CDomainConfiguration>("Configuration"));
1801 pParameterConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CCompoundRule>("CompoundRule"));
1802 pParameterConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CSelectionCriterionRule>("SelectionCriterionRule"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001803
1804 _pElementLibrarySet->addElementLibrary(pParameterConfigurationLibrary);
1805}
1806
1807// Remote Processor Server connection handling
1808bool CParameterMgr::handleRemoteProcessingInterface(string& strError)
1809{
1810 CAutoLog autoLog(this, "Handling remote processing interface");
1811
1812 // Start server if tuning allowed
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001813 if (getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001814
Kevin Rocardace81f82012-12-11 16:19:17 +01001815 log_info("Loading remote processor library");
Patrick Benavoli68a91282011-08-31 11:23:23 +02001816
1817 // Load library
1818 void* lib_handle = dlopen("libremote-processor.so", RTLD_NOW);
1819
1820 if (!lib_handle) {
1821
1822 // Return error
1823 const char* pcError = dlerror();
1824
1825 if (pcError) {
1826
1827 strError = pcError;
1828 } else {
1829
1830 strError = "Unable to load libremote-processor.so library";
1831 }
1832
1833 return false;
1834 }
1835
1836 CreateRemoteProcessorServer pfnCreateRemoteProcessorServer = (CreateRemoteProcessorServer)dlsym(lib_handle, "createRemoteProcessorServer");
1837
1838 if (!pfnCreateRemoteProcessorServer) {
1839
1840 strError = "libremote-process.so does not contain createRemoteProcessorServer symbol.";
1841
1842 return false;
1843 }
1844
1845 // Create server
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001846 _pRemoteProcessorServer = pfnCreateRemoteProcessorServer(getConstFrameworkConfiguration()->getServerPort(), _pCommandHandler);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001847
Kevin Rocardace81f82012-12-11 16:19:17 +01001848 log_info("Starting remote processor server on port %d", getConstFrameworkConfiguration()->getServerPort());
Patrick Benavoli68a91282011-08-31 11:23:23 +02001849 // Start
1850 if (!_pRemoteProcessorServer->start()) {
1851
1852 strError = "Unable to start remote processor server";
1853
1854 return false;
1855 }
1856 }
1857
1858 return true;
1859}
1860
1861// Back synchronization
Kevin Rocardace81f82012-12-11 16:19:17 +01001862CBackSynchronizer* CParameterMgr::createBackSynchronizer() const
Patrick Benavoli68a91282011-08-31 11:23:23 +02001863{
1864#ifdef SIMULATION
1865 // In simulation, back synchronization of the blackboard won't probably work
1866 // We need to ensure though the blackboard is initialized with valid data
Kevin Rocardace81f82012-12-11 16:19:17 +01001867 return new CSimulatedBackSynchronizer(getConstSystemClass(), _pMainParameterBlackboard);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001868#else
1869 // Real back synchronizer from subsystems
Kevin Rocardace81f82012-12-11 16:19:17 +01001870 return new CHardwareBackSynchronizer(getConstSystemClass(), _pMainParameterBlackboard);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001871#endif
1872}
1873
1874// Children typwise access
1875CParameterFrameworkConfiguration* CParameterMgr::getFrameworkConfiguration()
1876{
1877 return static_cast<CParameterFrameworkConfiguration*>(getChild(EFrameworkConfiguration));
1878}
1879
1880const CParameterFrameworkConfiguration* CParameterMgr::getConstFrameworkConfiguration()
1881{
1882 return getFrameworkConfiguration();
1883}
1884
1885CSelectionCriteria* CParameterMgr::getSelectionCriteria()
1886{
1887 return static_cast<CSelectionCriteria*>(getChild(ESelectionCriteria));
1888}
1889
1890const CSelectionCriteria* CParameterMgr::getConstSelectionCriteria()
1891{
1892 return static_cast<const CSelectionCriteria*>(getChild(ESelectionCriteria));
1893}
1894
1895CSystemClass* CParameterMgr::getSystemClass()
1896{
1897 return static_cast<CSystemClass*>(getChild(ESystemClass));
1898}
1899
1900const CSystemClass* CParameterMgr::getConstSystemClass() const
1901{
1902 return static_cast<const CSystemClass*>(getChild(ESystemClass));
1903}
1904
1905// Configurable Domains
1906CConfigurableDomains* CParameterMgr::getConfigurableDomains()
1907{
1908 return static_cast<CConfigurableDomains*>(getChild(EConfigurableDomains));
1909}
1910
1911const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains()
1912{
1913 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
1914}
1915
1916const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains() const
1917{
1918 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
1919}
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001920
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01001921// Apply configurations
1922void CParameterMgr::doApplyConfigurations(bool bForce)
1923{
1924 CSyncerSet syncerSet;
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001925
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01001926 // Check subsystems that need resync
1927 getSystemClass()->checkForSubsystemsToResync(syncerSet);
1928
1929 // Ensure application of currently selected configurations
1930 getConfigurableDomains()->apply(_pMainParameterBlackboard, syncerSet, bForce);
1931
1932 // Reset the modified status of the current criteria to indicate that a new configuration has been applied
1933 getSelectionCriteria()->resetModifiedStatus();
1934}
1935
1936/// GUI commands functions
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001937bool CParameterMgr::getDomainsXMLString(string& strResult, bool bWithSettings)
1938{
1939
1940 // Root element
1941 const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains();
1942
1943 // Get Schema file associated to root element
1944 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pConfigurableDomains->getKind() + ".xsd";
1945
1946 string strError;
1947
1948 // Context
1949 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1950
1951 // Value space
1952 xmlDomainSerializingContext.setValueSpaceRaw(_bValueSpaceIsRaw);
1953
1954 // Output raw format
1955 xmlDomainSerializingContext.setOutputRawFormat(_bOutputRawFormatIsHex);
1956
1957 // Use a doc source by loading data from instantiated Configurable Domains
1958 CXmlMemoryDocSource memorySource(pConfigurableDomains, pConfigurableDomains->getKind(), strXmlSchemaFilePath, "parameter-framework", getVersion());
1959
1960 // Use a doc sink the write the doc data in a string
1961 CXmlStringDocSink stringSink(strResult);
1962
1963 if (!stringSink.process(memorySource, xmlDomainSerializingContext)) {
1964 strResult = strError;
1965
1966 return false;
1967 }
1968
1969 return true;
1970}
1971
1972bool CParameterMgr::getSystemClassXMLString(string& strResult)
1973{
1974 // Root element
1975 const CSystemClass* pSystemClass = getSystemClass();
1976
1977 string strError;
1978
1979 CXmlSerializingContext xmlSerializingContext(strError);
1980
1981 // Use a doc source by loading data from instantiated Configurable Domains
1982 CXmlMemoryDocSource memorySource(pSystemClass, pSystemClass->getKind());
1983
1984 // Use a doc sink that write the doc data in a string
1985 CXmlStringDocSink stringSink(strResult);
1986
1987 if (!stringSink.process(memorySource, xmlSerializingContext)) {
1988 strResult = strError;
1989 return false;
1990 }
1991
1992 return true;
1993}