1 /*
2 * Copyright (c) 2011-2016, Intel Corporation
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice, this
9 * list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation and/or
13 * other materials provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its contributors
16 * may be used to endorse or promote products derived from this software without
17 * specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30 #include "version.h"
31 #include "ParameterMgr.h"
32 #include "ConfigurationAccessContext.h"
33 #include "XmlParameterSerializingContext.h"
34 #include "XmlElementSerializingContext.h"
35 #include "SystemClass.h"
36 #include "ElementLibrarySet.h"
37 #include "SubsystemLibrary.h"
38 #include "NamedElementBuilderTemplate.h"
39 #include "KindElementBuilderTemplate.h"
40 #include "ElementBuilderTemplate.h"
41 #include "SelectionCriterionType.h"
42 #include "SubsystemElementBuilder.h"
43 #include "FileIncluderElementBuilder.h"
44 #include "SelectionCriteria.h"
45 #include "ComponentType.h"
46 #include "ComponentInstance.h"
47 #include "ParameterBlockType.h"
48 #include "BooleanParameterType.h"
49 #include "IntegerParameterBuilder.h"
50 #include "FixedPointParameterType.h"
51 #include "FloatingPointParameterType.h"
52 #include "ParameterBlackboard.h"
53 #include "Parameter.h"
54 #include "ParameterAccessContext.h"
55 #include "ParameterFrameworkConfiguration.h"
56 #include "FrameworkConfigurationGroup.h"
57 #include "PluginLocation.h"
58 #include "SubsystemPlugins.h"
59 #include "FrameworkConfigurationLocation.h"
60 #include "ConfigurableDomains.h"
61 #include "ConfigurableDomain.h"
62 #include "DomainConfiguration.h"
63 #include "XmlDomainSerializingContext.h"
64 #include "XmlDomainExportContext.h"
65 #include "XmlDomainImportContext.h"
66 #include "BitParameterBlockType.h"
67 #include "BitParameterType.h"
68 #include "StringParameterType.h"
69 #include "EnumParameterType.h"
70 #include "BackgroundRemoteProcessorServer.h"
71 #include "ElementLocator.h"
72 #include "CompoundRule.h"
73 #include "SelectionCriterionRule.h"
74 #include "SimulatedBackSynchronizer.h"
75 #include "HardwareBackSynchronizer.h"
76 #include <cassert>
77 #include "ParameterHandle.h"
78 #include "LinearParameterAdaptation.h"
79 #include "LogarithmicParameterAdaptation.h"
80 #include "EnumValuePair.h"
81 #include "Subsystem.h"
82 #include "XmlStreamDocSink.h"
83 #include "XmlMemoryDocSink.h"
84 #include "XmlDocSource.h"
85 #include "XmlMemoryDocSource.h"
86 #include "SelectionCriteriaDefinition.h"
87 #include "Utility.h"
88 #include "Memory.hpp"
89 #include <sstream>
90 #include <fstream>
91 #include <algorithm>
92 #include <stdexcept>
93 #include <mutex>
94 #include <iomanip>
95 #include "convert.hpp"
96
97 #define base CElement
98
99 /** Private macro helper to declare a new context
100 *
101 * Context declaration always need logger and logging prefix to be
102 * passed as parameters.
103 * This macro aims to avoid this boring notation.
104 * This macro should be called only once in a scope. Nested scopes can
105 * call this macro too, as variable shadowing is supported.
106 */
107 #define LOG_CONTEXT(contextTitle) core::log::Context context(_logger, contextTitle)
108
109 #ifdef SIMULATION
110 // In simulation, back synchronization of the blackboard won't probably work
111 // We need to ensure though the blackboard is initialized with valid data
112 typedef CSimulatedBackSynchronizer BackSynchronizer;
113 #else
114 // Real back synchronizer from subsystems
115 typedef CHardwareBackSynchronizer BackSynchronizer;
116 #endif
117
118 using std::string;
119 using std::list;
120 using std::vector;
121 using std::ostringstream;
122 using std::ofstream;
123 using std::ifstream;
124 using std::mutex;
125 using std::lock_guard;
126
127 // FIXME: integrate ParameterMgr to core namespace
128 using namespace core;
129
130 // Used for remote processor server creation
131 typedef IRemoteProcessorServerInterface *(*CreateRemoteProcessorServer)(
132 std::string bindAddress, IRemoteCommandHandler *pCommandHandler);
133
134 // Config File System looks normally like this:
135 // ---------------------------------------------
136 //|-- <ParameterFrameworkConfiguration>.xml
137 //|-- schemas
138 //| `-- *.xsd
139 //|-- Settings
140 //| `-- <SystemClassName folder>*
141 //| |-- <ConfigurableDomains>.xml
142 //| `-- <Settings>.bin?
143 //`-- Structure
144 // `-- <SystemClassName folder>*
145 // |-- <SystemClassName>Class.xml
146 // `-- <Subsystem>.xml*
147 // --------------------------------------------
148
149 // Remote command parser array
150 const CParameterMgr::SRemoteCommandParserItem CParameterMgr::gastRemoteCommandParserItems[] = {
151
152 /// Version
153 {"version", &CParameterMgr::versionCommandProcess, 0, "", "Show version"},
154
155 /// Status
156 {"status", &CParameterMgr::statusCommandProcess, 0, "", "Show current status"},
157
158 /// Tuning Mode
159 {"setTuningMode", &CParameterMgr::setTuningModeCommandProcess, 1, "on|off*",
160 "Turn on or off Tuning Mode"},
161 {"getTuningMode", &CParameterMgr::getTuningModeCommandProcess, 0, "", "Show Tuning Mode"},
162
163 /// Value Space
164 {"setValueSpace", &CParameterMgr::setValueSpaceCommandProcess, 1, "raw|real*",
165 "Assigns Value Space used for parameter value interpretation"},
166 {"getValueSpace", &CParameterMgr::getValueSpaceCommandProcess, 0, "", "Show Value Space"},
167
168 /// Output Raw Format
169 {"setOutputRawFormat", &CParameterMgr::setOutputRawFormatCommandProcess, 1, "dec*|hex",
170 "Assigns format used to output parameter values when in raw Value Space"},
171 {"getOutputRawFormat", &CParameterMgr::getOutputRawFormatCommandProcess, 0, "",
172 "Show Output Raw Format"},
173
174 /// Sync
175 {"setAutoSync", &CParameterMgr::setAutoSyncCommandProcess, 1, "on*|off",
176 "Turn on or off automatic synchronization to hardware while in Tuning Mode"},
177 {"getAutoSync", &CParameterMgr::getAutoSyncCommandProcess, 0, "", "Show Auto Sync state"},
178 {"sync", &CParameterMgr::syncCommandProcess, 0, "",
179 "Synchronize current settings to hardware while in Tuning Mode and Auto Sync off"},
180
181 /// Criteria
182 {"listCriteria", &CParameterMgr::listCriteriaCommandProcess, 0, "[CSV|XML]",
183 "List selection criteria"},
184
185 /// Domains
186 {"listDomains", &CParameterMgr::listDomainsCommandProcess, 0, "", "List configurable domains"},
187 {"dumpDomains", &CParameterMgr::dumpDomainsCommandProcess, 0, "",
188 "Show all domains and configurations, including applicability conditions"},
189 {"createDomain", &CParameterMgr::createDomainCommandProcess, 1, "<domain>",
190 "Create new configurable domain"},
191 {"deleteDomain", &CParameterMgr::deleteDomainCommandProcess, 1, "<domain>",
192 "Delete configurable domain"},
193 {"deleteAllDomains", &CParameterMgr::deleteAllDomainsCommandProcess, 0, "",
194 "Delete all configurable domains"},
195 {"renameDomain", &CParameterMgr::renameDomainCommandProcess, 2, "<domain> <new name>",
196 "Rename configurable domain"},
197 {"setSequenceAwareness", &CParameterMgr::setSequenceAwarenessCommandProcess, 1,
198 "<domain> true|false*", "Set configurable domain sequence awareness"},
199 {"getSequenceAwareness", &CParameterMgr::getSequenceAwarenessCommandProcess, 1, "<domain>",
200 "Get configurable domain sequence awareness"},
201 {"listDomainElements", &CParameterMgr::listDomainElementsCommandProcess, 1, "<domain>",
202 "List elements associated to configurable domain"},
203 {"addElement", &CParameterMgr::addElementCommandProcess, 2, "<domain> <elem path>",
204 "Associate element at given path to configurable domain"},
205 {"removeElement", &CParameterMgr::removeElementCommandProcess, 2, "<domain> <elem path>",
206 "Dissociate element at given path from configurable domain"},
207 {"splitDomain", &CParameterMgr::splitDomainCommandProcess, 2, "<domain> <elem path>",
208 "Split configurable domain at given associated element path"},
209
210 /// Configurations
211 {"listConfigurations", &CParameterMgr::listConfigurationsCommandProcess, 1, "<domain>",
212 "List domain configurations"},
213 {"createConfiguration", &CParameterMgr::createConfigurationCommandProcess, 2,
214 "<domain> <configuration>", "Create new domain configuration"},
215 {"deleteConfiguration", &CParameterMgr::deleteConfigurationCommandProcess, 2,
216 "<domain> <configuration>", "Delete domain configuration"},
217 {"renameConfiguration", &CParameterMgr::renameConfigurationCommandProcess, 3,
218 "<domain> <configuration> <new name>", "Rename domain configuration"},
219 {"saveConfiguration", &CParameterMgr::saveConfigurationCommandProcess, 2,
220 "<domain> <configuration>", "Save current settings into configuration"},
221 {"restoreConfiguration", &CParameterMgr::restoreConfigurationCommandProcess, 2,
222 "<domain> <configuration>", "Restore current settings from configuration"},
223 {"setElementSequence", &CParameterMgr::setElementSequenceCommandProcess, 3,
224 "<domain> <configuration> <elem path list>",
225 "Set element application order for configuration"},
226 {"getElementSequence", &CParameterMgr::getElementSequenceCommandProcess, 2,
227 "<domain> <configuration>", "Get element application order for configuration"},
228 {"setRule", &CParameterMgr::setRuleCommandProcess, 3, "<domain> <configuration> <rule>",
229 "Set configuration application rule"},
230 {"clearRule", &CParameterMgr::clearRuleCommandProcess, 2, "<domain> <configuration>",
231 "Clear configuration application rule"},
232 {"getRule", &CParameterMgr::getRuleCommandProcess, 2, "<domain> <configuration>",
233 "Get configuration application rule"},
234
235 /// Elements/Parameters
236 {"listElements", &CParameterMgr::listElementsCommandProcess, 1, "<elem path>|/",
237 "List elements under element at given path or root"},
238 {"listParameters", &CParameterMgr::listParametersCommandProcess, 1, "<elem path>|/",
239 "List parameters under element at given path or root"},
240 {"getElementStructureXML", &CParameterMgr::getElementStructureXMLCommandProcess, 1,
241 "<elem path>", "Get structure of element at given path in XML format"},
242 {"getElementBytes", &CParameterMgr::getElementBytesCommandProcess, 1, "<elem path>",
243 "Get settings of element at given path in Byte Array format"},
244 {"setElementBytes", &CParameterMgr::setElementBytesCommandProcess, 2, "<elem path> <values>",
245 "Set settings of element at given path in Byte Array format"},
246 {"getElementXML", &CParameterMgr::getElementXMLCommandProcess, 1, "<elem path>",
247 "Get settings of element at given path in XML format"},
248 {"setElementXML", &CParameterMgr::setElementXMLCommandProcess, 2, "<elem path> <values>",
249 "Set settings of element at given path in XML format"},
250 {"dumpElement", &CParameterMgr::dumpElementCommandProcess, 1, "<elem path>",
251 "Dump structure and content of element at given path"},
252 {"getElementSize", &CParameterMgr::getElementSizeCommandProcess, 1, "<elem path>",
253 "Show size of element at given path"},
254 {"showProperties", &CParameterMgr::showPropertiesCommandProcess, 1, "<elem path>",
255 "Show properties of element at given path"},
256 {"getParameter", &CParameterMgr::getParameterCommandProcess, 1, "<param path>",
257 "Get value for parameter at given path"},
258 {"setParameter", &CParameterMgr::setParameterCommandProcess, 2, "<param path> <value>",
259 "Set value for parameter at given path"},
260 {"listBelongingDomains", &CParameterMgr::listBelongingDomainsCommandProcess, 1, "<elem path>",
261 "List domain(s) element at given path belongs to"},
262 {"listAssociatedDomains", &CParameterMgr::listAssociatedDomainsCommandProcess, 1, "<elem path>",
263 "List domain(s) element at given path is associated to"},
264 {"getConfigurationParameter", &CParameterMgr::getConfigurationParameterCommandProcess, 3,
265 "<domain> <configuration> <param path>",
266 "Get value for parameter at given path from configuration"},
267 {"setConfigurationParameter", &CParameterMgr::setConfigurationParameterCommandProcess, 4,
268 "<domain> <configuration> <param path> <value>",
269 "Set value for parameter at given path to configuration"},
270 {"showMapping", &CParameterMgr::showMappingCommandProcess, 1, "<elem path>",
271 "Show mapping for an element at given path"},
272
273 /// Browse
274 {"listAssociatedElements", &CParameterMgr::listAssociatedElementsCommandProcess, 0, "",
275 "List element sub-trees associated to at least one configurable domain"},
276 {"listConflictingElements", &CParameterMgr::listConflictingElementsCommandProcess, 0, "",
277 "List element sub-trees contained in more than one configurable domain"},
278 {"listRogueElements", &CParameterMgr::listRogueElementsCommandProcess, 0, "",
279 "List element sub-trees owned by no configurable domain"},
280
281 /// Settings Import/Export
282 {"exportDomainsXML", &CParameterMgr::exportDomainsXMLCommandProcess, 1, "<file path> ",
283 "Export domains to an XML file (provide an absolute path or relative"
284 "to the client's working directory)"},
285 {"importDomainsXML", &CParameterMgr::importDomainsXMLCommandProcess, 1, "<file path>",
286 "Import domains from an XML file (provide an absolute path or relative"
287 "to the client's working directory)"},
288 {"exportDomainsWithSettingsXML", &CParameterMgr::exportDomainsWithSettingsXMLCommandProcess, 1,
289 "<file path> ",
290 "Export domains including settings to XML file (provide an absolute path or relative"
291 "to the client's working directory)"},
292 {"exportDomainWithSettingsXML", &CParameterMgr::exportDomainWithSettingsXMLCommandProcess, 2,
293 "<domain> <file path> ", "Export a single given domain including settings to XML file"
294 " (provide an absolute path or relative to the client's"
295 " working directory)"},
296 {"importDomainsWithSettingsXML", &CParameterMgr::importDomainsWithSettingsXMLCommandProcess, 1,
297 "<file path>",
298 "Import domains including settings from XML file (provide an absolute path or relative"
299 "to the client's working directory)"},
300 {"importDomainWithSettingsXML", &CParameterMgr::importDomainWithSettingsXMLCommandProcess, 1,
301 "<file path> [overwrite]",
302 "Import a single domain including settings from XML file."
303 " Does not overwrite an existing domain unless 'overwrite' is passed as second"
304 " argument. Provide an absolute path or relative to the client's working directory)"},
305 {"getDomainsWithSettingsXML", &CParameterMgr::getDomainsWithSettingsXMLCommandProcess, 0, "",
306 "Print domains including settings as XML"},
307 {"getDomainWithSettingsXML", &CParameterMgr::getDomainWithSettingsXMLCommandProcess, 1,
308 "<domain>", "Print the given domain including settings as XML"},
309 {"setDomainsWithSettingsXML", &CParameterMgr::setDomainsWithSettingsXMLCommandProcess, 1,
310 "<xml configurable domains>", "Import domains including settings from XML string"},
311 {"setDomainWithSettingsXML", &CParameterMgr::setDomainWithSettingsXMLCommandProcess, 1,
312 "<xml configurable domain> [overwrite]",
313 "Import domains including settings from XML"
314 " string. Does not overwrite an existing domain unless 'overwrite' is passed as second"
315 " argument"},
316 /// Structure Export
317 {"getSystemClassXML", &CParameterMgr::getSystemClassXMLCommandProcess, 0, "",
318 "Print parameter structure as XML"},
319 /// Deprecated Commands
320 {"getDomainsXML", &CParameterMgr::getDomainsWithSettingsXMLCommandProcess, 0, "",
321 "DEPRECATED COMMAND, please use getDomainsWithSettingsXML"},
322
323 };
324
325 // Remote command parsers array Size
CParameterMgr(const string & strConfigurationFilePath,log::ILogger & logger)326 CParameterMgr::CParameterMgr(const string &strConfigurationFilePath, log::ILogger &logger)
327 : _pMainParameterBlackboard(new CParameterBlackboard),
328 _pElementLibrarySet(new CElementLibrarySet),
329 _xmlConfigurationUri(CXmlDocSource::mkUri(strConfigurationFilePath, "")), _logger(logger)
330 {
331 // Deal with children
332 addChild(new CParameterFrameworkConfiguration);
333 addChild(new CSelectionCriteria);
334 addChild(new CSystemClass(_logger));
335 addChild(new CConfigurableDomains);
336 }
337
~CParameterMgr()338 CParameterMgr::~CParameterMgr()
339 {
340 // Children
341 delete _pRemoteProcessorServer;
342 delete _pMainParameterBlackboard;
343 delete _pElementLibrarySet;
344 }
345
getKind() const346 string CParameterMgr::getKind() const
347 {
348 return "ParameterMgr";
349 }
350
351 // Version
getVersion() const352 string CParameterMgr::getVersion() const
353 {
354 return PARAMETER_FRAMEWORK_VERSION;
355 }
356
load(string & strError)357 bool CParameterMgr::load(string &strError)
358 {
359 LOG_CONTEXT("Loading");
360
361 feedElementLibraries();
362
363 // Load Framework configuration
364 if (!loadFrameworkConfiguration(strError)) {
365
366 return false;
367 }
368
369 if (!loadSubsystems(strError)) {
370
371 return false;
372 }
373
374 // Load structure
375 if (!loadStructure(strError)) {
376
377 return false;
378 }
379
380 // Load settings
381 if (!loadSettings(strError)) {
382
383 return false;
384 }
385
386 // Init flow of element tree
387 if (!init(strError)) {
388
389 return false;
390 }
391
392 {
393 LOG_CONTEXT("Main blackboard back synchronization");
394
395 // Back synchronization for areas in parameter blackboard not covered by any domain
396 BackSynchronizer(getConstSystemClass(), _pMainParameterBlackboard).sync();
397 }
398
399 // We're done loading the settings and back synchronizing
400 CConfigurableDomains *pConfigurableDomains = getConfigurableDomains();
401
402 // We need to ensure all domains are valid
403 pConfigurableDomains->validate(_pMainParameterBlackboard);
404
405 // Log selection criterion states
406 {
407 LOG_CONTEXT("Criterion states");
408
409 const CSelectionCriteria *selectionCriteria = getConstSelectionCriteria();
410
411 list<string> criteria;
412 selectionCriteria->listSelectionCriteria(criteria, true, false);
413
414 info() << criteria;
415 }
416
417 // Subsystem can not ask for resync as they have not been synced yet
418 getSystemClass()->cleanSubsystemsNeedToResync();
419
420 // At initialization, check subsystems that need resync
421 doApplyConfigurations(true);
422
423 // Start remote processor server if appropriate
424 return handleRemoteProcessingInterface(strError);
425 }
426
loadFrameworkConfiguration(string & strError)427 bool CParameterMgr::loadFrameworkConfiguration(string &strError)
428 {
429 LOG_CONTEXT("Loading framework configuration");
430
431 // Parse Structure XML file
432 CXmlElementSerializingContext elementSerializingContext(strError);
433
434 _xmlDoc *doc =
435 CXmlDocSource::mkXmlDoc(_xmlConfigurationUri, true, true, elementSerializingContext);
436 if (doc == nullptr) {
437 return false;
438 }
439
440 if (!xmlParse(elementSerializingContext, getFrameworkConfiguration(), doc, _xmlConfigurationUri,
441 EFrameworkConfigurationLibrary)) {
442
443 return false;
444 }
445 // Set class name to system class and configurable domains
446 getSystemClass()->setName(getConstFrameworkConfiguration()->getSystemClassName());
447 getConfigurableDomains()->setName(getConstFrameworkConfiguration()->getSystemClassName());
448
449 // Get subsystem plugins elements
450 _pSubsystemPlugins = static_cast<const CSubsystemPlugins *>(
451 getConstFrameworkConfiguration()->findChild("SubsystemPlugins"));
452
453 if (!_pSubsystemPlugins) {
454
455 strError = "Parameter Framework Configuration: couldn't find SubsystemPlugins element";
456
457 return false;
458 }
459
460 // Log tuning availability
461 info() << "Tuning "
462 << (getConstFrameworkConfiguration()->isTuningAllowed() ? "allowed" : "prohibited");
463
464 return true;
465 }
466
loadSubsystems(std::string & error)467 bool CParameterMgr::loadSubsystems(std::string &error)
468 {
469 LOG_CONTEXT("Loading subsystem plugins");
470
471 // Load subsystems
472 bool isSuccess =
473 getSystemClass()->loadSubsystems(error, _pSubsystemPlugins, !_bFailOnMissingSubsystem);
474
475 if (isSuccess) {
476 info() << "All subsystem plugins successfully loaded";
477
478 if (!error.empty()) {
479 // Log missing subsystems as info
480 info() << error;
481 }
482 } else {
483 warning() << error;
484 }
485 return isSuccess;
486 }
487
loadStructure(string & strError)488 bool CParameterMgr::loadStructure(string &strError)
489 {
490 // Retrieve system to load structure to
491 CSystemClass *pSystemClass = getSystemClass();
492
493 LOG_CONTEXT("Loading " + pSystemClass->getName() + " system class structure");
494
495 // Get structure description element
496 const CFrameworkConfigurationLocation *pStructureDescriptionFileLocation =
497 static_cast<const CFrameworkConfigurationLocation *>(
498 getConstFrameworkConfiguration()->findChildOfKind("StructureDescriptionFileLocation"));
499
500 if (!pStructureDescriptionFileLocation) {
501
502 strError = "No StructureDescriptionFileLocation element found for SystemClass " +
503 pSystemClass->getName();
504
505 return false;
506 }
507
508 // Parse Structure XML file
509 CParameterAccessContext accessContext(strError);
510 CXmlParameterSerializingContext parameterBuildContext(accessContext, strError);
511
512 {
513 // Get structure URI
514 string structureUri =
515 CXmlDocSource::mkUri(_xmlConfigurationUri, pStructureDescriptionFileLocation->getUri());
516
517 LOG_CONTEXT("Importing system structure from file " + structureUri);
518
519 _xmlDoc *doc = CXmlDocSource::mkXmlDoc(structureUri, true, true, parameterBuildContext);
520 if (doc == nullptr) {
521 return false;
522 }
523
524 if (!xmlParse(parameterBuildContext, pSystemClass, doc, structureUri,
525 EParameterCreationLibrary)) {
526
527 return false;
528 }
529 }
530
531 // Initialize offsets
532 pSystemClass->setOffset(0);
533
534 // Initialize main blackboard's size
535 _pMainParameterBlackboard->setSize(pSystemClass->getFootPrint());
536
537 return true;
538 }
539
loadSettings(string & strError)540 bool CParameterMgr::loadSettings(string &strError)
541 {
542 string strLoadError;
543 bool success = loadSettingsFromConfigFile(strLoadError);
544
545 if (!success && !_bFailOnFailedSettingsLoad) {
546 // Load can not fail, ie continue but log the load errors
547 warning() << strLoadError;
548 warning() << "Failed to load settings, continue without domains.";
549 success = true;
550 }
551
552 if (!success) {
553 // Propagate the litteral error only if the function fails
554 strError = strLoadError;
555 return false;
556 }
557
558 return true;
559 }
560
loadSettingsFromConfigFile(string & strError)561 bool CParameterMgr::loadSettingsFromConfigFile(string &strError)
562 {
563 LOG_CONTEXT("Loading settings");
564
565 // Get settings configuration element
566 const CFrameworkConfigurationGroup *pParameterConfigurationGroup =
567 static_cast<const CFrameworkConfigurationGroup *>(
568 getConstFrameworkConfiguration()->findChildOfKind("SettingsConfiguration"));
569
570 if (!pParameterConfigurationGroup) {
571
572 // No settings to load
573
574 return true;
575 }
576
577 // Get configurable domains element
578 const CFrameworkConfigurationLocation *pConfigurableDomainsFileLocation =
579 static_cast<const CFrameworkConfigurationLocation *>(
580 pParameterConfigurationGroup->findChildOfKind("ConfigurableDomainsFileLocation"));
581
582 if (!pConfigurableDomainsFileLocation) {
583
584 strError = "No ConfigurableDomainsFileLocation element found for SystemClass " +
585 getSystemClass()->getName();
586
587 return false;
588 }
589 // Get destination root element
590 CConfigurableDomains *pConfigurableDomains = getConfigurableDomains();
591
592 // Get Xml configuration domains URI
593 string configurationDomainsUri =
594 CXmlDocSource::mkUri(_xmlConfigurationUri, pConfigurableDomainsFileLocation->getUri());
595
596 // Parse configuration domains XML file
597 CXmlDomainImportContext xmlDomainImportContext(strError, true, *getSystemClass());
598
599 // Selection criteria definition for rule creation
600 xmlDomainImportContext.setSelectionCriteriaDefinition(
601 getConstSelectionCriteria()->getSelectionCriteriaDefinition());
602
603 // Auto validation of configurations
604 xmlDomainImportContext.setAutoValidationRequired(true);
605
606 info() << "Importing configurable domains from file " << configurationDomainsUri
607 << " with settings";
608
609 _xmlDoc *doc =
610 CXmlDocSource::mkXmlDoc(configurationDomainsUri, true, true, xmlDomainImportContext);
611 if (doc == nullptr) {
612 return false;
613 }
614
615 return xmlParse(xmlDomainImportContext, pConfigurableDomains, doc, _xmlConfigurationUri,
616 EParameterConfigurationLibrary, true, "SystemClassName");
617 }
618
619 // XML parsing
xmlParse(CXmlElementSerializingContext & elementSerializingContext,CElement * pRootElement,_xmlDoc * doc,const string & baseUri,CParameterMgr::ElementLibrary eElementLibrary,bool replace,const string & strNameAttributeName)620 bool CParameterMgr::xmlParse(CXmlElementSerializingContext &elementSerializingContext,
621 CElement *pRootElement, _xmlDoc *doc, const string &baseUri,
622 CParameterMgr::ElementLibrary eElementLibrary, bool replace,
623 const string &strNameAttributeName)
624 {
625 // Init serializing context
626 elementSerializingContext.set(_pElementLibrarySet->getElementLibrary(eElementLibrary), baseUri);
627
628 CXmlDocSource docSource(doc, _bValidateSchemasOnStart, pRootElement->getXmlElementName(),
629 pRootElement->getName(), strNameAttributeName);
630
631 docSource.setSchemaBaseUri(getSchemaUri());
632
633 // Start clean
634 auto clean = [replace, &pRootElement] {
635 if (replace) {
636 pRootElement->clean();
637 }
638 };
639 clean();
640
641 CXmlMemoryDocSink memorySink(pRootElement);
642
643 if (!memorySink.process(docSource, elementSerializingContext)) {
644 clean();
645 return false;
646 }
647
648 return true;
649 }
650
651 // Init
init(string & strError)652 bool CParameterMgr::init(string &strError)
653 {
654 return base::init(strError);
655 }
656
657 // Selection criteria interface
createSelectionCriterionType(bool bIsInclusive)658 CSelectionCriterionType *CParameterMgr::createSelectionCriterionType(bool bIsInclusive)
659 {
660 // Propagate
661 return getSelectionCriteria()->createSelectionCriterionType(bIsInclusive);
662 }
663
createSelectionCriterion(const string & strName,const CSelectionCriterionType * pSelectionCriterionType)664 CSelectionCriterion *CParameterMgr::createSelectionCriterion(
665 const string &strName, const CSelectionCriterionType *pSelectionCriterionType)
666 {
667 // Propagate
668 return getSelectionCriteria()->createSelectionCriterion(strName, pSelectionCriterionType,
669 _logger);
670 }
671
672 // Selection criterion retrieval
getSelectionCriterion(const string & strName)673 CSelectionCriterion *CParameterMgr::getSelectionCriterion(const string &strName)
674 {
675 // Propagate
676 return getSelectionCriteria()->getSelectionCriterion(strName);
677 }
678
679 // Configuration application
applyConfigurations()680 void CParameterMgr::applyConfigurations()
681 {
682 LOG_CONTEXT("Configuration application request");
683
684 // Lock state
685 lock_guard<mutex> autoLock(getBlackboardMutex());
686
687 if (!_bTuningModeIsOn) {
688
689 // Apply configuration(s)
690 doApplyConfigurations(false);
691 } else {
692
693 warning() << "Configurations were not applied because the TuningMode is on";
694 }
695 }
696
getConfigurableElement(const string & strPath,string & strError) const697 const CConfigurableElement *CParameterMgr::getConfigurableElement(const string &strPath,
698 string &strError) const
699 {
700 CPathNavigator pathNavigator(strPath);
701
702 // Nagivate through system class
703 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
704
705 return nullptr;
706 }
707
708 // Find element
709 const CElement *pElement = getConstSystemClass()->findDescendant(pathNavigator);
710
711 if (!pElement) {
712
713 strError = "Path not found: " + strPath;
714
715 return nullptr;
716 }
717
718 // Check found element is a parameter
719 const CConfigurableElement *pConfigurableElement =
720 static_cast<const CConfigurableElement *>(pElement);
721
722 return pConfigurableElement;
723 }
724
getConfigurableElement(const string & strPath,string & strError)725 CConfigurableElement *CParameterMgr::getConfigurableElement(const string &strPath, string &strError)
726 {
727 // Implement the mutable version by calling the const one and removing
728 // the const from the result.
729 const auto *constThis = this;
730 return const_cast<CConfigurableElement *>(constThis->getConfigurableElement(strPath, strError));
731 }
732
733 // Dynamic parameter handling
createParameterHandle(const string & strPath,string & strError)734 CParameterHandle *CParameterMgr::createParameterHandle(const string &strPath, string &strError)
735 {
736 CConfigurableElement *pConfigurableElement = getConfigurableElement(strPath, strError);
737
738 if (!pConfigurableElement) {
739
740 // Element not found
741 strError = "Element not found: " + strPath;
742 return nullptr;
743 }
744
745 if (!pConfigurableElement->isParameter()) {
746
747 // Element is not parameter
748 strError = "Not a parameter: " + strPath;
749
750 return nullptr;
751 }
752
753 // Convert as parameter and return new handle
754 return new CParameterHandle(static_cast<CBaseParameter &>(*pConfigurableElement), *this);
755 }
756
757 // Dynamic element handling
createElementHandle(const std::string & path,std::string & error)758 ElementHandle *CParameterMgr::createElementHandle(const std::string &path, std::string &error)
759 {
760 CConfigurableElement *pConfigurableElement;
761
762 if (path == "/") {
763 // Attempt to access root configurable element
764 pConfigurableElement = getSystemClass();
765 } else {
766 pConfigurableElement = getConfigurableElement(path, error);
767 }
768
769 if (!pConfigurableElement) {
770
771 // Element not found
772 error = "Element not found: " + path;
773 return nullptr;
774 }
775
776 // The only reason why a heap object is returned instead of retuning by copy
777 // is to inform the client of a failure through a nullptr.
778 // It could be avoided (return by copy) with an
779 // - optional equivalent (see boost::optional or std::experimental::optional)
780 // - exception (but the api is noexcept)
781 return new ElementHandle(*pConfigurableElement, *this);
782 }
783
getSettingsAsBytes(const CConfigurableElement & element,std::vector<uint8_t> & settings) const784 void CParameterMgr::getSettingsAsBytes(const CConfigurableElement &element,
785 std::vector<uint8_t> &settings) const
786 {
787 // Not useful as the get can not fail,
788 // but the current design forces all serialization and deserialization to
789 // have an error out string
790 std::string error;
791
792 // Prepare parameter access context for main blackboard.
793 // No need to handle output raw format and value space as Byte arrays are hexa formatted
794 CParameterAccessContext parameterAccessContext(error);
795 parameterAccessContext.setParameterBlackboard(_pMainParameterBlackboard);
796
797 // Get the settings
798 element.getSettingsAsBytes(settings, parameterAccessContext);
799 }
800
setSettingsAsBytes(const CConfigurableElement & element,const std::vector<uint8_t> & settings,std::string & error)801 bool CParameterMgr::setSettingsAsBytes(const CConfigurableElement &element,
802 const std::vector<uint8_t> &settings, std::string &error)
803 {
804 // Prepare parameter access context for main blackboard.
805 // Notes:
806 // - No need to handle output raw format and value space as Byte arrays are interpreted as
807 // raw formatted
808 // - No check is done as to the intgrity of the input data.
809 // This may lead to undetected out of range value assignment.
810 // Use this functionality with caution
811 CParameterAccessContext parameterAccessContext(error);
812 parameterAccessContext.setParameterBlackboard(_pMainParameterBlackboard);
813 parameterAccessContext.setAutoSync(autoSyncOn());
814
815 // Set the settings
816 return element.setSettingsAsBytes(settings, parameterAccessContext);
817 }
818
setFailureOnMissingSubsystem(bool bFail)819 void CParameterMgr::setFailureOnMissingSubsystem(bool bFail)
820 {
821 _bFailOnMissingSubsystem = bFail;
822 }
823
getFailureOnMissingSubsystem() const824 bool CParameterMgr::getFailureOnMissingSubsystem() const
825 {
826 return _bFailOnMissingSubsystem;
827 }
828
setFailureOnFailedSettingsLoad(bool bFail)829 void CParameterMgr::setFailureOnFailedSettingsLoad(bool bFail)
830 {
831 _bFailOnFailedSettingsLoad = bFail;
832 }
833
getFailureOnFailedSettingsLoad() const834 bool CParameterMgr::getFailureOnFailedSettingsLoad() const
835 {
836 return _bFailOnFailedSettingsLoad;
837 }
838
getSchemaUri() const839 const string &CParameterMgr::getSchemaUri() const
840 {
841 return _schemaUri;
842 }
843
setSchemaUri(const string & schemaUri)844 void CParameterMgr::setSchemaUri(const string &schemaUri)
845 {
846 _schemaUri = schemaUri;
847 }
848
setValidateSchemasOnStart(bool bValidate)849 void CParameterMgr::setValidateSchemasOnStart(bool bValidate)
850 {
851 _bValidateSchemasOnStart = bValidate;
852 }
853
getValidateSchemasOnStart() const854 bool CParameterMgr::getValidateSchemasOnStart() const
855 {
856 return _bValidateSchemasOnStart;
857 }
858
859 /////////////////// Remote command parsers
860 /// Version
versionCommandProcess(const IRemoteCommand &,string & strResult)861 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::versionCommandProcess(
862 const IRemoteCommand & /*command*/, string &strResult)
863 {
864 // Show version
865 strResult = getVersion();
866
867 return CCommandHandler::ESucceeded;
868 }
869
870 /// Status
statusCommandProcess(const IRemoteCommand &,string & strResult)871 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::statusCommandProcess(
872 const IRemoteCommand & /*command*/, string &strResult)
873 {
874 // System class
875 const CSystemClass *pSystemClass = getSystemClass();
876
877 // Show status
878 /// General section
879 utility::appendTitle(strResult, "General:");
880 // System class
881 strResult += "System Class: ";
882 strResult += pSystemClass->getName();
883 strResult += "\n";
884
885 // Tuning mode
886 strResult += "Tuning Mode: ";
887 strResult += tuningModeOn() ? "on" : "off";
888 strResult += "\n";
889
890 // Value space
891 strResult += "Value Space: ";
892 strResult += valueSpaceIsRaw() ? "raw" : "real";
893 strResult += "\n";
894
895 // Output raw format
896 strResult += "Output Raw Format: ";
897 strResult += outputRawFormatIsHex() ? "hex" : "dec";
898 strResult += "\n";
899
900 // Auto Sync
901 strResult += "Auto Sync: ";
902 strResult += autoSyncOn() ? "on" : "off";
903 strResult += "\n";
904
905 /// Subsystem list
906 utility::appendTitle(strResult, "Subsystems:");
907 string strSubsystemList;
908 pSystemClass->listChildrenPaths(strSubsystemList);
909 strResult += strSubsystemList;
910
911 /// Last applied configurations
912 utility::appendTitle(strResult, "Last Applied [Pending] Configurations:");
913 string strLastAppliedConfigurations;
914 getConfigurableDomains()->listLastAppliedConfigurations(strLastAppliedConfigurations);
915 strResult += strLastAppliedConfigurations;
916
917 /// Criteria states
918 utility::appendTitle(strResult, "Selection Criteria:");
919 list<string> lstrSelectionCriteria;
920 getSelectionCriteria()->listSelectionCriteria(lstrSelectionCriteria, false, true);
921 // Concatenate the criterion list as the command result
922 strResult += utility::asString(lstrSelectionCriteria);
923
924 return CCommandHandler::ESucceeded;
925 }
926
927 /// Tuning Mode
setTuningModeCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)928 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setTuningModeCommandProcess(
929 const IRemoteCommand &remoteCommand, string &strResult)
930 {
931 // Tuning allowed? Check done only when trying to access from python command bindings.
932 if (!getConstFrameworkConfiguration()->isTuningAllowed()) {
933
934 strResult = "Tuning prohibited";
935
936 return CCommandHandler::EFailed;
937 }
938 if (remoteCommand.getArgument(0) == "on") {
939
940 if (setTuningMode(true, strResult)) {
941
942 return CCommandHandler::EDone;
943 }
944 } else if (remoteCommand.getArgument(0) == "off") {
945
946 if (setTuningMode(false, strResult)) {
947
948 return CCommandHandler::EDone;
949 }
950 } else {
951 // Show usage
952 return CCommandHandler::EShowUsage;
953 }
954 return CCommandHandler::EFailed;
955 }
956
getTuningModeCommandProcess(const IRemoteCommand &,string & strResult)957 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getTuningModeCommandProcess(
958 const IRemoteCommand & /*command*/, string &strResult)
959 {
960 strResult = tuningModeOn() ? "on" : "off";
961
962 return CCommandHandler::ESucceeded;
963 }
964
965 /// Value Space
setValueSpaceCommandProcess(const IRemoteCommand & remoteCommand,string &)966 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setValueSpaceCommandProcess(
967 const IRemoteCommand &remoteCommand, string & /*strResult*/)
968 {
969 if (remoteCommand.getArgument(0) == "raw") {
970
971 setValueSpace(true);
972
973 return CCommandHandler::EDone;
974
975 } else if (remoteCommand.getArgument(0) == "real") {
976
977 setValueSpace(false);
978
979 return CCommandHandler::EDone;
980
981 } else {
982 // Show usage
983 return CCommandHandler::EShowUsage;
984 }
985 return CCommandHandler::EFailed;
986 }
987
getValueSpaceCommandProcess(const IRemoteCommand &,string & strResult)988 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getValueSpaceCommandProcess(
989 const IRemoteCommand & /*command*/, string &strResult)
990 {
991 strResult = valueSpaceIsRaw() ? "raw" : "real";
992
993 return CCommandHandler::ESucceeded;
994 }
995
996 /// Output Raw Format
setOutputRawFormatCommandProcess(const IRemoteCommand & remoteCommand,string &)997 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setOutputRawFormatCommandProcess(
998 const IRemoteCommand &remoteCommand, string & /*strResult*/)
999 {
1000 if (remoteCommand.getArgument(0) == "hex") {
1001
1002 setOutputRawFormat(true);
1003
1004 return CCommandHandler::EDone;
1005
1006 } else if (remoteCommand.getArgument(0) == "dec") {
1007
1008 setOutputRawFormat(false);
1009
1010 return CCommandHandler::EDone;
1011
1012 } else {
1013 // Show usage
1014 return CCommandHandler::EShowUsage;
1015 }
1016 return CCommandHandler::EFailed;
1017 }
1018
getOutputRawFormatCommandProcess(const IRemoteCommand &,string & strResult)1019 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getOutputRawFormatCommandProcess(
1020 const IRemoteCommand & /*command*/, string &strResult)
1021 {
1022 strResult = outputRawFormatIsHex() ? "hex" : "dec";
1023
1024 return CCommandHandler::ESucceeded;
1025 }
1026
1027 /// Sync
setAutoSyncCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1028 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setAutoSyncCommandProcess(
1029 const IRemoteCommand &remoteCommand, string &strResult)
1030 {
1031 if (remoteCommand.getArgument(0) == "on") {
1032
1033 if (setAutoSync(true, strResult)) {
1034
1035 return CCommandHandler::EDone;
1036 }
1037 } else if (remoteCommand.getArgument(0) == "off") {
1038
1039 if (setAutoSync(false, strResult)) {
1040
1041 return CCommandHandler::EDone;
1042 }
1043 } else {
1044 // Show usage
1045 return CCommandHandler::EShowUsage;
1046 }
1047 return CCommandHandler::EFailed;
1048 }
1049
getAutoSyncCommandProcess(const IRemoteCommand &,string & strResult)1050 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getAutoSyncCommandProcess(
1051 const IRemoteCommand & /*command*/, string &strResult)
1052 {
1053 strResult = autoSyncOn() ? "on" : "off";
1054
1055 return CCommandHandler::ESucceeded;
1056 }
1057
syncCommandProcess(const IRemoteCommand &,string & strResult)1058 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::syncCommandProcess(
1059 const IRemoteCommand &, string &strResult)
1060 {
1061 return sync(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1062 }
1063
1064 /// Criteria
listCriteriaCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1065 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listCriteriaCommandProcess(
1066 const IRemoteCommand &remoteCommand, string &strResult)
1067 {
1068 if (remoteCommand.getArgumentCount() > 1) {
1069
1070 return CCommandHandler::EShowUsage;
1071 }
1072
1073 string strOutputFormat;
1074
1075 // Look for optional arguments
1076 if (remoteCommand.getArgumentCount() == 1) {
1077
1078 // Get requested format
1079 strOutputFormat = remoteCommand.getArgument(0);
1080
1081 // Capitalize
1082 std::transform(strOutputFormat.begin(), strOutputFormat.end(), strOutputFormat.begin(),
1083 ::toupper);
1084
1085 if (strOutputFormat != "XML" && strOutputFormat != "CSV") {
1086
1087 return CCommandHandler::EShowUsage;
1088 }
1089 }
1090
1091 if (strOutputFormat == "XML") {
1092 // Get Root element where to export from
1093 const CSelectionCriteriaDefinition *pSelectionCriteriaDefinition =
1094 getConstSelectionCriteria()->getSelectionCriteriaDefinition();
1095
1096 if (!exportElementToXMLString(pSelectionCriteriaDefinition, "SelectionCriteria",
1097 CXmlSerializingContext{strResult}, strResult)) {
1098
1099 return CCommandHandler::EFailed;
1100 }
1101
1102 // Succeeded
1103 return CCommandHandler::ESucceeded;
1104 } else {
1105
1106 // Requested format will be either CSV or human readable based on strOutputFormat content
1107 bool bHumanReadable = strOutputFormat.empty();
1108
1109 list<string> lstrResult;
1110 getSelectionCriteria()->listSelectionCriteria(lstrResult, true, bHumanReadable);
1111
1112 // Concatenate the criterion list as the command result
1113 strResult += utility::asString(lstrResult);
1114
1115 return CCommandHandler::ESucceeded;
1116 }
1117 }
1118
1119 /// Domains
listDomainsCommandProcess(const IRemoteCommand &,string & strResult)1120 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainsCommandProcess(
1121 const IRemoteCommand & /*command*/, string &strResult)
1122 {
1123 getConfigurableDomains()->listDomains(strResult);
1124
1125 return CCommandHandler::ESucceeded;
1126 }
1127
createDomainCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1128 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createDomainCommandProcess(
1129 const IRemoteCommand &remoteCommand, string &strResult)
1130 {
1131 return createDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone
1132 : CCommandHandler::EFailed;
1133 }
1134
deleteDomainCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1135 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteDomainCommandProcess(
1136 const IRemoteCommand &remoteCommand, string &strResult)
1137 {
1138 return deleteDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone
1139 : CCommandHandler::EFailed;
1140 }
1141
deleteAllDomainsCommandProcess(const IRemoteCommand &,string & strResult)1142 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteAllDomainsCommandProcess(
1143 const IRemoteCommand & /*command*/, string &strResult)
1144 {
1145 return deleteAllDomains(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
1146 }
1147
renameDomainCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1148 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameDomainCommandProcess(
1149 const IRemoteCommand &remoteCommand, string &strResult)
1150 {
1151 return renameDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult)
1152 ? CCommandHandler::EDone
1153 : CCommandHandler::EFailed;
1154 }
1155
setSequenceAwarenessCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1156 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setSequenceAwarenessCommandProcess(
1157 const IRemoteCommand &remoteCommand, string &strResult)
1158 {
1159 // Set property
1160 bool bSequenceAware;
1161
1162 if (remoteCommand.getArgument(1) == "true") {
1163
1164 bSequenceAware = true;
1165
1166 } else if (remoteCommand.getArgument(1) == "false") {
1167
1168 bSequenceAware = false;
1169
1170 } else {
1171 // Show usage
1172 return CCommandHandler::EShowUsage;
1173 }
1174
1175 return setSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult)
1176 ? CCommandHandler::EDone
1177 : CCommandHandler::EFailed;
1178 }
1179
getSequenceAwarenessCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1180 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getSequenceAwarenessCommandProcess(
1181 const IRemoteCommand &remoteCommand, string &strResult)
1182 {
1183 // Get property
1184 bool bSequenceAware;
1185
1186 if (!getSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult)) {
1187
1188 return CCommandHandler::EFailed;
1189 }
1190
1191 strResult = bSequenceAware ? "true" : "false";
1192
1193 return CCommandHandler::ESucceeded;
1194 }
1195
listDomainElementsCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1196 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainElementsCommandProcess(
1197 const IRemoteCommand &remoteCommand, string &strResult)
1198 {
1199 return getConfigurableDomains()->listDomainElements(remoteCommand.getArgument(0), strResult)
1200 ? CCommandHandler::ESucceeded
1201 : CCommandHandler::EFailed;
1202 }
1203
addElementCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1204 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::addElementCommandProcess(
1205 const IRemoteCommand &remoteCommand, string &strResult)
1206 {
1207 return addConfigurableElementToDomain(remoteCommand.getArgument(0),
1208 remoteCommand.getArgument(1), strResult)
1209 ? CCommandHandler::EDone
1210 : CCommandHandler::EFailed;
1211 }
1212
removeElementCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1213 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::removeElementCommandProcess(
1214 const IRemoteCommand &remoteCommand, string &strResult)
1215 {
1216 return removeConfigurableElementFromDomain(remoteCommand.getArgument(0),
1217 remoteCommand.getArgument(1), strResult)
1218 ? CCommandHandler::EDone
1219 : CCommandHandler::EFailed;
1220 }
1221
splitDomainCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1222 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::splitDomainCommandProcess(
1223 const IRemoteCommand &remoteCommand, string &strResult)
1224 {
1225 return split(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult)
1226 ? CCommandHandler::EDone
1227 : CCommandHandler::EFailed;
1228 }
1229
1230 /// Configurations
listConfigurationsCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1231 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConfigurationsCommandProcess(
1232 const IRemoteCommand &remoteCommand, string &strResult)
1233 {
1234 return getConstConfigurableDomains()->listConfigurations(remoteCommand.getArgument(0),
1235 strResult)
1236 ? CCommandHandler::ESucceeded
1237 : CCommandHandler::EFailed;
1238 }
1239
dumpDomainsCommandProcess(const IRemoteCommand &,string & strResult)1240 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpDomainsCommandProcess(
1241 const IRemoteCommand & /*command*/, string &strResult)
1242 {
1243 // Dummy error context
1244 string strError;
1245 utility::ErrorContext errorContext(strError);
1246
1247 // Dump
1248 strResult = getConstConfigurableDomains()->dumpContent(errorContext);
1249
1250 return CCommandHandler::ESucceeded;
1251 }
1252
createConfigurationCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1253 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createConfigurationCommandProcess(
1254 const IRemoteCommand &remoteCommand, string &strResult)
1255 {
1256 return createConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1),
1257 strResult)
1258 ? CCommandHandler::EDone
1259 : CCommandHandler::EFailed;
1260 }
1261
deleteConfigurationCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1262 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteConfigurationCommandProcess(
1263 const IRemoteCommand &remoteCommand, string &strResult)
1264 {
1265 return deleteConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1),
1266 strResult)
1267 ? CCommandHandler::EDone
1268 : CCommandHandler::EFailed;
1269 }
1270
renameConfigurationCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1271 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameConfigurationCommandProcess(
1272 const IRemoteCommand &remoteCommand, string &strResult)
1273 {
1274 return renameConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1),
1275 remoteCommand.getArgument(2), strResult)
1276 ? CCommandHandler::EDone
1277 : CCommandHandler::EFailed;
1278 }
1279
saveConfigurationCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1280 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::saveConfigurationCommandProcess(
1281 const IRemoteCommand &remoteCommand, string &strResult)
1282 {
1283 return saveConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult)
1284 ? CCommandHandler::EDone
1285 : CCommandHandler::EFailed;
1286 }
1287
restoreConfigurationCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1288 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::restoreConfigurationCommandProcess(
1289 const IRemoteCommand &remoteCommand, string &strResult)
1290 {
1291 core::Results result;
1292 if (!restoreConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), result)) {
1293 // Concatenate the error list as the command result
1294 strResult = utility::asString(result);
1295
1296 return CCommandHandler::EFailed;
1297 }
1298 return CCommandHandler::EDone;
1299 }
1300
setElementSequenceCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1301 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setElementSequenceCommandProcess(
1302 const IRemoteCommand &remoteCommand, string &strResult)
1303 {
1304 // Build configurable element path list
1305 std::vector<string> astrNewElementSequence;
1306
1307 for (size_t argument = 2; argument < remoteCommand.getArgumentCount(); argument++) {
1308
1309 astrNewElementSequence.push_back(remoteCommand.getArgument(argument));
1310 }
1311
1312 // Delegate to configurable domains
1313 return setElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1),
1314 astrNewElementSequence, strResult)
1315 ? CCommandHandler::EDone
1316 : CCommandHandler::EFailed;
1317 }
1318
getElementSequenceCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1319 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSequenceCommandProcess(
1320 const IRemoteCommand &remoteCommand, string &strResult)
1321 {
1322 // Delegate to configurable domains
1323 return getConfigurableDomains()->getElementSequence(remoteCommand.getArgument(0),
1324 remoteCommand.getArgument(1), strResult)
1325 ? CCommandHandler::ESucceeded
1326 : CCommandHandler::EFailed;
1327 }
1328
setRuleCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1329 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setRuleCommandProcess(
1330 const IRemoteCommand &remoteCommand, string &strResult)
1331 {
1332 // Delegate to configurable domains
1333 return setApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1),
1334 remoteCommand.packArguments(2, remoteCommand.getArgumentCount() - 2),
1335 strResult)
1336 ? CCommandHandler::EDone
1337 : CCommandHandler::EFailed;
1338 }
1339
clearRuleCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1340 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::clearRuleCommandProcess(
1341 const IRemoteCommand &remoteCommand, string &strResult)
1342 {
1343 // Delegate to configurable domains
1344 return clearApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1),
1345 strResult)
1346 ? CCommandHandler::EDone
1347 : CCommandHandler::EFailed;
1348 }
1349
getRuleCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1350 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getRuleCommandProcess(
1351 const IRemoteCommand &remoteCommand, string &strResult)
1352 {
1353 // Delegate to configurable domains
1354 return getApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult)
1355 ? CCommandHandler::ESucceeded
1356 : CCommandHandler::EFailed;
1357 }
1358
1359 /// Elements/Parameters
listElementsCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1360 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listElementsCommandProcess(
1361 const IRemoteCommand &remoteCommand, string &strResult)
1362 {
1363 CElementLocator elementLocator(getSystemClass(), false);
1364
1365 CElement *pLocatedElement = nullptr;
1366
1367 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1368
1369 return CCommandHandler::EFailed;
1370 }
1371
1372 if (!pLocatedElement) {
1373
1374 // List from root folder
1375
1376 // Return system class qualified name
1377 pLocatedElement = getSystemClass();
1378 }
1379
1380 // Return sub-elements
1381 strResult += pLocatedElement->listQualifiedPaths(false);
1382
1383 return CCommandHandler::ESucceeded;
1384 }
1385
1386 /// Elements/Parameters
listParametersCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1387 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listParametersCommandProcess(
1388 const IRemoteCommand &remoteCommand, string &strResult)
1389 {
1390 CElementLocator elementLocator(getSystemClass(), false);
1391
1392 CElement *pLocatedElement = nullptr;
1393
1394 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1395
1396 return CCommandHandler::EFailed;
1397 }
1398
1399 if (!pLocatedElement) {
1400
1401 // List from root folder
1402
1403 // Return system class qualified name
1404 pLocatedElement = getSystemClass();
1405 }
1406
1407 // Return sub-elements
1408 strResult += pLocatedElement->listQualifiedPaths(true);
1409
1410 return CCommandHandler::ESucceeded;
1411 }
1412
getElementStructureXMLCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1413 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementStructureXMLCommandProcess(
1414 const IRemoteCommand &remoteCommand, string &strResult)
1415 {
1416 CElementLocator elementLocator(getSystemClass());
1417
1418 CElement *pLocatedElement = nullptr;
1419
1420 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1421
1422 return CCommandHandler::EFailed;
1423 }
1424
1425 // Use default access context for structure export
1426 CParameterAccessContext accessContext(strResult);
1427 if (!exportElementToXMLString(pLocatedElement, pLocatedElement->getXmlElementName(),
1428 CXmlParameterSerializingContext{accessContext, strResult},
1429 strResult)) {
1430
1431 return CCommandHandler::EFailed;
1432 }
1433
1434 return CCommandHandler::ESucceeded;
1435 }
1436
getElementBytesCommandProcess(const IRemoteCommand & remoteCommand,std::string & strResult)1437 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementBytesCommandProcess(
1438 const IRemoteCommand &remoteCommand, std::string &strResult)
1439 {
1440 CElementLocator elementLocator(getSystemClass());
1441
1442 CElement *pLocatedElement = nullptr;
1443
1444 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1445
1446 return CCommandHandler::EFailed;
1447 }
1448
1449 const CConfigurableElement *pConfigurableElement =
1450 static_cast<CConfigurableElement *>(pLocatedElement);
1451
1452 // Get the settings
1453 vector<uint8_t> bytes;
1454 getSettingsAsBytes(*pConfigurableElement, bytes);
1455
1456 // Hexa formatting
1457 std::ostringstream ostream;
1458 ostream << std::hex << std::setfill('0');
1459
1460 // Format bytes
1461 for (auto byte : bytes) {
1462
1463 // Convert to an int in order to avoid the "char" overload that would
1464 // print characters instead of numbers.
1465 ostream << "0x" << std::setw(2) << int{byte} << " ";
1466 }
1467
1468 strResult = ostream.str();
1469 if (not strResult.empty()) {
1470 // Remove the trailing space
1471 strResult.pop_back();
1472 }
1473
1474 return CCommandHandler::ESucceeded;
1475 }
1476
setElementBytesCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1477 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setElementBytesCommandProcess(
1478 const IRemoteCommand &remoteCommand, string &strResult)
1479 {
1480 // Check tuning mode
1481 if (!checkTuningModeOn(strResult)) {
1482
1483 return CCommandHandler::EFailed;
1484 }
1485
1486 // Retrieve configurable element
1487 CElementLocator elementLocator(getSystemClass());
1488
1489 CElement *pLocatedElement = nullptr;
1490
1491 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1492
1493 return CCommandHandler::EFailed;
1494 }
1495
1496 const CConfigurableElement *pConfigurableElement =
1497 static_cast<CConfigurableElement *>(pLocatedElement);
1498
1499 // Convert input data to binary
1500 vector<uint8_t> bytes;
1501
1502 auto first = remoteCommand.getArguments().cbegin() + 1;
1503 auto last = remoteCommand.getArguments().cend();
1504
1505 try {
1506 std::transform(first, last, begin(bytes), [](decltype(*first) input) {
1507 uint8_t byte;
1508
1509 if (!convertTo(input, byte)) {
1510 throw std::domain_error("Some values out of byte range");
1511 }
1512
1513 return byte;
1514 });
1515 } catch (const std::domain_error &e) {
1516 strResult = e.what();
1517
1518 return CCommandHandler::EFailed;
1519 }
1520
1521 // Set the settings
1522 if (!setSettingsAsBytes(*pConfigurableElement, bytes, strResult)) {
1523
1524 return CCommandHandler::EFailed;
1525 }
1526
1527 return CCommandHandler::EDone;
1528 }
1529
getSettingsAsXML(const CConfigurableElement * configurableElement,string & result) const1530 bool CParameterMgr::getSettingsAsXML(const CConfigurableElement *configurableElement,
1531 string &result) const
1532 {
1533 string error;
1534 CConfigurationAccessContext configContext(error, _pMainParameterBlackboard, _bValueSpaceIsRaw,
1535 _bOutputRawFormatIsHex, true);
1536
1537 CXmlParameterSerializingContext xmlParameterContext(configContext, error);
1538
1539 // Use a doc source by loading data from instantiated Configurable Domains
1540 CXmlMemoryDocSource memorySource(configurableElement, false,
1541 configurableElement->getXmlElementName());
1542
1543 // Use a doc sink that write the doc data in a string
1544 ostringstream output;
1545 CXmlStreamDocSink streamSink(output);
1546
1547 if (not streamSink.process(memorySource, xmlParameterContext)) {
1548 result = error;
1549 return false;
1550 }
1551 result = output.str();
1552 return true;
1553 }
1554
setSettingsAsXML(CConfigurableElement * configurableElement,const string & settings,string & error)1555 bool CParameterMgr::setSettingsAsXML(CConfigurableElement *configurableElement,
1556 const string &settings, string &error)
1557 {
1558 CConfigurationAccessContext configContext(error, _pMainParameterBlackboard, _bValueSpaceIsRaw,
1559 _bOutputRawFormatIsHex, false);
1560
1561 CXmlParameterSerializingContext xmlParameterContext(configContext, error);
1562
1563 // It doesn't make sense to resolve XIncludes on an imported file because
1564 // we can't reliably decide of a "base url"
1565 _xmlDoc *doc = CXmlDocSource::mkXmlDoc(settings, false, false, xmlParameterContext);
1566 if (doc == nullptr) {
1567 return false;
1568 }
1569 if (not xmlParse(xmlParameterContext, configurableElement, doc, "",
1570 EParameterConfigurationLibrary, false)) {
1571 return false;
1572 }
1573 if (_bAutoSyncOn) {
1574 CSyncerSet syncerSet;
1575 static_cast<CConfigurableElement *>(configurableElement)->fillSyncerSet(syncerSet);
1576 core::Results errors;
1577 if (not syncerSet.sync(*_pMainParameterBlackboard, false, &errors)) {
1578 error = utility::asString(errors);
1579
1580 return false;
1581 }
1582 }
1583 return true;
1584 }
1585
getElementXMLCommandProcess(const IRemoteCommand & remoteCommand,string & result)1586 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementXMLCommandProcess(
1587 const IRemoteCommand &remoteCommand, string &result)
1588 {
1589 CElementLocator elementLocator(getSystemClass());
1590
1591 CElement *locatedElement = nullptr;
1592
1593 if (not elementLocator.locate(remoteCommand.getArgument(0), &locatedElement, result)) {
1594
1595 return CCommandHandler::EFailed;
1596 }
1597
1598 if (not getSettingsAsXML(static_cast<CConfigurableElement *>(locatedElement), result)) {
1599 return CCommandHandler::EFailed;
1600 }
1601 return CCommandHandler::ESucceeded;
1602 }
1603
setElementXMLCommandProcess(const IRemoteCommand & remoteCommand,string & result)1604 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setElementXMLCommandProcess(
1605 const IRemoteCommand &remoteCommand, string &result)
1606 {
1607 if (!checkTuningModeOn(result)) {
1608
1609 return CCommandHandler::EFailed;
1610 }
1611
1612 CElementLocator elementLocator(getSystemClass());
1613
1614 CElement *locatedElement = nullptr;
1615
1616 if (not elementLocator.locate(remoteCommand.getArgument(0), &locatedElement, result)) {
1617
1618 return CCommandHandler::EFailed;
1619 }
1620 if (not setSettingsAsXML(static_cast<CConfigurableElement *>(locatedElement),
1621 remoteCommand.getArgument(1), result)) {
1622 return CCommandHandler::EFailed;
1623 }
1624 return CCommandHandler::EDone;
1625 }
1626
dumpElementCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1627 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpElementCommandProcess(
1628 const IRemoteCommand &remoteCommand, string &strResult)
1629 {
1630 CElementLocator elementLocator(getSystemClass());
1631
1632 CElement *pLocatedElement = nullptr;
1633
1634 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1635
1636 return CCommandHandler::EFailed;
1637 }
1638
1639 string strError;
1640
1641 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard,
1642 _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
1643
1644 // Dump elements
1645 strResult = pLocatedElement->dumpContent(parameterAccessContext);
1646
1647 return CCommandHandler::ESucceeded;
1648 }
1649
getElementSizeCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1650 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSizeCommandProcess(
1651 const IRemoteCommand &remoteCommand, string &strResult)
1652 {
1653 CElementLocator elementLocator(getSystemClass());
1654
1655 CElement *pLocatedElement = nullptr;
1656
1657 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1658
1659 return CCommandHandler::EFailed;
1660 }
1661
1662 // Converted to actual sizable element
1663 const CConfigurableElement *pConfigurableElement =
1664 static_cast<const CConfigurableElement *>(pLocatedElement);
1665
1666 // Get size as string
1667 strResult = pConfigurableElement->getFootprintAsString();
1668
1669 return CCommandHandler::ESucceeded;
1670 }
1671
showPropertiesCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1672 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showPropertiesCommandProcess(
1673 const IRemoteCommand &remoteCommand, string &strResult)
1674 {
1675 CElementLocator elementLocator(getSystemClass());
1676
1677 CElement *pLocatedElement = nullptr;
1678
1679 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1680
1681 return CCommandHandler::EFailed;
1682 }
1683
1684 // Convert element
1685 const CConfigurableElement *pConfigurableElement =
1686 static_cast<const CConfigurableElement *>(pLocatedElement);
1687
1688 // Return element properties
1689 pConfigurableElement->showProperties(strResult);
1690
1691 return CCommandHandler::ESucceeded;
1692 }
1693
getParameterCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1694 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getParameterCommandProcess(
1695 const IRemoteCommand &remoteCommand, string &strResult)
1696 {
1697 string strValue;
1698
1699 if (!accessParameterValue(remoteCommand.getArgument(0), strValue, false, strResult)) {
1700
1701 return CCommandHandler::EFailed;
1702 }
1703 // Succeeded
1704 strResult = strValue;
1705
1706 return CCommandHandler::ESucceeded;
1707 }
1708
setParameterCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1709 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setParameterCommandProcess(
1710 const IRemoteCommand &remoteCommand, string &strResult)
1711 {
1712 // Get value to set
1713 string strValue = remoteCommand.packArguments(1, remoteCommand.getArgumentCount() - 1);
1714
1715 return accessParameterValue(remoteCommand.getArgument(0), strValue, true, strResult)
1716 ? CCommandHandler::EDone
1717 : CCommandHandler::EFailed;
1718 }
1719
listBelongingDomainsCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1720 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listBelongingDomainsCommandProcess(
1721 const IRemoteCommand &remoteCommand, string &strResult)
1722 {
1723 CElementLocator elementLocator(getSystemClass());
1724
1725 CElement *pLocatedElement = nullptr;
1726
1727 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1728
1729 return CCommandHandler::EFailed;
1730 }
1731
1732 // Convert element
1733 const CConfigurableElement *pConfigurableElement =
1734 static_cast<const CConfigurableElement *>(pLocatedElement);
1735
1736 // Return element belonging domains
1737 pConfigurableElement->listBelongingDomains(strResult);
1738
1739 return CCommandHandler::ESucceeded;
1740 }
1741
listAssociatedDomainsCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1742 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedDomainsCommandProcess(
1743 const IRemoteCommand &remoteCommand, string &strResult)
1744 {
1745 CElementLocator elementLocator(getSystemClass());
1746
1747 CElement *pLocatedElement = nullptr;
1748
1749 if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
1750
1751 return CCommandHandler::EFailed;
1752 }
1753
1754 // Convert element
1755 const CConfigurableElement *pConfigurableElement =
1756 static_cast<const CConfigurableElement *>(pLocatedElement);
1757
1758 // Return element belonging domains
1759 pConfigurableElement->listAssociatedDomains(strResult);
1760
1761 return CCommandHandler::ESucceeded;
1762 }
1763
listAssociatedElementsCommandProcess(const IRemoteCommand &,string & strResult)1764 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedElementsCommandProcess(
1765 const IRemoteCommand & /*command*/, string &strResult)
1766 {
1767 getConfigurableDomains()->listAssociatedElements(strResult);
1768
1769 return CCommandHandler::ESucceeded;
1770 }
1771
listConflictingElementsCommandProcess(const IRemoteCommand &,string & strResult)1772 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConflictingElementsCommandProcess(
1773 const IRemoteCommand & /*command*/, string &strResult)
1774 {
1775 getConfigurableDomains()->listConflictingElements(strResult);
1776
1777 return CCommandHandler::ESucceeded;
1778 }
1779
listRogueElementsCommandProcess(const IRemoteCommand &,string & strResult)1780 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listRogueElementsCommandProcess(
1781 const IRemoteCommand & /*command*/, string &strResult)
1782 {
1783 getSystemClass()->listRogueElements(strResult);
1784
1785 return CCommandHandler::ESucceeded;
1786 }
1787
1788 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::
getConfigurationParameterCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1789 getConfigurationParameterCommandProcess(const IRemoteCommand &remoteCommand, string &strResult)
1790 {
1791 string strOutputValue;
1792 string strError;
1793
1794 if (!accessConfigurationValue(remoteCommand.getArgument(0), remoteCommand.getArgument(1),
1795 remoteCommand.getArgument(2), strOutputValue, false, strError)) {
1796
1797 strResult = strError;
1798 return CCommandHandler::EFailed;
1799 }
1800 // Succeeded
1801 strResult = strOutputValue;
1802
1803 return CCommandHandler::ESucceeded;
1804 }
1805
1806 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::
setConfigurationParameterCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1807 setConfigurationParameterCommandProcess(const IRemoteCommand &remoteCommand, string &strResult)
1808 {
1809 // Get value to set
1810 string strValue = remoteCommand.packArguments(3, remoteCommand.getArgumentCount() - 3);
1811
1812 bool bSuccess =
1813 accessConfigurationValue(remoteCommand.getArgument(0), remoteCommand.getArgument(1),
1814 remoteCommand.getArgument(2), strValue, true, strResult);
1815
1816 return bSuccess ? CCommandHandler::EDone : CCommandHandler::EFailed;
1817 }
1818
showMappingCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1819 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showMappingCommandProcess(
1820 const IRemoteCommand &remoteCommand, string &strResult)
1821 {
1822 if (!getParameterMapping(remoteCommand.getArgument(0), strResult)) {
1823
1824 return CCommandHandler::EFailed;
1825 }
1826
1827 return CCommandHandler::ESucceeded;
1828 }
1829
1830 /// Settings Import/Export
exportDomainsXMLCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1831 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportDomainsXMLCommandProcess(
1832 const IRemoteCommand &remoteCommand, string &strResult)
1833 {
1834 string strFileName = remoteCommand.getArgument(0);
1835 return exportDomainsXml(strFileName, false, true, strResult) ? CCommandHandler::EDone
1836 : CCommandHandler::EFailed;
1837 }
1838
importDomainsXMLCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1839 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importDomainsXMLCommandProcess(
1840 const IRemoteCommand &remoteCommand, string &strResult)
1841 {
1842 return importDomainsXml(remoteCommand.getArgument(0), false, true, strResult)
1843 ? CCommandHandler::EDone
1844 : CCommandHandler::EFailed;
1845 }
1846
1847 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::
exportDomainsWithSettingsXMLCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1848 exportDomainsWithSettingsXMLCommandProcess(const IRemoteCommand &remoteCommand,
1849 string &strResult)
1850 {
1851 string strFileName = remoteCommand.getArgument(0);
1852 return exportDomainsXml(strFileName, true, true, strResult) ? CCommandHandler::EDone
1853 : CCommandHandler::EFailed;
1854 }
1855
1856 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::
exportDomainWithSettingsXMLCommandProcess(const IRemoteCommand & remoteCommand,string & result)1857 exportDomainWithSettingsXMLCommandProcess(const IRemoteCommand &remoteCommand, string &result)
1858 {
1859 string domainName = remoteCommand.getArgument(0);
1860 string fileName = remoteCommand.getArgument(1);
1861 return exportSingleDomainXml(fileName, domainName, true, true, result)
1862 ? CCommandHandler::EDone
1863 : CCommandHandler::EFailed;
1864 }
1865
1866 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::
importDomainsWithSettingsXMLCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1867 importDomainsWithSettingsXMLCommandProcess(const IRemoteCommand &remoteCommand,
1868 string &strResult)
1869 {
1870 return importDomainsXml(remoteCommand.getArgument(0), true, true, strResult)
1871 ? CCommandHandler::EDone
1872 : CCommandHandler::EFailed;
1873 }
1874
1875 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::
importDomainWithSettingsXMLCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1876 importDomainWithSettingsXMLCommandProcess(const IRemoteCommand &remoteCommand,
1877 string &strResult)
1878 {
1879 bool bOverwrite = false;
1880
1881 // Look for optional arguments
1882 if (remoteCommand.getArgumentCount() > 1) {
1883
1884 if (remoteCommand.getArgument(1) == "overwrite") {
1885
1886 bOverwrite = true;
1887 } else {
1888 // Show usage
1889 return CCommandHandler::EShowUsage;
1890 }
1891 }
1892
1893 return importSingleDomainXml(remoteCommand.getArgument(0), bOverwrite, true, true, strResult)
1894 ? CCommandHandler::EDone
1895 : CCommandHandler::EFailed;
1896 }
1897
1898 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::
getDomainsWithSettingsXMLCommandProcess(const IRemoteCommand &,string & strResult)1899 getDomainsWithSettingsXMLCommandProcess(const IRemoteCommand & /*command*/, string &strResult)
1900 {
1901 if (!exportDomainsXml(strResult, true, false, strResult)) {
1902
1903 return CCommandHandler::EFailed;
1904 }
1905 // Succeeded
1906 return CCommandHandler::ESucceeded;
1907 }
1908
getDomainWithSettingsXMLCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1909 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getDomainWithSettingsXMLCommandProcess(
1910 const IRemoteCommand &remoteCommand, string &strResult)
1911 {
1912 string strDomainName = remoteCommand.getArgument(0);
1913
1914 return exportSingleDomainXml(strResult, strDomainName, true, false, strResult)
1915 ? CCommandHandler::ESucceeded
1916 : CCommandHandler::EFailed;
1917 }
1918
1919 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::
setDomainsWithSettingsXMLCommandProcess(const IRemoteCommand & remoteCommand,string & strResult)1920 setDomainsWithSettingsXMLCommandProcess(const IRemoteCommand &remoteCommand, string &strResult)
1921 {
1922 return importDomainsXml(remoteCommand.getArgument(0), true, false, strResult)
1923 ? CCommandHandler::EDone
1924 : CCommandHandler::EFailed;
1925 }
1926
setDomainWithSettingsXMLCommandProcess(const IRemoteCommand & remoteCommand,string & result)1927 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setDomainWithSettingsXMLCommandProcess(
1928 const IRemoteCommand &remoteCommand, string &result)
1929 {
1930 bool overwrite = false;
1931
1932 if (remoteCommand.getArgumentCount() > 1) {
1933
1934 if (remoteCommand.getArgument(1) == "overwrite") {
1935
1936 overwrite = true;
1937 } else {
1938 // Show usage
1939 return CCommandHandler::EShowUsage;
1940 }
1941 }
1942
1943 return importSingleDomainXml(remoteCommand.getArgument(0), overwrite, true, false, result)
1944 ? CCommandHandler::EDone
1945 : CCommandHandler::EFailed;
1946 }
1947
getSystemClassXMLCommandProcess(const IRemoteCommand &,string & strResult)1948 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getSystemClassXMLCommandProcess(
1949 const IRemoteCommand & /*command*/, string &strResult)
1950 {
1951 // Get Root element where to export from
1952 const CSystemClass *pSystemClass = getSystemClass();
1953
1954 // Use default access context for structure export
1955 CParameterAccessContext accessContext(strResult);
1956 if (!exportElementToXMLString(pSystemClass, pSystemClass->getXmlElementName(),
1957 CXmlParameterSerializingContext{accessContext, strResult},
1958 strResult)) {
1959 return CCommandHandler::EFailed;
1960 }
1961 // Succeeded
1962 return CCommandHandler::ESucceeded;
1963 }
1964
1965 // User set/get parameters in main BlackBoard
accessParameterValue(const string & strPath,string & strValue,bool bSet,string & strError)1966 bool CParameterMgr::accessParameterValue(const string &strPath, string &strValue, bool bSet,
1967 string &strError)
1968 {
1969 // Forbid write access when not in TuningMode
1970 if (bSet && !checkTuningModeOn(strError)) {
1971
1972 return false;
1973 }
1974
1975 // Define context
1976 CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard,
1977 _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
1978
1979 // Activate the auto synchronization with the hardware
1980 if (bSet) {
1981
1982 parameterAccessContext.setAutoSync(_bAutoSyncOn);
1983 }
1984
1985 return accessValue(parameterAccessContext, strPath, strValue, bSet, strError);
1986 }
1987
1988 // User get parameter mapping
getParameterMapping(const string & strPath,string & strResult) const1989 bool CParameterMgr::getParameterMapping(const string &strPath, string &strResult) const
1990 {
1991 // Get the ConfigurableElement corresponding to strPath
1992 const CConfigurableElement *pConfigurableElement = getConfigurableElement(strPath, strResult);
1993 if (!pConfigurableElement) {
1994
1995 return false;
1996 }
1997
1998 // Find the list of the ancestors of the current ConfigurableElement that have a mapping
1999 auto configurableElementPath = pConfigurableElement->getConfigurableElementContext();
2000
2001 // Get the Subsystem containing the ConfigurableElement
2002 const CSubsystem *pSubsystem = pConfigurableElement->getBelongingSubsystem();
2003 if (!pSubsystem) {
2004
2005 strResult = "Unable to find the Subsystem containing the parameter";
2006 return false;
2007 }
2008
2009 // Fetch the mapping corresponding to the ConfigurableElement
2010 strResult = pSubsystem->getMapping(configurableElementPath);
2011
2012 return true;
2013 }
2014
2015 // User set/get parameters in specific Configuration BlackBoard
accessConfigurationValue(const string & strDomain,const string & strConfiguration,const string & strPath,string & strValue,bool bSet,string & strError)2016 bool CParameterMgr::accessConfigurationValue(const string &strDomain,
2017 const string &strConfiguration, const string &strPath,
2018 string &strValue, bool bSet, string &strError)
2019 {
2020 CElementLocator elementLocator(getSystemClass());
2021
2022 CElement *pLocatedElement = nullptr;
2023
2024 if (!elementLocator.locate(strPath, &pLocatedElement, strError)) {
2025
2026 return false;
2027 }
2028
2029 // Convert element
2030 const CConfigurableElement *pConfigurableElement =
2031 static_cast<const CConfigurableElement *>(pLocatedElement);
2032
2033 // Get the Configuration blackboard and the Base Offset of the configurable element in this
2034 // blackboard
2035 size_t baseOffset;
2036 bool bIsLastApplied;
2037
2038 CParameterBlackboard *pConfigurationBlackboard = nullptr;
2039
2040 {
2041 pConfigurationBlackboard = getConstConfigurableDomains()->findConfigurationBlackboard(
2042 strDomain, strConfiguration, pConfigurableElement, baseOffset, bIsLastApplied,
2043 strError);
2044 if (!pConfigurationBlackboard) {
2045
2046 warning() << "Fail: " << strError;
2047 return false;
2048 }
2049 }
2050
2051 info() << "Element " << strPath << " in Domain " << strDomain
2052 << ", offset: " << pConfigurableElement->getOffset() << ", base offset: " << baseOffset;
2053
2054 /// Update the Configuration Blackboard
2055
2056 // Define Configuration context using Base Offset and keep Auto Sync off to prevent access to HW
2057 CParameterAccessContext parameterAccessContext(
2058 strError, pConfigurationBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex, baseOffset);
2059
2060 // Deactivate the auto synchronization with the hardware during the Configuration Blackboard
2061 // access (only Main Blackboard shall be synchronized, Configurations Blackboards are copied
2062 // into the Main Blackboard each time a configuration is restored but they are not synchronized
2063 // directly).
2064 if (bSet) {
2065
2066 parameterAccessContext.setAutoSync(false);
2067 }
2068
2069 // Access Value in the Configuration Blackboard
2070 if (!accessValue(parameterAccessContext, strPath, strValue, bSet, strError)) {
2071
2072 return false;
2073 }
2074
2075 /// If the Configuration is the last one applied, update the Main Blackboard as well
2076
2077 if (bIsLastApplied) {
2078
2079 // Define Main context
2080 parameterAccessContext.setParameterBlackboard(_pMainParameterBlackboard);
2081
2082 // Activate the auto synchronization with the hardware
2083 if (bSet) {
2084
2085 parameterAccessContext.setAutoSync(_bAutoSyncOn);
2086 }
2087
2088 // Access Value in the Main Blackboard
2089 return accessValue(parameterAccessContext, strPath, strValue, bSet, strError);
2090 }
2091
2092 return true;
2093 }
2094
2095 // User set/get parameters
accessValue(CParameterAccessContext & parameterAccessContext,const string & strPath,string & strValue,bool bSet,string & strError)2096 bool CParameterMgr::accessValue(CParameterAccessContext ¶meterAccessContext,
2097 const string &strPath, string &strValue, bool bSet,
2098 string &strError)
2099 {
2100 // Lock state
2101 lock_guard<mutex> autoLock(getBlackboardMutex());
2102
2103 CPathNavigator pathNavigator(strPath);
2104
2105 // Nagivate through system class
2106 if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
2107
2108 parameterAccessContext.setError(strError);
2109
2110 return false;
2111 }
2112
2113 // Do the get
2114 return getConstSystemClass()->accessValue(pathNavigator, strValue, bSet,
2115 parameterAccessContext);
2116 }
2117
2118 // Tuning mode
setTuningMode(bool bOn,string & strError)2119 bool CParameterMgr::setTuningMode(bool bOn, string &strError)
2120 {
2121 if (bOn == tuningModeOn()) {
2122 strError = "Tuning mode is already in the state requested";
2123 return false;
2124 }
2125 // Lock state
2126 lock_guard<mutex> autoLock(getBlackboardMutex());
2127
2128 // Warn domains about exiting tuning mode
2129 if (!bOn) {
2130
2131 // Ensure application of currently selected configurations
2132 // Force-apply configurations
2133 doApplyConfigurations(true);
2134 }
2135
2136 // Store
2137 _bTuningModeIsOn = bOn;
2138
2139 return true;
2140 }
2141
tuningModeOn() const2142 bool CParameterMgr::tuningModeOn() const
2143 {
2144 return _bTuningModeIsOn;
2145 }
2146
2147 // Current value space for user set/get value interpretation
setValueSpace(bool bIsRaw)2148 void CParameterMgr::setValueSpace(bool bIsRaw)
2149 {
2150 _bValueSpaceIsRaw = bIsRaw;
2151 }
2152
valueSpaceIsRaw()2153 bool CParameterMgr::valueSpaceIsRaw()
2154 {
2155 return _bValueSpaceIsRaw;
2156 }
2157
2158 // Current Output Raw Format for user get value interpretation
setOutputRawFormat(bool bIsHex)2159 void CParameterMgr::setOutputRawFormat(bool bIsHex)
2160 {
2161 _bOutputRawFormatIsHex = bIsHex;
2162 }
2163
outputRawFormatIsHex()2164 bool CParameterMgr::outputRawFormatIsHex()
2165 {
2166 return _bOutputRawFormatIsHex;
2167 }
2168
2169 /// Sync
2170 // Automatic hardware synchronization control (during tuning session)
setAutoSync(bool bAutoSyncOn,string & strError)2171 bool CParameterMgr::setAutoSync(bool bAutoSyncOn, string &strError)
2172 {
2173 // Warn domains about turning auto sync back on
2174 if (bAutoSyncOn && !_bAutoSyncOn) {
2175
2176 // Do the synchronization at system class level (could be optimized by keeping track of all
2177 // modified parameters)
2178 if (!sync(strError)) {
2179
2180 return false;
2181 }
2182 }
2183
2184 // Set Auto sync
2185 _bAutoSyncOn = bAutoSyncOn;
2186
2187 return true;
2188 }
2189
autoSyncOn() const2190 bool CParameterMgr::autoSyncOn() const
2191 {
2192 return _bAutoSyncOn;
2193 }
2194
2195 // Manual hardware synchronization control (during tuning session)
sync(string & strError)2196 bool CParameterMgr::sync(string &strError)
2197 {
2198 // Warn domains about turning auto sync back on
2199 if (_bAutoSyncOn) {
2200
2201 strError = "Feature unavailable when Auto Sync is on";
2202
2203 return false;
2204 }
2205
2206 // Get syncer set
2207 CSyncerSet syncerSet;
2208 // ... from system class
2209 getConstSystemClass()->fillSyncerSet(syncerSet);
2210
2211 // Sync
2212 core::Results error;
2213 if (!syncerSet.sync(*_pMainParameterBlackboard, false, &error)) {
2214
2215 strError = utility::asString(error);
2216 return false;
2217 };
2218
2219 return true;
2220 }
2221
2222 // Configuration/Domains handling
createDomain(const string & strName,string & strError)2223 bool CParameterMgr::createDomain(const string &strName, string &strError)
2224 {
2225 LOG_CONTEXT("Creating configurable domain " + strName);
2226 // Check tuning mode
2227 if (!checkTuningModeOn(strError)) {
2228
2229 return false;
2230 }
2231
2232 // Delegate to configurable domains
2233 return logResult(getConfigurableDomains()->createDomain(strName, strError), strError);
2234 }
2235
deleteDomain(const string & strName,string & strError)2236 bool CParameterMgr::deleteDomain(const string &strName, string &strError)
2237 {
2238 LOG_CONTEXT("Deleting configurable domain '" + strName + "'");
2239
2240 // Check tuning mode
2241 if (!checkTuningModeOn(strError)) {
2242
2243 warning() << "Fail: " << strError;
2244 return false;
2245 }
2246
2247 // Delegate to configurable domains
2248 return logResult(getConfigurableDomains()->deleteDomain(strName, strError), strError);
2249 }
2250
renameDomain(const string & strName,const string & strNewName,string & strError)2251 bool CParameterMgr::renameDomain(const string &strName, const string &strNewName, string &strError)
2252 {
2253 LOG_CONTEXT("Renaming configurable domain '" + strName + "' to '" + strNewName + "'");
2254
2255 // Delegate to configurable domains
2256 return logResult(getConfigurableDomains()->renameDomain(strName, strNewName, strError),
2257 strError);
2258 }
2259
deleteAllDomains(string & strError)2260 bool CParameterMgr::deleteAllDomains(string &strError)
2261 {
2262 LOG_CONTEXT("Deleting all configurable domains");
2263
2264 // Check tuning mode
2265 if (!checkTuningModeOn(strError)) {
2266
2267 warning() << "Fail: " << strError;
2268 return false;
2269 }
2270
2271 // Delegate to configurable domains
2272 getConfigurableDomains()->deleteAllDomains();
2273
2274 info() << "Success";
2275 return true;
2276 }
2277
setSequenceAwareness(const string & strName,bool bSequenceAware,string & strResult)2278 bool CParameterMgr::setSequenceAwareness(const string &strName, bool bSequenceAware,
2279 string &strResult)
2280 {
2281 LOG_CONTEXT("Making domain '" + strName + "' sequence " +
2282 (bSequenceAware ? "aware" : "unaware"));
2283 // Check tuning mode
2284 if (!checkTuningModeOn(strResult)) {
2285
2286 warning() << "Fail: " << strResult;
2287 return false;
2288 }
2289
2290 return logResult(
2291 getConfigurableDomains()->setSequenceAwareness(strName, bSequenceAware, strResult),
2292 strResult);
2293 }
2294
getSequenceAwareness(const string & strName,bool & bSequenceAware,string & strResult)2295 bool CParameterMgr::getSequenceAwareness(const string &strName, bool &bSequenceAware,
2296 string &strResult)
2297 {
2298 return getConfigurableDomains()->getSequenceAwareness(strName, bSequenceAware, strResult);
2299 }
2300
createConfiguration(const string & strDomain,const string & strConfiguration,string & strError)2301 bool CParameterMgr::createConfiguration(const string &strDomain, const string &strConfiguration,
2302 string &strError)
2303 {
2304 LOG_CONTEXT("Creating domain configuration '" + strConfiguration + "' into domain '" +
2305 strDomain + "'");
2306 // Check tuning mode
2307 if (!checkTuningModeOn(strError)) {
2308
2309 warning() << "Fail: " << strError;
2310 return false;
2311 }
2312
2313 // Delegate to configurable domains
2314 return logResult(getConfigurableDomains()->createConfiguration(
2315 strDomain, strConfiguration, _pMainParameterBlackboard, strError),
2316 strError);
2317 }
renameConfiguration(const string & strDomain,const string & strConfiguration,const string & strNewConfiguration,string & strError)2318 bool CParameterMgr::renameConfiguration(const string &strDomain, const string &strConfiguration,
2319 const string &strNewConfiguration, string &strError)
2320 {
2321 LOG_CONTEXT("Renaming domain '" + strDomain + "''s configuration '" + strConfiguration +
2322 "' to '" + strNewConfiguration + "'");
2323
2324 return logResult(getConfigurableDomains()->renameConfiguration(strDomain, strConfiguration,
2325 strNewConfiguration, strError),
2326 strError);
2327 }
2328
deleteConfiguration(const string & strDomain,const string & strConfiguration,string & strError)2329 bool CParameterMgr::deleteConfiguration(const string &strDomain, const string &strConfiguration,
2330 string &strError)
2331 {
2332 LOG_CONTEXT("Deleting configuration '" + strConfiguration + "' from domain '" + strDomain +
2333 "'");
2334
2335 // Check tuning mode
2336 if (!checkTuningModeOn(strError)) {
2337
2338 warning() << "Fail:" << strError;
2339 return false;
2340 }
2341
2342 // Delegate to configurable domains
2343 return logResult(
2344 getConfigurableDomains()->deleteConfiguration(strDomain, strConfiguration, strError),
2345 strError);
2346 }
2347
restoreConfiguration(const string & strDomain,const string & strConfiguration,core::Results & errors)2348 bool CParameterMgr::restoreConfiguration(const string &strDomain, const string &strConfiguration,
2349 core::Results &errors)
2350 {
2351 string strError;
2352 LOG_CONTEXT("Restoring domain '" + strDomain + "''s configuration '" + strConfiguration +
2353 "' to parameter blackboard");
2354 // Check tuning mode
2355 if (!checkTuningModeOn(strError)) {
2356
2357 errors.push_back(strError);
2358 warning() << "Fail:" << strError;
2359 return false;
2360 }
2361
2362 // Delegate to configurable domains
2363 return logResult(
2364 getConstConfigurableDomains()->restoreConfiguration(
2365 strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, errors),
2366 strError);
2367 }
2368
saveConfiguration(const string & strDomain,const string & strConfiguration,string & strError)2369 bool CParameterMgr::saveConfiguration(const string &strDomain, const string &strConfiguration,
2370 string &strError)
2371 {
2372 LOG_CONTEXT("Saving domain '" + strDomain + "' configuration '" + strConfiguration +
2373 "' from parameter blackboard");
2374 // Check tuning mode
2375 if (!checkTuningModeOn(strError)) {
2376
2377 warning() << "Fail:" << strError;
2378 return false;
2379 }
2380
2381 // Delegate to configurable domains
2382 return logResult(getConfigurableDomains()->saveConfiguration(
2383 strDomain, strConfiguration, _pMainParameterBlackboard, strError),
2384 strError);
2385 }
2386
2387 // Configurable element - domain association
addConfigurableElementToDomain(const string & strDomain,const string & strConfigurableElementPath,string & strError)2388 bool CParameterMgr::addConfigurableElementToDomain(const string &strDomain,
2389 const string &strConfigurableElementPath,
2390 string &strError)
2391 {
2392 LOG_CONTEXT("Adding configurable element '" + strConfigurableElementPath + "' to domain '" +
2393 strDomain + "'");
2394 // Check tuning mode
2395 if (!checkTuningModeOn(strError)) {
2396
2397 warning() << "Fail: " << strError;
2398 return false;
2399 }
2400
2401 CElementLocator elementLocator(getSystemClass());
2402
2403 CElement *pLocatedElement = nullptr;
2404
2405 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
2406
2407 warning() << "Fail: " << strError;
2408 return false;
2409 }
2410
2411 // Convert element
2412 CConfigurableElement *pConfigurableElement =
2413 static_cast<CConfigurableElement *>(pLocatedElement);
2414
2415 // Delegate
2416 core::Results infos;
2417 bool isSuccess = getConfigurableDomains()->addConfigurableElementToDomain(
2418 strDomain, pConfigurableElement, _pMainParameterBlackboard, infos);
2419
2420 if (isSuccess) {
2421 info() << infos;
2422 } else {
2423 warning() << infos;
2424 }
2425
2426 strError = utility::asString(infos);
2427 return isSuccess;
2428 }
2429
removeConfigurableElementFromDomain(const string & strDomain,const string & strConfigurableElementPath,string & strError)2430 bool CParameterMgr::removeConfigurableElementFromDomain(const string &strDomain,
2431 const string &strConfigurableElementPath,
2432 string &strError)
2433 {
2434 LOG_CONTEXT("Removing configurable element '" + strConfigurableElementPath + "' from domain '" +
2435 strDomain + "'");
2436
2437 // Check tuning mode
2438 if (!checkTuningModeOn(strError)) {
2439
2440 warning() << "Fail:" << strError;
2441 return false;
2442 }
2443
2444 CElementLocator elementLocator(getSystemClass());
2445
2446 CElement *pLocatedElement = nullptr;
2447
2448 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
2449
2450 warning() << "Fail:" << strError;
2451 return false;
2452 }
2453
2454 // Convert element
2455 CConfigurableElement *pConfigurableElement =
2456 static_cast<CConfigurableElement *>(pLocatedElement);
2457
2458 // Delegate
2459 return logResult(getConfigurableDomains()->removeConfigurableElementFromDomain(
2460 strDomain, pConfigurableElement, strError),
2461 strError);
2462 }
2463
split(const string & strDomain,const string & strConfigurableElementPath,string & strError)2464 bool CParameterMgr::split(const string &strDomain, const string &strConfigurableElementPath,
2465 string &strError)
2466 {
2467 LOG_CONTEXT("Splitting configurable element '" + strConfigurableElementPath + "' domain '" +
2468 strDomain + "'");
2469 // Check tuning mode
2470 if (!checkTuningModeOn(strError)) {
2471
2472 warning() << "Fail:" << strError;
2473 return false;
2474 }
2475
2476 CElementLocator elementLocator(getSystemClass());
2477
2478 CElement *pLocatedElement = nullptr;
2479
2480 if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
2481
2482 warning() << "Fail: " << strError;
2483 return false;
2484 }
2485
2486 // Convert element
2487 CConfigurableElement *pConfigurableElement =
2488 static_cast<CConfigurableElement *>(pLocatedElement);
2489
2490 // Delegate
2491 core::Results infos;
2492 bool isSuccess = getConfigurableDomains()->split(strDomain, pConfigurableElement, infos);
2493
2494 if (isSuccess) {
2495 info() << infos;
2496 } else {
2497 warning() << infos;
2498 }
2499
2500 strError = utility::asString(infos);
2501 return isSuccess;
2502 }
2503
setElementSequence(const string & strDomain,const string & strConfiguration,const std::vector<string> & astrNewElementSequence,string & strError)2504 bool CParameterMgr::setElementSequence(const string &strDomain, const string &strConfiguration,
2505 const std::vector<string> &astrNewElementSequence,
2506 string &strError)
2507 {
2508 // Check tuning mode
2509 if (!checkTuningModeOn(strError)) {
2510
2511 return false;
2512 }
2513
2514 return getConfigurableDomains()->setElementSequence(strDomain, strConfiguration,
2515 astrNewElementSequence, strError);
2516 }
2517
getApplicationRule(const string & strDomain,const string & strConfiguration,string & strResult)2518 bool CParameterMgr::getApplicationRule(const string &strDomain, const string &strConfiguration,
2519 string &strResult)
2520 {
2521 return getConfigurableDomains()->getApplicationRule(strDomain, strConfiguration, strResult);
2522 }
2523
setApplicationRule(const string & strDomain,const string & strConfiguration,const string & strApplicationRule,string & strError)2524 bool CParameterMgr::setApplicationRule(const string &strDomain, const string &strConfiguration,
2525 const string &strApplicationRule, string &strError)
2526 {
2527 return getConfigurableDomains()->setApplicationRule(
2528 strDomain, strConfiguration, strApplicationRule,
2529 getConstSelectionCriteria()->getSelectionCriteriaDefinition(), strError);
2530 }
2531
clearApplicationRule(const string & strDomain,const string & strConfiguration,string & strError)2532 bool CParameterMgr::clearApplicationRule(const string &strDomain, const string &strConfiguration,
2533 string &strError)
2534 {
2535 return getConfigurableDomains()->clearApplicationRule(strDomain, strConfiguration, strError);
2536 }
2537
importDomainsXml(const string & xmlSource,bool withSettings,bool fromFile,string & errorMsg)2538 bool CParameterMgr::importDomainsXml(const string &xmlSource, bool withSettings, bool fromFile,
2539 string &errorMsg)
2540 {
2541 // Check tuning mode
2542 if (!checkTuningModeOn(errorMsg)) {
2543
2544 return false;
2545 }
2546
2547 LOG_CONTEXT("Importing domains from " +
2548 (fromFile ? ("\"" + xmlSource + "\"") : "a user-provided buffer"));
2549
2550 // Root element
2551 CConfigurableDomains *pConfigurableDomains = getConfigurableDomains();
2552
2553 bool importSuccess = wrapLegacyXmlImport(xmlSource, fromFile, withSettings,
2554 *pConfigurableDomains, "SystemClassName", errorMsg);
2555
2556 if (importSuccess) {
2557
2558 // Validate domains after XML import
2559 pConfigurableDomains->validate(_pMainParameterBlackboard);
2560 }
2561
2562 return importSuccess;
2563 }
2564
importSingleDomainXml(const string & xmlSource,bool overwrite,bool withSettings,bool fromFile,string & errorMsg)2565 bool CParameterMgr::importSingleDomainXml(const string &xmlSource, bool overwrite,
2566 bool withSettings, bool fromFile, string &errorMsg)
2567 {
2568 if (!checkTuningModeOn(errorMsg)) {
2569
2570 return false;
2571 }
2572
2573 LOG_CONTEXT("Importing a single domain from " +
2574 (fromFile ? ('"' + xmlSource + '"') : "a user-provided buffer"));
2575
2576 // We initialize the domain with an empty name but since we have set the isDomainStandalone
2577 // context, the name will be retrieved during de-serialization
2578 auto standaloneDomain = utility::make_unique<CConfigurableDomain>();
2579
2580 if (!wrapLegacyXmlImport(xmlSource, fromFile, withSettings, *standaloneDomain, "", errorMsg)) {
2581 return false;
2582 }
2583
2584 if (!getConfigurableDomains()->addDomain(*standaloneDomain, overwrite, errorMsg)) {
2585 return false;
2586 }
2587
2588 // ownership has been transfered to the ConfigurableDomains object
2589 standaloneDomain.release();
2590 return true;
2591 }
2592
wrapLegacyXmlImport(const string & xmlSource,bool fromFile,bool withSettings,CElement & element,const string & nameAttributeName,string & errorMsg)2593 bool CParameterMgr::wrapLegacyXmlImport(const string &xmlSource, bool fromFile, bool withSettings,
2594 CElement &element, const string &nameAttributeName,
2595 string &errorMsg)
2596 {
2597 CXmlDomainImportContext xmlDomainImportContext(errorMsg, withSettings, *getSystemClass());
2598
2599 // Selection criteria definition for rule creation
2600 xmlDomainImportContext.setSelectionCriteriaDefinition(
2601 getConstSelectionCriteria()->getSelectionCriteriaDefinition());
2602
2603 // It doesn't make sense to resolve XIncludes on an imported file because
2604 // we can't reliably decide of a "base url"
2605 _xmlDoc *doc = CXmlDocSource::mkXmlDoc(xmlSource, fromFile, false, xmlDomainImportContext);
2606 if (doc == nullptr) {
2607 return false;
2608 }
2609
2610 return xmlParse(xmlDomainImportContext, &element, doc, "", EParameterConfigurationLibrary, true,
2611 nameAttributeName);
2612 }
2613
serializeElement(std::ostream & output,CXmlSerializingContext & xmlSerializingContext,const CElement & element) const2614 bool CParameterMgr::serializeElement(std::ostream &output,
2615 CXmlSerializingContext &xmlSerializingContext,
2616 const CElement &element) const
2617 {
2618 if (!output.good()) {
2619 xmlSerializingContext.setError("Can't write XML: the output is in a bad state.");
2620 return false;
2621 }
2622
2623 // Use a doc source by loading data from instantiated Configurable Domains
2624 CXmlMemoryDocSource memorySource(&element, _bValidateSchemasOnStart,
2625 element.getXmlElementName(), "parameter-framework",
2626 getVersion());
2627
2628 // Use a doc sink to write the doc data in a stream
2629 CXmlStreamDocSink sink(output);
2630
2631 bool processSuccess = sink.process(memorySource, xmlSerializingContext);
2632
2633 return processSuccess;
2634 }
2635
exportDomainsXml(string & xmlDest,bool withSettings,bool toFile,string & errorMsg) const2636 bool CParameterMgr::exportDomainsXml(string &xmlDest, bool withSettings, bool toFile,
2637 string &errorMsg) const
2638 {
2639 LOG_CONTEXT("Exporting domains to " +
2640 (toFile ? ('"' + xmlDest + '"') : "a user-provided buffer"));
2641
2642 const CConfigurableDomains *configurableDomains = getConstConfigurableDomains();
2643
2644 return wrapLegacyXmlExport(xmlDest, toFile, withSettings, *configurableDomains, errorMsg);
2645 }
2646
exportSingleDomainXml(string & xmlDest,const string & domainName,bool withSettings,bool toFile,string & errorMsg) const2647 bool CParameterMgr::exportSingleDomainXml(string &xmlDest, const string &domainName,
2648 bool withSettings, bool toFile, string &errorMsg) const
2649 {
2650 LOG_CONTEXT("Exporting single domain '" + domainName + "' to " +
2651 (toFile ? ('"' + xmlDest + '"') : "a user-provided buffer"));
2652
2653 // Element to be serialized
2654 const CConfigurableDomain *requestedDomain =
2655 getConstConfigurableDomains()->findConfigurableDomain(domainName, errorMsg);
2656
2657 if (requestedDomain == nullptr) {
2658 return false;
2659 }
2660
2661 return wrapLegacyXmlExport(xmlDest, toFile, withSettings, *requestedDomain, errorMsg);
2662 }
2663
wrapLegacyXmlExport(string & xmlDest,bool toFile,bool withSettings,const CElement & element,string & errorMsg) const2664 bool CParameterMgr::wrapLegacyXmlExport(string &xmlDest, bool toFile, bool withSettings,
2665 const CElement &element, string &errorMsg) const
2666 {
2667 CXmlDomainExportContext context(errorMsg, withSettings, _bValueSpaceIsRaw,
2668 _bOutputRawFormatIsHex);
2669
2670 if (toFile) {
2671 return wrapLegacyXmlExportToFile(xmlDest, element, context);
2672 } else {
2673 return wrapLegacyXmlExportToString(xmlDest, element, context);
2674 }
2675 }
2676
wrapLegacyXmlExportToFile(string & xmlDest,const CElement & element,CXmlDomainExportContext & context) const2677 bool CParameterMgr::wrapLegacyXmlExportToFile(string &xmlDest, const CElement &element,
2678 CXmlDomainExportContext &context) const
2679 {
2680 try {
2681 std::ofstream output;
2682 // Force stream to throw instead of using fail/bad bit
2683 // in order to retreive an error message.
2684 output.exceptions(~std::ifstream::goodbit);
2685
2686 output.open(xmlDest.c_str());
2687 bool status = serializeElement(output, context, element);
2688 output.close(); // Explicit close to detect errors
2689
2690 return status;
2691
2692 } catch (std::ofstream::failure &e) {
2693 context.setError("Failed to open \"" + xmlDest + "\" for writing: " + e.what());
2694 return false;
2695 }
2696 }
2697
wrapLegacyXmlExportToString(string & xmlDest,const CElement & element,CXmlDomainExportContext & context) const2698 bool CParameterMgr::wrapLegacyXmlExportToString(string &xmlDest, const CElement &element,
2699 CXmlDomainExportContext &context) const
2700 {
2701 std::ostringstream output;
2702
2703 if (!serializeElement(output, context, element)) {
2704 return false;
2705 }
2706
2707 xmlDest = output.str();
2708
2709 return true;
2710 }
2711
2712 // For tuning, check we're in tuning mode
checkTuningModeOn(string & strError) const2713 bool CParameterMgr::checkTuningModeOn(string &strError) const
2714 {
2715 // Tuning Mode on?
2716 if (!_bTuningModeIsOn) {
2717
2718 strError = "Tuning Mode must be on";
2719
2720 return false;
2721 }
2722 return true;
2723 }
2724
2725 // Tuning mutex dynamic parameter handling
getBlackboardMutex()2726 std::mutex &CParameterMgr::getBlackboardMutex()
2727 {
2728 return _blackboardMutex;
2729 }
2730
2731 // Blackboard reference (dynamic parameter handling)
getParameterBlackboard()2732 CParameterBlackboard *CParameterMgr::getParameterBlackboard()
2733 {
2734 return _pMainParameterBlackboard;
2735 }
2736
2737 // Dynamic creation library feeding
feedElementLibraries()2738 void CParameterMgr::feedElementLibraries()
2739 {
2740 // Global Configuration handling
2741 auto pFrameworkConfigurationLibrary = new CElementLibrary;
2742
2743 pFrameworkConfigurationLibrary->addElementBuilder(
2744 "ParameterFrameworkConfiguration",
2745 new TElementBuilderTemplate<CParameterFrameworkConfiguration>());
2746 pFrameworkConfigurationLibrary->addElementBuilder(
2747 "SubsystemPlugins", new TKindElementBuilderTemplate<CSubsystemPlugins>());
2748 pFrameworkConfigurationLibrary->addElementBuilder(
2749 "Location", new TKindElementBuilderTemplate<CPluginLocation>());
2750 pFrameworkConfigurationLibrary->addElementBuilder(
2751 "StructureDescriptionFileLocation",
2752 new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>());
2753 pFrameworkConfigurationLibrary->addElementBuilder(
2754 "SettingsConfiguration", new TKindElementBuilderTemplate<CFrameworkConfigurationGroup>());
2755 pFrameworkConfigurationLibrary->addElementBuilder(
2756 "ConfigurableDomainsFileLocation",
2757 new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>());
2758
2759 _pElementLibrarySet->addElementLibrary(pFrameworkConfigurationLibrary);
2760
2761 // Parameter creation
2762 auto pParameterCreationLibrary = new CElementLibrary;
2763
2764 pParameterCreationLibrary->addElementBuilder(
2765 "Subsystem", new CSubsystemElementBuilder(getSystemClass()->getSubsystemLibrary()));
2766 pParameterCreationLibrary->addElementBuilder(
2767 "ComponentType", new TNamedElementBuilderTemplate<CComponentType>());
2768 pParameterCreationLibrary->addElementBuilder(
2769 "Component", new TNamedElementBuilderTemplate<CComponentInstance>());
2770 pParameterCreationLibrary->addElementBuilder(
2771 "BitParameter", new TNamedElementBuilderTemplate<CBitParameterType>());
2772 pParameterCreationLibrary->addElementBuilder(
2773 "BitParameterBlock", new TNamedElementBuilderTemplate<CBitParameterBlockType>());
2774 pParameterCreationLibrary->addElementBuilder(
2775 "StringParameter", new TNamedElementBuilderTemplate<CStringParameterType>());
2776 pParameterCreationLibrary->addElementBuilder(
2777 "ParameterBlock", new TNamedElementBuilderTemplate<CParameterBlockType>());
2778 pParameterCreationLibrary->addElementBuilder(
2779 "BooleanParameter", new TNamedElementBuilderTemplate<CBooleanParameterType>());
2780 pParameterCreationLibrary->addElementBuilder("IntegerParameter", new IntegerParameterBuilder());
2781 pParameterCreationLibrary->addElementBuilder(
2782 "LinearAdaptation", new TElementBuilderTemplate<CLinearParameterAdaptation>());
2783 pParameterCreationLibrary->addElementBuilder(
2784 "LogarithmicAdaptation", new TElementBuilderTemplate<CLogarithmicParameterAdaptation>());
2785 pParameterCreationLibrary->addElementBuilder(
2786 "EnumParameter", new TNamedElementBuilderTemplate<CEnumParameterType>());
2787 pParameterCreationLibrary->addElementBuilder("ValuePair",
2788 new TElementBuilderTemplate<CEnumValuePair>());
2789 pParameterCreationLibrary->addElementBuilder(
2790 "FixedPointParameter", new TNamedElementBuilderTemplate<CFixedPointParameterType>());
2791 pParameterCreationLibrary->addElementBuilder(
2792 "FloatingPointParameter", new TNamedElementBuilderTemplate<CFloatingPointParameterType>);
2793 pParameterCreationLibrary->addElementBuilder(
2794 "SubsystemInclude",
2795 new CFileIncluderElementBuilder(_bValidateSchemasOnStart, getSchemaUri()));
2796
2797 _pElementLibrarySet->addElementLibrary(pParameterCreationLibrary);
2798
2799 // Parameter Configuration Domains creation
2800 auto pParameterConfigurationLibrary = new CElementLibrary;
2801
2802 pParameterConfigurationLibrary->addElementBuilder(
2803 "ConfigurableDomain", new TElementBuilderTemplate<CConfigurableDomain>());
2804 pParameterConfigurationLibrary->addElementBuilder(
2805 "Configuration", new TNamedElementBuilderTemplate<CDomainConfiguration>());
2806 pParameterConfigurationLibrary->addElementBuilder("CompoundRule",
2807 new TElementBuilderTemplate<CCompoundRule>());
2808 pParameterConfigurationLibrary->addElementBuilder(
2809 "SelectionCriterionRule", new TElementBuilderTemplate<CSelectionCriterionRule>());
2810
2811 _pElementLibrarySet->addElementLibrary(pParameterConfigurationLibrary);
2812 }
2813
getForceNoRemoteInterface() const2814 bool CParameterMgr::getForceNoRemoteInterface() const
2815 {
2816 return _bForceNoRemoteInterface;
2817 }
2818
setForceNoRemoteInterface(bool bForceNoRemoteInterface)2819 void CParameterMgr::setForceNoRemoteInterface(bool bForceNoRemoteInterface)
2820 {
2821 _bForceNoRemoteInterface = bForceNoRemoteInterface;
2822 }
2823
createCommandHandler()2824 CParameterMgr::CommandHandler CParameterMgr::createCommandHandler()
2825 {
2826 auto commandHandler = utility::make_unique<CCommandHandler>(this);
2827
2828 // Add command parsers
2829 for (const auto &remoteCommandParserItem : gastRemoteCommandParserItems) {
2830 commandHandler->addCommandParser(
2831 remoteCommandParserItem._pcCommandName, remoteCommandParserItem._pfnParser,
2832 remoteCommandParserItem._minArgumentCount, remoteCommandParserItem._pcHelp,
2833 remoteCommandParserItem._pcDescription);
2834 }
2835
2836 return commandHandler;
2837 }
2838
isRemoteInterfaceRequired()2839 bool CParameterMgr::isRemoteInterfaceRequired()
2840 {
2841 // The remote interface should only be started if the client didn't
2842 // explicitly forbid it and if the configuration file allows it.
2843 return (not _bForceNoRemoteInterface) and getConstFrameworkConfiguration()->isTuningAllowed();
2844 }
2845
2846 // Remote Processor Server connection handling
handleRemoteProcessingInterface(string & strError)2847 bool CParameterMgr::handleRemoteProcessingInterface(string &strError)
2848 {
2849 LOG_CONTEXT("Handling remote processing interface");
2850
2851 if (not isRemoteInterfaceRequired()) {
2852 return true;
2853 }
2854
2855 auto bindAddress = getConstFrameworkConfiguration()->getServerBindAddress();
2856
2857 try {
2858 // The ownership of remoteComandHandler is given to Bg remote processor server.
2859 _pRemoteProcessorServer =
2860 new BackgroundRemoteProcessorServer(bindAddress, createCommandHandler());
2861 } catch (std::runtime_error &e) {
2862 strError = string("ParameterMgr: Unable to create Remote Processor Server: ") + e.what();
2863 return false;
2864 }
2865
2866 if (_pRemoteProcessorServer == nullptr) {
2867 strError = "ParameterMgr: Unable to create Remote Processor Server";
2868 return false;
2869 }
2870
2871 if (!_pRemoteProcessorServer->start(strError)) {
2872 ostringstream oss;
2873 oss << "ParameterMgr: Unable to start remote processor server on " << bindAddress;
2874 strError = oss.str() + ": " + strError;
2875 return false;
2876 }
2877 info() << "Remote Processor Server started on " << bindAddress;
2878 return true;
2879 }
2880
2881 // Children typwise access
getFrameworkConfiguration()2882 CParameterFrameworkConfiguration *CParameterMgr::getFrameworkConfiguration()
2883 {
2884 return static_cast<CParameterFrameworkConfiguration *>(getChild(EFrameworkConfiguration));
2885 }
2886
getConstFrameworkConfiguration()2887 const CParameterFrameworkConfiguration *CParameterMgr::getConstFrameworkConfiguration()
2888 {
2889 return getFrameworkConfiguration();
2890 }
2891
getSelectionCriteria()2892 CSelectionCriteria *CParameterMgr::getSelectionCriteria()
2893 {
2894 return static_cast<CSelectionCriteria *>(getChild(ESelectionCriteria));
2895 }
2896
getConstSelectionCriteria()2897 const CSelectionCriteria *CParameterMgr::getConstSelectionCriteria()
2898 {
2899 return static_cast<const CSelectionCriteria *>(getChild(ESelectionCriteria));
2900 }
2901
getSystemClass()2902 CSystemClass *CParameterMgr::getSystemClass()
2903 {
2904 return static_cast<CSystemClass *>(getChild(ESystemClass));
2905 }
2906
getConstSystemClass() const2907 const CSystemClass *CParameterMgr::getConstSystemClass() const
2908 {
2909 return static_cast<const CSystemClass *>(getChild(ESystemClass));
2910 }
2911
2912 // Configurable Domains
getConfigurableDomains()2913 CConfigurableDomains *CParameterMgr::getConfigurableDomains()
2914 {
2915 return static_cast<CConfigurableDomains *>(getChild(EConfigurableDomains));
2916 }
2917
getConstConfigurableDomains()2918 const CConfigurableDomains *CParameterMgr::getConstConfigurableDomains()
2919 {
2920 return static_cast<const CConfigurableDomains *>(getChild(EConfigurableDomains));
2921 }
2922
getConstConfigurableDomains() const2923 const CConfigurableDomains *CParameterMgr::getConstConfigurableDomains() const
2924 {
2925 return static_cast<const CConfigurableDomains *>(getChild(EConfigurableDomains));
2926 }
2927
2928 // Apply configurations
doApplyConfigurations(bool bForce)2929 void CParameterMgr::doApplyConfigurations(bool bForce)
2930 {
2931 LOG_CONTEXT("Applying configurations");
2932
2933 CSyncerSet syncerSet;
2934
2935 core::Results infos;
2936 // Check subsystems that need resync
2937 getSystemClass()->checkForSubsystemsToResync(syncerSet, infos);
2938
2939 // Ensure application of currently selected configurations
2940 getConfigurableDomains()->apply(_pMainParameterBlackboard, syncerSet, bForce, infos);
2941 info() << infos;
2942
2943 // Reset the modified status of the current criteria to indicate that a new configuration has
2944 // been applied
2945 getSelectionCriteria()->resetModifiedStatus();
2946 }
2947
2948 // Export to XML string
exportElementToXMLString(const IXmlSource * pXmlSource,const string & strRootElementType,CXmlSerializingContext && xmlSerializingContext,string & strResult) const2949 bool CParameterMgr::exportElementToXMLString(const IXmlSource *pXmlSource,
2950 const string &strRootElementType,
2951 CXmlSerializingContext &&xmlSerializingContext,
2952 string &strResult) const
2953 {
2954 // Use a doc source by loading data from instantiated Configurable Domains
2955 CXmlMemoryDocSource memorySource(pXmlSource, false, strRootElementType);
2956
2957 // Use a doc sink that write the doc data in a string
2958 ostringstream output;
2959 CXmlStreamDocSink streamSink(output);
2960
2961 // Do the export
2962 bool bProcessSuccess = streamSink.process(memorySource, xmlSerializingContext);
2963
2964 strResult = output.str();
2965
2966 return bProcessSuccess;
2967 }
2968
logResult(bool isSuccess,const std::string & result)2969 bool CParameterMgr::logResult(bool isSuccess, const std::string &result)
2970 {
2971 std::string log = result.empty() ? "" : ": " + result;
2972
2973 if (isSuccess) {
2974 info() << "Success" << log;
2975 } else {
2976 warning() << "Fail" << log;
2977 }
2978
2979 return isSuccess;
2980 }
2981
info()2982 log::details::Info CParameterMgr::info()
2983 {
2984 return _logger.info();
2985 }
2986
warning()2987 log::details::Warning CParameterMgr::warning()
2988 {
2989 return _logger.warning();
2990 }
2991