blob: b5b968372fb314180c5ca196aa87fd62366ac3d4 [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
Kevin Rocard36299362013-02-04 14:57:47 +0100361 log_table(false, lstrSelectionCriteron);
Kevin Rocard7f265822012-12-07 18:51:22 +0100362 }
363
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100364 // At initialization, check subsystems that need resync
365 doApplyConfigurations(true);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200366
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200367 // Start remote processor server if appropriate
368 return handleRemoteProcessingInterface(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200369}
370
371bool CParameterMgr::loadFrameworkConfiguration(string& strError)
372{
373 CAutoLog autoLog(this, "Loading framework configuration");
374
Patrick Benavoli68a91282011-08-31 11:23:23 +0200375 // Parse Structure XML file
376 CXmlElementSerializingContext elementSerializingContext(strError);
377
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100378 if (!xmlParse(elementSerializingContext, getFrameworkConfiguration(), _strXmlConfigurationFilePath, _strXmlConfigurationFolderPath, EFrameworkConfigurationLibrary)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200379
380 return false;
381 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100382 // Set class name to system class and configurable domains
383 getSystemClass()->setName(getConstFrameworkConfiguration()->getSystemClassName());
384 getConfigurableDomains()->setName(getConstFrameworkConfiguration()->getSystemClassName());
385
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100386 // Get subsystem plugins elements
387 _pSubsystemPlugins = static_cast<const CSubsystemPlugins*>(getConstFrameworkConfiguration()->findChild("SubsystemPlugins"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200388
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100389 if (!_pSubsystemPlugins) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200390
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100391 strError = "Parameter Framework Configuration: couldn't find SubsystemPlugins element";
Patrick Benavoli68a91282011-08-31 11:23:23 +0200392
393 return false;
394 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200395
Patrick Benavoli68a91282011-08-31 11:23:23 +0200396 // Log tuning availability
Kevin Rocardace81f82012-12-11 16:19:17 +0100397 log_info("Tuning %s", getConstFrameworkConfiguration()->isTuningAllowed() ? "allowed" : "prohibited");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200398
399 return true;
400}
401
402bool CParameterMgr::loadStructure(string& strError)
403{
404 // Retrieve system to load structure to
405 CSystemClass* pSystemClass = getSystemClass();
406
407 CAutoLog autoLog(this, "Loading " + pSystemClass->getName() + " system class structure");
408
409 // Get structure description element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100410 const CFrameworkConfigurationLocation* pStructureDescriptionFileLocation = static_cast<const CFrameworkConfigurationLocation*>(getConstFrameworkConfiguration()->findChildOfKind("StructureDescriptionFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200411
412 if (!pStructureDescriptionFileLocation) {
413
414 strError = "No StructureDescriptionFileLocation element found for SystemClass " + pSystemClass->getName();
415
416 return false;
417 }
418
419 // Get Xml structure folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100420 string strXmlStructureFolder = pStructureDescriptionFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200421
422 // Get Xml structure file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100423 string strXmlStructureFilePath = pStructureDescriptionFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200424
425 // Parse Structure XML file
426 CXmlParameterSerializingContext parameterBuildContext(strError);
427
Kevin Rocard57096bd2012-11-30 11:24:20 +0100428 CAutoLog autolog(pSystemClass, "Importing system structure from file " + strXmlStructureFilePath);
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200429
Patrick Benavoli68a91282011-08-31 11:23:23 +0200430 if (!xmlParse(parameterBuildContext, pSystemClass, strXmlStructureFilePath, strXmlStructureFolder, EParameterCreationLibrary)) {
431
432 return false;
433 }
434
435 // Initialize offsets
436 pSystemClass->setOffset(0);
437
438 // Initialize main blackboard's size
439 _pMainParameterBlackboard->setSize(pSystemClass->getFootPrint());
440
441 return true;
442}
443
444bool CParameterMgr::loadSettings(string& strError)
445{
446 CAutoLog autoLog(this, "Loading settings");
447
448 // Get settings configuration element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100449 const CFrameworkConfigurationGroup* pParameterConfigurationGroup = static_cast<const CFrameworkConfigurationGroup*>(getConstFrameworkConfiguration()->findChildOfKind("SettingsConfiguration"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200450
451 if (!pParameterConfigurationGroup) {
452
453 // No settings to load
454
455 return true;
456 }
457 // Get binary settings file location
458 const CFrameworkConfigurationLocation* pBinarySettingsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("BinarySettingsFileLocation"));
459
460 string strXmlBinarySettingsFilePath;
461
462 if (pBinarySettingsFileLocation) {
463
464 // Get Xml binary settings file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100465 strXmlBinarySettingsFilePath = pBinarySettingsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200466 }
467
468 // Get configurable domains element
469 const CFrameworkConfigurationLocation* pConfigurableDomainsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("ConfigurableDomainsFileLocation"));
470
471 if (!pConfigurableDomainsFileLocation) {
472
473 strError = "No ConfigurableDomainsFileLocation element found for SystemClass " + getSystemClass()->getName();
474
475 return false;
476 }
477 // Get destination root element
478 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
479
480 // Get Xml configuration domains file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100481 string strXmlConfigurationDomainsFilePath = pConfigurableDomainsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200482
483 // Get Xml configuration domains folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100484 string strXmlConfigurationDomainsFolder = pConfigurableDomainsFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200485
486 // Parse configuration domains XML file (ask to read settings from XML file if they are not provided as binary)
487 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, !pBinarySettingsFileLocation);
488
489 // Selection criteria definition for rule creation
490 xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
491
Patrick Benavoli63499d42011-10-24 18:50:03 +0200492 // Auto validation of configurations if no binary settings provided
493 xmlDomainSerializingContext.setAutoValidationRequired(!pBinarySettingsFileLocation);
494
Kevin Rocardace81f82012-12-11 16:19:17 +0100495 log_info("Importing configurable domains from file %s %s settings", strXmlConfigurationDomainsFilePath.c_str(), pBinarySettingsFileLocation ? "without" : "with");
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200496
Patrick Benavoli68a91282011-08-31 11:23:23 +0200497 // Do parse
498 if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strXmlConfigurationDomainsFilePath, strXmlConfigurationDomainsFolder, EParameterConfigurationLibrary, "SystemClassName")) {
499
500 return false;
501 }
502 // We have loaded the whole system structure, compute checksum
503 const CSystemClass* pSystemClass = getConstSystemClass();
504 _uiStructureChecksum = pSystemClass->computeStructureChecksum() + getConfigurableDomains()->computeStructureChecksum() + getSelectionCriteria()->computeStructureChecksum();
505
506 // Load binary settings if any provided
507 if (pBinarySettingsFileLocation && !pConfigurableDomains->serializeSettings(strXmlBinarySettingsFilePath, false, _uiStructureChecksum, strError)) {
508
509 return false;
510 }
511
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200512 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200513}
514
515// XML parsing
516bool CParameterMgr::xmlParse(CXmlElementSerializingContext& elementSerializingContext, CElement* pRootElement, const string& strXmlFilePath, const string& strXmlFolder, CParameterMgr::ElementLibrary eElementLibrary, const string& strNameAttrituteName)
517{
518 // Init serializing context
519 elementSerializingContext.set(_pElementLibrarySet->getElementLibrary(eElementLibrary), strXmlFolder, _strSchemaFolderLocation);
520
521 // Get Schema file associated to root element
522 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pRootElement->getKind() + ".xsd";
523
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200524 CXmlFileDocSource fileDocSource(strXmlFilePath, strXmlSchemaFilePath, pRootElement->getKind(), pRootElement->getName(), strNameAttrituteName);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200525
526 // Start clean
527 pRootElement->clean();
528
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200529 CXmlMemoryDocSink memorySink(pRootElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200530
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200531 if (!memorySink.process(fileDocSource, elementSerializingContext)) {
532 //Cleanup
Patrick Benavoli68a91282011-08-31 11:23:23 +0200533 pRootElement->clean();
534
535 return false;
536 }
537
Patrick Benavoli68a91282011-08-31 11:23:23 +0200538 return true;
539}
540
541// Init
542bool CParameterMgr::init(string& strError)
543{
544 return base::init(strError);
545}
546
547// Selection criteria interface
548CSelectionCriterionType* CParameterMgr::createSelectionCriterionType(bool bIsInclusive)
549{
550 // Propagate
551 return getSelectionCriteria()->createSelectionCriterionType(bIsInclusive);
552}
553
554CSelectionCriterion* CParameterMgr::createSelectionCriterion(const string& strName, const CSelectionCriterionType* pSelectionCriterionType)
555{
556 // Propagate
557 return getSelectionCriteria()->createSelectionCriterion(strName, pSelectionCriterionType);
558}
559
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200560// Selection criterion retrieval
561CSelectionCriterion* CParameterMgr::getSelectionCriterion(const string& strName)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200562{
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200563 // Propagate
564 return getSelectionCriteria()->getSelectionCriterion(strName);
565}
566
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100567// Configuration application
Kevin Rocardace81f82012-12-11 16:19:17 +0100568void CParameterMgr::applyConfigurations()
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200569{
570 CAutoLog autoLog(this, "Configuration application request");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200571
572 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +0100573 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200574
575 if (!_bTuningModeIsOn) {
576
577 // Apply configuration(s)
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100578 doApplyConfigurations(false);
Frédéric Boisnarddaaa63c2012-08-27 15:48:15 +0200579 } else {
580
Kevin Rocardace81f82012-12-11 16:19:17 +0100581 log_warning("Configurations were not applied because the TuningMode is on");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200582 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200583}
584
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200585// Dynamic parameter handling
Patrick Benavoli065264a2011-11-20 15:46:41 +0100586CParameterHandle* CParameterMgr::createParameterHandle(const string& strPath, string& strError)
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200587{
Patrick Benavoli065264a2011-11-20 15:46:41 +0100588 CPathNavigator pathNavigator(strPath);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200589
Patrick Benavoli065264a2011-11-20 15:46:41 +0100590 // Nagivate through system class
591 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
592
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100593 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100594 }
595
596 // Find element
597 const CElement* pElement = getConstSystemClass()->findDescendant(pathNavigator);
598
599 if (!pElement) {
600
601 strError = "Path not found";
602
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100603 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100604 }
605
606 // Check found element is a parameter
607 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pElement);
608
609 if (!pConfigurableElement->isParameter()) {
610
611 // Element is not parameter
612 strError = "Not a parameter";
613
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100614 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100615 }
616
617 // Convert as parameter and return new handle
618 return new CParameterHandle(static_cast<const CBaseParameter*>(pElement), this);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200619}
620
Patrick Benavoli68a91282011-08-31 11:23:23 +0200621/////////////////// Remote command parsers
Patrick Benavoli592ae562011-09-05 16:53:58 +0200622/// Version
Patrick Benavoli63499d42011-10-24 18:50:03 +0200623CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::versionCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli592ae562011-09-05 16:53:58 +0200624{
625 (void)remoteCommand;
626
Patrick Benavoli63499d42011-10-24 18:50:03 +0200627 // Show version
628 strResult = getVersion();
Patrick Benavoli592ae562011-09-05 16:53:58 +0200629
Patrick Benavoli63499d42011-10-24 18:50:03 +0200630 return CCommandHandler::ESucceeded;
Patrick Benavoli592ae562011-09-05 16:53:58 +0200631}
632
Patrick Benavoli68a91282011-08-31 11:23:23 +0200633/// Status
Patrick Benavoli63499d42011-10-24 18:50:03 +0200634CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::statusCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200635{
636 (void)remoteCommand;
637 // System class
638 const CSystemClass* pSystemClass = getSystemClass();
639
Patrick Benavoli68a91282011-08-31 11:23:23 +0200640 // Show status
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200641 /// General section
642 appendTitle(strResult, "General:");
643 // System class
Patrick Benavoli68a91282011-08-31 11:23:23 +0200644 strResult += "System Class: ";
645 strResult += pSystemClass->getName();
646 strResult += "\n";
647
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200648 // Tuning mode
Patrick Benavoli68a91282011-08-31 11:23:23 +0200649 strResult += "Tuning Mode: ";
650 strResult += tuningModeOn() ? "on" : "off";
651 strResult += "\n";
652
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200653 // Value space
Patrick Benavoli68a91282011-08-31 11:23:23 +0200654 strResult += "Value Space: ";
655 strResult += valueSpaceIsRaw() ? "raw" : "real";
656 strResult += "\n";
657
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200658 // Output raw format
659 strResult += "Output Raw Format: ";
660 strResult += outputRawFormatIsHex() ? "hex" : "dec";
661 strResult += "\n";
662
663 // Auto Sync
Patrick Benavoli68a91282011-08-31 11:23:23 +0200664 strResult += "Auto Sync: ";
665 strResult += autoSyncOn() ? "on" : "off";
666 strResult += "\n";
667
668 /// Subsystem list
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200669 appendTitle(strResult, "Subsystems:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200670 string strSubsystemList;
671 pSystemClass->listChildrenPaths(strSubsystemList);
672 strResult += strSubsystemList;
673
674 /// Last applied configurations
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200675 appendTitle(strResult, "Last Applied [Pending] Configurations:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200676 string strLastAppliedConfigurations;
677 getConfigurableDomains()->listLastAppliedConfigurations(strLastAppliedConfigurations);
678 strResult += strLastAppliedConfigurations;
679
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200680 /// Criteria states
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200681 appendTitle(strResult, "Selection Criteria:");
Kevin Rocard7f265822012-12-07 18:51:22 +0100682 list<string> lstrSelectionCriteria;
683 getSelectionCriteria()->listSelectionCriteria(lstrSelectionCriteria, false, true);
684 // Concatenate the criterion list as the command result
685 CUtility::concatenate(lstrSelectionCriteria, strResult);
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200686
Patrick Benavoli63499d42011-10-24 18:50:03 +0200687 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200688}
689
690/// Tuning Mode
Patrick Benavoli63499d42011-10-24 18:50:03 +0200691CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200692{
693 if (remoteCommand.getArgument(0) == "on") {
694
695 if (setTuningMode(true, strResult)) {
696
Patrick Benavoli63499d42011-10-24 18:50:03 +0200697 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200698 }
699 } else if (remoteCommand.getArgument(0) == "off") {
700
701 if (setTuningMode(false, strResult)) {
702
Patrick Benavoli63499d42011-10-24 18:50:03 +0200703 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200704 }
705 } else {
706 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200707 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200708 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200709 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200710}
711
Patrick Benavoli63499d42011-10-24 18:50:03 +0200712CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200713{
714 (void)remoteCommand;
715
716 strResult = tuningModeOn() ? "on" : "off";
717
Patrick Benavoli63499d42011-10-24 18:50:03 +0200718 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200719}
720
721/// Value Space
Patrick Benavoli63499d42011-10-24 18:50:03 +0200722CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200723{
724 (void)strResult;
725
726 if (remoteCommand.getArgument(0) == "raw") {
727
728 setValueSpace(true);
729
Patrick Benavoli63499d42011-10-24 18:50:03 +0200730 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200731
732 } else if (remoteCommand.getArgument(0) == "real") {
733
734 setValueSpace(false);
735
Patrick Benavoli63499d42011-10-24 18:50:03 +0200736 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200737
738 } else {
739 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200740 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200741 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200742 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200743}
744
Patrick Benavoli63499d42011-10-24 18:50:03 +0200745CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200746{
747 (void)remoteCommand;
748
749 strResult = valueSpaceIsRaw() ? "raw" : "real";
750
Patrick Benavoli63499d42011-10-24 18:50:03 +0200751 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200752}
753
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200754/// Output Raw Format
Patrick Benavoli63499d42011-10-24 18:50:03 +0200755CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200756{
757 (void)strResult;
758
759 if (remoteCommand.getArgument(0) == "hex") {
760
761 setOutputRawFormat(true);
762
Patrick Benavoli63499d42011-10-24 18:50:03 +0200763 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200764
765 } else if (remoteCommand.getArgument(0) == "dec") {
766
767 setOutputRawFormat(false);
768
Patrick Benavoli63499d42011-10-24 18:50:03 +0200769 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200770
771 } else {
772 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200773 return CCommandHandler::EShowUsage;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200774 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200775 return CCommandHandler::EFailed;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200776}
777
Patrick Benavoli63499d42011-10-24 18:50:03 +0200778CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200779{
780 (void)remoteCommand;
781
782 strResult = outputRawFormatIsHex() ? "hex" : "dec";
783
Patrick Benavoli63499d42011-10-24 18:50:03 +0200784 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200785}
786
Patrick Benavoli68a91282011-08-31 11:23:23 +0200787/// Sync
Patrick Benavoli63499d42011-10-24 18:50:03 +0200788CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200789{
790 if (remoteCommand.getArgument(0) == "on") {
791
792 if (setAutoSync(true, strResult)) {
793
Patrick Benavoli63499d42011-10-24 18:50:03 +0200794 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200795 }
796 } else if (remoteCommand.getArgument(0) == "off") {
797
798 if (setAutoSync(false, strResult)) {
799
Patrick Benavoli63499d42011-10-24 18:50:03 +0200800 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200801 }
802 } else {
803 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200804 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200805 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200806 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200807}
808
Patrick Benavoli63499d42011-10-24 18:50:03 +0200809CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200810{
811 (void)remoteCommand;
812
813 strResult = autoSyncOn() ? "on" : "off";
814
Patrick Benavoli63499d42011-10-24 18:50:03 +0200815 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200816}
817
Patrick Benavoli63499d42011-10-24 18:50:03 +0200818CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::syncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200819{
820 (void)remoteCommand;
821
Patrick Benavoli63499d42011-10-24 18:50:03 +0200822 return sync(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200823}
824
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200825/// Criteria
Patrick Benavoli63499d42011-10-24 18:50:03 +0200826CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listCriteriaCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200827{
828 (void)remoteCommand;
829
Kevin Rocard7f265822012-12-07 18:51:22 +0100830 list<string> lstrResult;
831
832 getSelectionCriteria()->listSelectionCriteria(lstrResult, true, true);
833
834 // Concatenate the criterion list as the command result
835 CUtility::concatenate(lstrResult, strResult);
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200836
Patrick Benavoli63499d42011-10-24 18:50:03 +0200837 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200838}
Patrick Benavoli68a91282011-08-31 11:23:23 +0200839
840/// Domains
Patrick Benavoli63499d42011-10-24 18:50:03 +0200841CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200842{
843 (void)remoteCommand;
844
Patrick Benavoli63499d42011-10-24 18:50:03 +0200845 getConfigurableDomains()->listDomains(strResult);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200846
Patrick Benavoli63499d42011-10-24 18:50:03 +0200847 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200848}
849
Patrick Benavoli63499d42011-10-24 18:50:03 +0200850CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200851{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200852 return createDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200853}
854
Patrick Benavoli63499d42011-10-24 18:50:03 +0200855CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200856{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200857 return deleteDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200858}
859
Kevin Rocard170f0a42012-06-18 13:56:05 +0200860CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteAllDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
861{
862 (void)remoteCommand;
863
864 return deleteAllDomains(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
865}
866
Patrick Benavoli63499d42011-10-24 18:50:03 +0200867CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200868{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200869 return getConfigurableDomains()->renameDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200870}
871
Patrick Benavoli63499d42011-10-24 18:50:03 +0200872CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200873{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200874 // Check tuning mode
875 if (!checkTuningModeOn(strResult)) {
876
877 return CCommandHandler::EFailed;
878 }
879
880 // Set property
881 bool bSequenceAware;
882
883 if (remoteCommand.getArgument(1) == "true") {
884
885 bSequenceAware = true;
886
887 } else if (remoteCommand.getArgument(1) == "false") {
888
889 bSequenceAware = false;
890
891 } else {
892 // Show usage
893 return CCommandHandler::EShowUsage;
894 }
895
896 return getConfigurableDomains()->setSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200897}
898
Patrick Benavoli63499d42011-10-24 18:50:03 +0200899CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200900{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200901 // Get property
902 bool bSequenceAware;
903
904 if (!getConfigurableDomains()->getSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult)) {
905
906 return CCommandHandler::EFailed;
907 }
908
909 strResult = bSequenceAware ? "true" : "false";
910
911 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200912}
913
Patrick Benavoli63499d42011-10-24 18:50:03 +0200914CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200915{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200916 return getConfigurableDomains()->listDomainElements(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200917}
918
Patrick Benavoli63499d42011-10-24 18:50:03 +0200919CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::addElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200920{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200921 return addConfigurableElementToDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
922}
923
924CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::removeElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
925{
926 return removeConfigurableElementFromDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
927}
928
929CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::splitDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
930{
931 return split(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200932}
933
934/// Configurations
Patrick Benavoli63499d42011-10-24 18:50:03 +0200935CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConfigurationsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200936{
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100937 return getConstConfigurableDomains()->listConfigurations(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
938}
939
940CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
941{
942 (void)remoteCommand;
943
944 // Dummy error context
945 string strError;
946 CErrorContext errorContext(strError);
947
948 // Dump
949 getConstConfigurableDomains()->dumpContent(strResult, errorContext);
950
951 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200952}
953
Patrick Benavoli63499d42011-10-24 18:50:03 +0200954CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200955{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200956 return createConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200957}
958
Patrick Benavoli63499d42011-10-24 18:50:03 +0200959CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200960{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200961 return deleteConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200962}
963
Patrick Benavoli63499d42011-10-24 18:50:03 +0200964CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200965{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200966 return getConfigurableDomains()->renameConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200967}
968
Patrick Benavoli63499d42011-10-24 18:50:03 +0200969CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::saveConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200970{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200971 return saveConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200972}
973
Patrick Benavoli63499d42011-10-24 18:50:03 +0200974CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::restoreConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200975{
Kevin Rocardace81f82012-12-11 16:19:17 +0100976 list<string> lstrResult;
977 if (!restoreConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), lstrResult)) {
978 //Concatenate the error list as the command result
979 CUtility::concatenate(lstrResult, strResult);
980
981 return CCommandHandler::EFailed;
982 }
983 return CCommandHandler::EDone;
Patrick Benavoli63499d42011-10-24 18:50:03 +0200984}
985
986CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
987{
988 // Check tuning mode
989 if (!checkTuningModeOn(strResult)) {
990
991 return CCommandHandler::EFailed;
992 }
993
994 // Build configurable element path list
995 vector<string> astrNewElementSequence;
996
997 uint32_t uiArgument;
998
999 for (uiArgument = 2; uiArgument < remoteCommand.getArgumentCount(); uiArgument++) {
1000
1001 astrNewElementSequence.push_back(remoteCommand.getArgument(uiArgument));
1002 }
1003
1004 // Delegate to configurable domains
1005 return getConfigurableDomains()->setElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), astrNewElementSequence, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1006}
1007
1008CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1009{
1010 // Delegate to configurable domains
1011 return getConfigurableDomains()->getElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001012}
1013
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001014CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1015{
1016 // Delegate to configurable domains
1017 return getConfigurableDomains()->setApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.packArguments(2, remoteCommand.getArgumentCount() - 2), getConstSelectionCriteria()->getSelectionCriteriaDefinition(), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1018}
1019
1020CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::clearRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1021{
1022 // Delegate to configurable domains
1023 return getConfigurableDomains()->clearApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1024}
1025
1026CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1027{
1028 // Delegate to configurable domains
1029 return getConfigurableDomains()->getApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
1030}
1031
Patrick Benavoli68a91282011-08-31 11:23:23 +02001032/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001033CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001034{
1035 CElementLocator elementLocator(getSystemClass(), false);
1036
1037 CElement* pLocatedElement = NULL;
1038
1039 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1040
Patrick Benavoli63499d42011-10-24 18:50:03 +02001041 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001042 }
1043
1044 strResult = string("\n");
1045
1046 if (!pLocatedElement) {
1047
1048 // List from root folder
1049
1050 // Return system class qualified name
1051 pLocatedElement = getSystemClass();
1052 }
1053
1054 // Return sub-elements
1055 strResult += pLocatedElement->listQualifiedPaths(false);
1056
Patrick Benavoli63499d42011-10-24 18:50:03 +02001057 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001058}
1059
1060/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001061CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listParametersCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001062{
1063 CElementLocator elementLocator(getSystemClass(), false);
1064
1065 CElement* pLocatedElement = NULL;
1066
1067 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1068
Patrick Benavoli63499d42011-10-24 18:50:03 +02001069 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001070 }
1071
1072 strResult = string("\n");
1073
1074 if (!pLocatedElement) {
1075
1076 // List from root folder
1077
1078 // Return system class qualified name
1079 pLocatedElement = getSystemClass();
1080 }
1081
1082 // Return sub-elements
1083 strResult += pLocatedElement->listQualifiedPaths(true);
1084
Patrick Benavoli63499d42011-10-24 18:50:03 +02001085 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001086}
1087
Patrick Benavoli63499d42011-10-24 18:50:03 +02001088CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001089{
1090 CElementLocator elementLocator(getSystemClass());
1091
1092 CElement* pLocatedElement = NULL;
1093
1094 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1095
Patrick Benavoli63499d42011-10-24 18:50:03 +02001096 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001097 }
1098
1099 string strError;
1100
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001101 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001102
1103 // Dump elements
1104 pLocatedElement->dumpContent(strResult, parameterAccessContext);
1105
Patrick Benavoli63499d42011-10-24 18:50:03 +02001106 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001107}
1108
Patrick Benavoli63499d42011-10-24 18:50:03 +02001109CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSizeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001110{
1111 CElementLocator elementLocator(getSystemClass());
1112
1113 CElement* pLocatedElement = NULL;
1114
1115 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1116
Patrick Benavoli63499d42011-10-24 18:50:03 +02001117 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001118 }
1119
1120 // Converted to actual sizable element
1121 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1122
1123 // Get size as string
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001124 strResult = pConfigurableElement->getFootprintAsString();
Patrick Benavoli68a91282011-08-31 11:23:23 +02001125
Patrick Benavoli63499d42011-10-24 18:50:03 +02001126 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001127}
1128
Patrick Benavoli63499d42011-10-24 18:50:03 +02001129CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showPropertiesCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001130{
1131 CElementLocator elementLocator(getSystemClass());
1132
1133 CElement* pLocatedElement = NULL;
1134
1135 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1136
Patrick Benavoli63499d42011-10-24 18:50:03 +02001137 return CCommandHandler::EFailed;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001138 }
1139
1140 // Convert element
1141 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1142
1143 // Return element properties
1144 pConfigurableElement->showProperties(strResult);
1145
Patrick Benavoli63499d42011-10-24 18:50:03 +02001146 return CCommandHandler::ESucceeded;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001147}
1148
Patrick Benavoli63499d42011-10-24 18:50:03 +02001149CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001150{
1151 string strValue;
1152
Patrick Benavoli065264a2011-11-20 15:46:41 +01001153 if (!accessValue(remoteCommand.getArgument(0), strValue, false, strResult)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001154
Patrick Benavoli63499d42011-10-24 18:50:03 +02001155 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001156 }
1157 // Succeeded
1158 strResult = strValue;
1159
Patrick Benavoli63499d42011-10-24 18:50:03 +02001160 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001161}
1162
Patrick Benavoli63499d42011-10-24 18:50:03 +02001163CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001164{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001165 // Check tuning mode
1166 if (!checkTuningModeOn(strResult)) {
1167
1168 return CCommandHandler::EFailed;
1169 }
1170 // Get value to set
1171 string strValue = remoteCommand.packArguments(1, remoteCommand.getArgumentCount() - 1);
1172
1173 return accessValue(remoteCommand.getArgument(0), strValue, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001174}
1175
Patrick Benavoli63499d42011-10-24 18:50:03 +02001176CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listBelongingDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001177{
1178 CElementLocator elementLocator(getSystemClass());
1179
1180 CElement* pLocatedElement = NULL;
1181
1182 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1183
Patrick Benavoli63499d42011-10-24 18:50:03 +02001184 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001185 }
1186
1187 // Convert element
1188 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1189
1190 // Return element belonging domains
1191 pConfigurableElement->listBelongingDomains(strResult);
1192
Patrick Benavoli63499d42011-10-24 18:50:03 +02001193 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001194}
1195
Patrick Benavoli63499d42011-10-24 18:50:03 +02001196CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001197{
1198 CElementLocator elementLocator(getSystemClass());
1199
1200 CElement* pLocatedElement = NULL;
1201
1202 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1203
Patrick Benavoli63499d42011-10-24 18:50:03 +02001204 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001205 }
1206
1207 // Convert element
1208 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1209
1210 // Return element belonging domains
1211 pConfigurableElement->listAssociatedDomains(strResult);
1212
Patrick Benavoli63499d42011-10-24 18:50:03 +02001213 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001214}
1215
Patrick Benavoli63499d42011-10-24 18:50:03 +02001216CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001217{
1218 (void)remoteCommand;
1219
1220 getConfigurableDomains()->listAssociatedElements(strResult);
1221
Patrick Benavoli63499d42011-10-24 18:50:03 +02001222 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001223}
1224
Patrick Benavoli63499d42011-10-24 18:50:03 +02001225CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConflictingElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001226{
1227 (void)remoteCommand;
1228
1229 getConfigurableDomains()->listConflictingElements(strResult);
1230
Patrick Benavoli63499d42011-10-24 18:50:03 +02001231 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001232}
1233
Patrick Benavoli63499d42011-10-24 18:50:03 +02001234CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listRogueElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001235{
1236 (void)remoteCommand;
1237
1238 getSystemClass()->listRogueElements(strResult);
1239
Patrick Benavoli63499d42011-10-24 18:50:03 +02001240 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001241}
1242
1243/// Settings Import/Export
Patrick Benavoli63499d42011-10-24 18:50:03 +02001244CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001245{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001246 return exportDomainsXml(remoteCommand.getArgument(0), false, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001247}
1248
Patrick Benavoli63499d42011-10-24 18:50:03 +02001249CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001250{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001251 return importDomainsXml(remoteCommand.getArgument(0), false, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001252}
1253
Patrick Benavoli63499d42011-10-24 18:50:03 +02001254CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001255{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001256 return exportDomainsXml(remoteCommand.getArgument(0), true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001257}
1258
Patrick Benavoli63499d42011-10-24 18:50:03 +02001259CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001260{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001261 return importDomainsXml(remoteCommand.getArgument(0), true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001262}
1263
Patrick Benavoli63499d42011-10-24 18:50:03 +02001264CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001265{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001266 return exportDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001267}
1268
Patrick Benavoli63499d42011-10-24 18:50:03 +02001269CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001270{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001271 return importDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001272}
1273
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001274/// GUI commands
1275
1276CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getDomainsXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1277{
1278 (void)remoteCommand;
1279
1280 if (!getDomainsXMLString(strResult, true)) {
1281
1282 return CCommandHandler::EFailed;
1283 }
1284 // Succeeded
1285 return CCommandHandler::ESucceeded;
1286}
1287
1288CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getSystemClassXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1289{
1290 (void)remoteCommand;
1291
1292 if (!getSystemClassXMLString(strResult)) {
1293
1294 return CCommandHandler::EFailed;
1295 }
1296 // Succeeded
1297 return CCommandHandler::ESucceeded;
1298}
1299
Patrick Benavoli68a91282011-08-31 11:23:23 +02001300// User set/get parameters
Patrick Benavoli065264a2011-11-20 15:46:41 +01001301bool CParameterMgr::accessValue(const string& strPath, string& strValue, bool bSet, string& strError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001302{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001303 // Lock state
1304 CAutoLock autoLock(&_blackboardMutex);
1305
1306 CPathNavigator pathNavigator(strPath);
1307
1308 // Nagivate through system class
1309 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001310
1311 return false;
1312 }
1313
Patrick Benavoli065264a2011-11-20 15:46:41 +01001314 // Define context
1315 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001316
Patrick Benavoli68808c62012-02-02 17:12:41 +01001317 // Auto Sync
1318 if (bSet) {
1319
1320 parameterAccessContext.setAutoSync(_bAutoSyncOn);
1321 }
1322
Patrick Benavoli065264a2011-11-20 15:46:41 +01001323 // Do the get
1324 return getConstSystemClass()->accessValue(pathNavigator, strValue, bSet, parameterAccessContext);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001325}
1326
1327// Tuning mode
1328bool CParameterMgr::setTuningMode(bool bOn, string& strError)
1329{
1330 // Tuning allowed?
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001331 if (bOn && !getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001332
1333 strError = "Tuning prohibited";
1334
1335 return false;
1336 }
1337 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +01001338 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001339
1340 // Warn domains about exiting tuning mode
1341 if (!bOn && _bTuningModeIsOn) {
1342
1343 // Ensure application of currently selected configurations
Patrick Benavoli1387bda2011-08-31 11:23:24 +02001344 // Force-apply configurations
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01001345 doApplyConfigurations(true);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001346
Patrick Benavoli68a91282011-08-31 11:23:23 +02001347 // Turn auto sync back on
1348 _bAutoSyncOn = true;
1349 }
1350
1351 // Store
1352 _bTuningModeIsOn = bOn;
1353
Patrick Benavoli68a91282011-08-31 11:23:23 +02001354 return true;
1355}
1356
1357bool CParameterMgr::tuningModeOn() const
1358{
1359 return _bTuningModeIsOn;
1360}
1361
1362// Current value space for user set/get value interpretation
1363void CParameterMgr::setValueSpace(bool bIsRaw)
1364{
1365 _bValueSpaceIsRaw = bIsRaw;
1366}
1367
1368bool CParameterMgr::valueSpaceIsRaw()
1369{
1370 return _bValueSpaceIsRaw;
1371}
1372
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001373// Current Output Raw Format for user get value interpretation
1374void CParameterMgr::setOutputRawFormat(bool bIsHex)
1375{
1376 _bOutputRawFormatIsHex = bIsHex;
1377}
1378
1379bool CParameterMgr::outputRawFormatIsHex()
1380{
1381 return _bOutputRawFormatIsHex;
1382}
1383
Patrick Benavoli68a91282011-08-31 11:23:23 +02001384/// Sync
1385// Automatic hardware synchronization control (during tuning session)
1386bool CParameterMgr::setAutoSync(bool bAutoSyncOn, string& strError)
1387{
1388 // Check tuning mode
1389 if (!checkTuningModeOn(strError)) {
1390
1391 return false;
1392 }
1393 // Warn domains about turning auto sync back on
1394 if (bAutoSyncOn && !_bAutoSyncOn) {
1395
Patrick Benavoli592ae562011-09-05 16:53:58 +02001396 // Do the synchronization at system class level (could be optimized by keeping track of all modified parameters)
1397 if (!sync(strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001398
1399 return false;
1400 }
1401 }
1402
1403 // Set Auto sync
1404 _bAutoSyncOn = bAutoSyncOn;
1405
1406 return true;
1407}
1408
1409bool CParameterMgr::autoSyncOn() const
1410{
1411 return _bAutoSyncOn;
1412}
1413
1414// Manual hardware synchronization control (during tuning session)
1415bool CParameterMgr::sync(string& strError)
1416{
1417 // Check tuning mode
1418 if (!checkTuningModeOn(strError)) {
1419
1420 return false;
1421 }
1422 // Warn domains about turning auto sync back on
1423 if (_bAutoSyncOn) {
1424
1425 strError = "Feature unavailable when Auto Sync is on";
1426
1427 return false;
1428 }
1429
1430 // Get syncer set
1431 CSyncerSet syncerSet;
1432 // ... from system class
1433 getConstSystemClass()->fillSyncerSet(syncerSet);
Kevin Rocardace81f82012-12-11 16:19:17 +01001434
Patrick Benavoli68a91282011-08-31 11:23:23 +02001435 // Sync
Kevin Rocardace81f82012-12-11 16:19:17 +01001436 list<string> lstrError;
1437 if (! syncerSet.sync(*_pMainParameterBlackboard, false, &lstrError)){
1438
1439 CUtility::concatenate(lstrError, strError);
1440 return false;
1441 };
1442
1443 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001444}
1445
1446// Content dump
1447void CParameterMgr::logStructureContent(string& strContent) const
1448{
1449 string strError;
1450
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001451 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001452
1453 dumpContent(strContent, parameterAccessContext);
1454}
1455
1456// Configuration/Domains handling
1457bool CParameterMgr::createDomain(const string& strName, string& strError)
1458{
1459 // Check tuning mode
1460 if (!checkTuningModeOn(strError)) {
1461
1462 return false;
1463 }
1464
1465 // Delegate to configurable domains
1466 return getConfigurableDomains()->createDomain(strName, strError);
1467}
1468
1469bool CParameterMgr::deleteDomain(const string& strName, string& strError)
1470{
1471 // Check tuning mode
1472 if (!checkTuningModeOn(strError)) {
1473
1474 return false;
1475 }
1476
1477 // Delegate to configurable domains
1478 return getConfigurableDomains()->deleteDomain(strName, strError);
1479}
1480
Kevin Rocard170f0a42012-06-18 13:56:05 +02001481bool CParameterMgr::deleteAllDomains(string& strError)
1482{
1483 // Check tuning mode
1484 if (!checkTuningModeOn(strError)) {
1485
1486 return false;
1487 }
1488
1489 // Delegate to configurable domains
1490 getConfigurableDomains()->deleteAllDomains();
1491
1492 return true;
1493}
1494
Patrick Benavoli68a91282011-08-31 11:23:23 +02001495bool CParameterMgr::createConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1496{
1497 // Check tuning mode
1498 if (!checkTuningModeOn(strError)) {
1499
1500 return false;
1501 }
1502
1503 // Delegate to configurable domains
1504 return getConfigurableDomains()->createConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1505}
1506
1507bool CParameterMgr::deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1508{
1509 // Check tuning mode
1510 if (!checkTuningModeOn(strError)) {
1511
1512 return false;
1513 }
1514
1515 // Delegate to configurable domains
1516 return getConfigurableDomains()->deleteConfiguration(strDomain, strConfiguration, strError);
1517}
1518
Kevin Rocardace81f82012-12-11 16:19:17 +01001519bool CParameterMgr::restoreConfiguration(const string& strDomain, const string& strConfiguration, list<string>& lstrError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001520{
Kevin Rocardace81f82012-12-11 16:19:17 +01001521 string strError;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001522 // Check tuning mode
1523 if (!checkTuningModeOn(strError)) {
1524
Kevin Rocardace81f82012-12-11 16:19:17 +01001525 lstrError.push_back(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001526 return false;
1527 }
1528
1529 // Delegate to configurable domains
Kevin Rocardace81f82012-12-11 16:19:17 +01001530 return getConstConfigurableDomains()->restoreConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, lstrError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001531}
1532
1533bool CParameterMgr::saveConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1534{
1535 // Check tuning mode
1536 if (!checkTuningModeOn(strError)) {
1537
1538 return false;
1539 }
1540
1541 // Delegate to configurable domains
1542 return getConfigurableDomains()->saveConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1543}
1544
1545// Configurable element - domain association
1546bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1547{
1548 // Check tuning mode
1549 if (!checkTuningModeOn(strError)) {
1550
1551 return false;
1552 }
1553
1554 CElementLocator elementLocator(getSystemClass());
1555
1556 CElement* pLocatedElement = NULL;
1557
1558 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1559
1560 return false;
1561 }
1562
1563 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001564 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001565
1566 // Delegate
1567 return getConfigurableDomains()->addConfigurableElementToDomain(strDomain, pConfigurableElement, _pMainParameterBlackboard, strError);
1568}
1569
1570bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1571{
1572 // Check tuning mode
1573 if (!checkTuningModeOn(strError)) {
1574
1575 return false;
1576 }
1577
1578 CElementLocator elementLocator(getSystemClass());
1579
1580 CElement* pLocatedElement = NULL;
1581
1582 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1583
Patrick Benavoli63499d42011-10-24 18:50:03 +02001584 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001585 }
1586
1587 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001588 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001589
1590 // Delegate
1591 return getConfigurableDomains()->removeConfigurableElementFromDomain(strDomain, pConfigurableElement, strError);
1592}
1593
1594bool CParameterMgr::split(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1595{
1596 // Check tuning mode
1597 if (!checkTuningModeOn(strError)) {
1598
1599 return false;
1600 }
1601
1602 CElementLocator elementLocator(getSystemClass());
1603
1604 CElement* pLocatedElement = NULL;
1605
1606 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1607
Patrick Benavoli63499d42011-10-24 18:50:03 +02001608 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001609 }
1610
1611 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001612 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001613
1614 // Delegate
1615 return getConfigurableDomains()->split(strDomain, pConfigurableElement, strError);
1616}
1617
1618// XML Import/Export
1619bool CParameterMgr::importDomainsXml(const string& strFileName, bool bWithSettings, string& strError)
1620{
1621 // Check tuning mode
1622 if (!checkTuningModeOn(strError)) {
1623
1624 return false;
1625 }
1626
1627 // check path is absolute
1628 if (strFileName[0] != '/') {
1629
1630 strError = "Please provide absolute path";
1631
1632 return false;
1633 }
1634 // Root element
1635 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1636
1637 // Context
1638 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1639
1640 // Secltion criteria definition for rule creation
1641 xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
1642
1643 // Parse
1644 if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strFileName, "", EParameterConfigurationLibrary, "SystemClassName")) {
1645
1646 return false;
1647 }
1648
1649 // Validate domains after XML import
1650 pConfigurableDomains->validate(_pMainParameterBlackboard);
1651
1652 return true;
1653}
1654
1655bool CParameterMgr::exportDomainsXml(const string& strFileName, bool bWithSettings, string& strError) const
1656{
1657 // check path is absolute
1658 if (strFileName[0] != '/') {
1659
1660 strError = "Please provide absolute path";
1661
1662 return false;
1663 }
1664
1665 // Root element
1666 const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains();
1667
1668 // Get Schema file associated to root element
1669 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pConfigurableDomains->getKind() + ".xsd";
1670
1671 // Context
1672 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1673
1674 // Value space
1675 xmlDomainSerializingContext.setValueSpaceRaw(_bValueSpaceIsRaw);
1676
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001677 // Output raw format
1678 xmlDomainSerializingContext.setOutputRawFormat(_bOutputRawFormatIsHex);
1679
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001680 // Use a doc source by loading data from instantiated Configurable Domains
1681 CXmlMemoryDocSource memorySource(pConfigurableDomains, pConfigurableDomains->getKind(), strXmlSchemaFilePath, "parameter-framework", getVersion());
Patrick Benavoli68a91282011-08-31 11:23:23 +02001682
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001683 // Use a doc sink to write the doc data in a file
1684 CXmlFileDocSink fileSink(strFileName);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001685
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001686 if (!fileSink.process(memorySource, xmlDomainSerializingContext)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001687 return false;
1688 }
1689
1690 return true;
1691}
1692
1693// Binary Import/Export
1694bool CParameterMgr::importDomainsBinary(const string& strFileName, string& strError)
1695{
1696 // Check tuning mode
1697 if (!checkTuningModeOn(strError)) {
1698
1699 return false;
1700 }
1701 // check path is absolute
1702 if (strFileName[0] != '/') {
1703
1704 strError = "Please provide absolute path";
1705
1706 return false;
1707 }
1708 // Root element
1709 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1710
1711 // Serialize in
1712 return pConfigurableDomains->serializeSettings(strFileName, false, _uiStructureChecksum, strError);
1713}
1714
1715bool CParameterMgr::exportDomainsBinary(const string& strFileName, string& strError)
1716{
1717 // check path is absolute
1718 if (strFileName[0] != '/') {
1719
1720 strError = "Please provide absolute path";
1721
1722 return false;
1723 }
Patrick Benavoli68a91282011-08-31 11:23:23 +02001724
Patrick Benavoli68a91282011-08-31 11:23:23 +02001725 // Root element
1726 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1727
1728 // Serialize out
1729 return pConfigurableDomains->serializeSettings(strFileName, true, _uiStructureChecksum, strError);
1730}
1731
1732// For tuning, check we're in tuning mode
1733bool CParameterMgr::checkTuningModeOn(string& strError) const
1734{
1735 // Tuning Mode on?
1736 if (!_bTuningModeIsOn) {
1737
1738 strError = "Tuning Mode must be on";
1739
1740 return false;
1741 }
1742 return true;
1743}
1744
Patrick Benavoli065264a2011-11-20 15:46:41 +01001745// Tuning mutex dynamic parameter handling
1746pthread_mutex_t* CParameterMgr::getBlackboardMutex()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001747{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001748 return &_blackboardMutex;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001749}
1750
Patrick Benavoli065264a2011-11-20 15:46:41 +01001751// Blackboard reference (dynamic parameter handling)
1752CParameterBlackboard* CParameterMgr::getParameterBlackboard()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001753{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001754 return _pMainParameterBlackboard;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02001755}
1756
Patrick Benavoli68a91282011-08-31 11:23:23 +02001757// Dynamic creation library feeding
1758void CParameterMgr::feedElementLibraries()
1759{
1760 // Global Configuration handling
1761 CElementLibrary* pFrameworkConfigurationLibrary = new CElementLibrary;
1762
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001763 pFrameworkConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CParameterFrameworkConfiguration>("ParameterFrameworkConfiguration"));
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +01001764 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CSubsystemPlugins>("SubsystemPlugins"));
1765 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CPluginLocation>("Location"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001766 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("StructureDescriptionFileLocation"));
1767 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationGroup>("SettingsConfiguration"));
1768 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("ConfigurableDomainsFileLocation"));
1769 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("BinarySettingsFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001770
1771 _pElementLibrarySet->addElementLibrary(pFrameworkConfigurationLibrary);
1772
1773 // Parameter creation
1774 CElementLibrary* pParameterCreationLibrary = new CElementLibrary;
1775
1776 pParameterCreationLibrary->addElementBuilder(new CSubsystemElementBuilder(getSystemClass()->getSubsystemLibrary()));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001777 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CComponentType>("ComponentType"));
1778 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CComponentInstance>("Component"));
1779 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBitParameterType>("BitParameter"));
1780 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBitParameterBlockType>("BitParameterBlock"));
Patrick Benavoli1352ae52011-10-21 16:48:04 +02001781 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CStringParameterType>("StringParameter"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001782 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CParameterBlockType>("ParameterBlock"));
1783 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBooleanParameterType>("BooleanParameter"));
1784 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CIntegerParameterType>("IntegerParameter"));
Patrick Benavoliee65e6d2011-11-20 18:52:24 +01001785 pParameterCreationLibrary->addElementBuilder(new TElementBuilderTemplate<CLinearParameterAdaptation>("LinearAdaptation"));
Patrick Benavoli9fc3c0d2011-10-27 14:27:27 +02001786 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CEnumParameterType>("EnumParameter"));
Patrick Benavoli68808c62012-02-02 17:12:41 +01001787 pParameterCreationLibrary->addElementBuilder(new TElementBuilderTemplate<CEnumValuePair>("ValuePair"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001788 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CFixedPointParameterType>("FixedPointParameter"));
1789 pParameterCreationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CXmlFileIncluderElement>("SubsystemInclude"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001790
1791 _pElementLibrarySet->addElementLibrary(pParameterCreationLibrary);
1792
1793 // Parameter Configuration Domains creation
1794 CElementLibrary* pParameterConfigurationLibrary = new CElementLibrary;
1795
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001796 pParameterConfigurationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CConfigurableDomain>("ConfigurableDomain"));
1797 pParameterConfigurationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CDomainConfiguration>("Configuration"));
1798 pParameterConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CCompoundRule>("CompoundRule"));
1799 pParameterConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CSelectionCriterionRule>("SelectionCriterionRule"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02001800
1801 _pElementLibrarySet->addElementLibrary(pParameterConfigurationLibrary);
1802}
1803
1804// Remote Processor Server connection handling
1805bool CParameterMgr::handleRemoteProcessingInterface(string& strError)
1806{
1807 CAutoLog autoLog(this, "Handling remote processing interface");
1808
1809 // Start server if tuning allowed
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001810 if (getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001811
Kevin Rocardace81f82012-12-11 16:19:17 +01001812 log_info("Loading remote processor library");
Patrick Benavoli68a91282011-08-31 11:23:23 +02001813
1814 // Load library
1815 void* lib_handle = dlopen("libremote-processor.so", RTLD_NOW);
1816
1817 if (!lib_handle) {
1818
1819 // Return error
1820 const char* pcError = dlerror();
1821
1822 if (pcError) {
1823
1824 strError = pcError;
1825 } else {
1826
1827 strError = "Unable to load libremote-processor.so library";
1828 }
1829
1830 return false;
1831 }
1832
1833 CreateRemoteProcessorServer pfnCreateRemoteProcessorServer = (CreateRemoteProcessorServer)dlsym(lib_handle, "createRemoteProcessorServer");
1834
1835 if (!pfnCreateRemoteProcessorServer) {
1836
1837 strError = "libremote-process.so does not contain createRemoteProcessorServer symbol.";
1838
1839 return false;
1840 }
1841
1842 // Create server
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001843 _pRemoteProcessorServer = pfnCreateRemoteProcessorServer(getConstFrameworkConfiguration()->getServerPort(), _pCommandHandler);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001844
Kevin Rocardace81f82012-12-11 16:19:17 +01001845 log_info("Starting remote processor server on port %d", getConstFrameworkConfiguration()->getServerPort());
Patrick Benavoli68a91282011-08-31 11:23:23 +02001846 // Start
1847 if (!_pRemoteProcessorServer->start()) {
1848
1849 strError = "Unable to start remote processor server";
1850
1851 return false;
1852 }
1853 }
1854
1855 return true;
1856}
1857
1858// Back synchronization
Kevin Rocardace81f82012-12-11 16:19:17 +01001859CBackSynchronizer* CParameterMgr::createBackSynchronizer() const
Patrick Benavoli68a91282011-08-31 11:23:23 +02001860{
1861#ifdef SIMULATION
1862 // In simulation, back synchronization of the blackboard won't probably work
1863 // We need to ensure though the blackboard is initialized with valid data
Kevin Rocardace81f82012-12-11 16:19:17 +01001864 return new CSimulatedBackSynchronizer(getConstSystemClass(), _pMainParameterBlackboard);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001865#else
1866 // Real back synchronizer from subsystems
Kevin Rocardace81f82012-12-11 16:19:17 +01001867 return new CHardwareBackSynchronizer(getConstSystemClass(), _pMainParameterBlackboard);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001868#endif
1869}
1870
1871// Children typwise access
1872CParameterFrameworkConfiguration* CParameterMgr::getFrameworkConfiguration()
1873{
1874 return static_cast<CParameterFrameworkConfiguration*>(getChild(EFrameworkConfiguration));
1875}
1876
1877const CParameterFrameworkConfiguration* CParameterMgr::getConstFrameworkConfiguration()
1878{
1879 return getFrameworkConfiguration();
1880}
1881
1882CSelectionCriteria* CParameterMgr::getSelectionCriteria()
1883{
1884 return static_cast<CSelectionCriteria*>(getChild(ESelectionCriteria));
1885}
1886
1887const CSelectionCriteria* CParameterMgr::getConstSelectionCriteria()
1888{
1889 return static_cast<const CSelectionCriteria*>(getChild(ESelectionCriteria));
1890}
1891
1892CSystemClass* CParameterMgr::getSystemClass()
1893{
1894 return static_cast<CSystemClass*>(getChild(ESystemClass));
1895}
1896
1897const CSystemClass* CParameterMgr::getConstSystemClass() const
1898{
1899 return static_cast<const CSystemClass*>(getChild(ESystemClass));
1900}
1901
1902// Configurable Domains
1903CConfigurableDomains* CParameterMgr::getConfigurableDomains()
1904{
1905 return static_cast<CConfigurableDomains*>(getChild(EConfigurableDomains));
1906}
1907
1908const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains()
1909{
1910 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
1911}
1912
1913const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains() const
1914{
1915 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
1916}
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001917
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01001918// Apply configurations
1919void CParameterMgr::doApplyConfigurations(bool bForce)
1920{
1921 CSyncerSet syncerSet;
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001922
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01001923 // Check subsystems that need resync
1924 getSystemClass()->checkForSubsystemsToResync(syncerSet);
1925
1926 // Ensure application of currently selected configurations
1927 getConfigurableDomains()->apply(_pMainParameterBlackboard, syncerSet, bForce);
1928
1929 // Reset the modified status of the current criteria to indicate that a new configuration has been applied
1930 getSelectionCriteria()->resetModifiedStatus();
1931}
1932
1933/// GUI commands functions
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001934bool CParameterMgr::getDomainsXMLString(string& strResult, bool bWithSettings)
1935{
1936
1937 // Root element
1938 const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains();
1939
1940 // Get Schema file associated to root element
1941 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pConfigurableDomains->getKind() + ".xsd";
1942
1943 string strError;
1944
1945 // Context
1946 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1947
1948 // Value space
1949 xmlDomainSerializingContext.setValueSpaceRaw(_bValueSpaceIsRaw);
1950
1951 // Output raw format
1952 xmlDomainSerializingContext.setOutputRawFormat(_bOutputRawFormatIsHex);
1953
1954 // Use a doc source by loading data from instantiated Configurable Domains
1955 CXmlMemoryDocSource memorySource(pConfigurableDomains, pConfigurableDomains->getKind(), strXmlSchemaFilePath, "parameter-framework", getVersion());
1956
1957 // Use a doc sink the write the doc data in a string
1958 CXmlStringDocSink stringSink(strResult);
1959
1960 if (!stringSink.process(memorySource, xmlDomainSerializingContext)) {
1961 strResult = strError;
1962
1963 return false;
1964 }
1965
1966 return true;
1967}
1968
1969bool CParameterMgr::getSystemClassXMLString(string& strResult)
1970{
1971 // Root element
1972 const CSystemClass* pSystemClass = getSystemClass();
1973
1974 string strError;
1975
1976 CXmlSerializingContext xmlSerializingContext(strError);
1977
1978 // Use a doc source by loading data from instantiated Configurable Domains
1979 CXmlMemoryDocSource memorySource(pSystemClass, pSystemClass->getKind());
1980
1981 // Use a doc sink that write the doc data in a string
1982 CXmlStringDocSink stringSink(strResult);
1983
1984 if (!stringSink.process(memorySource, xmlSerializingContext)) {
1985 strResult = strError;
1986 return false;
1987 }
1988
1989 return true;
1990}