blob: 6293129fc7d9916ddf94a7192ec1f41321dec341 [file] [log] [blame]
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001 /*
Patrick Benavoli68a91282011-08-31 11:23:23 +02002 * INTEL CONFIDENTIAL
3 * Copyright © 2011 Intel
4 * Corporation All Rights Reserved.
5 *
6 * The source code contained or described herein and all documents related to
7 * the source code ("Material") are owned by Intel Corporation or its suppliers
8 * or licensors. Title to the Material remains with Intel Corporation or its
9 * suppliers and licensors. The Material contains trade secrets and proprietary
10 * and confidential information of Intel or its suppliers and licensors. The
11 * Material is protected by worldwide copyright and trade secret laws and
12 * treaty provisions. No part of the Material may be used, copied, reproduced,
13 * modified, published, uploaded, posted, transmitted, distributed, or
14 * disclosed in any way without Intel’s prior express written permission.
15 *
16 * No license under any patent, copyright, trade secret or other intellectual
17 * property right is granted to or conferred upon you by disclosure or delivery
18 * of the Materials, either expressly, by implication, inducement, estoppel or
19 * otherwise. Any license under such intellectual property rights must be
20 * express and approved by Intel in writing.
21 *
Patrick Benavoli68a91282011-08-31 11:23:23 +020022 * CREATED: 2011-06-01
23 * UPDATED: 2011-07-27
Patrick Benavoli68a91282011-08-31 11:23:23 +020024 */
25#include "ParameterMgr.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020026#include "XmlParameterSerializingContext.h"
27#include "XmlElementSerializingContext.h"
28#include "SystemClass.h"
29#include "ElementLibrarySet.h"
30#include "SubsystemLibrary.h"
31#include "NamedElementBuilderTemplate.h"
32#include "KindElementBuilderTemplate.h"
33#include "ElementBuilderTemplate.h"
34#include "SelectionCriterionType.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020035#include "SubsystemElementBuilder.h"
36#include "SelectionCriteria.h"
37#include "ComponentType.h"
38#include "ComponentInstance.h"
39#include "ParameterBlockType.h"
40#include "BooleanParameterType.h"
41#include "IntegerParameterType.h"
42#include "FixedPointParameterType.h"
43#include "ParameterBlackboard.h"
44#include "Parameter.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020045#include "ParameterAccessContext.h"
46#include "XmlFileIncluderElement.h"
47#include "ParameterFrameworkConfiguration.h"
48#include "FrameworkConfigurationGroup.h"
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +010049#include "PluginLocation.h"
50#include "SubsystemPlugins.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020051#include "FrameworkConfigurationLocation.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020052#include "ConfigurableDomains.h"
53#include "ConfigurableDomain.h"
54#include "DomainConfiguration.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020055#include "XmlDomainSerializingContext.h"
56#include "BitParameterBlockType.h"
57#include "BitParameterType.h"
Patrick Benavoli1352ae52011-10-21 16:48:04 +020058#include "StringParameterType.h"
Patrick Benavoli9fc3c0d2011-10-27 14:27:27 +020059#include "EnumParameterType.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020060#include "RemoteProcessorServerInterface.h"
61#include "ElementLocator.h"
62#include "AutoLog.h"
63#include "CompoundRule.h"
64#include "SelectionCriterionRule.h"
65#include "SimulatedBackSynchronizer.h"
66#include "HardwareBackSynchronizer.h"
Patrick Benavoli1387bda2011-08-31 11:23:24 +020067#include "AutoLock.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020068#include <strings.h>
69#include <dlfcn.h>
70#include <assert.h>
Patrick Benavoli065264a2011-11-20 15:46:41 +010071#include "ParameterHandle.h"
Patrick Benavoliee65e6d2011-11-20 18:52:24 +010072#include "LinearParameterAdaptation.h"
Patrick Benavoli68808c62012-02-02 17:12:41 +010073#include "EnumValuePair.h"
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020074#include "XmlFileDocSink.h"
75#include "XmlFileDocSource.h"
76#include "XmlStringDocSink.h"
Georges-Henri Baroncec86c12012-09-04 17:30:28 +020077#include "XmlStringDocSource.h"
Georges-Henri Baron326a31d2012-06-28 12:05:09 +020078#include "XmlMemoryDocSink.h"
79#include "XmlMemoryDocSource.h"
Kevin Rocardace81f82012-12-11 16:19:17 +010080#include "Utility.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020081
82#define base CElement
83
84// Used for remote processor server creation
85typedef IRemoteProcessorServerInterface* (*CreateRemoteProcessorServer)(uint16_t uiPort, IRemoteCommandHandler* pCommandHandler);
86
87// Global configuration file name (fixed)
88const char* gacParameterFrameworkConfigurationFileName = "ParameterFrameworkConfiguration.xml";
89const char* gacSystemSchemasSubFolder = "Schemas";
90
91// Config File System looks normally like this:
92// ---------------------------------------------
Patrick Benavoli95ac0342011-11-07 20:32:51 +010093//├── <ParameterFrameworkConfiguration>.xml
Patrick Benavoli68a91282011-08-31 11:23:23 +020094//├── Schemas
95//│ └── *.xsd
96//├── Settings
97//│ └── <SystemClassName folder>*
98//│ ├── <ConfigurableDomains>.xml
99//│ └── <Settings>.bin?
100//└── Structure
101// └── <SystemClassName folder>*
102// ├── <SystemClassName>Class.xml
103// └── <Subsystem>.xml*
104// --------------------------------------------
105
106
107// Remote command parser array
Patrick Benavoli592ae562011-09-05 16:53:58 +0200108const CParameterMgr::SRemoteCommandParserItem CParameterMgr::gastRemoteCommandParserItems[] = {
Kevin Rocard3949b342013-05-24 18:43:53 +0200109
Patrick Benavoli592ae562011-09-05 16:53:58 +0200110 /// Version
Kevin Rocard3949b342013-05-24 18:43:53 +0200111 { "version", &CParameterMgr::versionCommandProcess, 0,
112 "", "Show version" },
113
Patrick Benavoli68a91282011-08-31 11:23:23 +0200114 /// Status
Kevin Rocard3949b342013-05-24 18:43:53 +0200115 { "status", &CParameterMgr::statusCommandProcess, 0, "",
116 "Show current status" },
117
Patrick Benavoli68a91282011-08-31 11:23:23 +0200118 /// Tuning Mode
Kevin Rocard3949b342013-05-24 18:43:53 +0200119 { "setTuningMode", &CParameterMgr::setTuningModeCommmandProcess, 1,
120 "on|off*", "Turn on or off Tuning Mode" },
121 { "getTuningMode", &CParameterMgr::getTuningModeCommmandProcess, 0,
122 "", "Show Tuning Mode" },
123
Patrick Benavoli68a91282011-08-31 11:23:23 +0200124 /// Value Space
Kevin Rocard3949b342013-05-24 18:43:53 +0200125 { "setValueSpace", &CParameterMgr::setValueSpaceCommmandProcess, 1,
126 "raw|real*", "Assigns Value Space used for parameter value interpretation" },
127 { "getValueSpace", &CParameterMgr::getValueSpaceCommmandProcess, 0,
128 "", "Show Value Space" },
129
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200130 /// Output Raw Format
Kevin Rocard3949b342013-05-24 18:43:53 +0200131 { "setOutputRawFormat", &CParameterMgr::setOutputRawFormatCommmandProcess, 1,
132 "dec*|hex", "Assigns format used to output parameter values when in raw Value Space" },
133 { "getOutputRawFormat", &CParameterMgr::getOutputRawFormatCommmandProcess, 0,
134 "", "Show Output Raw Format" },
135
Patrick Benavoli68a91282011-08-31 11:23:23 +0200136 /// Sync
Kevin Rocard3949b342013-05-24 18:43:53 +0200137 { "setAutoSync", &CParameterMgr::setAutoSyncCommmandProcess, 1,
138 "on*|off", "Turn on or off automatic synchronization to hardware while in Tuning Mode" },
139 { "getAutoSync", &CParameterMgr::getAutoSyncCommmandProcess, 0,
140 "", "Show Auto Sync state" },
141 { "sync", &CParameterMgr::syncCommmandProcess, 0,
142 "", "Synchronize current settings to hardware while in Tuning Mode and Auto Sync off" },
143
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200144 /// Criteria
Kevin Rocard3949b342013-05-24 18:43:53 +0200145 { "listCriteria", &CParameterMgr::listCriteriaCommmandProcess, 0,
146 "[csv]", "List selection criteria" },
147
Patrick Benavoli68a91282011-08-31 11:23:23 +0200148 /// Domains
Kevin Rocard3949b342013-05-24 18:43:53 +0200149 { "listDomains", &CParameterMgr::listDomainsCommmandProcess, 0,
150 "", "List configurable domains" },
151 { "dumpDomains", &CParameterMgr::dumpDomainsCommmandProcess, 0,
152 "", "Show all domains and configurations, including applicability conditions" },
153 { "createDomain", &CParameterMgr::createDomainCommmandProcess, 1,
154 "<domain>", "Create new configurable domain" },
155 { "deleteDomain", &CParameterMgr::deleteDomainCommmandProcess, 1,
156 "<domain>", "Delete configurable domain" },
157 { "deleteAllDomains", &CParameterMgr::deleteAllDomainsCommmandProcess, 0,
158 "", "Delete all configurable domains" },
159 { "renameDomain", &CParameterMgr::renameDomainCommmandProcess, 2,
160 "<domain> <new name>", "Rename configurable domain" },
161 { "setSequenceAwareness", &CParameterMgr::setSequenceAwarenessCommmandProcess, 1,
162 "<domain> true|false*", "Set configurable domain sequence awareness" },
163 { "getSequenceAwareness", &CParameterMgr::getSequenceAwarenessCommmandProcess, 1,
164 "<domain>", "Get configurable domain sequence awareness" },
165 { "listDomainElements", &CParameterMgr::listDomainElementsCommmandProcess, 1,
166 "<domain>", "List elements associated to configurable domain" },
167 { "addElement", &CParameterMgr::addElementCommmandProcess, 2,
168 "<domain> <elem path>", "Associate element at given path to configurable domain" },
169 { "removeElement", &CParameterMgr::removeElementCommmandProcess, 2,
170 "<domain> <elem path>", "Dissociate element at given path from configurable domain" },
171 { "splitDomain", &CParameterMgr::splitDomainCommmandProcess, 2,
172 "<domain> <elem path>", "Split configurable domain at given associated element path" },
173
Patrick Benavoli68a91282011-08-31 11:23:23 +0200174 /// Configurations
Kevin Rocard3949b342013-05-24 18:43:53 +0200175 { "listConfigurations", &CParameterMgr::listConfigurationsCommmandProcess, 1,
176 "<domain>", "List domain configurations" },
177 { "createConfiguration", &CParameterMgr::createConfigurationCommmandProcess, 2,
178 "<domain> <configuration>", "Create new domain configuration" },
179 { "deleteConfiguration", &CParameterMgr::deleteConfigurationCommmandProcess, 2,
180 "<domain> <configuration>", "Delete domain configuration" },
181 { "renameConfiguration", &CParameterMgr::renameConfigurationCommmandProcess, 3,
182 "<domain> <configuration> <new name>", "Rename domain configuration" },
183 { "saveConfiguration", &CParameterMgr::saveConfigurationCommmandProcess, 2,
184 "<domain> <configuration>", "Save current settings into configuration" },
185 { "restoreConfiguration", &CParameterMgr::restoreConfigurationCommmandProcess, 2,
186 "<domain> <configuration>", "Restore current settings from configuration" },
187 { "setElementSequence", &CParameterMgr::setElementSequenceCommmandProcess, 3,
188 "<domain> <configuration> <elem path list>",
189 "Set element application order for configuration" },
190 { "getElementSequence", &CParameterMgr::getElementSequenceCommmandProcess, 2,
191 "<domain> <configuration>", "Get element application order for configuration" },
192 { "setRule", &CParameterMgr::setRuleCommmandProcess, 3,
193 "<domain> <configuration> <rule>", "Set configuration application rule" },
194 { "clearRule", &CParameterMgr::clearRuleCommmandProcess, 2,
195 "<domain> <configuration>", "Clear configuration application rule" },
196 { "getRule", &CParameterMgr::getRuleCommmandProcess, 2,
197 "<domain> <configuration>", "Get configuration application rule" },
198
Patrick Benavoli68a91282011-08-31 11:23:23 +0200199 /// Elements/Parameters
Kevin Rocard3949b342013-05-24 18:43:53 +0200200 { "listElements", &CParameterMgr::listElementsCommmandProcess, 1,
201 "<elem path>|/", "List elements under element at given path or root" },
202 { "listParameters", &CParameterMgr::listParametersCommmandProcess, 1,
203 "<elem path>|/", "List parameters under element at given path or root" },
204 { "dumpElement", &CParameterMgr::dumpElementCommmandProcess, 1,
205 "<elem path>", "Dump structure and content of element at given path" },
206 { "getElementSize", &CParameterMgr::getElementSizeCommmandProcess, 1,
207 "<elem path>", "Show size of element at given path" },
208 { "showProperties", &CParameterMgr::showPropertiesCommmandProcess, 1,
209 "<elem path>", "Show properties of element at given path" },
210 { "getParameter", &CParameterMgr::getParameterCommmandProcess, 1,
211 "<param path>", "Get value for parameter at given path" },
212 { "setParameter", &CParameterMgr::setParameterCommmandProcess, 2,
213 "<param path> <value>", "Set value for parameter at given path" },
214 { "listBelongingDomains", &CParameterMgr::listBelongingDomainsCommmandProcess, 1,
215 "<elem path>", "List domain(s) element at given path belongs to" },
216 { "listAssociatedDomains", &CParameterMgr::listAssociatedDomainsCommmandProcess, 1,
217 "<elem path>", "List domain(s) element at given path is associated to" },
218 { "getConfigurationParameter", &CParameterMgr::getConfigurationParameterCommmandProcess, 3,
219 "<domain> <configuration> <param path>",
220 "Get value for parameter at given path from configuration" },
221 { "setConfigurationParameter", &CParameterMgr::setConfigurationParameterCommmandProcess, 4,
222 "<domain> <configuration> <param path> <value>",
223 "Set value for parameter at given path to configuration" },
224
Patrick Benavoli68a91282011-08-31 11:23:23 +0200225 /// Browse
Kevin Rocard3949b342013-05-24 18:43:53 +0200226 { "listAssociatedElements", &CParameterMgr::listAssociatedElementsCommmandProcess, 0,
227 "", "List element sub-trees associated to at least one configurable domain" },
228 { "listConflictingElements", &CParameterMgr::listConflictingElementsCommmandProcess, 0,
229 "", "List element sub-trees contained in more than one configurable domain" },
230 { "listRogueElements", &CParameterMgr::listRogueElementsCommmandProcess, 0,
231 "", "List element sub-trees owned by no configurable domain" },
232
Patrick Benavoli68a91282011-08-31 11:23:23 +0200233 /// Settings Import/Export
Kevin Rocard3949b342013-05-24 18:43:53 +0200234 { "exportDomainsXML", &CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess, 1,
235 "<file path> ", "Export domains to XML file" },
236 { "importDomainsXML", &CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess, 1,
237 "<file path>", "Import domains from XML file" },
238 { "exportDomainsWithSettingsXML",
239 &CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess, 1,
240 "<file path> ", "Export domains including settings to XML file" },
241 { "importDomainsWithSettingsXML",
242 &CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess, 1,
243 "<file path>", "Import domains including settings from XML file" },
244 { "exportSettings", &CParameterMgr::exportSettingsCommmandProcess, 1,
245 "<file path>", "Export settings to binary file" },
246 { "importSettings", &CParameterMgr::importSettingsCommmandProcess, 1,
247 "<file path>", "Import settings from binary file" },
Georges-Henri Baroncec86c12012-09-04 17:30:28 +0200248 { "getDomainsWithSettingsXML",
249 &CParameterMgr::getConfigurableDomainsWithSettingsXMLCommmandProcess, 0,
Kevin Rocard3949b342013-05-24 18:43:53 +0200250 "", "Print domains including settings as XML" },
Georges-Henri Baroncec86c12012-09-04 17:30:28 +0200251 { "setDomainsWithSettingsXML",
252 &CParameterMgr::setConfigurableDomainsWithSettingsXMLCommmandProcess, 1,
253 "<xml configurable domains>", "Import domains including settings from XML string" },
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200254 /// Structure Export
Kevin Rocard3949b342013-05-24 18:43:53 +0200255 { "getSystemClassXML", &CParameterMgr::getSystemClassXMLCommmandProcess, 0 ,
Kevin Rocardc0211572013-06-18 11:34:53 +0200256 "", "Print parameter structure as XML" },
257 /// Deprecated Commands
258 { "getDomainsXML",
259 &CParameterMgr::getConfigurableDomainsWithSettingsXMLCommmandProcess, 0,
260 "", "DEPRECATED COMMAND, please use getDomainsWithSettingsXML" },
Georges-Henri Baroncec86c12012-09-04 17:30:28 +0200261
Patrick Benavoli68a91282011-08-31 11:23:23 +0200262};
Kevin Rocard3949b342013-05-24 18:43:53 +0200263
Patrick Benavoli68a91282011-08-31 11:23:23 +0200264// Remote command parsers array Size
Patrick Benavoli592ae562011-09-05 16:53:58 +0200265const uint32_t CParameterMgr::guiNbRemoteCommandParserItems = sizeof(gastRemoteCommandParserItems) / sizeof(gastRemoteCommandParserItems[0]);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200266
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100267CParameterMgr::CParameterMgr(const string& strConfigurationFilePath) :
Patrick Benavoli68a91282011-08-31 11:23:23 +0200268 _bTuningModeIsOn(false),
269 _bValueSpaceIsRaw(false),
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200270 _bOutputRawFormatIsHex(false),
Patrick Benavoli68a91282011-08-31 11:23:23 +0200271 _bAutoSyncOn(true),
272 _pMainParameterBlackboard(new CParameterBlackboard),
273 _pElementLibrarySet(new CElementLibrarySet),
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100274 _strXmlConfigurationFilePath(strConfigurationFilePath),
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100275 _pSubsystemPlugins(NULL),
Patrick Benavoli68a91282011-08-31 11:23:23 +0200276 _uiStructureChecksum(0),
277 _pRemoteProcessorServer(NULL),
278 _uiMaxCommandUsageLength(0),
279 _pLogger(NULL),
280 _uiLogDepth(0)
281{
282 // Tuning Mode Mutex
Patrick Benavoli065264a2011-11-20 15:46:41 +0100283 bzero(&_blackboardMutex, sizeof(_blackboardMutex));
284 pthread_mutex_init(&_blackboardMutex, NULL);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200285
286 // Deal with children
287 addChild(new CParameterFrameworkConfiguration);
288 addChild(new CSelectionCriteria);
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100289 addChild(new CSystemClass);
290 addChild(new CConfigurableDomains);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200291
292 // Feed element library
293 feedElementLibraries();
Patrick Benavoli63499d42011-10-24 18:50:03 +0200294
295 _pCommandHandler = new CCommandHandler(this);
296
297 // Add command parsers
298 uint32_t uiRemoteCommandParserItem;
299
300 for (uiRemoteCommandParserItem = 0; uiRemoteCommandParserItem < guiNbRemoteCommandParserItems; uiRemoteCommandParserItem++) {
301
302 const SRemoteCommandParserItem* pRemoteCommandParserItem = &gastRemoteCommandParserItems[uiRemoteCommandParserItem];
303
304 _pCommandHandler->addCommandParser(pRemoteCommandParserItem->_pcCommandName,
305 pRemoteCommandParserItem->_pfnParser,
306 pRemoteCommandParserItem->_uiMinArgumentCount,
307 pRemoteCommandParserItem->_pcHelp,
308 pRemoteCommandParserItem->_pcDescription);
309 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100310
311 // Configuration file folder
312 uint32_t uiSlashPos = _strXmlConfigurationFilePath.rfind('/', -1);
313
314 assert(uiSlashPos != (uint32_t)-1);
315
316 _strXmlConfigurationFolderPath = _strXmlConfigurationFilePath.substr(0, uiSlashPos);
317
318 // Schema absolute folder location
319 _strSchemaFolderLocation = _strXmlConfigurationFolderPath + "/" + gacSystemSchemasSubFolder;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200320}
321
322CParameterMgr::~CParameterMgr()
323{
324 // Children
325 delete _pRemoteProcessorServer;
Frederic Boisnard31242302012-04-26 17:07:34 +0200326 delete _pCommandHandler;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200327 delete _pMainParameterBlackboard;
328 delete _pElementLibrarySet;
329
330 // Tuning Mode Mutex
Patrick Benavoli065264a2011-11-20 15:46:41 +0100331 pthread_mutex_destroy(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200332}
333
334string CParameterMgr::getKind() const
335{
336 return "ParameterMgr";
337}
338
339// Logging
340void CParameterMgr::setLogger(CParameterMgr::ILogger* pLogger)
341{
342 _pLogger = pLogger;
343}
344
345// Logging
Kevin Rocardace81f82012-12-11 16:19:17 +0100346void CParameterMgr::doLog(bool bIsWarning, const string& strLog) const
Patrick Benavoli68a91282011-08-31 11:23:23 +0200347{
348 if (_pLogger) {
349
350 // Nest
351 string strIndent;
352
353 // Level
354 uint32_t uiNbIndents = _uiLogDepth;
355
356 while (uiNbIndents--) {
357
358 strIndent += " ";
359 }
360
361 // Log
Kevin Rocardace81f82012-12-11 16:19:17 +0100362 _pLogger->log(bIsWarning, strIndent + strLog);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200363 }
364}
365
366void CParameterMgr::nestLog() const
367{
Patrick Benavoli592ae562011-09-05 16:53:58 +0200368 _uiLogDepth++;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200369}
370
371void CParameterMgr::unnestLog() const
372{
Patrick Benavoli592ae562011-09-05 16:53:58 +0200373 _uiLogDepth--;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200374}
375
Patrick Benavoli63499d42011-10-24 18:50:03 +0200376// Version
377string CParameterMgr::getVersion() const
378{
379 string strVersion;
380
381 // Major
382 strVersion = toString(guiEditionMajor) + ".";
383 // Minor
384 strVersion += toString(guiEditionMinor) + ".";
385 // Revision
386 strVersion += toString(guiRevision);
387
388 return strVersion;
389}
390
Patrick Benavoli68a91282011-08-31 11:23:23 +0200391bool CParameterMgr::load(string& strError)
392{
393 CAutoLog autoLog(this, "Loading");
394
395 // Load Framework configuration
396 if (!loadFrameworkConfiguration(strError)) {
397
398 return false;
399 }
400
401 // Load subsystems
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100402 if (!getSystemClass()->loadSubsystems(strError, _pSubsystemPlugins)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200403
404 return false;
405 }
406
407 // Load structure
408 if (!loadStructure(strError)) {
409
410 return false;
411 }
412
413 // Load settings
414 if (!loadSettings(strError)) {
415
416 return false;
417 }
418
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200419 // Back synchronization for areas in parameter blackboard not covered by any domain
Kevin Rocardace81f82012-12-11 16:19:17 +0100420 CBackSynchronizer* pBackSynchronizer = createBackSynchronizer();
Patrick Benavoli68a91282011-08-31 11:23:23 +0200421
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200422 // Back-synchronize
Kevin Rocard57096bd2012-11-30 11:24:20 +0100423 {
424 CAutoLog autoLog(this, "Main blackboard back synchronization");
425
Kevin Rocard5d6e05a2013-01-21 15:57:45 +0100426 pBackSynchronizer->sync();
Kevin Rocard57096bd2012-11-30 11:24:20 +0100427
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200428 // Get rid of back synchronizer
429 delete pBackSynchronizer;
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200430 }
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200431
432 // We're done loading the settings and back synchronizing
433 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
434
435 // We need to ensure all domains are valid
436 pConfigurableDomains->validate(_pMainParameterBlackboard);
437
Kevin Rocard7f265822012-12-07 18:51:22 +0100438 // Log selection criterion states
439 {
440 CAutoLog autoLog(this, "Criterion states");
441
442 const CSelectionCriteria* selectionCriteria = getConstSelectionCriteria();
443
444 list<string> lstrSelectionCriteron;
445 selectionCriteria->listSelectionCriteria(lstrSelectionCriteron, true, false);
446
Kevin Rocard36299362013-02-04 14:57:47 +0100447 log_table(false, lstrSelectionCriteron);
Kevin Rocard7f265822012-12-07 18:51:22 +0100448 }
449
Kevin Rocard2fbe6e82013-03-26 17:09:29 +0100450 // Subsystem can not ask for resync as they have not been synced yet
451 getSystemClass()->cleanSubsystemsNeedToResync();
452
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100453 // At initialization, check subsystems that need resync
454 doApplyConfigurations(true);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200455
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200456 // Start remote processor server if appropriate
457 return handleRemoteProcessingInterface(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200458}
459
460bool CParameterMgr::loadFrameworkConfiguration(string& strError)
461{
462 CAutoLog autoLog(this, "Loading framework configuration");
463
Patrick Benavoli68a91282011-08-31 11:23:23 +0200464 // Parse Structure XML file
465 CXmlElementSerializingContext elementSerializingContext(strError);
466
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100467 if (!xmlParse(elementSerializingContext, getFrameworkConfiguration(), _strXmlConfigurationFilePath, _strXmlConfigurationFolderPath, EFrameworkConfigurationLibrary)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200468
469 return false;
470 }
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100471 // Set class name to system class and configurable domains
472 getSystemClass()->setName(getConstFrameworkConfiguration()->getSystemClassName());
473 getConfigurableDomains()->setName(getConstFrameworkConfiguration()->getSystemClassName());
474
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100475 // Get subsystem plugins elements
476 _pSubsystemPlugins = static_cast<const CSubsystemPlugins*>(getConstFrameworkConfiguration()->findChild("SubsystemPlugins"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200477
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100478 if (!_pSubsystemPlugins) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200479
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +0100480 strError = "Parameter Framework Configuration: couldn't find SubsystemPlugins element";
Patrick Benavoli68a91282011-08-31 11:23:23 +0200481
482 return false;
483 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200484
Patrick Benavoli68a91282011-08-31 11:23:23 +0200485 // Log tuning availability
Kevin Rocardace81f82012-12-11 16:19:17 +0100486 log_info("Tuning %s", getConstFrameworkConfiguration()->isTuningAllowed() ? "allowed" : "prohibited");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200487
488 return true;
489}
490
491bool CParameterMgr::loadStructure(string& strError)
492{
493 // Retrieve system to load structure to
494 CSystemClass* pSystemClass = getSystemClass();
495
Kevin Rocarde25ee792013-04-22 17:46:28 +0200496 log_info("Loading " + pSystemClass->getName() + " system class structure");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200497
498 // Get structure description element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100499 const CFrameworkConfigurationLocation* pStructureDescriptionFileLocation = static_cast<const CFrameworkConfigurationLocation*>(getConstFrameworkConfiguration()->findChildOfKind("StructureDescriptionFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200500
501 if (!pStructureDescriptionFileLocation) {
502
503 strError = "No StructureDescriptionFileLocation element found for SystemClass " + pSystemClass->getName();
504
505 return false;
506 }
507
508 // Get Xml structure folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100509 string strXmlStructureFolder = pStructureDescriptionFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200510
511 // Get Xml structure file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100512 string strXmlStructureFilePath = pStructureDescriptionFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200513
514 // Parse Structure XML file
515 CXmlParameterSerializingContext parameterBuildContext(strError);
516
Kevin Rocard57096bd2012-11-30 11:24:20 +0100517 CAutoLog autolog(pSystemClass, "Importing system structure from file " + strXmlStructureFilePath);
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200518
Patrick Benavoli68a91282011-08-31 11:23:23 +0200519 if (!xmlParse(parameterBuildContext, pSystemClass, strXmlStructureFilePath, strXmlStructureFolder, EParameterCreationLibrary)) {
520
521 return false;
522 }
523
524 // Initialize offsets
525 pSystemClass->setOffset(0);
526
527 // Initialize main blackboard's size
528 _pMainParameterBlackboard->setSize(pSystemClass->getFootPrint());
529
530 return true;
531}
532
533bool CParameterMgr::loadSettings(string& strError)
534{
535 CAutoLog autoLog(this, "Loading settings");
536
537 // Get settings configuration element
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100538 const CFrameworkConfigurationGroup* pParameterConfigurationGroup = static_cast<const CFrameworkConfigurationGroup*>(getConstFrameworkConfiguration()->findChildOfKind("SettingsConfiguration"));
Patrick Benavoli68a91282011-08-31 11:23:23 +0200539
540 if (!pParameterConfigurationGroup) {
541
542 // No settings to load
543
544 return true;
545 }
546 // Get binary settings file location
547 const CFrameworkConfigurationLocation* pBinarySettingsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("BinarySettingsFileLocation"));
548
549 string strXmlBinarySettingsFilePath;
550
551 if (pBinarySettingsFileLocation) {
552
553 // Get Xml binary settings file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100554 strXmlBinarySettingsFilePath = pBinarySettingsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200555 }
556
557 // Get configurable domains element
558 const CFrameworkConfigurationLocation* pConfigurableDomainsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("ConfigurableDomainsFileLocation"));
559
560 if (!pConfigurableDomainsFileLocation) {
561
562 strError = "No ConfigurableDomainsFileLocation element found for SystemClass " + getSystemClass()->getName();
563
564 return false;
565 }
566 // Get destination root element
567 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
568
569 // Get Xml configuration domains file name
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100570 string strXmlConfigurationDomainsFilePath = pConfigurableDomainsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200571
572 // Get Xml configuration domains folder
Patrick Benavoli95ac0342011-11-07 20:32:51 +0100573 string strXmlConfigurationDomainsFolder = pConfigurableDomainsFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200574
575 // Parse configuration domains XML file (ask to read settings from XML file if they are not provided as binary)
576 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, !pBinarySettingsFileLocation);
577
578 // Selection criteria definition for rule creation
579 xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
580
Patrick Benavoli63499d42011-10-24 18:50:03 +0200581 // Auto validation of configurations if no binary settings provided
582 xmlDomainSerializingContext.setAutoValidationRequired(!pBinarySettingsFileLocation);
583
Kevin Rocardace81f82012-12-11 16:19:17 +0100584 log_info("Importing configurable domains from file %s %s settings", strXmlConfigurationDomainsFilePath.c_str(), pBinarySettingsFileLocation ? "without" : "with");
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200585
Patrick Benavoli68a91282011-08-31 11:23:23 +0200586 // Do parse
587 if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strXmlConfigurationDomainsFilePath, strXmlConfigurationDomainsFolder, EParameterConfigurationLibrary, "SystemClassName")) {
588
589 return false;
590 }
591 // We have loaded the whole system structure, compute checksum
592 const CSystemClass* pSystemClass = getConstSystemClass();
593 _uiStructureChecksum = pSystemClass->computeStructureChecksum() + getConfigurableDomains()->computeStructureChecksum() + getSelectionCriteria()->computeStructureChecksum();
594
595 // Load binary settings if any provided
596 if (pBinarySettingsFileLocation && !pConfigurableDomains->serializeSettings(strXmlBinarySettingsFilePath, false, _uiStructureChecksum, strError)) {
597
598 return false;
599 }
600
Patrick Benavoli1387bda2011-08-31 11:23:24 +0200601 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200602}
603
604// XML parsing
605bool CParameterMgr::xmlParse(CXmlElementSerializingContext& elementSerializingContext, CElement* pRootElement, const string& strXmlFilePath, const string& strXmlFolder, CParameterMgr::ElementLibrary eElementLibrary, const string& strNameAttrituteName)
606{
607 // Init serializing context
608 elementSerializingContext.set(_pElementLibrarySet->getElementLibrary(eElementLibrary), strXmlFolder, _strSchemaFolderLocation);
609
610 // Get Schema file associated to root element
611 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pRootElement->getKind() + ".xsd";
612
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200613 CXmlFileDocSource fileDocSource(strXmlFilePath, strXmlSchemaFilePath, pRootElement->getKind(), pRootElement->getName(), strNameAttrituteName);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200614
615 // Start clean
616 pRootElement->clean();
617
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200618 CXmlMemoryDocSink memorySink(pRootElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200619
Georges-Henri Baron326a31d2012-06-28 12:05:09 +0200620 if (!memorySink.process(fileDocSource, elementSerializingContext)) {
621 //Cleanup
Patrick Benavoli68a91282011-08-31 11:23:23 +0200622 pRootElement->clean();
623
624 return false;
625 }
626
Patrick Benavoli68a91282011-08-31 11:23:23 +0200627 return true;
628}
629
630// Init
631bool CParameterMgr::init(string& strError)
632{
633 return base::init(strError);
634}
635
636// Selection criteria interface
637CSelectionCriterionType* CParameterMgr::createSelectionCriterionType(bool bIsInclusive)
638{
639 // Propagate
640 return getSelectionCriteria()->createSelectionCriterionType(bIsInclusive);
641}
642
643CSelectionCriterion* CParameterMgr::createSelectionCriterion(const string& strName, const CSelectionCriterionType* pSelectionCriterionType)
644{
645 // Propagate
646 return getSelectionCriteria()->createSelectionCriterion(strName, pSelectionCriterionType);
647}
648
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200649// Selection criterion retrieval
650CSelectionCriterion* CParameterMgr::getSelectionCriterion(const string& strName)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200651{
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200652 // Propagate
653 return getSelectionCriteria()->getSelectionCriterion(strName);
654}
655
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100656// Configuration application
Kevin Rocardace81f82012-12-11 16:19:17 +0100657void CParameterMgr::applyConfigurations()
Patrick Benavolib71ccf72011-09-13 14:15:52 +0200658{
659 CAutoLog autoLog(this, "Configuration application request");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200660
661 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +0100662 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200663
664 if (!_bTuningModeIsOn) {
665
666 // Apply configuration(s)
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100667 doApplyConfigurations(false);
Frédéric Boisnarddaaa63c2012-08-27 15:48:15 +0200668 } else {
669
Kevin Rocardace81f82012-12-11 16:19:17 +0100670 log_warning("Configurations were not applied because the TuningMode is on");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200671 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200672}
673
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200674// Dynamic parameter handling
Patrick Benavoli065264a2011-11-20 15:46:41 +0100675CParameterHandle* CParameterMgr::createParameterHandle(const string& strPath, string& strError)
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200676{
Patrick Benavoli065264a2011-11-20 15:46:41 +0100677 CPathNavigator pathNavigator(strPath);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200678
Patrick Benavoli065264a2011-11-20 15:46:41 +0100679 // Nagivate through system class
680 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
681
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100682 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100683 }
684
685 // Find element
686 const CElement* pElement = getConstSystemClass()->findDescendant(pathNavigator);
687
688 if (!pElement) {
689
690 strError = "Path not found";
691
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100692 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100693 }
694
695 // Check found element is a parameter
696 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pElement);
697
698 if (!pConfigurableElement->isParameter()) {
699
700 // Element is not parameter
701 strError = "Not a parameter";
702
Patrick Benavoli79f16cc2011-11-25 22:36:41 +0100703 return NULL;
Patrick Benavoli065264a2011-11-20 15:46:41 +0100704 }
705
706 // Convert as parameter and return new handle
707 return new CParameterHandle(static_cast<const CBaseParameter*>(pElement), this);
Patrick Benavoli4bed9212011-10-27 14:18:00 +0200708}
709
Patrick Benavoli68a91282011-08-31 11:23:23 +0200710/////////////////// Remote command parsers
Patrick Benavoli592ae562011-09-05 16:53:58 +0200711/// Version
Patrick Benavoli63499d42011-10-24 18:50:03 +0200712CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::versionCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli592ae562011-09-05 16:53:58 +0200713{
714 (void)remoteCommand;
715
Patrick Benavoli63499d42011-10-24 18:50:03 +0200716 // Show version
717 strResult = getVersion();
Patrick Benavoli592ae562011-09-05 16:53:58 +0200718
Patrick Benavoli63499d42011-10-24 18:50:03 +0200719 return CCommandHandler::ESucceeded;
Patrick Benavoli592ae562011-09-05 16:53:58 +0200720}
721
Patrick Benavoli68a91282011-08-31 11:23:23 +0200722/// Status
Patrick Benavoli63499d42011-10-24 18:50:03 +0200723CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::statusCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200724{
725 (void)remoteCommand;
726 // System class
727 const CSystemClass* pSystemClass = getSystemClass();
728
Patrick Benavoli68a91282011-08-31 11:23:23 +0200729 // Show status
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200730 /// General section
731 appendTitle(strResult, "General:");
732 // System class
Patrick Benavoli68a91282011-08-31 11:23:23 +0200733 strResult += "System Class: ";
734 strResult += pSystemClass->getName();
735 strResult += "\n";
736
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200737 // Tuning mode
Patrick Benavoli68a91282011-08-31 11:23:23 +0200738 strResult += "Tuning Mode: ";
739 strResult += tuningModeOn() ? "on" : "off";
740 strResult += "\n";
741
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200742 // Value space
Patrick Benavoli68a91282011-08-31 11:23:23 +0200743 strResult += "Value Space: ";
744 strResult += valueSpaceIsRaw() ? "raw" : "real";
745 strResult += "\n";
746
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200747 // Output raw format
748 strResult += "Output Raw Format: ";
749 strResult += outputRawFormatIsHex() ? "hex" : "dec";
750 strResult += "\n";
751
752 // Auto Sync
Patrick Benavoli68a91282011-08-31 11:23:23 +0200753 strResult += "Auto Sync: ";
754 strResult += autoSyncOn() ? "on" : "off";
755 strResult += "\n";
756
757 /// Subsystem list
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200758 appendTitle(strResult, "Subsystems:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200759 string strSubsystemList;
760 pSystemClass->listChildrenPaths(strSubsystemList);
761 strResult += strSubsystemList;
762
763 /// Last applied configurations
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200764 appendTitle(strResult, "Last Applied [Pending] Configurations:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200765 string strLastAppliedConfigurations;
766 getConfigurableDomains()->listLastAppliedConfigurations(strLastAppliedConfigurations);
767 strResult += strLastAppliedConfigurations;
768
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200769 /// Criteria states
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200770 appendTitle(strResult, "Selection Criteria:");
Kevin Rocard7f265822012-12-07 18:51:22 +0100771 list<string> lstrSelectionCriteria;
772 getSelectionCriteria()->listSelectionCriteria(lstrSelectionCriteria, false, true);
773 // Concatenate the criterion list as the command result
Frederic Boisnard390b36d2013-05-23 15:28:31 +0200774 string strCriteriaStates;
775 CUtility::asString(lstrSelectionCriteria, strCriteriaStates);
776 strResult += strCriteriaStates;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200777
Patrick Benavoli63499d42011-10-24 18:50:03 +0200778 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200779}
780
781/// Tuning Mode
Patrick Benavoli63499d42011-10-24 18:50:03 +0200782CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200783{
784 if (remoteCommand.getArgument(0) == "on") {
785
786 if (setTuningMode(true, strResult)) {
787
Patrick Benavoli63499d42011-10-24 18:50:03 +0200788 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200789 }
790 } else if (remoteCommand.getArgument(0) == "off") {
791
792 if (setTuningMode(false, strResult)) {
793
Patrick Benavoli63499d42011-10-24 18:50:03 +0200794 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200795 }
796 } else {
797 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200798 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200799 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200800 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200801}
802
Patrick Benavoli63499d42011-10-24 18:50:03 +0200803CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200804{
805 (void)remoteCommand;
806
807 strResult = tuningModeOn() ? "on" : "off";
808
Patrick Benavoli63499d42011-10-24 18:50:03 +0200809 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200810}
811
812/// Value Space
Patrick Benavoli63499d42011-10-24 18:50:03 +0200813CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200814{
815 (void)strResult;
816
817 if (remoteCommand.getArgument(0) == "raw") {
818
819 setValueSpace(true);
820
Patrick Benavoli63499d42011-10-24 18:50:03 +0200821 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200822
823 } else if (remoteCommand.getArgument(0) == "real") {
824
825 setValueSpace(false);
826
Patrick Benavoli63499d42011-10-24 18:50:03 +0200827 return CCommandHandler::EDone;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200828
829 } else {
830 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200831 return CCommandHandler::EShowUsage;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200832 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200833 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200834}
835
Patrick Benavoli63499d42011-10-24 18:50:03 +0200836CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200837{
838 (void)remoteCommand;
839
840 strResult = valueSpaceIsRaw() ? "raw" : "real";
841
Patrick Benavoli63499d42011-10-24 18:50:03 +0200842 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200843}
844
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200845/// Output Raw Format
Patrick Benavoli63499d42011-10-24 18:50:03 +0200846CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200847{
848 (void)strResult;
849
850 if (remoteCommand.getArgument(0) == "hex") {
851
852 setOutputRawFormat(true);
853
Patrick Benavoli63499d42011-10-24 18:50:03 +0200854 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200855
856 } else if (remoteCommand.getArgument(0) == "dec") {
857
858 setOutputRawFormat(false);
859
Patrick Benavoli63499d42011-10-24 18:50:03 +0200860 return CCommandHandler::EDone;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200861
862 } else {
863 // Show usage
Patrick Benavoli63499d42011-10-24 18:50:03 +0200864 return CCommandHandler::EShowUsage;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200865 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200866 return CCommandHandler::EFailed;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200867}
868
Patrick Benavoli63499d42011-10-24 18:50:03 +0200869CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200870{
871 (void)remoteCommand;
872
873 strResult = outputRawFormatIsHex() ? "hex" : "dec";
874
Patrick Benavoli63499d42011-10-24 18:50:03 +0200875 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200876}
877
Patrick Benavoli68a91282011-08-31 11:23:23 +0200878/// Sync
Patrick Benavoli63499d42011-10-24 18:50:03 +0200879CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200880{
881 if (remoteCommand.getArgument(0) == "on") {
882
883 if (setAutoSync(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 (setAutoSync(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::getAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200901{
902 (void)remoteCommand;
903
904 strResult = autoSyncOn() ? "on" : "off";
905
Patrick Benavoli63499d42011-10-24 18:50:03 +0200906 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200907}
908
Patrick Benavoli63499d42011-10-24 18:50:03 +0200909CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::syncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200910{
911 (void)remoteCommand;
912
Patrick Benavoli63499d42011-10-24 18:50:03 +0200913 return sync(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200914}
915
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200916/// Criteria
Patrick Benavoli63499d42011-10-24 18:50:03 +0200917CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listCriteriaCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200918{
919 (void)remoteCommand;
920
Kevin Rocard4eae8272013-04-18 19:12:46 +0200921 bool humanReadable = true;
Kevin Rocard7f265822012-12-07 18:51:22 +0100922
Kevin Rocard4eae8272013-04-18 19:12:46 +0200923 // Look for optional arguments
924 if (remoteCommand.getArgumentCount() >= 1) {
925
926 // If csv is provided, format the criterion list in Commas Separated Value pairs
927 if (remoteCommand.getArgument(0) == "csv") {
928 humanReadable = false;
929 } else {
930 return CCommandHandler::EShowUsage;
931 }
932 }
933
934 list<string> lstrResult;
935 getSelectionCriteria()->listSelectionCriteria(lstrResult, true, humanReadable);
Kevin Rocard7f265822012-12-07 18:51:22 +0100936
937 // Concatenate the criterion list as the command result
Frederic Boisnard390b36d2013-05-23 15:28:31 +0200938 CUtility::asString(lstrResult, strResult);
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200939
Patrick Benavoli63499d42011-10-24 18:50:03 +0200940 return CCommandHandler::ESucceeded;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200941}
Patrick Benavoli68a91282011-08-31 11:23:23 +0200942
943/// Domains
Patrick Benavoli63499d42011-10-24 18:50:03 +0200944CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200945{
946 (void)remoteCommand;
947
Patrick Benavoli63499d42011-10-24 18:50:03 +0200948 getConfigurableDomains()->listDomains(strResult);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200949
Patrick Benavoli63499d42011-10-24 18:50:03 +0200950 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200951}
952
Patrick Benavoli63499d42011-10-24 18:50:03 +0200953CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200954{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200955 return createDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200956}
957
Patrick Benavoli63499d42011-10-24 18:50:03 +0200958CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200959{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200960 return deleteDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200961}
962
Kevin Rocard170f0a42012-06-18 13:56:05 +0200963CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteAllDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
964{
965 (void)remoteCommand;
966
967 return deleteAllDomains(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
968}
969
Patrick Benavoli63499d42011-10-24 18:50:03 +0200970CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200971{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200972 return getConfigurableDomains()->renameDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200973}
974
Patrick Benavoli63499d42011-10-24 18:50:03 +0200975CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200976{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200977 // Check tuning mode
978 if (!checkTuningModeOn(strResult)) {
979
980 return CCommandHandler::EFailed;
981 }
982
983 // Set property
984 bool bSequenceAware;
985
986 if (remoteCommand.getArgument(1) == "true") {
987
988 bSequenceAware = true;
989
990 } else if (remoteCommand.getArgument(1) == "false") {
991
992 bSequenceAware = false;
993
994 } else {
995 // Show usage
996 return CCommandHandler::EShowUsage;
997 }
998
999 return getConfigurableDomains()->setSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001000}
1001
Patrick Benavoli63499d42011-10-24 18:50:03 +02001002CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001003{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001004 // Get property
1005 bool bSequenceAware;
1006
1007 if (!getConfigurableDomains()->getSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult)) {
1008
1009 return CCommandHandler::EFailed;
1010 }
1011
1012 strResult = bSequenceAware ? "true" : "false";
1013
1014 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001015}
1016
Patrick Benavoli63499d42011-10-24 18:50:03 +02001017CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001018{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001019 return getConfigurableDomains()->listDomainElements(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001020}
1021
Patrick Benavoli63499d42011-10-24 18:50:03 +02001022CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::addElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001023{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001024 return addConfigurableElementToDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1025}
1026
1027CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::removeElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1028{
1029 return removeConfigurableElementFromDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1030}
1031
1032CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::splitDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1033{
1034 return split(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001035}
1036
1037/// Configurations
Patrick Benavoli63499d42011-10-24 18:50:03 +02001038CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConfigurationsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001039{
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001040 return getConstConfigurableDomains()->listConfigurations(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
1041}
1042
1043CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1044{
1045 (void)remoteCommand;
1046
1047 // Dummy error context
1048 string strError;
1049 CErrorContext errorContext(strError);
1050
1051 // Dump
1052 getConstConfigurableDomains()->dumpContent(strResult, errorContext);
1053
1054 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001055}
1056
Patrick Benavoli63499d42011-10-24 18:50:03 +02001057CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001058{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001059 return createConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001060}
1061
Patrick Benavoli63499d42011-10-24 18:50:03 +02001062CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001063{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001064 return deleteConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001065}
1066
Patrick Benavoli63499d42011-10-24 18:50:03 +02001067CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001068{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001069 return getConfigurableDomains()->renameConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), 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::saveConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001073{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001074 return saveConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001075}
1076
Patrick Benavoli63499d42011-10-24 18:50:03 +02001077CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::restoreConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001078{
Kevin Rocardace81f82012-12-11 16:19:17 +01001079 list<string> lstrResult;
1080 if (!restoreConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), lstrResult)) {
1081 //Concatenate the error list as the command result
Frederic Boisnard390b36d2013-05-23 15:28:31 +02001082 CUtility::asString(lstrResult, strResult);
Kevin Rocardace81f82012-12-11 16:19:17 +01001083
1084 return CCommandHandler::EFailed;
1085 }
1086 return CCommandHandler::EDone;
Patrick Benavoli63499d42011-10-24 18:50:03 +02001087}
1088
1089CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1090{
1091 // Check tuning mode
1092 if (!checkTuningModeOn(strResult)) {
1093
1094 return CCommandHandler::EFailed;
1095 }
1096
1097 // Build configurable element path list
1098 vector<string> astrNewElementSequence;
1099
1100 uint32_t uiArgument;
1101
1102 for (uiArgument = 2; uiArgument < remoteCommand.getArgumentCount(); uiArgument++) {
1103
1104 astrNewElementSequence.push_back(remoteCommand.getArgument(uiArgument));
1105 }
1106
1107 // Delegate to configurable domains
1108 return getConfigurableDomains()->setElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), astrNewElementSequence, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1109}
1110
1111CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1112{
1113 // Delegate to configurable domains
1114 return getConfigurableDomains()->getElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001115}
1116
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001117CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1118{
1119 // Delegate to configurable domains
1120 return getConfigurableDomains()->setApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.packArguments(2, remoteCommand.getArgumentCount() - 2), getConstSelectionCriteria()->getSelectionCriteriaDefinition(), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1121}
1122
1123CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::clearRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1124{
1125 // Delegate to configurable domains
1126 return getConfigurableDomains()->clearApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1127}
1128
1129CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1130{
1131 // Delegate to configurable domains
1132 return getConfigurableDomains()->getApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
1133}
1134
Patrick Benavoli68a91282011-08-31 11:23:23 +02001135/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001136CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001137{
1138 CElementLocator elementLocator(getSystemClass(), false);
1139
1140 CElement* pLocatedElement = NULL;
1141
1142 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1143
Patrick Benavoli63499d42011-10-24 18:50:03 +02001144 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001145 }
1146
1147 strResult = string("\n");
1148
1149 if (!pLocatedElement) {
1150
1151 // List from root folder
1152
1153 // Return system class qualified name
1154 pLocatedElement = getSystemClass();
1155 }
1156
1157 // Return sub-elements
1158 strResult += pLocatedElement->listQualifiedPaths(false);
1159
Patrick Benavoli63499d42011-10-24 18:50:03 +02001160 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001161}
1162
1163/// Elements/Parameters
Patrick Benavoli63499d42011-10-24 18:50:03 +02001164CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listParametersCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001165{
1166 CElementLocator elementLocator(getSystemClass(), false);
1167
1168 CElement* pLocatedElement = NULL;
1169
1170 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1171
Patrick Benavoli63499d42011-10-24 18:50:03 +02001172 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001173 }
1174
1175 strResult = string("\n");
1176
1177 if (!pLocatedElement) {
1178
1179 // List from root folder
1180
1181 // Return system class qualified name
1182 pLocatedElement = getSystemClass();
1183 }
1184
1185 // Return sub-elements
1186 strResult += pLocatedElement->listQualifiedPaths(true);
1187
Patrick Benavoli63499d42011-10-24 18:50:03 +02001188 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001189}
1190
Patrick Benavoli63499d42011-10-24 18:50:03 +02001191CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001192{
1193 CElementLocator elementLocator(getSystemClass());
1194
1195 CElement* pLocatedElement = NULL;
1196
1197 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1198
Patrick Benavoli63499d42011-10-24 18:50:03 +02001199 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001200 }
1201
1202 string strError;
1203
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001204 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001205
1206 // Dump elements
1207 pLocatedElement->dumpContent(strResult, parameterAccessContext);
1208
Patrick Benavoli63499d42011-10-24 18:50:03 +02001209 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001210}
1211
Patrick Benavoli63499d42011-10-24 18:50:03 +02001212CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSizeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001213{
1214 CElementLocator elementLocator(getSystemClass());
1215
1216 CElement* pLocatedElement = NULL;
1217
1218 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1219
Patrick Benavoli63499d42011-10-24 18:50:03 +02001220 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001221 }
1222
1223 // Converted to actual sizable element
1224 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1225
1226 // Get size as string
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001227 strResult = pConfigurableElement->getFootprintAsString();
Patrick Benavoli68a91282011-08-31 11:23:23 +02001228
Patrick Benavoli63499d42011-10-24 18:50:03 +02001229 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001230}
1231
Patrick Benavoli63499d42011-10-24 18:50:03 +02001232CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showPropertiesCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001233{
1234 CElementLocator elementLocator(getSystemClass());
1235
1236 CElement* pLocatedElement = NULL;
1237
1238 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1239
Patrick Benavoli63499d42011-10-24 18:50:03 +02001240 return CCommandHandler::EFailed;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001241 }
1242
1243 // Convert element
1244 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1245
1246 // Return element properties
1247 pConfigurableElement->showProperties(strResult);
1248
Patrick Benavoli63499d42011-10-24 18:50:03 +02001249 return CCommandHandler::ESucceeded;
Patrick Benavoli2ecf9002011-08-31 11:23:24 +02001250}
1251
Patrick Benavoli63499d42011-10-24 18:50:03 +02001252CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001253{
1254 string strValue;
1255
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001256 if (!accessParameterValue(remoteCommand.getArgument(0), strValue, false, strResult)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001257
Patrick Benavoli63499d42011-10-24 18:50:03 +02001258 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001259 }
1260 // Succeeded
1261 strResult = strValue;
1262
Patrick Benavoli63499d42011-10-24 18:50:03 +02001263 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001264}
1265
Patrick Benavoli63499d42011-10-24 18:50:03 +02001266CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001267{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001268 // Check tuning mode
1269 if (!checkTuningModeOn(strResult)) {
1270
1271 return CCommandHandler::EFailed;
1272 }
1273 // Get value to set
1274 string strValue = remoteCommand.packArguments(1, remoteCommand.getArgumentCount() - 1);
1275
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001276 return accessParameterValue(remoteCommand.getArgument(0), strValue, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001277}
1278
Patrick Benavoli63499d42011-10-24 18:50:03 +02001279CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listBelongingDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001280{
1281 CElementLocator elementLocator(getSystemClass());
1282
1283 CElement* pLocatedElement = NULL;
1284
1285 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1286
Patrick Benavoli63499d42011-10-24 18:50:03 +02001287 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001288 }
1289
1290 // Convert element
1291 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1292
1293 // Return element belonging domains
1294 pConfigurableElement->listBelongingDomains(strResult);
1295
Patrick Benavoli63499d42011-10-24 18:50:03 +02001296 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001297}
1298
Patrick Benavoli63499d42011-10-24 18:50:03 +02001299CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001300{
1301 CElementLocator elementLocator(getSystemClass());
1302
1303 CElement* pLocatedElement = NULL;
1304
1305 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1306
Patrick Benavoli63499d42011-10-24 18:50:03 +02001307 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001308 }
1309
1310 // Convert element
1311 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1312
1313 // Return element belonging domains
1314 pConfigurableElement->listAssociatedDomains(strResult);
1315
Patrick Benavoli63499d42011-10-24 18:50:03 +02001316 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001317}
1318
Patrick Benavoli63499d42011-10-24 18:50:03 +02001319CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001320{
1321 (void)remoteCommand;
1322
1323 getConfigurableDomains()->listAssociatedElements(strResult);
1324
Patrick Benavoli63499d42011-10-24 18:50:03 +02001325 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001326}
1327
Patrick Benavoli63499d42011-10-24 18:50:03 +02001328CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConflictingElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001329{
1330 (void)remoteCommand;
1331
1332 getConfigurableDomains()->listConflictingElements(strResult);
1333
Patrick Benavoli63499d42011-10-24 18:50:03 +02001334 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001335}
1336
Patrick Benavoli63499d42011-10-24 18:50:03 +02001337CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listRogueElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001338{
1339 (void)remoteCommand;
1340
1341 getSystemClass()->listRogueElements(strResult);
1342
Patrick Benavoli63499d42011-10-24 18:50:03 +02001343 return CCommandHandler::ESucceeded;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001344}
1345
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001346CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getConfigurationParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1347{
1348 string strOutputValue;
1349 string strError;
1350
1351 if (!accessConfigurationValue(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), strOutputValue, false, strError)) {
1352
1353 strResult = strError;
1354 return CCommandHandler::EFailed;
1355 }
1356 // Succeeded
1357 strResult = strOutputValue;
1358
1359 return CCommandHandler::ESucceeded;
1360}
1361
1362CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setConfigurationParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
1363{
1364 // Get value to set
1365 string strValue = remoteCommand.packArguments(3, remoteCommand.getArgumentCount() - 3);
1366
1367 bool bSuccess = accessConfigurationValue(remoteCommand.getArgument(0),
1368 remoteCommand.getArgument(1),
1369 remoteCommand.getArgument(2),
1370 strValue, true, strResult);
1371
1372 return bSuccess ? CCommandHandler::EDone : CCommandHandler::EFailed;
1373}
1374
Patrick Benavoli68a91282011-08-31 11:23:23 +02001375/// Settings Import/Export
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001376CParameterMgr::CCommandHandler::CommandStatus
1377 CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess(
1378 const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001379{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001380 string strFileName = remoteCommand.getArgument(0);
1381 return exportDomainsXml(strFileName, false, true, strResult) ?
1382 CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001383}
1384
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001385CParameterMgr::CCommandHandler::CommandStatus
1386 CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess(
1387 const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001388{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001389 return importDomainsXml(remoteCommand.getArgument(0), false, true, strResult) ?
1390 CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001391}
1392
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001393CParameterMgr::CCommandHandler::CommandStatus
1394 CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess(
1395 const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001396{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001397 string strFileName = remoteCommand.getArgument(0);
1398 return exportDomainsXml(strFileName, true, true, strResult) ?
1399 CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001400}
1401
Patrick Benavoli63499d42011-10-24 18:50:03 +02001402CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001403{
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001404 return importDomainsXml(remoteCommand.getArgument(0), true, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001405}
1406
Patrick Benavoli63499d42011-10-24 18:50:03 +02001407CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001408{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001409 return exportDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001410}
1411
Patrick Benavoli63499d42011-10-24 18:50:03 +02001412CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001413{
Patrick Benavoli63499d42011-10-24 18:50:03 +02001414 return importDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001415}
1416
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001417CParameterMgr::CCommandHandler::CommandStatus
1418 CParameterMgr::getConfigurableDomainsWithSettingsXMLCommmandProcess(
1419 const IRemoteCommand& remoteCommand, string& strResult)
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001420{
1421 (void)remoteCommand;
1422
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001423 if (!exportDomainsXml(strResult, true, false, strResult)) {
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001424
1425 return CCommandHandler::EFailed;
1426 }
1427 // Succeeded
1428 return CCommandHandler::ESucceeded;
1429}
1430
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001431CParameterMgr::CCommandHandler::CommandStatus
1432 CParameterMgr::setConfigurableDomainsWithSettingsXMLCommmandProcess(
1433 const IRemoteCommand& remoteCommand, string& strResult)
1434{
1435 return importDomainsXml(remoteCommand.getArgument(0), true, false, strResult) ?
1436 CCommandHandler::EDone : CCommandHandler::EFailed;
1437}
1438
1439CParameterMgr::CCommandHandler::CommandStatus
1440 CParameterMgr::getSystemClassXMLCommmandProcess(
1441 const IRemoteCommand& remoteCommand, string& strResult)
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001442{
1443 (void)remoteCommand;
1444
1445 if (!getSystemClassXMLString(strResult)) {
1446
1447 return CCommandHandler::EFailed;
1448 }
1449 // Succeeded
1450 return CCommandHandler::ESucceeded;
1451}
1452
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001453// User set/get parameters in main BlackBoard
1454bool CParameterMgr::accessParameterValue(const string& strPath, string& strValue, bool bSet, string& strError)
1455{
1456 // Define context
1457 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
1458
Frédéric Boisnard150407c2013-03-15 14:46:23 +01001459 // Activate the auto synchronization with the hardware
1460 if (bSet) {
1461
1462 parameterAccessContext.setAutoSync(_bAutoSyncOn);
1463 }
1464
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001465 return accessValue(parameterAccessContext, strPath, strValue, bSet, strError);
1466}
1467
1468// User set/get parameters in specific Configuration BlackBoard
1469bool CParameterMgr::accessConfigurationValue(const string& strDomain, const string& strConfiguration, const string& strPath, string& strValue, bool bSet, string& strError)
1470{
1471 CElementLocator elementLocator(getSystemClass());
1472
1473 CElement* pLocatedElement = NULL;
1474
1475 if (!elementLocator.locate(strPath, &pLocatedElement, strError)) {
1476
1477 return false;
1478 }
1479
1480 // Convert element
1481 const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
1482
1483 // Get the Configuration blackboard and the Base Offset of the configurable element in this blackboard
1484 uint32_t uiBaseOffset;
1485 bool bIsLastApplied;
1486
1487 CParameterBlackboard* pConfigurationBlackboard = getConstConfigurableDomains()->findConfigurationBlackboard(strDomain, strConfiguration, pConfigurableElement, uiBaseOffset, bIsLastApplied, strError);
1488
1489 if (!pConfigurationBlackboard) {
1490
1491 return false;
1492 }
1493
1494 log_info("Element %s in Domain %s, offset: %d, base offset: %d", strPath.c_str(), strDomain.c_str(), pConfigurableElement->getOffset(), uiBaseOffset);
1495
1496 /// Update the Configuration Blackboard
1497
Frédéric Boisnard150407c2013-03-15 14:46:23 +01001498 // 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 +01001499 CParameterAccessContext parameterAccessContext(strError, pConfigurationBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex, uiBaseOffset);
1500
1501 // Access Value in the Configuration Blackboard
1502 if (!accessValue(parameterAccessContext, strPath, strValue, bSet, strError)) {
1503
1504 return false;
1505 }
1506
1507 /// If the Configuration is the last one applied, update the Main Blackboard as well
1508
1509 if (bIsLastApplied) {
1510
1511 // Define Main context
1512 parameterAccessContext.setParameterBlackboard(_pMainParameterBlackboard);
1513
Frédéric Boisnard150407c2013-03-15 14:46:23 +01001514 // Activate the auto synchronization with the hardware
1515 if (bSet) {
1516
1517 parameterAccessContext.setAutoSync(_bAutoSyncOn);
1518 }
1519
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001520 // Access Value in the Main Blackboard
1521 return accessValue(parameterAccessContext, strPath, strValue, bSet, strError);
1522 }
1523
1524 return true;
1525}
1526
Patrick Benavoli68a91282011-08-31 11:23:23 +02001527// User set/get parameters
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001528bool CParameterMgr::accessValue(CParameterAccessContext& parameterAccessContext, const string& strPath, string& strValue, bool bSet, string& strError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001529{
Patrick Benavoli065264a2011-11-20 15:46:41 +01001530 // Lock state
1531 CAutoLock autoLock(&_blackboardMutex);
1532
1533 CPathNavigator pathNavigator(strPath);
1534
1535 // Nagivate through system class
1536 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001537
1538 return false;
1539 }
1540
Patrick Benavoli065264a2011-11-20 15:46:41 +01001541 // Do the get
1542 return getConstSystemClass()->accessValue(pathNavigator, strValue, bSet, parameterAccessContext);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001543}
1544
1545// Tuning mode
1546bool CParameterMgr::setTuningMode(bool bOn, string& strError)
1547{
1548 // Tuning allowed?
Patrick Benavoli95ac0342011-11-07 20:32:51 +01001549 if (bOn && !getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001550
1551 strError = "Tuning prohibited";
1552
1553 return false;
1554 }
1555 // Lock state
Patrick Benavoli065264a2011-11-20 15:46:41 +01001556 CAutoLock autoLock(&_blackboardMutex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001557
1558 // Warn domains about exiting tuning mode
1559 if (!bOn && _bTuningModeIsOn) {
1560
1561 // Ensure application of currently selected configurations
Patrick Benavoli1387bda2011-08-31 11:23:24 +02001562 // Force-apply configurations
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01001563 doApplyConfigurations(true);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001564
Patrick Benavoli68a91282011-08-31 11:23:23 +02001565 // Turn auto sync back on
1566 _bAutoSyncOn = true;
1567 }
1568
1569 // Store
1570 _bTuningModeIsOn = bOn;
1571
Patrick Benavoli68a91282011-08-31 11:23:23 +02001572 return true;
1573}
1574
1575bool CParameterMgr::tuningModeOn() const
1576{
1577 return _bTuningModeIsOn;
1578}
1579
1580// Current value space for user set/get value interpretation
1581void CParameterMgr::setValueSpace(bool bIsRaw)
1582{
1583 _bValueSpaceIsRaw = bIsRaw;
1584}
1585
1586bool CParameterMgr::valueSpaceIsRaw()
1587{
1588 return _bValueSpaceIsRaw;
1589}
1590
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001591// Current Output Raw Format for user get value interpretation
1592void CParameterMgr::setOutputRawFormat(bool bIsHex)
1593{
1594 _bOutputRawFormatIsHex = bIsHex;
1595}
1596
1597bool CParameterMgr::outputRawFormatIsHex()
1598{
1599 return _bOutputRawFormatIsHex;
1600}
1601
Patrick Benavoli68a91282011-08-31 11:23:23 +02001602/// Sync
1603// Automatic hardware synchronization control (during tuning session)
1604bool CParameterMgr::setAutoSync(bool bAutoSyncOn, string& strError)
1605{
1606 // Check tuning mode
1607 if (!checkTuningModeOn(strError)) {
1608
1609 return false;
1610 }
1611 // Warn domains about turning auto sync back on
1612 if (bAutoSyncOn && !_bAutoSyncOn) {
1613
Patrick Benavoli592ae562011-09-05 16:53:58 +02001614 // Do the synchronization at system class level (could be optimized by keeping track of all modified parameters)
1615 if (!sync(strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001616
1617 return false;
1618 }
1619 }
1620
1621 // Set Auto sync
1622 _bAutoSyncOn = bAutoSyncOn;
1623
1624 return true;
1625}
1626
1627bool CParameterMgr::autoSyncOn() const
1628{
1629 return _bAutoSyncOn;
1630}
1631
1632// Manual hardware synchronization control (during tuning session)
1633bool CParameterMgr::sync(string& strError)
1634{
1635 // Check tuning mode
1636 if (!checkTuningModeOn(strError)) {
1637
1638 return false;
1639 }
1640 // Warn domains about turning auto sync back on
1641 if (_bAutoSyncOn) {
1642
1643 strError = "Feature unavailable when Auto Sync is on";
1644
1645 return false;
1646 }
1647
1648 // Get syncer set
1649 CSyncerSet syncerSet;
1650 // ... from system class
1651 getConstSystemClass()->fillSyncerSet(syncerSet);
Kevin Rocardace81f82012-12-11 16:19:17 +01001652
Patrick Benavoli68a91282011-08-31 11:23:23 +02001653 // Sync
Kevin Rocardace81f82012-12-11 16:19:17 +01001654 list<string> lstrError;
1655 if (! syncerSet.sync(*_pMainParameterBlackboard, false, &lstrError)){
1656
Frederic Boisnard390b36d2013-05-23 15:28:31 +02001657 CUtility::asString(lstrError, strError);
Kevin Rocardace81f82012-12-11 16:19:17 +01001658 return false;
1659 };
1660
1661 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001662}
1663
1664// Content dump
1665void CParameterMgr::logStructureContent(string& strContent) const
1666{
1667 string strError;
1668
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001669 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001670
1671 dumpContent(strContent, parameterAccessContext);
1672}
1673
1674// Configuration/Domains handling
1675bool CParameterMgr::createDomain(const string& strName, string& strError)
1676{
1677 // Check tuning mode
1678 if (!checkTuningModeOn(strError)) {
1679
1680 return false;
1681 }
1682
1683 // Delegate to configurable domains
1684 return getConfigurableDomains()->createDomain(strName, strError);
1685}
1686
1687bool CParameterMgr::deleteDomain(const string& strName, string& strError)
1688{
1689 // Check tuning mode
1690 if (!checkTuningModeOn(strError)) {
1691
1692 return false;
1693 }
1694
1695 // Delegate to configurable domains
1696 return getConfigurableDomains()->deleteDomain(strName, strError);
1697}
1698
Kevin Rocard170f0a42012-06-18 13:56:05 +02001699bool CParameterMgr::deleteAllDomains(string& strError)
1700{
1701 // Check tuning mode
1702 if (!checkTuningModeOn(strError)) {
1703
1704 return false;
1705 }
1706
1707 // Delegate to configurable domains
1708 getConfigurableDomains()->deleteAllDomains();
1709
1710 return true;
1711}
1712
Patrick Benavoli68a91282011-08-31 11:23:23 +02001713bool CParameterMgr::createConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1714{
1715 // Check tuning mode
1716 if (!checkTuningModeOn(strError)) {
1717
1718 return false;
1719 }
1720
1721 // Delegate to configurable domains
1722 return getConfigurableDomains()->createConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1723}
1724
1725bool CParameterMgr::deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1726{
1727 // Check tuning mode
1728 if (!checkTuningModeOn(strError)) {
1729
1730 return false;
1731 }
1732
1733 // Delegate to configurable domains
1734 return getConfigurableDomains()->deleteConfiguration(strDomain, strConfiguration, strError);
1735}
1736
Kevin Rocardace81f82012-12-11 16:19:17 +01001737bool CParameterMgr::restoreConfiguration(const string& strDomain, const string& strConfiguration, list<string>& lstrError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001738{
Kevin Rocardace81f82012-12-11 16:19:17 +01001739 string strError;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001740 // Check tuning mode
1741 if (!checkTuningModeOn(strError)) {
1742
Kevin Rocardace81f82012-12-11 16:19:17 +01001743 lstrError.push_back(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001744 return false;
1745 }
1746
1747 // Delegate to configurable domains
Kevin Rocardace81f82012-12-11 16:19:17 +01001748 return getConstConfigurableDomains()->restoreConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, lstrError);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001749}
1750
1751bool CParameterMgr::saveConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
1752{
1753 // Check tuning mode
1754 if (!checkTuningModeOn(strError)) {
1755
1756 return false;
1757 }
1758
1759 // Delegate to configurable domains
1760 return getConfigurableDomains()->saveConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
1761}
1762
1763// Configurable element - domain association
1764bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1765{
1766 // Check tuning mode
1767 if (!checkTuningModeOn(strError)) {
1768
1769 return false;
1770 }
1771
1772 CElementLocator elementLocator(getSystemClass());
1773
1774 CElement* pLocatedElement = NULL;
1775
1776 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1777
1778 return false;
1779 }
1780
1781 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001782 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001783
1784 // Delegate
1785 return getConfigurableDomains()->addConfigurableElementToDomain(strDomain, pConfigurableElement, _pMainParameterBlackboard, strError);
1786}
1787
1788bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1789{
1790 // Check tuning mode
1791 if (!checkTuningModeOn(strError)) {
1792
1793 return false;
1794 }
1795
1796 CElementLocator elementLocator(getSystemClass());
1797
1798 CElement* pLocatedElement = NULL;
1799
1800 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1801
Patrick Benavoli63499d42011-10-24 18:50:03 +02001802 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001803 }
1804
1805 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001806 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001807
1808 // Delegate
1809 return getConfigurableDomains()->removeConfigurableElementFromDomain(strDomain, pConfigurableElement, strError);
1810}
1811
1812bool CParameterMgr::split(const string& strDomain, const string& strConfigurableElementPath, string& strError)
1813{
1814 // Check tuning mode
1815 if (!checkTuningModeOn(strError)) {
1816
1817 return false;
1818 }
1819
1820 CElementLocator elementLocator(getSystemClass());
1821
1822 CElement* pLocatedElement = NULL;
1823
1824 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
1825
Patrick Benavoli63499d42011-10-24 18:50:03 +02001826 return CCommandHandler::EFailed;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001827 }
1828
1829 // Convert element
Pavel Chupin85413ff2012-04-24 10:55:48 +04001830 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001831
1832 // Delegate
1833 return getConfigurableDomains()->split(strDomain, pConfigurableElement, strError);
1834}
1835
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001836bool CParameterMgr::importDomainsXml(const string& strXmlSource, bool bWithSettings,
1837 bool bFromFile, string& strError)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001838{
1839 // Check tuning mode
1840 if (!checkTuningModeOn(strError)) {
1841
1842 return false;
1843 }
1844
1845 // check path is absolute
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001846 if (bFromFile && strXmlSource[0] != '/') {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001847
1848 strError = "Please provide absolute path";
1849
1850 return false;
1851 }
1852 // Root element
1853 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1854
1855 // Context
1856 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1857
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001858 // Selection criteria definition for rule creation
1859 xmlDomainSerializingContext.setSelectionCriteriaDefinition(
1860 getConstSelectionCriteria()->getSelectionCriteriaDefinition());
Patrick Benavoli68a91282011-08-31 11:23:23 +02001861
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001862 // Init serializing context
1863 xmlDomainSerializingContext.set(
1864 _pElementLibrarySet->getElementLibrary(EParameterConfigurationLibrary),
1865 "", _strSchemaFolderLocation);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001866
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001867 // Get Schema file associated to root element
1868 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" +
1869 pConfigurableDomains->getKind() + ".xsd";
1870
1871 // Xml Source
1872 CXmlDocSource* pSource;
1873
1874 if (bFromFile) {
1875
1876 // when importing from a file strXmlSource is the file name
1877 pSource = new CXmlFileDocSource(strXmlSource, strXmlSchemaFilePath,
1878 pConfigurableDomains->getKind(),
1879 pConfigurableDomains->getName(), "SystemClassName");
1880
1881 } else {
1882
1883 // when importing from an xml string, strXmlSource contains the string
1884 pSource = new CXmlStringDocSource(strXmlSource, strXmlSchemaFilePath,
1885 pConfigurableDomains->getKind(),
1886 pConfigurableDomains->getName(), "SystemClassName");
1887
1888 }
1889 // Start clean
1890 pConfigurableDomains->clean();
1891
1892 // Use a doc sink that instantiate Configurable Domains from the given doc source
1893 CXmlMemoryDocSink memorySink(pConfigurableDomains);
1894
1895 bool bProcessSuccess = memorySink.process(*pSource, xmlDomainSerializingContext);
1896
1897 if (!bProcessSuccess) {
1898
1899 //Cleanup
1900 pConfigurableDomains->clean();
1901
1902 } else {
1903
1904 // Validate domains after XML import
1905 pConfigurableDomains->validate(_pMainParameterBlackboard);
1906
Patrick Benavoli68a91282011-08-31 11:23:23 +02001907 }
1908
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001909 delete pSource;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001910
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001911 return bProcessSuccess;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001912}
1913
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001914bool CParameterMgr::exportDomainsXml(string& strXmlDest, bool bWithSettings, bool bToFile,
1915 string& strError) const
Patrick Benavoli68a91282011-08-31 11:23:23 +02001916{
1917 // check path is absolute
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001918 if (bToFile && strXmlDest[0] != '/') {
Patrick Benavoli68a91282011-08-31 11:23:23 +02001919
1920 strError = "Please provide absolute path";
1921
1922 return false;
1923 }
1924
1925 // Root element
1926 const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains();
1927
1928 // Get Schema file associated to root element
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001929 string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" +
1930 pConfigurableDomains->getKind() + ".xsd";
Patrick Benavoli68a91282011-08-31 11:23:23 +02001931
1932 // Context
1933 CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings);
1934
1935 // Value space
1936 xmlDomainSerializingContext.setValueSpaceRaw(_bValueSpaceIsRaw);
1937
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02001938 // Output raw format
1939 xmlDomainSerializingContext.setOutputRawFormat(_bOutputRawFormatIsHex);
1940
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02001941 // Use a doc source by loading data from instantiated Configurable Domains
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001942 CXmlMemoryDocSource memorySource(pConfigurableDomains, pConfigurableDomains->getKind(),
1943 strXmlSchemaFilePath, "parameter-framework", getVersion());
Patrick Benavoli68a91282011-08-31 11:23:23 +02001944
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001945 // Xml Sink
1946 CXmlDocSink* pSink;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001947
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001948 if (bToFile) {
1949
1950 // Use a doc sink to write the doc data in a file
1951 pSink = new CXmlFileDocSink(strXmlDest);
1952
1953 } else {
1954
1955 // Use a doc sink to write the doc data in a string
1956 pSink = new CXmlStringDocSink(strXmlDest);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001957 }
1958
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02001959 bool bProcessSuccess = pSink->process(memorySource, xmlDomainSerializingContext);
1960
1961 delete pSink;
1962 return bProcessSuccess;
Patrick Benavoli68a91282011-08-31 11:23:23 +02001963}
1964
1965// Binary Import/Export
1966bool CParameterMgr::importDomainsBinary(const string& strFileName, string& strError)
1967{
1968 // Check tuning mode
1969 if (!checkTuningModeOn(strError)) {
1970
1971 return false;
1972 }
1973 // check path is absolute
1974 if (strFileName[0] != '/') {
1975
1976 strError = "Please provide absolute path";
1977
1978 return false;
1979 }
1980 // Root element
1981 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1982
1983 // Serialize in
1984 return pConfigurableDomains->serializeSettings(strFileName, false, _uiStructureChecksum, strError);
1985}
1986
1987bool CParameterMgr::exportDomainsBinary(const string& strFileName, string& strError)
1988{
1989 // check path is absolute
1990 if (strFileName[0] != '/') {
1991
1992 strError = "Please provide absolute path";
1993
1994 return false;
1995 }
Patrick Benavoli68a91282011-08-31 11:23:23 +02001996
Patrick Benavoli68a91282011-08-31 11:23:23 +02001997 // Root element
1998 CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
1999
2000 // Serialize out
2001 return pConfigurableDomains->serializeSettings(strFileName, true, _uiStructureChecksum, strError);
2002}
2003
2004// For tuning, check we're in tuning mode
2005bool CParameterMgr::checkTuningModeOn(string& strError) const
2006{
2007 // Tuning Mode on?
2008 if (!_bTuningModeIsOn) {
2009
2010 strError = "Tuning Mode must be on";
2011
2012 return false;
2013 }
2014 return true;
2015}
2016
Patrick Benavoli065264a2011-11-20 15:46:41 +01002017// Tuning mutex dynamic parameter handling
2018pthread_mutex_t* CParameterMgr::getBlackboardMutex()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002019{
Patrick Benavoli065264a2011-11-20 15:46:41 +01002020 return &_blackboardMutex;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002021}
2022
Patrick Benavoli065264a2011-11-20 15:46:41 +01002023// Blackboard reference (dynamic parameter handling)
2024CParameterBlackboard* CParameterMgr::getParameterBlackboard()
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002025{
Patrick Benavoli065264a2011-11-20 15:46:41 +01002026 return _pMainParameterBlackboard;
Patrick Benavoli4bed9212011-10-27 14:18:00 +02002027}
2028
Patrick Benavoli68a91282011-08-31 11:23:23 +02002029// Dynamic creation library feeding
2030void CParameterMgr::feedElementLibraries()
2031{
2032 // Global Configuration handling
2033 CElementLibrary* pFrameworkConfigurationLibrary = new CElementLibrary;
2034
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02002035 pFrameworkConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CParameterFrameworkConfiguration>("ParameterFrameworkConfiguration"));
Guillaume Denneulina4ec15d2012-02-17 14:38:14 +01002036 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CSubsystemPlugins>("SubsystemPlugins"));
2037 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CPluginLocation>("Location"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02002038 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("StructureDescriptionFileLocation"));
2039 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationGroup>("SettingsConfiguration"));
2040 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("ConfigurableDomainsFileLocation"));
2041 pFrameworkConfigurationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>("BinarySettingsFileLocation"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02002042
2043 _pElementLibrarySet->addElementLibrary(pFrameworkConfigurationLibrary);
2044
2045 // Parameter creation
2046 CElementLibrary* pParameterCreationLibrary = new CElementLibrary;
2047
2048 pParameterCreationLibrary->addElementBuilder(new CSubsystemElementBuilder(getSystemClass()->getSubsystemLibrary()));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02002049 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CComponentType>("ComponentType"));
2050 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CComponentInstance>("Component"));
2051 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBitParameterType>("BitParameter"));
2052 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBitParameterBlockType>("BitParameterBlock"));
Patrick Benavoli1352ae52011-10-21 16:48:04 +02002053 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CStringParameterType>("StringParameter"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02002054 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CParameterBlockType>("ParameterBlock"));
2055 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CBooleanParameterType>("BooleanParameter"));
2056 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CIntegerParameterType>("IntegerParameter"));
Patrick Benavoliee65e6d2011-11-20 18:52:24 +01002057 pParameterCreationLibrary->addElementBuilder(new TElementBuilderTemplate<CLinearParameterAdaptation>("LinearAdaptation"));
Patrick Benavoli9fc3c0d2011-10-27 14:27:27 +02002058 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CEnumParameterType>("EnumParameter"));
Patrick Benavoli68808c62012-02-02 17:12:41 +01002059 pParameterCreationLibrary->addElementBuilder(new TElementBuilderTemplate<CEnumValuePair>("ValuePair"));
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02002060 pParameterCreationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CFixedPointParameterType>("FixedPointParameter"));
2061 pParameterCreationLibrary->addElementBuilder(new TKindElementBuilderTemplate<CXmlFileIncluderElement>("SubsystemInclude"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02002062
2063 _pElementLibrarySet->addElementLibrary(pParameterCreationLibrary);
2064
2065 // Parameter Configuration Domains creation
2066 CElementLibrary* pParameterConfigurationLibrary = new CElementLibrary;
2067
Patrick Benavoli6ba361d2011-08-31 11:23:24 +02002068 pParameterConfigurationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CConfigurableDomain>("ConfigurableDomain"));
2069 pParameterConfigurationLibrary->addElementBuilder(new TNamedElementBuilderTemplate<CDomainConfiguration>("Configuration"));
2070 pParameterConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CCompoundRule>("CompoundRule"));
2071 pParameterConfigurationLibrary->addElementBuilder(new TElementBuilderTemplate<CSelectionCriterionRule>("SelectionCriterionRule"));
Patrick Benavoli68a91282011-08-31 11:23:23 +02002072
2073 _pElementLibrarySet->addElementLibrary(pParameterConfigurationLibrary);
2074}
2075
2076// Remote Processor Server connection handling
2077bool CParameterMgr::handleRemoteProcessingInterface(string& strError)
2078{
2079 CAutoLog autoLog(this, "Handling remote processing interface");
2080
2081 // Start server if tuning allowed
Patrick Benavoli95ac0342011-11-07 20:32:51 +01002082 if (getConstFrameworkConfiguration()->isTuningAllowed()) {
Patrick Benavoli68a91282011-08-31 11:23:23 +02002083
Kevin Rocardace81f82012-12-11 16:19:17 +01002084 log_info("Loading remote processor library");
Patrick Benavoli68a91282011-08-31 11:23:23 +02002085
2086 // Load library
2087 void* lib_handle = dlopen("libremote-processor.so", RTLD_NOW);
2088
2089 if (!lib_handle) {
2090
2091 // Return error
2092 const char* pcError = dlerror();
2093
2094 if (pcError) {
2095
2096 strError = pcError;
2097 } else {
2098
2099 strError = "Unable to load libremote-processor.so library";
2100 }
2101
2102 return false;
2103 }
2104
2105 CreateRemoteProcessorServer pfnCreateRemoteProcessorServer = (CreateRemoteProcessorServer)dlsym(lib_handle, "createRemoteProcessorServer");
2106
2107 if (!pfnCreateRemoteProcessorServer) {
2108
2109 strError = "libremote-process.so does not contain createRemoteProcessorServer symbol.";
2110
2111 return false;
2112 }
2113
2114 // Create server
Patrick Benavoli95ac0342011-11-07 20:32:51 +01002115 _pRemoteProcessorServer = pfnCreateRemoteProcessorServer(getConstFrameworkConfiguration()->getServerPort(), _pCommandHandler);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002116
Kevin Rocardace81f82012-12-11 16:19:17 +01002117 log_info("Starting remote processor server on port %d", getConstFrameworkConfiguration()->getServerPort());
Patrick Benavoli68a91282011-08-31 11:23:23 +02002118 // Start
2119 if (!_pRemoteProcessorServer->start()) {
2120
2121 strError = "Unable to start remote processor server";
2122
2123 return false;
2124 }
2125 }
2126
2127 return true;
2128}
2129
2130// Back synchronization
Kevin Rocardace81f82012-12-11 16:19:17 +01002131CBackSynchronizer* CParameterMgr::createBackSynchronizer() const
Patrick Benavoli68a91282011-08-31 11:23:23 +02002132{
2133#ifdef SIMULATION
2134 // In simulation, back synchronization of the blackboard won't probably work
2135 // We need to ensure though the blackboard is initialized with valid data
Kevin Rocardace81f82012-12-11 16:19:17 +01002136 return new CSimulatedBackSynchronizer(getConstSystemClass(), _pMainParameterBlackboard);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002137#else
2138 // Real back synchronizer from subsystems
Kevin Rocardace81f82012-12-11 16:19:17 +01002139 return new CHardwareBackSynchronizer(getConstSystemClass(), _pMainParameterBlackboard);
Patrick Benavoli68a91282011-08-31 11:23:23 +02002140#endif
2141}
2142
2143// Children typwise access
2144CParameterFrameworkConfiguration* CParameterMgr::getFrameworkConfiguration()
2145{
2146 return static_cast<CParameterFrameworkConfiguration*>(getChild(EFrameworkConfiguration));
2147}
2148
2149const CParameterFrameworkConfiguration* CParameterMgr::getConstFrameworkConfiguration()
2150{
2151 return getFrameworkConfiguration();
2152}
2153
2154CSelectionCriteria* CParameterMgr::getSelectionCriteria()
2155{
2156 return static_cast<CSelectionCriteria*>(getChild(ESelectionCriteria));
2157}
2158
2159const CSelectionCriteria* CParameterMgr::getConstSelectionCriteria()
2160{
2161 return static_cast<const CSelectionCriteria*>(getChild(ESelectionCriteria));
2162}
2163
2164CSystemClass* CParameterMgr::getSystemClass()
2165{
2166 return static_cast<CSystemClass*>(getChild(ESystemClass));
2167}
2168
2169const CSystemClass* CParameterMgr::getConstSystemClass() const
2170{
2171 return static_cast<const CSystemClass*>(getChild(ESystemClass));
2172}
2173
2174// Configurable Domains
2175CConfigurableDomains* CParameterMgr::getConfigurableDomains()
2176{
2177 return static_cast<CConfigurableDomains*>(getChild(EConfigurableDomains));
2178}
2179
2180const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains()
2181{
2182 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
2183}
2184
2185const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains() const
2186{
2187 return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
2188}
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002189
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01002190// Apply configurations
2191void CParameterMgr::doApplyConfigurations(bool bForce)
2192{
2193 CSyncerSet syncerSet;
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002194
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +01002195 // Check subsystems that need resync
2196 getSystemClass()->checkForSubsystemsToResync(syncerSet);
2197
2198 // Ensure application of currently selected configurations
2199 getConfigurableDomains()->apply(_pMainParameterBlackboard, syncerSet, bForce);
2200
2201 // Reset the modified status of the current criteria to indicate that a new configuration has been applied
2202 getSelectionCriteria()->resetModifiedStatus();
2203}
2204
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002205bool CParameterMgr::getSystemClassXMLString(string& strResult)
2206{
2207 // Root element
2208 const CSystemClass* pSystemClass = getSystemClass();
2209
2210 string strError;
2211
2212 CXmlSerializingContext xmlSerializingContext(strError);
2213
2214 // Use a doc source by loading data from instantiated Configurable Domains
2215 CXmlMemoryDocSource memorySource(pSystemClass, pSystemClass->getKind());
2216
2217 // Use a doc sink that write the doc data in a string
2218 CXmlStringDocSink stringSink(strResult);
2219
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002220 bool bProcessSuccess = stringSink.process(memorySource, xmlSerializingContext);
2221
2222 if (!bProcessSuccess) {
2223
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002224 strResult = strError;
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002225
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002226 }
2227
Georges-Henri Baroncec86c12012-09-04 17:30:28 +02002228 return bProcessSuccess;
Georges-Henri Baron326a31d2012-06-28 12:05:09 +02002229}