blob: 0101dfb1680d499620c87b6e3252dd115b075541 [file] [log] [blame]
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +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"
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +020039#include "XmlFileIncluderElement.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020040#include "SelectionCriterionType.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020041#include "SubsystemElementBuilder.h"
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +020042#include "FileIncluderElementBuilder.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020043#include "SelectionCriteria.h"
44#include "ComponentType.h"
45#include "ComponentInstance.h"
46#include "ParameterBlockType.h"
47#include "BooleanParameterType.h"
48#include "IntegerParameterType.h"
49#include "FixedPointParameterType.h"
50#include "ParameterBlackboard.h"
51#include "Parameter.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020052#include "ParameterAccessContext.h"
53#include "XmlFileIncluderElement.h"
54#include "ParameterFrameworkConfiguration.h"
55#include "FrameworkConfigurationGroup.h"
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +010056#include "PluginLocation.h"
57#include "SubsystemPlugins.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020058#include "FrameworkConfigurationLocation.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020059#include "ConfigurableDomains.h"
60#include "ConfigurableDomain.h"
61#include "DomainConfiguration.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020062#include "XmlDomainSerializingContext.h"
63#include "BitParameterBlockType.h"
64#include "BitParameterType.h"
Patrick Benavoli1352ae52011-10-21 16:48:04 +020065#include "StringParameterType.h"
Patrick Benavoli9fc3c0d2011-10-27 14:27:27 +020066#include "EnumParameterType.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020067#include "RemoteProcessorServerInterface.h"
68#include "ElementLocator.h"
69#include "AutoLog.h"
70#include "CompoundRule.h"
71#include "SelectionCriterionRule.h"
72#include "SimulatedBackSynchronizer.h"
73#include "HardwareBackSynchronizer.h"
Patrick Benavoli1387bda2011-08-31 11:23:24 +020074#include "AutoLock.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020075#include <strings.h>
76#include <dlfcn.h>
77#include <assert.h>
Patrick Benavoli065264a2011-11-20 15:46:41 +010078#include "ParameterHandle.h"
Patrick Benavoliee65e6d2011-11-20 18:52:24 +010079#include "LinearParameterAdaptation.h"
Patrick Benavoli68808c62012-02-02 17:12:41 +010080#include "EnumValuePair.h"
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +020081#include "Subsystem.h"
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020082#include "XmlFileDocSink.h"
83#include "XmlFileDocSource.h"
84#include "XmlStringDocSink.h"
Georges-Henri Baroncec86c12012-09-04 17:30:28 +020085#include "XmlStringDocSource.h"
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020086#include "XmlMemoryDocSink.h"
87#include "XmlMemoryDocSource.h"
Kevin Rocardace81f82012-12-11 16:19:17 +010088#include "Utility.h"
Frédéric Boisnard6c55e9a2014-01-10 18:46:33 +010089#include <sstream>
Patrick Benavoli68a91282011-08-31 11:23:23 +020090
91#define base CElement
92
Sebastien Gonzalved9526492014-02-20 22:28:03 +010093using std::string;
94using std::list;
95using std::vector;
96using std::ostringstream;
97
Patrick Benavoli68a91282011-08-31 11:23:23 +020098// Used for remote processor server creation
99typedef IRemoteProcessorServerInterface* (*CreateRemoteProcessorServer)(uint16_t uiPort, IRemoteCommandHandler* pCommandHandler);
100
101// Global configuration file name (fixed)
102const char* gacParameterFrameworkConfigurationFileName = "ParameterFrameworkConfiguration.xml";
103const char* gacSystemSchemasSubFolder = "Schemas";
104
105// Config File System looks normally like this:
106// ---------------------------------------------
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100107//├── <ParameterFrameworkConfiguration>.xml
Patrick Benavoli68a91282011-08-31 11:23:23 +0200108//├── Schemas
109//│ └── *.xsd
110//├── Settings
111//│ └── <SystemClassName folder>*
112//│ ├── <ConfigurableDomains>.xml
113//│ └── <Settings>.bin?
114//└── Structure
115// └── <SystemClassName folder>*
116// ├── <SystemClassName>Class.xml
117// └── <Subsystem>.xml*
118// --------------------------------------------
119
120
121// Remote command parser array
Patrick Benavoli592ae562011-09-05 16:53:58 +0200122const CParameterMgr::SRemoteCommandParserItem CParameterMgr::gastRemoteCommandParserItems[] = {
Kevin Rocard3949b342013-05-24 18:43:53 +0200123
Patrick Benavoli592ae562011-09-05 16:53:58 +0200124 /// Version
Kevin Rocard3949b342013-05-24 18:43:53 +0200125 { "version", &CParameterMgr::versionCommandProcess, 0,
126 "", "Show version" },
127
Patrick Benavoli68a91282011-08-31 11:23:23 +0200128 /// Status
Kevin Rocard3949b342013-05-24 18:43:53 +0200129 { "status", &CParameterMgr::statusCommandProcess, 0, "",
130 "Show current status" },
131
Patrick Benavoli68a91282011-08-31 11:23:23 +0200132 /// Tuning Mode
Kevin Rocard3949b342013-05-24 18:43:53 +0200133 { "setTuningMode", &CParameterMgr::setTuningModeCommmandProcess, 1,
134 "on|off*", "Turn on or off Tuning Mode" },
135 { "getTuningMode", &CParameterMgr::getTuningModeCommmandProcess, 0,
136 "", "Show Tuning Mode" },
137
Patrick Benavoli68a91282011-08-31 11:23:23 +0200138 /// Value Space
Kevin Rocard3949b342013-05-24 18:43:53 +0200139 { "setValueSpace", &CParameterMgr::setValueSpaceCommmandProcess, 1,
140 "raw|real*", "Assigns Value Space used for parameter value interpretation" },
141 { "getValueSpace", &CParameterMgr::getValueSpaceCommmandProcess, 0,
142 "", "Show Value Space" },
143
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200144 /// Output Raw Format
Kevin Rocard3949b342013-05-24 18:43:53 +0200145 { "setOutputRawFormat", &CParameterMgr::setOutputRawFormatCommmandProcess, 1,
146 "dec*|hex", "Assigns format used to output parameter values when in raw Value Space" },
147 { "getOutputRawFormat", &CParameterMgr::getOutputRawFormatCommmandProcess, 0,
148 "", "Show Output Raw Format" },
149
Patrick Benavoli68a91282011-08-31 11:23:23 +0200150 /// Sync
Kevin Rocard3949b342013-05-24 18:43:53 +0200151 { "setAutoSync", &CParameterMgr::setAutoSyncCommmandProcess, 1,
152 "on*|off", "Turn on or off automatic synchronization to hardware while in Tuning Mode" },
153 { "getAutoSync", &CParameterMgr::getAutoSyncCommmandProcess, 0,
154 "", "Show Auto Sync state" },
155 { "sync", &CParameterMgr::syncCommmandProcess, 0,
156 "", "Synchronize current settings to hardware while in Tuning Mode and Auto Sync off" },
157
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200158 /// Criteria
Kevin Rocard3949b342013-05-24 18:43:53 +0200159 { "listCriteria", &CParameterMgr::listCriteriaCommmandProcess, 0,
160 "[csv]", "List selection criteria" },
161
Patrick Benavoli68a91282011-08-31 11:23:23 +0200162 /// Domains
Kevin Rocard3949b342013-05-24 18:43:53 +0200163 { "listDomains", &CParameterMgr::listDomainsCommmandProcess, 0,
164 "", "List configurable domains" },
165 { "dumpDomains", &CParameterMgr::dumpDomainsCommmandProcess, 0,
166 "", "Show all domains and configurations, including applicability conditions" },
167 { "createDomain", &CParameterMgr::createDomainCommmandProcess, 1,
168 "<domain>", "Create new configurable domain" },
169 { "deleteDomain", &CParameterMgr::deleteDomainCommmandProcess, 1,
170 "<domain>", "Delete configurable domain" },
171 { "deleteAllDomains", &CParameterMgr::deleteAllDomainsCommmandProcess, 0,
172 "", "Delete all configurable domains" },
173 { "renameDomain", &CParameterMgr::renameDomainCommmandProcess, 2,
174 "<domain> <new name>", "Rename configurable domain" },
175 { "setSequenceAwareness", &CParameterMgr::setSequenceAwarenessCommmandProcess, 1,
176 "<domain> true|false*", "Set configurable domain sequence awareness" },
177 { "getSequenceAwareness", &CParameterMgr::getSequenceAwarenessCommmandProcess, 1,
178 "<domain>", "Get configurable domain sequence awareness" },
179 { "listDomainElements", &CParameterMgr::listDomainElementsCommmandProcess, 1,
180 "<domain>", "List elements associated to configurable domain" },
181 { "addElement", &CParameterMgr::addElementCommmandProcess, 2,
182 "<domain> <elem path>", "Associate element at given path to configurable domain" },
183 { "removeElement", &CParameterMgr::removeElementCommmandProcess, 2,
184 "<domain> <elem path>", "Dissociate element at given path from configurable domain" },
185 { "splitDomain", &CParameterMgr::splitDomainCommmandProcess, 2,
186 "<domain> <elem path>", "Split configurable domain at given associated element path" },
187
Patrick Benavoli68a91282011-08-31 11:23:23 +0200188 /// Configurations
Kevin Rocard3949b342013-05-24 18:43:53 +0200189 { "listConfigurations", &CParameterMgr::listConfigurationsCommmandProcess, 1,
190 "<domain>", "List domain configurations" },
191 { "createConfiguration", &CParameterMgr::createConfigurationCommmandProcess, 2,
192 "<domain> <configuration>", "Create new domain configuration" },
193 { "deleteConfiguration", &CParameterMgr::deleteConfigurationCommmandProcess, 2,
194 "<domain> <configuration>", "Delete domain configuration" },
195 { "renameConfiguration", &CParameterMgr::renameConfigurationCommmandProcess, 3,
196 "<domain> <configuration> <new name>", "Rename domain configuration" },
197 { "saveConfiguration", &CParameterMgr::saveConfigurationCommmandProcess, 2,
198 "<domain> <configuration>", "Save current settings into configuration" },
199 { "restoreConfiguration", &CParameterMgr::restoreConfigurationCommmandProcess, 2,
200 "<domain> <configuration>", "Restore current settings from configuration" },
201 { "setElementSequence", &CParameterMgr::setElementSequenceCommmandProcess, 3,
202 "<domain> <configuration> <elem path list>",
203 "Set element application order for configuration" },
204 { "getElementSequence", &CParameterMgr::getElementSequenceCommmandProcess, 2,
205 "<domain> <configuration>", "Get element application order for configuration" },
206 { "setRule", &CParameterMgr::setRuleCommmandProcess, 3,
207 "<domain> <configuration> <rule>", "Set configuration application rule" },
208 { "clearRule", &CParameterMgr::clearRuleCommmandProcess, 2,
209 "<domain> <configuration>", "Clear configuration application rule" },
210 { "getRule", &CParameterMgr::getRuleCommmandProcess, 2,
211 "<domain> <configuration>", "Get configuration application rule" },
212
Patrick Benavoli68a91282011-08-31 11:23:23 +0200213 /// Elements/Parameters
Kevin Rocard3949b342013-05-24 18:43:53 +0200214 { "listElements", &CParameterMgr::listElementsCommmandProcess, 1,
215 "<elem path>|/", "List elements under element at given path or root" },
216 { "listParameters", &CParameterMgr::listParametersCommmandProcess, 1,
217 "<elem path>|/", "List parameters under element at given path or root" },
218 { "dumpElement", &CParameterMgr::dumpElementCommmandProcess, 1,
219 "<elem path>", "Dump structure and content of element at given path" },
220 { "getElementSize", &CParameterMgr::getElementSizeCommmandProcess, 1,
221 "<elem path>", "Show size of element at given path" },
222 { "showProperties", &CParameterMgr::showPropertiesCommmandProcess, 1,
223 "<elem path>", "Show properties of element at given path" },
224 { "getParameter", &CParameterMgr::getParameterCommmandProcess, 1,
225 "<param path>", "Get value for parameter at given path" },
226 { "setParameter", &CParameterMgr::setParameterCommmandProcess, 2,
227 "<param path> <value>", "Set value for parameter at given path" },
228 { "listBelongingDomains", &CParameterMgr::listBelongingDomainsCommmandProcess, 1,
229 "<elem path>", "List domain(s) element at given path belongs to" },
230 { "listAssociatedDomains", &CParameterMgr::listAssociatedDomainsCommmandProcess, 1,
231 "<elem path>", "List domain(s) element at given path is associated to" },
232 { "getConfigurationParameter", &CParameterMgr::getConfigurationParameterCommmandProcess, 3,
233 "<domain> <configuration> <param path>",
234 "Get value for parameter at given path from configuration" },
235 { "setConfigurationParameter", &CParameterMgr::setConfigurationParameterCommmandProcess, 4,
236 "<domain> <configuration> <param path> <value>",
237 "Set value for parameter at given path to configuration" },
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200238 { "showMapping", &CParameterMgr::showMappingCommmandProcess, 1,
239 "<elem path>", "Show mapping for an element at given path" },
Kevin Rocard3949b342013-05-24 18:43:53 +0200240
Patrick Benavoli68a91282011-08-31 11:23:23 +0200241 /// Browse
Kevin Rocard3949b342013-05-24 18:43:53 +0200242 { "listAssociatedElements", &CParameterMgr::listAssociatedElementsCommmandProcess, 0,
243 "", "List element sub-trees associated to at least one configurable domain" },
244 { "listConflictingElements", &CParameterMgr::listConflictingElementsCommmandProcess, 0,
245 "", "List element sub-trees contained in more than one configurable domain" },
246 { "listRogueElements", &CParameterMgr::listRogueElementsCommmandProcess, 0,
247 "", "List element sub-trees owned by no configurable domain" },
248
Patrick Benavoli68a91282011-08-31 11:23:23 +0200249 /// Settings Import/Export
Kevin Rocard3949b342013-05-24 18:43:53 +0200250 { "exportDomainsXML", &CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess, 1,
251 "<file path> ", "Export domains to XML file" },
252 { "importDomainsXML", &CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess, 1,
253 "<file path>", "Import domains from XML file" },
254 { "exportDomainsWithSettingsXML",
255 &CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess, 1,
256 "<file path> ", "Export domains including settings to XML file" },
257 { "importDomainsWithSettingsXML",
258 &CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess, 1,
259 "<file path>", "Import domains including settings from XML file" },
260 { "exportSettings", &CParameterMgr::exportSettingsCommmandProcess, 1,
261 "<file path>", "Export settings to binary file" },
262 { "importSettings", &CParameterMgr::importSettingsCommmandProcess, 1,
263 "<file path>", "Import settings from binary file" },
Georges-Henri Baroncec86c12012-09-04 17:30:28 +0200264 { "getDomainsWithSettingsXML",
265 &CParameterMgr::getConfigurableDomainsWithSettingsXMLCommmandProcess, 0,
Kevin Rocard3949b342013-05-24 18:43:53 +0200266 "", "Print domains including settings as XML" },
Georges-Henri Baroncec86c12012-09-04 17:30:28 +0200267 { "setDomainsWithSettingsXML",
268 &CParameterMgr::setConfigurableDomainsWithSettingsXMLCommmandProcess, 1,
269 "<xml configurable domains>", "Import domains including settings from XML string" },
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200270 /// Structure Export
Kevin Rocard3949b342013-05-24 18:43:53 +0200271 { "getSystemClassXML", &CParameterMgr::getSystemClassXMLCommmandProcess, 0 ,
Kevin Rocardc0211572013-06-18 11:34:53 +0200272 "", "Print parameter structure as XML" },
273 /// Deprecated Commands
274 { "getDomainsXML",
275 &CParameterMgr::getConfigurableDomainsWithSettingsXMLCommmandProcess, 0,
276 "", "DEPRECATED COMMAND, please use getDomainsWithSettingsXML" },
Georges-Henri Baroncec86c12012-09-04 17:30:28 +0200277
Patrick Benavoli68a91282011-08-31 11:23:23 +0200278};
Kevin Rocard3949b342013-05-24 18:43:53 +0200279
Patrick Benavoli68a91282011-08-31 11:23:23 +0200280// Remote command parsers array Size
Patrick Benavoli592ae562011-09-05 16:53:58 +0200281const uint32_t CParameterMgr::guiNbRemoteCommandParserItems = sizeof(gastRemoteCommandParserItems) / sizeof(gastRemoteCommandParserItems[0]);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200282
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100283CParameterMgr::CParameterMgr(const string& strConfigurationFilePath) :
Patrick Benavoli68a91282011-08-31 11:23:23 +0200284 _bTuningModeIsOn(false),
285 _bValueSpaceIsRaw(false),
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200286 _bOutputRawFormatIsHex(false),
Patrick Benavoli68a91282011-08-31 11:23:23 +0200287 _bAutoSyncOn(true),
288 _pMainParameterBlackboard(new CParameterBlackboard),
289 _pElementLibrarySet(new CElementLibrarySet),
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100290 _strXmlConfigurationFilePath(strConfigurationFilePath),
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100291 _pSubsystemPlugins(NULL),
Renaud de Chivre1b8b3ca2013-12-13 15:09:44 +0100292 _handleLibRemoteProcessor(NULL),
Patrick Benavoli68a91282011-08-31 11:23:23 +0200293 _uiStructureChecksum(0),
294 _pRemoteProcessorServer(NULL),
295 _uiMaxCommandUsageLength(0),
296 _pLogger(NULL),
Kevin Rocardecf93102013-07-10 18:28:10 +0200297 _uiLogDepth(0),
Kevin Rocardd6909eb2013-07-18 09:13:51 +0200298 _bFailOnMissingSubsystem(true),
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +0200299 _bFailOnFailedSettingsLoad(true),
300 _bValidateSchemasOnStart(false)
301
Patrick Benavoli68a91282011-08-31 11:23:23 +0200302{
303 // Tuning Mode Mutex
Patrick Benavoli065264a2011-11-20 15:46:41 +0100304 bzero(&_blackboardMutex, sizeof(_blackboardMutex));
305 pthread_mutex_init(&_blackboardMutex, NULL);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200306
307 // Deal with children
308 addChild(new CParameterFrameworkConfiguration);
309 addChild(new CSelectionCriteria);
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100310 addChild(new CSystemClass);
311 addChild(new CConfigurableDomains);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200312
Patrick Benavoli63499d42011-10-24 18:50:03 +0200313 _pCommandHandler = new CCommandHandler(this);
314
315 // Add command parsers
316 uint32_t uiRemoteCommandParserItem;
317
318 for (uiRemoteCommandParserItem = 0; uiRemoteCommandParserItem < guiNbRemoteCommandParserItems; uiRemoteCommandParserItem++) {
319
320 const SRemoteCommandParserItem* pRemoteCommandParserItem = &gastRemoteCommandParserItems[uiRemoteCommandParserItem];
321
322 _pCommandHandler->addCommandParser(pRemoteCommandParserItem->_pcCommandName,
323 pRemoteCommandParserItem->_pfnParser,
324 pRemoteCommandParserItem->_uiMinArgumentCount,
325 pRemoteCommandParserItem->_pcHelp,
326 pRemoteCommandParserItem->_pcDescription);
327 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100328
329 // Configuration file folder
330 uint32_t uiSlashPos = _strXmlConfigurationFilePath.rfind('/', -1);
331
332 assert(uiSlashPos != (uint32_t)-1);
333
334 _strXmlConfigurationFolderPath = _strXmlConfigurationFilePath.substr(0, uiSlashPos);
335
336 // Schema absolute folder location
337 _strSchemaFolderLocation = _strXmlConfigurationFolderPath + "/" + gacSystemSchemasSubFolder;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200338}
339
340CParameterMgr::~CParameterMgr()
341{
342 // Children
343 delete _pRemoteProcessorServer;
Frederic Boisnard31242302012-04-26 17:07:34 +0200344 delete _pCommandHandler;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200345 delete _pMainParameterBlackboard;
346 delete _pElementLibrarySet;
347
Renaud de Chivre1b8b3ca2013-12-13 15:09:44 +0100348 // Close remote processor library
349 if (_handleLibRemoteProcessor != NULL) {
350 dlclose(_handleLibRemoteProcessor);
351 }
352
Patrick Benavoli68a91282011-08-31 11:23:23 +0200353 // Tuning Mode Mutex
Patrick Benavoli065264a2011-11-20 15:46:41 +0100354 pthread_mutex_destroy(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200355}
356
357string CParameterMgr::getKind() const
358{
359 return "ParameterMgr";
360}
361
362// Logging
363void CParameterMgr::setLogger(CParameterMgr::ILogger* pLogger)
364{
365 _pLogger = pLogger;
366}
367
368// Logging
Kevin Rocardace81f82012-12-11 16:19:17 +0100369void CParameterMgr::doLog(bool bIsWarning, const string& strLog) const
Patrick Benavoli68a91282011-08-31 11:23:23 +0200370{
371 if (_pLogger) {
372
373 // Nest
374 string strIndent;
375
376 // Level
377 uint32_t uiNbIndents = _uiLogDepth;
378
379 while (uiNbIndents--) {
380
381 strIndent += " ";
382 }
383
384 // Log
Kevin Rocardace81f82012-12-11 16:19:17 +0100385 _pLogger->log(bIsWarning, strIndent + strLog);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200386 }
387}
388
389void CParameterMgr::nestLog() const
390{
Patrick Benavoli592ae562011-09-05 16:53:58 +0200391 _uiLogDepth++;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200392}
393
394void CParameterMgr::unnestLog() const
395{
Patrick Benavoli592ae562011-09-05 16:53:58 +0200396 _uiLogDepth--;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200397}
398
Patrick Benavoli63499d42011-10-24 18:50:03 +0200399// Version
400string CParameterMgr::getVersion() const
401{
402 string strVersion;
403
404 // Major
405 strVersion = toString(guiEditionMajor) + ".";
406 // Minor
407 strVersion += toString(guiEditionMinor) + ".";
408 // Revision
409 strVersion += toString(guiRevision);
410
411 return strVersion;
412}
413
Patrick Benavoli68a91282011-08-31 11:23:23 +0200414bool CParameterMgr::load(string& strError)
415{
416 CAutoLog autoLog(this, "Loading");
417
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +0200418 feedElementLibraries();
419
Patrick Benavoli68a91282011-08-31 11:23:23 +0200420 // Load Framework configuration
421 if (!loadFrameworkConfiguration(strError)) {
422
423 return false;
424 }
425
426 // Load subsystems
Kevin Rocardecf93102013-07-10 18:28:10 +0200427 if (!getSystemClass()->loadSubsystems(strError,
428 _pSubsystemPlugins, !_bFailOnMissingSubsystem)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200429
430 return false;
431 }
432
433 // Load structure
434 if (!loadStructure(strError)) {
435
436 return false;
437 }
438
439 // Load settings
440 if (!loadSettings(strError)) {
441
442 return false;
443 }
444
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200445 // Back synchronization for areas in parameter blackboard not covered by any domain
Kevin Rocardace81f82012-12-11 16:19:17 +0100446 CBackSynchronizer* pBackSynchronizer = createBackSynchronizer();
Patrick Benavoli68a91282011-08-31 11:23:23 +0200447
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200448 // Back-synchronize
Kevin Rocard57096bd2012-11-30 11:24:20 +0100449 {
450 CAutoLog autoLog(this, "Main blackboard back synchronization");
451
Kevin Rocard5d6e05a2013-01-21 15:57:45 +0100452 pBackSynchronizer->sync();
Kevin Rocard57096bd2012-11-30 11:24:20 +0100453
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200454 // Get rid of back synchronizer
455 delete pBackSynchronizer;
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200456 }
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200457
458 // We're done loading the settings and back synchronizing
459 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
460
461 // We need to ensure all domains are valid
462 pConfigurableDomains->validate(_pMainParameterBlackboard);
463
Kevin Rocard7f265822012-12-07 18:51:22 +0100464 // Log selection criterion states
465 {
466 CAutoLog autoLog(this, "Criterion states");
467
468 const CSelectionCriteria* selectionCriteria = getConstSelectionCriteria();
469
470 list<string> lstrSelectionCriteron;
471 selectionCriteria->listSelectionCriteria(lstrSelectionCriteron, true, false);
472
Kevin Rocard36299362013-02-04 14:57:47 +0100473 log_table(false, lstrSelectionCriteron);
Kevin Rocard7f265822012-12-07 18:51:22 +0100474 }
475
Kevin Rocard2fbe6e82013-03-26 17:09:29 +0100476 // Subsystem can not ask for resync as they have not been synced yet
477 getSystemClass()->cleanSubsystemsNeedToResync();
478
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100479 // At initialization, check subsystems that need resync
480 doApplyConfigurations(true);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200481
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200482 // Start remote processor server if appropriate
483 return handleRemoteProcessingInterface(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200484}
485
486bool CParameterMgr::loadFrameworkConfiguration(string& strError)
487{
488 CAutoLog autoLog(this, "Loading framework configuration");
489
Patrick Benavoli68a91282011-08-31 11:23:23 +0200490 // Parse Structure XML file
491 CXmlElementSerializingContext elementSerializingContext(strError);
492
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100493 if (!xmlParse(elementSerializingContext, getFrameworkConfiguration(), _strXmlConfigurationFilePath, _strXmlConfigurationFolderPath, EFrameworkConfigurationLibrary)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200494
495 return false;
496 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100497 // Set class name to system class and configurable domains
498 getSystemClass()->setName(getConstFrameworkConfiguration()->getSystemClassName());
499 getConfigurableDomains()->setName(getConstFrameworkConfiguration()->getSystemClassName());
500
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100501 // Get subsystem plugins elements
502 _pSubsystemPlugins = static_cast<const CSubsystemPlugins*>(getConstFrameworkConfiguration()->findChild("SubsystemPlugins"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200503
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100504 if (!_pSubsystemPlugins) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200505
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100506 strError = "Parameter Framework Configuration: couldn't find SubsystemPlugins element";
Patrick Benavoli68a91282011-08-31 11:23:23 +0200507
508 return false;
509 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200510
Patrick Benavoli68a91282011-08-31 11:23:23 +0200511 // Log tuning availability
Kevin Rocardace81f82012-12-11 16:19:17 +0100512 log_info("Tuning %s", getConstFrameworkConfiguration()->isTuningAllowed() ? "allowed" : "prohibited");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200513
514 return true;
515}
516
517bool CParameterMgr::loadStructure(string& strError)
518{
519 // Retrieve system to load structure to
520 CSystemClass* pSystemClass = getSystemClass();
521
Kevin Rocarde25ee792013-04-22 17:46:28 +0200522 log_info("Loading " + pSystemClass->getName() + " system class structure");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200523
524 // Get structure description element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100525 const CFrameworkConfigurationLocation* pStructureDescriptionFileLocation = static_cast<const CFrameworkConfigurationLocation*>(getConstFrameworkConfiguration()->findChildOfKind("StructureDescriptionFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200526
527 if (!pStructureDescriptionFileLocation) {
528
529 strError = "No StructureDescriptionFileLocation element found for SystemClass " + pSystemClass->getName();
530
531 return false;
532 }
533
534 // Get Xml structure folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100535 string strXmlStructureFolder = pStructureDescriptionFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200536
537 // Get Xml structure file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100538 string strXmlStructureFilePath = pStructureDescriptionFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200539
540 // Parse Structure XML file
541 CXmlParameterSerializingContext parameterBuildContext(strError);
542
Kevin Rocard57096bd2012-11-30 11:24:20 +0100543 CAutoLog autolog(pSystemClass, "Importing system structure from file " + strXmlStructureFilePath);
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200544
Patrick Benavoli68a91282011-08-31 11:23:23 +0200545 if (!xmlParse(parameterBuildContext, pSystemClass, strXmlStructureFilePath, strXmlStructureFolder, EParameterCreationLibrary)) {
546
547 return false;
548 }
549
550 // Initialize offsets
551 pSystemClass->setOffset(0);
552
553 // Initialize main blackboard's size
554 _pMainParameterBlackboard->setSize(pSystemClass->getFootPrint());
555
556 return true;
557}
558
559bool CParameterMgr::loadSettings(string& strError)
560{
Kevin Rocardd6909eb2013-07-18 09:13:51 +0200561 string strLoadError;
562 bool success = loadSettingsFromConfigFile(strLoadError);
563
564 if (!success && !_bFailOnFailedSettingsLoad) {
565 // Load can not fail, ie continue but log the load errors
566 log_info(strLoadError);
567 log_info("Failed to load settings, continue without domains.");
568 success = true;
569 }
570
571 if (!success) {
572 // Propagate the litteral error only if the function fails
573 strError = strLoadError;
574 return false;
575 }
576
577 return true;
578}
579
580bool CParameterMgr::loadSettingsFromConfigFile(string& strError)
581{
Patrick Benavoli68a91282011-08-31 11:23:23 +0200582 CAutoLog autoLog(this, "Loading settings");
583
584 // Get settings configuration element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100585 const CFrameworkConfigurationGroup* pParameterConfigurationGroup = static_cast<const CFrameworkConfigurationGroup*>(getConstFrameworkConfiguration()->findChildOfKind("SettingsConfiguration"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200586
587 if (!pParameterConfigurationGroup) {
588
589 // No settings to load
590
591 return true;
592 }
593 // Get binary settings file location
594 const CFrameworkConfigurationLocation* pBinarySettingsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("BinarySettingsFileLocation"));
595
596 string strXmlBinarySettingsFilePath;
597
598 if (pBinarySettingsFileLocation) {
599
600 // Get Xml binary settings file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100601 strXmlBinarySettingsFilePath = pBinarySettingsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200602 }
603
604 // Get configurable domains element
605 const CFrameworkConfigurationLocation* pConfigurableDomainsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("ConfigurableDomainsFileLocation"));
606
607 if (!pConfigurableDomainsFileLocation) {
608
609 strError = "No ConfigurableDomainsFileLocation element found for SystemClass " + getSystemClass()->getName();
610
611 return false;
Kevin Rocardd6909eb2013-07-18 09:13:51 +0200612 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200613 // Get destination root element
614 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
615
616 // Get Xml configuration domains file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100617 string strXmlConfigurationDomainsFilePath = pConfigurableDomainsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200618
619 // Get Xml configuration domains folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100620 string strXmlConfigurationDomainsFolder = pConfigurableDomainsFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200621
622 // Parse configuration domains XML file (ask to read settings from XML file if they are not provided as binary)
623 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, !pBinarySettingsFileLocation);
624
625 // Selection criteria definition for rule creation
626 xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
627
Patrick Benavoli63499d42011-10-24 18:50:03 +0200628 // Auto validation of configurations if no binary settings provided
629 xmlDomainSerializingContext.setAutoValidationRequired(!pBinarySettingsFileLocation);
630
Kevin Rocardace81f82012-12-11 16:19:17 +0100631 log_info("Importing configurable domains from file %s %s settings", strXmlConfigurationDomainsFilePath.c_str(), pBinarySettingsFileLocation ? "without" : "with");
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200632
Patrick Benavoli68a91282011-08-31 11:23:23 +0200633 // Do parse
634 if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strXmlConfigurationDomainsFilePath, strXmlConfigurationDomainsFolder, EParameterConfigurationLibrary, "SystemClassName")) {
635
636 return false;
637 }
638 // We have loaded the whole system structure, compute checksum
639 const CSystemClass* pSystemClass = getConstSystemClass();
640 _uiStructureChecksum = pSystemClass->computeStructureChecksum() + getConfigurableDomains()->computeStructureChecksum() + getSelectionCriteria()->computeStructureChecksum();
641
642 // Load binary settings if any provided
643 if (pBinarySettingsFileLocation && !pConfigurableDomains->serializeSettings(strXmlBinarySettingsFilePath, false, _uiStructureChecksum, strError)) {
644
645 return false;
646 }
647
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200648 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200649}
650
651// XML parsing
652bool CParameterMgr::xmlParse(CXmlElementSerializingContext& elementSerializingContext, CElement* pRootElement, const string& strXmlFilePath, const string& strXmlFolder, CParameterMgr::ElementLibrary eElementLibrary, const string& strNameAttrituteName)
653{
654 // Init serializing context
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +0200655 elementSerializingContext.set(_pElementLibrarySet->getElementLibrary(
656 eElementLibrary), strXmlFolder, _strSchemaFolderLocation);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200657
658 // Get Schema file associated to root element
659 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pRootElement->getKind() + ".xsd";
660
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +0200661 CXmlFileDocSource fileDocSource(strXmlFilePath, strXmlSchemaFilePath,
662 pRootElement->getKind(),
663 pRootElement->getName(), strNameAttrituteName,
664 _bValidateSchemasOnStart);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200665
666 // Start clean
667 pRootElement->clean();
668
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200669 CXmlMemoryDocSink memorySink(pRootElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200670
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200671 if (!memorySink.process(fileDocSource, elementSerializingContext)) {
672 //Cleanup
Patrick Benavoli68a91282011-08-31 11:23:23 +0200673 pRootElement->clean();
674
675 return false;
676 }
677
Patrick Benavoli68a91282011-08-31 11:23:23 +0200678 return true;
679}
680
681// Init
682bool CParameterMgr::init(string& strError)
683{
684 return base::init(strError);
685}
686
687// Selection criteria interface
688CSelectionCriterionType* CParameterMgr::createSelectionCriterionType(bool bIsInclusive)
689{
690 // Propagate
691 return getSelectionCriteria()->createSelectionCriterionType(bIsInclusive);
692}
693
694CSelectionCriterion* CParameterMgr::createSelectionCriterion(const string& strName, const CSelectionCriterionType* pSelectionCriterionType)
695{
696 // Propagate
697 return getSelectionCriteria()->createSelectionCriterion(strName, pSelectionCriterionType);
698}
699
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200700// Selection criterion retrieval
701CSelectionCriterion* CParameterMgr::getSelectionCriterion(const string& strName)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200702{
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200703 // Propagate
704 return getSelectionCriteria()->getSelectionCriterion(strName);
705}
706
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100707// Configuration application
Kevin Rocardace81f82012-12-11 16:19:17 +0100708void CParameterMgr::applyConfigurations()
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200709{
710 CAutoLog autoLog(this, "Configuration application request");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200711
712 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +0100713 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200714
715 if (!_bTuningModeIsOn) {
716
717 // Apply configuration(s)
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100718 doApplyConfigurations(false);
Frédéric Boisnarddaaa63c2012-08-27 15:48:15 +0200719 } else {
720
Kevin Rocardace81f82012-12-11 16:19:17 +0100721 log_warning("Configurations were not applied because the TuningMode is on");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200722 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200723}
724
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200725// Get the configurableElement corresponding to the given path
726const CConfigurableElement* CParameterMgr::getConfigurableElement(const string& strPath,
727 string& strError) const
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200728{
Patrick Benavoli065264a2011-11-20 15:46:41 +0100729 CPathNavigator pathNavigator(strPath);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200730
Patrick Benavoli065264a2011-11-20 15:46:41 +0100731 // Nagivate through system class
732 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
733
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100734 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100735 }
736
737 // Find element
738 const CElement* pElement = getConstSystemClass()->findDescendant(pathNavigator);
739
740 if (!pElement) {
741
Kevin Rocard4c3f8d82013-11-21 12:16:28 +0100742 strError = "Path not found: " + strPath;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100743
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100744 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100745 }
746
747 // Check found element is a parameter
748 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pElement);
749
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200750 return pConfigurableElement;
751}
752
753// Dynamic parameter handling
754CParameterHandle* CParameterMgr::createParameterHandle(const string& strPath, string& strError)
755{
756 const CConfigurableElement* pConfigurableElement = getConfigurableElement(strPath, strError);
757
758 if (!pConfigurableElement) {
759
760 // Element not found
Kevin Rocard4c3f8d82013-11-21 12:16:28 +0100761 strError = "Element not found: " + strPath;
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200762 return NULL;
763 }
764
Patrick Benavoli065264a2011-11-20 15:46:41 +0100765 if (!pConfigurableElement->isParameter()) {
766
767 // Element is not parameter
Kevin Rocard4c3f8d82013-11-21 12:16:28 +0100768 strError = "Not a parameter: " + strPath;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100769
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100770 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100771 }
772
773 // Convert as parameter and return new handle
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200774 return new CParameterHandle(static_cast<const CBaseParameter*>(pConfigurableElement), this);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200775}
776
Kevin Rocardecf93102013-07-10 18:28:10 +0200777void CParameterMgr::setFailureOnMissingSubsystem(bool bFail)
778{
779 _bFailOnMissingSubsystem = bFail;
780}
781
782bool CParameterMgr::getFailureOnMissingSubsystem() const
783{
784 return _bFailOnMissingSubsystem;
785}
Kevin Rocardd6909eb2013-07-18 09:13:51 +0200786
787void CParameterMgr::setFailureOnFailedSettingsLoad(bool bFail)
788{
789 _bFailOnFailedSettingsLoad = bFail;
790}
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +0200791
Kevin Rocardd6909eb2013-07-18 09:13:51 +0200792bool CParameterMgr::getFailureOnFailedSettingsLoad()
793{
794 return _bFailOnFailedSettingsLoad;
795}
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +0200796
797void CParameterMgr::setValidateSchemasOnStart(bool bValidate)
798{
799 _bValidateSchemasOnStart = bValidate;
800}
801
802bool CParameterMgr::getValidateSchemasOnStart() const
803{
804 return _bValidateSchemasOnStart;
805}
806
Patrick Benavoli68a91282011-08-31 11:23:23 +0200807/////////////////// Remote command parsers
Patrick Benavoli592ae562011-09-05 16:53:58 +0200808/// Version
Patrick Benavoli63499d42011-10-24 18:50:03 +0200809CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::versionCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli592ae562011-09-05 16:53:58 +0200810{
811 (void)remoteCommand;
812
Patrick Benavoli63499d42011-10-24 18:50:03 +0200813 // Show version
814 strResult = getVersion();
Patrick Benavoli592ae562011-09-05 16:53:58 +0200815
Patrick Benavoli63499d42011-10-24 18:50:03 +0200816 return CCommandHandler::ESucceeded;
Patrick Benavoli592ae562011-09-05 16:53:58 +0200817}
818
Patrick Benavoli68a91282011-08-31 11:23:23 +0200819/// Status
Patrick Benavoli63499d42011-10-24 18:50:03 +0200820CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::statusCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200821{
822 (void)remoteCommand;
823 // System class
824 const CSystemClass* pSystemClass = getSystemClass();
825
Patrick Benavoli68a91282011-08-31 11:23:23 +0200826 // Show status
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200827 /// General section
828 appendTitle(strResult, "General:");
829 // System class
Patrick Benavoli68a91282011-08-31 11:23:23 +0200830 strResult += "System Class: ";
831 strResult += pSystemClass->getName();
832 strResult += "\n";
833
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200834 // Tuning mode
Patrick Benavoli68a91282011-08-31 11:23:23 +0200835 strResult += "Tuning Mode: ";
836 strResult += tuningModeOn() ? "on" : "off";
837 strResult += "\n";
838
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200839 // Value space
Patrick Benavoli68a91282011-08-31 11:23:23 +0200840 strResult += "Value Space: ";
841 strResult += valueSpaceIsRaw() ? "raw" : "real";
842 strResult += "\n";
843
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200844 // Output raw format
845 strResult += "Output Raw Format: ";
846 strResult += outputRawFormatIsHex() ? "hex" : "dec";
847 strResult += "\n";
848
849 // Auto Sync
Patrick Benavoli68a91282011-08-31 11:23:23 +0200850 strResult += "Auto Sync: ";
851 strResult += autoSyncOn() ? "on" : "off";
852 strResult += "\n";
853
854 /// Subsystem list
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200855 appendTitle(strResult, "Subsystems:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200856 string strSubsystemList;
857 pSystemClass->listChildrenPaths(strSubsystemList);
858 strResult += strSubsystemList;
859
860 /// Last applied configurations
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200861 appendTitle(strResult, "Last Applied [Pending] Configurations:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200862 string strLastAppliedConfigurations;
863 getConfigurableDomains()->listLastAppliedConfigurations(strLastAppliedConfigurations);
864 strResult += strLastAppliedConfigurations;
865
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200866 /// Criteria states
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200867 appendTitle(strResult, "Selection Criteria:");
Kevin Rocard7f265822012-12-07 18:51:22 +0100868 list<string> lstrSelectionCriteria;
869 getSelectionCriteria()->listSelectionCriteria(lstrSelectionCriteria, false, true);
870 // Concatenate the criterion list as the command result
Frederic Boisnard390b36d2013-05-23 15:28:31 +0200871 string strCriteriaStates;
872 CUtility::asString(lstrSelectionCriteria, strCriteriaStates);
873 strResult += strCriteriaStates;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200874
Patrick Benavoli63499d42011-10-24 18:50:03 +0200875 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200876}
877
878/// Tuning Mode
Patrick Benavoli63499d42011-10-24 18:50:03 +0200879CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200880{
881 if (remoteCommand.getArgument(0) == "on") {
882
883 if (setTuningMode(true, strResult)) {
884
Patrick Benavoli63499d42011-10-24 18:50:03 +0200885 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200886 }
887 } else if (remoteCommand.getArgument(0) == "off") {
888
889 if (setTuningMode(false, strResult)) {
890
Patrick Benavoli63499d42011-10-24 18:50:03 +0200891 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200892 }
893 } else {
894 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200895 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200896 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200897 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200898}
899
Patrick Benavoli63499d42011-10-24 18:50:03 +0200900CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200901{
902 (void)remoteCommand;
903
904 strResult = tuningModeOn() ? "on" : "off";
905
Patrick Benavoli63499d42011-10-24 18:50:03 +0200906 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200907}
908
909/// Value Space
Patrick Benavoli63499d42011-10-24 18:50:03 +0200910CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200911{
912 (void)strResult;
913
914 if (remoteCommand.getArgument(0) == "raw") {
915
916 setValueSpace(true);
917
Patrick Benavoli63499d42011-10-24 18:50:03 +0200918 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200919
920 } else if (remoteCommand.getArgument(0) == "real") {
921
922 setValueSpace(false);
923
Patrick Benavoli63499d42011-10-24 18:50:03 +0200924 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200925
926 } else {
927 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200928 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200929 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200930 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200931}
932
Patrick Benavoli63499d42011-10-24 18:50:03 +0200933CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200934{
935 (void)remoteCommand;
936
937 strResult = valueSpaceIsRaw() ? "raw" : "real";
938
Patrick Benavoli63499d42011-10-24 18:50:03 +0200939 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200940}
941
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200942/// Output Raw Format
Patrick Benavoli63499d42011-10-24 18:50:03 +0200943CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200944{
945 (void)strResult;
946
947 if (remoteCommand.getArgument(0) == "hex") {
948
949 setOutputRawFormat(true);
950
Patrick Benavoli63499d42011-10-24 18:50:03 +0200951 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200952
953 } else if (remoteCommand.getArgument(0) == "dec") {
954
955 setOutputRawFormat(false);
956
Patrick Benavoli63499d42011-10-24 18:50:03 +0200957 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200958
959 } else {
960 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200961 return CCommandHandler::EShowUsage;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200962 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200963 return CCommandHandler::EFailed;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200964}
965
Patrick Benavoli63499d42011-10-24 18:50:03 +0200966CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200967{
968 (void)remoteCommand;
969
970 strResult = outputRawFormatIsHex() ? "hex" : "dec";
971
Patrick Benavoli63499d42011-10-24 18:50:03 +0200972 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200973}
974
Patrick Benavoli68a91282011-08-31 11:23:23 +0200975/// Sync
Patrick Benavoli63499d42011-10-24 18:50:03 +0200976CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200977{
978 if (remoteCommand.getArgument(0) == "on") {
979
980 if (setAutoSync(true, strResult)) {
981
Patrick Benavoli63499d42011-10-24 18:50:03 +0200982 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200983 }
984 } else if (remoteCommand.getArgument(0) == "off") {
985
986 if (setAutoSync(false, strResult)) {
987
Patrick Benavoli63499d42011-10-24 18:50:03 +0200988 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200989 }
990 } else {
991 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200992 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200993 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200994 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200995}
996
Patrick Benavoli63499d42011-10-24 18:50:03 +0200997CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200998{
999 (void)remoteCommand;
1000
1001 strResult = autoSyncOn() ? "on" : "off";
1002
Patrick Benavoli63499d42011-10-24 18:50:03 +02001003 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001004}
1005
Patrick Benavoli63499d42011-10-24 18:50:03 +02001006CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::syncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001007{
1008 (void)remoteCommand;
1009
Patrick Benavoli63499d42011-10-24 18:50:03 +02001010 return sync(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001011}
1012
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001013/// Criteria
Patrick Benavoli63499d42011-10-24 18:50:03 +02001014CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listCriteriaCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001015{
1016 (void)remoteCommand;
1017
Kevin Rocard4eae8272013-04-18 19:12:46 +02001018 bool humanReadable = true;
Kevin Rocard7f265822012-12-07 18:51:22 +01001019
Kevin Rocard4eae8272013-04-18 19:12:46 +02001020 // Look for optional arguments
1021 if (remoteCommand.getArgumentCount() >= 1) {
1022
1023 // If csv is provided, format the criterion list in Commas Separated Value pairs
1024 if (remoteCommand.getArgument(0) == "csv") {
1025 humanReadable = false;
1026 } else {
1027 return CCommandHandler::EShowUsage;
1028 }
1029 }
1030
1031 list<string> lstrResult;
1032 getSelectionCriteria()->listSelectionCriteria(lstrResult, true, humanReadable);
Kevin Rocard7f265822012-12-07 18:51:22 +01001033
1034 // Concatenate the criterion list as the command result
Frederic Boisnard390b36d2013-05-23 15:28:31 +02001035 CUtility::asString(lstrResult, strResult);
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001036
Patrick Benavoli63499d42011-10-24 18:50:03 +02001037 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001038}
Patrick Benavoli68a91282011-08-31 11:23:23 +02001039
1040/// Domains
Patrick Benavoli63499d42011-10-24 18:50:03 +02001041CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001042{
1043 (void)remoteCommand;
1044
Patrick Benavoli63499d42011-10-24 18:50:03 +02001045 getConfigurableDomains()->listDomains(strResult);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001046
Patrick Benavoli63499d42011-10-24 18:50:03 +02001047 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001048}
1049
Patrick Benavoli63499d42011-10-24 18:50:03 +02001050CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001051{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001052 return createDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001053}
1054
Patrick Benavoli63499d42011-10-24 18:50:03 +02001055CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001056{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001057 return deleteDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001058}
1059
Kevin Rocard170f0a42012-06-18 13:56:05 +02001060CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteAllDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1061{
1062 (void)remoteCommand;
1063
1064 return deleteAllDomains(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1065}
1066
Patrick Benavoli63499d42011-10-24 18:50:03 +02001067CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001068{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001069 return getConfigurableDomains()->renameDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001070}
1071
Patrick Benavoli63499d42011-10-24 18:50:03 +02001072CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001073{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001074 // Check tuning mode
1075 if (!checkTuningModeOn(strResult)) {
1076
1077 return CCommandHandler::EFailed;
1078 }
1079
1080 // Set property
1081 bool bSequenceAware;
1082
1083 if (remoteCommand.getArgument(1) == "true") {
1084
1085 bSequenceAware = true;
1086
1087 } else if (remoteCommand.getArgument(1) == "false") {
1088
1089 bSequenceAware = false;
1090
1091 } else {
1092 // Show usage
1093 return CCommandHandler::EShowUsage;
1094 }
1095
1096 return getConfigurableDomains()->setSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001097}
1098
Patrick Benavoli63499d42011-10-24 18:50:03 +02001099CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001100{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001101 // Get property
1102 bool bSequenceAware;
1103
1104 if (!getConfigurableDomains()->getSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult)) {
1105
1106 return CCommandHandler::EFailed;
1107 }
1108
1109 strResult = bSequenceAware ? "true" : "false";
1110
1111 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001112}
1113
Patrick Benavoli63499d42011-10-24 18:50:03 +02001114CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001115{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001116 return getConfigurableDomains()->listDomainElements(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001117}
1118
Patrick Benavoli63499d42011-10-24 18:50:03 +02001119CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::addElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001120{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001121 return addConfigurableElementToDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1122}
1123
1124CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::removeElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1125{
1126 return removeConfigurableElementFromDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1127}
1128
1129CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::splitDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1130{
1131 return split(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001132}
1133
1134/// Configurations
Patrick Benavoli63499d42011-10-24 18:50:03 +02001135CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConfigurationsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001136{
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001137 return getConstConfigurableDomains()->listConfigurations(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
1138}
1139
1140CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1141{
1142 (void)remoteCommand;
1143
1144 // Dummy error context
1145 string strError;
1146 CErrorContext errorContext(strError);
1147
1148 // Dump
1149 getConstConfigurableDomains()->dumpContent(strResult, errorContext);
1150
1151 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001152}
1153
Patrick Benavoli63499d42011-10-24 18:50:03 +02001154CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001155{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001156 return createConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001157}
1158
Patrick Benavoli63499d42011-10-24 18:50:03 +02001159CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001160{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001161 return deleteConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001162}
1163
Patrick Benavoli63499d42011-10-24 18:50:03 +02001164CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001165{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001166 return getConfigurableDomains()->renameConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001167}
1168
Patrick Benavoli63499d42011-10-24 18:50:03 +02001169CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::saveConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001170{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001171 return saveConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001172}
1173
Patrick Benavoli63499d42011-10-24 18:50:03 +02001174CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::restoreConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001175{
Kevin Rocardace81f82012-12-11 16:19:17 +01001176 list<string> lstrResult;
1177 if (!restoreConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), lstrResult)) {
1178 //Concatenate the error list as the command result
Frederic Boisnard390b36d2013-05-23 15:28:31 +02001179 CUtility::asString(lstrResult, strResult);
Kevin Rocardace81f82012-12-11 16:19:17 +01001180
1181 return CCommandHandler::EFailed;
1182 }
1183 return CCommandHandler::EDone;
Patrick Benavoli63499d42011-10-24 18:50:03 +02001184}
1185
1186CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1187{
1188 // Check tuning mode
1189 if (!checkTuningModeOn(strResult)) {
1190
1191 return CCommandHandler::EFailed;
1192 }
1193
1194 // Build configurable element path list
Sebastien Gonzalved9526492014-02-20 22:28:03 +01001195 std::vector<string> astrNewElementSequence;
Patrick Benavoli63499d42011-10-24 18:50:03 +02001196
1197 uint32_t uiArgument;
1198
1199 for (uiArgument = 2; uiArgument < remoteCommand.getArgumentCount(); uiArgument++) {
1200
1201 astrNewElementSequence.push_back(remoteCommand.getArgument(uiArgument));
1202 }
1203
1204 // Delegate to configurable domains
1205 return getConfigurableDomains()->setElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), astrNewElementSequence, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1206}
1207
1208CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1209{
1210 // Delegate to configurable domains
1211 return getConfigurableDomains()->getElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001212}
1213
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001214CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1215{
1216 // Delegate to configurable domains
1217 return getConfigurableDomains()->setApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.packArguments(2, remoteCommand.getArgumentCount() - 2), getConstSelectionCriteria()->getSelectionCriteriaDefinition(), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1218}
1219
1220CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::clearRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1221{
1222 // Delegate to configurable domains
1223 return getConfigurableDomains()->clearApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1224}
1225
1226CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1227{
1228 // Delegate to configurable domains
1229 return getConfigurableDomains()->getApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
1230}
1231
Patrick Benavoli68a91282011-08-31 11:23:23 +02001232/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001233CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001234{
1235 CElementLocator elementLocator(getSystemClass(), false);
1236
1237 CElement* pLocatedElement = NULL;
1238
1239 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1240
Patrick Benavoli63499d42011-10-24 18:50:03 +02001241 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001242 }
1243
1244 strResult = string("\n");
1245
1246 if (!pLocatedElement) {
1247
1248 // List from root folder
1249
1250 // Return system class qualified name
1251 pLocatedElement = getSystemClass();
1252 }
1253
1254 // Return sub-elements
1255 strResult += pLocatedElement->listQualifiedPaths(false);
1256
Patrick Benavoli63499d42011-10-24 18:50:03 +02001257 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001258}
1259
1260/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001261CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listParametersCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001262{
1263 CElementLocator elementLocator(getSystemClass(), false);
1264
1265 CElement* pLocatedElement = NULL;
1266
1267 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1268
Patrick Benavoli63499d42011-10-24 18:50:03 +02001269 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001270 }
1271
1272 strResult = string("\n");
1273
1274 if (!pLocatedElement) {
1275
1276 // List from root folder
1277
1278 // Return system class qualified name
1279 pLocatedElement = getSystemClass();
1280 }
1281
1282 // Return sub-elements
1283 strResult += pLocatedElement->listQualifiedPaths(true);
1284
Patrick Benavoli63499d42011-10-24 18:50:03 +02001285 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001286}
1287
Patrick Benavoli63499d42011-10-24 18:50:03 +02001288CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001289{
1290 CElementLocator elementLocator(getSystemClass());
1291
1292 CElement* pLocatedElement = NULL;
1293
1294 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1295
Patrick Benavoli63499d42011-10-24 18:50:03 +02001296 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001297 }
1298
1299 string strError;
1300
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001301 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001302
1303 // Dump elements
1304 pLocatedElement->dumpContent(strResult, parameterAccessContext);
1305
Patrick Benavoli63499d42011-10-24 18:50:03 +02001306 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001307}
1308
Patrick Benavoli63499d42011-10-24 18:50:03 +02001309CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSizeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001310{
1311 CElementLocator elementLocator(getSystemClass());
1312
1313 CElement* pLocatedElement = NULL;
1314
1315 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1316
Patrick Benavoli63499d42011-10-24 18:50:03 +02001317 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001318 }
1319
1320 // Converted to actual sizable element
1321 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1322
1323 // Get size as string
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001324 strResult = pConfigurableElement->getFootprintAsString();
Patrick Benavoli68a91282011-08-31 11:23:23 +02001325
Patrick Benavoli63499d42011-10-24 18:50:03 +02001326 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001327}
1328
Patrick Benavoli63499d42011-10-24 18:50:03 +02001329CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showPropertiesCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001330{
1331 CElementLocator elementLocator(getSystemClass());
1332
1333 CElement* pLocatedElement = NULL;
1334
1335 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1336
Patrick Benavoli63499d42011-10-24 18:50:03 +02001337 return CCommandHandler::EFailed;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001338 }
1339
1340 // Convert element
1341 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1342
1343 // Return element properties
1344 pConfigurableElement->showProperties(strResult);
1345
Patrick Benavoli63499d42011-10-24 18:50:03 +02001346 return CCommandHandler::ESucceeded;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001347}
1348
Patrick Benavoli63499d42011-10-24 18:50:03 +02001349CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001350{
1351 string strValue;
1352
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001353 if (!accessParameterValue(remoteCommand.getArgument(0), strValue, false, strResult)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001354
Patrick Benavoli63499d42011-10-24 18:50:03 +02001355 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001356 }
1357 // Succeeded
1358 strResult = strValue;
1359
Patrick Benavoli63499d42011-10-24 18:50:03 +02001360 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001361}
1362
Patrick Benavoli63499d42011-10-24 18:50:03 +02001363CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001364{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001365 // Check tuning mode
1366 if (!checkTuningModeOn(strResult)) {
1367
1368 return CCommandHandler::EFailed;
1369 }
1370 // Get value to set
1371 string strValue = remoteCommand.packArguments(1, remoteCommand.getArgumentCount() - 1);
1372
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001373 return accessParameterValue(remoteCommand.getArgument(0), strValue, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001374}
1375
Patrick Benavoli63499d42011-10-24 18:50:03 +02001376CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listBelongingDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001377{
1378 CElementLocator elementLocator(getSystemClass());
1379
1380 CElement* pLocatedElement = NULL;
1381
1382 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1383
Patrick Benavoli63499d42011-10-24 18:50:03 +02001384 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001385 }
1386
1387 // Convert element
1388 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1389
1390 // Return element belonging domains
1391 pConfigurableElement->listBelongingDomains(strResult);
1392
Patrick Benavoli63499d42011-10-24 18:50:03 +02001393 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001394}
1395
Patrick Benavoli63499d42011-10-24 18:50:03 +02001396CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001397{
1398 CElementLocator elementLocator(getSystemClass());
1399
1400 CElement* pLocatedElement = NULL;
1401
1402 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1403
Patrick Benavoli63499d42011-10-24 18:50:03 +02001404 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001405 }
1406
1407 // Convert element
1408 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1409
1410 // Return element belonging domains
1411 pConfigurableElement->listAssociatedDomains(strResult);
1412
Patrick Benavoli63499d42011-10-24 18:50:03 +02001413 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001414}
1415
Patrick Benavoli63499d42011-10-24 18:50:03 +02001416CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001417{
1418 (void)remoteCommand;
1419
1420 getConfigurableDomains()->listAssociatedElements(strResult);
1421
Patrick Benavoli63499d42011-10-24 18:50:03 +02001422 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001423}
1424
Patrick Benavoli63499d42011-10-24 18:50:03 +02001425CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConflictingElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001426{
1427 (void)remoteCommand;
1428
1429 getConfigurableDomains()->listConflictingElements(strResult);
1430
Patrick Benavoli63499d42011-10-24 18:50:03 +02001431 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001432}
1433
Patrick Benavoli63499d42011-10-24 18:50:03 +02001434CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listRogueElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001435{
1436 (void)remoteCommand;
1437
1438 getSystemClass()->listRogueElements(strResult);
1439
Patrick Benavoli63499d42011-10-24 18:50:03 +02001440 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001441}
1442
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001443CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getConfigurationParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1444{
1445 string strOutputValue;
1446 string strError;
1447
1448 if (!accessConfigurationValue(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), strOutputValue, false, strError)) {
1449
1450 strResult = strError;
1451 return CCommandHandler::EFailed;
1452 }
1453 // Succeeded
1454 strResult = strOutputValue;
1455
1456 return CCommandHandler::ESucceeded;
1457}
1458
1459CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setConfigurationParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1460{
1461 // Get value to set
1462 string strValue = remoteCommand.packArguments(3, remoteCommand.getArgumentCount() - 3);
1463
1464 bool bSuccess = accessConfigurationValue(remoteCommand.getArgument(0),
1465 remoteCommand.getArgument(1),
1466 remoteCommand.getArgument(2),
1467 strValue, true, strResult);
1468
1469 return bSuccess ? CCommandHandler::EDone : CCommandHandler::EFailed;
1470}
1471
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +02001472CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showMappingCommmandProcess(
1473 const IRemoteCommand& remoteCommand,
1474 string& strResult)
1475{
1476 if (!getParameterMapping(remoteCommand.getArgument(0), strResult)) {
1477
1478 return CCommandHandler::EFailed;
1479 }
1480
1481 return CCommandHandler::ESucceeded;
1482}
1483
Patrick Benavoli68a91282011-08-31 11:23:23 +02001484/// Settings Import/Export
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001485CParameterMgr::CCommandHandler::CommandStatus
1486 CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess(
1487 const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001488{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001489 string strFileName = remoteCommand.getArgument(0);
1490 return exportDomainsXml(strFileName, false, true, strResult) ?
1491 CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001492}
1493
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001494CParameterMgr::CCommandHandler::CommandStatus
1495 CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess(
1496 const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001497{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001498 return importDomainsXml(remoteCommand.getArgument(0), false, true, strResult) ?
1499 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::exportConfigurableDomainsWithSettingsToXMLCommmandProcess(
1504 const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001505{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001506 string strFileName = remoteCommand.getArgument(0);
1507 return exportDomainsXml(strFileName, true, true, strResult) ?
1508 CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001509}
1510
Patrick Benavoli63499d42011-10-24 18:50:03 +02001511CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001512{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001513 return importDomainsXml(remoteCommand.getArgument(0), true, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001514}
1515
Patrick Benavoli63499d42011-10-24 18:50:03 +02001516CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001517{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001518 return exportDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001519}
1520
Patrick Benavoli63499d42011-10-24 18:50:03 +02001521CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001522{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001523 return importDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001524}
1525
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001526CParameterMgr::CCommandHandler::CommandStatus
1527 CParameterMgr::getConfigurableDomainsWithSettingsXMLCommmandProcess(
1528 const IRemoteCommand& remoteCommand, string& strResult)
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001529{
1530 (void)remoteCommand;
1531
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001532 if (!exportDomainsXml(strResult, true, false, strResult)) {
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001533
1534 return CCommandHandler::EFailed;
1535 }
1536 // Succeeded
1537 return CCommandHandler::ESucceeded;
1538}
1539
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001540CParameterMgr::CCommandHandler::CommandStatus
1541 CParameterMgr::setConfigurableDomainsWithSettingsXMLCommmandProcess(
1542 const IRemoteCommand& remoteCommand, string& strResult)
1543{
1544 return importDomainsXml(remoteCommand.getArgument(0), true, false, strResult) ?
1545 CCommandHandler::EDone : CCommandHandler::EFailed;
1546}
1547
1548CParameterMgr::CCommandHandler::CommandStatus
1549 CParameterMgr::getSystemClassXMLCommmandProcess(
1550 const IRemoteCommand& remoteCommand, string& strResult)
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001551{
1552 (void)remoteCommand;
1553
1554 if (!getSystemClassXMLString(strResult)) {
1555
1556 return CCommandHandler::EFailed;
1557 }
1558 // Succeeded
1559 return CCommandHandler::ESucceeded;
1560}
1561
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001562// User set/get parameters in main BlackBoard
1563bool CParameterMgr::accessParameterValue(const string& strPath, string& strValue, bool bSet, string& strError)
1564{
1565 // Define context
1566 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
1567
Frédéric Boisnard150407c2013-03-15 14:46:23 +01001568 // Activate the auto synchronization with the hardware
1569 if (bSet) {
1570
1571 parameterAccessContext.setAutoSync(_bAutoSyncOn);
1572 }
1573
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001574 return accessValue(parameterAccessContext, strPath, strValue, bSet, strError);
1575}
1576
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +02001577// User get parameter mapping
1578bool CParameterMgr::getParameterMapping(const string& strPath, string& strResult) const
1579{
1580 CPathNavigator pathNavigator(strPath);
1581
1582 // Nagivate through system class
1583 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strResult)) {
1584
1585 return false;
1586 }
1587
1588 // Get the ConfigurableElement corresponding to strPath
1589 const CConfigurableElement* pConfigurableElement = getConfigurableElement(strPath, strResult);
1590 if (!pConfigurableElement) {
1591
1592 return false;
1593 }
1594
1595 // Find the list of the ancestors of the current ConfigurableElement that have a mapping
1596 list<const CConfigurableElement*> configurableElementPath;
1597 pConfigurableElement->getListOfElementsWithMapping(configurableElementPath);
1598
1599 // Get the Subsystem containing the ConfigurableElement
1600 const CSubsystem* pSubsystem = pConfigurableElement->getBelongingSubsystem();
1601 if (!pSubsystem) {
1602
1603 strResult = "Unable to find the Subsystem containing the parameter";
1604 return false;
1605 }
1606
1607 // Fetch the mapping corresponding to the ConfigurableElement
1608 strResult = pSubsystem->getMapping(configurableElementPath);
1609
1610 return true;
1611}
1612
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001613// User set/get parameters in specific Configuration BlackBoard
1614bool CParameterMgr::accessConfigurationValue(const string& strDomain, const string& strConfiguration, const string& strPath, string& strValue, bool bSet, string& strError)
1615{
1616 CElementLocator elementLocator(getSystemClass());
1617
1618 CElement* pLocatedElement = NULL;
1619
1620 if (!elementLocator.locate(strPath, &pLocatedElement, strError)) {
1621
1622 return false;
1623 }
1624
1625 // Convert element
1626 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1627
1628 // Get the Configuration blackboard and the Base Offset of the configurable element in this blackboard
1629 uint32_t uiBaseOffset;
1630 bool bIsLastApplied;
1631
1632 CParameterBlackboard* pConfigurationBlackboard = getConstConfigurableDomains()->findConfigurationBlackboard(strDomain, strConfiguration, pConfigurableElement, uiBaseOffset, bIsLastApplied, strError);
1633
1634 if (!pConfigurationBlackboard) {
1635
1636 return false;
1637 }
1638
1639 log_info("Element %s in Domain %s, offset: %d, base offset: %d", strPath.c_str(), strDomain.c_str(), pConfigurableElement->getOffset(), uiBaseOffset);
1640
1641 /// Update the Configuration Blackboard
1642
Frédéric Boisnard150407c2013-03-15 14:46:23 +01001643 // 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 +01001644 CParameterAccessContext parameterAccessContext(strError, pConfigurationBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex, uiBaseOffset);
1645
Frédéric Boisnardda8298c2014-05-23 19:05:31 +02001646 // Deactivate the auto synchronization with the hardware during the Configuration Blackboard
1647 // access (only Main Blackboard shall be synchronized, Configurations Blackboards are copied
1648 // into the Main Blackboard each time a configuration is restored but they are not synchronized
1649 // directly).
1650 if (bSet) {
1651
1652 parameterAccessContext.setAutoSync(false);
1653 }
1654
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001655 // Access Value in the Configuration Blackboard
1656 if (!accessValue(parameterAccessContext, strPath, strValue, bSet, strError)) {
1657
1658 return false;
1659 }
1660
1661 /// If the Configuration is the last one applied, update the Main Blackboard as well
1662
1663 if (bIsLastApplied) {
1664
1665 // Define Main context
1666 parameterAccessContext.setParameterBlackboard(_pMainParameterBlackboard);
1667
Frédéric Boisnard150407c2013-03-15 14:46:23 +01001668 // Activate the auto synchronization with the hardware
1669 if (bSet) {
1670
1671 parameterAccessContext.setAutoSync(_bAutoSyncOn);
1672 }
1673
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001674 // Access Value in the Main Blackboard
1675 return accessValue(parameterAccessContext, strPath, strValue, bSet, strError);
1676 }
1677
1678 return true;
1679}
1680
Patrick Benavoli68a91282011-08-31 11:23:23 +02001681// User set/get parameters
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001682bool CParameterMgr::accessValue(CParameterAccessContext& parameterAccessContext, const string& strPath, string& strValue, bool bSet, string& strError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001683{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001684 // Lock state
1685 CAutoLock autoLock(&_blackboardMutex);
1686
1687 CPathNavigator pathNavigator(strPath);
1688
1689 // Nagivate through system class
1690 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001691
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +02001692 parameterAccessContext.setError(strError);
1693
Patrick Benavoli68a91282011-08-31 11:23:23 +02001694 return false;
1695 }
1696
Patrick Benavoli065264a2011-11-20 15:46:41 +01001697 // Do the get
1698 return getConstSystemClass()->accessValue(pathNavigator, strValue, bSet, parameterAccessContext);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001699}
1700
1701// Tuning mode
1702bool CParameterMgr::setTuningMode(bool bOn, string& strError)
1703{
1704 // Tuning allowed?
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001705 if (bOn && !getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001706
1707 strError = "Tuning prohibited";
1708
1709 return false;
1710 }
1711 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +01001712 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001713
1714 // Warn domains about exiting tuning mode
1715 if (!bOn && _bTuningModeIsOn) {
1716
1717 // Ensure application of currently selected configurations
Patrick Benavoli1387bda2011-08-31 11:23:24 +02001718 // Force-apply configurations
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01001719 doApplyConfigurations(true);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001720
Patrick Benavoli68a91282011-08-31 11:23:23 +02001721 // Turn auto sync back on
1722 _bAutoSyncOn = true;
1723 }
1724
1725 // Store
1726 _bTuningModeIsOn = bOn;
1727
Patrick Benavoli68a91282011-08-31 11:23:23 +02001728 return true;
1729}
1730
1731bool CParameterMgr::tuningModeOn() const
1732{
1733 return _bTuningModeIsOn;
1734}
1735
1736// Current value space for user set/get value interpretation
1737void CParameterMgr::setValueSpace(bool bIsRaw)
1738{
1739 _bValueSpaceIsRaw = bIsRaw;
1740}
1741
1742bool CParameterMgr::valueSpaceIsRaw()
1743{
1744 return _bValueSpaceIsRaw;
1745}
1746
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001747// Current Output Raw Format for user get value interpretation
1748void CParameterMgr::setOutputRawFormat(bool bIsHex)
1749{
1750 _bOutputRawFormatIsHex = bIsHex;
1751}
1752
1753bool CParameterMgr::outputRawFormatIsHex()
1754{
1755 return _bOutputRawFormatIsHex;
1756}
1757
Patrick Benavoli68a91282011-08-31 11:23:23 +02001758/// Sync
1759// Automatic hardware synchronization control (during tuning session)
1760bool CParameterMgr::setAutoSync(bool bAutoSyncOn, string& strError)
1761{
1762 // Check tuning mode
1763 if (!checkTuningModeOn(strError)) {
1764
1765 return false;
1766 }
1767 // Warn domains about turning auto sync back on
1768 if (bAutoSyncOn && !_bAutoSyncOn) {
1769
Patrick Benavoli592ae562011-09-05 16:53:58 +02001770 // Do the synchronization at system class level (could be optimized by keeping track of all modified parameters)
1771 if (!sync(strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001772
1773 return false;
1774 }
1775 }
1776
1777 // Set Auto sync
1778 _bAutoSyncOn = bAutoSyncOn;
1779
1780 return true;
1781}
1782
1783bool CParameterMgr::autoSyncOn() const
1784{
1785 return _bAutoSyncOn;
1786}
1787
1788// Manual hardware synchronization control (during tuning session)
1789bool CParameterMgr::sync(string& strError)
1790{
1791 // Check tuning mode
1792 if (!checkTuningModeOn(strError)) {
1793
1794 return false;
1795 }
1796 // Warn domains about turning auto sync back on
1797 if (_bAutoSyncOn) {
1798
1799 strError = "Feature unavailable when Auto Sync is on";
1800
1801 return false;
1802 }
1803
1804 // Get syncer set
1805 CSyncerSet syncerSet;
1806 // ... from system class
1807 getConstSystemClass()->fillSyncerSet(syncerSet);
Kevin Rocardace81f82012-12-11 16:19:17 +01001808
Patrick Benavoli68a91282011-08-31 11:23:23 +02001809 // Sync
Kevin Rocardace81f82012-12-11 16:19:17 +01001810 list<string> lstrError;
1811 if (! syncerSet.sync(*_pMainParameterBlackboard, false, &lstrError)){
1812
Frederic Boisnard390b36d2013-05-23 15:28:31 +02001813 CUtility::asString(lstrError, strError);
Kevin Rocardace81f82012-12-11 16:19:17 +01001814 return false;
1815 };
1816
1817 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001818}
1819
1820// Content dump
1821void CParameterMgr::logStructureContent(string& strContent) const
1822{
1823 string strError;
1824
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001825 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001826
1827 dumpContent(strContent, parameterAccessContext);
1828}
1829
1830// Configuration/Domains handling
1831bool CParameterMgr::createDomain(const string& strName, string& strError)
1832{
1833 // Check tuning mode
1834 if (!checkTuningModeOn(strError)) {
1835
1836 return false;
1837 }
1838
1839 // Delegate to configurable domains
1840 return getConfigurableDomains()->createDomain(strName, strError);
1841}
1842
1843bool CParameterMgr::deleteDomain(const string& strName, string& strError)
1844{
1845 // Check tuning mode
1846 if (!checkTuningModeOn(strError)) {
1847
1848 return false;
1849 }
1850
1851 // Delegate to configurable domains
1852 return getConfigurableDomains()->deleteDomain(strName, strError);
1853}
1854
Kevin Rocard170f0a42012-06-18 13:56:05 +02001855bool CParameterMgr::deleteAllDomains(string& strError)
1856{
1857 // Check tuning mode
1858 if (!checkTuningModeOn(strError)) {
1859
1860 return false;
1861 }
1862
1863 // Delegate to configurable domains
1864 getConfigurableDomains()->deleteAllDomains();
1865
1866 return true;
1867}
1868
Patrick Benavoli68a91282011-08-31 11:23:23 +02001869bool CParameterMgr::createConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1870{
1871 // Check tuning mode
1872 if (!checkTuningModeOn(strError)) {
1873
1874 return false;
1875 }
1876
1877 // Delegate to configurable domains
1878 return getConfigurableDomains()->createConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1879}
1880
1881bool CParameterMgr::deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1882{
1883 // Check tuning mode
1884 if (!checkTuningModeOn(strError)) {
1885
1886 return false;
1887 }
1888
1889 // Delegate to configurable domains
1890 return getConfigurableDomains()->deleteConfiguration(strDomain, strConfiguration, strError);
1891}
1892
Kevin Rocardace81f82012-12-11 16:19:17 +01001893bool CParameterMgr::restoreConfiguration(const string& strDomain, const string& strConfiguration, list<string>& lstrError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001894{
Kevin Rocardace81f82012-12-11 16:19:17 +01001895 string strError;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001896 // Check tuning mode
1897 if (!checkTuningModeOn(strError)) {
1898
Kevin Rocardace81f82012-12-11 16:19:17 +01001899 lstrError.push_back(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001900 return false;
1901 }
1902
1903 // Delegate to configurable domains
Kevin Rocardace81f82012-12-11 16:19:17 +01001904 return getConstConfigurableDomains()->restoreConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, lstrError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001905}
1906
1907bool CParameterMgr::saveConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1908{
1909 // Check tuning mode
1910 if (!checkTuningModeOn(strError)) {
1911
1912 return false;
1913 }
1914
1915 // Delegate to configurable domains
1916 return getConfigurableDomains()->saveConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1917}
1918
1919// Configurable element - domain association
1920bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1921{
1922 // Check tuning mode
1923 if (!checkTuningModeOn(strError)) {
1924
1925 return false;
1926 }
1927
1928 CElementLocator elementLocator(getSystemClass());
1929
1930 CElement* pLocatedElement = NULL;
1931
1932 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1933
1934 return false;
1935 }
1936
1937 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001938 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001939
1940 // Delegate
1941 return getConfigurableDomains()->addConfigurableElementToDomain(strDomain, pConfigurableElement, _pMainParameterBlackboard, strError);
1942}
1943
1944bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1945{
1946 // Check tuning mode
1947 if (!checkTuningModeOn(strError)) {
1948
1949 return false;
1950 }
1951
1952 CElementLocator elementLocator(getSystemClass());
1953
1954 CElement* pLocatedElement = NULL;
1955
1956 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1957
Patrick Benavoli63499d42011-10-24 18:50:03 +02001958 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001959 }
1960
1961 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001962 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001963
1964 // Delegate
1965 return getConfigurableDomains()->removeConfigurableElementFromDomain(strDomain, pConfigurableElement, strError);
1966}
1967
1968bool CParameterMgr::split(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1969{
1970 // Check tuning mode
1971 if (!checkTuningModeOn(strError)) {
1972
1973 return false;
1974 }
1975
1976 CElementLocator elementLocator(getSystemClass());
1977
1978 CElement* pLocatedElement = NULL;
1979
1980 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1981
Patrick Benavoli63499d42011-10-24 18:50:03 +02001982 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001983 }
1984
1985 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001986 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001987
1988 // Delegate
1989 return getConfigurableDomains()->split(strDomain, pConfigurableElement, strError);
1990}
1991
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001992bool CParameterMgr::importDomainsXml(const string& strXmlSource, bool bWithSettings,
1993 bool bFromFile, string& strError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001994{
1995 // Check tuning mode
1996 if (!checkTuningModeOn(strError)) {
1997
1998 return false;
1999 }
2000
2001 // check path is absolute
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002002 if (bFromFile && strXmlSource[0] != '/') {
Patrick Benavoli68a91282011-08-31 11:23:23 +02002003
2004 strError = "Please provide absolute path";
2005
2006 return false;
2007 }
2008 // Root element
2009 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
2010
2011 // Context
2012 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
2013
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002014 // Selection criteria definition for rule creation
2015 xmlDomainSerializingContext.setSelectionCriteriaDefinition(
2016 getConstSelectionCriteria()->getSelectionCriteriaDefinition());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002017
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002018 // Init serializing context
2019 xmlDomainSerializingContext.set(
2020 _pElementLibrarySet->getElementLibrary(EParameterConfigurationLibrary),
2021 "", _strSchemaFolderLocation);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002022
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002023 // Get Schema file associated to root element
2024 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" +
2025 pConfigurableDomains->getKind() + ".xsd";
2026
2027 // Xml Source
2028 CXmlDocSource* pSource;
2029
2030 if (bFromFile) {
2031
2032 // when importing from a file strXmlSource is the file name
2033 pSource = new CXmlFileDocSource(strXmlSource, strXmlSchemaFilePath,
2034 pConfigurableDomains->getKind(),
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +02002035 pConfigurableDomains->getName(), "SystemClassName",
2036 _bValidateSchemasOnStart);
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002037
2038 } else {
2039
2040 // when importing from an xml string, strXmlSource contains the string
2041 pSource = new CXmlStringDocSource(strXmlSource, strXmlSchemaFilePath,
2042 pConfigurableDomains->getKind(),
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +02002043 pConfigurableDomains->getName(), "SystemClassName",
2044 _bValidateSchemasOnStart);
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002045
2046 }
2047 // Start clean
2048 pConfigurableDomains->clean();
2049
2050 // Use a doc sink that instantiate Configurable Domains from the given doc source
2051 CXmlMemoryDocSink memorySink(pConfigurableDomains);
2052
2053 bool bProcessSuccess = memorySink.process(*pSource, xmlDomainSerializingContext);
2054
2055 if (!bProcessSuccess) {
2056
2057 //Cleanup
2058 pConfigurableDomains->clean();
2059
2060 } else {
2061
2062 // Validate domains after XML import
2063 pConfigurableDomains->validate(_pMainParameterBlackboard);
2064
Patrick Benavoli68a91282011-08-31 11:23:23 +02002065 }
2066
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002067 delete pSource;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002068
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002069 return bProcessSuccess;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002070}
2071
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002072bool CParameterMgr::exportDomainsXml(string& strXmlDest, bool bWithSettings, bool bToFile,
2073 string& strError) const
Patrick Benavoli68a91282011-08-31 11:23:23 +02002074{
2075 // check path is absolute
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002076 if (bToFile && strXmlDest[0] != '/') {
Patrick Benavoli68a91282011-08-31 11:23:23 +02002077
2078 strError = "Please provide absolute path";
2079
2080 return false;
2081 }
2082
2083 // Root element
2084 const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains();
2085
2086 // Get Schema file associated to root element
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002087 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" +
2088 pConfigurableDomains->getKind() + ".xsd";
Patrick Benavoli68a91282011-08-31 11:23:23 +02002089
2090 // Context
2091 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
2092
2093 // Value space
2094 xmlDomainSerializingContext.setValueSpaceRaw(_bValueSpaceIsRaw);
2095
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02002096 // Output raw format
2097 xmlDomainSerializingContext.setOutputRawFormat(_bOutputRawFormatIsHex);
2098
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002099 // Use a doc source by loading data from instantiated Configurable Domains
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002100 CXmlMemoryDocSource memorySource(pConfigurableDomains, pConfigurableDomains->getKind(),
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +02002101 strXmlSchemaFilePath, "parameter-framework",
2102 getVersion(), _bValidateSchemasOnStart);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002103
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002104 // Xml Sink
2105 CXmlDocSink* pSink;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002106
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002107 if (bToFile) {
2108
2109 // Use a doc sink to write the doc data in a file
2110 pSink = new CXmlFileDocSink(strXmlDest);
2111
2112 } else {
2113
2114 // Use a doc sink to write the doc data in a string
2115 pSink = new CXmlStringDocSink(strXmlDest);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002116 }
2117
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002118 bool bProcessSuccess = pSink->process(memorySource, xmlDomainSerializingContext);
2119
2120 delete pSink;
2121 return bProcessSuccess;
Patrick Benavoli68a91282011-08-31 11:23:23 +02002122}
2123
2124// Binary Import/Export
2125bool CParameterMgr::importDomainsBinary(const string& strFileName, string& strError)
2126{
2127 // Check tuning mode
2128 if (!checkTuningModeOn(strError)) {
2129
2130 return false;
2131 }
2132 // check path is absolute
2133 if (strFileName[0] != '/') {
2134
2135 strError = "Please provide absolute path";
2136
2137 return false;
2138 }
2139 // Root element
2140 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
2141
2142 // Serialize in
2143 return pConfigurableDomains->serializeSettings(strFileName, false, _uiStructureChecksum, strError);
2144}
2145
2146bool CParameterMgr::exportDomainsBinary(const string& strFileName, string& strError)
2147{
2148 // check path is absolute
2149 if (strFileName[0] != '/') {
2150
2151 strError = "Please provide absolute path";
2152
2153 return false;
2154 }
Patrick Benavoli68a91282011-08-31 11:23:23 +02002155
Patrick Benavoli68a91282011-08-31 11:23:23 +02002156 // Root element
2157 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
2158
2159 // Serialize out
2160 return pConfigurableDomains->serializeSettings(strFileName, true, _uiStructureChecksum, strError);
2161}
2162
2163// For tuning, check we're in tuning mode
2164bool CParameterMgr::checkTuningModeOn(string& strError) const
2165{
2166 // Tuning Mode on?
2167 if (!_bTuningModeIsOn) {
2168
2169 strError = "Tuning Mode must be on";
2170
2171 return false;
2172 }
2173 return true;
2174}
2175
Patrick Benavoli065264a2011-11-20 15:46:41 +01002176// Tuning mutex dynamic parameter handling
2177pthread_mutex_t* CParameterMgr::getBlackboardMutex()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002178{
Patrick Benavoli065264a2011-11-20 15:46:41 +01002179 return &_blackboardMutex;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002180}
2181
Patrick Benavoli065264a2011-11-20 15:46:41 +01002182// Blackboard reference (dynamic parameter handling)
2183CParameterBlackboard* CParameterMgr::getParameterBlackboard()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002184{
Patrick Benavoli065264a2011-11-20 15:46:41 +01002185 return _pMainParameterBlackboard;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002186}
2187
Patrick Benavoli68a91282011-08-31 11:23:23 +02002188// Dynamic creation library feeding
2189void CParameterMgr::feedElementLibraries()
2190{
2191 // Global Configuration handling
2192 CElementLibrary* pFrameworkConfigurationLibrary = new CElementLibrary;
2193
Kevin Rocarda7b69602013-08-07 16:15:33 +02002194 pFrameworkConfigurationLibrary->addElementBuilder("ParameterFrameworkConfiguration", new TElementBuilderTemplate<CParameterFrameworkConfiguration>());
2195 pFrameworkConfigurationLibrary->addElementBuilder("SubsystemPlugins", new TKindElementBuilderTemplate<CSubsystemPlugins>());
2196 pFrameworkConfigurationLibrary->addElementBuilder("Location", new TKindElementBuilderTemplate<CPluginLocation>());
2197 pFrameworkConfigurationLibrary->addElementBuilder("StructureDescriptionFileLocation", new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>());
2198 pFrameworkConfigurationLibrary->addElementBuilder("SettingsConfiguration", new TKindElementBuilderTemplate<CFrameworkConfigurationGroup>());
2199 pFrameworkConfigurationLibrary->addElementBuilder("ConfigurableDomainsFileLocation", new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>());
2200 pFrameworkConfigurationLibrary->addElementBuilder("BinarySettingsFileLocation", new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002201
2202 _pElementLibrarySet->addElementLibrary(pFrameworkConfigurationLibrary);
2203
2204 // Parameter creation
2205 CElementLibrary* pParameterCreationLibrary = new CElementLibrary;
2206
Kevin Rocarda7b69602013-08-07 16:15:33 +02002207 pParameterCreationLibrary->addElementBuilder("Subsystem", new CSubsystemElementBuilder(getSystemClass()->getSubsystemLibrary()));
2208 pParameterCreationLibrary->addElementBuilder("ComponentType", new TNamedElementBuilderTemplate<CComponentType>());
2209 pParameterCreationLibrary->addElementBuilder("Component", new TNamedElementBuilderTemplate<CComponentInstance>());
2210 pParameterCreationLibrary->addElementBuilder("BitParameter", new TNamedElementBuilderTemplate<CBitParameterType>());
2211 pParameterCreationLibrary->addElementBuilder("BitParameterBlock", new TNamedElementBuilderTemplate<CBitParameterBlockType>());
2212 pParameterCreationLibrary->addElementBuilder("StringParameter", new TNamedElementBuilderTemplate<CStringParameterType>());
2213 pParameterCreationLibrary->addElementBuilder("ParameterBlock", new TNamedElementBuilderTemplate<CParameterBlockType>());
2214 pParameterCreationLibrary->addElementBuilder("BooleanParameter", new TNamedElementBuilderTemplate<CBooleanParameterType>());
2215 pParameterCreationLibrary->addElementBuilder("IntegerParameter", new TNamedElementBuilderTemplate<CIntegerParameterType>());
2216 pParameterCreationLibrary->addElementBuilder("LinearAdaptation", new TElementBuilderTemplate<CLinearParameterAdaptation>());
2217 pParameterCreationLibrary->addElementBuilder("EnumParameter", new TNamedElementBuilderTemplate<CEnumParameterType>());
2218 pParameterCreationLibrary->addElementBuilder("ValuePair", new TElementBuilderTemplate<CEnumValuePair>());
2219 pParameterCreationLibrary->addElementBuilder("FixedPointParameter", new TNamedElementBuilderTemplate<CFixedPointParameterType>());
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +02002220 pParameterCreationLibrary->addElementBuilder("SubsystemInclude", new CFileIncluderElementBuilder(_bValidateSchemasOnStart));
Patrick Benavoli68a91282011-08-31 11:23:23 +02002221
2222 _pElementLibrarySet->addElementLibrary(pParameterCreationLibrary);
2223
2224 // Parameter Configuration Domains creation
2225 CElementLibrary* pParameterConfigurationLibrary = new CElementLibrary;
2226
Kevin Rocarda7b69602013-08-07 16:15:33 +02002227 pParameterConfigurationLibrary->addElementBuilder("ConfigurableDomain", new TNamedElementBuilderTemplate<CConfigurableDomain>());
2228 pParameterConfigurationLibrary->addElementBuilder("Configuration", new TNamedElementBuilderTemplate<CDomainConfiguration>());
2229 pParameterConfigurationLibrary->addElementBuilder("CompoundRule", new TElementBuilderTemplate<CCompoundRule>());
2230 pParameterConfigurationLibrary->addElementBuilder("SelectionCriterionRule", new TElementBuilderTemplate<CSelectionCriterionRule>());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002231
2232 _pElementLibrarySet->addElementLibrary(pParameterConfigurationLibrary);
2233}
2234
2235// Remote Processor Server connection handling
2236bool CParameterMgr::handleRemoteProcessingInterface(string& strError)
2237{
2238 CAutoLog autoLog(this, "Handling remote processing interface");
2239
2240 // Start server if tuning allowed
Patrick Benavoli95ac0342011-11-07 20:32:51 +01002241 if (getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02002242
Kevin Rocardace81f82012-12-11 16:19:17 +01002243 log_info("Loading remote processor library");
Patrick Benavoli68a91282011-08-31 11:23:23 +02002244
2245 // Load library
Renaud de Chivre1b8b3ca2013-12-13 15:09:44 +01002246 _handleLibRemoteProcessor = dlopen("libremote-processor.so", RTLD_NOW);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002247
Renaud de Chivre1b8b3ca2013-12-13 15:09:44 +01002248 if (!_handleLibRemoteProcessor) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02002249
2250 // Return error
2251 const char* pcError = dlerror();
2252
2253 if (pcError) {
2254
2255 strError = pcError;
2256 } else {
2257
2258 strError = "Unable to load libremote-processor.so library";
2259 }
2260
2261 return false;
2262 }
2263
Renaud de Chivre1b8b3ca2013-12-13 15:09:44 +01002264 CreateRemoteProcessorServer pfnCreateRemoteProcessorServer = (CreateRemoteProcessorServer)dlsym(_handleLibRemoteProcessor, "createRemoteProcessorServer");
Patrick Benavoli68a91282011-08-31 11:23:23 +02002265
2266 if (!pfnCreateRemoteProcessorServer) {
2267
2268 strError = "libremote-process.so does not contain createRemoteProcessorServer symbol.";
2269
2270 return false;
2271 }
2272
2273 // Create server
Patrick Benavoli95ac0342011-11-07 20:32:51 +01002274 _pRemoteProcessorServer = pfnCreateRemoteProcessorServer(getConstFrameworkConfiguration()->getServerPort(), _pCommandHandler);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002275
Kevin Rocardace81f82012-12-11 16:19:17 +01002276 log_info("Starting remote processor server on port %d", getConstFrameworkConfiguration()->getServerPort());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002277 // Start
2278 if (!_pRemoteProcessorServer->start()) {
2279
Frédéric Boisnard6c55e9a2014-01-10 18:46:33 +01002280 ostringstream oss;
2281 oss << "ParameterMgr: Unable to start remote processor server on port "
2282 << getConstFrameworkConfiguration()->getServerPort();
2283 strError = oss.str();
Patrick Benavoli68a91282011-08-31 11:23:23 +02002284
2285 return false;
2286 }
2287 }
2288
2289 return true;
2290}
2291
2292// Back synchronization
Kevin Rocardace81f82012-12-11 16:19:17 +01002293CBackSynchronizer* CParameterMgr::createBackSynchronizer() const
Patrick Benavoli68a91282011-08-31 11:23:23 +02002294{
2295#ifdef SIMULATION
2296 // In simulation, back synchronization of the blackboard won't probably work
2297 // We need to ensure though the blackboard is initialized with valid data
Kevin Rocardace81f82012-12-11 16:19:17 +01002298 return new CSimulatedBackSynchronizer(getConstSystemClass(), _pMainParameterBlackboard);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002299#else
2300 // Real back synchronizer from subsystems
Kevin Rocardace81f82012-12-11 16:19:17 +01002301 return new CHardwareBackSynchronizer(getConstSystemClass(), _pMainParameterBlackboard);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002302#endif
2303}
2304
2305// Children typwise access
2306CParameterFrameworkConfiguration* CParameterMgr::getFrameworkConfiguration()
2307{
2308 return static_cast<CParameterFrameworkConfiguration*>(getChild(EFrameworkConfiguration));
2309}
2310
2311const CParameterFrameworkConfiguration* CParameterMgr::getConstFrameworkConfiguration()
2312{
2313 return getFrameworkConfiguration();
2314}
2315
2316CSelectionCriteria* CParameterMgr::getSelectionCriteria()
2317{
2318 return static_cast<CSelectionCriteria*>(getChild(ESelectionCriteria));
2319}
2320
2321const CSelectionCriteria* CParameterMgr::getConstSelectionCriteria()
2322{
2323 return static_cast<const CSelectionCriteria*>(getChild(ESelectionCriteria));
2324}
2325
2326CSystemClass* CParameterMgr::getSystemClass()
2327{
2328 return static_cast<CSystemClass*>(getChild(ESystemClass));
2329}
2330
2331const CSystemClass* CParameterMgr::getConstSystemClass() const
2332{
2333 return static_cast<const CSystemClass*>(getChild(ESystemClass));
2334}
2335
2336// Configurable Domains
2337CConfigurableDomains* CParameterMgr::getConfigurableDomains()
2338{
2339 return static_cast<CConfigurableDomains*>(getChild(EConfigurableDomains));
2340}
2341
2342const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains()
2343{
2344 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
2345}
2346
2347const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains() const
2348{
2349 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
2350}
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002351
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01002352// Apply configurations
2353void CParameterMgr::doApplyConfigurations(bool bForce)
2354{
2355 CSyncerSet syncerSet;
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002356
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01002357 // Check subsystems that need resync
2358 getSystemClass()->checkForSubsystemsToResync(syncerSet);
2359
2360 // Ensure application of currently selected configurations
2361 getConfigurableDomains()->apply(_pMainParameterBlackboard, syncerSet, bForce);
2362
2363 // Reset the modified status of the current criteria to indicate that a new configuration has been applied
2364 getSelectionCriteria()->resetModifiedStatus();
2365}
2366
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002367bool CParameterMgr::getSystemClassXMLString(string& strResult)
2368{
2369 // Root element
2370 const CSystemClass* pSystemClass = getSystemClass();
2371
2372 string strError;
2373
2374 CXmlSerializingContext xmlSerializingContext(strError);
2375
2376 // Use a doc source by loading data from instantiated Configurable Domains
Mattijs Korpershoekcce85f62014-04-08 14:10:03 +02002377 CXmlMemoryDocSource memorySource(pSystemClass, pSystemClass->getKind(),
2378 _bValidateSchemasOnStart);
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002379
2380 // Use a doc sink that write the doc data in a string
2381 CXmlStringDocSink stringSink(strResult);
2382
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002383 bool bProcessSuccess = stringSink.process(memorySource, xmlSerializingContext);
2384
2385 if (!bProcessSuccess) {
2386
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002387 strResult = strError;
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002388
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002389 }
2390
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002391 return bProcessSuccess;
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002392}