blob: 999cb1f15f314e1cb94883f986058599ee7036e0 [file] [log] [blame]
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +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 "ParameterAccessContext.h"
46#include "XmlFileIncluderElement.h"
47#include "ParameterFrameworkConfiguration.h"
48#include "FrameworkConfigurationGroup.h"
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +010049#include "PluginLocation.h"
50#include "SubsystemPlugins.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020051#include "FrameworkConfigurationLocation.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020052#include "ConfigurableDomains.h"
53#include "ConfigurableDomain.h"
54#include "DomainConfiguration.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020055#include "XmlDomainSerializingContext.h"
56#include "BitParameterBlockType.h"
57#include "BitParameterType.h"
Patrick Benavoli1352ae52011-10-21 16:48:04 +020058#include "StringParameterType.h"
Patrick Benavoli9fc3c0d2011-10-27 14:27:27 +020059#include "EnumParameterType.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020060#include "RemoteProcessorServerInterface.h"
61#include "ElementLocator.h"
62#include "AutoLog.h"
63#include "CompoundRule.h"
64#include "SelectionCriterionRule.h"
65#include "SimulatedBackSynchronizer.h"
66#include "HardwareBackSynchronizer.h"
Patrick Benavoli1387bda2011-08-31 11:23:24 +020067#include "AutoLock.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020068#include <strings.h>
69#include <dlfcn.h>
70#include <assert.h>
Patrick Benavoli065264a2011-11-20 15:46:41 +010071#include "ParameterHandle.h"
Patrick Benavoliee65e6d2011-11-20 18:52:24 +010072#include "LinearParameterAdaptation.h"
Patrick Benavoli68808c62012-02-02 17:12:41 +010073#include "EnumValuePair.h"
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +020074#include "Subsystem.h"
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020075#include "XmlFileDocSink.h"
76#include "XmlFileDocSource.h"
77#include "XmlStringDocSink.h"
Georges-Henri Baroncec86c12012-09-04 17:30:28 +020078#include "XmlStringDocSource.h"
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020079#include "XmlMemoryDocSink.h"
80#include "XmlMemoryDocSource.h"
Kevin Rocardace81f82012-12-11 16:19:17 +010081#include "Utility.h"
Frédéric Boisnard6c55e9a2014-01-10 18:46:33 +010082#include <sstream>
Patrick Benavoli68a91282011-08-31 11:23:23 +020083
84#define base CElement
85
86// Used for remote processor server creation
87typedef IRemoteProcessorServerInterface* (*CreateRemoteProcessorServer)(uint16_t uiPort, IRemoteCommandHandler* pCommandHandler);
88
89// Global configuration file name (fixed)
90const char* gacParameterFrameworkConfigurationFileName = "ParameterFrameworkConfiguration.xml";
91const char* gacSystemSchemasSubFolder = "Schemas";
92
93// Config File System looks normally like this:
94// ---------------------------------------------
Patrick Benavoli95ac0342011-11-07 20:32:51 +010095//├── <ParameterFrameworkConfiguration>.xml
Patrick Benavoli68a91282011-08-31 11:23:23 +020096//├── Schemas
97//│ └── *.xsd
98//├── Settings
99//│ └── <SystemClassName folder>*
100//│ ├── <ConfigurableDomains>.xml
101//│ └── <Settings>.bin?
102//└── Structure
103// └── <SystemClassName folder>*
104// ├── <SystemClassName>Class.xml
105// └── <Subsystem>.xml*
106// --------------------------------------------
107
108
109// Remote command parser array
Patrick Benavoli592ae562011-09-05 16:53:58 +0200110const CParameterMgr::SRemoteCommandParserItem CParameterMgr::gastRemoteCommandParserItems[] = {
Kevin Rocard3949b342013-05-24 18:43:53 +0200111
Patrick Benavoli592ae562011-09-05 16:53:58 +0200112 /// Version
Kevin Rocard3949b342013-05-24 18:43:53 +0200113 { "version", &CParameterMgr::versionCommandProcess, 0,
114 "", "Show version" },
115
Patrick Benavoli68a91282011-08-31 11:23:23 +0200116 /// Status
Kevin Rocard3949b342013-05-24 18:43:53 +0200117 { "status", &CParameterMgr::statusCommandProcess, 0, "",
118 "Show current status" },
119
Patrick Benavoli68a91282011-08-31 11:23:23 +0200120 /// Tuning Mode
Kevin Rocard3949b342013-05-24 18:43:53 +0200121 { "setTuningMode", &CParameterMgr::setTuningModeCommmandProcess, 1,
122 "on|off*", "Turn on or off Tuning Mode" },
123 { "getTuningMode", &CParameterMgr::getTuningModeCommmandProcess, 0,
124 "", "Show Tuning Mode" },
125
Patrick Benavoli68a91282011-08-31 11:23:23 +0200126 /// Value Space
Kevin Rocard3949b342013-05-24 18:43:53 +0200127 { "setValueSpace", &CParameterMgr::setValueSpaceCommmandProcess, 1,
128 "raw|real*", "Assigns Value Space used for parameter value interpretation" },
129 { "getValueSpace", &CParameterMgr::getValueSpaceCommmandProcess, 0,
130 "", "Show Value Space" },
131
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200132 /// Output Raw Format
Kevin Rocard3949b342013-05-24 18:43:53 +0200133 { "setOutputRawFormat", &CParameterMgr::setOutputRawFormatCommmandProcess, 1,
134 "dec*|hex", "Assigns format used to output parameter values when in raw Value Space" },
135 { "getOutputRawFormat", &CParameterMgr::getOutputRawFormatCommmandProcess, 0,
136 "", "Show Output Raw Format" },
137
Patrick Benavoli68a91282011-08-31 11:23:23 +0200138 /// Sync
Kevin Rocard3949b342013-05-24 18:43:53 +0200139 { "setAutoSync", &CParameterMgr::setAutoSyncCommmandProcess, 1,
140 "on*|off", "Turn on or off automatic synchronization to hardware while in Tuning Mode" },
141 { "getAutoSync", &CParameterMgr::getAutoSyncCommmandProcess, 0,
142 "", "Show Auto Sync state" },
143 { "sync", &CParameterMgr::syncCommmandProcess, 0,
144 "", "Synchronize current settings to hardware while in Tuning Mode and Auto Sync off" },
145
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200146 /// Criteria
Kevin Rocard3949b342013-05-24 18:43:53 +0200147 { "listCriteria", &CParameterMgr::listCriteriaCommmandProcess, 0,
148 "[csv]", "List selection criteria" },
149
Patrick Benavoli68a91282011-08-31 11:23:23 +0200150 /// Domains
Kevin Rocard3949b342013-05-24 18:43:53 +0200151 { "listDomains", &CParameterMgr::listDomainsCommmandProcess, 0,
152 "", "List configurable domains" },
153 { "dumpDomains", &CParameterMgr::dumpDomainsCommmandProcess, 0,
154 "", "Show all domains and configurations, including applicability conditions" },
155 { "createDomain", &CParameterMgr::createDomainCommmandProcess, 1,
156 "<domain>", "Create new configurable domain" },
157 { "deleteDomain", &CParameterMgr::deleteDomainCommmandProcess, 1,
158 "<domain>", "Delete configurable domain" },
159 { "deleteAllDomains", &CParameterMgr::deleteAllDomainsCommmandProcess, 0,
160 "", "Delete all configurable domains" },
161 { "renameDomain", &CParameterMgr::renameDomainCommmandProcess, 2,
162 "<domain> <new name>", "Rename configurable domain" },
163 { "setSequenceAwareness", &CParameterMgr::setSequenceAwarenessCommmandProcess, 1,
164 "<domain> true|false*", "Set configurable domain sequence awareness" },
165 { "getSequenceAwareness", &CParameterMgr::getSequenceAwarenessCommmandProcess, 1,
166 "<domain>", "Get configurable domain sequence awareness" },
167 { "listDomainElements", &CParameterMgr::listDomainElementsCommmandProcess, 1,
168 "<domain>", "List elements associated to configurable domain" },
169 { "addElement", &CParameterMgr::addElementCommmandProcess, 2,
170 "<domain> <elem path>", "Associate element at given path to configurable domain" },
171 { "removeElement", &CParameterMgr::removeElementCommmandProcess, 2,
172 "<domain> <elem path>", "Dissociate element at given path from configurable domain" },
173 { "splitDomain", &CParameterMgr::splitDomainCommmandProcess, 2,
174 "<domain> <elem path>", "Split configurable domain at given associated element path" },
175
Patrick Benavoli68a91282011-08-31 11:23:23 +0200176 /// Configurations
Kevin Rocard3949b342013-05-24 18:43:53 +0200177 { "listConfigurations", &CParameterMgr::listConfigurationsCommmandProcess, 1,
178 "<domain>", "List domain configurations" },
179 { "createConfiguration", &CParameterMgr::createConfigurationCommmandProcess, 2,
180 "<domain> <configuration>", "Create new domain configuration" },
181 { "deleteConfiguration", &CParameterMgr::deleteConfigurationCommmandProcess, 2,
182 "<domain> <configuration>", "Delete domain configuration" },
183 { "renameConfiguration", &CParameterMgr::renameConfigurationCommmandProcess, 3,
184 "<domain> <configuration> <new name>", "Rename domain configuration" },
185 { "saveConfiguration", &CParameterMgr::saveConfigurationCommmandProcess, 2,
186 "<domain> <configuration>", "Save current settings into configuration" },
187 { "restoreConfiguration", &CParameterMgr::restoreConfigurationCommmandProcess, 2,
188 "<domain> <configuration>", "Restore current settings from configuration" },
189 { "setElementSequence", &CParameterMgr::setElementSequenceCommmandProcess, 3,
190 "<domain> <configuration> <elem path list>",
191 "Set element application order for configuration" },
192 { "getElementSequence", &CParameterMgr::getElementSequenceCommmandProcess, 2,
193 "<domain> <configuration>", "Get element application order for configuration" },
194 { "setRule", &CParameterMgr::setRuleCommmandProcess, 3,
195 "<domain> <configuration> <rule>", "Set configuration application rule" },
196 { "clearRule", &CParameterMgr::clearRuleCommmandProcess, 2,
197 "<domain> <configuration>", "Clear configuration application rule" },
198 { "getRule", &CParameterMgr::getRuleCommmandProcess, 2,
199 "<domain> <configuration>", "Get configuration application rule" },
200
Patrick Benavoli68a91282011-08-31 11:23:23 +0200201 /// Elements/Parameters
Kevin Rocard3949b342013-05-24 18:43:53 +0200202 { "listElements", &CParameterMgr::listElementsCommmandProcess, 1,
203 "<elem path>|/", "List elements under element at given path or root" },
204 { "listParameters", &CParameterMgr::listParametersCommmandProcess, 1,
205 "<elem path>|/", "List parameters under element at given path or root" },
206 { "dumpElement", &CParameterMgr::dumpElementCommmandProcess, 1,
207 "<elem path>", "Dump structure and content of element at given path" },
208 { "getElementSize", &CParameterMgr::getElementSizeCommmandProcess, 1,
209 "<elem path>", "Show size of element at given path" },
210 { "showProperties", &CParameterMgr::showPropertiesCommmandProcess, 1,
211 "<elem path>", "Show properties of element at given path" },
212 { "getParameter", &CParameterMgr::getParameterCommmandProcess, 1,
213 "<param path>", "Get value for parameter at given path" },
214 { "setParameter", &CParameterMgr::setParameterCommmandProcess, 2,
215 "<param path> <value>", "Set value for parameter at given path" },
216 { "listBelongingDomains", &CParameterMgr::listBelongingDomainsCommmandProcess, 1,
217 "<elem path>", "List domain(s) element at given path belongs to" },
218 { "listAssociatedDomains", &CParameterMgr::listAssociatedDomainsCommmandProcess, 1,
219 "<elem path>", "List domain(s) element at given path is associated to" },
220 { "getConfigurationParameter", &CParameterMgr::getConfigurationParameterCommmandProcess, 3,
221 "<domain> <configuration> <param path>",
222 "Get value for parameter at given path from configuration" },
223 { "setConfigurationParameter", &CParameterMgr::setConfigurationParameterCommmandProcess, 4,
224 "<domain> <configuration> <param path> <value>",
225 "Set value for parameter at given path to configuration" },
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200226 { "showMapping", &CParameterMgr::showMappingCommmandProcess, 1,
227 "<elem path>", "Show mapping for an element at given path" },
Kevin Rocard3949b342013-05-24 18:43:53 +0200228
Patrick Benavoli68a91282011-08-31 11:23:23 +0200229 /// Browse
Kevin Rocard3949b342013-05-24 18:43:53 +0200230 { "listAssociatedElements", &CParameterMgr::listAssociatedElementsCommmandProcess, 0,
231 "", "List element sub-trees associated to at least one configurable domain" },
232 { "listConflictingElements", &CParameterMgr::listConflictingElementsCommmandProcess, 0,
233 "", "List element sub-trees contained in more than one configurable domain" },
234 { "listRogueElements", &CParameterMgr::listRogueElementsCommmandProcess, 0,
235 "", "List element sub-trees owned by no configurable domain" },
236
Patrick Benavoli68a91282011-08-31 11:23:23 +0200237 /// Settings Import/Export
Kevin Rocard3949b342013-05-24 18:43:53 +0200238 { "exportDomainsXML", &CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess, 1,
239 "<file path> ", "Export domains to XML file" },
240 { "importDomainsXML", &CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess, 1,
241 "<file path>", "Import domains from XML file" },
242 { "exportDomainsWithSettingsXML",
243 &CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess, 1,
244 "<file path> ", "Export domains including settings to XML file" },
245 { "importDomainsWithSettingsXML",
246 &CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess, 1,
247 "<file path>", "Import domains including settings from XML file" },
248 { "exportSettings", &CParameterMgr::exportSettingsCommmandProcess, 1,
249 "<file path>", "Export settings to binary file" },
250 { "importSettings", &CParameterMgr::importSettingsCommmandProcess, 1,
251 "<file path>", "Import settings from binary file" },
Georges-Henri Baroncec86c12012-09-04 17:30:28 +0200252 { "getDomainsWithSettingsXML",
253 &CParameterMgr::getConfigurableDomainsWithSettingsXMLCommmandProcess, 0,
Kevin Rocard3949b342013-05-24 18:43:53 +0200254 "", "Print domains including settings as XML" },
Georges-Henri Baroncec86c12012-09-04 17:30:28 +0200255 { "setDomainsWithSettingsXML",
256 &CParameterMgr::setConfigurableDomainsWithSettingsXMLCommmandProcess, 1,
257 "<xml configurable domains>", "Import domains including settings from XML string" },
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200258 /// Structure Export
Kevin Rocard3949b342013-05-24 18:43:53 +0200259 { "getSystemClassXML", &CParameterMgr::getSystemClassXMLCommmandProcess, 0 ,
Kevin Rocardc0211572013-06-18 11:34:53 +0200260 "", "Print parameter structure as XML" },
261 /// Deprecated Commands
262 { "getDomainsXML",
263 &CParameterMgr::getConfigurableDomainsWithSettingsXMLCommmandProcess, 0,
264 "", "DEPRECATED COMMAND, please use getDomainsWithSettingsXML" },
Georges-Henri Baroncec86c12012-09-04 17:30:28 +0200265
Patrick Benavoli68a91282011-08-31 11:23:23 +0200266};
Kevin Rocard3949b342013-05-24 18:43:53 +0200267
Patrick Benavoli68a91282011-08-31 11:23:23 +0200268// Remote command parsers array Size
Patrick Benavoli592ae562011-09-05 16:53:58 +0200269const uint32_t CParameterMgr::guiNbRemoteCommandParserItems = sizeof(gastRemoteCommandParserItems) / sizeof(gastRemoteCommandParserItems[0]);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200270
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100271CParameterMgr::CParameterMgr(const string& strConfigurationFilePath) :
Patrick Benavoli68a91282011-08-31 11:23:23 +0200272 _bTuningModeIsOn(false),
273 _bValueSpaceIsRaw(false),
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200274 _bOutputRawFormatIsHex(false),
Patrick Benavoli68a91282011-08-31 11:23:23 +0200275 _bAutoSyncOn(true),
276 _pMainParameterBlackboard(new CParameterBlackboard),
277 _pElementLibrarySet(new CElementLibrarySet),
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100278 _strXmlConfigurationFilePath(strConfigurationFilePath),
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100279 _pSubsystemPlugins(NULL),
Renaud de Chivre1b8b3ca2013-12-13 15:09:44 +0100280 _handleLibRemoteProcessor(NULL),
Patrick Benavoli68a91282011-08-31 11:23:23 +0200281 _uiStructureChecksum(0),
282 _pRemoteProcessorServer(NULL),
283 _uiMaxCommandUsageLength(0),
284 _pLogger(NULL),
Kevin Rocardecf93102013-07-10 18:28:10 +0200285 _uiLogDepth(0),
Kevin Rocardd6909eb2013-07-18 09:13:51 +0200286 _bFailOnMissingSubsystem(true),
287 _bFailOnFailedSettingsLoad(true)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200288{
289 // Tuning Mode Mutex
Patrick Benavoli065264a2011-11-20 15:46:41 +0100290 bzero(&_blackboardMutex, sizeof(_blackboardMutex));
291 pthread_mutex_init(&_blackboardMutex, NULL);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200292
293 // Deal with children
294 addChild(new CParameterFrameworkConfiguration);
295 addChild(new CSelectionCriteria);
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100296 addChild(new CSystemClass);
297 addChild(new CConfigurableDomains);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200298
299 // Feed element library
300 feedElementLibraries();
Patrick Benavoli63499d42011-10-24 18:50:03 +0200301
302 _pCommandHandler = new CCommandHandler(this);
303
304 // Add command parsers
305 uint32_t uiRemoteCommandParserItem;
306
307 for (uiRemoteCommandParserItem = 0; uiRemoteCommandParserItem < guiNbRemoteCommandParserItems; uiRemoteCommandParserItem++) {
308
309 const SRemoteCommandParserItem* pRemoteCommandParserItem = &gastRemoteCommandParserItems[uiRemoteCommandParserItem];
310
311 _pCommandHandler->addCommandParser(pRemoteCommandParserItem->_pcCommandName,
312 pRemoteCommandParserItem->_pfnParser,
313 pRemoteCommandParserItem->_uiMinArgumentCount,
314 pRemoteCommandParserItem->_pcHelp,
315 pRemoteCommandParserItem->_pcDescription);
316 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100317
318 // Configuration file folder
319 uint32_t uiSlashPos = _strXmlConfigurationFilePath.rfind('/', -1);
320
321 assert(uiSlashPos != (uint32_t)-1);
322
323 _strXmlConfigurationFolderPath = _strXmlConfigurationFilePath.substr(0, uiSlashPos);
324
325 // Schema absolute folder location
326 _strSchemaFolderLocation = _strXmlConfigurationFolderPath + "/" + gacSystemSchemasSubFolder;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200327}
328
329CParameterMgr::~CParameterMgr()
330{
331 // Children
332 delete _pRemoteProcessorServer;
Frederic Boisnard31242302012-04-26 17:07:34 +0200333 delete _pCommandHandler;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200334 delete _pMainParameterBlackboard;
335 delete _pElementLibrarySet;
336
Renaud de Chivre1b8b3ca2013-12-13 15:09:44 +0100337 // Close remote processor library
338 if (_handleLibRemoteProcessor != NULL) {
339 dlclose(_handleLibRemoteProcessor);
340 }
341
Patrick Benavoli68a91282011-08-31 11:23:23 +0200342 // Tuning Mode Mutex
Patrick Benavoli065264a2011-11-20 15:46:41 +0100343 pthread_mutex_destroy(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200344}
345
346string CParameterMgr::getKind() const
347{
348 return "ParameterMgr";
349}
350
351// Logging
352void CParameterMgr::setLogger(CParameterMgr::ILogger* pLogger)
353{
354 _pLogger = pLogger;
355}
356
357// Logging
Kevin Rocardace81f82012-12-11 16:19:17 +0100358void CParameterMgr::doLog(bool bIsWarning, const string& strLog) const
Patrick Benavoli68a91282011-08-31 11:23:23 +0200359{
360 if (_pLogger) {
361
362 // Nest
363 string strIndent;
364
365 // Level
366 uint32_t uiNbIndents = _uiLogDepth;
367
368 while (uiNbIndents--) {
369
370 strIndent += " ";
371 }
372
373 // Log
Kevin Rocardace81f82012-12-11 16:19:17 +0100374 _pLogger->log(bIsWarning, strIndent + strLog);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200375 }
376}
377
378void CParameterMgr::nestLog() const
379{
Patrick Benavoli592ae562011-09-05 16:53:58 +0200380 _uiLogDepth++;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200381}
382
383void CParameterMgr::unnestLog() const
384{
Patrick Benavoli592ae562011-09-05 16:53:58 +0200385 _uiLogDepth--;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200386}
387
Patrick Benavoli63499d42011-10-24 18:50:03 +0200388// Version
389string CParameterMgr::getVersion() const
390{
391 string strVersion;
392
393 // Major
394 strVersion = toString(guiEditionMajor) + ".";
395 // Minor
396 strVersion += toString(guiEditionMinor) + ".";
397 // Revision
398 strVersion += toString(guiRevision);
399
400 return strVersion;
401}
402
Patrick Benavoli68a91282011-08-31 11:23:23 +0200403bool CParameterMgr::load(string& strError)
404{
405 CAutoLog autoLog(this, "Loading");
406
407 // Load Framework configuration
408 if (!loadFrameworkConfiguration(strError)) {
409
410 return false;
411 }
412
413 // Load subsystems
Kevin Rocardecf93102013-07-10 18:28:10 +0200414 if (!getSystemClass()->loadSubsystems(strError,
415 _pSubsystemPlugins, !_bFailOnMissingSubsystem)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200416
417 return false;
418 }
419
420 // Load structure
421 if (!loadStructure(strError)) {
422
423 return false;
424 }
425
426 // Load settings
427 if (!loadSettings(strError)) {
428
429 return false;
430 }
431
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200432 // Back synchronization for areas in parameter blackboard not covered by any domain
Kevin Rocardace81f82012-12-11 16:19:17 +0100433 CBackSynchronizer* pBackSynchronizer = createBackSynchronizer();
Patrick Benavoli68a91282011-08-31 11:23:23 +0200434
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200435 // Back-synchronize
Kevin Rocard57096bd2012-11-30 11:24:20 +0100436 {
437 CAutoLog autoLog(this, "Main blackboard back synchronization");
438
Kevin Rocard5d6e05a2013-01-21 15:57:45 +0100439 pBackSynchronizer->sync();
Kevin Rocard57096bd2012-11-30 11:24:20 +0100440
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200441 // Get rid of back synchronizer
442 delete pBackSynchronizer;
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200443 }
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200444
445 // We're done loading the settings and back synchronizing
446 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
447
448 // We need to ensure all domains are valid
449 pConfigurableDomains->validate(_pMainParameterBlackboard);
450
Kevin Rocard7f265822012-12-07 18:51:22 +0100451 // Log selection criterion states
452 {
453 CAutoLog autoLog(this, "Criterion states");
454
455 const CSelectionCriteria* selectionCriteria = getConstSelectionCriteria();
456
457 list<string> lstrSelectionCriteron;
458 selectionCriteria->listSelectionCriteria(lstrSelectionCriteron, true, false);
459
Kevin Rocard36299362013-02-04 14:57:47 +0100460 log_table(false, lstrSelectionCriteron);
Kevin Rocard7f265822012-12-07 18:51:22 +0100461 }
462
Kevin Rocard2fbe6e82013-03-26 17:09:29 +0100463 // Subsystem can not ask for resync as they have not been synced yet
464 getSystemClass()->cleanSubsystemsNeedToResync();
465
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100466 // At initialization, check subsystems that need resync
467 doApplyConfigurations(true);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200468
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200469 // Start remote processor server if appropriate
470 return handleRemoteProcessingInterface(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200471}
472
473bool CParameterMgr::loadFrameworkConfiguration(string& strError)
474{
475 CAutoLog autoLog(this, "Loading framework configuration");
476
Patrick Benavoli68a91282011-08-31 11:23:23 +0200477 // Parse Structure XML file
478 CXmlElementSerializingContext elementSerializingContext(strError);
479
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100480 if (!xmlParse(elementSerializingContext, getFrameworkConfiguration(), _strXmlConfigurationFilePath, _strXmlConfigurationFolderPath, EFrameworkConfigurationLibrary)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200481
482 return false;
483 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100484 // Set class name to system class and configurable domains
485 getSystemClass()->setName(getConstFrameworkConfiguration()->getSystemClassName());
486 getConfigurableDomains()->setName(getConstFrameworkConfiguration()->getSystemClassName());
487
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100488 // Get subsystem plugins elements
489 _pSubsystemPlugins = static_cast<const CSubsystemPlugins*>(getConstFrameworkConfiguration()->findChild("SubsystemPlugins"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200490
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100491 if (!_pSubsystemPlugins) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200492
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100493 strError = "Parameter Framework Configuration: couldn't find SubsystemPlugins element";
Patrick Benavoli68a91282011-08-31 11:23:23 +0200494
495 return false;
496 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200497
Patrick Benavoli68a91282011-08-31 11:23:23 +0200498 // Log tuning availability
Kevin Rocardace81f82012-12-11 16:19:17 +0100499 log_info("Tuning %s", getConstFrameworkConfiguration()->isTuningAllowed() ? "allowed" : "prohibited");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200500
501 return true;
502}
503
504bool CParameterMgr::loadStructure(string& strError)
505{
506 // Retrieve system to load structure to
507 CSystemClass* pSystemClass = getSystemClass();
508
Kevin Rocarde25ee792013-04-22 17:46:28 +0200509 log_info("Loading " + pSystemClass->getName() + " system class structure");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200510
511 // Get structure description element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100512 const CFrameworkConfigurationLocation* pStructureDescriptionFileLocation = static_cast<const CFrameworkConfigurationLocation*>(getConstFrameworkConfiguration()->findChildOfKind("StructureDescriptionFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200513
514 if (!pStructureDescriptionFileLocation) {
515
516 strError = "No StructureDescriptionFileLocation element found for SystemClass " + pSystemClass->getName();
517
518 return false;
519 }
520
521 // Get Xml structure folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100522 string strXmlStructureFolder = pStructureDescriptionFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200523
524 // Get Xml structure file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100525 string strXmlStructureFilePath = pStructureDescriptionFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200526
527 // Parse Structure XML file
528 CXmlParameterSerializingContext parameterBuildContext(strError);
529
Kevin Rocard57096bd2012-11-30 11:24:20 +0100530 CAutoLog autolog(pSystemClass, "Importing system structure from file " + strXmlStructureFilePath);
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200531
Patrick Benavoli68a91282011-08-31 11:23:23 +0200532 if (!xmlParse(parameterBuildContext, pSystemClass, strXmlStructureFilePath, strXmlStructureFolder, EParameterCreationLibrary)) {
533
534 return false;
535 }
536
537 // Initialize offsets
538 pSystemClass->setOffset(0);
539
540 // Initialize main blackboard's size
541 _pMainParameterBlackboard->setSize(pSystemClass->getFootPrint());
542
543 return true;
544}
545
546bool CParameterMgr::loadSettings(string& strError)
547{
Kevin Rocardd6909eb2013-07-18 09:13:51 +0200548 string strLoadError;
549 bool success = loadSettingsFromConfigFile(strLoadError);
550
551 if (!success && !_bFailOnFailedSettingsLoad) {
552 // Load can not fail, ie continue but log the load errors
553 log_info(strLoadError);
554 log_info("Failed to load settings, continue without domains.");
555 success = true;
556 }
557
558 if (!success) {
559 // Propagate the litteral error only if the function fails
560 strError = strLoadError;
561 return false;
562 }
563
564 return true;
565}
566
567bool CParameterMgr::loadSettingsFromConfigFile(string& strError)
568{
Patrick Benavoli68a91282011-08-31 11:23:23 +0200569 CAutoLog autoLog(this, "Loading settings");
570
571 // Get settings configuration element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100572 const CFrameworkConfigurationGroup* pParameterConfigurationGroup = static_cast<const CFrameworkConfigurationGroup*>(getConstFrameworkConfiguration()->findChildOfKind("SettingsConfiguration"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200573
574 if (!pParameterConfigurationGroup) {
575
576 // No settings to load
577
578 return true;
579 }
580 // Get binary settings file location
581 const CFrameworkConfigurationLocation* pBinarySettingsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("BinarySettingsFileLocation"));
582
583 string strXmlBinarySettingsFilePath;
584
585 if (pBinarySettingsFileLocation) {
586
587 // Get Xml binary settings file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100588 strXmlBinarySettingsFilePath = pBinarySettingsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200589 }
590
591 // Get configurable domains element
592 const CFrameworkConfigurationLocation* pConfigurableDomainsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("ConfigurableDomainsFileLocation"));
593
594 if (!pConfigurableDomainsFileLocation) {
595
596 strError = "No ConfigurableDomainsFileLocation element found for SystemClass " + getSystemClass()->getName();
597
598 return false;
Kevin Rocardd6909eb2013-07-18 09:13:51 +0200599 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200600 // Get destination root element
601 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
602
603 // Get Xml configuration domains file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100604 string strXmlConfigurationDomainsFilePath = pConfigurableDomainsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200605
606 // Get Xml configuration domains folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100607 string strXmlConfigurationDomainsFolder = pConfigurableDomainsFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200608
609 // Parse configuration domains XML file (ask to read settings from XML file if they are not provided as binary)
610 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, !pBinarySettingsFileLocation);
611
612 // Selection criteria definition for rule creation
613 xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
614
Patrick Benavoli63499d42011-10-24 18:50:03 +0200615 // Auto validation of configurations if no binary settings provided
616 xmlDomainSerializingContext.setAutoValidationRequired(!pBinarySettingsFileLocation);
617
Kevin Rocardace81f82012-12-11 16:19:17 +0100618 log_info("Importing configurable domains from file %s %s settings", strXmlConfigurationDomainsFilePath.c_str(), pBinarySettingsFileLocation ? "without" : "with");
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200619
Patrick Benavoli68a91282011-08-31 11:23:23 +0200620 // Do parse
621 if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strXmlConfigurationDomainsFilePath, strXmlConfigurationDomainsFolder, EParameterConfigurationLibrary, "SystemClassName")) {
622
623 return false;
624 }
625 // We have loaded the whole system structure, compute checksum
626 const CSystemClass* pSystemClass = getConstSystemClass();
627 _uiStructureChecksum = pSystemClass->computeStructureChecksum() + getConfigurableDomains()->computeStructureChecksum() + getSelectionCriteria()->computeStructureChecksum();
628
629 // Load binary settings if any provided
630 if (pBinarySettingsFileLocation && !pConfigurableDomains->serializeSettings(strXmlBinarySettingsFilePath, false, _uiStructureChecksum, strError)) {
631
632 return false;
633 }
634
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200635 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200636}
637
638// XML parsing
639bool CParameterMgr::xmlParse(CXmlElementSerializingContext& elementSerializingContext, CElement* pRootElement, const string& strXmlFilePath, const string& strXmlFolder, CParameterMgr::ElementLibrary eElementLibrary, const string& strNameAttrituteName)
640{
641 // Init serializing context
642 elementSerializingContext.set(_pElementLibrarySet->getElementLibrary(eElementLibrary), strXmlFolder, _strSchemaFolderLocation);
643
644 // Get Schema file associated to root element
645 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pRootElement->getKind() + ".xsd";
646
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200647 CXmlFileDocSource fileDocSource(strXmlFilePath, strXmlSchemaFilePath, pRootElement->getKind(), pRootElement->getName(), strNameAttrituteName);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200648
649 // Start clean
650 pRootElement->clean();
651
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200652 CXmlMemoryDocSink memorySink(pRootElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200653
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200654 if (!memorySink.process(fileDocSource, elementSerializingContext)) {
655 //Cleanup
Patrick Benavoli68a91282011-08-31 11:23:23 +0200656 pRootElement->clean();
657
658 return false;
659 }
660
Patrick Benavoli68a91282011-08-31 11:23:23 +0200661 return true;
662}
663
664// Init
665bool CParameterMgr::init(string& strError)
666{
667 return base::init(strError);
668}
669
670// Selection criteria interface
671CSelectionCriterionType* CParameterMgr::createSelectionCriterionType(bool bIsInclusive)
672{
673 // Propagate
674 return getSelectionCriteria()->createSelectionCriterionType(bIsInclusive);
675}
676
677CSelectionCriterion* CParameterMgr::createSelectionCriterion(const string& strName, const CSelectionCriterionType* pSelectionCriterionType)
678{
679 // Propagate
680 return getSelectionCriteria()->createSelectionCriterion(strName, pSelectionCriterionType);
681}
682
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200683// Selection criterion retrieval
684CSelectionCriterion* CParameterMgr::getSelectionCriterion(const string& strName)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200685{
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200686 // Propagate
687 return getSelectionCriteria()->getSelectionCriterion(strName);
688}
689
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100690// Configuration application
Kevin Rocardace81f82012-12-11 16:19:17 +0100691void CParameterMgr::applyConfigurations()
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200692{
693 CAutoLog autoLog(this, "Configuration application request");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200694
695 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +0100696 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200697
698 if (!_bTuningModeIsOn) {
699
700 // Apply configuration(s)
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100701 doApplyConfigurations(false);
Frédéric Boisnarddaaa63c2012-08-27 15:48:15 +0200702 } else {
703
Kevin Rocardace81f82012-12-11 16:19:17 +0100704 log_warning("Configurations were not applied because the TuningMode is on");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200705 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200706}
707
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200708// Get the configurableElement corresponding to the given path
709const CConfigurableElement* CParameterMgr::getConfigurableElement(const string& strPath,
710 string& strError) const
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200711{
Patrick Benavoli065264a2011-11-20 15:46:41 +0100712 CPathNavigator pathNavigator(strPath);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200713
Patrick Benavoli065264a2011-11-20 15:46:41 +0100714 // Nagivate through system class
715 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
716
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100717 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100718 }
719
720 // Find element
721 const CElement* pElement = getConstSystemClass()->findDescendant(pathNavigator);
722
723 if (!pElement) {
724
Kevin Rocard4c3f8d82013-11-21 12:16:28 +0100725 strError = "Path not found: " + strPath;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100726
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100727 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100728 }
729
730 // Check found element is a parameter
731 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pElement);
732
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200733 return pConfigurableElement;
734}
735
736// Dynamic parameter handling
737CParameterHandle* CParameterMgr::createParameterHandle(const string& strPath, string& strError)
738{
739 const CConfigurableElement* pConfigurableElement = getConfigurableElement(strPath, strError);
740
741 if (!pConfigurableElement) {
742
743 // Element not found
Kevin Rocard4c3f8d82013-11-21 12:16:28 +0100744 strError = "Element not found: " + strPath;
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200745 return NULL;
746 }
747
Patrick Benavoli065264a2011-11-20 15:46:41 +0100748 if (!pConfigurableElement->isParameter()) {
749
750 // Element is not parameter
Kevin Rocard4c3f8d82013-11-21 12:16:28 +0100751 strError = "Not a parameter: " + strPath;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100752
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100753 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100754 }
755
756 // Convert as parameter and return new handle
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200757 return new CParameterHandle(static_cast<const CBaseParameter*>(pConfigurableElement), this);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200758}
759
Kevin Rocardecf93102013-07-10 18:28:10 +0200760void CParameterMgr::setFailureOnMissingSubsystem(bool bFail)
761{
762 _bFailOnMissingSubsystem = bFail;
763}
764
765bool CParameterMgr::getFailureOnMissingSubsystem() const
766{
767 return _bFailOnMissingSubsystem;
768}
Kevin Rocardd6909eb2013-07-18 09:13:51 +0200769
770void CParameterMgr::setFailureOnFailedSettingsLoad(bool bFail)
771{
772 _bFailOnFailedSettingsLoad = bFail;
773}
774bool CParameterMgr::getFailureOnFailedSettingsLoad()
775{
776 return _bFailOnFailedSettingsLoad;
777}
Patrick Benavoli68a91282011-08-31 11:23:23 +0200778/////////////////// Remote command parsers
Patrick Benavoli592ae562011-09-05 16:53:58 +0200779/// Version
Patrick Benavoli63499d42011-10-24 18:50:03 +0200780CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::versionCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli592ae562011-09-05 16:53:58 +0200781{
782 (void)remoteCommand;
783
Patrick Benavoli63499d42011-10-24 18:50:03 +0200784 // Show version
785 strResult = getVersion();
Patrick Benavoli592ae562011-09-05 16:53:58 +0200786
Patrick Benavoli63499d42011-10-24 18:50:03 +0200787 return CCommandHandler::ESucceeded;
Patrick Benavoli592ae562011-09-05 16:53:58 +0200788}
789
Patrick Benavoli68a91282011-08-31 11:23:23 +0200790/// Status
Patrick Benavoli63499d42011-10-24 18:50:03 +0200791CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::statusCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200792{
793 (void)remoteCommand;
794 // System class
795 const CSystemClass* pSystemClass = getSystemClass();
796
Patrick Benavoli68a91282011-08-31 11:23:23 +0200797 // Show status
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200798 /// General section
799 appendTitle(strResult, "General:");
800 // System class
Patrick Benavoli68a91282011-08-31 11:23:23 +0200801 strResult += "System Class: ";
802 strResult += pSystemClass->getName();
803 strResult += "\n";
804
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200805 // Tuning mode
Patrick Benavoli68a91282011-08-31 11:23:23 +0200806 strResult += "Tuning Mode: ";
807 strResult += tuningModeOn() ? "on" : "off";
808 strResult += "\n";
809
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200810 // Value space
Patrick Benavoli68a91282011-08-31 11:23:23 +0200811 strResult += "Value Space: ";
812 strResult += valueSpaceIsRaw() ? "raw" : "real";
813 strResult += "\n";
814
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200815 // Output raw format
816 strResult += "Output Raw Format: ";
817 strResult += outputRawFormatIsHex() ? "hex" : "dec";
818 strResult += "\n";
819
820 // Auto Sync
Patrick Benavoli68a91282011-08-31 11:23:23 +0200821 strResult += "Auto Sync: ";
822 strResult += autoSyncOn() ? "on" : "off";
823 strResult += "\n";
824
825 /// Subsystem list
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200826 appendTitle(strResult, "Subsystems:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200827 string strSubsystemList;
828 pSystemClass->listChildrenPaths(strSubsystemList);
829 strResult += strSubsystemList;
830
831 /// Last applied configurations
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200832 appendTitle(strResult, "Last Applied [Pending] Configurations:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200833 string strLastAppliedConfigurations;
834 getConfigurableDomains()->listLastAppliedConfigurations(strLastAppliedConfigurations);
835 strResult += strLastAppliedConfigurations;
836
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200837 /// Criteria states
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200838 appendTitle(strResult, "Selection Criteria:");
Kevin Rocard7f265822012-12-07 18:51:22 +0100839 list<string> lstrSelectionCriteria;
840 getSelectionCriteria()->listSelectionCriteria(lstrSelectionCriteria, false, true);
841 // Concatenate the criterion list as the command result
Frederic Boisnard390b36d2013-05-23 15:28:31 +0200842 string strCriteriaStates;
843 CUtility::asString(lstrSelectionCriteria, strCriteriaStates);
844 strResult += strCriteriaStates;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200845
Patrick Benavoli63499d42011-10-24 18:50:03 +0200846 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200847}
848
849/// Tuning Mode
Patrick Benavoli63499d42011-10-24 18:50:03 +0200850CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200851{
852 if (remoteCommand.getArgument(0) == "on") {
853
854 if (setTuningMode(true, strResult)) {
855
Patrick Benavoli63499d42011-10-24 18:50:03 +0200856 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200857 }
858 } else if (remoteCommand.getArgument(0) == "off") {
859
860 if (setTuningMode(false, strResult)) {
861
Patrick Benavoli63499d42011-10-24 18:50:03 +0200862 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200863 }
864 } else {
865 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200866 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200867 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200868 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200869}
870
Patrick Benavoli63499d42011-10-24 18:50:03 +0200871CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200872{
873 (void)remoteCommand;
874
875 strResult = tuningModeOn() ? "on" : "off";
876
Patrick Benavoli63499d42011-10-24 18:50:03 +0200877 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200878}
879
880/// Value Space
Patrick Benavoli63499d42011-10-24 18:50:03 +0200881CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200882{
883 (void)strResult;
884
885 if (remoteCommand.getArgument(0) == "raw") {
886
887 setValueSpace(true);
888
Patrick Benavoli63499d42011-10-24 18:50:03 +0200889 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200890
891 } else if (remoteCommand.getArgument(0) == "real") {
892
893 setValueSpace(false);
894
Patrick Benavoli63499d42011-10-24 18:50:03 +0200895 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200896
897 } else {
898 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200899 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200900 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200901 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200902}
903
Patrick Benavoli63499d42011-10-24 18:50:03 +0200904CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200905{
906 (void)remoteCommand;
907
908 strResult = valueSpaceIsRaw() ? "raw" : "real";
909
Patrick Benavoli63499d42011-10-24 18:50:03 +0200910 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200911}
912
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200913/// Output Raw Format
Patrick Benavoli63499d42011-10-24 18:50:03 +0200914CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200915{
916 (void)strResult;
917
918 if (remoteCommand.getArgument(0) == "hex") {
919
920 setOutputRawFormat(true);
921
Patrick Benavoli63499d42011-10-24 18:50:03 +0200922 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200923
924 } else if (remoteCommand.getArgument(0) == "dec") {
925
926 setOutputRawFormat(false);
927
Patrick Benavoli63499d42011-10-24 18:50:03 +0200928 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200929
930 } else {
931 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200932 return CCommandHandler::EShowUsage;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200933 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200934 return CCommandHandler::EFailed;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200935}
936
Patrick Benavoli63499d42011-10-24 18:50:03 +0200937CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200938{
939 (void)remoteCommand;
940
941 strResult = outputRawFormatIsHex() ? "hex" : "dec";
942
Patrick Benavoli63499d42011-10-24 18:50:03 +0200943 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200944}
945
Patrick Benavoli68a91282011-08-31 11:23:23 +0200946/// Sync
Patrick Benavoli63499d42011-10-24 18:50:03 +0200947CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200948{
949 if (remoteCommand.getArgument(0) == "on") {
950
951 if (setAutoSync(true, strResult)) {
952
Patrick Benavoli63499d42011-10-24 18:50:03 +0200953 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200954 }
955 } else if (remoteCommand.getArgument(0) == "off") {
956
957 if (setAutoSync(false, strResult)) {
958
Patrick Benavoli63499d42011-10-24 18:50:03 +0200959 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200960 }
961 } else {
962 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200963 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200964 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200965 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200966}
967
Patrick Benavoli63499d42011-10-24 18:50:03 +0200968CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200969{
970 (void)remoteCommand;
971
972 strResult = autoSyncOn() ? "on" : "off";
973
Patrick Benavoli63499d42011-10-24 18:50:03 +0200974 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200975}
976
Patrick Benavoli63499d42011-10-24 18:50:03 +0200977CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::syncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200978{
979 (void)remoteCommand;
980
Patrick Benavoli63499d42011-10-24 18:50:03 +0200981 return sync(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200982}
983
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200984/// Criteria
Patrick Benavoli63499d42011-10-24 18:50:03 +0200985CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listCriteriaCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200986{
987 (void)remoteCommand;
988
Kevin Rocard4eae8272013-04-18 19:12:46 +0200989 bool humanReadable = true;
Kevin Rocard7f265822012-12-07 18:51:22 +0100990
Kevin Rocard4eae8272013-04-18 19:12:46 +0200991 // Look for optional arguments
992 if (remoteCommand.getArgumentCount() >= 1) {
993
994 // If csv is provided, format the criterion list in Commas Separated Value pairs
995 if (remoteCommand.getArgument(0) == "csv") {
996 humanReadable = false;
997 } else {
998 return CCommandHandler::EShowUsage;
999 }
1000 }
1001
1002 list<string> lstrResult;
1003 getSelectionCriteria()->listSelectionCriteria(lstrResult, true, humanReadable);
Kevin Rocard7f265822012-12-07 18:51:22 +01001004
1005 // Concatenate the criterion list as the command result
Frederic Boisnard390b36d2013-05-23 15:28:31 +02001006 CUtility::asString(lstrResult, strResult);
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001007
Patrick Benavoli63499d42011-10-24 18:50:03 +02001008 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001009}
Patrick Benavoli68a91282011-08-31 11:23:23 +02001010
1011/// Domains
Patrick Benavoli63499d42011-10-24 18:50:03 +02001012CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001013{
1014 (void)remoteCommand;
1015
Patrick Benavoli63499d42011-10-24 18:50:03 +02001016 getConfigurableDomains()->listDomains(strResult);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001017
Patrick Benavoli63499d42011-10-24 18:50:03 +02001018 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001019}
1020
Patrick Benavoli63499d42011-10-24 18:50:03 +02001021CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001022{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001023 return createDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001024}
1025
Patrick Benavoli63499d42011-10-24 18:50:03 +02001026CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001027{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001028 return deleteDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001029}
1030
Kevin Rocard170f0a42012-06-18 13:56:05 +02001031CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteAllDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1032{
1033 (void)remoteCommand;
1034
1035 return deleteAllDomains(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1036}
1037
Patrick Benavoli63499d42011-10-24 18:50:03 +02001038CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001039{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001040 return getConfigurableDomains()->renameDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001041}
1042
Patrick Benavoli63499d42011-10-24 18:50:03 +02001043CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001044{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001045 // Check tuning mode
1046 if (!checkTuningModeOn(strResult)) {
1047
1048 return CCommandHandler::EFailed;
1049 }
1050
1051 // Set property
1052 bool bSequenceAware;
1053
1054 if (remoteCommand.getArgument(1) == "true") {
1055
1056 bSequenceAware = true;
1057
1058 } else if (remoteCommand.getArgument(1) == "false") {
1059
1060 bSequenceAware = false;
1061
1062 } else {
1063 // Show usage
1064 return CCommandHandler::EShowUsage;
1065 }
1066
1067 return getConfigurableDomains()->setSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001068}
1069
Patrick Benavoli63499d42011-10-24 18:50:03 +02001070CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001071{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001072 // Get property
1073 bool bSequenceAware;
1074
1075 if (!getConfigurableDomains()->getSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult)) {
1076
1077 return CCommandHandler::EFailed;
1078 }
1079
1080 strResult = bSequenceAware ? "true" : "false";
1081
1082 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001083}
1084
Patrick Benavoli63499d42011-10-24 18:50:03 +02001085CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001086{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001087 return getConfigurableDomains()->listDomainElements(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001088}
1089
Patrick Benavoli63499d42011-10-24 18:50:03 +02001090CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::addElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001091{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001092 return addConfigurableElementToDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1093}
1094
1095CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::removeElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1096{
1097 return removeConfigurableElementFromDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1098}
1099
1100CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::splitDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1101{
1102 return split(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001103}
1104
1105/// Configurations
Patrick Benavoli63499d42011-10-24 18:50:03 +02001106CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConfigurationsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001107{
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001108 return getConstConfigurableDomains()->listConfigurations(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
1109}
1110
1111CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1112{
1113 (void)remoteCommand;
1114
1115 // Dummy error context
1116 string strError;
1117 CErrorContext errorContext(strError);
1118
1119 // Dump
1120 getConstConfigurableDomains()->dumpContent(strResult, errorContext);
1121
1122 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001123}
1124
Patrick Benavoli63499d42011-10-24 18:50:03 +02001125CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001126{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001127 return createConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001128}
1129
Patrick Benavoli63499d42011-10-24 18:50:03 +02001130CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001131{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001132 return deleteConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001133}
1134
Patrick Benavoli63499d42011-10-24 18:50:03 +02001135CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001136{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001137 return getConfigurableDomains()->renameConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001138}
1139
Patrick Benavoli63499d42011-10-24 18:50:03 +02001140CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::saveConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001141{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001142 return saveConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001143}
1144
Patrick Benavoli63499d42011-10-24 18:50:03 +02001145CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::restoreConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001146{
Kevin Rocardace81f82012-12-11 16:19:17 +01001147 list<string> lstrResult;
1148 if (!restoreConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), lstrResult)) {
1149 //Concatenate the error list as the command result
Frederic Boisnard390b36d2013-05-23 15:28:31 +02001150 CUtility::asString(lstrResult, strResult);
Kevin Rocardace81f82012-12-11 16:19:17 +01001151
1152 return CCommandHandler::EFailed;
1153 }
1154 return CCommandHandler::EDone;
Patrick Benavoli63499d42011-10-24 18:50:03 +02001155}
1156
1157CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1158{
1159 // Check tuning mode
1160 if (!checkTuningModeOn(strResult)) {
1161
1162 return CCommandHandler::EFailed;
1163 }
1164
1165 // Build configurable element path list
1166 vector<string> astrNewElementSequence;
1167
1168 uint32_t uiArgument;
1169
1170 for (uiArgument = 2; uiArgument < remoteCommand.getArgumentCount(); uiArgument++) {
1171
1172 astrNewElementSequence.push_back(remoteCommand.getArgument(uiArgument));
1173 }
1174
1175 // Delegate to configurable domains
1176 return getConfigurableDomains()->setElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), astrNewElementSequence, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1177}
1178
1179CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1180{
1181 // Delegate to configurable domains
1182 return getConfigurableDomains()->getElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001183}
1184
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001185CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1186{
1187 // Delegate to configurable domains
1188 return getConfigurableDomains()->setApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.packArguments(2, remoteCommand.getArgumentCount() - 2), getConstSelectionCriteria()->getSelectionCriteriaDefinition(), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1189}
1190
1191CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::clearRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1192{
1193 // Delegate to configurable domains
1194 return getConfigurableDomains()->clearApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1195}
1196
1197CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1198{
1199 // Delegate to configurable domains
1200 return getConfigurableDomains()->getApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
1201}
1202
Patrick Benavoli68a91282011-08-31 11:23:23 +02001203/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001204CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001205{
1206 CElementLocator elementLocator(getSystemClass(), false);
1207
1208 CElement* pLocatedElement = NULL;
1209
1210 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1211
Patrick Benavoli63499d42011-10-24 18:50:03 +02001212 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001213 }
1214
1215 strResult = string("\n");
1216
1217 if (!pLocatedElement) {
1218
1219 // List from root folder
1220
1221 // Return system class qualified name
1222 pLocatedElement = getSystemClass();
1223 }
1224
1225 // Return sub-elements
1226 strResult += pLocatedElement->listQualifiedPaths(false);
1227
Patrick Benavoli63499d42011-10-24 18:50:03 +02001228 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001229}
1230
1231/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001232CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listParametersCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001233{
1234 CElementLocator elementLocator(getSystemClass(), false);
1235
1236 CElement* pLocatedElement = NULL;
1237
1238 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1239
Patrick Benavoli63499d42011-10-24 18:50:03 +02001240 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001241 }
1242
1243 strResult = string("\n");
1244
1245 if (!pLocatedElement) {
1246
1247 // List from root folder
1248
1249 // Return system class qualified name
1250 pLocatedElement = getSystemClass();
1251 }
1252
1253 // Return sub-elements
1254 strResult += pLocatedElement->listQualifiedPaths(true);
1255
Patrick Benavoli63499d42011-10-24 18:50:03 +02001256 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001257}
1258
Patrick Benavoli63499d42011-10-24 18:50:03 +02001259CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001260{
1261 CElementLocator elementLocator(getSystemClass());
1262
1263 CElement* pLocatedElement = NULL;
1264
1265 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1266
Patrick Benavoli63499d42011-10-24 18:50:03 +02001267 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001268 }
1269
1270 string strError;
1271
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001272 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001273
1274 // Dump elements
1275 pLocatedElement->dumpContent(strResult, parameterAccessContext);
1276
Patrick Benavoli63499d42011-10-24 18:50:03 +02001277 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001278}
1279
Patrick Benavoli63499d42011-10-24 18:50:03 +02001280CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSizeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001281{
1282 CElementLocator elementLocator(getSystemClass());
1283
1284 CElement* pLocatedElement = NULL;
1285
1286 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1287
Patrick Benavoli63499d42011-10-24 18:50:03 +02001288 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001289 }
1290
1291 // Converted to actual sizable element
1292 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1293
1294 // Get size as string
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001295 strResult = pConfigurableElement->getFootprintAsString();
Patrick Benavoli68a91282011-08-31 11:23:23 +02001296
Patrick Benavoli63499d42011-10-24 18:50:03 +02001297 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001298}
1299
Patrick Benavoli63499d42011-10-24 18:50:03 +02001300CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showPropertiesCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001301{
1302 CElementLocator elementLocator(getSystemClass());
1303
1304 CElement* pLocatedElement = NULL;
1305
1306 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1307
Patrick Benavoli63499d42011-10-24 18:50:03 +02001308 return CCommandHandler::EFailed;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001309 }
1310
1311 // Convert element
1312 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1313
1314 // Return element properties
1315 pConfigurableElement->showProperties(strResult);
1316
Patrick Benavoli63499d42011-10-24 18:50:03 +02001317 return CCommandHandler::ESucceeded;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001318}
1319
Patrick Benavoli63499d42011-10-24 18:50:03 +02001320CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001321{
1322 string strValue;
1323
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001324 if (!accessParameterValue(remoteCommand.getArgument(0), strValue, false, strResult)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001325
Patrick Benavoli63499d42011-10-24 18:50:03 +02001326 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001327 }
1328 // Succeeded
1329 strResult = strValue;
1330
Patrick Benavoli63499d42011-10-24 18:50:03 +02001331 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001332}
1333
Patrick Benavoli63499d42011-10-24 18:50:03 +02001334CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001335{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001336 // Check tuning mode
1337 if (!checkTuningModeOn(strResult)) {
1338
1339 return CCommandHandler::EFailed;
1340 }
1341 // Get value to set
1342 string strValue = remoteCommand.packArguments(1, remoteCommand.getArgumentCount() - 1);
1343
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001344 return accessParameterValue(remoteCommand.getArgument(0), strValue, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001345}
1346
Patrick Benavoli63499d42011-10-24 18:50:03 +02001347CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listBelongingDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001348{
1349 CElementLocator elementLocator(getSystemClass());
1350
1351 CElement* pLocatedElement = NULL;
1352
1353 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1354
Patrick Benavoli63499d42011-10-24 18:50:03 +02001355 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001356 }
1357
1358 // Convert element
1359 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1360
1361 // Return element belonging domains
1362 pConfigurableElement->listBelongingDomains(strResult);
1363
Patrick Benavoli63499d42011-10-24 18:50:03 +02001364 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001365}
1366
Patrick Benavoli63499d42011-10-24 18:50:03 +02001367CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001368{
1369 CElementLocator elementLocator(getSystemClass());
1370
1371 CElement* pLocatedElement = NULL;
1372
1373 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1374
Patrick Benavoli63499d42011-10-24 18:50:03 +02001375 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001376 }
1377
1378 // Convert element
1379 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1380
1381 // Return element belonging domains
1382 pConfigurableElement->listAssociatedDomains(strResult);
1383
Patrick Benavoli63499d42011-10-24 18:50:03 +02001384 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001385}
1386
Patrick Benavoli63499d42011-10-24 18:50:03 +02001387CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001388{
1389 (void)remoteCommand;
1390
1391 getConfigurableDomains()->listAssociatedElements(strResult);
1392
Patrick Benavoli63499d42011-10-24 18:50:03 +02001393 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001394}
1395
Patrick Benavoli63499d42011-10-24 18:50:03 +02001396CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConflictingElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001397{
1398 (void)remoteCommand;
1399
1400 getConfigurableDomains()->listConflictingElements(strResult);
1401
Patrick Benavoli63499d42011-10-24 18:50:03 +02001402 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001403}
1404
Patrick Benavoli63499d42011-10-24 18:50:03 +02001405CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listRogueElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001406{
1407 (void)remoteCommand;
1408
1409 getSystemClass()->listRogueElements(strResult);
1410
Patrick Benavoli63499d42011-10-24 18:50:03 +02001411 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001412}
1413
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001414CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getConfigurationParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1415{
1416 string strOutputValue;
1417 string strError;
1418
1419 if (!accessConfigurationValue(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), strOutputValue, false, strError)) {
1420
1421 strResult = strError;
1422 return CCommandHandler::EFailed;
1423 }
1424 // Succeeded
1425 strResult = strOutputValue;
1426
1427 return CCommandHandler::ESucceeded;
1428}
1429
1430CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setConfigurationParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1431{
1432 // Get value to set
1433 string strValue = remoteCommand.packArguments(3, remoteCommand.getArgumentCount() - 3);
1434
1435 bool bSuccess = accessConfigurationValue(remoteCommand.getArgument(0),
1436 remoteCommand.getArgument(1),
1437 remoteCommand.getArgument(2),
1438 strValue, true, strResult);
1439
1440 return bSuccess ? CCommandHandler::EDone : CCommandHandler::EFailed;
1441}
1442
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +02001443CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showMappingCommmandProcess(
1444 const IRemoteCommand& remoteCommand,
1445 string& strResult)
1446{
1447 if (!getParameterMapping(remoteCommand.getArgument(0), strResult)) {
1448
1449 return CCommandHandler::EFailed;
1450 }
1451
1452 return CCommandHandler::ESucceeded;
1453}
1454
Patrick Benavoli68a91282011-08-31 11:23:23 +02001455/// Settings Import/Export
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001456CParameterMgr::CCommandHandler::CommandStatus
1457 CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess(
1458 const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001459{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001460 string strFileName = remoteCommand.getArgument(0);
1461 return exportDomainsXml(strFileName, false, true, strResult) ?
1462 CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001463}
1464
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001465CParameterMgr::CCommandHandler::CommandStatus
1466 CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess(
1467 const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001468{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001469 return importDomainsXml(remoteCommand.getArgument(0), false, true, strResult) ?
1470 CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001471}
1472
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001473CParameterMgr::CCommandHandler::CommandStatus
1474 CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess(
1475 const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001476{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001477 string strFileName = remoteCommand.getArgument(0);
1478 return exportDomainsXml(strFileName, true, true, strResult) ?
1479 CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001480}
1481
Patrick Benavoli63499d42011-10-24 18:50:03 +02001482CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001483{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001484 return importDomainsXml(remoteCommand.getArgument(0), true, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001485}
1486
Patrick Benavoli63499d42011-10-24 18:50:03 +02001487CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001488{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001489 return exportDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001490}
1491
Patrick Benavoli63499d42011-10-24 18:50:03 +02001492CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001493{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001494 return importDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001495}
1496
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001497CParameterMgr::CCommandHandler::CommandStatus
1498 CParameterMgr::getConfigurableDomainsWithSettingsXMLCommmandProcess(
1499 const IRemoteCommand& remoteCommand, string& strResult)
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001500{
1501 (void)remoteCommand;
1502
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001503 if (!exportDomainsXml(strResult, true, false, strResult)) {
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001504
1505 return CCommandHandler::EFailed;
1506 }
1507 // Succeeded
1508 return CCommandHandler::ESucceeded;
1509}
1510
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001511CParameterMgr::CCommandHandler::CommandStatus
1512 CParameterMgr::setConfigurableDomainsWithSettingsXMLCommmandProcess(
1513 const IRemoteCommand& remoteCommand, string& strResult)
1514{
1515 return importDomainsXml(remoteCommand.getArgument(0), true, false, strResult) ?
1516 CCommandHandler::EDone : CCommandHandler::EFailed;
1517}
1518
1519CParameterMgr::CCommandHandler::CommandStatus
1520 CParameterMgr::getSystemClassXMLCommmandProcess(
1521 const IRemoteCommand& remoteCommand, string& strResult)
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001522{
1523 (void)remoteCommand;
1524
1525 if (!getSystemClassXMLString(strResult)) {
1526
1527 return CCommandHandler::EFailed;
1528 }
1529 // Succeeded
1530 return CCommandHandler::ESucceeded;
1531}
1532
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001533// User set/get parameters in main BlackBoard
1534bool CParameterMgr::accessParameterValue(const string& strPath, string& strValue, bool bSet, string& strError)
1535{
1536 // Define context
1537 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
1538
Frédéric Boisnard150407c2013-03-15 14:46:23 +01001539 // Activate the auto synchronization with the hardware
1540 if (bSet) {
1541
1542 parameterAccessContext.setAutoSync(_bAutoSyncOn);
1543 }
1544
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001545 return accessValue(parameterAccessContext, strPath, strValue, bSet, strError);
1546}
1547
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +02001548// User get parameter mapping
1549bool CParameterMgr::getParameterMapping(const string& strPath, string& strResult) const
1550{
1551 CPathNavigator pathNavigator(strPath);
1552
1553 // Nagivate through system class
1554 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strResult)) {
1555
1556 return false;
1557 }
1558
1559 // Get the ConfigurableElement corresponding to strPath
1560 const CConfigurableElement* pConfigurableElement = getConfigurableElement(strPath, strResult);
1561 if (!pConfigurableElement) {
1562
1563 return false;
1564 }
1565
1566 // Find the list of the ancestors of the current ConfigurableElement that have a mapping
1567 list<const CConfigurableElement*> configurableElementPath;
1568 pConfigurableElement->getListOfElementsWithMapping(configurableElementPath);
1569
1570 // Get the Subsystem containing the ConfigurableElement
1571 const CSubsystem* pSubsystem = pConfigurableElement->getBelongingSubsystem();
1572 if (!pSubsystem) {
1573
1574 strResult = "Unable to find the Subsystem containing the parameter";
1575 return false;
1576 }
1577
1578 // Fetch the mapping corresponding to the ConfigurableElement
1579 strResult = pSubsystem->getMapping(configurableElementPath);
1580
1581 return true;
1582}
1583
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001584// User set/get parameters in specific Configuration BlackBoard
1585bool CParameterMgr::accessConfigurationValue(const string& strDomain, const string& strConfiguration, const string& strPath, string& strValue, bool bSet, string& strError)
1586{
1587 CElementLocator elementLocator(getSystemClass());
1588
1589 CElement* pLocatedElement = NULL;
1590
1591 if (!elementLocator.locate(strPath, &pLocatedElement, strError)) {
1592
1593 return false;
1594 }
1595
1596 // Convert element
1597 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1598
1599 // Get the Configuration blackboard and the Base Offset of the configurable element in this blackboard
1600 uint32_t uiBaseOffset;
1601 bool bIsLastApplied;
1602
1603 CParameterBlackboard* pConfigurationBlackboard = getConstConfigurableDomains()->findConfigurationBlackboard(strDomain, strConfiguration, pConfigurableElement, uiBaseOffset, bIsLastApplied, strError);
1604
1605 if (!pConfigurationBlackboard) {
1606
1607 return false;
1608 }
1609
1610 log_info("Element %s in Domain %s, offset: %d, base offset: %d", strPath.c_str(), strDomain.c_str(), pConfigurableElement->getOffset(), uiBaseOffset);
1611
1612 /// Update the Configuration Blackboard
1613
Frédéric Boisnard150407c2013-03-15 14:46:23 +01001614 // Define Configuration context using Base Offset and keep Auto Sync off to prevent access to HW
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001615 CParameterAccessContext parameterAccessContext(strError, pConfigurationBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex, uiBaseOffset);
1616
1617 // Access Value in the Configuration Blackboard
1618 if (!accessValue(parameterAccessContext, strPath, strValue, bSet, strError)) {
1619
1620 return false;
1621 }
1622
1623 /// If the Configuration is the last one applied, update the Main Blackboard as well
1624
1625 if (bIsLastApplied) {
1626
1627 // Define Main context
1628 parameterAccessContext.setParameterBlackboard(_pMainParameterBlackboard);
1629
Frédéric Boisnard150407c2013-03-15 14:46:23 +01001630 // Activate the auto synchronization with the hardware
1631 if (bSet) {
1632
1633 parameterAccessContext.setAutoSync(_bAutoSyncOn);
1634 }
1635
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001636 // Access Value in the Main Blackboard
1637 return accessValue(parameterAccessContext, strPath, strValue, bSet, strError);
1638 }
1639
1640 return true;
1641}
1642
Patrick Benavoli68a91282011-08-31 11:23:23 +02001643// User set/get parameters
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001644bool CParameterMgr::accessValue(CParameterAccessContext& parameterAccessContext, const string& strPath, string& strValue, bool bSet, string& strError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001645{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001646 // Lock state
1647 CAutoLock autoLock(&_blackboardMutex);
1648
1649 CPathNavigator pathNavigator(strPath);
1650
1651 // Nagivate through system class
1652 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001653
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +02001654 parameterAccessContext.setError(strError);
1655
Patrick Benavoli68a91282011-08-31 11:23:23 +02001656 return false;
1657 }
1658
Patrick Benavoli065264a2011-11-20 15:46:41 +01001659 // Do the get
1660 return getConstSystemClass()->accessValue(pathNavigator, strValue, bSet, parameterAccessContext);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001661}
1662
1663// Tuning mode
1664bool CParameterMgr::setTuningMode(bool bOn, string& strError)
1665{
1666 // Tuning allowed?
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001667 if (bOn && !getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001668
1669 strError = "Tuning prohibited";
1670
1671 return false;
1672 }
1673 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +01001674 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001675
1676 // Warn domains about exiting tuning mode
1677 if (!bOn && _bTuningModeIsOn) {
1678
1679 // Ensure application of currently selected configurations
Patrick Benavoli1387bda2011-08-31 11:23:24 +02001680 // Force-apply configurations
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01001681 doApplyConfigurations(true);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001682
Patrick Benavoli68a91282011-08-31 11:23:23 +02001683 // Turn auto sync back on
1684 _bAutoSyncOn = true;
1685 }
1686
1687 // Store
1688 _bTuningModeIsOn = bOn;
1689
Patrick Benavoli68a91282011-08-31 11:23:23 +02001690 return true;
1691}
1692
1693bool CParameterMgr::tuningModeOn() const
1694{
1695 return _bTuningModeIsOn;
1696}
1697
1698// Current value space for user set/get value interpretation
1699void CParameterMgr::setValueSpace(bool bIsRaw)
1700{
1701 _bValueSpaceIsRaw = bIsRaw;
1702}
1703
1704bool CParameterMgr::valueSpaceIsRaw()
1705{
1706 return _bValueSpaceIsRaw;
1707}
1708
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001709// Current Output Raw Format for user get value interpretation
1710void CParameterMgr::setOutputRawFormat(bool bIsHex)
1711{
1712 _bOutputRawFormatIsHex = bIsHex;
1713}
1714
1715bool CParameterMgr::outputRawFormatIsHex()
1716{
1717 return _bOutputRawFormatIsHex;
1718}
1719
Patrick Benavoli68a91282011-08-31 11:23:23 +02001720/// Sync
1721// Automatic hardware synchronization control (during tuning session)
1722bool CParameterMgr::setAutoSync(bool bAutoSyncOn, string& strError)
1723{
1724 // Check tuning mode
1725 if (!checkTuningModeOn(strError)) {
1726
1727 return false;
1728 }
1729 // Warn domains about turning auto sync back on
1730 if (bAutoSyncOn && !_bAutoSyncOn) {
1731
Patrick Benavoli592ae562011-09-05 16:53:58 +02001732 // Do the synchronization at system class level (could be optimized by keeping track of all modified parameters)
1733 if (!sync(strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001734
1735 return false;
1736 }
1737 }
1738
1739 // Set Auto sync
1740 _bAutoSyncOn = bAutoSyncOn;
1741
1742 return true;
1743}
1744
1745bool CParameterMgr::autoSyncOn() const
1746{
1747 return _bAutoSyncOn;
1748}
1749
1750// Manual hardware synchronization control (during tuning session)
1751bool CParameterMgr::sync(string& strError)
1752{
1753 // Check tuning mode
1754 if (!checkTuningModeOn(strError)) {
1755
1756 return false;
1757 }
1758 // Warn domains about turning auto sync back on
1759 if (_bAutoSyncOn) {
1760
1761 strError = "Feature unavailable when Auto Sync is on";
1762
1763 return false;
1764 }
1765
1766 // Get syncer set
1767 CSyncerSet syncerSet;
1768 // ... from system class
1769 getConstSystemClass()->fillSyncerSet(syncerSet);
Kevin Rocardace81f82012-12-11 16:19:17 +01001770
Patrick Benavoli68a91282011-08-31 11:23:23 +02001771 // Sync
Kevin Rocardace81f82012-12-11 16:19:17 +01001772 list<string> lstrError;
1773 if (! syncerSet.sync(*_pMainParameterBlackboard, false, &lstrError)){
1774
Frederic Boisnard390b36d2013-05-23 15:28:31 +02001775 CUtility::asString(lstrError, strError);
Kevin Rocardace81f82012-12-11 16:19:17 +01001776 return false;
1777 };
1778
1779 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001780}
1781
1782// Content dump
1783void CParameterMgr::logStructureContent(string& strContent) const
1784{
1785 string strError;
1786
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001787 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001788
1789 dumpContent(strContent, parameterAccessContext);
1790}
1791
1792// Configuration/Domains handling
1793bool CParameterMgr::createDomain(const string& strName, string& strError)
1794{
1795 // Check tuning mode
1796 if (!checkTuningModeOn(strError)) {
1797
1798 return false;
1799 }
1800
1801 // Delegate to configurable domains
1802 return getConfigurableDomains()->createDomain(strName, strError);
1803}
1804
1805bool CParameterMgr::deleteDomain(const string& strName, string& strError)
1806{
1807 // Check tuning mode
1808 if (!checkTuningModeOn(strError)) {
1809
1810 return false;
1811 }
1812
1813 // Delegate to configurable domains
1814 return getConfigurableDomains()->deleteDomain(strName, strError);
1815}
1816
Kevin Rocard170f0a42012-06-18 13:56:05 +02001817bool CParameterMgr::deleteAllDomains(string& strError)
1818{
1819 // Check tuning mode
1820 if (!checkTuningModeOn(strError)) {
1821
1822 return false;
1823 }
1824
1825 // Delegate to configurable domains
1826 getConfigurableDomains()->deleteAllDomains();
1827
1828 return true;
1829}
1830
Patrick Benavoli68a91282011-08-31 11:23:23 +02001831bool CParameterMgr::createConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1832{
1833 // Check tuning mode
1834 if (!checkTuningModeOn(strError)) {
1835
1836 return false;
1837 }
1838
1839 // Delegate to configurable domains
1840 return getConfigurableDomains()->createConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1841}
1842
1843bool CParameterMgr::deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1844{
1845 // Check tuning mode
1846 if (!checkTuningModeOn(strError)) {
1847
1848 return false;
1849 }
1850
1851 // Delegate to configurable domains
1852 return getConfigurableDomains()->deleteConfiguration(strDomain, strConfiguration, strError);
1853}
1854
Kevin Rocardace81f82012-12-11 16:19:17 +01001855bool CParameterMgr::restoreConfiguration(const string& strDomain, const string& strConfiguration, list<string>& lstrError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001856{
Kevin Rocardace81f82012-12-11 16:19:17 +01001857 string strError;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001858 // Check tuning mode
1859 if (!checkTuningModeOn(strError)) {
1860
Kevin Rocardace81f82012-12-11 16:19:17 +01001861 lstrError.push_back(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001862 return false;
1863 }
1864
1865 // Delegate to configurable domains
Kevin Rocardace81f82012-12-11 16:19:17 +01001866 return getConstConfigurableDomains()->restoreConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, lstrError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001867}
1868
1869bool CParameterMgr::saveConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1870{
1871 // Check tuning mode
1872 if (!checkTuningModeOn(strError)) {
1873
1874 return false;
1875 }
1876
1877 // Delegate to configurable domains
1878 return getConfigurableDomains()->saveConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1879}
1880
1881// Configurable element - domain association
1882bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1883{
1884 // Check tuning mode
1885 if (!checkTuningModeOn(strError)) {
1886
1887 return false;
1888 }
1889
1890 CElementLocator elementLocator(getSystemClass());
1891
1892 CElement* pLocatedElement = NULL;
1893
1894 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1895
1896 return false;
1897 }
1898
1899 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001900 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001901
1902 // Delegate
1903 return getConfigurableDomains()->addConfigurableElementToDomain(strDomain, pConfigurableElement, _pMainParameterBlackboard, strError);
1904}
1905
1906bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1907{
1908 // Check tuning mode
1909 if (!checkTuningModeOn(strError)) {
1910
1911 return false;
1912 }
1913
1914 CElementLocator elementLocator(getSystemClass());
1915
1916 CElement* pLocatedElement = NULL;
1917
1918 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1919
Patrick Benavoli63499d42011-10-24 18:50:03 +02001920 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001921 }
1922
1923 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001924 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001925
1926 // Delegate
1927 return getConfigurableDomains()->removeConfigurableElementFromDomain(strDomain, pConfigurableElement, strError);
1928}
1929
1930bool CParameterMgr::split(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1931{
1932 // Check tuning mode
1933 if (!checkTuningModeOn(strError)) {
1934
1935 return false;
1936 }
1937
1938 CElementLocator elementLocator(getSystemClass());
1939
1940 CElement* pLocatedElement = NULL;
1941
1942 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1943
Patrick Benavoli63499d42011-10-24 18:50:03 +02001944 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001945 }
1946
1947 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001948 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001949
1950 // Delegate
1951 return getConfigurableDomains()->split(strDomain, pConfigurableElement, strError);
1952}
1953
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001954bool CParameterMgr::importDomainsXml(const string& strXmlSource, bool bWithSettings,
1955 bool bFromFile, string& strError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001956{
1957 // Check tuning mode
1958 if (!checkTuningModeOn(strError)) {
1959
1960 return false;
1961 }
1962
1963 // check path is absolute
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001964 if (bFromFile && strXmlSource[0] != '/') {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001965
1966 strError = "Please provide absolute path";
1967
1968 return false;
1969 }
1970 // Root element
1971 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1972
1973 // Context
1974 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1975
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001976 // Selection criteria definition for rule creation
1977 xmlDomainSerializingContext.setSelectionCriteriaDefinition(
1978 getConstSelectionCriteria()->getSelectionCriteriaDefinition());
Patrick Benavoli68a91282011-08-31 11:23:23 +02001979
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001980 // Init serializing context
1981 xmlDomainSerializingContext.set(
1982 _pElementLibrarySet->getElementLibrary(EParameterConfigurationLibrary),
1983 "", _strSchemaFolderLocation);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001984
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001985 // Get Schema file associated to root element
1986 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" +
1987 pConfigurableDomains->getKind() + ".xsd";
1988
1989 // Xml Source
1990 CXmlDocSource* pSource;
1991
1992 if (bFromFile) {
1993
1994 // when importing from a file strXmlSource is the file name
1995 pSource = new CXmlFileDocSource(strXmlSource, strXmlSchemaFilePath,
1996 pConfigurableDomains->getKind(),
1997 pConfigurableDomains->getName(), "SystemClassName");
1998
1999 } else {
2000
2001 // when importing from an xml string, strXmlSource contains the string
2002 pSource = new CXmlStringDocSource(strXmlSource, strXmlSchemaFilePath,
2003 pConfigurableDomains->getKind(),
2004 pConfigurableDomains->getName(), "SystemClassName");
2005
2006 }
2007 // Start clean
2008 pConfigurableDomains->clean();
2009
2010 // Use a doc sink that instantiate Configurable Domains from the given doc source
2011 CXmlMemoryDocSink memorySink(pConfigurableDomains);
2012
2013 bool bProcessSuccess = memorySink.process(*pSource, xmlDomainSerializingContext);
2014
2015 if (!bProcessSuccess) {
2016
2017 //Cleanup
2018 pConfigurableDomains->clean();
2019
2020 } else {
2021
2022 // Validate domains after XML import
2023 pConfigurableDomains->validate(_pMainParameterBlackboard);
2024
Patrick Benavoli68a91282011-08-31 11:23:23 +02002025 }
2026
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002027 delete pSource;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002028
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002029 return bProcessSuccess;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002030}
2031
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002032bool CParameterMgr::exportDomainsXml(string& strXmlDest, bool bWithSettings, bool bToFile,
2033 string& strError) const
Patrick Benavoli68a91282011-08-31 11:23:23 +02002034{
2035 // check path is absolute
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002036 if (bToFile && strXmlDest[0] != '/') {
Patrick Benavoli68a91282011-08-31 11:23:23 +02002037
2038 strError = "Please provide absolute path";
2039
2040 return false;
2041 }
2042
2043 // Root element
2044 const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains();
2045
2046 // Get Schema file associated to root element
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002047 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" +
2048 pConfigurableDomains->getKind() + ".xsd";
Patrick Benavoli68a91282011-08-31 11:23:23 +02002049
2050 // Context
2051 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
2052
2053 // Value space
2054 xmlDomainSerializingContext.setValueSpaceRaw(_bValueSpaceIsRaw);
2055
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02002056 // Output raw format
2057 xmlDomainSerializingContext.setOutputRawFormat(_bOutputRawFormatIsHex);
2058
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002059 // Use a doc source by loading data from instantiated Configurable Domains
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002060 CXmlMemoryDocSource memorySource(pConfigurableDomains, pConfigurableDomains->getKind(),
2061 strXmlSchemaFilePath, "parameter-framework", getVersion());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002062
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002063 // Xml Sink
2064 CXmlDocSink* pSink;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002065
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002066 if (bToFile) {
2067
2068 // Use a doc sink to write the doc data in a file
2069 pSink = new CXmlFileDocSink(strXmlDest);
2070
2071 } else {
2072
2073 // Use a doc sink to write the doc data in a string
2074 pSink = new CXmlStringDocSink(strXmlDest);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002075 }
2076
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002077 bool bProcessSuccess = pSink->process(memorySource, xmlDomainSerializingContext);
2078
2079 delete pSink;
2080 return bProcessSuccess;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002081}
2082
2083// Binary Import/Export
2084bool CParameterMgr::importDomainsBinary(const string& strFileName, string& strError)
2085{
2086 // Check tuning mode
2087 if (!checkTuningModeOn(strError)) {
2088
2089 return false;
2090 }
2091 // check path is absolute
2092 if (strFileName[0] != '/') {
2093
2094 strError = "Please provide absolute path";
2095
2096 return false;
2097 }
2098 // Root element
2099 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
2100
2101 // Serialize in
2102 return pConfigurableDomains->serializeSettings(strFileName, false, _uiStructureChecksum, strError);
2103}
2104
2105bool CParameterMgr::exportDomainsBinary(const string& strFileName, string& strError)
2106{
2107 // check path is absolute
2108 if (strFileName[0] != '/') {
2109
2110 strError = "Please provide absolute path";
2111
2112 return false;
2113 }
Patrick Benavoli68a91282011-08-31 11:23:23 +02002114
Patrick Benavoli68a91282011-08-31 11:23:23 +02002115 // Root element
2116 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
2117
2118 // Serialize out
2119 return pConfigurableDomains->serializeSettings(strFileName, true, _uiStructureChecksum, strError);
2120}
2121
2122// For tuning, check we're in tuning mode
2123bool CParameterMgr::checkTuningModeOn(string& strError) const
2124{
2125 // Tuning Mode on?
2126 if (!_bTuningModeIsOn) {
2127
2128 strError = "Tuning Mode must be on";
2129
2130 return false;
2131 }
2132 return true;
2133}
2134
Patrick Benavoli065264a2011-11-20 15:46:41 +01002135// Tuning mutex dynamic parameter handling
2136pthread_mutex_t* CParameterMgr::getBlackboardMutex()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002137{
Patrick Benavoli065264a2011-11-20 15:46:41 +01002138 return &_blackboardMutex;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002139}
2140
Patrick Benavoli065264a2011-11-20 15:46:41 +01002141// Blackboard reference (dynamic parameter handling)
2142CParameterBlackboard* CParameterMgr::getParameterBlackboard()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002143{
Patrick Benavoli065264a2011-11-20 15:46:41 +01002144 return _pMainParameterBlackboard;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002145}
2146
Patrick Benavoli68a91282011-08-31 11:23:23 +02002147// Dynamic creation library feeding
2148void CParameterMgr::feedElementLibraries()
2149{
2150 // Global Configuration handling
2151 CElementLibrary* pFrameworkConfigurationLibrary = new CElementLibrary;
2152
Kevin Rocarda7b69602013-08-07 16:15:33 +02002153 pFrameworkConfigurationLibrary->addElementBuilder("ParameterFrameworkConfiguration", new TElementBuilderTemplate<CParameterFrameworkConfiguration>());
2154 pFrameworkConfigurationLibrary->addElementBuilder("SubsystemPlugins", new TKindElementBuilderTemplate<CSubsystemPlugins>());
2155 pFrameworkConfigurationLibrary->addElementBuilder("Location", new TKindElementBuilderTemplate<CPluginLocation>());
2156 pFrameworkConfigurationLibrary->addElementBuilder("StructureDescriptionFileLocation", new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>());
2157 pFrameworkConfigurationLibrary->addElementBuilder("SettingsConfiguration", new TKindElementBuilderTemplate<CFrameworkConfigurationGroup>());
2158 pFrameworkConfigurationLibrary->addElementBuilder("ConfigurableDomainsFileLocation", new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>());
2159 pFrameworkConfigurationLibrary->addElementBuilder("BinarySettingsFileLocation", new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002160
2161 _pElementLibrarySet->addElementLibrary(pFrameworkConfigurationLibrary);
2162
2163 // Parameter creation
2164 CElementLibrary* pParameterCreationLibrary = new CElementLibrary;
2165
Kevin Rocarda7b69602013-08-07 16:15:33 +02002166 pParameterCreationLibrary->addElementBuilder("Subsystem", new CSubsystemElementBuilder(getSystemClass()->getSubsystemLibrary()));
2167 pParameterCreationLibrary->addElementBuilder("ComponentType", new TNamedElementBuilderTemplate<CComponentType>());
2168 pParameterCreationLibrary->addElementBuilder("Component", new TNamedElementBuilderTemplate<CComponentInstance>());
2169 pParameterCreationLibrary->addElementBuilder("BitParameter", new TNamedElementBuilderTemplate<CBitParameterType>());
2170 pParameterCreationLibrary->addElementBuilder("BitParameterBlock", new TNamedElementBuilderTemplate<CBitParameterBlockType>());
2171 pParameterCreationLibrary->addElementBuilder("StringParameter", new TNamedElementBuilderTemplate<CStringParameterType>());
2172 pParameterCreationLibrary->addElementBuilder("ParameterBlock", new TNamedElementBuilderTemplate<CParameterBlockType>());
2173 pParameterCreationLibrary->addElementBuilder("BooleanParameter", new TNamedElementBuilderTemplate<CBooleanParameterType>());
2174 pParameterCreationLibrary->addElementBuilder("IntegerParameter", new TNamedElementBuilderTemplate<CIntegerParameterType>());
2175 pParameterCreationLibrary->addElementBuilder("LinearAdaptation", new TElementBuilderTemplate<CLinearParameterAdaptation>());
2176 pParameterCreationLibrary->addElementBuilder("EnumParameter", new TNamedElementBuilderTemplate<CEnumParameterType>());
2177 pParameterCreationLibrary->addElementBuilder("ValuePair", new TElementBuilderTemplate<CEnumValuePair>());
2178 pParameterCreationLibrary->addElementBuilder("FixedPointParameter", new TNamedElementBuilderTemplate<CFixedPointParameterType>());
2179 pParameterCreationLibrary->addElementBuilder("SubsystemInclude", new TKindElementBuilderTemplate<CXmlFileIncluderElement>());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002180
2181 _pElementLibrarySet->addElementLibrary(pParameterCreationLibrary);
2182
2183 // Parameter Configuration Domains creation
2184 CElementLibrary* pParameterConfigurationLibrary = new CElementLibrary;
2185
Kevin Rocarda7b69602013-08-07 16:15:33 +02002186 pParameterConfigurationLibrary->addElementBuilder("ConfigurableDomain", new TNamedElementBuilderTemplate<CConfigurableDomain>());
2187 pParameterConfigurationLibrary->addElementBuilder("Configuration", new TNamedElementBuilderTemplate<CDomainConfiguration>());
2188 pParameterConfigurationLibrary->addElementBuilder("CompoundRule", new TElementBuilderTemplate<CCompoundRule>());
2189 pParameterConfigurationLibrary->addElementBuilder("SelectionCriterionRule", new TElementBuilderTemplate<CSelectionCriterionRule>());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002190
2191 _pElementLibrarySet->addElementLibrary(pParameterConfigurationLibrary);
2192}
2193
2194// Remote Processor Server connection handling
2195bool CParameterMgr::handleRemoteProcessingInterface(string& strError)
2196{
2197 CAutoLog autoLog(this, "Handling remote processing interface");
2198
2199 // Start server if tuning allowed
Patrick Benavoli95ac0342011-11-07 20:32:51 +01002200 if (getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02002201
Kevin Rocardace81f82012-12-11 16:19:17 +01002202 log_info("Loading remote processor library");
Patrick Benavoli68a91282011-08-31 11:23:23 +02002203
2204 // Load library
Renaud de Chivre1b8b3ca2013-12-13 15:09:44 +01002205 _handleLibRemoteProcessor = dlopen("libremote-processor.so", RTLD_NOW);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002206
Renaud de Chivre1b8b3ca2013-12-13 15:09:44 +01002207 if (!_handleLibRemoteProcessor) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02002208
2209 // Return error
2210 const char* pcError = dlerror();
2211
2212 if (pcError) {
2213
2214 strError = pcError;
2215 } else {
2216
2217 strError = "Unable to load libremote-processor.so library";
2218 }
2219
2220 return false;
2221 }
2222
Renaud de Chivre1b8b3ca2013-12-13 15:09:44 +01002223 CreateRemoteProcessorServer pfnCreateRemoteProcessorServer = (CreateRemoteProcessorServer)dlsym(_handleLibRemoteProcessor, "createRemoteProcessorServer");
Patrick Benavoli68a91282011-08-31 11:23:23 +02002224
2225 if (!pfnCreateRemoteProcessorServer) {
2226
2227 strError = "libremote-process.so does not contain createRemoteProcessorServer symbol.";
2228
2229 return false;
2230 }
2231
2232 // Create server
Patrick Benavoli95ac0342011-11-07 20:32:51 +01002233 _pRemoteProcessorServer = pfnCreateRemoteProcessorServer(getConstFrameworkConfiguration()->getServerPort(), _pCommandHandler);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002234
Kevin Rocardace81f82012-12-11 16:19:17 +01002235 log_info("Starting remote processor server on port %d", getConstFrameworkConfiguration()->getServerPort());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002236 // Start
2237 if (!_pRemoteProcessorServer->start()) {
2238
Frédéric Boisnard6c55e9a2014-01-10 18:46:33 +01002239 ostringstream oss;
2240 oss << "ParameterMgr: Unable to start remote processor server on port "
2241 << getConstFrameworkConfiguration()->getServerPort();
2242 strError = oss.str();
Patrick Benavoli68a91282011-08-31 11:23:23 +02002243
2244 return false;
2245 }
2246 }
2247
2248 return true;
2249}
2250
2251// Back synchronization
Kevin Rocardace81f82012-12-11 16:19:17 +01002252CBackSynchronizer* CParameterMgr::createBackSynchronizer() const
Patrick Benavoli68a91282011-08-31 11:23:23 +02002253{
2254#ifdef SIMULATION
2255 // In simulation, back synchronization of the blackboard won't probably work
2256 // We need to ensure though the blackboard is initialized with valid data
Kevin Rocardace81f82012-12-11 16:19:17 +01002257 return new CSimulatedBackSynchronizer(getConstSystemClass(), _pMainParameterBlackboard);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002258#else
2259 // Real back synchronizer from subsystems
Kevin Rocardace81f82012-12-11 16:19:17 +01002260 return new CHardwareBackSynchronizer(getConstSystemClass(), _pMainParameterBlackboard);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002261#endif
2262}
2263
2264// Children typwise access
2265CParameterFrameworkConfiguration* CParameterMgr::getFrameworkConfiguration()
2266{
2267 return static_cast<CParameterFrameworkConfiguration*>(getChild(EFrameworkConfiguration));
2268}
2269
2270const CParameterFrameworkConfiguration* CParameterMgr::getConstFrameworkConfiguration()
2271{
2272 return getFrameworkConfiguration();
2273}
2274
2275CSelectionCriteria* CParameterMgr::getSelectionCriteria()
2276{
2277 return static_cast<CSelectionCriteria*>(getChild(ESelectionCriteria));
2278}
2279
2280const CSelectionCriteria* CParameterMgr::getConstSelectionCriteria()
2281{
2282 return static_cast<const CSelectionCriteria*>(getChild(ESelectionCriteria));
2283}
2284
2285CSystemClass* CParameterMgr::getSystemClass()
2286{
2287 return static_cast<CSystemClass*>(getChild(ESystemClass));
2288}
2289
2290const CSystemClass* CParameterMgr::getConstSystemClass() const
2291{
2292 return static_cast<const CSystemClass*>(getChild(ESystemClass));
2293}
2294
2295// Configurable Domains
2296CConfigurableDomains* CParameterMgr::getConfigurableDomains()
2297{
2298 return static_cast<CConfigurableDomains*>(getChild(EConfigurableDomains));
2299}
2300
2301const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains()
2302{
2303 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
2304}
2305
2306const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains() const
2307{
2308 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
2309}
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002310
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01002311// Apply configurations
2312void CParameterMgr::doApplyConfigurations(bool bForce)
2313{
2314 CSyncerSet syncerSet;
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002315
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01002316 // Check subsystems that need resync
2317 getSystemClass()->checkForSubsystemsToResync(syncerSet);
2318
2319 // Ensure application of currently selected configurations
2320 getConfigurableDomains()->apply(_pMainParameterBlackboard, syncerSet, bForce);
2321
2322 // Reset the modified status of the current criteria to indicate that a new configuration has been applied
2323 getSelectionCriteria()->resetModifiedStatus();
2324}
2325
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002326bool CParameterMgr::getSystemClassXMLString(string& strResult)
2327{
2328 // Root element
2329 const CSystemClass* pSystemClass = getSystemClass();
2330
2331 string strError;
2332
2333 CXmlSerializingContext xmlSerializingContext(strError);
2334
2335 // Use a doc source by loading data from instantiated Configurable Domains
2336 CXmlMemoryDocSource memorySource(pSystemClass, pSystemClass->getKind());
2337
2338 // Use a doc sink that write the doc data in a string
2339 CXmlStringDocSink stringSink(strResult);
2340
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002341 bool bProcessSuccess = stringSink.process(memorySource, xmlSerializingContext);
2342
2343 if (!bProcessSuccess) {
2344
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002345 strResult = strError;
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002346
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002347 }
2348
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002349 return bProcessSuccess;
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002350}