blob: 639c59ff998fadf783d956f7a350505ba08b70e6 [file] [log] [blame]
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +02001 /*
David Wagnerb76c9d62014-02-05 18:30:24 +01002 * Copyright (c) 2011-2014, Intel Corporation
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice, this
9 * list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation and/or
13 * other materials provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its contributors
16 * may be used to endorse or promote products derived from this software without
17 * specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Patrick Benavoli68a91282011-08-31 11:23:23 +020029 */
30#include "ParameterMgr.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020031#include "XmlParameterSerializingContext.h"
32#include "XmlElementSerializingContext.h"
33#include "SystemClass.h"
34#include "ElementLibrarySet.h"
35#include "SubsystemLibrary.h"
36#include "NamedElementBuilderTemplate.h"
37#include "KindElementBuilderTemplate.h"
38#include "ElementBuilderTemplate.h"
39#include "SelectionCriterionType.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020040#include "SubsystemElementBuilder.h"
41#include "SelectionCriteria.h"
42#include "ComponentType.h"
43#include "ComponentInstance.h"
44#include "ParameterBlockType.h"
45#include "BooleanParameterType.h"
46#include "IntegerParameterType.h"
47#include "FixedPointParameterType.h"
48#include "ParameterBlackboard.h"
49#include "Parameter.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020050#include "ParameterAccessContext.h"
51#include "XmlFileIncluderElement.h"
52#include "ParameterFrameworkConfiguration.h"
53#include "FrameworkConfigurationGroup.h"
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +010054#include "PluginLocation.h"
55#include "SubsystemPlugins.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020056#include "FrameworkConfigurationLocation.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020057#include "ConfigurableDomains.h"
58#include "ConfigurableDomain.h"
59#include "DomainConfiguration.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020060#include "XmlDomainSerializingContext.h"
61#include "BitParameterBlockType.h"
62#include "BitParameterType.h"
Patrick Benavoli1352ae52011-10-21 16:48:04 +020063#include "StringParameterType.h"
Patrick Benavoli9fc3c0d2011-10-27 14:27:27 +020064#include "EnumParameterType.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020065#include "RemoteProcessorServerInterface.h"
66#include "ElementLocator.h"
67#include "AutoLog.h"
68#include "CompoundRule.h"
69#include "SelectionCriterionRule.h"
70#include "SimulatedBackSynchronizer.h"
71#include "HardwareBackSynchronizer.h"
Patrick Benavoli1387bda2011-08-31 11:23:24 +020072#include "AutoLock.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020073#include <strings.h>
74#include <dlfcn.h>
75#include <assert.h>
Patrick Benavoli065264a2011-11-20 15:46:41 +010076#include "ParameterHandle.h"
Patrick Benavoliee65e6d2011-11-20 18:52:24 +010077#include "LinearParameterAdaptation.h"
Patrick Benavoli68808c62012-02-02 17:12:41 +010078#include "EnumValuePair.h"
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +020079#include "Subsystem.h"
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020080#include "XmlFileDocSink.h"
81#include "XmlFileDocSource.h"
82#include "XmlStringDocSink.h"
Georges-Henri Baroncec86c12012-09-04 17:30:28 +020083#include "XmlStringDocSource.h"
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020084#include "XmlMemoryDocSink.h"
85#include "XmlMemoryDocSource.h"
Kevin Rocardace81f82012-12-11 16:19:17 +010086#include "Utility.h"
Frédéric Boisnard6c55e9a2014-01-10 18:46:33 +010087#include <sstream>
Patrick Benavoli68a91282011-08-31 11:23:23 +020088
89#define base CElement
90
91// Used for remote processor server creation
92typedef IRemoteProcessorServerInterface* (*CreateRemoteProcessorServer)(uint16_t uiPort, IRemoteCommandHandler* pCommandHandler);
93
94// Global configuration file name (fixed)
95const char* gacParameterFrameworkConfigurationFileName = "ParameterFrameworkConfiguration.xml";
96const char* gacSystemSchemasSubFolder = "Schemas";
97
98// Config File System looks normally like this:
99// ---------------------------------------------
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100100//├── <ParameterFrameworkConfiguration>.xml
Patrick Benavoli68a91282011-08-31 11:23:23 +0200101//├── Schemas
102//│ └── *.xsd
103//├── Settings
104//│ └── <SystemClassName folder>*
105//│ ├── <ConfigurableDomains>.xml
106//│ └── <Settings>.bin?
107//└── Structure
108// └── <SystemClassName folder>*
109// ├── <SystemClassName>Class.xml
110// └── <Subsystem>.xml*
111// --------------------------------------------
112
113
114// Remote command parser array
Patrick Benavoli592ae562011-09-05 16:53:58 +0200115const CParameterMgr::SRemoteCommandParserItem CParameterMgr::gastRemoteCommandParserItems[] = {
Kevin Rocard3949b342013-05-24 18:43:53 +0200116
Patrick Benavoli592ae562011-09-05 16:53:58 +0200117 /// Version
Kevin Rocard3949b342013-05-24 18:43:53 +0200118 { "version", &CParameterMgr::versionCommandProcess, 0,
119 "", "Show version" },
120
Patrick Benavoli68a91282011-08-31 11:23:23 +0200121 /// Status
Kevin Rocard3949b342013-05-24 18:43:53 +0200122 { "status", &CParameterMgr::statusCommandProcess, 0, "",
123 "Show current status" },
124
Patrick Benavoli68a91282011-08-31 11:23:23 +0200125 /// Tuning Mode
Kevin Rocard3949b342013-05-24 18:43:53 +0200126 { "setTuningMode", &CParameterMgr::setTuningModeCommmandProcess, 1,
127 "on|off*", "Turn on or off Tuning Mode" },
128 { "getTuningMode", &CParameterMgr::getTuningModeCommmandProcess, 0,
129 "", "Show Tuning Mode" },
130
Patrick Benavoli68a91282011-08-31 11:23:23 +0200131 /// Value Space
Kevin Rocard3949b342013-05-24 18:43:53 +0200132 { "setValueSpace", &CParameterMgr::setValueSpaceCommmandProcess, 1,
133 "raw|real*", "Assigns Value Space used for parameter value interpretation" },
134 { "getValueSpace", &CParameterMgr::getValueSpaceCommmandProcess, 0,
135 "", "Show Value Space" },
136
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200137 /// Output Raw Format
Kevin Rocard3949b342013-05-24 18:43:53 +0200138 { "setOutputRawFormat", &CParameterMgr::setOutputRawFormatCommmandProcess, 1,
139 "dec*|hex", "Assigns format used to output parameter values when in raw Value Space" },
140 { "getOutputRawFormat", &CParameterMgr::getOutputRawFormatCommmandProcess, 0,
141 "", "Show Output Raw Format" },
142
Patrick Benavoli68a91282011-08-31 11:23:23 +0200143 /// Sync
Kevin Rocard3949b342013-05-24 18:43:53 +0200144 { "setAutoSync", &CParameterMgr::setAutoSyncCommmandProcess, 1,
145 "on*|off", "Turn on or off automatic synchronization to hardware while in Tuning Mode" },
146 { "getAutoSync", &CParameterMgr::getAutoSyncCommmandProcess, 0,
147 "", "Show Auto Sync state" },
148 { "sync", &CParameterMgr::syncCommmandProcess, 0,
149 "", "Synchronize current settings to hardware while in Tuning Mode and Auto Sync off" },
150
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200151 /// Criteria
Kevin Rocard3949b342013-05-24 18:43:53 +0200152 { "listCriteria", &CParameterMgr::listCriteriaCommmandProcess, 0,
153 "[csv]", "List selection criteria" },
154
Patrick Benavoli68a91282011-08-31 11:23:23 +0200155 /// Domains
Kevin Rocard3949b342013-05-24 18:43:53 +0200156 { "listDomains", &CParameterMgr::listDomainsCommmandProcess, 0,
157 "", "List configurable domains" },
158 { "dumpDomains", &CParameterMgr::dumpDomainsCommmandProcess, 0,
159 "", "Show all domains and configurations, including applicability conditions" },
160 { "createDomain", &CParameterMgr::createDomainCommmandProcess, 1,
161 "<domain>", "Create new configurable domain" },
162 { "deleteDomain", &CParameterMgr::deleteDomainCommmandProcess, 1,
163 "<domain>", "Delete configurable domain" },
164 { "deleteAllDomains", &CParameterMgr::deleteAllDomainsCommmandProcess, 0,
165 "", "Delete all configurable domains" },
166 { "renameDomain", &CParameterMgr::renameDomainCommmandProcess, 2,
167 "<domain> <new name>", "Rename configurable domain" },
168 { "setSequenceAwareness", &CParameterMgr::setSequenceAwarenessCommmandProcess, 1,
169 "<domain> true|false*", "Set configurable domain sequence awareness" },
170 { "getSequenceAwareness", &CParameterMgr::getSequenceAwarenessCommmandProcess, 1,
171 "<domain>", "Get configurable domain sequence awareness" },
172 { "listDomainElements", &CParameterMgr::listDomainElementsCommmandProcess, 1,
173 "<domain>", "List elements associated to configurable domain" },
174 { "addElement", &CParameterMgr::addElementCommmandProcess, 2,
175 "<domain> <elem path>", "Associate element at given path to configurable domain" },
176 { "removeElement", &CParameterMgr::removeElementCommmandProcess, 2,
177 "<domain> <elem path>", "Dissociate element at given path from configurable domain" },
178 { "splitDomain", &CParameterMgr::splitDomainCommmandProcess, 2,
179 "<domain> <elem path>", "Split configurable domain at given associated element path" },
180
Patrick Benavoli68a91282011-08-31 11:23:23 +0200181 /// Configurations
Kevin Rocard3949b342013-05-24 18:43:53 +0200182 { "listConfigurations", &CParameterMgr::listConfigurationsCommmandProcess, 1,
183 "<domain>", "List domain configurations" },
184 { "createConfiguration", &CParameterMgr::createConfigurationCommmandProcess, 2,
185 "<domain> <configuration>", "Create new domain configuration" },
186 { "deleteConfiguration", &CParameterMgr::deleteConfigurationCommmandProcess, 2,
187 "<domain> <configuration>", "Delete domain configuration" },
188 { "renameConfiguration", &CParameterMgr::renameConfigurationCommmandProcess, 3,
189 "<domain> <configuration> <new name>", "Rename domain configuration" },
190 { "saveConfiguration", &CParameterMgr::saveConfigurationCommmandProcess, 2,
191 "<domain> <configuration>", "Save current settings into configuration" },
192 { "restoreConfiguration", &CParameterMgr::restoreConfigurationCommmandProcess, 2,
193 "<domain> <configuration>", "Restore current settings from configuration" },
194 { "setElementSequence", &CParameterMgr::setElementSequenceCommmandProcess, 3,
195 "<domain> <configuration> <elem path list>",
196 "Set element application order for configuration" },
197 { "getElementSequence", &CParameterMgr::getElementSequenceCommmandProcess, 2,
198 "<domain> <configuration>", "Get element application order for configuration" },
199 { "setRule", &CParameterMgr::setRuleCommmandProcess, 3,
200 "<domain> <configuration> <rule>", "Set configuration application rule" },
201 { "clearRule", &CParameterMgr::clearRuleCommmandProcess, 2,
202 "<domain> <configuration>", "Clear configuration application rule" },
203 { "getRule", &CParameterMgr::getRuleCommmandProcess, 2,
204 "<domain> <configuration>", "Get configuration application rule" },
205
Patrick Benavoli68a91282011-08-31 11:23:23 +0200206 /// Elements/Parameters
Kevin Rocard3949b342013-05-24 18:43:53 +0200207 { "listElements", &CParameterMgr::listElementsCommmandProcess, 1,
208 "<elem path>|/", "List elements under element at given path or root" },
209 { "listParameters", &CParameterMgr::listParametersCommmandProcess, 1,
210 "<elem path>|/", "List parameters under element at given path or root" },
211 { "dumpElement", &CParameterMgr::dumpElementCommmandProcess, 1,
212 "<elem path>", "Dump structure and content of element at given path" },
213 { "getElementSize", &CParameterMgr::getElementSizeCommmandProcess, 1,
214 "<elem path>", "Show size of element at given path" },
215 { "showProperties", &CParameterMgr::showPropertiesCommmandProcess, 1,
216 "<elem path>", "Show properties of element at given path" },
217 { "getParameter", &CParameterMgr::getParameterCommmandProcess, 1,
218 "<param path>", "Get value for parameter at given path" },
219 { "setParameter", &CParameterMgr::setParameterCommmandProcess, 2,
220 "<param path> <value>", "Set value for parameter at given path" },
221 { "listBelongingDomains", &CParameterMgr::listBelongingDomainsCommmandProcess, 1,
222 "<elem path>", "List domain(s) element at given path belongs to" },
223 { "listAssociatedDomains", &CParameterMgr::listAssociatedDomainsCommmandProcess, 1,
224 "<elem path>", "List domain(s) element at given path is associated to" },
225 { "getConfigurationParameter", &CParameterMgr::getConfigurationParameterCommmandProcess, 3,
226 "<domain> <configuration> <param path>",
227 "Get value for parameter at given path from configuration" },
228 { "setConfigurationParameter", &CParameterMgr::setConfigurationParameterCommmandProcess, 4,
229 "<domain> <configuration> <param path> <value>",
230 "Set value for parameter at given path to configuration" },
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200231 { "showMapping", &CParameterMgr::showMappingCommmandProcess, 1,
232 "<elem path>", "Show mapping for an element at given path" },
Kevin Rocard3949b342013-05-24 18:43:53 +0200233
Patrick Benavoli68a91282011-08-31 11:23:23 +0200234 /// Browse
Kevin Rocard3949b342013-05-24 18:43:53 +0200235 { "listAssociatedElements", &CParameterMgr::listAssociatedElementsCommmandProcess, 0,
236 "", "List element sub-trees associated to at least one configurable domain" },
237 { "listConflictingElements", &CParameterMgr::listConflictingElementsCommmandProcess, 0,
238 "", "List element sub-trees contained in more than one configurable domain" },
239 { "listRogueElements", &CParameterMgr::listRogueElementsCommmandProcess, 0,
240 "", "List element sub-trees owned by no configurable domain" },
241
Patrick Benavoli68a91282011-08-31 11:23:23 +0200242 /// Settings Import/Export
Kevin Rocard3949b342013-05-24 18:43:53 +0200243 { "exportDomainsXML", &CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess, 1,
244 "<file path> ", "Export domains to XML file" },
245 { "importDomainsXML", &CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess, 1,
246 "<file path>", "Import domains from XML file" },
247 { "exportDomainsWithSettingsXML",
248 &CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess, 1,
249 "<file path> ", "Export domains including settings to XML file" },
250 { "importDomainsWithSettingsXML",
251 &CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess, 1,
252 "<file path>", "Import domains including settings from XML file" },
253 { "exportSettings", &CParameterMgr::exportSettingsCommmandProcess, 1,
254 "<file path>", "Export settings to binary file" },
255 { "importSettings", &CParameterMgr::importSettingsCommmandProcess, 1,
256 "<file path>", "Import settings from binary file" },
Georges-Henri Baroncec86c12012-09-04 17:30:28 +0200257 { "getDomainsWithSettingsXML",
258 &CParameterMgr::getConfigurableDomainsWithSettingsXMLCommmandProcess, 0,
Kevin Rocard3949b342013-05-24 18:43:53 +0200259 "", "Print domains including settings as XML" },
Georges-Henri Baroncec86c12012-09-04 17:30:28 +0200260 { "setDomainsWithSettingsXML",
261 &CParameterMgr::setConfigurableDomainsWithSettingsXMLCommmandProcess, 1,
262 "<xml configurable domains>", "Import domains including settings from XML string" },
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200263 /// Structure Export
Kevin Rocard3949b342013-05-24 18:43:53 +0200264 { "getSystemClassXML", &CParameterMgr::getSystemClassXMLCommmandProcess, 0 ,
Kevin Rocardc0211572013-06-18 11:34:53 +0200265 "", "Print parameter structure as XML" },
266 /// Deprecated Commands
267 { "getDomainsXML",
268 &CParameterMgr::getConfigurableDomainsWithSettingsXMLCommmandProcess, 0,
269 "", "DEPRECATED COMMAND, please use getDomainsWithSettingsXML" },
Georges-Henri Baroncec86c12012-09-04 17:30:28 +0200270
Patrick Benavoli68a91282011-08-31 11:23:23 +0200271};
Kevin Rocard3949b342013-05-24 18:43:53 +0200272
Patrick Benavoli68a91282011-08-31 11:23:23 +0200273// Remote command parsers array Size
Patrick Benavoli592ae562011-09-05 16:53:58 +0200274const uint32_t CParameterMgr::guiNbRemoteCommandParserItems = sizeof(gastRemoteCommandParserItems) / sizeof(gastRemoteCommandParserItems[0]);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200275
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100276CParameterMgr::CParameterMgr(const string& strConfigurationFilePath) :
Patrick Benavoli68a91282011-08-31 11:23:23 +0200277 _bTuningModeIsOn(false),
278 _bValueSpaceIsRaw(false),
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200279 _bOutputRawFormatIsHex(false),
Patrick Benavoli68a91282011-08-31 11:23:23 +0200280 _bAutoSyncOn(true),
281 _pMainParameterBlackboard(new CParameterBlackboard),
282 _pElementLibrarySet(new CElementLibrarySet),
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100283 _strXmlConfigurationFilePath(strConfigurationFilePath),
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100284 _pSubsystemPlugins(NULL),
Renaud de Chivre1b8b3ca2013-12-13 15:09:44 +0100285 _handleLibRemoteProcessor(NULL),
Patrick Benavoli68a91282011-08-31 11:23:23 +0200286 _uiStructureChecksum(0),
287 _pRemoteProcessorServer(NULL),
288 _uiMaxCommandUsageLength(0),
289 _pLogger(NULL),
Kevin Rocardecf93102013-07-10 18:28:10 +0200290 _uiLogDepth(0),
Kevin Rocardd6909eb2013-07-18 09:13:51 +0200291 _bFailOnMissingSubsystem(true),
292 _bFailOnFailedSettingsLoad(true)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200293{
294 // Tuning Mode Mutex
Patrick Benavoli065264a2011-11-20 15:46:41 +0100295 bzero(&_blackboardMutex, sizeof(_blackboardMutex));
296 pthread_mutex_init(&_blackboardMutex, NULL);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200297
298 // Deal with children
299 addChild(new CParameterFrameworkConfiguration);
300 addChild(new CSelectionCriteria);
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100301 addChild(new CSystemClass);
302 addChild(new CConfigurableDomains);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200303
304 // Feed element library
305 feedElementLibraries();
Patrick Benavoli63499d42011-10-24 18:50:03 +0200306
307 _pCommandHandler = new CCommandHandler(this);
308
309 // Add command parsers
310 uint32_t uiRemoteCommandParserItem;
311
312 for (uiRemoteCommandParserItem = 0; uiRemoteCommandParserItem < guiNbRemoteCommandParserItems; uiRemoteCommandParserItem++) {
313
314 const SRemoteCommandParserItem* pRemoteCommandParserItem = &gastRemoteCommandParserItems[uiRemoteCommandParserItem];
315
316 _pCommandHandler->addCommandParser(pRemoteCommandParserItem->_pcCommandName,
317 pRemoteCommandParserItem->_pfnParser,
318 pRemoteCommandParserItem->_uiMinArgumentCount,
319 pRemoteCommandParserItem->_pcHelp,
320 pRemoteCommandParserItem->_pcDescription);
321 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100322
323 // Configuration file folder
324 uint32_t uiSlashPos = _strXmlConfigurationFilePath.rfind('/', -1);
325
326 assert(uiSlashPos != (uint32_t)-1);
327
328 _strXmlConfigurationFolderPath = _strXmlConfigurationFilePath.substr(0, uiSlashPos);
329
330 // Schema absolute folder location
331 _strSchemaFolderLocation = _strXmlConfigurationFolderPath + "/" + gacSystemSchemasSubFolder;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200332}
333
334CParameterMgr::~CParameterMgr()
335{
336 // Children
337 delete _pRemoteProcessorServer;
Frederic Boisnard31242302012-04-26 17:07:34 +0200338 delete _pCommandHandler;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200339 delete _pMainParameterBlackboard;
340 delete _pElementLibrarySet;
341
Renaud de Chivre1b8b3ca2013-12-13 15:09:44 +0100342 // Close remote processor library
343 if (_handleLibRemoteProcessor != NULL) {
344 dlclose(_handleLibRemoteProcessor);
345 }
346
Patrick Benavoli68a91282011-08-31 11:23:23 +0200347 // Tuning Mode Mutex
Patrick Benavoli065264a2011-11-20 15:46:41 +0100348 pthread_mutex_destroy(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200349}
350
351string CParameterMgr::getKind() const
352{
353 return "ParameterMgr";
354}
355
356// Logging
357void CParameterMgr::setLogger(CParameterMgr::ILogger* pLogger)
358{
359 _pLogger = pLogger;
360}
361
362// Logging
Kevin Rocardace81f82012-12-11 16:19:17 +0100363void CParameterMgr::doLog(bool bIsWarning, const string& strLog) const
Patrick Benavoli68a91282011-08-31 11:23:23 +0200364{
365 if (_pLogger) {
366
367 // Nest
368 string strIndent;
369
370 // Level
371 uint32_t uiNbIndents = _uiLogDepth;
372
373 while (uiNbIndents--) {
374
375 strIndent += " ";
376 }
377
378 // Log
Kevin Rocardace81f82012-12-11 16:19:17 +0100379 _pLogger->log(bIsWarning, strIndent + strLog);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200380 }
381}
382
383void CParameterMgr::nestLog() const
384{
Patrick Benavoli592ae562011-09-05 16:53:58 +0200385 _uiLogDepth++;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200386}
387
388void CParameterMgr::unnestLog() const
389{
Patrick Benavoli592ae562011-09-05 16:53:58 +0200390 _uiLogDepth--;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200391}
392
Patrick Benavoli63499d42011-10-24 18:50:03 +0200393// Version
394string CParameterMgr::getVersion() const
395{
396 string strVersion;
397
398 // Major
399 strVersion = toString(guiEditionMajor) + ".";
400 // Minor
401 strVersion += toString(guiEditionMinor) + ".";
402 // Revision
403 strVersion += toString(guiRevision);
404
405 return strVersion;
406}
407
Patrick Benavoli68a91282011-08-31 11:23:23 +0200408bool CParameterMgr::load(string& strError)
409{
410 CAutoLog autoLog(this, "Loading");
411
412 // Load Framework configuration
413 if (!loadFrameworkConfiguration(strError)) {
414
415 return false;
416 }
417
418 // Load subsystems
Kevin Rocardecf93102013-07-10 18:28:10 +0200419 if (!getSystemClass()->loadSubsystems(strError,
420 _pSubsystemPlugins, !_bFailOnMissingSubsystem)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200421
422 return false;
423 }
424
425 // Load structure
426 if (!loadStructure(strError)) {
427
428 return false;
429 }
430
431 // Load settings
432 if (!loadSettings(strError)) {
433
434 return false;
435 }
436
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200437 // Back synchronization for areas in parameter blackboard not covered by any domain
Kevin Rocardace81f82012-12-11 16:19:17 +0100438 CBackSynchronizer* pBackSynchronizer = createBackSynchronizer();
Patrick Benavoli68a91282011-08-31 11:23:23 +0200439
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200440 // Back-synchronize
Kevin Rocard57096bd2012-11-30 11:24:20 +0100441 {
442 CAutoLog autoLog(this, "Main blackboard back synchronization");
443
Kevin Rocard5d6e05a2013-01-21 15:57:45 +0100444 pBackSynchronizer->sync();
Kevin Rocard57096bd2012-11-30 11:24:20 +0100445
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200446 // Get rid of back synchronizer
447 delete pBackSynchronizer;
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200448 }
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200449
450 // We're done loading the settings and back synchronizing
451 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
452
453 // We need to ensure all domains are valid
454 pConfigurableDomains->validate(_pMainParameterBlackboard);
455
Kevin Rocard7f265822012-12-07 18:51:22 +0100456 // Log selection criterion states
457 {
458 CAutoLog autoLog(this, "Criterion states");
459
460 const CSelectionCriteria* selectionCriteria = getConstSelectionCriteria();
461
462 list<string> lstrSelectionCriteron;
463 selectionCriteria->listSelectionCriteria(lstrSelectionCriteron, true, false);
464
Kevin Rocard36299362013-02-04 14:57:47 +0100465 log_table(false, lstrSelectionCriteron);
Kevin Rocard7f265822012-12-07 18:51:22 +0100466 }
467
Kevin Rocard2fbe6e82013-03-26 17:09:29 +0100468 // Subsystem can not ask for resync as they have not been synced yet
469 getSystemClass()->cleanSubsystemsNeedToResync();
470
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100471 // At initialization, check subsystems that need resync
472 doApplyConfigurations(true);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200473
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200474 // Start remote processor server if appropriate
475 return handleRemoteProcessingInterface(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200476}
477
478bool CParameterMgr::loadFrameworkConfiguration(string& strError)
479{
480 CAutoLog autoLog(this, "Loading framework configuration");
481
Patrick Benavoli68a91282011-08-31 11:23:23 +0200482 // Parse Structure XML file
483 CXmlElementSerializingContext elementSerializingContext(strError);
484
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100485 if (!xmlParse(elementSerializingContext, getFrameworkConfiguration(), _strXmlConfigurationFilePath, _strXmlConfigurationFolderPath, EFrameworkConfigurationLibrary)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200486
487 return false;
488 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100489 // Set class name to system class and configurable domains
490 getSystemClass()->setName(getConstFrameworkConfiguration()->getSystemClassName());
491 getConfigurableDomains()->setName(getConstFrameworkConfiguration()->getSystemClassName());
492
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100493 // Get subsystem plugins elements
494 _pSubsystemPlugins = static_cast<const CSubsystemPlugins*>(getConstFrameworkConfiguration()->findChild("SubsystemPlugins"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200495
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100496 if (!_pSubsystemPlugins) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200497
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100498 strError = "Parameter Framework Configuration: couldn't find SubsystemPlugins element";
Patrick Benavoli68a91282011-08-31 11:23:23 +0200499
500 return false;
501 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200502
Patrick Benavoli68a91282011-08-31 11:23:23 +0200503 // Log tuning availability
Kevin Rocardace81f82012-12-11 16:19:17 +0100504 log_info("Tuning %s", getConstFrameworkConfiguration()->isTuningAllowed() ? "allowed" : "prohibited");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200505
506 return true;
507}
508
509bool CParameterMgr::loadStructure(string& strError)
510{
511 // Retrieve system to load structure to
512 CSystemClass* pSystemClass = getSystemClass();
513
Kevin Rocarde25ee792013-04-22 17:46:28 +0200514 log_info("Loading " + pSystemClass->getName() + " system class structure");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200515
516 // Get structure description element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100517 const CFrameworkConfigurationLocation* pStructureDescriptionFileLocation = static_cast<const CFrameworkConfigurationLocation*>(getConstFrameworkConfiguration()->findChildOfKind("StructureDescriptionFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200518
519 if (!pStructureDescriptionFileLocation) {
520
521 strError = "No StructureDescriptionFileLocation element found for SystemClass " + pSystemClass->getName();
522
523 return false;
524 }
525
526 // Get Xml structure folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100527 string strXmlStructureFolder = pStructureDescriptionFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200528
529 // Get Xml structure file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100530 string strXmlStructureFilePath = pStructureDescriptionFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200531
532 // Parse Structure XML file
533 CXmlParameterSerializingContext parameterBuildContext(strError);
534
Kevin Rocard57096bd2012-11-30 11:24:20 +0100535 CAutoLog autolog(pSystemClass, "Importing system structure from file " + strXmlStructureFilePath);
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200536
Patrick Benavoli68a91282011-08-31 11:23:23 +0200537 if (!xmlParse(parameterBuildContext, pSystemClass, strXmlStructureFilePath, strXmlStructureFolder, EParameterCreationLibrary)) {
538
539 return false;
540 }
541
542 // Initialize offsets
543 pSystemClass->setOffset(0);
544
545 // Initialize main blackboard's size
546 _pMainParameterBlackboard->setSize(pSystemClass->getFootPrint());
547
548 return true;
549}
550
551bool CParameterMgr::loadSettings(string& strError)
552{
Kevin Rocardd6909eb2013-07-18 09:13:51 +0200553 string strLoadError;
554 bool success = loadSettingsFromConfigFile(strLoadError);
555
556 if (!success && !_bFailOnFailedSettingsLoad) {
557 // Load can not fail, ie continue but log the load errors
558 log_info(strLoadError);
559 log_info("Failed to load settings, continue without domains.");
560 success = true;
561 }
562
563 if (!success) {
564 // Propagate the litteral error only if the function fails
565 strError = strLoadError;
566 return false;
567 }
568
569 return true;
570}
571
572bool CParameterMgr::loadSettingsFromConfigFile(string& strError)
573{
Patrick Benavoli68a91282011-08-31 11:23:23 +0200574 CAutoLog autoLog(this, "Loading settings");
575
576 // Get settings configuration element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100577 const CFrameworkConfigurationGroup* pParameterConfigurationGroup = static_cast<const CFrameworkConfigurationGroup*>(getConstFrameworkConfiguration()->findChildOfKind("SettingsConfiguration"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200578
579 if (!pParameterConfigurationGroup) {
580
581 // No settings to load
582
583 return true;
584 }
585 // Get binary settings file location
586 const CFrameworkConfigurationLocation* pBinarySettingsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("BinarySettingsFileLocation"));
587
588 string strXmlBinarySettingsFilePath;
589
590 if (pBinarySettingsFileLocation) {
591
592 // Get Xml binary settings file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100593 strXmlBinarySettingsFilePath = pBinarySettingsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200594 }
595
596 // Get configurable domains element
597 const CFrameworkConfigurationLocation* pConfigurableDomainsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("ConfigurableDomainsFileLocation"));
598
599 if (!pConfigurableDomainsFileLocation) {
600
601 strError = "No ConfigurableDomainsFileLocation element found for SystemClass " + getSystemClass()->getName();
602
603 return false;
Kevin Rocardd6909eb2013-07-18 09:13:51 +0200604 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200605 // Get destination root element
606 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
607
608 // Get Xml configuration domains file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100609 string strXmlConfigurationDomainsFilePath = pConfigurableDomainsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200610
611 // Get Xml configuration domains folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100612 string strXmlConfigurationDomainsFolder = pConfigurableDomainsFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200613
614 // Parse configuration domains XML file (ask to read settings from XML file if they are not provided as binary)
615 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, !pBinarySettingsFileLocation);
616
617 // Selection criteria definition for rule creation
618 xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
619
Patrick Benavoli63499d42011-10-24 18:50:03 +0200620 // Auto validation of configurations if no binary settings provided
621 xmlDomainSerializingContext.setAutoValidationRequired(!pBinarySettingsFileLocation);
622
Kevin Rocardace81f82012-12-11 16:19:17 +0100623 log_info("Importing configurable domains from file %s %s settings", strXmlConfigurationDomainsFilePath.c_str(), pBinarySettingsFileLocation ? "without" : "with");
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200624
Patrick Benavoli68a91282011-08-31 11:23:23 +0200625 // Do parse
626 if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strXmlConfigurationDomainsFilePath, strXmlConfigurationDomainsFolder, EParameterConfigurationLibrary, "SystemClassName")) {
627
628 return false;
629 }
630 // We have loaded the whole system structure, compute checksum
631 const CSystemClass* pSystemClass = getConstSystemClass();
632 _uiStructureChecksum = pSystemClass->computeStructureChecksum() + getConfigurableDomains()->computeStructureChecksum() + getSelectionCriteria()->computeStructureChecksum();
633
634 // Load binary settings if any provided
635 if (pBinarySettingsFileLocation && !pConfigurableDomains->serializeSettings(strXmlBinarySettingsFilePath, false, _uiStructureChecksum, strError)) {
636
637 return false;
638 }
639
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200640 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200641}
642
643// XML parsing
644bool CParameterMgr::xmlParse(CXmlElementSerializingContext& elementSerializingContext, CElement* pRootElement, const string& strXmlFilePath, const string& strXmlFolder, CParameterMgr::ElementLibrary eElementLibrary, const string& strNameAttrituteName)
645{
646 // Init serializing context
647 elementSerializingContext.set(_pElementLibrarySet->getElementLibrary(eElementLibrary), strXmlFolder, _strSchemaFolderLocation);
648
649 // Get Schema file associated to root element
650 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pRootElement->getKind() + ".xsd";
651
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200652 CXmlFileDocSource fileDocSource(strXmlFilePath, strXmlSchemaFilePath, pRootElement->getKind(), pRootElement->getName(), strNameAttrituteName);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200653
654 // Start clean
655 pRootElement->clean();
656
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200657 CXmlMemoryDocSink memorySink(pRootElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200658
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200659 if (!memorySink.process(fileDocSource, elementSerializingContext)) {
660 //Cleanup
Patrick Benavoli68a91282011-08-31 11:23:23 +0200661 pRootElement->clean();
662
663 return false;
664 }
665
Patrick Benavoli68a91282011-08-31 11:23:23 +0200666 return true;
667}
668
669// Init
670bool CParameterMgr::init(string& strError)
671{
672 return base::init(strError);
673}
674
675// Selection criteria interface
676CSelectionCriterionType* CParameterMgr::createSelectionCriterionType(bool bIsInclusive)
677{
678 // Propagate
679 return getSelectionCriteria()->createSelectionCriterionType(bIsInclusive);
680}
681
682CSelectionCriterion* CParameterMgr::createSelectionCriterion(const string& strName, const CSelectionCriterionType* pSelectionCriterionType)
683{
684 // Propagate
685 return getSelectionCriteria()->createSelectionCriterion(strName, pSelectionCriterionType);
686}
687
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200688// Selection criterion retrieval
689CSelectionCriterion* CParameterMgr::getSelectionCriterion(const string& strName)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200690{
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200691 // Propagate
692 return getSelectionCriteria()->getSelectionCriterion(strName);
693}
694
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100695// Configuration application
Kevin Rocardace81f82012-12-11 16:19:17 +0100696void CParameterMgr::applyConfigurations()
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200697{
698 CAutoLog autoLog(this, "Configuration application request");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200699
700 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +0100701 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200702
703 if (!_bTuningModeIsOn) {
704
705 // Apply configuration(s)
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100706 doApplyConfigurations(false);
Frédéric Boisnarddaaa63c2012-08-27 15:48:15 +0200707 } else {
708
Kevin Rocardace81f82012-12-11 16:19:17 +0100709 log_warning("Configurations were not applied because the TuningMode is on");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200710 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200711}
712
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200713// Get the configurableElement corresponding to the given path
714const CConfigurableElement* CParameterMgr::getConfigurableElement(const string& strPath,
715 string& strError) const
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200716{
Patrick Benavoli065264a2011-11-20 15:46:41 +0100717 CPathNavigator pathNavigator(strPath);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200718
Patrick Benavoli065264a2011-11-20 15:46:41 +0100719 // Nagivate through system class
720 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
721
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100722 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100723 }
724
725 // Find element
726 const CElement* pElement = getConstSystemClass()->findDescendant(pathNavigator);
727
728 if (!pElement) {
729
Kevin Rocard4c3f8d82013-11-21 12:16:28 +0100730 strError = "Path not found: " + strPath;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100731
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100732 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100733 }
734
735 // Check found element is a parameter
736 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pElement);
737
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200738 return pConfigurableElement;
739}
740
741// Dynamic parameter handling
742CParameterHandle* CParameterMgr::createParameterHandle(const string& strPath, string& strError)
743{
744 const CConfigurableElement* pConfigurableElement = getConfigurableElement(strPath, strError);
745
746 if (!pConfigurableElement) {
747
748 // Element not found
Kevin Rocard4c3f8d82013-11-21 12:16:28 +0100749 strError = "Element not found: " + strPath;
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200750 return NULL;
751 }
752
Patrick Benavoli065264a2011-11-20 15:46:41 +0100753 if (!pConfigurableElement->isParameter()) {
754
755 // Element is not parameter
Kevin Rocard4c3f8d82013-11-21 12:16:28 +0100756 strError = "Not a parameter: " + strPath;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100757
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100758 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100759 }
760
761 // Convert as parameter and return new handle
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200762 return new CParameterHandle(static_cast<const CBaseParameter*>(pConfigurableElement), this);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200763}
764
Kevin Rocardecf93102013-07-10 18:28:10 +0200765void CParameterMgr::setFailureOnMissingSubsystem(bool bFail)
766{
767 _bFailOnMissingSubsystem = bFail;
768}
769
770bool CParameterMgr::getFailureOnMissingSubsystem() const
771{
772 return _bFailOnMissingSubsystem;
773}
Kevin Rocardd6909eb2013-07-18 09:13:51 +0200774
775void CParameterMgr::setFailureOnFailedSettingsLoad(bool bFail)
776{
777 _bFailOnFailedSettingsLoad = bFail;
778}
779bool CParameterMgr::getFailureOnFailedSettingsLoad()
780{
781 return _bFailOnFailedSettingsLoad;
782}
Patrick Benavoli68a91282011-08-31 11:23:23 +0200783/////////////////// Remote command parsers
Patrick Benavoli592ae562011-09-05 16:53:58 +0200784/// Version
Patrick Benavoli63499d42011-10-24 18:50:03 +0200785CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::versionCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli592ae562011-09-05 16:53:58 +0200786{
787 (void)remoteCommand;
788
Patrick Benavoli63499d42011-10-24 18:50:03 +0200789 // Show version
790 strResult = getVersion();
Patrick Benavoli592ae562011-09-05 16:53:58 +0200791
Patrick Benavoli63499d42011-10-24 18:50:03 +0200792 return CCommandHandler::ESucceeded;
Patrick Benavoli592ae562011-09-05 16:53:58 +0200793}
794
Patrick Benavoli68a91282011-08-31 11:23:23 +0200795/// Status
Patrick Benavoli63499d42011-10-24 18:50:03 +0200796CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::statusCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200797{
798 (void)remoteCommand;
799 // System class
800 const CSystemClass* pSystemClass = getSystemClass();
801
Patrick Benavoli68a91282011-08-31 11:23:23 +0200802 // Show status
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200803 /// General section
804 appendTitle(strResult, "General:");
805 // System class
Patrick Benavoli68a91282011-08-31 11:23:23 +0200806 strResult += "System Class: ";
807 strResult += pSystemClass->getName();
808 strResult += "\n";
809
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200810 // Tuning mode
Patrick Benavoli68a91282011-08-31 11:23:23 +0200811 strResult += "Tuning Mode: ";
812 strResult += tuningModeOn() ? "on" : "off";
813 strResult += "\n";
814
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200815 // Value space
Patrick Benavoli68a91282011-08-31 11:23:23 +0200816 strResult += "Value Space: ";
817 strResult += valueSpaceIsRaw() ? "raw" : "real";
818 strResult += "\n";
819
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200820 // Output raw format
821 strResult += "Output Raw Format: ";
822 strResult += outputRawFormatIsHex() ? "hex" : "dec";
823 strResult += "\n";
824
825 // Auto Sync
Patrick Benavoli68a91282011-08-31 11:23:23 +0200826 strResult += "Auto Sync: ";
827 strResult += autoSyncOn() ? "on" : "off";
828 strResult += "\n";
829
830 /// Subsystem list
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200831 appendTitle(strResult, "Subsystems:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200832 string strSubsystemList;
833 pSystemClass->listChildrenPaths(strSubsystemList);
834 strResult += strSubsystemList;
835
836 /// Last applied configurations
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200837 appendTitle(strResult, "Last Applied [Pending] Configurations:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200838 string strLastAppliedConfigurations;
839 getConfigurableDomains()->listLastAppliedConfigurations(strLastAppliedConfigurations);
840 strResult += strLastAppliedConfigurations;
841
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200842 /// Criteria states
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200843 appendTitle(strResult, "Selection Criteria:");
Kevin Rocard7f265822012-12-07 18:51:22 +0100844 list<string> lstrSelectionCriteria;
845 getSelectionCriteria()->listSelectionCriteria(lstrSelectionCriteria, false, true);
846 // Concatenate the criterion list as the command result
Frederic Boisnard390b36d2013-05-23 15:28:31 +0200847 string strCriteriaStates;
848 CUtility::asString(lstrSelectionCriteria, strCriteriaStates);
849 strResult += strCriteriaStates;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200850
Patrick Benavoli63499d42011-10-24 18:50:03 +0200851 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200852}
853
854/// Tuning Mode
Patrick Benavoli63499d42011-10-24 18:50:03 +0200855CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200856{
857 if (remoteCommand.getArgument(0) == "on") {
858
859 if (setTuningMode(true, strResult)) {
860
Patrick Benavoli63499d42011-10-24 18:50:03 +0200861 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200862 }
863 } else if (remoteCommand.getArgument(0) == "off") {
864
865 if (setTuningMode(false, strResult)) {
866
Patrick Benavoli63499d42011-10-24 18:50:03 +0200867 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200868 }
869 } else {
870 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200871 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200872 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200873 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200874}
875
Patrick Benavoli63499d42011-10-24 18:50:03 +0200876CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200877{
878 (void)remoteCommand;
879
880 strResult = tuningModeOn() ? "on" : "off";
881
Patrick Benavoli63499d42011-10-24 18:50:03 +0200882 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200883}
884
885/// Value Space
Patrick Benavoli63499d42011-10-24 18:50:03 +0200886CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200887{
888 (void)strResult;
889
890 if (remoteCommand.getArgument(0) == "raw") {
891
892 setValueSpace(true);
893
Patrick Benavoli63499d42011-10-24 18:50:03 +0200894 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200895
896 } else if (remoteCommand.getArgument(0) == "real") {
897
898 setValueSpace(false);
899
Patrick Benavoli63499d42011-10-24 18:50:03 +0200900 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200901
902 } else {
903 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200904 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200905 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200906 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200907}
908
Patrick Benavoli63499d42011-10-24 18:50:03 +0200909CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200910{
911 (void)remoteCommand;
912
913 strResult = valueSpaceIsRaw() ? "raw" : "real";
914
Patrick Benavoli63499d42011-10-24 18:50:03 +0200915 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200916}
917
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200918/// Output Raw Format
Patrick Benavoli63499d42011-10-24 18:50:03 +0200919CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200920{
921 (void)strResult;
922
923 if (remoteCommand.getArgument(0) == "hex") {
924
925 setOutputRawFormat(true);
926
Patrick Benavoli63499d42011-10-24 18:50:03 +0200927 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200928
929 } else if (remoteCommand.getArgument(0) == "dec") {
930
931 setOutputRawFormat(false);
932
Patrick Benavoli63499d42011-10-24 18:50:03 +0200933 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200934
935 } else {
936 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200937 return CCommandHandler::EShowUsage;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200938 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200939 return CCommandHandler::EFailed;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200940}
941
Patrick Benavoli63499d42011-10-24 18:50:03 +0200942CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200943{
944 (void)remoteCommand;
945
946 strResult = outputRawFormatIsHex() ? "hex" : "dec";
947
Patrick Benavoli63499d42011-10-24 18:50:03 +0200948 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200949}
950
Patrick Benavoli68a91282011-08-31 11:23:23 +0200951/// Sync
Patrick Benavoli63499d42011-10-24 18:50:03 +0200952CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200953{
954 if (remoteCommand.getArgument(0) == "on") {
955
956 if (setAutoSync(true, strResult)) {
957
Patrick Benavoli63499d42011-10-24 18:50:03 +0200958 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200959 }
960 } else if (remoteCommand.getArgument(0) == "off") {
961
962 if (setAutoSync(false, strResult)) {
963
Patrick Benavoli63499d42011-10-24 18:50:03 +0200964 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200965 }
966 } else {
967 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200968 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200969 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200970 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200971}
972
Patrick Benavoli63499d42011-10-24 18:50:03 +0200973CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200974{
975 (void)remoteCommand;
976
977 strResult = autoSyncOn() ? "on" : "off";
978
Patrick Benavoli63499d42011-10-24 18:50:03 +0200979 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200980}
981
Patrick Benavoli63499d42011-10-24 18:50:03 +0200982CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::syncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200983{
984 (void)remoteCommand;
985
Patrick Benavoli63499d42011-10-24 18:50:03 +0200986 return sync(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200987}
988
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200989/// Criteria
Patrick Benavoli63499d42011-10-24 18:50:03 +0200990CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listCriteriaCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200991{
992 (void)remoteCommand;
993
Kevin Rocard4eae8272013-04-18 19:12:46 +0200994 bool humanReadable = true;
Kevin Rocard7f265822012-12-07 18:51:22 +0100995
Kevin Rocard4eae8272013-04-18 19:12:46 +0200996 // Look for optional arguments
997 if (remoteCommand.getArgumentCount() >= 1) {
998
999 // If csv is provided, format the criterion list in Commas Separated Value pairs
1000 if (remoteCommand.getArgument(0) == "csv") {
1001 humanReadable = false;
1002 } else {
1003 return CCommandHandler::EShowUsage;
1004 }
1005 }
1006
1007 list<string> lstrResult;
1008 getSelectionCriteria()->listSelectionCriteria(lstrResult, true, humanReadable);
Kevin Rocard7f265822012-12-07 18:51:22 +01001009
1010 // Concatenate the criterion list as the command result
Frederic Boisnard390b36d2013-05-23 15:28:31 +02001011 CUtility::asString(lstrResult, strResult);
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001012
Patrick Benavoli63499d42011-10-24 18:50:03 +02001013 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001014}
Patrick Benavoli68a91282011-08-31 11:23:23 +02001015
1016/// Domains
Patrick Benavoli63499d42011-10-24 18:50:03 +02001017CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001018{
1019 (void)remoteCommand;
1020
Patrick Benavoli63499d42011-10-24 18:50:03 +02001021 getConfigurableDomains()->listDomains(strResult);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001022
Patrick Benavoli63499d42011-10-24 18:50:03 +02001023 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001024}
1025
Patrick Benavoli63499d42011-10-24 18:50:03 +02001026CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001027{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001028 return createDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001029}
1030
Patrick Benavoli63499d42011-10-24 18:50:03 +02001031CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001032{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001033 return deleteDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001034}
1035
Kevin Rocard170f0a42012-06-18 13:56:05 +02001036CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteAllDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1037{
1038 (void)remoteCommand;
1039
1040 return deleteAllDomains(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1041}
1042
Patrick Benavoli63499d42011-10-24 18:50:03 +02001043CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001044{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001045 return getConfigurableDomains()->renameDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001046}
1047
Patrick Benavoli63499d42011-10-24 18:50:03 +02001048CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001049{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001050 // Check tuning mode
1051 if (!checkTuningModeOn(strResult)) {
1052
1053 return CCommandHandler::EFailed;
1054 }
1055
1056 // Set property
1057 bool bSequenceAware;
1058
1059 if (remoteCommand.getArgument(1) == "true") {
1060
1061 bSequenceAware = true;
1062
1063 } else if (remoteCommand.getArgument(1) == "false") {
1064
1065 bSequenceAware = false;
1066
1067 } else {
1068 // Show usage
1069 return CCommandHandler::EShowUsage;
1070 }
1071
1072 return getConfigurableDomains()->setSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001073}
1074
Patrick Benavoli63499d42011-10-24 18:50:03 +02001075CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001076{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001077 // Get property
1078 bool bSequenceAware;
1079
1080 if (!getConfigurableDomains()->getSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult)) {
1081
1082 return CCommandHandler::EFailed;
1083 }
1084
1085 strResult = bSequenceAware ? "true" : "false";
1086
1087 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001088}
1089
Patrick Benavoli63499d42011-10-24 18:50:03 +02001090CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001091{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001092 return getConfigurableDomains()->listDomainElements(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001093}
1094
Patrick Benavoli63499d42011-10-24 18:50:03 +02001095CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::addElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001096{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001097 return addConfigurableElementToDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1098}
1099
1100CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::removeElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1101{
1102 return removeConfigurableElementFromDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1103}
1104
1105CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::splitDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1106{
1107 return split(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001108}
1109
1110/// Configurations
Patrick Benavoli63499d42011-10-24 18:50:03 +02001111CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConfigurationsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001112{
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001113 return getConstConfigurableDomains()->listConfigurations(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
1114}
1115
1116CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1117{
1118 (void)remoteCommand;
1119
1120 // Dummy error context
1121 string strError;
1122 CErrorContext errorContext(strError);
1123
1124 // Dump
1125 getConstConfigurableDomains()->dumpContent(strResult, errorContext);
1126
1127 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001128}
1129
Patrick Benavoli63499d42011-10-24 18:50:03 +02001130CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001131{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001132 return createConfiguration(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::deleteConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001136{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001137 return deleteConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), 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::renameConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001141{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001142 return getConfigurableDomains()->renameConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), 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::saveConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001146{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001147 return saveConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001148}
1149
Patrick Benavoli63499d42011-10-24 18:50:03 +02001150CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::restoreConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001151{
Kevin Rocardace81f82012-12-11 16:19:17 +01001152 list<string> lstrResult;
1153 if (!restoreConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), lstrResult)) {
1154 //Concatenate the error list as the command result
Frederic Boisnard390b36d2013-05-23 15:28:31 +02001155 CUtility::asString(lstrResult, strResult);
Kevin Rocardace81f82012-12-11 16:19:17 +01001156
1157 return CCommandHandler::EFailed;
1158 }
1159 return CCommandHandler::EDone;
Patrick Benavoli63499d42011-10-24 18:50:03 +02001160}
1161
1162CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1163{
1164 // Check tuning mode
1165 if (!checkTuningModeOn(strResult)) {
1166
1167 return CCommandHandler::EFailed;
1168 }
1169
1170 // Build configurable element path list
1171 vector<string> astrNewElementSequence;
1172
1173 uint32_t uiArgument;
1174
1175 for (uiArgument = 2; uiArgument < remoteCommand.getArgumentCount(); uiArgument++) {
1176
1177 astrNewElementSequence.push_back(remoteCommand.getArgument(uiArgument));
1178 }
1179
1180 // Delegate to configurable domains
1181 return getConfigurableDomains()->setElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), astrNewElementSequence, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1182}
1183
1184CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1185{
1186 // Delegate to configurable domains
1187 return getConfigurableDomains()->getElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001188}
1189
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001190CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1191{
1192 // Delegate to configurable domains
1193 return getConfigurableDomains()->setApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.packArguments(2, remoteCommand.getArgumentCount() - 2), getConstSelectionCriteria()->getSelectionCriteriaDefinition(), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1194}
1195
1196CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::clearRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1197{
1198 // Delegate to configurable domains
1199 return getConfigurableDomains()->clearApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1200}
1201
1202CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1203{
1204 // Delegate to configurable domains
1205 return getConfigurableDomains()->getApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
1206}
1207
Patrick Benavoli68a91282011-08-31 11:23:23 +02001208/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001209CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001210{
1211 CElementLocator elementLocator(getSystemClass(), false);
1212
1213 CElement* pLocatedElement = NULL;
1214
1215 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1216
Patrick Benavoli63499d42011-10-24 18:50:03 +02001217 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001218 }
1219
1220 strResult = string("\n");
1221
1222 if (!pLocatedElement) {
1223
1224 // List from root folder
1225
1226 // Return system class qualified name
1227 pLocatedElement = getSystemClass();
1228 }
1229
1230 // Return sub-elements
1231 strResult += pLocatedElement->listQualifiedPaths(false);
1232
Patrick Benavoli63499d42011-10-24 18:50:03 +02001233 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001234}
1235
1236/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001237CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listParametersCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001238{
1239 CElementLocator elementLocator(getSystemClass(), false);
1240
1241 CElement* pLocatedElement = NULL;
1242
1243 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1244
Patrick Benavoli63499d42011-10-24 18:50:03 +02001245 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001246 }
1247
1248 strResult = string("\n");
1249
1250 if (!pLocatedElement) {
1251
1252 // List from root folder
1253
1254 // Return system class qualified name
1255 pLocatedElement = getSystemClass();
1256 }
1257
1258 // Return sub-elements
1259 strResult += pLocatedElement->listQualifiedPaths(true);
1260
Patrick Benavoli63499d42011-10-24 18:50:03 +02001261 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001262}
1263
Patrick Benavoli63499d42011-10-24 18:50:03 +02001264CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001265{
1266 CElementLocator elementLocator(getSystemClass());
1267
1268 CElement* pLocatedElement = NULL;
1269
1270 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1271
Patrick Benavoli63499d42011-10-24 18:50:03 +02001272 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001273 }
1274
1275 string strError;
1276
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001277 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001278
1279 // Dump elements
1280 pLocatedElement->dumpContent(strResult, parameterAccessContext);
1281
Patrick Benavoli63499d42011-10-24 18:50:03 +02001282 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001283}
1284
Patrick Benavoli63499d42011-10-24 18:50:03 +02001285CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSizeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001286{
1287 CElementLocator elementLocator(getSystemClass());
1288
1289 CElement* pLocatedElement = NULL;
1290
1291 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1292
Patrick Benavoli63499d42011-10-24 18:50:03 +02001293 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001294 }
1295
1296 // Converted to actual sizable element
1297 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1298
1299 // Get size as string
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001300 strResult = pConfigurableElement->getFootprintAsString();
Patrick Benavoli68a91282011-08-31 11:23:23 +02001301
Patrick Benavoli63499d42011-10-24 18:50:03 +02001302 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001303}
1304
Patrick Benavoli63499d42011-10-24 18:50:03 +02001305CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showPropertiesCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001306{
1307 CElementLocator elementLocator(getSystemClass());
1308
1309 CElement* pLocatedElement = NULL;
1310
1311 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1312
Patrick Benavoli63499d42011-10-24 18:50:03 +02001313 return CCommandHandler::EFailed;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001314 }
1315
1316 // Convert element
1317 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1318
1319 // Return element properties
1320 pConfigurableElement->showProperties(strResult);
1321
Patrick Benavoli63499d42011-10-24 18:50:03 +02001322 return CCommandHandler::ESucceeded;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001323}
1324
Patrick Benavoli63499d42011-10-24 18:50:03 +02001325CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001326{
1327 string strValue;
1328
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001329 if (!accessParameterValue(remoteCommand.getArgument(0), strValue, false, strResult)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001330
Patrick Benavoli63499d42011-10-24 18:50:03 +02001331 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001332 }
1333 // Succeeded
1334 strResult = strValue;
1335
Patrick Benavoli63499d42011-10-24 18:50:03 +02001336 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001337}
1338
Patrick Benavoli63499d42011-10-24 18:50:03 +02001339CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001340{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001341 // Check tuning mode
1342 if (!checkTuningModeOn(strResult)) {
1343
1344 return CCommandHandler::EFailed;
1345 }
1346 // Get value to set
1347 string strValue = remoteCommand.packArguments(1, remoteCommand.getArgumentCount() - 1);
1348
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001349 return accessParameterValue(remoteCommand.getArgument(0), strValue, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001350}
1351
Patrick Benavoli63499d42011-10-24 18:50:03 +02001352CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listBelongingDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001353{
1354 CElementLocator elementLocator(getSystemClass());
1355
1356 CElement* pLocatedElement = NULL;
1357
1358 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1359
Patrick Benavoli63499d42011-10-24 18:50:03 +02001360 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001361 }
1362
1363 // Convert element
1364 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1365
1366 // Return element belonging domains
1367 pConfigurableElement->listBelongingDomains(strResult);
1368
Patrick Benavoli63499d42011-10-24 18:50:03 +02001369 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001370}
1371
Patrick Benavoli63499d42011-10-24 18:50:03 +02001372CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001373{
1374 CElementLocator elementLocator(getSystemClass());
1375
1376 CElement* pLocatedElement = NULL;
1377
1378 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1379
Patrick Benavoli63499d42011-10-24 18:50:03 +02001380 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001381 }
1382
1383 // Convert element
1384 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1385
1386 // Return element belonging domains
1387 pConfigurableElement->listAssociatedDomains(strResult);
1388
Patrick Benavoli63499d42011-10-24 18:50:03 +02001389 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001390}
1391
Patrick Benavoli63499d42011-10-24 18:50:03 +02001392CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001393{
1394 (void)remoteCommand;
1395
1396 getConfigurableDomains()->listAssociatedElements(strResult);
1397
Patrick Benavoli63499d42011-10-24 18:50:03 +02001398 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001399}
1400
Patrick Benavoli63499d42011-10-24 18:50:03 +02001401CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConflictingElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001402{
1403 (void)remoteCommand;
1404
1405 getConfigurableDomains()->listConflictingElements(strResult);
1406
Patrick Benavoli63499d42011-10-24 18:50:03 +02001407 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001408}
1409
Patrick Benavoli63499d42011-10-24 18:50:03 +02001410CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listRogueElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001411{
1412 (void)remoteCommand;
1413
1414 getSystemClass()->listRogueElements(strResult);
1415
Patrick Benavoli63499d42011-10-24 18:50:03 +02001416 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001417}
1418
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001419CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getConfigurationParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1420{
1421 string strOutputValue;
1422 string strError;
1423
1424 if (!accessConfigurationValue(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), strOutputValue, false, strError)) {
1425
1426 strResult = strError;
1427 return CCommandHandler::EFailed;
1428 }
1429 // Succeeded
1430 strResult = strOutputValue;
1431
1432 return CCommandHandler::ESucceeded;
1433}
1434
1435CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setConfigurationParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1436{
1437 // Get value to set
1438 string strValue = remoteCommand.packArguments(3, remoteCommand.getArgumentCount() - 3);
1439
1440 bool bSuccess = accessConfigurationValue(remoteCommand.getArgument(0),
1441 remoteCommand.getArgument(1),
1442 remoteCommand.getArgument(2),
1443 strValue, true, strResult);
1444
1445 return bSuccess ? CCommandHandler::EDone : CCommandHandler::EFailed;
1446}
1447
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +02001448CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showMappingCommmandProcess(
1449 const IRemoteCommand& remoteCommand,
1450 string& strResult)
1451{
1452 if (!getParameterMapping(remoteCommand.getArgument(0), strResult)) {
1453
1454 return CCommandHandler::EFailed;
1455 }
1456
1457 return CCommandHandler::ESucceeded;
1458}
1459
Patrick Benavoli68a91282011-08-31 11:23:23 +02001460/// Settings Import/Export
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001461CParameterMgr::CCommandHandler::CommandStatus
1462 CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess(
1463 const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001464{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001465 string strFileName = remoteCommand.getArgument(0);
1466 return exportDomainsXml(strFileName, false, true, strResult) ?
1467 CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001468}
1469
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001470CParameterMgr::CCommandHandler::CommandStatus
1471 CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess(
1472 const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001473{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001474 return importDomainsXml(remoteCommand.getArgument(0), false, true, strResult) ?
1475 CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001476}
1477
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001478CParameterMgr::CCommandHandler::CommandStatus
1479 CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess(
1480 const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001481{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001482 string strFileName = remoteCommand.getArgument(0);
1483 return exportDomainsXml(strFileName, true, true, strResult) ?
1484 CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001485}
1486
Patrick Benavoli63499d42011-10-24 18:50:03 +02001487CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001488{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001489 return importDomainsXml(remoteCommand.getArgument(0), true, true, 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::exportSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001493{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001494 return exportDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001495}
1496
Patrick Benavoli63499d42011-10-24 18:50:03 +02001497CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001498{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001499 return importDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001500}
1501
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001502CParameterMgr::CCommandHandler::CommandStatus
1503 CParameterMgr::getConfigurableDomainsWithSettingsXMLCommmandProcess(
1504 const IRemoteCommand& remoteCommand, string& strResult)
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001505{
1506 (void)remoteCommand;
1507
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001508 if (!exportDomainsXml(strResult, true, false, strResult)) {
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001509
1510 return CCommandHandler::EFailed;
1511 }
1512 // Succeeded
1513 return CCommandHandler::ESucceeded;
1514}
1515
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001516CParameterMgr::CCommandHandler::CommandStatus
1517 CParameterMgr::setConfigurableDomainsWithSettingsXMLCommmandProcess(
1518 const IRemoteCommand& remoteCommand, string& strResult)
1519{
1520 return importDomainsXml(remoteCommand.getArgument(0), true, false, strResult) ?
1521 CCommandHandler::EDone : CCommandHandler::EFailed;
1522}
1523
1524CParameterMgr::CCommandHandler::CommandStatus
1525 CParameterMgr::getSystemClassXMLCommmandProcess(
1526 const IRemoteCommand& remoteCommand, string& strResult)
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001527{
1528 (void)remoteCommand;
1529
1530 if (!getSystemClassXMLString(strResult)) {
1531
1532 return CCommandHandler::EFailed;
1533 }
1534 // Succeeded
1535 return CCommandHandler::ESucceeded;
1536}
1537
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001538// User set/get parameters in main BlackBoard
1539bool CParameterMgr::accessParameterValue(const string& strPath, string& strValue, bool bSet, string& strError)
1540{
1541 // Define context
1542 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
1543
Frédéric Boisnard150407c2013-03-15 14:46:23 +01001544 // Activate the auto synchronization with the hardware
1545 if (bSet) {
1546
1547 parameterAccessContext.setAutoSync(_bAutoSyncOn);
1548 }
1549
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001550 return accessValue(parameterAccessContext, strPath, strValue, bSet, strError);
1551}
1552
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +02001553// User get parameter mapping
1554bool CParameterMgr::getParameterMapping(const string& strPath, string& strResult) const
1555{
1556 CPathNavigator pathNavigator(strPath);
1557
1558 // Nagivate through system class
1559 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strResult)) {
1560
1561 return false;
1562 }
1563
1564 // Get the ConfigurableElement corresponding to strPath
1565 const CConfigurableElement* pConfigurableElement = getConfigurableElement(strPath, strResult);
1566 if (!pConfigurableElement) {
1567
1568 return false;
1569 }
1570
1571 // Find the list of the ancestors of the current ConfigurableElement that have a mapping
1572 list<const CConfigurableElement*> configurableElementPath;
1573 pConfigurableElement->getListOfElementsWithMapping(configurableElementPath);
1574
1575 // Get the Subsystem containing the ConfigurableElement
1576 const CSubsystem* pSubsystem = pConfigurableElement->getBelongingSubsystem();
1577 if (!pSubsystem) {
1578
1579 strResult = "Unable to find the Subsystem containing the parameter";
1580 return false;
1581 }
1582
1583 // Fetch the mapping corresponding to the ConfigurableElement
1584 strResult = pSubsystem->getMapping(configurableElementPath);
1585
1586 return true;
1587}
1588
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001589// User set/get parameters in specific Configuration BlackBoard
1590bool CParameterMgr::accessConfigurationValue(const string& strDomain, const string& strConfiguration, const string& strPath, string& strValue, bool bSet, string& strError)
1591{
1592 CElementLocator elementLocator(getSystemClass());
1593
1594 CElement* pLocatedElement = NULL;
1595
1596 if (!elementLocator.locate(strPath, &pLocatedElement, strError)) {
1597
1598 return false;
1599 }
1600
1601 // Convert element
1602 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1603
1604 // Get the Configuration blackboard and the Base Offset of the configurable element in this blackboard
1605 uint32_t uiBaseOffset;
1606 bool bIsLastApplied;
1607
1608 CParameterBlackboard* pConfigurationBlackboard = getConstConfigurableDomains()->findConfigurationBlackboard(strDomain, strConfiguration, pConfigurableElement, uiBaseOffset, bIsLastApplied, strError);
1609
1610 if (!pConfigurationBlackboard) {
1611
1612 return false;
1613 }
1614
1615 log_info("Element %s in Domain %s, offset: %d, base offset: %d", strPath.c_str(), strDomain.c_str(), pConfigurableElement->getOffset(), uiBaseOffset);
1616
1617 /// Update the Configuration Blackboard
1618
Frédéric Boisnard150407c2013-03-15 14:46:23 +01001619 // 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 +01001620 CParameterAccessContext parameterAccessContext(strError, pConfigurationBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex, uiBaseOffset);
1621
1622 // Access Value in the Configuration Blackboard
1623 if (!accessValue(parameterAccessContext, strPath, strValue, bSet, strError)) {
1624
1625 return false;
1626 }
1627
1628 /// If the Configuration is the last one applied, update the Main Blackboard as well
1629
1630 if (bIsLastApplied) {
1631
1632 // Define Main context
1633 parameterAccessContext.setParameterBlackboard(_pMainParameterBlackboard);
1634
Frédéric Boisnard150407c2013-03-15 14:46:23 +01001635 // Activate the auto synchronization with the hardware
1636 if (bSet) {
1637
1638 parameterAccessContext.setAutoSync(_bAutoSyncOn);
1639 }
1640
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001641 // Access Value in the Main Blackboard
1642 return accessValue(parameterAccessContext, strPath, strValue, bSet, strError);
1643 }
1644
1645 return true;
1646}
1647
Patrick Benavoli68a91282011-08-31 11:23:23 +02001648// User set/get parameters
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001649bool CParameterMgr::accessValue(CParameterAccessContext& parameterAccessContext, const string& strPath, string& strValue, bool bSet, string& strError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001650{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001651 // Lock state
1652 CAutoLock autoLock(&_blackboardMutex);
1653
1654 CPathNavigator pathNavigator(strPath);
1655
1656 // Nagivate through system class
1657 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001658
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +02001659 parameterAccessContext.setError(strError);
1660
Patrick Benavoli68a91282011-08-31 11:23:23 +02001661 return false;
1662 }
1663
Patrick Benavoli065264a2011-11-20 15:46:41 +01001664 // Do the get
1665 return getConstSystemClass()->accessValue(pathNavigator, strValue, bSet, parameterAccessContext);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001666}
1667
1668// Tuning mode
1669bool CParameterMgr::setTuningMode(bool bOn, string& strError)
1670{
1671 // Tuning allowed?
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001672 if (bOn && !getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001673
1674 strError = "Tuning prohibited";
1675
1676 return false;
1677 }
1678 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +01001679 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001680
1681 // Warn domains about exiting tuning mode
1682 if (!bOn && _bTuningModeIsOn) {
1683
1684 // Ensure application of currently selected configurations
Patrick Benavoli1387bda2011-08-31 11:23:24 +02001685 // Force-apply configurations
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01001686 doApplyConfigurations(true);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001687
Patrick Benavoli68a91282011-08-31 11:23:23 +02001688 // Turn auto sync back on
1689 _bAutoSyncOn = true;
1690 }
1691
1692 // Store
1693 _bTuningModeIsOn = bOn;
1694
Patrick Benavoli68a91282011-08-31 11:23:23 +02001695 return true;
1696}
1697
1698bool CParameterMgr::tuningModeOn() const
1699{
1700 return _bTuningModeIsOn;
1701}
1702
1703// Current value space for user set/get value interpretation
1704void CParameterMgr::setValueSpace(bool bIsRaw)
1705{
1706 _bValueSpaceIsRaw = bIsRaw;
1707}
1708
1709bool CParameterMgr::valueSpaceIsRaw()
1710{
1711 return _bValueSpaceIsRaw;
1712}
1713
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001714// Current Output Raw Format for user get value interpretation
1715void CParameterMgr::setOutputRawFormat(bool bIsHex)
1716{
1717 _bOutputRawFormatIsHex = bIsHex;
1718}
1719
1720bool CParameterMgr::outputRawFormatIsHex()
1721{
1722 return _bOutputRawFormatIsHex;
1723}
1724
Patrick Benavoli68a91282011-08-31 11:23:23 +02001725/// Sync
1726// Automatic hardware synchronization control (during tuning session)
1727bool CParameterMgr::setAutoSync(bool bAutoSyncOn, string& strError)
1728{
1729 // Check tuning mode
1730 if (!checkTuningModeOn(strError)) {
1731
1732 return false;
1733 }
1734 // Warn domains about turning auto sync back on
1735 if (bAutoSyncOn && !_bAutoSyncOn) {
1736
Patrick Benavoli592ae562011-09-05 16:53:58 +02001737 // Do the synchronization at system class level (could be optimized by keeping track of all modified parameters)
1738 if (!sync(strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001739
1740 return false;
1741 }
1742 }
1743
1744 // Set Auto sync
1745 _bAutoSyncOn = bAutoSyncOn;
1746
1747 return true;
1748}
1749
1750bool CParameterMgr::autoSyncOn() const
1751{
1752 return _bAutoSyncOn;
1753}
1754
1755// Manual hardware synchronization control (during tuning session)
1756bool CParameterMgr::sync(string& strError)
1757{
1758 // Check tuning mode
1759 if (!checkTuningModeOn(strError)) {
1760
1761 return false;
1762 }
1763 // Warn domains about turning auto sync back on
1764 if (_bAutoSyncOn) {
1765
1766 strError = "Feature unavailable when Auto Sync is on";
1767
1768 return false;
1769 }
1770
1771 // Get syncer set
1772 CSyncerSet syncerSet;
1773 // ... from system class
1774 getConstSystemClass()->fillSyncerSet(syncerSet);
Kevin Rocardace81f82012-12-11 16:19:17 +01001775
Patrick Benavoli68a91282011-08-31 11:23:23 +02001776 // Sync
Kevin Rocardace81f82012-12-11 16:19:17 +01001777 list<string> lstrError;
1778 if (! syncerSet.sync(*_pMainParameterBlackboard, false, &lstrError)){
1779
Frederic Boisnard390b36d2013-05-23 15:28:31 +02001780 CUtility::asString(lstrError, strError);
Kevin Rocardace81f82012-12-11 16:19:17 +01001781 return false;
1782 };
1783
1784 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001785}
1786
1787// Content dump
1788void CParameterMgr::logStructureContent(string& strContent) const
1789{
1790 string strError;
1791
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001792 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001793
1794 dumpContent(strContent, parameterAccessContext);
1795}
1796
1797// Configuration/Domains handling
1798bool CParameterMgr::createDomain(const string& strName, string& strError)
1799{
1800 // Check tuning mode
1801 if (!checkTuningModeOn(strError)) {
1802
1803 return false;
1804 }
1805
1806 // Delegate to configurable domains
1807 return getConfigurableDomains()->createDomain(strName, strError);
1808}
1809
1810bool CParameterMgr::deleteDomain(const string& strName, string& strError)
1811{
1812 // Check tuning mode
1813 if (!checkTuningModeOn(strError)) {
1814
1815 return false;
1816 }
1817
1818 // Delegate to configurable domains
1819 return getConfigurableDomains()->deleteDomain(strName, strError);
1820}
1821
Kevin Rocard170f0a42012-06-18 13:56:05 +02001822bool CParameterMgr::deleteAllDomains(string& strError)
1823{
1824 // Check tuning mode
1825 if (!checkTuningModeOn(strError)) {
1826
1827 return false;
1828 }
1829
1830 // Delegate to configurable domains
1831 getConfigurableDomains()->deleteAllDomains();
1832
1833 return true;
1834}
1835
Patrick Benavoli68a91282011-08-31 11:23:23 +02001836bool CParameterMgr::createConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1837{
1838 // Check tuning mode
1839 if (!checkTuningModeOn(strError)) {
1840
1841 return false;
1842 }
1843
1844 // Delegate to configurable domains
1845 return getConfigurableDomains()->createConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1846}
1847
1848bool CParameterMgr::deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1849{
1850 // Check tuning mode
1851 if (!checkTuningModeOn(strError)) {
1852
1853 return false;
1854 }
1855
1856 // Delegate to configurable domains
1857 return getConfigurableDomains()->deleteConfiguration(strDomain, strConfiguration, strError);
1858}
1859
Kevin Rocardace81f82012-12-11 16:19:17 +01001860bool CParameterMgr::restoreConfiguration(const string& strDomain, const string& strConfiguration, list<string>& lstrError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001861{
Kevin Rocardace81f82012-12-11 16:19:17 +01001862 string strError;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001863 // Check tuning mode
1864 if (!checkTuningModeOn(strError)) {
1865
Kevin Rocardace81f82012-12-11 16:19:17 +01001866 lstrError.push_back(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001867 return false;
1868 }
1869
1870 // Delegate to configurable domains
Kevin Rocardace81f82012-12-11 16:19:17 +01001871 return getConstConfigurableDomains()->restoreConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, lstrError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001872}
1873
1874bool CParameterMgr::saveConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1875{
1876 // Check tuning mode
1877 if (!checkTuningModeOn(strError)) {
1878
1879 return false;
1880 }
1881
1882 // Delegate to configurable domains
1883 return getConfigurableDomains()->saveConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1884}
1885
1886// Configurable element - domain association
1887bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1888{
1889 // Check tuning mode
1890 if (!checkTuningModeOn(strError)) {
1891
1892 return false;
1893 }
1894
1895 CElementLocator elementLocator(getSystemClass());
1896
1897 CElement* pLocatedElement = NULL;
1898
1899 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1900
1901 return false;
1902 }
1903
1904 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001905 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001906
1907 // Delegate
1908 return getConfigurableDomains()->addConfigurableElementToDomain(strDomain, pConfigurableElement, _pMainParameterBlackboard, strError);
1909}
1910
1911bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1912{
1913 // Check tuning mode
1914 if (!checkTuningModeOn(strError)) {
1915
1916 return false;
1917 }
1918
1919 CElementLocator elementLocator(getSystemClass());
1920
1921 CElement* pLocatedElement = NULL;
1922
1923 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1924
Patrick Benavoli63499d42011-10-24 18:50:03 +02001925 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001926 }
1927
1928 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001929 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001930
1931 // Delegate
1932 return getConfigurableDomains()->removeConfigurableElementFromDomain(strDomain, pConfigurableElement, strError);
1933}
1934
1935bool CParameterMgr::split(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1936{
1937 // Check tuning mode
1938 if (!checkTuningModeOn(strError)) {
1939
1940 return false;
1941 }
1942
1943 CElementLocator elementLocator(getSystemClass());
1944
1945 CElement* pLocatedElement = NULL;
1946
1947 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1948
Patrick Benavoli63499d42011-10-24 18:50:03 +02001949 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001950 }
1951
1952 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001953 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001954
1955 // Delegate
1956 return getConfigurableDomains()->split(strDomain, pConfigurableElement, strError);
1957}
1958
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001959bool CParameterMgr::importDomainsXml(const string& strXmlSource, bool bWithSettings,
1960 bool bFromFile, string& strError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001961{
1962 // Check tuning mode
1963 if (!checkTuningModeOn(strError)) {
1964
1965 return false;
1966 }
1967
1968 // check path is absolute
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001969 if (bFromFile && strXmlSource[0] != '/') {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001970
1971 strError = "Please provide absolute path";
1972
1973 return false;
1974 }
1975 // Root element
1976 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1977
1978 // Context
1979 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1980
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001981 // Selection criteria definition for rule creation
1982 xmlDomainSerializingContext.setSelectionCriteriaDefinition(
1983 getConstSelectionCriteria()->getSelectionCriteriaDefinition());
Patrick Benavoli68a91282011-08-31 11:23:23 +02001984
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001985 // Init serializing context
1986 xmlDomainSerializingContext.set(
1987 _pElementLibrarySet->getElementLibrary(EParameterConfigurationLibrary),
1988 "", _strSchemaFolderLocation);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001989
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001990 // Get Schema file associated to root element
1991 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" +
1992 pConfigurableDomains->getKind() + ".xsd";
1993
1994 // Xml Source
1995 CXmlDocSource* pSource;
1996
1997 if (bFromFile) {
1998
1999 // when importing from a file strXmlSource is the file name
2000 pSource = new CXmlFileDocSource(strXmlSource, strXmlSchemaFilePath,
2001 pConfigurableDomains->getKind(),
2002 pConfigurableDomains->getName(), "SystemClassName");
2003
2004 } else {
2005
2006 // when importing from an xml string, strXmlSource contains the string
2007 pSource = new CXmlStringDocSource(strXmlSource, strXmlSchemaFilePath,
2008 pConfigurableDomains->getKind(),
2009 pConfigurableDomains->getName(), "SystemClassName");
2010
2011 }
2012 // Start clean
2013 pConfigurableDomains->clean();
2014
2015 // Use a doc sink that instantiate Configurable Domains from the given doc source
2016 CXmlMemoryDocSink memorySink(pConfigurableDomains);
2017
2018 bool bProcessSuccess = memorySink.process(*pSource, xmlDomainSerializingContext);
2019
2020 if (!bProcessSuccess) {
2021
2022 //Cleanup
2023 pConfigurableDomains->clean();
2024
2025 } else {
2026
2027 // Validate domains after XML import
2028 pConfigurableDomains->validate(_pMainParameterBlackboard);
2029
Patrick Benavoli68a91282011-08-31 11:23:23 +02002030 }
2031
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002032 delete pSource;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002033
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002034 return bProcessSuccess;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002035}
2036
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002037bool CParameterMgr::exportDomainsXml(string& strXmlDest, bool bWithSettings, bool bToFile,
2038 string& strError) const
Patrick Benavoli68a91282011-08-31 11:23:23 +02002039{
2040 // check path is absolute
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002041 if (bToFile && strXmlDest[0] != '/') {
Patrick Benavoli68a91282011-08-31 11:23:23 +02002042
2043 strError = "Please provide absolute path";
2044
2045 return false;
2046 }
2047
2048 // Root element
2049 const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains();
2050
2051 // Get Schema file associated to root element
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002052 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" +
2053 pConfigurableDomains->getKind() + ".xsd";
Patrick Benavoli68a91282011-08-31 11:23:23 +02002054
2055 // Context
2056 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
2057
2058 // Value space
2059 xmlDomainSerializingContext.setValueSpaceRaw(_bValueSpaceIsRaw);
2060
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02002061 // Output raw format
2062 xmlDomainSerializingContext.setOutputRawFormat(_bOutputRawFormatIsHex);
2063
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002064 // Use a doc source by loading data from instantiated Configurable Domains
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002065 CXmlMemoryDocSource memorySource(pConfigurableDomains, pConfigurableDomains->getKind(),
2066 strXmlSchemaFilePath, "parameter-framework", getVersion());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002067
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002068 // Xml Sink
2069 CXmlDocSink* pSink;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002070
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002071 if (bToFile) {
2072
2073 // Use a doc sink to write the doc data in a file
2074 pSink = new CXmlFileDocSink(strXmlDest);
2075
2076 } else {
2077
2078 // Use a doc sink to write the doc data in a string
2079 pSink = new CXmlStringDocSink(strXmlDest);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002080 }
2081
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002082 bool bProcessSuccess = pSink->process(memorySource, xmlDomainSerializingContext);
2083
2084 delete pSink;
2085 return bProcessSuccess;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002086}
2087
2088// Binary Import/Export
2089bool CParameterMgr::importDomainsBinary(const string& strFileName, string& strError)
2090{
2091 // Check tuning mode
2092 if (!checkTuningModeOn(strError)) {
2093
2094 return false;
2095 }
2096 // check path is absolute
2097 if (strFileName[0] != '/') {
2098
2099 strError = "Please provide absolute path";
2100
2101 return false;
2102 }
2103 // Root element
2104 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
2105
2106 // Serialize in
2107 return pConfigurableDomains->serializeSettings(strFileName, false, _uiStructureChecksum, strError);
2108}
2109
2110bool CParameterMgr::exportDomainsBinary(const string& strFileName, string& strError)
2111{
2112 // check path is absolute
2113 if (strFileName[0] != '/') {
2114
2115 strError = "Please provide absolute path";
2116
2117 return false;
2118 }
Patrick Benavoli68a91282011-08-31 11:23:23 +02002119
Patrick Benavoli68a91282011-08-31 11:23:23 +02002120 // Root element
2121 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
2122
2123 // Serialize out
2124 return pConfigurableDomains->serializeSettings(strFileName, true, _uiStructureChecksum, strError);
2125}
2126
2127// For tuning, check we're in tuning mode
2128bool CParameterMgr::checkTuningModeOn(string& strError) const
2129{
2130 // Tuning Mode on?
2131 if (!_bTuningModeIsOn) {
2132
2133 strError = "Tuning Mode must be on";
2134
2135 return false;
2136 }
2137 return true;
2138}
2139
Patrick Benavoli065264a2011-11-20 15:46:41 +01002140// Tuning mutex dynamic parameter handling
2141pthread_mutex_t* CParameterMgr::getBlackboardMutex()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002142{
Patrick Benavoli065264a2011-11-20 15:46:41 +01002143 return &_blackboardMutex;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002144}
2145
Patrick Benavoli065264a2011-11-20 15:46:41 +01002146// Blackboard reference (dynamic parameter handling)
2147CParameterBlackboard* CParameterMgr::getParameterBlackboard()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002148{
Patrick Benavoli065264a2011-11-20 15:46:41 +01002149 return _pMainParameterBlackboard;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002150}
2151
Patrick Benavoli68a91282011-08-31 11:23:23 +02002152// Dynamic creation library feeding
2153void CParameterMgr::feedElementLibraries()
2154{
2155 // Global Configuration handling
2156 CElementLibrary* pFrameworkConfigurationLibrary = new CElementLibrary;
2157
Kevin Rocarda7b69602013-08-07 16:15:33 +02002158 pFrameworkConfigurationLibrary->addElementBuilder("ParameterFrameworkConfiguration", new TElementBuilderTemplate<CParameterFrameworkConfiguration>());
2159 pFrameworkConfigurationLibrary->addElementBuilder("SubsystemPlugins", new TKindElementBuilderTemplate<CSubsystemPlugins>());
2160 pFrameworkConfigurationLibrary->addElementBuilder("Location", new TKindElementBuilderTemplate<CPluginLocation>());
2161 pFrameworkConfigurationLibrary->addElementBuilder("StructureDescriptionFileLocation", new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>());
2162 pFrameworkConfigurationLibrary->addElementBuilder("SettingsConfiguration", new TKindElementBuilderTemplate<CFrameworkConfigurationGroup>());
2163 pFrameworkConfigurationLibrary->addElementBuilder("ConfigurableDomainsFileLocation", new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>());
2164 pFrameworkConfigurationLibrary->addElementBuilder("BinarySettingsFileLocation", new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002165
2166 _pElementLibrarySet->addElementLibrary(pFrameworkConfigurationLibrary);
2167
2168 // Parameter creation
2169 CElementLibrary* pParameterCreationLibrary = new CElementLibrary;
2170
Kevin Rocarda7b69602013-08-07 16:15:33 +02002171 pParameterCreationLibrary->addElementBuilder("Subsystem", new CSubsystemElementBuilder(getSystemClass()->getSubsystemLibrary()));
2172 pParameterCreationLibrary->addElementBuilder("ComponentType", new TNamedElementBuilderTemplate<CComponentType>());
2173 pParameterCreationLibrary->addElementBuilder("Component", new TNamedElementBuilderTemplate<CComponentInstance>());
2174 pParameterCreationLibrary->addElementBuilder("BitParameter", new TNamedElementBuilderTemplate<CBitParameterType>());
2175 pParameterCreationLibrary->addElementBuilder("BitParameterBlock", new TNamedElementBuilderTemplate<CBitParameterBlockType>());
2176 pParameterCreationLibrary->addElementBuilder("StringParameter", new TNamedElementBuilderTemplate<CStringParameterType>());
2177 pParameterCreationLibrary->addElementBuilder("ParameterBlock", new TNamedElementBuilderTemplate<CParameterBlockType>());
2178 pParameterCreationLibrary->addElementBuilder("BooleanParameter", new TNamedElementBuilderTemplate<CBooleanParameterType>());
2179 pParameterCreationLibrary->addElementBuilder("IntegerParameter", new TNamedElementBuilderTemplate<CIntegerParameterType>());
2180 pParameterCreationLibrary->addElementBuilder("LinearAdaptation", new TElementBuilderTemplate<CLinearParameterAdaptation>());
2181 pParameterCreationLibrary->addElementBuilder("EnumParameter", new TNamedElementBuilderTemplate<CEnumParameterType>());
2182 pParameterCreationLibrary->addElementBuilder("ValuePair", new TElementBuilderTemplate<CEnumValuePair>());
2183 pParameterCreationLibrary->addElementBuilder("FixedPointParameter", new TNamedElementBuilderTemplate<CFixedPointParameterType>());
2184 pParameterCreationLibrary->addElementBuilder("SubsystemInclude", new TKindElementBuilderTemplate<CXmlFileIncluderElement>());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002185
2186 _pElementLibrarySet->addElementLibrary(pParameterCreationLibrary);
2187
2188 // Parameter Configuration Domains creation
2189 CElementLibrary* pParameterConfigurationLibrary = new CElementLibrary;
2190
Kevin Rocarda7b69602013-08-07 16:15:33 +02002191 pParameterConfigurationLibrary->addElementBuilder("ConfigurableDomain", new TNamedElementBuilderTemplate<CConfigurableDomain>());
2192 pParameterConfigurationLibrary->addElementBuilder("Configuration", new TNamedElementBuilderTemplate<CDomainConfiguration>());
2193 pParameterConfigurationLibrary->addElementBuilder("CompoundRule", new TElementBuilderTemplate<CCompoundRule>());
2194 pParameterConfigurationLibrary->addElementBuilder("SelectionCriterionRule", new TElementBuilderTemplate<CSelectionCriterionRule>());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002195
2196 _pElementLibrarySet->addElementLibrary(pParameterConfigurationLibrary);
2197}
2198
2199// Remote Processor Server connection handling
2200bool CParameterMgr::handleRemoteProcessingInterface(string& strError)
2201{
2202 CAutoLog autoLog(this, "Handling remote processing interface");
2203
2204 // Start server if tuning allowed
Patrick Benavoli95ac0342011-11-07 20:32:51 +01002205 if (getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02002206
Kevin Rocardace81f82012-12-11 16:19:17 +01002207 log_info("Loading remote processor library");
Patrick Benavoli68a91282011-08-31 11:23:23 +02002208
2209 // Load library
Renaud de Chivre1b8b3ca2013-12-13 15:09:44 +01002210 _handleLibRemoteProcessor = dlopen("libremote-processor.so", RTLD_NOW);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002211
Renaud de Chivre1b8b3ca2013-12-13 15:09:44 +01002212 if (!_handleLibRemoteProcessor) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02002213
2214 // Return error
2215 const char* pcError = dlerror();
2216
2217 if (pcError) {
2218
2219 strError = pcError;
2220 } else {
2221
2222 strError = "Unable to load libremote-processor.so library";
2223 }
2224
2225 return false;
2226 }
2227
Renaud de Chivre1b8b3ca2013-12-13 15:09:44 +01002228 CreateRemoteProcessorServer pfnCreateRemoteProcessorServer = (CreateRemoteProcessorServer)dlsym(_handleLibRemoteProcessor, "createRemoteProcessorServer");
Patrick Benavoli68a91282011-08-31 11:23:23 +02002229
2230 if (!pfnCreateRemoteProcessorServer) {
2231
2232 strError = "libremote-process.so does not contain createRemoteProcessorServer symbol.";
2233
2234 return false;
2235 }
2236
2237 // Create server
Patrick Benavoli95ac0342011-11-07 20:32:51 +01002238 _pRemoteProcessorServer = pfnCreateRemoteProcessorServer(getConstFrameworkConfiguration()->getServerPort(), _pCommandHandler);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002239
Kevin Rocardace81f82012-12-11 16:19:17 +01002240 log_info("Starting remote processor server on port %d", getConstFrameworkConfiguration()->getServerPort());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002241 // Start
2242 if (!_pRemoteProcessorServer->start()) {
2243
Frédéric Boisnard6c55e9a2014-01-10 18:46:33 +01002244 ostringstream oss;
2245 oss << "ParameterMgr: Unable to start remote processor server on port "
2246 << getConstFrameworkConfiguration()->getServerPort();
2247 strError = oss.str();
Patrick Benavoli68a91282011-08-31 11:23:23 +02002248
2249 return false;
2250 }
2251 }
2252
2253 return true;
2254}
2255
2256// Back synchronization
Kevin Rocardace81f82012-12-11 16:19:17 +01002257CBackSynchronizer* CParameterMgr::createBackSynchronizer() const
Patrick Benavoli68a91282011-08-31 11:23:23 +02002258{
2259#ifdef SIMULATION
2260 // In simulation, back synchronization of the blackboard won't probably work
2261 // We need to ensure though the blackboard is initialized with valid data
Kevin Rocardace81f82012-12-11 16:19:17 +01002262 return new CSimulatedBackSynchronizer(getConstSystemClass(), _pMainParameterBlackboard);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002263#else
2264 // Real back synchronizer from subsystems
Kevin Rocardace81f82012-12-11 16:19:17 +01002265 return new CHardwareBackSynchronizer(getConstSystemClass(), _pMainParameterBlackboard);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002266#endif
2267}
2268
2269// Children typwise access
2270CParameterFrameworkConfiguration* CParameterMgr::getFrameworkConfiguration()
2271{
2272 return static_cast<CParameterFrameworkConfiguration*>(getChild(EFrameworkConfiguration));
2273}
2274
2275const CParameterFrameworkConfiguration* CParameterMgr::getConstFrameworkConfiguration()
2276{
2277 return getFrameworkConfiguration();
2278}
2279
2280CSelectionCriteria* CParameterMgr::getSelectionCriteria()
2281{
2282 return static_cast<CSelectionCriteria*>(getChild(ESelectionCriteria));
2283}
2284
2285const CSelectionCriteria* CParameterMgr::getConstSelectionCriteria()
2286{
2287 return static_cast<const CSelectionCriteria*>(getChild(ESelectionCriteria));
2288}
2289
2290CSystemClass* CParameterMgr::getSystemClass()
2291{
2292 return static_cast<CSystemClass*>(getChild(ESystemClass));
2293}
2294
2295const CSystemClass* CParameterMgr::getConstSystemClass() const
2296{
2297 return static_cast<const CSystemClass*>(getChild(ESystemClass));
2298}
2299
2300// Configurable Domains
2301CConfigurableDomains* CParameterMgr::getConfigurableDomains()
2302{
2303 return static_cast<CConfigurableDomains*>(getChild(EConfigurableDomains));
2304}
2305
2306const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains()
2307{
2308 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
2309}
2310
2311const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains() const
2312{
2313 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
2314}
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002315
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01002316// Apply configurations
2317void CParameterMgr::doApplyConfigurations(bool bForce)
2318{
2319 CSyncerSet syncerSet;
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002320
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01002321 // Check subsystems that need resync
2322 getSystemClass()->checkForSubsystemsToResync(syncerSet);
2323
2324 // Ensure application of currently selected configurations
2325 getConfigurableDomains()->apply(_pMainParameterBlackboard, syncerSet, bForce);
2326
2327 // Reset the modified status of the current criteria to indicate that a new configuration has been applied
2328 getSelectionCriteria()->resetModifiedStatus();
2329}
2330
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002331bool CParameterMgr::getSystemClassXMLString(string& strResult)
2332{
2333 // Root element
2334 const CSystemClass* pSystemClass = getSystemClass();
2335
2336 string strError;
2337
2338 CXmlSerializingContext xmlSerializingContext(strError);
2339
2340 // Use a doc source by loading data from instantiated Configurable Domains
2341 CXmlMemoryDocSource memorySource(pSystemClass, pSystemClass->getKind());
2342
2343 // Use a doc sink that write the doc data in a string
2344 CXmlStringDocSink stringSink(strResult);
2345
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002346 bool bProcessSuccess = stringSink.process(memorySource, xmlSerializingContext);
2347
2348 if (!bProcessSuccess) {
2349
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002350 strResult = strError;
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002351
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002352 }
2353
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002354 return bProcessSuccess;
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002355}